readline#createInterface TypeScript Examples
The following examples show how to use
readline#createInterface.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: utils.ts From pdf-visual-diff with MIT License | 7 votes |
askForConfirmation = (question: string): Promise<boolean> => {
const readline = createInterface({ input: process.stdin, output: process.stdout })
return new Promise((res) => {
readline.question(question + ' [Y/n]: ', (answer) => {
readline.close()
const cleaned = answer.trim().toLocaleLowerCase()
if (cleaned === '' || ['yes', 'y'].indexOf(cleaned) >= 0) {
res(true)
} else if (['no', 'n'].indexOf(cleaned) >= 0) {
res(false)
} else {
process.stdout.write('\nInvalid Response. Please answer with yes(y) or no(n)\n\n')
askForConfirmation(question).then(res)
}
})
})
}
Example #2
Source File: sigintWin32.ts From Assistive-Webdriver with MIT License | 6 votes |
sigintWin32 = (): void => {
if (process.platform === "win32") {
const readline = createInterface({
input: process.stdin,
output: process.stdout
});
readline.on("SIGINT", function () {
process.emit("SIGINT" as any);
});
}
}
Example #3
Source File: index.ts From mtcute with GNU Lesser General Public License v3.0 | 6 votes |
/**
* Tiny wrapper over Node `readline` package
* for simpler user input for `.run()` method.
*
* Associated `readline` interface is closed
* after `run()` returns, or with the client.
*
*
* @param text Text of the question
*/
input(text: string): Promise<string> {
if (!this._rl) {
this._rl = createInterface({
input: process.stdin,
output: process.stdout,
})
}
return new Promise((res) => this._rl!.question(text, res))
}
Example #4
Source File: shared.ts From s-libs with MIT License | 6 votes |
export async function getInput(text: string): Promise<string> {
return new Promise<string>((resolve) => {
const reader = createInterface(process.stdin, process.stdout);
reader.question(text, (answer) => {
resolve(answer);
reader.close();
});
});
}
Example #5
Source File: index.ts From vt-api with GNU Affero General Public License v3.0 | 5 votes |
export function channelManager() {
console.clear();
console.log(
'---------------------------- Manage Channels ----------------------------\n' +
' Make sure you\'ve set up the .json files in channels/organizations directory.\n' +
' Check templates.json to see how to make custom channels, or move the files\n' +
' from the default directory to the organizations directory.\n' +
'-----------------------------------------------------------------------------\n' +
' [1] Initialize (Run Everything)\n' +
' [2] Validate JSON Files\n' +
' [3] Save + Update\n' +
' [4] Save Channels\n' +
' [5] Update Channels\n' +
' [6] Scrape Channels\n' +
' [7] Drop Members and Channels Collection\n' +
' [8] Drop vt-api Database\n' +
' [9] Exit\n'
);
const rl = createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('Selection: ', async input => {
process.env.DEBUG = process.env.DEBUG.slice(0, -6);
rl.close();
switch (input) {
default:
return channelManager();
case '1':
await init();
break;
case '2':
validateChannels();
break;
case '3':
case '4':
await Promise.all(saveChannels({}, true));
if (input === '4') break;
case '5':
await updateChannels();
break;
case '6':
await scrapeChannels();
break;
case '7':
await dropCollections();
break;
case '8':
await dropDatabase();
break;
case '9': process.exit();
}
delayEnd();
});
}
Example #6
Source File: map.process.ts From diablo2 with MIT License | 5 votes |
/** Start the map process waiting for the `init` event before allowing anything to continue */
async start(log: LogType): Promise<void> {
if (this.isRunning) return;
this.generatedCount = 0;
const args = [this.mapCommand, Diablo2Path];
log.info({ proc: this.id, wineArgs: args }, 'MapProcess:Starting');
return new Promise(async (resolve) => {
const proc = spawn(WineCommand, args, { cwd, env: { WINEPREFIX: process.env['WINEPREFIX'], WINEDEBUG: '-all' } });
if (proc == null || proc.stdout == null) throw new Error('Failed to start command');
this.process = proc;
proc.stderr.on('data', (data) => {
const line = data.toString().trim();
if (line.includes('FS volume label and serial are not available')) return;
Log.debug({ proc: this.id, data: line }, 'MapProcess:stderr');
if (line.includes('We got a big Error here')) this.stop(log);
});
proc.on('error', (error) => {
log.fatal({ proc: this.id, error }, 'MapProcess:Died');
inter.close();
this.process = null;
});
proc.on('close', (exitCode) => {
inter.close();
this.process = null;
this.events.emit('close');
if (exitCode == null) return;
if (exitCode > 0) log.fatal({ proc: this.id, exitCode }, 'MapProcess:Closed');
});
log.info({ proc: this.id, processId: this.process.pid }, 'MapProcess:Started');
const inter = createInterface(proc.stdout).on('line', (line): unknown => {
const json = getJson<Diablo2MapGenMessage | LogMessage>(line);
if (json == null) return;
if (isLogMessage(json)) return this.events.emit('log', json);
if (json.type) return this.events.emit(json.type, json);
return;
});
await this.once('init');
resolve();
});
}
Example #7
Source File: index.ts From react-js-tutorial with MIT License | 5 votes |
rl = createInterface({ input: process.stdin, output: process.stdout, })
Example #8
Source File: terminal-io.ts From protobuf-ts with Apache License 2.0 | 5 votes |
private readonly rli = createInterface(process.stdin, process.stdout);
Example #9
Source File: get-changed-file.ts From action-php-codesniffer with MIT License | 5 votes |
export async function getChangedFiles(): Promise<ChangedFiles> {
const pattern = core.getInput('files', {
required: false,
});
const globs = pattern.length ? pattern.split(',') : ['**.php'];
const isMatch = picomatch(globs);
console.log('Filter patterns:', globs, isMatch('src/test.php'));
const payload = github.context.payload as Webhooks.WebhookPayloadPullRequest;
/*
getting them from Git
git diff-tree --no-commit-id --name-status --diff-filter=d -r ${{ github.event.pull_request.base.sha }}..${{ github.event.after }}
*/
try {
const git = spawn(
'git',
[
'--no-pager',
'diff-tree',
'--no-commit-id',
'--name-status',
'--diff-filter=d', // we don't need deleted files
'-r',
`${payload.pull_request.base.sha}..`,
],
{
windowsHide: true,
timeout: 5000,
}
);
const readline = createInterface({
input: git.stdout,
});
const result: ChangedFiles = {
added: [],
modified: [],
};
for await (const line of readline) {
const parsed = /^(?<status>[ACMR])[\s\t]+(?<file>\S+)$/.exec(line);
if (parsed?.groups) {
const { status, file } = parsed.groups;
// ensure file exists
if (isMatch(file) && existsSync(file)) {
switch (status) {
case 'A':
case 'C':
case 'R':
result.added.push(file);
break;
case 'M':
result.modified.push(file);
}
}
}
}
return result;
} catch (err) {
console.error(err);
return {
added: [],
modified: [],
};
}
}