1 Star 0 Fork 1

Raisr / xterm-terminal

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

XtermTerminal

  • 采用 xterm 库做的一个 web 版终端工具。

组件演示

显示日志

import React from 'react';
import XtermTerminal from '@rasir/xterm-terminal';

const XtermLogger = () => {
  const testText = `2022-07-29 13:49:20,288 [main] ERROR - execute sql error
    org.apache.hive.service.cli.HiveSQLException: Error while compiling statement: FAILED: SemanticException org.apache.hadoop.hive.ql.parse.SemanticException: Table already exists: sf_hkust.yiqing_755fb_0729_waybill_182
    at org.apache.hive.jdbc.Utils.verifySuccess(Utils.java:266)
    at org.apache.hive.jdbc.Utils.verifySuccessWithInfo(Utils.java:252)
    at org.apache.hive.jdbc.HiveStatement.runAsyncOnServer(HiveStatement.java:318)
    at org.apache.hive.jdbc.HiveStatement.execute(HiveStatement.java:260)
    at com.sf.bdp.schetl.hive.driver.HiveJdbcExecutor.execute(HiveJdbcExecutor.java:93)
    at com.sf.bdp.schetl.hive.driver.HiveJdbcExecutor.execute(HiveJdbcExecutor.java:112)
    at com.sf.bdp.schetl.hive.driver.HiveDriver.main(HiveDriver.java:71)
    Caused by: org.apache.hive.service.cli.HiveSQLException: Error while compiling statement: FAILED: SemanticException org.apache.hadoop.hive.ql.parse.SemanticException: Table already exists: sf_hkust.yiqing_755fb_0729_waybill_182
    at org.apache.hive.service.cli.operation.Operation.toSQLException(Operation.java:388)
    at org.apache.hive.service.cli.operation.SQLOperation.prepare(SQLOperation.java:193)
    at org.apache.hive.service.cli.operation.SQLOperation.runInternal(SQLOperation.java:276)
    at org.apache.hive.service.cli.operation.Operation.run(Operation.java:324)
    at org.apache.hive.service.cli.session.HiveSessionImpl.executeStatementInternal(HiveSessionImpl.java:505)
    at org.apache.hive.service.cli.session.HiveSessionImpl.executeStatementAsync(HiveSessionImpl.java:492)
    at org.apache.hive.service.cli.CLIService.executeStatementAsync(CLIService.java:295)
    at org.apache.hive.service.cli.thrift.ThriftCLIService.ExecuteStatement(ThriftCLIService.java:506)
    at org.apache.hive.service.rpc.thrift.TCLIService$Processor$ExecuteStatement.getResult(TCLIService.java:1437)
    at org.apache.hive.service.rpc.thrift.TCLIService$Processor$ExecuteStatement.getResult(TCLIService.java:1422)
    at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:39)
    at org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:39)
    at org.apache.hive.service.auth.TSetIpAddressProcessor.process(TSetIpAddressProcessor.java:56)
    at org.apache.thrift.server.TThreadPoolServer$WorkerProcess.run(TThreadPoolServer.java:286)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
    Caused by: java.lang.RuntimeException: org.apache.hadoop.hive.ql.parse.SemanticException:org.apache.hadoop.hive.ql.parse.SemanticException: Table already exists: sf_hkust.yiqing_755fb_0729_waybill_182
    at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.analyzeCreateTable(SemanticAnalyzer.java:11767)
    at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.genResolvedParseTree(SemanticAnalyzer.java:10717)
    at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.analyzeInternal(SemanticAnalyzer.java:10827)
    at org.apache.hadoop.hive.ql.parse.CalcitePlanner.analyzeInternal(CalcitePlanner.java:246)
    at org.apache.hadoop.hive.ql.parse.BaseSemanticAnalyzer.analyze(BaseSemanticAnalyzer.java:251)
    at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:479)
    at org.apache.hadoop.hive.ql.Driver.compileInternal(Driver.java:1253)
    at org.apache.hadoop.hive.ql.Driver.compileAndRespond(Driver.java:1240)
    at org.apache.hive.service.cli.operation.SQLOperation.prepare(SQLOperation.java:191)
    ... 15 more
    Caused by: java.lang.RuntimeException: org.apache.hadoop.hive.ql.parse.SemanticException:Table already exists: sf_hkust.yiqing_755fb_0729_waybill_182
    at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.analyzeCreateTable(SemanticAnalyzer.java:11764)
    ... 23 more
    Exception in thread "main" com.sf.bdp.schetl.common.exception.ScheduleException: org.apache.hive.service.cli.HiveSQLException: Error while compiling statement: FAILED: SemanticException org.apache.hadoop.hive.ql.parse.SemanticException: Table already exists: sf_hkust.yiqing_755fb_0729_waybill_1822022-07-29 13:49:20,290 [Thread-6] ERROR - execute sql error
    java.sql.SQLException: Method getQueryLog() failed. Because the stmtHandle in HiveStatement is null and the statement execution might fail.
    at org.apache.hive.jdbc.HiveStatement.getQueryLog(HiveStatement.java:894)
    at org.apache.hive.jdbc.HiveStatement.getQueryLog(HiveStatement.java:857)
    at com.sf.bdp.schetl.hive.driver.HiveJdbcExecutor$LogPrinter.run(HiveJdbcExecutor.java:141)
    
    at com.sf.bdp.schetl.hive.driver.HiveJdbcExecutor.execute(HiveJdbcExecutor.java:97)日志收集出错:Method getQueryLog() failed. Because the stmtHandle in HiveStatement is null and the statement execution might fail.
    
    at com.sf.bdp.schetl.hive.driver.HiveJdbcExecutor.execute(HiveJdbcExecutor.java:112)
    at com.sf.bdp.schetl.hive.driver.HiveDriver.main(HiveDriver.java:71)
    Caused by: org.apache.hive.service.cli.HiveSQLException: Error while compiling statement: FAILED: SemanticException org.apache.hadoop.hive.ql.parse.SemanticException: Table already exists: sf_hkust.yiqing_755fb_0729_waybill_182
    at org.apache.hive.jdbc.Utils.verifySuccess(Utils.java:266)
    at org.apache.hive.jdbc.Utils.verifySuccessWithInfo(Utils.java:252)
    at org.apache.hive.jdbc.HiveStatement.runAsyncOnServer(HiveStatement.java:318)
    at org.apache.hive.jdbc.HiveStatement.execute(HiveStatement.java:260)
    at com.sf.bdp.schetl.hive.driver.HiveJdbcExecutor.execute(HiveJdbcExecutor.java:93)
    ... 2 more
    Caused by: org.apache.hive.service.cli.HiveSQLException: Error while compiling statement: FAILED: SemanticException org.apache.hadoop.hive.ql.parse.SemanticException: Table already exists: sf_hkust.yiqing_755fb_0729_waybill_182
    at org.apache.hive.service.cli.operation.Operation.toSQLException(Operation.java:388)
    at org.apache.hive.service.cli.operation.SQLOperation.prepare(SQLOperation.java:193)
    at org.apache.hive.service.cli.operation.SQLOperation.runInternal(SQLOperation.java:276)
    at org.apache.hive.service.cli.operation.Operation.run(Operation.java:324)
    at org.apache.hive.service.cli.session.HiveSessionImpl.executeStatementInternal(HiveSessionImpl.java:505)
    at org.apache.hive.service.cli.session.HiveSessionImpl.executeStatementAsync(HiveSessionImpl.java:492)
    at org.apache.hive.service.cli.CLIService.executeStatementAsync(CLIService.java:295)
    at org.apache.hive.service.cli.thrift.ThriftCLIService.ExecuteStatement(ThriftCLIService.java:506)
    at org.apache.hive.service.rpc.thrift.TCLIService$Processor$ExecuteStatement.getResult(TCLIService.java:1437)
    at org.apache.hive.service.rpc.thrift.TCLIService$Processor$ExecuteStatement.getResult(TCLIService.java:1422)
    at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:39)
    at org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:39)
    at org.apache.hive.service.auth.TSetIpAddressProcessor.process(TSetIpAddressProcessor.java:56)2022-07-29 13:49:20,292 [Hive-JDBC-Driver-ShutdownHook] INFO  - trigger Hive-JDBC-Driver shutdown.
    
    at org.apache.thrift.server.TThreadPoolServer$WorkerProcess.run(TThreadPoolServer.java:286)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
    Caused by: java.lang.RuntimeException: org.apache.hadoop.hive.ql.parse.SemanticException:org.apache.hadoop.hive.ql.parse.SemanticException: Table already exists: sf_hkust.yiqing_755fb_0729_waybill_182
    at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.analyzeCreateTable(SemanticAnalyzer.java:11767)
    at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.genResolvedParseTree(SemanticAnalyzer.java:10717)
    at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.analyzeInternal(SemanticAnalyzer.java:10827)
    at org.apache.hadoop.hive.ql.parse.CalcitePlanner.analyzeInternal(CalcitePlanner.java:246)
    at org.apache.hadoop.hive.ql.parse.BaseSemanticAnalyzer.analyze(BaseSemanticAnalyzer.java:251)`;
  const loaded = (e, api) => {
    Promise.resolve().then(() => {
      testText.split(/\n/).forEach((text, i) => {
        if (i === 0) {
          api.writeln({ text, color: 'YELLOW' });
        } else {
          api.writeln(text.trim());
        }
      });
    });
  };

  return (
    <div>
      <XtermTerminal
        colorRules={[{ pattern: /error.*$/gi, color: 'RED' }]}
        lineTitle=""
        preLog=""
        disableStdin
        height={300}
        onLoad={loaded}
      />
    </div>
  );
};

