npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@rasir/xterm-terminal

v1.0.2

Published

基于xterm的web终端React组件

Readme

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"