Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

@alterior/terminal

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@alterior/terminal - npm Package Compare versions

Comparing version
3.1.11
to
3.1.12
+26
dist/terminal-ui.d.ts
/// <reference types="node" />
/// <reference types="node" />
import { ReadStream, WriteStream } from 'tty';
import { StyledString } from './style';
export declare class TerminalUI {
constructor(input?: NodeJS.ReadStream & {
fd: 0;
}, output?: NodeJS.WriteStream & {
fd: 1;
});
input: ReadStream;
output: WriteStream;
private rl;
private _prompt;
get prompt(): string;
set prompt(value: string);
runCommand: (line: string) => Promise<void>;
beforeShowingPrompt: () => Promise<void>;
runningCommand: boolean;
start(): Promise<void>;
history: string[];
private startPrompt;
private allocatePromptSpace;
private deletePrompt;
log(...contents: (string | number | StyledString)[]): Promise<void>;
}
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TerminalUI = void 0;
const readline_1 = __importDefault(require("readline"));
const style_1 = require("./style");
class TerminalUI {
constructor(input = process.stdin, output = process.stdout) {
this.runningCommand = false;
this.history = [];
this.input = input;
this.output = output;
}
get prompt() {
return this._prompt;
}
set prompt(value) {
this._prompt = value;
if (this.rl) {
this.rl.setPrompt(value);
this.rl._refreshLine();
}
}
async start() {
//await this.runCommand('sleep');
this.startPrompt();
}
async startPrompt() {
var _a;
readline_1.default.emitKeypressEvents(this.input);
this.rl = readline_1.default.createInterface({
input: this.input,
output: this.output,
history: this.history
});
this.rl.addListener('SIGINT', () => {
this.log();
});
this.rl.setPrompt(this._prompt);
this.rl.addListener('history', async (lines) => this.history = lines);
this.rl.addListener('line', async (line) => {
this.rl.close();
this.rl = null;
this.runningCommand = true;
this.output.cork();
this.output.moveCursor(0, -1);
this.deletePrompt();
this.output.uncork();
try {
await this.runCommand(line);
}
finally {
this.runningCommand = false;
this.output.cork();
this.startPrompt();
this.output.uncork();
}
});
await ((_a = this.beforeShowingPrompt) === null || _a === void 0 ? void 0 : _a.call(this));
this.allocatePromptSpace();
this.rl.prompt();
}
allocatePromptSpace() {
let lines = this._prompt.split("\n").length + 1;
this.output.write(Array(lines + 1).join("\n"));
this.output.moveCursor(0, -lines);
}
deletePrompt() {
for (let i = 0, max = this.prompt.split("\n").length; i < max; ++i) {
this.output.clearLine(0);
this.output.cursorTo(0);
if (i + 1 < max)
this.output.moveCursor(0, -1);
}
}
async log(...contents) {
var _a, _b;
let message = (0, style_1.styled)(...contents);
let actualCursorPos = (_b = (_a = this.rl) === null || _a === void 0 ? void 0 : _a.getCursorPos()) !== null && _b !== void 0 ? _b : { rows: 0, cols: 0 };
this.output.cork();
if (this.rl)
this.deletePrompt();
this.output.write(message + `\n`);
if (this.rl) {
this.allocatePromptSpace();
this.output.write(this.prompt + this.rl.line);
this.output.cursorTo(actualCursorPos.cols);
}
this.output.uncork();
}
}
exports.TerminalUI = TerminalUI;
//# sourceMappingURL=terminal-ui.js.map
{"version":3,"file":"terminal-ui.js","sourceRoot":"","sources":["../src/terminal-ui.ts"],"names":[],"mappings":";;;;;;AACA,wDAAgC;AAChC,mCAA+C;AAE/C,MAAa,UAAU;IACnB,YAAY,KAAK,GAAG,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM;QAwB1D,mBAAc,GAAG,KAAK,CAAC;QAOvB,YAAO,GAAa,EAAE,CAAC;QA9BnB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAOD,IAAI,MAAM;QACN,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAED,IAAI,MAAM,CAAC,KAAK;QACZ,IAAI,CAAC,OAAO,GAAG,KAAK,C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AAC,CAAC,CAAC;SACrC;IACL,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAG,QAA4C;;QACrD,IAAI,OAAO,GAAG,IAAA,cAAM,EAAC,GAAU,QAAQ,CAAC,CAAC;QACzC,IAAI,eAAe,GAAG,MAAA,MAAA,IAAI,CAAC,EAAE,0CAAE,YAAY,EAAE,mCAAI,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;QACtE,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;QACnB,IAAI,IAAI,CAAC,EAAE;YACP,IAAI,CAAC,YAAY,EAAE,CAAC;QACxB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;QAClC,IAAI,IAAI,CAAC,EAAE,EAAE;YACT,IAAI,CAAC,mBAAmB,EAAE,CAAC;YAC3B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;YAC9C,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;SAC9C;QAED,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;IACzB,CAAC;CACJ;AArGD,gCAqGC"}
import { ReadStream, WriteStream } from 'tty';
import readline from 'readline';
import { styled, StyledString } from './style';
export class TerminalUI {
constructor(input = process.stdin, output = process.stdout) {
this.input = input;
this.output = output;
}
input: ReadStream;
output: WriteStream;
private rl: readline.Interface;
private _prompt: string;
get prompt() {
return this._prompt;
}
set prompt(value) {
this._prompt = value;
if (this.rl) {
this.rl.setPrompt(value);
(this.rl as any)._refreshLine();
}
}
runCommand: (line: string) => Promise<void>;
beforeShowingPrompt: () => Promise<void>;
runningCommand = false;
async start() {
//await this.runCommand('sleep');
this.startPrompt();
}
history: string[] = [];
private async startPrompt() {
readline.emitKeypressEvents(this.input);
this.rl = readline.createInterface({
input: this.input,
output: this.output,
history: this.history
});
this.rl.addListener('SIGINT', () => {
this.log();
});
this.rl.setPrompt(this._prompt);
this.rl.addListener('history', async lines => this.history = lines);
this.rl.addListener('line', async line => {
this.rl.close();
this.rl = null;
this.runningCommand = true;
this.output.cork();
this.output.moveCursor(0, -1);
this.deletePrompt();
this.output.uncork();
try {
await this.runCommand(line);
} finally {
this.runningCommand = false;
this.output.cork();
this.startPrompt();
this.output.uncork();
}
});
await this.beforeShowingPrompt?.();
this.allocatePromptSpace();
this.rl.prompt();
}
private allocatePromptSpace() {
let lines = this._prompt.split("\n").length + 1;
this.output.write(Array(lines + 1).join("\n"));
this.output.moveCursor(0, -lines);
}
private deletePrompt() {
for (let i = 0, max = this.prompt.split("\n").length; i < max; ++i) {
this.output.clearLine(0);
this.output.cursorTo(0);
if (i + 1 < max)
this.output.moveCursor(0, -1);
}
}
async log(...contents: (string | number | StyledString)[]) {
let message = styled(...<any[]>contents);
let actualCursorPos = this.rl?.getCursorPos() ?? { rows: 0, cols: 0 };
this.output.cork();
if (this.rl)
this.deletePrompt();
this.output.write(message + `\n`);
if (this.rl) {
this.allocatePromptSpace();
this.output.write(this.prompt + this.rl.line);
this.output.cursorTo(actualCursorPos.cols);
}
this.output.uncork();
}
}
+1
-0
export * from './style';
export * from './read';
export * from './terminal-ui';

@@ -19,2 +19,3 @@ "use strict";

__exportStar(require("./read"), exports);
__exportStar(require("./terminal-ui"), exports);
//# sourceMappingURL=index.js.map
+1
-1

@@ -1,1 +0,1 @@

{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,yCAAuB"}
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,yCAAuB;AACvB,gDAA8B"}
{
"name": "@alterior/terminal",
"version": "3.1.11",
"version": "3.1.12",
"main": "dist/index.js",

@@ -30,3 +30,3 @@ "types": "dist/index.d.ts",

},
"gitHead": "541793b14f2b48a840c27243f2b71aa4f4f148dd"
"gitHead": "b2faab5729a63f356c37b6bab5a6eacb1a1180ef"
}
export * from './style';
export * from './read';
export * from './read';
export * from './terminal-ui';