mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: remove terminal-kit
This commit is contained in:
1 parent
f4c415acb3
commit
4c37aedfff
3 files changed
+38
-79
No files matched your search
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/hydrojudge",
|
"name": "@hydrooj/hydrojudge",
|
||||||
"bin": "bin/hydrojudge.js",
|
"bin": "bin/hydrojudge.js",
|
||||||
"version": "2.4.5",
|
"version": "2.4.6",
|
||||||
"os": [
|
"os": [
|
||||||
"linux"
|
"linux"
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "2.19.4",
|
"version": "2.19.5",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "dist/loader.js",
|
"main": "dist/loader.js",
|
||||||
"typings": "dist/loader.d.ts",
|
"typings": "dist/loader.d.ts",
|
||||||
@@ -16,6 +16,7 @@
|
|||||||
"cookies": "^0.8.0",
|
"cookies": "^0.8.0",
|
||||||
"detect-browser": "^5.1.1",
|
"detect-browser": "^5.1.1",
|
||||||
"fs-extra": "^9.1.0",
|
"fs-extra": "^9.1.0",
|
||||||
|
"inquirer": "^8.0.0",
|
||||||
"js-yaml": "^4.0.0",
|
"js-yaml": "^4.0.0",
|
||||||
"koa": "^2.13.1",
|
"koa": "^2.13.1",
|
||||||
"koa-body": "^4.2.0",
|
"koa-body": "^4.2.0",
|
||||||
@@ -33,13 +34,13 @@
|
|||||||
"sockjs": "^0.3.20",
|
"sockjs": "^0.3.20",
|
||||||
"superagent": "^6.1.0",
|
"superagent": "^6.1.0",
|
||||||
"systeminformation": "5.3.3",
|
"systeminformation": "5.3.3",
|
||||||
"terminal-kit": "^1.47.0",
|
|
||||||
"wtfnode": "^0.8.4",
|
"wtfnode": "^0.8.4",
|
||||||
"yargs": "^16.2.0"
|
"yargs": "^16.2.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/adm-zip": "^0.4.33",
|
"@types/adm-zip": "^0.4.33",
|
||||||
"@types/fs-extra": "^9.0.7",
|
"@types/fs-extra": "^9.0.7",
|
||||||
|
"@types/inquirer": "^7.3.1",
|
||||||
"@types/js-yaml": "^4.0.0",
|
"@types/js-yaml": "^4.0.0",
|
||||||
"@types/koa": "^2.13.0",
|
"@types/koa": "^2.13.0",
|
||||||
"@types/koa-router": "^7.4.1",
|
"@types/koa-router": "^7.4.1",
|
||||||
@@ -52,7 +53,6 @@
|
|||||||
"@types/serialize-javascript": "^5.0.0",
|
"@types/serialize-javascript": "^5.0.0",
|
||||||
"@types/sockjs": "^0.3.32",
|
"@types/sockjs": "^0.3.32",
|
||||||
"@types/superagent": "^4.1.8",
|
"@types/superagent": "^4.1.8",
|
||||||
"@types/terminal-kit": "^1.28.2",
|
|
||||||
"@types/wtfnode": "^0.7.0",
|
"@types/wtfnode": "^0.7.0",
|
||||||
"@types/yargs": "^16.0.0",
|
"@types/yargs": "^16.0.0",
|
||||||
"formidable": "^1.2.2"
|
"formidable": "^1.2.2"
|
||||||
|
|||||||
+34
-75
@@ -1,22 +1,11 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-shadow */
|
/* eslint-disable @typescript-eslint/no-shadow */
|
||||||
// @ts-nocheck
|
|
||||||
import cluster from 'cluster';
|
import cluster from 'cluster';
|
||||||
import {
|
|
||||||
terminal, TextBox, LabeledInput,
|
|
||||||
} from 'terminal-kit';
|
|
||||||
import { ProgressBarOptions } from 'terminal-kit/Terminal';
|
|
||||||
import { argv } from 'yargs';
|
import { argv } from 'yargs';
|
||||||
|
import BottomBar from 'inquirer/lib/ui/bottom-bar';
|
||||||
import { Logger } from './logger';
|
import { Logger } from './logger';
|
||||||
import * as bus from './service/bus';
|
import * as bus from './service/bus';
|
||||||
|
|
||||||
const logger = new Logger('ui');
|
const logger = new Logger('ui');
|
||||||
|
|
||||||
declare module 'terminal-kit/Terminal' {
|
|
||||||
interface ProgressBarOptions {
|
|
||||||
y?: number;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const useTerminal = cluster.isMaster && process.stdout.isTTY && !argv.legacy && !argv._.length;
|
const useTerminal = cluster.isMaster && process.stdout.isTTY && !argv.legacy && !argv._.length;
|
||||||
|
|
||||||
export namespace Progress {
|
export namespace Progress {
|
||||||
@@ -38,11 +27,8 @@ export namespace Progress {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function create(args: ProgressBarOptions) {
|
export function create(args) {
|
||||||
// TODO handle worker process
|
return new Progress(args);
|
||||||
return useTerminal
|
|
||||||
? terminal.progressBar(args)
|
|
||||||
: new Progress(args);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,71 +39,44 @@ async function terminate() {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
hasError = true;
|
hasError = true;
|
||||||
}
|
}
|
||||||
if (useTerminal) {
|
|
||||||
terminal.styleReset();
|
|
||||||
terminal.resetScrollingRegion();
|
|
||||||
terminal.moveTo(terminal.width, terminal.height);
|
|
||||||
terminal('\n');
|
|
||||||
}
|
|
||||||
process.exit(hasError ? 1 : 0);
|
process.exit(hasError ? 1 : 0);
|
||||||
}
|
}
|
||||||
process.on('SIGINT', terminate);
|
process.on('SIGINT', terminate);
|
||||||
|
|
||||||
if (useTerminal) {
|
if (useTerminal) {
|
||||||
terminal.clear();
|
let current = 0;
|
||||||
terminal.grabInput();
|
const history = [''];
|
||||||
// Clipboard doesn't work well over ssh env, it throws an error.
|
let input = '';
|
||||||
terminal.getClipboard = () => { };
|
const ui = new BottomBar({ bottomBar: '>' });
|
||||||
terminal.setClipboard = () => { };
|
process.stdin.on('data', (data) => {
|
||||||
const document = terminal.createDocument({});
|
// Control Seq?
|
||||||
const LogBox = new TextBox({
|
const seq = data.toString('hex');
|
||||||
parent: document,
|
logger.info(data.toString('hex'));
|
||||||
contentHasMarkup: true,
|
if (seq === '7f') input = input.substr(0, input.length - 1);
|
||||||
scrollable: true,
|
else if (seq === '1b5b41') {
|
||||||
vScrollBar: true,
|
// Arrow up
|
||||||
lineWrap: true,
|
current--;
|
||||||
x: 0,
|
input = history[current];
|
||||||
y: 0,
|
} else if (seq === '1b5b42') {
|
||||||
width: terminal.width,
|
// Arrow down
|
||||||
height: terminal.height - 1,
|
current++;
|
||||||
});
|
input = history[current];
|
||||||
const ShellInput = new LabeledInput({
|
} else if (seq === '0d') {
|
||||||
parent: document,
|
// Enter
|
||||||
label: '>',
|
history.push(input);
|
||||||
x: 1,
|
current = history.length;
|
||||||
y: terminal.height - 1,
|
if (input[0] === '@') {
|
||||||
width: terminal.width,
|
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) => {
|
bus.on('message/log', (message) => {
|
||||||
LogBox.appendLog(message);
|
ui.log.write(message);
|
||||||
});
|
|
||||||
const history = [''];
|
|
||||||
let current = 0;
|
|
||||||
ShellInput.on('submit', async (input: string) => {
|
|
||||||
history.push(input);
|
|
||||||
current = history.length;
|
|
||||||
ShellInput.input.setContent(' '.repeat(terminal.width), false, false);
|
|
||||||
ShellInput.input.setContent('', false, false);
|
|
||||||
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);
|
|
||||||
});
|
|
||||||
ShellInput.on('key', (key) => {
|
|
||||||
if (key === 'UP') {
|
|
||||||
current--;
|
|
||||||
ShellInput.input.setContent(' '.repeat(terminal.width), false, false);
|
|
||||||
ShellInput.input.setContent(history[current] || '', false, false);
|
|
||||||
} else if (key === 'DOWN') {
|
|
||||||
current++;
|
|
||||||
ShellInput.input.setContent(' '.repeat(terminal.width), false, false);
|
|
||||||
ShellInput.input.setContent(history[current] || '', false, false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
terminal.on('key', (key) => {
|
|
||||||
if (key === 'CTRL_C') terminate();
|
|
||||||
});
|
});
|
||||||
if (process.env.SSH_CLIENT || process.env.SSH_TTY || process.env.SSH_CONNECTION) {
|
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.');
|
logger.warn('Running over ssh detected. Add a --legacy when starting if GUI mode doesn\'t work properly.');
|
||||||
|
|||||||
Reference in new issue
Block a user