本文整理汇总了TypeScript中tty.isatty函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isatty函数的具体用法?TypeScript isatty怎么用?TypeScript isatty使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isatty函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: show
export default function show(this:CmdLineConfig, envName) {
envName = envName || getCurrentDefault();
if (!envName) {
throw new MyError('no default config. use "jenv --env" to set it. or specify a config name.');
}
const config = readEnvSync(envName);
if (isatty(process.stdout.fd)) {
console.log(require('util').inspect(config, {colors: true, depth: 999}));
} else {
console.log(JSON.stringify(config, null, 4));
}
}
开发者ID:GongT,项目名称:jenv,代码行数:13,代码来源:show.ts
示例2: CancellationToken
function main<T>(task: Promise<any>): void {
let latestVersion: string = null;
const token = new CancellationToken();
if (isatty(1)) {
getLatestVersion(pkg.name, token)
.then(version => latestVersion = version)
.catch(err => !isCancelledError(err) && console.error(err));
}
task
.catch(fatal)
.then(() => {
if (latestVersion && semver.gt(latestVersion, pkg.version)) {
console.log(`\nThe latest version of ${ pkg.name } is ${ latestVersion } and you have ${ pkg.version }.\nUpdate it now: npm install -g ${ pkg.name }`);
} else {
token.cancel();
}
});
}
开发者ID:rlugojr,项目名称:vscode-vsce,代码行数:21,代码来源:main.ts
示例3: Buffer
////////////////////////////////////////////////////
/// TTY tests : http://nodejs.org/api/tty.html
////////////////////////////////////////////////////
namespace tty_tests {
let rs: tty.ReadStream;
let ws: tty.WriteStream;
let rsIsRaw: boolean = rs.isRaw;
rs.setRawMode(true);
let wsColumns: number = ws.columns;
let wsRows: number = ws.rows;
let isTTY: boolean = tty.isatty(1);
}
////////////////////////////////////////////////////
/// Dgram tests : http://nodejs.org/api/dgram.html
////////////////////////////////////////////////////
namespace dgram_tests {
var ds: dgram.Socket = dgram.createSocket("udp4", (msg: Buffer, rinfo: dgram.RemoteInfo): void => {
});
var ai: dgram.AddressInfo = ds.address();
ds.send(new Buffer("hello"), 0, 5, 5000, "127.0.0.1", (error: Error, bytes: number): void => {
});
}
////////////////////////////////////////////////////
开发者ID:Crevil,项目名称:DefinitelyTyped,代码行数:30,代码来源:node-tests.ts
示例4: isatty
import {isatty} from "tty";
export const prettyPrint: boolean = isatty(1) && isatty(2);
开发者ID:GongT,项目名称:jenv,代码行数:3,代码来源:output.ts
示例5: cli
function cli() {
var inputs: string[] = [];
var outputJS: any = null;
var outputCPP: any = null;
var outputAsmJS: any = null;
var moduleName: any = null;
var helpFlag: boolean = false;
var watchFlag: boolean = false;
var fs: any = require('fs');
var tty: any = require('tty');
var path: any = require('path');
var notifier: any = require('terminal-notifier');
var useColors: boolean = tty.isatty(1) && tty.isatty(2);
function time(): string {
var now: Date = new Date();
if (!watchFlag) return '';
return ((now.getHours() % 12 + 11) % 12 + 1) + ':' +
(100 + now.getMinutes()).toString().slice(1) +
['am', 'pm'][now.getHours() / 12 | 0] +
' - ';
}
function indent(text: string): string {
return ' ' + text.replace(/\n/g, '\n ');
}
function wrapColor(color: number): (text: string) => string {
if (!useColors) return text => { return text; };
return text => { return '\u001b[' + color + 'm' + text + '\u001b[0m'; };
}
var gray: (text: string) => string = wrapColor(90);
var red: (text: string) => string = wrapColor(91);
var green: (text: string) => string = wrapColor(92);
function showNotification(diagnostic: Diagnostic) {
if (!watchFlag) return;
var options: any = {
title: diagnostic.range !== null ? diagnostic.range.source.name + ' on line ' + diagnostic.range.start.line : 'Build error',
group: 'bitscript'
};
if (diagnostic.range !== null && process.env.EDITOR) {
options.execute = process.env.EDITOR + ' "' + path.resolve(diagnostic.range.source.name) + ':' + diagnostic.range.start.line + '"';
}
notifier(diagnostic.text, options);
}
function compile() {
var compiler = new Compiler();
inputs.forEach(input => compiler.addSource(input, fs.readFileSync(input, 'utf8')));
compiler.compile();
// Output code on success
if (compiler.log.errorCount === 0) {
if (outputJS !== null) {
var root: string = path.relative(path.dirname(outputJS), '.');
var codeAndMap: { code: string; map: string } = OutputJS.generateWithSourceMap(compiler.module, root);
fs.writeFileSync(outputJS, codeAndMap.code + '\n/' + /* Break this up to make Chrome ignore it */ '/# sourceMappingURL=' + path.basename(outputJS) + '.map\n');
fs.writeFileSync(outputJS + '.map', codeAndMap.map + '\n');
}
if (outputCPP !== null) fs.writeFileSync(outputCPP, OutputCPP.generate(compiler.module) + '\n');
if (outputAsmJS !== null) fs.writeFileSync(outputAsmJS, OutputAsmJS.generate(compiler.module, moduleName) + '\n');
console.log(gray(time() + 'build successful'));
return true;
}
// Remove files on failure
if (outputJS !== null && fs.existsSync(outputJS)) {
fs.unlinkSync(outputJS);
fs.unlinkSync(outputJS + '.map');
}
if (outputCPP !== null && fs.existsSync(outputCPP)) fs.unlinkSync(outputCPP);
if (outputAsmJS !== null && fs.existsSync(outputAsmJS)) fs.unlinkSync(outputAsmJS);
if (watchFlag) showNotification(compiler.log.diagnostics[0]);
// Use fancy colored output for TTYs
console.log(gray(time() + 'build failed\n\n') + indent(compiler.log.diagnostics.map(d => {
var parts = d.range.sourceString().split('\n');
return gray(d.type + ' on line ' + d.range.start.line + ' of ' + d.range.source.name + ': ') + red(d.text) + '\n\n' + parts[0] + '\n' + green(parts[1]) + '\n';
}).join('\n')));
return false;
}
// Return a unique string that will change when one of the files changes
function stat(): string {
return inputs.map(input => input + fs.statSync(input).mtime).join('\n');
}
function usage() {
console.log([
'',
'usage: bitc in1.bit in2.bit ... [--js out.js] [--cpp out.cpp] [--asmjs out.js] [--name moduleName] [--watch]',
'',
].join('\n'));
}
// Parse command-line flags
var args = process.argv.slice(2);
//.........这里部分代码省略.........
开发者ID:evanw,项目名称:bitscript,代码行数:101,代码来源:cli.ts
注:本文中的tty.isatty函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论