• Stars
    star
    501
  • Rank 88,002 (Top 2 %)
  • Language
    JavaScript
  • Created over 7 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple Terminal Multiplexer for Node.js Environments

stmux

Simple Terminal Multiplexing for Node Environments

Abstract

This is a simple terminal multiplexing utility for Node.js environments. It is inspired by the awesome and unreachable tmux native Unix utility. The stmux utility is intended to provide just a very tiny subset of the original tmux functionality, but in a portable way for bare Node.js environments and with some special features for application build environments. Most notably, stmux has a built-time error detection and notification feature, can automatically restart terminated commands, and can automatically close or wait after all spawned commands have successfully or unsuccessfully terminated.

Internally, stmux is based on the awesome Blessed screen rendering environment and emulates full XTerm-compatible pseudo-terminals to the spawned programs with the help of Blessed XTerm and the underlying XTerm.js terminal rendering and node-pty pseudo-terminal integration 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-side inside their own XTerm emulating terminal widget (and, just for fun, CTRL+a ? was pressed to open up the stmux help window):

stmux usage

Intention

This utility is primarily intended to be used from within a package.json script to easily side-by-side run various NPM-based commands in a Node.js build-time environment. Sample package.json entries 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, the run-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), the result might be similar to the following one:

stmux example

Installation

$ npm install -g stmux

Transitive Dependency

