mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: add task manager
This commit is contained in:
1 parent
e5b1304bd9
commit
2b4b7de28d
6 files changed
+152
-171
No files matched your search
@@ -1,12 +1,8 @@
|
||||
/* eslint-disable @typescript-eslint/no-shadow */
|
||||
import cluster from 'cluster';
|
||||
import { argv } from 'yargs';
|
||||
import BottomBar from 'inquirer/lib/ui/bottom-bar';
|
||||
import { Logger } from './logger';
|
||||
import * as bus from './service/bus';
|
||||
|
||||
const logger = new Logger('ui');
|
||||
const useTerminal = cluster.isMaster && process.stdout.isTTY;
|
||||
const disabledTerminal = argv.legacy || argv._.length || process.env.NODE_ENV === 'test';
|
||||
|
||||
export namespace Progress {
|
||||
@@ -43,45 +39,7 @@ async function terminate() {
|
||||
process.exit(hasError ? 1 : 0);
|
||||
}
|
||||
process.on('SIGINT', terminate);
|
||||
|
||||
if (useTerminal && !disabledTerminal) {
|
||||
let current = 0;
|
||||
const history = [''];
|
||||
let input = '';
|
||||
const ui = new BottomBar({ bottomBar: '>' });
|
||||
process.stdin.on('data', (data) => {
|
||||
// Control Seq?
|
||||
const seq = data.toString('hex');
|
||||
if (seq === '7f') input = input.substr(0, input.length - 1);
|
||||
else if (seq === '1b5b41') {
|
||||
// Arrow up
|
||||
current--;
|
||||
input = history[current];
|
||||
} else if (seq === '1b5b42') {
|
||||
// Arrow down
|
||||
current++;
|
||||
input = history[current];
|
||||
} else if (seq === '0d') {
|
||||
// Enter
|
||||
history.push(input);
|
||||
current = history.length;
|
||||
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);
|
||||
input = '';
|
||||
} else input += data.toString();
|
||||
ui.updateBottomBar(`>${input}`);
|
||||
});
|
||||
bus.on('message/log', (message) => {
|
||||
ui.log.write(message);
|
||||
});
|
||||
if (process.env.SSH_CLIENT || process.env.SSH_TTY || process.env.SSH_CONNECTION) {
|
||||
logger.warn('Running over ssh detected. Add a --legacy when starting if GUI mode doesn\'t work properly.');
|
||||
}
|
||||
} else if (cluster.isMaster) {
|
||||
if (cluster.isMaster) {
|
||||
if (!disabledTerminal) console.log('Not running in a terminal environment. Interactive mode disabled.');
|
||||
bus.on('message/log', (message) => {
|
||||
process.stdout.write(`${message}\n`);
|
||||
|
||||
Reference in new issue
Block a user