Merge pull request #17 from RimuruChan/terminal-improve

Terminal improve
This commit is contained in:
Suwings 2022-02-08 22:00:06 +08:00 committed by GitHub
commit acaee9b7f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 146 additions and 122 deletions

View File

@ -33,6 +33,7 @@ import "../assets/css/common.css";
import "../assets/css/tools.css";
import "../assets/css/responsive.css";
import "../assets/css/action.css";
import "../assets/css/fonts.css";
import App from "./App.vue";
import "./service/protocol";

View File

@ -22,16 +22,32 @@
import { Terminal } from "xterm";
import { FitAddon } from "xterm-addon-fit";
export const TERM_TEXT_RED = "\x1B[31m";
export const TERM_TEXT_GREEN = "\x1B[32m";
export const TERM_TEXT_YELLOW = "\x1B[33m";
export const TERM_TEXT_BLUE = "\x1B[34m";
export const TERM_TEXT_FUCHSIA = "\x1B[35m";
export const TERM_TEXT_CYAN = "\x1B[36m";
export const TERM_TEXT_WHITE = "\x1B[37m";
export const TERM_TEXT_B = "\x1B[1m";
export const termColor = {};
termColor.TERM_RESET = "\x1B[0m";
termColor.TERM_TEXT_BLACK = "\x1B[0;30m"; // Black §0
termColor.TERM_TEXT_DARK_BLUE = "\x1B[0;34m"; // Dark Blue §1
termColor.TERM_TEXT_DARK_GREEN = "\x1B[0;32m"; // Dark Green §2
termColor.TERM_TEXT_DARK_AQUA = "\x1B[0;36m"; // Dark Aqua §3
termColor.TERM_TEXT_DARK_RED = "\x1B[0;31m"; // Dark Red §4
termColor.TERM_TEXT_DARK_PURPLE = "\x1B[0;35m"; // Dark Purple §5
termColor.TERM_TEXT_GOLD = "\x1B[0;33m"; // Gold §6
termColor.TERM_TEXT_GRAY = "\x1B[0;37m"; // Gray §7
termColor.TERM_TEXT_DARK_GRAY = "\x1B[0;30;1m"; // Dark Gray §8
termColor.TERM_TEXT_BLUE = "\x1B[0;34;1m"; // Blue §9
termColor.TERM_TEXT_GREEN = "\x1B[0;32;1m"; // Green §a
termColor.TERM_TEXT_AQUA = "\x1B[0;36;1m"; // Aqua §b
termColor.TERM_TEXT_RED = "\x1B[0;31;1m"; // Red §c
termColor.TERM_TEXT_LIGHT_PURPLE = "\x1B[0;35;1m"; // Light Purple §d
termColor.TERM_TEXT_YELLOW = "\x1B[0;33;1m"; // Yellow §e
termColor.TERM_TEXT_WHITE = "\x1B[0;37;1m"; // White §f
termColor.TERM_TEXT_OBFUSCATED = "\x1B[5m"; // Obfuscated §k
termColor.TERM_TEXT_BOLD = "\x1B[21m"; // Bold §l
termColor.TERM_TEXT_STRIKETHROUGH = "\x1B[9m"; // Strikethrough §m
termColor.TERM_TEXT_UNDERLINE = "\x1B[4m"; // Underline §n
termColor.TERM_TEXT_ITALIC = "\x1B[3m"; // Italic §o
termColor.TERM_TEXT_B = "\x1B[1m";
export function initTerminalWindow(elem, fontSize = 13) {
export function initTerminalWindow(elem, fontSize = 14) {
const term = new Terminal({
rendererType: "canvas",
convertEol: true,
@ -39,6 +55,7 @@ export function initTerminalWindow(elem, fontSize = 13) {
cursorStyle: "underline",
cursorBlink: true,
fontSize: fontSize,
fontFamily: "'Fira Code', monospace",
theme: {
background: "#1e1e1e"
}
@ -53,46 +70,43 @@ export function initTerminalWindow(elem, fontSize = 13) {
fitAddon.fit();
}, 3000);
term.writeln(`${TERM_TEXT_YELLOW}MCSManager Terminal ${TERM_TEXT_CYAN}[Powered by Term.js]`);
term.writeln(`${TERM_TEXT_YELLOW}Copyright Suwings All rights reserved${TERM_TEXT_WHITE}`);
term.writeln(`${termColor.TERM_TEXT_GOLD}MCSManager Terminal ${termColor.TERM_TEXT_DARK_AQUA}[Powered by Term.js]`);
term.writeln(`${termColor.TERM_TEXT_GOLD}Copyright Suwings All rights reserved${termColor.TERM_RESET}\r\n`);
term.info = (msg) => {
term.writeln(`\r\n[MCSManager] [INFO] ${msg}`);
};
term.prompt = () => {
term.write(`${TERM_TEXT_WHITE}\r\n$`);
};
term.prompt();
// term.prompt = () => {
// term.write(`${termColor.TERM_RESET}\r\n$ `);
// };
//term.prompt();
return term;
}
export function textToTermText(data) {
let text = `${data}`;
text = text.replace(/§0/gim, TERM_TEXT_WHITE);
text = text.replace(/§1/gim, TERM_TEXT_BLUE);
text = text.replace(/§2/gim, TERM_TEXT_GREEN);
text = text.replace(/§3/gim, TERM_TEXT_BLUE);
text = text.replace(/§4/gim, TERM_TEXT_RED);
text = text.replace(/§5/gim, TERM_TEXT_FUCHSIA);
text = text.replace(/§6/gim, TERM_TEXT_YELLOW);
text = text.replace(/§7/gim, TERM_TEXT_WHITE);
text = text.replace(/§8/gim, TERM_TEXT_WHITE);
text = text.replace(/§9/gim, TERM_TEXT_BLUE);
text = text.replace(/§a/gim, TERM_TEXT_GREEN);
text = text.replace(/§b/gim, TERM_TEXT_GREEN);
text = text.replace(/§c/gim, TERM_TEXT_RED);
text = text.replace(/§d/gim, TERM_TEXT_CYAN);
text = text.replace(/§e/gim, TERM_TEXT_YELLOW);
text = text.replace(/§f/gim, TERM_TEXT_WHITE);
text = text.replace(/§g/gim, TERM_TEXT_YELLOW);
text = text.replace(/§k/gim, TERM_TEXT_WHITE);
text = text.replace(/§i/gim, TERM_TEXT_B);
text = text.replace(/§l/gim, TERM_TEXT_B);
text = text.replace(/§m/gim, TERM_TEXT_WHITE);
text = text.replace(/§n/gim, TERM_TEXT_WHITE);
text = text.replace(/§o/gim, TERM_TEXT_WHITE);
text = text.replace(/§r/gim, TERM_TEXT_WHITE);
text = text.replace(/\r\n/gim, `\n`);
text = text.replace(/\r/gim, `\n`);
text = text.replace(/\n/gim, `${TERM_TEXT_WHITE}\n`);
text = text.replace(/§0/gim, termColor.TERM_TEXT_BLACK);
text = text.replace(/§1/gim, termColor.TERM_TEXT_DARK_BLUE);
text = text.replace(/§2/gim, termColor.TERM_TEXT_DARK_GREEN);
text = text.replace(/§3/gim, termColor.TERM_TEXT_DARK_AQUA);
text = text.replace(/§4/gim, termColor.TERM_TEXT_DARK_RED);
text = text.replace(/§5/gim, termColor.TERM_TEXT_DARK_PURPLE);
text = text.replace(/§6/gim, termColor.TERM_TEXT_GOLD);
text = text.replace(/§7/gim, termColor.TERM_TEXT_GRAY);
text = text.replace(/§8/gim, termColor.TERM_TEXT_DARK_GRAY);
text = text.replace(/§9/gim, termColor.TERM_TEXT_BLUE);
text = text.replace(/§a/gim, termColor.TERM_TEXT_GREEN);
text = text.replace(/§b/gim, termColor.TERM_TEXT_AQUA);
text = text.replace(/§c/gim, termColor.TERM_TEXT_RED);
text = text.replace(/§d/gim, termColor.TERM_TEXT_LIGHT_PURPLE);
text = text.replace(/§e/gim, termColor.TERM_TEXT_YELLOW);
text = text.replace(/§f/gim, termColor.TERM_TEXT_WHITE);
text = text.replace(/§k/gim, termColor.TERM_TEXT_OBFUSCATED);
text = text.replace(/§l/gim, termColor.TERM_TEXT_BOLD);
text = text.replace(/§m/gim, termColor.TERM_TEXT_STRIKETHROUGH);
text = text.replace(/§n/gim, termColor.TERM_TEXT_UNDERLINE);
text = text.replace(/§o/gim, termColor.TERM_TEXT_ITALIC);
text = text.replace(/§r/gim, termColor.TERM_RESET);
// 行结尾符号替换
text = text.replace(/\r\n/gm, termColor.TERM_RESET + "\r\n");
return text;
}

View File

@ -19,75 +19,71 @@
可以前往 https://mcsmanager.com/ 阅读用户协议,申请闭源开发授权等。
*/
import { termColor } from "./term";
// 用于 Terminal 视图中终端组件的文字颜色渲染
export function encodeConsoleColor(text) {
const term = {};
term.TERM_NULL = "\x1B[0m";
term.TERM_TEXT_RED = "\x1B[1;0;31m";
term.TERM_TEXT_GREEN = "\x1B[1;0;32m";
term.TERM_TEXT_YELLOW = "\x1B[1;0;33m";
term.TERM_TEXT_BLUE = "\x1B[1;1;34m";
term.TERM_TEXT_FUCHSIA = "\x1B[1;0;35m";
term.TERM_TEXT_CYAN = "\x1B[1;0;36m";
term.TERM_TEXT_WHITE = "\x1B[1;0;37m";
term.TERM_TEXT_B = "\x1B[1m";
// 基本颜色
text = text.replace(/\[([^[\]]+)\]/gim, "[§1$1§r]");
text = text.replace(/([A-Za-z0-9 _§&;\-\\.]{1,}: )/gim, "§6$1§r");
// eslint-disable-next-line no-control-regex
text = text.replace(/(\x1B[^m]*m)/gm, "$1;");
text = text.replace(/ \[([A-Za-z0-9 _\-\\.]+)]/gim, " [§3$1§r]");
text = text.replace(/^\[([A-Za-z0-9 _\-\\.]+)]/gim, "[§3$1§r]");
text = text.replace(/([A-Za-z0-9 _\-\\.]+: )/gim, "§6$1§r");
// eslint-disable-next-line no-control-regex
text = text.replace(/(\x1B[^m]*m);/gm, "$1");
// text = text.replace(/INFO/gm, term.TERM_TEXT_GREEN + "INFO" + term.TERM_NULL);
// text = text.replace(/(\d{2,}:\d{2,}:\d{2,})/gm, term.TERM_TEXT_CYAN + "$1" + term.TERM_NULL);
// Minecraft 原生颜色替代解析
text = text.replace(/§0/gm, term.TERM_TEXT_WHITE);
text = text.replace(/§1/gm, term.TERM_TEXT_CYAN);
text = text.replace(/§2/gm, term.TERM_TEXT_GREEN);
text = text.replace(/§3/gm, term.TERM_TEXT_CYAN);
text = text.replace(/§4/gm, term.TERM_TEXT_RED);
text = text.replace(/§5/gm, term.TERM_TEXT_FUCHSIA);
text = text.replace(/§6/gm, term.TERM_TEXT_YELLOW);
text = text.replace(/§7/gm, term.TERM_TEXT_WHITE);
text = text.replace(/§8/gm, term.TERM_TEXT_WHITE);
text = text.replace(/§9/gm, term.TERM_TEXT_CYAN);
text = text.replace(/§a/gm, term.TERM_TEXT_GREEN);
text = text.replace(/§b/gm, term.TERM_TEXT_CYAN);
text = text.replace(/§c/gm, term.TERM_TEXT_RED);
text = text.replace(/§d/gm, term.TERM_TEXT_RED);
text = text.replace(/§e/gm, term.TERM_TEXT_YELLOW);
text = text.replace(/§f/gm, term.TERM_TEXT_WHITE);
text = text.replace(/§0/gim, termColor.TERM_TEXT_BLACK);
text = text.replace(/§1/gim, termColor.TERM_TEXT_DARK_BLUE);
text = text.replace(/§2/gim, termColor.TERM_TEXT_DARK_GREEN);
text = text.replace(/§3/gim, termColor.TERM_TEXT_DARK_AQUA);
text = text.replace(/§4/gim, termColor.TERM_TEXT_DARK_RED);
text = text.replace(/§5/gim, termColor.TERM_TEXT_DARK_PURPLE);
text = text.replace(/§6/gim, termColor.TERM_TEXT_GOLD);
text = text.replace(/§7/gim, termColor.TERM_TEXT_GRAY);
text = text.replace(/§8/gim, termColor.TERM_TEXT_DARK_GRAY);
text = text.replace(/§9/gim, termColor.TERM_TEXT_BLUE);
text = text.replace(/§a/gim, termColor.TERM_TEXT_GREEN);
text = text.replace(/§b/gim, termColor.TERM_TEXT_AQUA);
text = text.replace(/§c/gim, termColor.TERM_TEXT_RED);
text = text.replace(/§d/gim, termColor.TERM_TEXT_LIGHT_PURPLE);
text = text.replace(/§e/gim, termColor.TERM_TEXT_YELLOW);
text = text.replace(/§f/gim, termColor.TERM_TEXT_WHITE);
text = text.replace(/§k/gim, termColor.TERM_TEXT_OBFUSCATED);
text = text.replace(/§l/gim, termColor.TERM_TEXT_BOLD);
text = text.replace(/§m/gim, termColor.TERM_TEXT_STRIKETHROUGH);
text = text.replace(/§n/gim, termColor.TERM_TEXT_UNDERLINE);
text = text.replace(/§o/gim, termColor.TERM_TEXT_ITALIC);
text = text.replace(/§r/gim, termColor.TERM_RESET);
// 基于&符号
text = text.replace(/&0/gm, term.TERM_TEXT_WHITE);
text = text.replace(/&1/gm, term.TERM_TEXT_CYAN);
text = text.replace(/&2/gm, term.TERM_TEXT_GREEN);
text = text.replace(/&3/gm, term.TERM_TEXT_CYAN);
text = text.replace(/&4/gm, term.TERM_TEXT_RED);
text = text.replace(/&5/gm, term.TERM_TEXT_FUCHSIA);
text = text.replace(/&6/gm, term.TERM_TEXT_YELLOW);
text = text.replace(/&7/gm, term.TERM_TEXT_WHITE);
text = text.replace(/&8/gm, term.TERM_TEXT_WHITE);
text = text.replace(/&9/gm, term.TERM_TEXT_CYAN);
text = text.replace(/&a/gm, term.TERM_TEXT_GREEN);
text = text.replace(/&b/gm, term.TERM_TEXT_CYAN);
text = text.replace(/&c/gm, term.TERM_TEXT_RED);
text = text.replace(/&d/gm, term.TERM_TEXT_RED);
text = text.replace(/&e/gm, term.TERM_TEXT_YELLOW);
text = text.replace(/&f/gm, term.TERM_TEXT_WHITE);
// 字体格式
text = text.replace(/§r/gm, term.TERM_NULL);
text = text.replace(/&r/gm, term.TERM_NULL);
text = text.replace(/§k/gm, "\x1B[1m");
text = text.replace(/&k/gm, "\x1B[1m");
text = text.replace(/§l/gm, "\x1B[1m");
text = text.replace(/&l/gm, "\x1B[1m");
text = text.replace(/§m/gm, "\x1B[2m");
text = text.replace(/&m/gm, "\x1B[2m");
text = text.replace(/§n/gm, "\x1B[4m");
text = text.replace(/&n/gm, "\x1B[4m");
text = text.replace(/§o/gm, "\x1B[3m");
text = text.replace(/&o/gm, "\x1B[3m");
text = text.replace(/&0/gim, termColor.TERM_TEXT_BLACK);
text = text.replace(/&1/gim, termColor.TERM_TEXT_DARK_BLUE);
text = text.replace(/&2/gim, termColor.TERM_TEXT_DARK_GREEN);
text = text.replace(/&3/gim, termColor.TERM_TEXT_DARK_AQUA);
text = text.replace(/&4/gim, termColor.TERM_TEXT_DARK_RED);
text = text.replace(/&5/gim, termColor.TERM_TEXT_DARK_PURPLE);
text = text.replace(/&6/gim, termColor.TERM_TEXT_GOLD);
text = text.replace(/&7/gim, termColor.TERM_TEXT_GRAY);
text = text.replace(/&8/gim, termColor.TERM_TEXT_DARK_GRAY);
text = text.replace(/&9/gim, termColor.TERM_TEXT_BLUE);
text = text.replace(/&a/gim, termColor.TERM_TEXT_GREEN);
text = text.replace(/&b/gim, termColor.TERM_TEXT_AQUA);
text = text.replace(/&c/gim, termColor.TERM_TEXT_RED);
text = text.replace(/&d/gim, termColor.TERM_TEXT_LIGHT_PURPLE);
text = text.replace(/&e/gim, termColor.TERM_TEXT_YELLOW);
text = text.replace(/&f/gim, termColor.TERM_TEXT_WHITE);
text = text.replace(/&k/gim, termColor.TERM_TEXT_OBFUSCATED);
text = text.replace(/&l/gim, termColor.TERM_TEXT_BOLD);
text = text.replace(/&m/gim, termColor.TERM_TEXT_STRIKETHROUGH);
text = text.replace(/&n/gim, termColor.TERM_TEXT_UNDERLINE);
text = text.replace(/&o/gim, termColor.TERM_TEXT_ITALIC);
text = text.replace(/&r/gim, termColor.TERM_RESET);
// 特殊文本替换
var RegExpStringArr = [
const RegExpStringArr = [
//蓝色
[
"Unknown command",
@ -101,6 +97,8 @@ export function encodeConsoleColor(text) {
],
//绿色
[
"INFO",
"EULA",
"/help",
"left the game",
"Enabling",
@ -120,35 +118,28 @@ export function encodeConsoleColor(text) {
"Preparing start region for level"
],
//红色
["WARN", "EULA", "Error", "Invalid", "Stopping the server", "Caused by", "Stopping"],
["Error", "Invalid", "Stopping the server", "Caused by", "Stopping"],
//黄色
[
"Starting Minecraft server on",
"world_the_end",
"world_nether",
"Done",
"MCSMANAGER",
"Server thread"
]
["WARN", "Starting Minecraft server on", "Done", "MCSMANAGER", "Server thread"]
];
for (var k in RegExpStringArr) {
for (var y in RegExpStringArr[k]) {
var reg = new RegExp("(" + RegExpStringArr[k][y].replace(/ /gim, " ") + ")", "igm");
if (k == 0)
for (const k in RegExpStringArr) {
for (const y in RegExpStringArr[k]) {
const reg = new RegExp("(" + RegExpStringArr[k][y].replace(/ /gim, " ") + ")", "igm");
if (k === "0")
//蓝色
text = text.replace(reg, term.TERM_TEXT_BLUE + "$1" + term.TERM_NULL);
if (k == 1)
text = text.replace(reg, termColor.TERM_TEXT_BLUE + "$1" + termColor.TERM_RESET);
if (k === "1")
//绿色
text = text.replace(reg, term.TERM_TEXT_GREEN + "$1" + term.TERM_NULL);
if (k == 2)
text = text.replace(reg, termColor.TERM_TEXT_DARK_GREEN + "$1" + termColor.TERM_RESET);
if (k === "2")
//红色
text = text.replace(reg, term.TERM_TEXT_RED + "$1" + term.TERM_NULL);
if (k == 3)
text = text.replace(reg, termColor.TERM_TEXT_RED + "$1" + termColor.TERM_RESET);
if (k === "3")
//黄色
text = text.replace(reg, term.TERM_TEXT_YELLOW + "$1" + term.TERM_NULL);
text = text.replace(reg, termColor.TERM_TEXT_GOLD + "$1" + termColor.TERM_RESET);
}
}
// 行结尾符号替换
text = text.replace(/\r\n/gm, term.TERM_NULL + "\r\n");
text = text.replace(/\r\n/gm, termColor.TERM_RESET + "\r\n");
return text;
}

18
src/assets/css/fonts.css Normal file
View File

@ -0,0 +1,18 @@
/* latin-ext */
@font-face {
font-family: 'Fira Code';
font-style: normal;
font-weight: 400;
font-display: swap;
src: url(../fonts/fira_code_latin_ext.woff2) format('woff2');
unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
/* latin */
@font-face {
font-family: 'Fira Code';
font-style: normal;
font-weight: 400;
font-display: swap;
src: url(../fonts/fira_code_latin.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

Binary file not shown.

Binary file not shown.