MIT License

项目介绍

trzsz/trzsz.js 是一个托管在 GitHub 上的开源项目,主要使用 TypeScript 编写,采用 MIT License 许可证,目前获得 201 个 Star、17 次 Fork。

仓库全名
trzsz/trzsz.js
开源许可证
MIT License
Star 数
201
Fork 数
17
未关闭 Issue
1

README 摘要

trzsz.js ( trz / tsz ) - the js version of trzsz trzsz.js makes terminal built with electron and webshell to support trzsz ( trz / tsz ), which similar to ( rz / sz ), and compatible with tmux. Please check https://trzsz.github.io for more information about trzsz ( trz / tsz ). Getting Started Install the module or Use in Node.js or Use in browser Create TrzszFilter object for each connection. Generally, the output…

完整内容见 GitHub 原始 README 或本页 。

常见问题

trzsz.js 用什么语言开发?

主要使用 TypeScript 编写,采用 MIT License 许可证,目前有 201 个 Star。

trzsz.js 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 trzsz.js 的源码?

可以直接克隆仓库:git clone https://github.com/trzsz/trzsz.js.git,默认分支为 main;安装与运行步骤见仓库 README。

trzsz.js 最近还在维护吗?

仓库最近一次更新为 3月7日,当前有 1 个未关闭 Issue;Star 数为 201,可作为社区活跃度的参考。

关于

trzsz.js is the js version of trzsz, makes terminal built with electron and webshell to support trzsz ( trz / tsz ).

描述取自 GitHub 官方 API,中文内容由 GitRead 中文社区 编辑团队整理。

简要分析

热度分
238
价值分
125
活跃状态
活跃

语言占比

JavaScript
TypeScript

Release

README

trzsz.js ( trz / tsz ) - the js version of trzsz

MIT License npmjs trzsz WebSite 中文文档

trzsz.js makes terminal built with electron and webshell to support trzsz ( trz / tsz ), which similar to ( rz / sz ), and compatible with tmux.

Please check https://trzsz.github.io for more information about trzsz ( trz / tsz ).

Getting Started

  • Install the module

    npm install trzsz
    

    or

    yarn add trzsz
    
  • Use in Node.js

    import { TrzszFilter } from "trzsz";
    

    or

    const { TrzszFilter } = require("trzsz");
    
  • Use in browser

    <script src="node_modules/trzsz/lib/trzsz.js"></script>
    
  • Create TrzszFilter object for each connection.

    const trzszFilter = new TrzszFilter({
      // The trzsz options, see below
    });
    
  • Generally, the output of the server is forwarded to the terminal. Pass the output through TrzszFilter.

    const trzszFilter = new TrzszFilter({
      // The output will be forwarded back by TrzszFilter, unless the user runs ( trz / tsz ) on the server.
      writeToTerminal: (data) => terminal.write(typeof data === "string" ? data : new Uint8Array(data)),
    });
    
    // forward the output to TrzszFilter
    webSocket.addEventListener("message", (ev) => trzszFilter.processServerOutput(ev.data));
    
  • Generally, the user input is forwarded to the server. Pass the user input through TrzszFilter.

    const trzszFilter = new TrzszFilter({
      // The user input will be forwarded back by TrzszFilter, unless there are files being transferred.
      sendToServer: (data) => webSocket.send(data),
    });
    
    // forward the user input to TrzszFilter
    terminal.onData((data) => trzszFilter.processTerminalInput(data));
    // forward binary input to TrzszFilter
    terminal.onBinary((data) => trzszFilter.processBinaryInput(data));
    
  • Let TrzszFilter know the terminal columns for rendering progress bar.

    const trzszFilter = new TrzszFilter({
      // initialize the terminal columns
      terminalColumns: terminal.cols,
    });
    
    // reset the terminal columns
    terminal.onResize((size) => trzszFilter.setTerminalColumns(size.cols));
    
  • If the remote server is a Windows shell, such as cmd and PowerShell.

    const trzszFilter = new TrzszFilter({
      // There is a windows shell
      isWindowsShell: true,
    });
    
  • If running in Node.js and TrzszFilter can require('fs'), chooseSendFiles and chooseSaveDirectory are required. If running in web browser, they will be ignored. Note that they are async functions.

    const trzszFilter = new TrzszFilter({
      // call on the user runs trz ( upload files ) on the server and no error on require('fs').
      chooseSendFiles: async (directory) => {
        // if `directory` is `true`, allow to choose multiple directories and files.
        // otherwise, only allow to choose multiple files.
        // return `undefined` if the user cancels.
        // return an array of file paths choosed by the user.
        return ["/path/to/file1", "/path/to/file2", "/path/to/directory3"];
      },
      // call on the user runs tsz ( download files ) on the server and no error on require('fs').
      chooseSaveDirectory: async () => {
        // return `undefined` if the user cancels.
        // return a directory path choosed by the user.
        return "/path/to/directory";
      },
    });
    
  • Support dragging files or directories to upload.

    terminalHtmlElement.addEventListener("dragover", (event) => event.preventDefault());
    terminalHtmlElement.addEventListener("drop", (event) => {
      event.preventDefault();
      trzszFilter
        .uploadFiles(event.dataTransfer.items)
        .then(() => console.log("upload success"))
        .catch((err) => console.log(err));
    });
    
  • TrzszAddon is a wrapper for TrzszFilter. If you are using xterm-addon-attach, just replace AttachAddon with TrzszAddon.

    import { Terminal } from "xterm";
    import { TrzszAddon } from "trzsz";
    
    const terminal = new Terminal();
    const trzszAddon = new TrzszAddon(webSocket);
    terminal.loadAddon(trzszAddon);
    

Examples

Screenshot

upload and download files in web browser

browser example

upload and download files in electron app

electron example

Contact

Feel free to email the author [email protected], or create an issue. Welcome to join the QQ group: 318578930.

❤️ Sponsor trzsz ❤️, buy the author a drink 🍺 ? Thank you for your support!

评论

暂无评论