export default XtermLogger;

终端操作

import React, { useState } from 'react';
import XtermTerminal from '@rasir/xterm-terminal';

const Terminal = () => {
  const [term, setTerm] = useState();
  const [api, setApi] = useState();

  const loaded = (term, api) => {
    setTerm(term);
    setApi(api);
  };

  const onCommand = (cmd) => {
    api.writeln(`hello Rasir!!!`);
    api.writeln('');
  };

  return (
    <div>
      <XtermTerminal
        colorRules={[{ pattern: /error.*$/gi, color: 'RED' }]}
        lineTitle="$: "
        preLog="### START ###"
        height={300}
        onLoad={loaded}
        onCommand={onCommand}
      />
    </div>
  );
};

export default Terminal;

API

属性 说明 类型 默认值
className 容器类名 string ---
height 容器高度,height变化会引起 xterm 自适应 number ---
style 容器高度样式 React.CSSProperties ---
disableStdin 是否禁用输入 boolean ---
lineTitle 终端输出的每一行开头的字符,不计入输入字符 string $:
preLog 终端预置日志 string \r\n*** COMMAND START ***\r\n
command 终端执行命令,最好与disableStdin一起使用 string ---
onCommand 在终端输入回车时会调用回调 (command?: string) => void ---
onClear 输入clear会触发回调 () => void ---
onCopy ctrl+c/cmd+c 复制回调 (text: string) => Promise<void> ---
onPaste ctrl+v/cmd+v 粘贴回调 () => Promise<string> ---
onLoad 终端初始化完成时的回调 (term: XTerminal, api: TerminalApi) => void ---
colorRules 文字显示颜色的规则 ColorRule[] ---
options xterm原生配置,初始化时使用,初始化之后,如果要改变配置,可以使用xterm原来的setOption方法 ITerminalOptions ---

TerminalApi

interface TerminalApi {
    clearLog: () => void;
    writeln: (text?: string) => void;
    write: (text?: string) => void;
    getCommand: () => string;
    resize: () => void;
}

ColorRule

type ColorRule = {
    pattern: RegExp;
    color: Color;
}

Color

Color = "BLACK" | "RED" | "GREEN" | "YELLOW" | "BLUE" | "MAGENTA" | "CYAN" | "WHITE" | "RESET"
MIT License Copyright (c) 2021 Raisr Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

采用 xterm 库做的一个 web 版终端工具。 展开 收起
JavaScript 等 3 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
JavaScript
1
https://gitee.com/rasir/xterm-terminal.git
git@gitee.com:rasir/xterm-terminal.git
rasir
xterm-terminal
xterm-terminal
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891