stmux

授权协议 Readme
开发语言 JavaScript
所属分类 Web应用开发、 常用JavaScript包
软件类型 开源软件
地区 不详
投 递 者 刘野
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

stmux

Simple Terminal Multiplexing for Node Environments

Abstract

This is a simple terminal multiplexing utility for Node.jsenvironments. It is inspired by the awesome and unreachabletmux native Unix utility. The stmux utilityis intended to provide just a very tiny subset of the originaltmux functionality, but in a portable way forbare Node.js environments and with some special features for applicationbuild environments. Most notably, stmux has a built-time errordetection and notification feature, can automatically restart terminated commands,and can automatically close or wait after all spawned commands havesuccessfully or unsuccessfully terminated.

Internally, stmux is based on the awesomeBlessed screen rendering environmentand emulates full XTerm-compatible pseudo-terminalsto the spawned programs with the help of Blessed XTermand the underlying XTerm.js terminal renderingand node-pty pseudo-terminalintegration modules.

Example

The following command...

$ stmux -- [ [ -s 1/3 bash .. vim ] : mc ]

...leads to the following particular terminal multiplexing environment,where GNU bash, Vim and Midnight Commander are running side-by-sideinside their own XTerm emulating terminal widget (and, just for fun,CTRL+a ? was pressed to open up the stmux help window):

Intention

This utility is primarily intended to be used from within apackage.json script to easily side-by-side run various NPM-basedcommands in a Node.js build-time environment. Sample package.jsonentries from a top-level NPM-based project follows, which on npm run dev allows one to conveniently run the commands of two sub-projects.First, the build-time of the frontend user interface (UI) project.Second, the build-time of the backend server (SV) project. Third, therun-time of the backend server project.

{
    ...
    "dependencies": {
        "stmux":      "*"
    },
    "scripts": {
        "install":    "npm run install:ui && npm run install:sv",
        "install:ui": "cd ui && npm install",
        "install:sv": "cd sv && npm install",

        "build":      "npm run build:ui && npm run build:sv",
        "build:ui":   "cd ui && npm run build",
        "build:sv":   "cd sv && npm run build",

        "start":      "cd sv && npm start",

        "clean":      "npm run clean:ui && npm run clean:sv",
        "clean:ui":   "cd ui && npm run clean",
        "clean:sv":   "cd sv && npm run clean",

        "dev":        "stmux -w always -e ERROR -m beep,system -- [ [ \"npm run dev:ui\" .. \"npm run dev:sv\" ] : -s 1/3 -f \"npm start\" ]",
        "dev:ui":     "cd ui && npm run build:watch",
        "dev:sv":     "cd sv && npm run build:watch"
    }
}

In case of a build-time error in the frontend user interface (SV), theresult might be similar to the following one:

Installation

$ npm install -g stmux

Dependency: node-gyp

You must have node-gyp installed,as stmux requires node-pty whichmust be built with node-gyp duringnpm install.

Please check out the documentation ofnode-gyp on how to providethe necessary C/C++ compiler environment on your operating system.

  • macOS: install the "Command Line Tools" under"Preferences > Downloads" in Xcode.
  • Windows: open an elevated cmd.exe and run the commandsnpm install --global windows-build-tools andnpm config set msvs_version 2015 --global
  • Windows Subsystem for Linux (WSL), Ubuntu distribution: run the commandssudo apt-get update andsudo apt-get install -y python make build-essential
  • Under Linux or FreeBSD you usually don't have to do anything.

Usage

The following command line arguments are supported:

$ stmux [-h] [-V] [-w <condition>] [-a <activator>] [-t <title>]
        [-c <type>] [-n] [-e <regexp>] [-m <method>] [-M] [-f <file>]
        [-- <spec>]
  • -h, --help
    Show usage help.
  • -V, --version
    Show program version information.
  • -w <condition>, --wait <condition>
    Wait after last finished command (and do not shutdown automatically),either if any command terminated with an error or just always.
  • -a <activator>, --activator <activator>
    Use CTRL+<activator> as the prefix to special commands.The default activator character is a.
  • -t <title>, --title <title>
    Set title on terminal. The default title is stmux.
  • -c <type>, --cursor <type>
    Set type of cursor to block (default), underline or line.
  • -n, --number
    Show terminal number in terminal title.
  • -e <regexp>[,...], --error <regexp>[,...]
    Observe terminal lines for errors (global option).One or more regular expressions can be specified and have to match on a single line.If a regular expression is preceeded with the prefix !, it isrequired that it does not match.
  • -m <methods>, --method <methods>
    In case of detected errors, use the comma-separatedlist of methods to perform user notification. The defaultis no extra notification (just the terminal annotation).Possible methods are beep and system.
  • -M, --mouse
    Enable mouse event handling. This enables the focus switchingby left mouse click, the scrolling with mouse wheel andsends down mouse events to the terminal as mouse key sequences.
  • -f <file>, --file <file>
    Read specification <spec> from a configuration file. Thedefault is to use the specification inside the command line argumentsor (alternatively) to read the specification from stdin.

