]> git.wincent.com - wincent.git/commitdiff
refactor: start working on terminfo aspect
authorGreg Hurrell <greg@hurrell.net>
Sat, 21 Mar 2020 16:46:25 +0000 (17:46 +0100)
committerGreg Hurrell <greg@hurrell.net>
Sat, 21 Mar 2020 16:46:25 +0000 (17:46 +0100)
Not a "feat" yet.

aspects/terminfo/files/README.md [new file with mode: 0644]
aspects/terminfo/files/tmux-256color.terminfo [new file with mode: 0644]
aspects/terminfo/files/tmux.terminfo [new file with mode: 0644]
aspects/terminfo/files/xterm-256color.terminfo [new file with mode: 0644]
aspects/terminfo/index.ts [new file with mode: 0644]
aspects/terminfo/meta.json [new file with mode: 0644]
install-next
src/Fig.ts [new file with mode: 0644]
src/main.ts
tsconfig.json

diff --git a/aspects/terminfo/files/README.md b/aspects/terminfo/files/README.md
new file mode 100644 (file)
index 0000000..c2ca70c
--- /dev/null
@@ -0,0 +1,8 @@
+This role manages `TERMINFO` files that add escape sequences for italic,
+and overwrite conflicting sequences for standout text.
+
+To check that the terminal does the right thing:
+
+```sh
+echo `tput sitm`italics`tput ritm` `tput smso`standout`tput rmso`
+```
diff --git a/aspects/terminfo/files/tmux-256color.terminfo b/aspects/terminfo/files/tmux-256color.terminfo
new file mode 100644 (file)
index 0000000..9e84705
--- /dev/null
@@ -0,0 +1,4 @@
+tmux-256color|tmux with 256 colors,
+  sitm=\E[3m, ritm=\E[23m,
+  smso=\E[7m, rmso=\E[27m,
+  use=screen-256color,
diff --git a/aspects/terminfo/files/tmux.terminfo b/aspects/terminfo/files/tmux.terminfo
new file mode 100644 (file)
index 0000000..9887711
--- /dev/null
@@ -0,0 +1,4 @@
+tmux|tmux terminal multiplexer,
+  sitm=\E[3m, ritm=\E[23m,
+  smso=\E[7m, rmso=\E[27m,
+  use=screen,
diff --git a/aspects/terminfo/files/xterm-256color.terminfo b/aspects/terminfo/files/xterm-256color.terminfo
new file mode 100644 (file)
index 0000000..2af39cb
--- /dev/null
@@ -0,0 +1,3 @@
+xterm-256color|xterm with 256 colors and italic,
+  sitm=\E[3m, ritm=\E[23m,
+  use=xterm-256color,
diff --git a/aspects/terminfo/index.ts b/aspects/terminfo/index.ts
new file mode 100644 (file)
index 0000000..193fa04
--- /dev/null
@@ -0,0 +1,14 @@
+// because we want relative file access, will have to direct it via API (because
+// files are in "aspects" but we are built in "lib/aspects"
+
+// - name: terminfo | create target directory
+//   file: path={{ terminfo_path }} state=directory
+Fig.task('create target directory');
+
+// - name: terminfo | update terminfo files
+//   command:
+//     tic -o {{ terminfo_path }} roles/terminfo/files/{{ item }}
+//   loop:
+//     - tmux.terminfo
+//     - tmux-256color.terminfo
+//     - xterm-256color.terminfo
diff --git a/aspects/terminfo/meta.json b/aspects/terminfo/meta.json
new file mode 100644 (file)
index 0000000..2366fcd
--- /dev/null
@@ -0,0 +1,6 @@
+{
+  "description": "Sets up terminfo database entries for italics and 256-color support",
+  "defaults": {
+    "terminfo_path": "~/.terminfo"
+  }
+}
index 9634a23c74bb07b4de7ae7603b7f712ad51a0aa5..0ee59e720c83cd4dff9dca907d459bad92fb2862 100755 (executable)
@@ -20,4 +20,4 @@ tsc
 
 log_info "Running main"
 
-node "$REPO_ROOT/lib/main.js" "$@"
+node "$REPO_ROOT/lib/src/main.js" "$@"
diff --git a/src/Fig.ts b/src/Fig.ts
new file mode 100644 (file)
index 0000000..403c0f0
--- /dev/null
@@ -0,0 +1,42 @@
+class CapturingError extends Error {
+  prepareStackTrace(_error: Error, structuredStackTrace: any): any {
+    return structuredStackTrace;
+  }
+}
+
+/**
+ * @see https://v8.dev/docs/stack-trace-api
+ */
+function getCaller(): string {
+  const prepareStackTrace = Error.prepareStackTrace;
+
+  try {
+    Error.prepareStackTrace = (_error: Error, structuredStackTrace: Array<NodeJS.CallSite>): Array<NodeJS.CallSite> => {
+      return structuredStackTrace;
+    }
+
+    const stack: Array<NodeJS.CallSite> = new Error().stack as any;
+
+    // Skip two stack frames (this function, and caller of this
+    // function), to get caller of our caller.
+    return (stack.length > 2 ? stack[2].getFileName() : '') || '[unknown]';
+  } finally {
+    Error.prepareStackTrace = prepareStackTrace;
+  }
+}
+
+/**
+ * Set up `Fig` global for use in aspects, templates etc.
+ */
+const F = {
+  task(name: string) {
+    const caller = getCaller();
+
+    // TODO: use `caller` to make namespaced task name.
+    console.log(`caller: ${JSON.stringify(caller, null, 2)} - ${name}`);
+  }
+};
+
+declare var Fig: typeof F;
+
+(global as any).Fig = F;
index 9f2d53b25392b3afcd2e37c156e40462555dbb06..fade0e9d99434f43c4c1e7ff0d632b8dbd5fca7e 100644 (file)
@@ -1,3 +1,5 @@
+import './Fig';
+
 import {log} from './console';
 import test from './test';
 
@@ -9,6 +11,9 @@ log.debug(JSON.stringify(process.argv, null, 2));
 async function main() {
   log.info('Running tests');
   await test();
+
+  log.info('Running runbooks');
+  require('../aspects/terminfo');
 }
 
 main().catch(error => {
index 060fb05ee1fbdc41ea579f6af67c1b2d2e66aecd..bb7b83444b871acf1b8d354300ef409625ac34bb 100644 (file)
@@ -5,5 +5,5 @@
     "strict": true,
     "target": "ES2019"
   },
-  "include": ["src/**/*.ts"]
+  "include": ["aspects/**/*.ts", "src/**/*.ts"]
 }