@travetto/terminal 4.0.0-rc.3 → 4.0.0-rc.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/terminal",
3
- "version": "4.0.0-rc.3",
3
+ "version": "4.0.0-rc.4",
4
4
  "description": "General terminal support",
5
5
  "keywords": [
6
6
  "terminal",
@@ -24,7 +24,7 @@
24
24
  "directory": "module/terminal"
25
25
  },
26
26
  "dependencies": {
27
- "@travetto/base": "^4.0.0-rc.3",
27
+ "@travetto/base": "^4.0.0-rc.4",
28
28
  "chalk": "^4.1.2"
29
29
  },
30
30
  "travetto": {
package/src/terminal.ts CHANGED
@@ -19,7 +19,6 @@ export class Terminal {
19
19
 
20
20
  #interactive: boolean;
21
21
  #writer: TerminalWriter;
22
- #reset: () => Promise<void>;
23
22
  #cleanExit = 0;
24
23
  #width: number;
25
24
  #height: number;
@@ -37,10 +36,10 @@ export class Terminal {
37
36
 
38
37
  #cleanOnExit(): () => void {
39
38
  if (this.#cleanExit === 0) {
40
- process.on('exit', this.#reset);
39
+ process.on('exit', TerminalWriter.reset);
41
40
  }
42
41
  this.#cleanExit += 1;
43
- return () => (this.#cleanExit -= 1) === 0 && process.off('exit', this.#reset);
42
+ return () => (this.#cleanExit -= 1) === 0 && process.off('exit', TerminalWriter.reset);
44
43
  }
45
44
 
46
45
  constructor(output?: tty.WriteStream, config?: { width?: number, height?: number }) {
@@ -48,8 +47,7 @@ export class Terminal {
48
47
  this.#interactive = this.#output.isTTY && !Env.TRV_QUIET.isTrue;
49
48
  this.#width = config?.width ?? (this.#output.isTTY ? this.#output.columns : 120);
50
49
  this.#height = config?.height ?? (this.#output.isTTY ? this.#output.rows : 120);
51
- const w = this.#writer = new TerminalWriter(this);
52
- this.#reset = (): Promise<void> => w.softReset().commit();
50
+ this.#writer = new TerminalWriter(this);
53
51
  }
54
52
 
55
53
  get output(): tty.WriteStream { return this.#output; }
package/src/writer.ts CHANGED
@@ -14,7 +14,7 @@ const Codes = {
14
14
  SCROLL_RANGE_CLEAR: `${ESC}r`,
15
15
  POSITION_RESTORE: `${ESC}u`,
16
16
  POSITION_SAVE: `${ESC}s`,
17
- SOFT_RESET_CODES: `${ESC}!p`,
17
+ SOFT_RESET: `${ESC}!p`,
18
18
  ERASE_LINE_RIGHT: `${ESC}0K`,
19
19
  ERASE_LINE_LEFT: `${ESC}1K`,
20
20
  ERASE_LINE_ALL: `${ESC}2K`,
@@ -31,6 +31,12 @@ const Codes = {
31
31
  * Buffered/batched writer. Meant to be similar to readline.Readline, but with more general writing support and extensibility
32
32
  */
33
33
  export class TerminalWriter {
34
+
35
+ static reset(): void {
36
+ process.stdout.isTTY && process.stdout.write(Codes.SOFT_RESET);
37
+ process.stderr.isTTY && process.stderr.write(Codes.SOFT_RESET);
38
+ }
39
+
34
40
  #buffer: (string | number)[] = [];
35
41
  #restoreOnCommit = false;
36
42
  #term: State;
@@ -141,6 +147,6 @@ export class TerminalWriter {
141
147
 
142
148
  /** Reset */
143
149
  softReset(): this {
144
- return this.write(Codes.SOFT_RESET_CODES);
150
+ return this.write(Codes.SOFT_RESET);
145
151
  }
146
152
  }