The following PEG-style grammar loosly describes the specification <spec>.For exact details see the real PEG grammar of stmux.

spec      ::= "[" directive (":"  directive)* "]"  /* vertical   split */
            | "[" directive (".." directive)* "]"  /* horizontal split */

directive ::= option* spec                         /* RECURSION */
            | option* string                       /* shell command */

option    ::= ("-f" | "--focus")                   /* focus terminal initially */
            | ("-r" | "--restart")                 /* restart command automatically */
            | ("-d" | "--delay") number            /* delay <number> seconds on restart */
            | ("-t" | "--title") string            /* set title of terminal */
            | ("-s" | "--size") size               /* request a size on terminal */
            | ("-e" | "--error") regexp            /* observe terminal for errors (local option) */

size      ::= /^\d+$/                              /* fixed character size */
            | /^\d+\.\d+$/                         /* total size factor */
            | /^\d+\/\d+$/                         /* total size fraction */
            | /^\d+%$/                             /* total size percentage */

The following keystrokes are supported under run-time:

  • CTRL+activator activator:
    Send the CTRL+activator key-sequence to the focused terminal.
  • CTRL+activator BACKSPACE:
    Switch the focus to the previous terminal in sequence.
  • CTRL+activator SPACE:
    Switch the focus to the next terminal in sequence.
  • CTRL+activator LEFT/RIGHT/UP/DOWN:
    Switch the focus to the best matching terminal in a direction.
  • CTRL+activator 1/2/.../9:
    Directly switch to a particular terminal.
  • CTRL+activator n:
    Toggle showing/hiding of terminal numbers.
  • CTRL+activator z:
    Toggle the zooming of focused terminal.
  • CTRL+activator v:
    Switch the focused terminal into visual/scrolling mode.Use PAGEUP/PAGEDOWN during this mode to scroll up/down.Any other key leaves this mode.
  • CTRL+activator l:
    Relayout the screen.
  • CTRL+activator r:
    Restart the program in the focused terminal.
  • CTRL+activator k:
    Kill the application and all shell commands in all terminals.
  • CTRL+activator ?:
    Show help window.

Specification Examples

  • stmux [ A ]:

    +-----------+
    |           |
    |     A     |
    |           |
    +-----------+
    
  • stmux [ A .. B ]:

    +-----+-----+
    |     |     |
    |  A  |  B  |
    |     |     |
    +-----+-----+
    
  • stmux [ A : B ]:

    +-----------+
    |     A     |
    +-----------+
    |     B     |
    +-----------+
    
  • stmux [ [ A .. B ] : C ]:

    +-----+-----+
    |  A  |  B  |
    +-----+-----+
    |     C     |
    +-----------+
    
  • stmux [ [ A : B ] .. C ]:

    +-----+-----+
    |  A  |     |
    +-----+  C  |
    |  B  |     |
    +-----+-----+
    
  • stmux [ [ A : B ] .. [ C : D ] ]:

    +-----+-----+
    |  A  |  C  |
    +-----+-----+
    |  B  |  D  |
    +-----+-----+
    
  • stmux [ [ A .. B ] : [ C .. D ] ]:

    +-----+-----+
    |  A  |  B  |
    +-----+-----+
    |  C  |  D  |
    +-----+-----+
    
  • stmux -- [ [ -s 1/3 A .. B ] : [ C .. -s 1/3 D ] ]:

    +---+-------+
    | A |    B  |
    +---+---+---+
    |    C  | D |
    +-------+---+
    

License

Copyright (c) 2017-2021 Dr. Ralf S. Engelschall (http://engelschall.com/)

Permission is hereby granted, free of charge, to any person obtaininga copy of this software and associated documentation files (the"Software"), to deal in the Software without restriction, includingwithout limitation the rights to use, copy, modify, merge, publish,distribute, sublicense, and/or sell copies of the Software, and topermit persons to whom the Software is furnished to do so, subject tothe following conditions:

The above copyright notice and this permission notice shall be includedin 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 OFMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANYCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THESOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

相关阅读

相关文章

相关问答

相关文档