The dependencies of stmux transitively include node-pty which must be built with node-gyp during npm install. Please check out the documentation of node-gyp on how to provide the 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 commands npm install --global windows-build-tools and npm config set msvs_version 2015 --global
  • Windows Subsystem for Linux (WSL), Ubuntu distribution: run the commands sudo apt-get update and sudo 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. For instance, for the default activator case, opening the help popup requires you to press CTRL+a (and release it again) and then (separately) press ?.
  • -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 is required that it does not match.
  • -m <methods>, --method <methods>
    In case of detected errors, use the comma-separated list of methods to perform user notification. The default is no extra notification (just the terminal annotation). Possible methods are beep and system.
  • -M, --mouse
    Enable mouse event handling. This enables the focus switching by left mouse click, the scrolling with mouse wheel and sends down mouse events to the terminal as mouse key sequences.
  • -f <file>, --file <file>
    Read specification <spec> from a configuration file. The default is to use the specification inside the command line arguments or (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-2023 Dr. Ralf S. Engelschall (http://engelschall.com/)

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.

More Repositories

1

es6-features

ECMAScript 6: Feature Overview & Comparison
HTML
6,228
star
2

astq

Abstract Syntax Tree (AST) Query Engine
JavaScript
192
star
3

vingester

Ingest Web Contents as Video Streams
JavaScript
187
star
4

typopro

Fonts for Professional Typography
129
star
5

tokenizr

String Tokenization Library for JavaScript
JavaScript
93
star
6

graphql-tools-sequelize

Integration of GraphQL-Tools and Sequelize ORM
JavaScript
90
star
7

componentjs

ComponentJS -- Powerful run-time Component System for structuring HTML5-based Rich Clients
JavaScript
85
star
8

slideshow

Slideshow -- Observe and Control Slideshow Applications
AppleScript
82
star
9

ducky

Duck-Typed Value Handling for JavaScript
JavaScript
72
star
10

extraction

Tree Extraction for JavaScript Object Graphs
JavaScript
71
star
11

es6-support

ECMAScript 6: Support Hints & Examples
JavaScript
71
star
12

thenable

Embeddable Minimum Strictly-Compliant Promises/A+ 1.1.1 Thenable
JavaScript
66
star
13

pure-uuid

Pure JavaScript Based Universally Unique Identifiers (UUID)
JavaScript
64
star
14

aggregation

Aggregation of Base Class and Mixin Classes
JavaScript
59
star
15

jquery-markup

jQuery Template Based Markup Generation
JavaScript
55
star
16

hapi-plugin-websocket

HAPI plugin for seamless WebSocket integration
JavaScript
53
star
17

graphql-tools-types

Custom Scalar Types for GraphQL-Tools
JavaScript
47
star
18

vue-i18next

Vue plugin for integrating I18Next
JavaScript
46
star
19

node-prince

Node API for executing PrinceXML via prince(1) CLI
Shell
46
star
20

blessed-xterm

XTerm Widget for Blessed Curses Environment
JavaScript
46
star
21

graphql-io

GraphQL Network Communication Framework
JavaScript
41
star
22

vmix-scripts

vMix Scripts Collection
Visual Basic .NET
40
star
23

graphql-query-compress

Compress GraphQL Query String
JavaScript
38
star
24

mqtt-json-rpc

JSON-RPC protocol over MQTT communication
JavaScript
37
star
25

asty

Abstract Syntax Tree (AST) Data Structure
JavaScript
34
star
26

json-asty

Lossless JSON-to-AST Parser and AST-to-JSON Generator
JavaScript
33
star
27

unix-under-windows

Unix Environment under Windows
32
star
28

vdon-call

Remote Caller Ingest for Live Video Productions with VDO.Ninja & OBS Studio
HTML
32
star
29

pegjs-util

Utility Class for PEG.js
JavaScript
31
star
30

node-enigmavirtualbox

Node API for executing Enigma Virtual Box
JavaScript
30
star
31

microkernel

Microkernel for Server Applications
JavaScript
28
star
32

graphql-tutorial

Tutorial for GraphQL
JavaScript
27
star
33

glyphs2font

SVG Glyph Icons to Web Font Generation
JavaScript
27
star
34

grunt-bower-install-simple

Grunt Task for Installing Bower Dependencies
JavaScript
26
star
35

obs-setup

OBS Studio Setup Information
26
star
36

vdo-ninja-trampoline

VDO.Ninja Trampoline
HTML
25
star
37

hapi-plugin-graphiql

HAPI plugin for GraphiQL integration
CSS
22
star
38

typopro-web

TypoPRO (Web Font Formats)
CSS
19
star
39

huds

Head-Up-Display Server (HUDS)
JavaScript
19
star
40

tika-server

Apache Tika Server as a Background Service in Node.js
JavaScript
18
star
41

node-inline-assets

Node API, CLI and Grunt Task for inlining external assets of HTML/CSS files
JavaScript
18
star
42

grunt-merge-json

Grunt Task for Merging Multiple JSON Files
JavaScript
18
star
43

node-http-proxy-simple

Simple HTTP proxy extension module for Node.js, allowing protocol and payload interception
JavaScript
17
star
44

jquery-stage

jQuery Stage Information
JavaScript
15
star
45

obs-scripts

OBS Studio Lua Scripts
Lua
15
star
46

html5-spa-essentials

Essential Functionalities for HTML5 Single-Page-Apps (SPA)
JavaScript
15
star
47

audio-node-suite

Web Audio API AudioNode Suite
TypeScript
13
star
48

apollo-client-ws

GraphQL WebSocket Network Interface for Apollo Client
JavaScript
13
star
49

huds-hud-training

Training HUD for HUDS
Vue
12
star
50

pdfbox-simple

Simple PDFBox Wrapper
JavaScript
11
star
51

fasttext-lid

Language Identification with Facebook FastText for Node.js
JavaScript
11
star
52

jquery-page

jQuery Page Transitions
JavaScript
11
star
53

cache-lru

In-Memory Cache with O(1) Operations and LRU Purging Strategy
JavaScript
10
star
54

browserify-derequire

Browserify Plugin for Renaming require() Calls
JavaScript
10
star
55

encodr

Encoding/Decoding to/from CBOR/MsgPack/JSON for Node.js and Browser
JavaScript
9
star
56

dotfiles

Small Opinionated Collection of Unix Configuration Files for User Shell Environment
Shell
9
star
57

lowerthird

Lower Thirds for OBS Studio
JavaScript
8
star
58

graphql-io-server

GraphQL Network Communication Framework (Server)
JavaScript
8
star
59

stanford-postagger

Stanford Log-linear Part-Of-Speech (PoS) Tagger for Node.js
JavaScript
8
star
60

oset

Ordered Set Data Structure for JavaScript
JavaScript
8
star
61

wordnet-lmf

WordNet Lexical Markup Framework (LMF)
JavaScript
7
star
62

upd

Upgrade Package Dependencies (UPD)
JavaScript
7
star
63

hapi-plugin-co

HAPI plugin for Co-Routine handlers
JavaScript
7
star
64

sublime-scheme-rse

Sublime Text Color Scheme RSE
7
star
65

hapi-plugin-traffic

HAPI plugin for network traffic accounting
JavaScript
7
star
66

soundfx

Sound Effect Collection
JavaScript
7
star
67

syntax

Unobtrusive Syntax Highlighting
JavaScript
7
star
68

bash-fzf

Enhance GNU Bash with FZF Matching
Makefile
7
star
69

psd2pptx

Convert Photoshop (PSD) layers to PowerPoint (PPTX) slides
JavaScript
7
star
70

grunt-newer-explicit

Grunt Task for running tasks if source files are newer only.
JavaScript
6
star
71

asty-astq

Abstract Syntax Tree With Integrated Query Engine
JavaScript
6
star
72

node-unix

Unix operating system integration for Node.js-based services
JavaScript
6
star
73

ipc-pubsub

Inter-Process-Communication (IPC) Publish-Subscribe (PubSub) Abstraction Layer
JavaScript
6
star
74

live-receiver

Live Video Experience (LiVE) Receiver
Vue
6
star
75

jquery-schedule

jQuery plugin for performing scheduled/deferred actions on DOM elements.
JavaScript
6
star
76

node-xmlhttprequest-cookie

Cookie-aware XMLHttpRequest Wrapper
JavaScript
6
star
77

websocket-framed

Framed WebSocket Communication
JavaScript
6
star
78

ffmpeg

FFmpeg distribution for NPM
JavaScript
5
star
79

sysload

System Load Determination
JavaScript
5
star
80

style-scope

PostCSS and PostHTML plugins for locally scoping styles
JavaScript
5
star
81

audio-setup

Windows Audio Setup
5
star
82

sprintfjs

POSIX sprintf(3)-style Formatting for JavaScript
JavaScript
5
star
83

studio-canvas

Real-Time Virtual Studio Canvas Rendering
TypeScript
5
star
84

browserify-replace

Browserify Transform For Replacing Strings
JavaScript
5
star
85

gridless

Grid System for LESS CSS
CSS
4
star
86

mostlikely

Most-Likely Classification Through Bloom-Filtering
JavaScript
4
star
87

obs-crop-control

Remote Crop-Filter Control for OBS Studio
JavaScript
4
star
88

k8s-sample

Kubernetes (K8S) Sample Application
JavaScript
4
star
89

peertime

Network Peer Time Synchronization
JavaScript
3
star
90

obs-banner

Simple Banner for OBS Studio
JavaScript
3
star
91

obs-cam-control

Camera Control for OBS Studio
JavaScript
3
star
92

vue-params

Vue plugin for global parameters triggering data-binding updates
JavaScript
3
star
93

pptx-surgeon

PowerPoint OpenXML File Surgeon
JavaScript
3
star
94

pdf-scrape

PDF Text Scraping
JavaScript
3
star
95

hapi-plugin-header

HAPI plugin to always send a Server identification header
JavaScript
3
star
96

grunt-extend-config

Grunt Plugin for Extending Grunt Configuration
JavaScript
3
star
97

nunjucks-cli

Nunjucks Template Rendering Command-Line Interface
JavaScript
3
star
98

huds-hud-hello

Hello World HUD for HUDS
HTML
3
star
99

graphql-io-client

GraphQL Network Communication Framework (Client)
JavaScript
3
star
100

ael

Advanced Expression Language
JavaScript
3
star