mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
fix some bugs, bump ver(2.15.0), update install
This commit is contained in:
1 parent
4d031eb9ab
commit
bd8ff05387
29 files changed
+226
-162
No files matched your search
@@ -5,6 +5,36 @@ import {
|
||||
} from 'terminal-kit';
|
||||
import * as bus from './service/bus';
|
||||
|
||||
declare module 'terminal-kit/Terminal' {
|
||||
interface ProgressBarOptions {
|
||||
y?: number;
|
||||
}
|
||||
}
|
||||
|
||||
export namespace Progress {
|
||||
export class Progress {
|
||||
constructor(public args) {
|
||||
console.log('progress start: ', args);
|
||||
}
|
||||
|
||||
startItem(args) {
|
||||
console.log('progress: ', this.args, args);
|
||||
}
|
||||
|
||||
itemDone(args) {
|
||||
console.log('done: ', this.args, args);
|
||||
}
|
||||
|
||||
stop: () => {}
|
||||
}
|
||||
|
||||
export function create(args) {
|
||||
return process.stdout.isTTY
|
||||
? terminal.progressBar(args)
|
||||
: new Progress(args);
|
||||
}
|
||||
}
|
||||
|
||||
async function terminate() {
|
||||
let hasError = false;
|
||||
try {
|
||||
@@ -12,7 +42,7 @@ async function terminate() {
|
||||
} catch (e) {
|
||||
hasError = true;
|
||||
}
|
||||
if (cluster.isMaster) {
|
||||
if (cluster.isMaster && process.stdout.isTTY) {
|
||||
terminal.hideCursor(false);
|
||||
terminal.styleReset();
|
||||
terminal.resetScrollingRegion();
|
||||
@@ -22,7 +52,8 @@ async function terminate() {
|
||||
process.exit(hasError ? 1 : 0);
|
||||
}
|
||||
process.on('SIGINT', terminate);
|
||||
if (cluster.isMaster) {
|
||||
|
||||
if (cluster.isMaster && process.stdout.isTTY) {
|
||||
terminal.clear();
|
||||
terminal.grabInput();
|
||||
terminal.hideCursor();
|
||||
@@ -76,7 +107,22 @@ if (cluster.isMaster) {
|
||||
ShellInput.input.setContent(history[current] || '', false, false);
|
||||
}
|
||||
});
|
||||
terminal.on('key', (key, matches, data) => {
|
||||
terminal.on('key', (key) => {
|
||||
if (key === 'CTRL_C') terminate();
|
||||
});
|
||||
} else if (cluster.isMaster) {
|
||||
console.log('Not running in a terminal environment. Interactive mode disabled.');
|
||||
bus.on('message/log', (message) => {
|
||||
process.stdout.write(`${message}\n`);
|
||||
});
|
||||
process.stdin.setEncoding('utf-8');
|
||||
process.stdin.on('data', (buf) => {
|
||||
const input = buf.toString();
|
||||
if (input[0] === '@') {
|
||||
for (const i in cluster.workers) {
|
||||
cluster.workers[i].send({ event: 'message/run', payload: [input.substr(1, input.length - 1)] });
|
||||
break;
|
||||
}
|
||||
} else bus.parallel('message/run', input);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user