From 842e9064ea3eba8ebd60d11fe5b5f1e113bd3ab8 Mon Sep 17 00:00:00 2001 From: hanez Date: Mon, 23 Nov 2026 13:24:16 +0100 Subject: [PATCH 01/18] Show the murx logo in command-line help --- README.md | 2 +- murx.1 | 2 +- murx.c | 16 ++++++++++++++++ os/alpine/APKBUILD | 6 +++--- os/arch/PKGBUILD | 6 +++--- 5 files changed, 24 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index c81181f..79d2866 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ make ./murx --hostname work # show the hostname: prefix in window titles ./murx --pane-titles work # show a title row above each pane ./murx -l, --list-sessions # list running sessions without attaching -./murx --help # version, usage and all shortcuts +./murx --help # logo, version, usage and shortcuts ./murx -v, --version # print the version and exit ``` diff --git a/murx.1 b/murx.1 index 97d6fa2..ea8657e 100644 --- a/murx.1 +++ b/murx.1 @@ -96,7 +96,7 @@ Show the hostname: prefix in window names and the outer terminal title. Show the title row above each pane. Pane titles are off by default. .TP .BR \-h ", " \-\-help -Print the program version, usage and keyboard shortcuts, then exit. +Print the text logo, program version, usage and keyboard shortcuts, then exit. .TP .BR \-v ", " \-\-version Print the program version and exit. diff --git a/murx.c b/murx.c index bb701db..ce1d6ba 100644 --- a/murx.c +++ b/murx.c @@ -4962,6 +4962,22 @@ static void help_row(FILE *out, const char *left, const char *right) { } static void print_help(FILE *out) { + fputs(" +-------------------------+\n" + " | o o o |\n" + " +-------------+-----------+\n" + " | >_ | ======== |\n" + " | | ==== |\n" + " | +-----------+\n" + " | | :|:||: |\n" + " +-------------+-----------+\n" + "\n" + " ######## ## ## ###### ## ##\n" + " ## ## ## ## ## ## ## ##\n" + " ## ## ## ## ## ## ###\n" + " ## ## ## ## ## ## ## ##\n" + " ## ## ## ##### ## ## ##\n" + " -- terminal multiplexer --\n" + "\n", out); fprintf(out, "murx %s\n\n", MURX_VERSION); fputs("usage: murx [OPTIONS] [session]\n" "\n" diff --git a/os/alpine/APKBUILD b/os/alpine/APKBUILD index 9c329a8..237f6b6 100644 --- a/os/alpine/APKBUILD +++ b/os/alpine/APKBUILD @@ -26,10 +26,10 @@ package() { } sha512sums=" -68c0e952a57d03e5c2cc6a7451cca1687341c20620634617529b6dc84f0fcdc7cb49cbc662bfad5b1fe3229c082a61480813ed5c01a1994c1b2a8e34bd421e29 murx.c +315f6bd49ede1f83132698347e5766a9b3df918abc7fbdae891851bf202064bb68a76dd2c4faa920f610600817278650deae3a8fe6746047d42753d9b49b62ad murx.c ac75bfe596fae665ba882a10f5d16551bdd02cd601b786364763ac74dbc651c386d3a464eb63e0344354b953611629135190633e3b8ff3a8ef0f0849d60a3f7b Makefile -219082e6277ee8c226cdd61a5b17d4e3c6893adf04b2f59ea84a6b6421dbd5a6d0ff38b93d8dd8ae41ed037e77252058dacadd5ff1f0c36c7c1ff95503e1e7a8 murx.1 -1b98d82dc3c41c376827cfd3883ee8918f24e82eab138fbb0e62bc5c2b0ba9498eb3abe59dc96b3f3d67a20fbdb331ed113d1898297c4f3c904e6341364cfdc9 MURX-README.md +84713fc8e6b244292bdd53d6071578cde67b9fe136d85e4b4809eceab53dbb6d86f33fd846ec87eeccefdbd006744ca7898b677f43b3447a1c357b8a6a2f8301 murx.1 +167090193501e8f2fbe1a6c34369b7ee556ca5c84207b54e8952b19b44ef6d4eac89c03ec450956284d6754dd3c00ffa2241976545909d9504e30802c9c28e26 MURX-README.md 2fe33ba22c5f68e124904be594208f050be20f33d115f9a56f60cac93304102da32e6a7e78154e831d3704da7ca8bfefd7025e7b8901e65babcd83e7342f6382 LICENSE 4d32dba475e5f9818fcd008068b011cbae9fc4b8e29897c933775d6660f44a7992d08a1550320d83233af729a42b241ef1d182bf5983ef2f64deab76cab2260d AUTHORS " diff --git a/os/arch/PKGBUILD b/os/arch/PKGBUILD index a036fb1..0908e41 100644 --- a/os/arch/PKGBUILD +++ b/os/arch/PKGBUILD @@ -8,10 +8,10 @@ url='https://codeberg.org/armin/murx' license=('Apache-2.0') depends=('glibc') source=('murx.c' 'Makefile' 'murx.1' 'MURX-README.md' 'LICENSE' 'AUTHORS') -sha256sums=('358d39eed410a9657ef811892288ef407fe8f17709cb1b4b5e0405635594b70d' +sha256sums=('68b2e3aa8cf2de7a69aeee008242983f5ca01839e54127547b2f6860ff249dd5' '78a9c19c212e8038422e1bb4bb96d9b25eb19ad1359489cd32edf9e1a76638b2' - '953966bfdd0b49cb26c11220e1e2bf6b5862aaa1b2d0bf002cde9d276f0ae96b' - '1a9c479723f74cdc3a2af6cf7a4ad52388681b11a5ba3f4cfb73d28af631e036' + 'b0965c6c8cd73cef1e578e4a8295df0899b43f20ab9a9649150790a3b1434c1b' + '7cb95cc829fd2f9756cbb611aa4ddb8dc97853ccf360efd18d1423628e484aa1' '31c5556be4cdd9bf52bb55f18ead0c68a4f0e793c2c2dab0a2a2c6d92407d0d4' 'dbc8a4fc569d4cd7bcd45516ccc98c1396fce0682c262103069c8f5150538cdb') From d4740da8e9b312afa2a4bdfe539c176fda884b08 Mon Sep 17 00:00:00 2001 From: Armin Date: Mon, 23 Nov 2026 13:43:03 +0100 Subject: [PATCH 02/18] Compact the logo shown in --help --- murx.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/murx.c b/murx.c index ce1d6ba..6157183 100644 --- a/murx.c +++ b/murx.c @@ -4962,21 +4962,14 @@ static void help_row(FILE *out, const char *left, const char *right) { } static void print_help(FILE *out) { - fputs(" +-------------------------+\n" - " | o o o |\n" - " +-------------+-----------+\n" - " | >_ | ======== |\n" - " | | ==== |\n" - " | +-----------+\n" - " | | :|:||: |\n" - " +-------------+-----------+\n" - "\n" - " ######## ## ## ###### ## ##\n" - " ## ## ## ## ## ## ## ##\n" - " ## ## ## ## ## ## ###\n" - " ## ## ## ## ## ## ## ##\n" - " ## ## ## ##### ## ## ##\n" - " -- terminal multiplexer --\n" + fputs(" +-------------------------+\n" + " | murx | |\n" + " +-------------+-----------+\n" + " | >_ | ======== |\n" + " | | ==== |\n" + " | terminal +-----------+\n" + " | multiplexer | :|:||: |\n" + " +-------------+-----------+\n" "\n", out); fprintf(out, "murx %s\n\n", MURX_VERSION); fputs("usage: murx [OPTIONS] [session]\n" From 1c686572f462d230eaee3d8f045d1e0fdeb9e684 Mon Sep 17 00:00:00 2001 From: hanez Date: Mon, 23 Nov 2026 13:45:52 +0100 Subject: [PATCH 03/18] pkg build files update. --- os/alpine/APKBUILD | 2 +- os/arch/PKGBUILD | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/os/alpine/APKBUILD b/os/alpine/APKBUILD index 237f6b6..60ab8b2 100644 --- a/os/alpine/APKBUILD +++ b/os/alpine/APKBUILD @@ -26,7 +26,7 @@ package() { } sha512sums=" -315f6bd49ede1f83132698347e5766a9b3df918abc7fbdae891851bf202064bb68a76dd2c4faa920f610600817278650deae3a8fe6746047d42753d9b49b62ad murx.c +f39b354e08d4200f604ddf699d918eb39481219f5eec8a66369c83bd0bcad3121e09584d3fefc1749a85b31fffef5609359dc44fa4d5bcce84e5798483622f58 murx.c ac75bfe596fae665ba882a10f5d16551bdd02cd601b786364763ac74dbc651c386d3a464eb63e0344354b953611629135190633e3b8ff3a8ef0f0849d60a3f7b Makefile 84713fc8e6b244292bdd53d6071578cde67b9fe136d85e4b4809eceab53dbb6d86f33fd846ec87eeccefdbd006744ca7898b677f43b3447a1c357b8a6a2f8301 murx.1 167090193501e8f2fbe1a6c34369b7ee556ca5c84207b54e8952b19b44ef6d4eac89c03ec450956284d6754dd3c00ffa2241976545909d9504e30802c9c28e26 MURX-README.md diff --git a/os/arch/PKGBUILD b/os/arch/PKGBUILD index 0908e41..18c9ac1 100644 --- a/os/arch/PKGBUILD +++ b/os/arch/PKGBUILD @@ -8,7 +8,7 @@ url='https://codeberg.org/armin/murx' license=('Apache-2.0') depends=('glibc') source=('murx.c' 'Makefile' 'murx.1' 'MURX-README.md' 'LICENSE' 'AUTHORS') -sha256sums=('68b2e3aa8cf2de7a69aeee008242983f5ca01839e54127547b2f6860ff249dd5' +sha256sums=('da9a5d8451c396f45d5c1839ca762d066fa531b42339db81d1e478b9ad6559f0' '78a9c19c212e8038422e1bb4bb96d9b25eb19ad1359489cd32edf9e1a76638b2' 'b0965c6c8cd73cef1e578e4a8295df0899b43f20ab9a9649150790a3b1434c1b' '7cb95cc829fd2f9756cbb611aa4ddb8dc97853ccf360efd18d1423628e484aa1' From 4dd76a8176b4f227d21b9ee75d3bcc574768985b Mon Sep 17 00:00:00 2001 From: hanez Date: Mon, 23 Nov 2026 13:53:11 +0100 Subject: [PATCH 04/18] removed AGENTS.md. --- AGENTS.md | 68 ------------------------------------------------------- 1 file changed, 68 deletions(-) delete mode 100644 AGENTS.md diff --git a/AGENTS.md b/AGENTS.md deleted file mode 100644 index 7e44d2a..0000000 --- a/AGENTS.md +++ /dev/null @@ -1,68 +0,0 @@ -# murx project instructions - -murx is a deliberately small terminal multiplexer: one C99 source file -(`murx.c`), no dependencies, no config file. - -## Build - -```sh -make # cc -O2 -std=c99 -Wall -Wextra -o murx murx.c -make clean -``` - -There is no test suite. Build must stay warning-free except for the known -pre-existing `g_spawn_err` unused-variable warning. Use a throwaway harness -outside the repo for geometry/logic checks; do not leave test files behind. - -## Conventions - -- Keep changes inside `murx.c` where possible; the single-file design is - intentional. -- `README.md` is user-facing documentation. Update it when shortcuts, behavior, - or limitations change. -- Match the existing style: 4-space indentation, C99 declarations, `/* */` - comments. -- Do not remove existing user changes in the working tree; check `git diff` - before editing and keep unrelated edits intact. - -## Layout model (important for navigation/resizing) - -- Windows use a binary `Layout` tree: `L_COLS` (left/right split) or - `L_ROWS` (top/bottom split), with `Layout` x/y/w/h plus a `Pane` leaf. -- `layout_apply()` assigns pane content rectangles. With `--pane-titles`, - each leaf reserves its top row for a title and sets - `pane->y = layout->y + 1`. By default, content fills the leaf. -- Splits reserve one border column/row between children. With titles shown, - horizontal splits use the lower pane's title row as the separator; with titles - hidden, horizontal splits draw a border row like vertical splits. -- Pane movement must be based on rectangle edges, not centres. A pane is only - to the right if `p->x >= a->x + a->w` (and similar for the other directions). - Centre comparison wrongly classifies tall/wide panes that merely extend past - the active pane. - -## Current work (2026-10-30) - -Reworked `select_pane_dir()` in `murx.c` so `Ctrl-A h/j/k/l` and the arrow -keys choose the pane exactly left/down/up/right: - -1. Only panes strictly beyond the active pane's edge in the requested direction - are candidates. -2. Prefer candidates that overlap on the perpendicular axis. -3. Then choose the smallest edge distance in the direction of travel. -4. Break ties by perpendicular gap, then centre alignment. - -Verified with a temporary randomized split-layout simulation: the old -centre-based algorithm chose a pane outside the requested direction in many -cases; the new one never did and always preferred an overlapping candidate when -one existed. `make` succeeds with only the pre-existing warning above. - -### Terminal resize robustness - -The client now reconciles its size with `TIOCGWINSZ` every `SIZE_CHECK_MS` -(250 ms) instead of only reacting to `SIGWINCH`. Some terminals update the pty -size without delivering a signal, or deliver it before the new size is -visible; the periodic check corrects both. Keep the SIGWINCH self-pipe and flag -as the low-latency path. The session size is set by the most recently attached -or resized client, so reattaching from a larger terminal grows the session even -if an older client is still connected; smaller clients show the top-left part. -Use `Ctrl-A *` to list attached clients when diagnosing size reports. From f6cd548aefdd585659f37dc28e461566c7416677 Mon Sep 17 00:00:00 2001 From: hanez Date: Mon, 23 Nov 2026 18:00:54 +0100 Subject: [PATCH 05/18] Rename pane title option to --titles --- README.md | 6 +++--- RELEASES.md | 4 ++++ murx.1 | 6 +++--- murx.c | 4 ++-- os/alpine/APKBUILD | 6 +++--- os/arch/PKGBUILD | 6 +++--- 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 79d2866..7fa9e71 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ make ./murx --history 10000 work # keep up to 10,000 history lines per pane ./murx --clock work # show the status bar clock ./murx --hostname work # show the hostname: prefix in window titles -./murx --pane-titles work # show a title row above each pane +./murx --titles work # show a title row above each pane ./murx -l, --list-sessions # list running sessions without attaching ./murx --help # logo, version, usage and shortcuts ./murx -v, --version # print the version and exit @@ -71,7 +71,7 @@ and `--clock` to show the clock on the right. Use `--murx` to show `[murx]` on the left when `--cwd` is not enabled; the directory takes precedence if both are supplied. Use `--hostname` to show the `hostname:` prefix in window names and the outer terminal title. These display options are disabled by -default. Use `--pane-titles` to show the title row above each pane. These +default. Use `--titles` to show the title row above each pane. These options set the initial values for a new session. The `Configuration...` menu can change them in a running session (see [Menu](#menu)). To restore the previous default display, use @@ -388,7 +388,7 @@ Hard-coded: A root shell that does not run the hooks cannot report its privilege change. - Pane borders are thin box-drawing lines (`─`, `│`, `┬`, `┼`, ...) in `colour8`, drawn on the terminal's default background. Enable title rows - with `--pane-titles` or the Configuration menu. Each title row shows + with `--titles` or the Configuration menu. Each title row shows `[N: title]`. On the active pane, brackets and numbers use `colour7`, the separator uses `colour11`, and the title uses `colour15`. Inactive panes use `colour8`, `colour3`, and `colour12`. diff --git a/RELEASES.md b/RELEASES.md index 7eb06ff..e925faa 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,3 +1,7 @@ +# Unreleased + +- Renamed `--pane-titles` to `--titles`. + # murx 1.0.3 released **November 23, 2026** diff --git a/murx.1 b/murx.1 index ea8657e..37eb733 100644 --- a/murx.1 +++ b/murx.1 @@ -11,7 +11,7 @@ murx \- small persistent terminal multiplexer .RB [ \-\-clock ] .RB [ \-\-murx ] .RB [ \-\-hostname ] -.RB [ \-\-pane-titles ] +.RB [ \-\-titles ] .RB [ \-\- ] .RI [ session ] .br @@ -92,7 +92,7 @@ is not enabled. The directory takes precedence if both options are supplied. .B \-\-hostname Show the hostname: prefix in window names and the outer terminal title. .TP -.B \-\-pane-titles +.B \-\-titles Show the title row above each pane. Pane titles are off by default. .TP .BR \-h ", " \-\-help @@ -278,7 +278,7 @@ The outer terminal title follows [murx] program, or [murx] hostname:program with --hostname. Its [murx] prefix is always present; --murx controls only the status label. Hostnames are shortened at the first dot. -With \-\-pane-titles enabled, each pane has a title row above its content showing +With \-\-titles enabled, each pane has a title row above its content showing [R N: title R], where N is the pane number. Active pane titles use colour7 brackets/numbers, colour11 separator and colour15 title; inactive panes use colour8, colour3 and colour12. Toggle title rows in the Configuration menu. diff --git a/murx.c b/murx.c index 6157183..ad70350 100644 --- a/murx.c +++ b/murx.c @@ -4994,7 +4994,7 @@ static void print_help(FILE *out) { help_row(out, "--clock", "show clock in status bar"); help_row(out, "--murx", "show [murx] in status bar unless --cwd is set"); help_row(out, "--hostname", "show hostname: prefix in window titles"); - help_row(out, "--pane-titles", "show the title row above each pane (default: off)"); + help_row(out, "--titles", "show the title row above each pane (default: off)"); fputs("\n" "Without -s or -c, an existing session keeps its position and color.\n" @@ -5095,7 +5095,7 @@ int main(int argc, char **argv) { display.show_murx = 1; } else if (strcmp(option, "--hostname") == 0) { display.show_hostname = 1; - } else if (strcmp(option, "--pane-titles") == 0) { + } else if (strcmp(option, "--titles") == 0) { display.show_pane_titles = 1; } else if (strcmp(option, "-p") == 0 || strcmp(option, "--prefix") == 0) { if (argi >= argc || !parse_prefix(argv[argi], &prefix)) { diff --git a/os/alpine/APKBUILD b/os/alpine/APKBUILD index 60ab8b2..7a53009 100644 --- a/os/alpine/APKBUILD +++ b/os/alpine/APKBUILD @@ -26,10 +26,10 @@ package() { } sha512sums=" -f39b354e08d4200f604ddf699d918eb39481219f5eec8a66369c83bd0bcad3121e09584d3fefc1749a85b31fffef5609359dc44fa4d5bcce84e5798483622f58 murx.c +bebecd0e6129ea313febe21a49e2721cc3e0409571f3db8bfb7fa0e36dec9bec6bb339b50d857e1a05bb4a22829bc26f1ab387d5e33ad8a1e71d059545cdb443 murx.c ac75bfe596fae665ba882a10f5d16551bdd02cd601b786364763ac74dbc651c386d3a464eb63e0344354b953611629135190633e3b8ff3a8ef0f0849d60a3f7b Makefile -84713fc8e6b244292bdd53d6071578cde67b9fe136d85e4b4809eceab53dbb6d86f33fd846ec87eeccefdbd006744ca7898b677f43b3447a1c357b8a6a2f8301 murx.1 -167090193501e8f2fbe1a6c34369b7ee556ca5c84207b54e8952b19b44ef6d4eac89c03ec450956284d6754dd3c00ffa2241976545909d9504e30802c9c28e26 MURX-README.md +9a7f4aa4baf95bb53ccb0fbc51d99bb685c201d182264d981ae6af63da2e33c181030e49b881b02a73bf9d54e2a6ece6db2a4b38962434c672c968882ab5938c murx.1 +a89076262e2b5b0901d377a76c175b8f2bb213c55ceaa59ce9ccfd8e498fc12e4543e599e106ed6fe1bda3d1bcaa1cb9e0e9687fff5ea28d772795123682743c MURX-README.md 2fe33ba22c5f68e124904be594208f050be20f33d115f9a56f60cac93304102da32e6a7e78154e831d3704da7ca8bfefd7025e7b8901e65babcd83e7342f6382 LICENSE 4d32dba475e5f9818fcd008068b011cbae9fc4b8e29897c933775d6660f44a7992d08a1550320d83233af729a42b241ef1d182bf5983ef2f64deab76cab2260d AUTHORS " diff --git a/os/arch/PKGBUILD b/os/arch/PKGBUILD index 18c9ac1..0fd7393 100644 --- a/os/arch/PKGBUILD +++ b/os/arch/PKGBUILD @@ -8,10 +8,10 @@ url='https://codeberg.org/armin/murx' license=('Apache-2.0') depends=('glibc') source=('murx.c' 'Makefile' 'murx.1' 'MURX-README.md' 'LICENSE' 'AUTHORS') -sha256sums=('da9a5d8451c396f45d5c1839ca762d066fa531b42339db81d1e478b9ad6559f0' +sha256sums=('464b37bb35d329bf40ef77175e3670fbe7dfc0b73d58740362b93569dc2fabed' '78a9c19c212e8038422e1bb4bb96d9b25eb19ad1359489cd32edf9e1a76638b2' - 'b0965c6c8cd73cef1e578e4a8295df0899b43f20ab9a9649150790a3b1434c1b' - '7cb95cc829fd2f9756cbb611aa4ddb8dc97853ccf360efd18d1423628e484aa1' + '06633deeeaf1f3eda60a2463c393b3c4a9ef1c5fe08d28fb5357d5ec18dbec7c' + '2b0d69adee164b43e5f099b2bb3a33b302ca5c21e8c99ff0f838d486c53f6793' '31c5556be4cdd9bf52bb55f18ead0c68a4f0e793c2c2dab0a2a2c6d92407d0d4' 'dbc8a4fc569d4cd7bcd45516ccc98c1396fce0682c262103069c8f5150538cdb') From 71517ec2465c485c7b4ca2d336d041203ddbb474 Mon Sep 17 00:00:00 2001 From: hanez Date: Mon, 23 Nov 2026 18:16:04 +0100 Subject: [PATCH 06/18] Add short aliases for all command-line options --- README.md | 18 +++++++++--------- RELEASES.md | 3 +++ murx.1 | 24 ++++++++++++------------ murx.c | 24 ++++++++++++------------ 4 files changed, 36 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 7fa9e71..0e388e4 100644 --- a/README.md +++ b/README.md @@ -14,16 +14,16 @@ make ./murx --prefix x work # same as -p x ./murx -s bottom work # show the session status line at the bottom ./murx --status bottom work # same as -s bottom -./murx --cwd work # show the current directory in the status bar -./murx --murx work # show [murx] on the left of the status bar +./murx -d work # --cwd, show the current directory in the status bar +./murx -m work # --murx, show [murx] on the left of the status bar ./murx -c 191a1c work # use a grey status bar background -./murx --history 10000 work # keep up to 10,000 history lines per pane -./murx --clock work # show the status bar clock -./murx --hostname work # show the hostname: prefix in window titles -./murx --titles work # show a title row above each pane -./murx -l, --list-sessions # list running sessions without attaching -./murx --help # logo, version, usage and shortcuts -./murx -v, --version # print the version and exit +./murx -H 10000 work # --history, keep up to 10,000 history lines per pane +./murx -C work # --clock, show the status bar clock +./murx -n work # --hostname, show the hostname: prefix in window titles +./murx -t work # --titles, show a title row above each pane +./murx -l # --list-sessions, list running sessions without attaching +./murx -h # --help, logo, version, usage and shortcuts +./murx -v # --version, print the version and exit ``` Detach with `Ctrl-A d`. Run `murx` again to reattach. diff --git a/RELEASES.md b/RELEASES.md index e925faa..0fda5c4 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,5 +1,8 @@ # Unreleased +- Added short options for `--history` (`-H`), `--cwd` (`-d`), + `--clock` (`-C`), `--murx` (`-m`), `--hostname` (`-n`), and + `--titles` (`-t`). - Renamed `--pane-titles` to `--titles`. # murx 1.0.3 released diff --git a/murx.1 b/murx.1 index 37eb733..7bf930f 100644 --- a/murx.1 +++ b/murx.1 @@ -6,12 +6,12 @@ murx \- small persistent terminal multiplexer .RB [ \-p " letter"] .RB [ \-s " top|bottom"] .RB [ \-c " RRGGBB"] -.RB [ \-\-history " lines"] -.RB [ \-\-cwd ] -.RB [ \-\-clock ] -.RB [ \-\-murx ] -.RB [ \-\-hostname ] -.RB [ \-\-titles ] +.RB [ \-H " lines"] +.RB [ \-d ] +.RB [ \-C ] +.RB [ \-m ] +.RB [ \-n ] +.RB [ \-t ] .RB [ \-\- ] .RI [ session ] .br @@ -46,7 +46,7 @@ hyphens or underscores. Use before a name beginning with a hyphen. .SH OPTIONS .TP -.BR \-\-history " lines" +.BR \-H ", " \-\-history " lines" Set the maximum number of normal-screen history lines retained per pane in a new session. Accepts 0 to 100,000, with 0 disabling history retention. Reattaching preserves the existing session's limit. @@ -78,21 +78,21 @@ Supply six hexadecimal digits, such as 000000 for black. Omitting this option preserves the session's color when reattaching. New sessions use the terminal's default background unless a color is supplied. .TP -.B \-\-cwd +.BR \-d ", " \-\-cwd Show the current directory at the left of the status line. .TP -.B \-\-clock +.BR \-C ", " \-\-clock Show the status clock. .TP -.B \-\-murx +.BR \-m ", " \-\-murx Show the [murx] label at the left of the status line when .B \-\-cwd is not enabled. The directory takes precedence if both options are supplied. .TP -.B \-\-hostname +.BR \-n ", " \-\-hostname Show the hostname: prefix in window names and the outer terminal title. .TP -.B \-\-titles +.BR \-t ", " \-\-titles Show the title row above each pane. Pane titles are off by default. .TP .BR \-h ", " \-\-help diff --git a/murx.c b/murx.c index ad70350..c85958c 100644 --- a/murx.c +++ b/murx.c @@ -4989,12 +4989,12 @@ static void print_help(FILE *out) { snprintf(history_help, sizeof history_help, "history lines per pane in new sessions (0-%d, default: %d)", MAX_HISTORY_LINES, DEFAULT_HISTORY_LINES); - help_row(out, "--history LINES", history_help); - help_row(out, "--cwd", "show current directory in status bar"); - help_row(out, "--clock", "show clock in status bar"); - help_row(out, "--murx", "show [murx] in status bar unless --cwd is set"); - help_row(out, "--hostname", "show hostname: prefix in window titles"); - help_row(out, "--titles", "show the title row above each pane (default: off)"); + help_row(out, "-H, --history LINES", history_help); + help_row(out, "-d, --cwd", "show current directory in status bar"); + help_row(out, "-C, --clock", "show clock in status bar"); + help_row(out, "-m, --murx", "show [murx] in status bar unless --cwd is set"); + help_row(out, "-n, --hostname", "show hostname: prefix in window titles"); + help_row(out, "-t, --titles", "show the title row above each pane (default: off)"); fputs("\n" "Without -s or -c, an existing session keeps its position and color.\n" @@ -5076,7 +5076,7 @@ int main(int argc, char **argv) { } if (strcmp(option, "-l") == 0 || strcmp(option, "--list-sessions") == 0) { list = 1; - } else if (strcmp(option, "--history") == 0) { + } else if (strcmp(option, "-H") == 0 || strcmp(option, "--history") == 0) { const char *value = argi < argc ? argv[argi] : ""; char *end; long lines = strtol(value, &end, 10); @@ -5087,15 +5087,15 @@ int main(int argc, char **argv) { } history_limit = (int)lines; argi++; - } else if (strcmp(option, "--cwd") == 0) { + } else if (strcmp(option, "-d") == 0 || strcmp(option, "--cwd") == 0) { display.show_cwd = 1; - } else if (strcmp(option, "--clock") == 0) { + } else if (strcmp(option, "-C") == 0 || strcmp(option, "--clock") == 0) { display.show_clock = 1; - } else if (strcmp(option, "--murx") == 0) { + } else if (strcmp(option, "-m") == 0 || strcmp(option, "--murx") == 0) { display.show_murx = 1; - } else if (strcmp(option, "--hostname") == 0) { + } else if (strcmp(option, "-n") == 0 || strcmp(option, "--hostname") == 0) { display.show_hostname = 1; - } else if (strcmp(option, "--titles") == 0) { + } else if (strcmp(option, "-t") == 0 || strcmp(option, "--titles") == 0) { display.show_pane_titles = 1; } else if (strcmp(option, "-p") == 0 || strcmp(option, "--prefix") == 0) { if (argi >= argc || !parse_prefix(argv[argi], &prefix)) { From b803115d643c880a4d3c79fd41da4dc4d1bb7a83 Mon Sep 17 00:00:00 2001 From: hanez Date: Mon, 23 Nov 2026 18:16:59 +0100 Subject: [PATCH 07/18] Refresh Alpine and Arch package checksums --- os/alpine/APKBUILD | 6 +++--- os/arch/PKGBUILD | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/os/alpine/APKBUILD b/os/alpine/APKBUILD index 7a53009..de59b53 100644 --- a/os/alpine/APKBUILD +++ b/os/alpine/APKBUILD @@ -26,10 +26,10 @@ package() { } sha512sums=" -bebecd0e6129ea313febe21a49e2721cc3e0409571f3db8bfb7fa0e36dec9bec6bb339b50d857e1a05bb4a22829bc26f1ab387d5e33ad8a1e71d059545cdb443 murx.c +0df7be74bc76c32ead5c71e617f618296cdb3aa86760da748f1e4091cb2ad24d6c522f4aae4e4c82296222608e5be5c1c7525e091af6e52faf938f2466f63587 murx.c ac75bfe596fae665ba882a10f5d16551bdd02cd601b786364763ac74dbc651c386d3a464eb63e0344354b953611629135190633e3b8ff3a8ef0f0849d60a3f7b Makefile -9a7f4aa4baf95bb53ccb0fbc51d99bb685c201d182264d981ae6af63da2e33c181030e49b881b02a73bf9d54e2a6ece6db2a4b38962434c672c968882ab5938c murx.1 -a89076262e2b5b0901d377a76c175b8f2bb213c55ceaa59ce9ccfd8e498fc12e4543e599e106ed6fe1bda3d1bcaa1cb9e0e9687fff5ea28d772795123682743c MURX-README.md +7546e0d84cb9094b4b2ac14e05d38a37270c2a4451f3d41aaa7b0b38290acb0ff6de821331634c802d08568817cf1ed0fbb5afd6734ef4a8155720b826ab6ce9 murx.1 +22d6907c0ea385c7368880f71f0ce9f6549a6623718e6447132d74b4cd18085dcbc861593f91b70decc83bf859ce93403e613e6b967a205edd51f8ecd51ddd15 MURX-README.md 2fe33ba22c5f68e124904be594208f050be20f33d115f9a56f60cac93304102da32e6a7e78154e831d3704da7ca8bfefd7025e7b8901e65babcd83e7342f6382 LICENSE 4d32dba475e5f9818fcd008068b011cbae9fc4b8e29897c933775d6660f44a7992d08a1550320d83233af729a42b241ef1d182bf5983ef2f64deab76cab2260d AUTHORS " diff --git a/os/arch/PKGBUILD b/os/arch/PKGBUILD index 0fd7393..623d10d 100644 --- a/os/arch/PKGBUILD +++ b/os/arch/PKGBUILD @@ -8,10 +8,10 @@ url='https://codeberg.org/armin/murx' license=('Apache-2.0') depends=('glibc') source=('murx.c' 'Makefile' 'murx.1' 'MURX-README.md' 'LICENSE' 'AUTHORS') -sha256sums=('464b37bb35d329bf40ef77175e3670fbe7dfc0b73d58740362b93569dc2fabed' +sha256sums=('c4c21bc98923bee42f1dc8154ec67d53614e4e5a2f82b844efa9e554ed1a6eb7' '78a9c19c212e8038422e1bb4bb96d9b25eb19ad1359489cd32edf9e1a76638b2' - '06633deeeaf1f3eda60a2463c393b3c4a9ef1c5fe08d28fb5357d5ec18dbec7c' - '2b0d69adee164b43e5f099b2bb3a33b302ca5c21e8c99ff0f838d486c53f6793' + 'a4b48ce1c847869956ea52eac50c51446a9e6f720d8e4b211cb97a78a7f53663' + 'a3f4b484eb18b3277370b495ff7174fb9aac48b41759f838d5ccdec8c37c5ccf' '31c5556be4cdd9bf52bb55f18ead0c68a4f0e793c2c2dab0a2a2c6d92407d0d4' 'dbc8a4fc569d4cd7bcd45516ccc98c1396fce0682c262103069c8f5150538cdb') From 3b4a45077157d4074175faea739c51cec293040c Mon Sep 17 00:00:00 2001 From: hanez Date: Mon, 23 Nov 2026 18:58:40 +0100 Subject: [PATCH 08/18] Some small --help fix. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0e388e4..1e60ce2 100644 --- a/README.md +++ b/README.md @@ -16,13 +16,13 @@ make ./murx --status bottom work # same as -s bottom ./murx -d work # --cwd, show the current directory in the status bar ./murx -m work # --murx, show [murx] on the left of the status bar -./murx -c 191a1c work # use a grey status bar background +./murx -c 191a1c work # --color, use a grey status bar background ./murx -H 10000 work # --history, keep up to 10,000 history lines per pane ./murx -C work # --clock, show the status bar clock ./murx -n work # --hostname, show the hostname: prefix in window titles ./murx -t work # --titles, show a title row above each pane ./murx -l # --list-sessions, list running sessions without attaching -./murx -h # --help, logo, version, usage and shortcuts +./murx -h # --help, usage and shortcuts ./murx -v # --version, print the version and exit ``` From 465648e448170943f9c5e9a146cc3f6e4bdcc3f6 Mon Sep 17 00:00:00 2001 From: hanez Date: Mon, 23 Nov 2026 19:13:49 +0100 Subject: [PATCH 09/18] Group history limits with configuration constants --- murx.c | 5 ++--- os/alpine/APKBUILD | 4 ++-- os/arch/PKGBUILD | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/murx.c b/murx.c index c85958c..046baea 100644 --- a/murx.c +++ b/murx.c @@ -149,6 +149,8 @@ static int send_msg(int fd, uint32_t type, const void *data, size_t len); #define SIZE_CHECK_MS 250 #define NAME_CHECK_MS 1000 #define MENU_MAX_DEPTH 8 +#define DEFAULT_HISTORY_LINES 2000 +#define MAX_HISTORY_LINES 100000 /* ------------------------------------------------------------------ */ /* small helpers */ @@ -393,9 +395,6 @@ typedef enum { PS_STRING_ESC } ParseState; -#define DEFAULT_HISTORY_LINES 2000 -#define MAX_HISTORY_LINES 100000 - typedef struct Pane Pane; struct Pane { diff --git a/os/alpine/APKBUILD b/os/alpine/APKBUILD index de59b53..2eb341a 100644 --- a/os/alpine/APKBUILD +++ b/os/alpine/APKBUILD @@ -26,10 +26,10 @@ package() { } sha512sums=" -0df7be74bc76c32ead5c71e617f618296cdb3aa86760da748f1e4091cb2ad24d6c522f4aae4e4c82296222608e5be5c1c7525e091af6e52faf938f2466f63587 murx.c +f861459121c3beec590a4d9a40f1a66ebc7933c024cca0c9c18a1608ca11e5ad1b064e0f732bafa0c153e57b45faa10c623387fc162c43aab81bd7607435fd6f murx.c ac75bfe596fae665ba882a10f5d16551bdd02cd601b786364763ac74dbc651c386d3a464eb63e0344354b953611629135190633e3b8ff3a8ef0f0849d60a3f7b Makefile 7546e0d84cb9094b4b2ac14e05d38a37270c2a4451f3d41aaa7b0b38290acb0ff6de821331634c802d08568817cf1ed0fbb5afd6734ef4a8155720b826ab6ce9 murx.1 -22d6907c0ea385c7368880f71f0ce9f6549a6623718e6447132d74b4cd18085dcbc861593f91b70decc83bf859ce93403e613e6b967a205edd51f8ecd51ddd15 MURX-README.md +162b917a63a481554368083ba4d285c759c4c62148b073d658a8e32840f1aeffedff369876190cc0d2f164efdb800220bee882d823fa350b2063d022842e1182 MURX-README.md 2fe33ba22c5f68e124904be594208f050be20f33d115f9a56f60cac93304102da32e6a7e78154e831d3704da7ca8bfefd7025e7b8901e65babcd83e7342f6382 LICENSE 4d32dba475e5f9818fcd008068b011cbae9fc4b8e29897c933775d6660f44a7992d08a1550320d83233af729a42b241ef1d182bf5983ef2f64deab76cab2260d AUTHORS " diff --git a/os/arch/PKGBUILD b/os/arch/PKGBUILD index 623d10d..e415b8e 100644 --- a/os/arch/PKGBUILD +++ b/os/arch/PKGBUILD @@ -8,10 +8,10 @@ url='https://codeberg.org/armin/murx' license=('Apache-2.0') depends=('glibc') source=('murx.c' 'Makefile' 'murx.1' 'MURX-README.md' 'LICENSE' 'AUTHORS') -sha256sums=('c4c21bc98923bee42f1dc8154ec67d53614e4e5a2f82b844efa9e554ed1a6eb7' +sha256sums=('936dc8c7fb6d1538f8a1d8f9110eeb8bc0a627ca4847f8edffb7a9afcf4f7c53' '78a9c19c212e8038422e1bb4bb96d9b25eb19ad1359489cd32edf9e1a76638b2' 'a4b48ce1c847869956ea52eac50c51446a9e6f720d8e4b211cb97a78a7f53663' - 'a3f4b484eb18b3277370b495ff7174fb9aac48b41759f838d5ccdec8c37c5ccf' + 'd86bb6257dee64ff4709faf4ab8c1dc2d6adfc98b464978389bcfa88568e63fb' '31c5556be4cdd9bf52bb55f18ead0c68a4f0e793c2c2dab0a2a2c6d92407d0d4' 'dbc8a4fc569d4cd7bcd45516ccc98c1396fce0682c262103069c8f5150538cdb') From 4ca0d31b7da86c8792ee90e668ee0beacae5bcb3 Mon Sep 17 00:00:00 2001 From: hanez Date: Mon, 23 Nov 2026 19:56:16 +0100 Subject: [PATCH 10/18] Define the complete named xterm color palette --- murx.c | 271 +++++++++++++++++++++++++++++++++++++++++++-- os/alpine/APKBUILD | 2 +- os/arch/PKGBUILD | 2 +- 3 files changed, 261 insertions(+), 14 deletions(-) diff --git a/murx.c b/murx.c index 046baea..9d994dd 100644 --- a/murx.c +++ b/murx.c @@ -102,16 +102,263 @@ typedef struct { static int send_msg(int fd, uint32_t type, const void *data, size_t len); -/* colour palette */ -#define C_BLACK 0 -#define C_CYAN 6 -#define C_WHITE 7 -#define C_GREY 8 -#define C_RED 9 -#define C_YELLOW 11 -#define C_BLUE 12 -#define C_CYAN2 14 -#define C_BWHITE 15 +/* xterm-256 palette indices. The terminal defines the ANSI colours. */ +#define C_BLACK 0 +#define C_MAROON 1 +#define C_DGREEN 2 +#define C_OLIVE 3 +#define C_NAVY 4 +#define C_PURPLE 5 +#define C_CYAN 6 +#define C_WHITE 7 +#define C_GREY 8 +#define C_RED 9 +#define C_GREEN 10 +#define C_YELLOW 11 +#define C_BLUE 12 +#define C_MAGENTA 13 +#define C_CYAN2 14 +#define C_BWHITE 15 +#define C_GREY_0 16 +#define C_NAVY_BLUE 17 +#define C_DARK_BLUE 18 +#define C_BLUE_3_19 19 +#define C_BLUE_3_20 20 +#define C_BLUE_1 21 +#define C_DARK_GREEN 22 +#define C_DEEP_SKY_BLUE_4_23 23 +#define C_DEEP_SKY_BLUE_4_24 24 +#define C_DEEP_SKY_BLUE_4_25 25 +#define C_DODGER_BLUE_3 26 +#define C_DODGER_BLUE_2 27 +#define C_GREEN_4 28 +#define C_SPRING_GREEN_4 29 +#define C_TURQUOISE_4 30 +#define C_DEEP_SKY_BLUE_3_31 31 +#define C_DEEP_SKY_BLUE_3_32 32 +#define C_DODGER_BLUE_1 33 +#define C_GREEN_3_34 34 +#define C_SPRING_GREEN_3_35 35 +#define C_DARK_CYAN 36 +#define C_LIGHT_SEA_GREEN 37 +#define C_DEEP_SKY_BLUE_2 38 +#define C_DEEP_SKY_BLUE_1 39 +#define C_GREEN_3_40 40 +#define C_SPRING_GREEN_3_41 41 +#define C_SPRING_GREEN_2_42 42 +#define C_CYAN_3 43 +#define C_DARK_TURQUOISE 44 +#define C_TURQUOISE_2 45 +#define C_GREEN_1 46 +#define C_SPRING_GREEN_2_47 47 +#define C_SPRING_GREEN_1 48 +#define C_MEDIUM_SPRING_GREEN 49 +#define C_CYAN_2 50 +#define C_CYAN_1 51 +#define C_DARK_RED_52 52 +#define C_DEEP_PINK_4_53 53 +#define C_PURPLE_4_54 54 +#define C_PURPLE_4_55 55 +#define C_PURPLE_3 56 +#define C_BLUE_VIOLET 57 +#define C_ORANGE_4_58 58 +#define C_GREY_37 59 +#define C_MEDIUM_PURPLE_4 60 +#define C_SLATE_BLUE_3_61 61 +#define C_SLATE_BLUE_3_62 62 +#define C_ROYAL_BLUE_1 63 +#define C_CHARTREUSE_4 64 +#define C_DARK_SEA_GREEN_4_65 65 +#define C_PALE_TURQUOISE_4 66 +#define C_STEEL_BLUE 67 +#define C_STEEL_BLUE_3 68 +#define C_CORNFLOWER_BLUE 69 +#define C_CHARTREUSE_3_70 70 +#define C_DARK_SEA_GREEN_4_71 71 +#define C_CADET_BLUE_72 72 +#define C_CADET_BLUE_73 73 +#define C_SKY_BLUE_3 74 +#define C_STEEL_BLUE_1_75 75 +#define C_CHARTREUSE_3_76 76 +#define C_PALE_GREEN_3_77 77 +#define C_SEA_GREEN_3 78 +#define C_AQUAMARINE_3 79 +#define C_MEDIUM_TURQUOISE 80 +#define C_STEEL_BLUE_1_81 81 +#define C_CHARTREUSE_2_82 82 +#define C_SEA_GREEN_2 83 +#define C_SEA_GREEN_1_84 84 +#define C_SEA_GREEN_1_85 85 +#define C_AQUAMARINE_1_86 86 +#define C_DARK_SLATE_GRAY_2 87 +#define C_DARK_RED_88 88 +#define C_DEEP_PINK_4_89 89 +#define C_DARK_MAGENTA_90 90 +#define C_DARK_MAGENTA_91 91 +#define C_DARK_VIOLET_92 92 +#define C_PURPLE_93 93 +#define C_ORANGE_4_94 94 +#define C_LIGHT_PINK_4 95 +#define C_PLUM_4 96 +#define C_MEDIUM_PURPLE_3_97 97 +#define C_MEDIUM_PURPLE_3_98 98 +#define C_SLATE_BLUE_1 99 +#define C_YELLOW_4_100 100 +#define C_WHEAT_4 101 +#define C_GREY_53 102 +#define C_LIGHT_SLATE_GREY 103 +#define C_MEDIUM_PURPLE 104 +#define C_LIGHT_SLATE_BLUE 105 +#define C_YELLOW_4_106 106 +#define C_DARK_OLIVE_GREEN_3_107 107 +#define C_DARK_SEA_GREEN 108 +#define C_LIGHT_SKY_BLUE_3_109 109 +#define C_LIGHT_SKY_BLUE_3_110 110 +#define C_SKY_BLUE_2 111 +#define C_CHARTREUSE_2_112 112 +#define C_DARK_OLIVE_GREEN_3_113 113 +#define C_PALE_GREEN_3_114 114 +#define C_DARK_SEA_GREEN_3_115 115 +#define C_DARK_SLATE_GRAY_3 116 +#define C_SKY_BLUE_1 117 +#define C_CHARTREUSE_1 118 +#define C_LIGHT_GREEN_119 119 +#define C_LIGHT_GREEN_120 120 +#define C_PALE_GREEN_1_121 121 +#define C_AQUAMARINE_1_122 122 +#define C_DARK_SLATE_GRAY_1 123 +#define C_RED_3_124 124 +#define C_DEEP_PINK_4_125 125 +#define C_MEDIUM_VIOLET_RED 126 +#define C_MAGENTA_3_127 127 +#define C_DARK_VIOLET_128 128 +#define C_PURPLE_129 129 +#define C_DARK_ORANGE_3_130 130 +#define C_INDIAN_RED_131 131 +#define C_HOT_PINK_3_132 132 +#define C_MEDIUM_ORCHID_3 133 +#define C_MEDIUM_ORCHID 134 +#define C_MEDIUM_PURPLE_2_135 135 +#define C_DARK_GOLDENROD 136 +#define C_LIGHT_SALMON_3_137 137 +#define C_ROSY_BROWN 138 +#define C_GREY_63 139 +#define C_MEDIUM_PURPLE_2_140 140 +#define C_MEDIUM_PURPLE_1 141 +#define C_GOLD_3_142 142 +#define C_DARK_KHAKI 143 +#define C_NAVAJO_WHITE_3 144 +#define C_GREY_69 145 +#define C_LIGHT_STEEL_BLUE_3 146 +#define C_LIGHT_STEEL_BLUE 147 +#define C_YELLOW_3_148 148 +#define C_DARK_OLIVE_GREEN_3_149 149 +#define C_DARK_SEA_GREEN_3_150 150 +#define C_DARK_SEA_GREEN_2_151 151 +#define C_LIGHT_CYAN_3 152 +#define C_LIGHT_SKY_BLUE_1 153 +#define C_GREEN_YELLOW 154 +#define C_DARK_OLIVE_GREEN_2 155 +#define C_PALE_GREEN_1_156 156 +#define C_DARK_SEA_GREEN_2_157 157 +#define C_DARK_SEA_GREEN_1_158 158 +#define C_PALE_TURQUOISE_1 159 +#define C_RED_3_160 160 +#define C_DEEP_PINK_3_161 161 +#define C_DEEP_PINK_3_162 162 +#define C_MAGENTA_3_163 163 +#define C_MAGENTA_3_164 164 +#define C_MAGENTA_2_165 165 +#define C_DARK_ORANGE_3_166 166 +#define C_INDIAN_RED_167 167 +#define C_HOT_PINK_3_168 168 +#define C_HOT_PINK_2 169 +#define C_ORCHID 170 +#define C_MEDIUM_ORCHID_1_171 171 +#define C_ORANGE_3 172 +#define C_LIGHT_SALMON_3_173 173 +#define C_LIGHT_PINK_3 174 +#define C_PINK_3 175 +#define C_PLUM_3 176 +#define C_VIOLET 177 +#define C_GOLD_3_178 178 +#define C_LIGHT_GOLDENROD_3 179 +#define C_TAN 180 +#define C_MISTY_ROSE_3 181 +#define C_THISTLE_3 182 +#define C_PLUM_2 183 +#define C_YELLOW_3_184 184 +#define C_KHAKI_3 185 +#define C_LIGHT_GOLDENROD_2_186 186 +#define C_LIGHT_YELLOW_3 187 +#define C_GREY_84 188 +#define C_LIGHT_STEEL_BLUE_1 189 +#define C_YELLOW_2 190 +#define C_DARK_OLIVE_GREEN_1_191 191 +#define C_DARK_OLIVE_GREEN_1_192 192 +#define C_DARK_SEA_GREEN_1_193 193 +#define C_HONEYDEW_2 194 +#define C_LIGHT_CYAN_1 195 +#define C_RED_1 196 +#define C_DEEP_PINK_2 197 +#define C_DEEP_PINK_1_198 198 +#define C_DEEP_PINK_1_199 199 +#define C_MAGENTA_2_200 200 +#define C_MAGENTA_1 201 +#define C_ORANGE_RED_1 202 +#define C_INDIAN_RED_1_203 203 +#define C_INDIAN_RED_1_204 204 +#define C_HOT_PINK_205 205 +#define C_HOT_PINK_206 206 +#define C_MEDIUM_ORCHID_1_207 207 +#define C_DARK_ORANGE 208 +#define C_SALMON_1 209 +#define C_LIGHT_CORAL 210 +#define C_PALE_VIOLET_RED_1 211 +#define C_ORCHID_2 212 +#define C_ORCHID_1 213 +#define C_ORANGE_1 214 +#define C_SANDY_BROWN 215 +#define C_LIGHT_SALMON_1 216 +#define C_LIGHT_PINK_1 217 +#define C_PINK_1 218 +#define C_PLUM_1 219 +#define C_GOLD_1 220 +#define C_LIGHT_GOLDENROD_2_221 221 +#define C_LIGHT_GOLDENROD_2_222 222 +#define C_NAVAJO_WHITE_1 223 +#define C_MISTY_ROSE_1 224 +#define C_THISTLE_1 225 +#define C_YELLOW_1 226 +#define C_LIGHT_GOLDENROD_1 227 +#define C_KHAKI_1 228 +#define C_WHEAT_1 229 +#define C_CORNSILK_1 230 +#define C_GREY_100 231 +#define C_GREY_3 232 +#define C_GREY_7 233 +#define C_GREY_11 234 +#define C_GREY_15 235 +#define C_GREY_19 236 +#define C_GREY_23 237 +#define C_GREY_27 238 +#define C_GREY_30 239 +#define C_GREY_35 240 +#define C_GREY_39 241 +#define C_GREY_42 242 +#define C_GREY_46 243 +#define C_GREY_50 244 +#define C_GREY_54 245 +#define C_GREY_58 246 +#define C_GREY_62 247 +#define C_GREY_66 248 +#define C_GREY_70 249 +#define C_GREY_74 250 +#define C_GREY_78 251 +#define C_GREY_82 252 +#define C_GREY_85 253 +#define C_GREY_89 254 +#define C_GREY_93 255 /* Pane borders: thin box-drawing lines in a muted grey, drawn over the terminal's own background. */ @@ -2748,7 +2995,7 @@ static int color256_from_rgb(int r, int g, int b) { int cr = nearest_cube_level(r, &ri); int cg = nearest_cube_level(g, &gi); int cb = nearest_cube_level(b, &bi); - int cube = 16 + 36 * ri + 6 * gi + bi; + int cube = C_GREY_0 + 36 * ri + 6 * gi + bi; long cubed = (long)(r - cr) * (r - cr) + (long)(g - cg) * (g - cg) + (long)(b - cb) * (b - cb); @@ -2762,7 +3009,7 @@ static int color256_from_rgb(int r, int g, int b) { (long)(g - gv) * (g - gv) + (long)(b - gv) * (b - gv); - if (grayd < cubed) return 232 + gidx; + if (grayd < cubed) return C_GREY_3 + gidx; return cube; } diff --git a/os/alpine/APKBUILD b/os/alpine/APKBUILD index 2eb341a..8c43a08 100644 --- a/os/alpine/APKBUILD +++ b/os/alpine/APKBUILD @@ -26,7 +26,7 @@ package() { } sha512sums=" -f861459121c3beec590a4d9a40f1a66ebc7933c024cca0c9c18a1608ca11e5ad1b064e0f732bafa0c153e57b45faa10c623387fc162c43aab81bd7607435fd6f murx.c +299f4fcc053bcf46313ad34655aaf9180b59dc3a86758fd24e848c0cb1933d99ceeb56e4f85c592dd612d625f55b118284ee6a94c991216af61daa343091d518 murx.c ac75bfe596fae665ba882a10f5d16551bdd02cd601b786364763ac74dbc651c386d3a464eb63e0344354b953611629135190633e3b8ff3a8ef0f0849d60a3f7b Makefile 7546e0d84cb9094b4b2ac14e05d38a37270c2a4451f3d41aaa7b0b38290acb0ff6de821331634c802d08568817cf1ed0fbb5afd6734ef4a8155720b826ab6ce9 murx.1 162b917a63a481554368083ba4d285c759c4c62148b073d658a8e32840f1aeffedff369876190cc0d2f164efdb800220bee882d823fa350b2063d022842e1182 MURX-README.md diff --git a/os/arch/PKGBUILD b/os/arch/PKGBUILD index e415b8e..624a9de 100644 --- a/os/arch/PKGBUILD +++ b/os/arch/PKGBUILD @@ -8,7 +8,7 @@ url='https://codeberg.org/armin/murx' license=('Apache-2.0') depends=('glibc') source=('murx.c' 'Makefile' 'murx.1' 'MURX-README.md' 'LICENSE' 'AUTHORS') -sha256sums=('936dc8c7fb6d1538f8a1d8f9110eeb8bc0a627ca4847f8edffb7a9afcf4f7c53' +sha256sums=('4ab7d155c3d9b23c22fc5792837ce2dd4e020cf0998edb743e7726edee73b438' '78a9c19c212e8038422e1bb4bb96d9b25eb19ad1359489cd32edf9e1a76638b2' 'a4b48ce1c847869956ea52eac50c51446a9e6f720d8e4b211cb97a78a7f53663' 'd86bb6257dee64ff4709faf4ab8c1dc2d6adfc98b464978389bcfa88568e63fb' From f517cad02546ecd3c4d372af94d3b91c5117d37c Mon Sep 17 00:00:00 2001 From: hanez Date: Mon, 23 Nov 2026 20:06:02 +0100 Subject: [PATCH 11/18] Accept xterm color names for the status bar background --- README.md | 9 +- murx.1 | 9 +- murx.c | 314 ++++++++++++++++++++++++++++++++++++++++++++- os/alpine/APKBUILD | 6 +- os/arch/PKGBUILD | 6 +- 5 files changed, 326 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 1e60ce2..3176a3e 100644 --- a/README.md +++ b/README.md @@ -396,9 +396,12 @@ Hard-coded: - Menus use a black background with a `colour12` frame, `colour11` titles and selection, `colour14` accents and dim `colour8` hints and separators. -Use `-c RRGGBB` or `--color RRGGBB` to set the session's status bar -background for all attached clients. Supply six hexadecimal digits, such as -`000000` for black. The session remembers the color across reattachments. New +Use `-c COLOR` or `--color COLOR` to set the session's status bar +background for all attached clients. Supply six hexadecimal digits such as +`191a1c`, or an xterm palette name such as `NavyBlue` or `navy-blue`. Names +are case-insensitive, and spaces, hyphens and underscores are ignored. A +repeated name selects the lowest palette index. Use `Blue3:20` to select a +specific entry. The session remembers the color across reattachments. New sessions use the terminal's default background unless a color is supplied. Colours are written to the outer terminal using 256-colour SGR (`38;5;n` / diff --git a/murx.1 b/murx.1 index 7bf930f..f985bf1 100644 --- a/murx.1 +++ b/murx.1 @@ -5,7 +5,7 @@ murx \- small persistent terminal multiplexer .B murx .RB [ \-p " letter"] .RB [ \-s " top|bottom"] -.RB [ \-c " RRGGBB"] +.RB [ \-c " COLOR"] .RB [ \-H " lines"] .RB [ \-d ] .RB [ \-C ] @@ -72,9 +72,12 @@ New sessions default to top. An explicit choice changes an existing session for all clients. Omitting this option preserves the session's position. Prompts and messages follow the status line. .TP -.BR \-c " RRGGBB, " \-\-color " RRGGBB" +.BR \-c " COLOR, " \-\-color " COLOR" Set the session's status bar background for all attached clients. -Supply six hexadecimal digits, such as 000000 for black. +Supply six hexadecimal digits (RRGGBB), such as 191a1c, or an xterm palette +name such as NavyBlue or navy-blue. Names are case-insensitive, and spaces, +hyphens and underscores are ignored. Repeated names select the lowest +palette index. Append :INDEX to choose a specific entry, as in Blue3:20. Omitting this option preserves the session's color when reattaching. New sessions use the terminal's default background unless a color is supplied. .TP diff --git a/murx.c b/murx.c index 9d994dd..410230f 100644 --- a/murx.c +++ b/murx.c @@ -52,6 +52,7 @@ #include #include #include +#include #include #include #include @@ -384,6 +385,7 @@ static int send_msg(int fd, uint32_t type, const void *data, size_t len); #define DEFAULT_COLOR (-1) #define RGB_FLAG 0x01000000 +#define INDEXED_COLOR_FLAG 0x02000000 #define WIDE_CONT 0xFFFFFFFFu #define MAX_DIMENSION 1000 /* resource policy, not a C type limit */ @@ -4375,7 +4377,11 @@ static void handle_message(Client *c, Session *s, uint32_t type, const unsigned if (status > 2) { c->dead = 1; return; } uint32_t color = 0; if (len >= 24) memcpy(&color, data + 20, 4); - if (color && (color >> 24) != 1) { c->dead = 1; return; } + if (color && (color & 0xff000000u) != RGB_FLAG && + (color & ~0xffu) != INDEXED_COLOR_FLAG) { + c->dead = 1; + return; + } if (color) s->status_bg = (int32_t)color; if (status) { s->status_bottom = status == 2; @@ -5230,7 +5236,7 @@ static void print_help(FILE *out) { help_row(out, "-l, --list-sessions", "list running sessions without attaching"); help_row(out, "-p, --prefix LETTER", "client prefix Ctrl-LETTER (a-z, default: a)"); help_row(out, "-s, --status POSITION", "status line: top or bottom (new sessions: top)"); - help_row(out, "-c, --color RRGGBB", "status bar background, six hex digits (e.g. 000000)"); + help_row(out, "-c, --color COLOR", "status bar background: xterm name or RRGGBB"); char history_help[96]; snprintf(history_help, sizeof history_help, "history lines per pane in new sessions (0-%d, default: %d)", @@ -5243,6 +5249,7 @@ static void print_help(FILE *out) { help_row(out, "-t, --titles", "show the title row above each pane (default: off)"); fputs("\n" + "For repeated xterm names, add :INDEX (e.g. Blue3:20).\n" "Without -s or -c, an existing session keeps its position and color.\n" "Display options set new session values and can be changed later from\n" "the Configuration menu.\n" @@ -5299,6 +5306,301 @@ static int parse_prefix(const char *text, unsigned char *prefix) { return 1; } +static const char *const xterm_color_names[] = { + [C_BLACK] = "Black", + [C_MAROON] = "Maroon", + [C_DGREEN] = "Green", + [C_OLIVE] = "Olive", + [C_NAVY] = "Navy", + [C_PURPLE] = "Purple", + [C_CYAN] = "Teal", + [C_WHITE] = "Silver", + [C_GREY] = "Grey", + [C_RED] = "Red", + [C_GREEN] = "Lime", + [C_YELLOW] = "Yellow", + [C_BLUE] = "Blue", + [C_MAGENTA] = "Fuchsia", + [C_CYAN2] = "Aqua", + [C_BWHITE] = "White", + [C_GREY_0] = "Grey0", + [C_NAVY_BLUE] = "NavyBlue", + [C_DARK_BLUE] = "DarkBlue", + [C_BLUE_3_19] = "Blue3", + [C_BLUE_3_20] = "Blue3", + [C_BLUE_1] = "Blue1", + [C_DARK_GREEN] = "DarkGreen", + [C_DEEP_SKY_BLUE_4_23] = "DeepSkyBlue4", + [C_DEEP_SKY_BLUE_4_24] = "DeepSkyBlue4", + [C_DEEP_SKY_BLUE_4_25] = "DeepSkyBlue4", + [C_DODGER_BLUE_3] = "DodgerBlue3", + [C_DODGER_BLUE_2] = "DodgerBlue2", + [C_GREEN_4] = "Green4", + [C_SPRING_GREEN_4] = "SpringGreen4", + [C_TURQUOISE_4] = "Turquoise4", + [C_DEEP_SKY_BLUE_3_31] = "DeepSkyBlue3", + [C_DEEP_SKY_BLUE_3_32] = "DeepSkyBlue3", + [C_DODGER_BLUE_1] = "DodgerBlue1", + [C_GREEN_3_34] = "Green3", + [C_SPRING_GREEN_3_35] = "SpringGreen3", + [C_DARK_CYAN] = "DarkCyan", + [C_LIGHT_SEA_GREEN] = "LightSeaGreen", + [C_DEEP_SKY_BLUE_2] = "DeepSkyBlue2", + [C_DEEP_SKY_BLUE_1] = "DeepSkyBlue1", + [C_GREEN_3_40] = "Green3", + [C_SPRING_GREEN_3_41] = "SpringGreen3", + [C_SPRING_GREEN_2_42] = "SpringGreen2", + [C_CYAN_3] = "Cyan3", + [C_DARK_TURQUOISE] = "DarkTurquoise", + [C_TURQUOISE_2] = "Turquoise2", + [C_GREEN_1] = "Green1", + [C_SPRING_GREEN_2_47] = "SpringGreen2", + [C_SPRING_GREEN_1] = "SpringGreen1", + [C_MEDIUM_SPRING_GREEN] = "MediumSpringGreen", + [C_CYAN_2] = "Cyan2", + [C_CYAN_1] = "Cyan1", + [C_DARK_RED_52] = "DarkRed", + [C_DEEP_PINK_4_53] = "DeepPink4", + [C_PURPLE_4_54] = "Purple4", + [C_PURPLE_4_55] = "Purple4", + [C_PURPLE_3] = "Purple3", + [C_BLUE_VIOLET] = "BlueViolet", + [C_ORANGE_4_58] = "Orange4", + [C_GREY_37] = "Grey37", + [C_MEDIUM_PURPLE_4] = "MediumPurple4", + [C_SLATE_BLUE_3_61] = "SlateBlue3", + [C_SLATE_BLUE_3_62] = "SlateBlue3", + [C_ROYAL_BLUE_1] = "RoyalBlue1", + [C_CHARTREUSE_4] = "Chartreuse4", + [C_DARK_SEA_GREEN_4_65] = "DarkSeaGreen4", + [C_PALE_TURQUOISE_4] = "PaleTurquoise4", + [C_STEEL_BLUE] = "SteelBlue", + [C_STEEL_BLUE_3] = "SteelBlue3", + [C_CORNFLOWER_BLUE] = "CornflowerBlue", + [C_CHARTREUSE_3_70] = "Chartreuse3", + [C_DARK_SEA_GREEN_4_71] = "DarkSeaGreen4", + [C_CADET_BLUE_72] = "CadetBlue", + [C_CADET_BLUE_73] = "CadetBlue", + [C_SKY_BLUE_3] = "SkyBlue3", + [C_STEEL_BLUE_1_75] = "SteelBlue1", + [C_CHARTREUSE_3_76] = "Chartreuse3", + [C_PALE_GREEN_3_77] = "PaleGreen3", + [C_SEA_GREEN_3] = "SeaGreen3", + [C_AQUAMARINE_3] = "Aquamarine3", + [C_MEDIUM_TURQUOISE] = "MediumTurquoise", + [C_STEEL_BLUE_1_81] = "SteelBlue1", + [C_CHARTREUSE_2_82] = "Chartreuse2", + [C_SEA_GREEN_2] = "SeaGreen2", + [C_SEA_GREEN_1_84] = "SeaGreen1", + [C_SEA_GREEN_1_85] = "SeaGreen1", + [C_AQUAMARINE_1_86] = "Aquamarine1", + [C_DARK_SLATE_GRAY_2] = "DarkSlateGray2", + [C_DARK_RED_88] = "DarkRed", + [C_DEEP_PINK_4_89] = "DeepPink4", + [C_DARK_MAGENTA_90] = "DarkMagenta", + [C_DARK_MAGENTA_91] = "DarkMagenta", + [C_DARK_VIOLET_92] = "DarkViolet", + [C_PURPLE_93] = "Purple", + [C_ORANGE_4_94] = "Orange4", + [C_LIGHT_PINK_4] = "LightPink4", + [C_PLUM_4] = "Plum4", + [C_MEDIUM_PURPLE_3_97] = "MediumPurple3", + [C_MEDIUM_PURPLE_3_98] = "MediumPurple3", + [C_SLATE_BLUE_1] = "SlateBlue1", + [C_YELLOW_4_100] = "Yellow4", + [C_WHEAT_4] = "Wheat4", + [C_GREY_53] = "Grey53", + [C_LIGHT_SLATE_GREY] = "LightSlateGrey", + [C_MEDIUM_PURPLE] = "MediumPurple", + [C_LIGHT_SLATE_BLUE] = "LightSlateBlue", + [C_YELLOW_4_106] = "Yellow4", + [C_DARK_OLIVE_GREEN_3_107] = "DarkOliveGreen3", + [C_DARK_SEA_GREEN] = "DarkSeaGreen", + [C_LIGHT_SKY_BLUE_3_109] = "LightSkyBlue3", + [C_LIGHT_SKY_BLUE_3_110] = "LightSkyBlue3", + [C_SKY_BLUE_2] = "SkyBlue2", + [C_CHARTREUSE_2_112] = "Chartreuse2", + [C_DARK_OLIVE_GREEN_3_113] = "DarkOliveGreen3", + [C_PALE_GREEN_3_114] = "PaleGreen3", + [C_DARK_SEA_GREEN_3_115] = "DarkSeaGreen3", + [C_DARK_SLATE_GRAY_3] = "DarkSlateGray3", + [C_SKY_BLUE_1] = "SkyBlue1", + [C_CHARTREUSE_1] = "Chartreuse1", + [C_LIGHT_GREEN_119] = "LightGreen", + [C_LIGHT_GREEN_120] = "LightGreen", + [C_PALE_GREEN_1_121] = "PaleGreen1", + [C_AQUAMARINE_1_122] = "Aquamarine1", + [C_DARK_SLATE_GRAY_1] = "DarkSlateGray1", + [C_RED_3_124] = "Red3", + [C_DEEP_PINK_4_125] = "DeepPink4", + [C_MEDIUM_VIOLET_RED] = "MediumVioletRed", + [C_MAGENTA_3_127] = "Magenta3", + [C_DARK_VIOLET_128] = "DarkViolet", + [C_PURPLE_129] = "Purple", + [C_DARK_ORANGE_3_130] = "DarkOrange3", + [C_INDIAN_RED_131] = "IndianRed", + [C_HOT_PINK_3_132] = "HotPink3", + [C_MEDIUM_ORCHID_3] = "MediumOrchid3", + [C_MEDIUM_ORCHID] = "MediumOrchid", + [C_MEDIUM_PURPLE_2_135] = "MediumPurple2", + [C_DARK_GOLDENROD] = "DarkGoldenrod", + [C_LIGHT_SALMON_3_137] = "LightSalmon3", + [C_ROSY_BROWN] = "RosyBrown", + [C_GREY_63] = "Grey63", + [C_MEDIUM_PURPLE_2_140] = "MediumPurple2", + [C_MEDIUM_PURPLE_1] = "MediumPurple1", + [C_GOLD_3_142] = "Gold3", + [C_DARK_KHAKI] = "DarkKhaki", + [C_NAVAJO_WHITE_3] = "NavajoWhite3", + [C_GREY_69] = "Grey69", + [C_LIGHT_STEEL_BLUE_3] = "LightSteelBlue3", + [C_LIGHT_STEEL_BLUE] = "LightSteelBlue", + [C_YELLOW_3_148] = "Yellow3", + [C_DARK_OLIVE_GREEN_3_149] = "DarkOliveGreen3", + [C_DARK_SEA_GREEN_3_150] = "DarkSeaGreen3", + [C_DARK_SEA_GREEN_2_151] = "DarkSeaGreen2", + [C_LIGHT_CYAN_3] = "LightCyan3", + [C_LIGHT_SKY_BLUE_1] = "LightSkyBlue1", + [C_GREEN_YELLOW] = "GreenYellow", + [C_DARK_OLIVE_GREEN_2] = "DarkOliveGreen2", + [C_PALE_GREEN_1_156] = "PaleGreen1", + [C_DARK_SEA_GREEN_2_157] = "DarkSeaGreen2", + [C_DARK_SEA_GREEN_1_158] = "DarkSeaGreen1", + [C_PALE_TURQUOISE_1] = "PaleTurquoise1", + [C_RED_3_160] = "Red3", + [C_DEEP_PINK_3_161] = "DeepPink3", + [C_DEEP_PINK_3_162] = "DeepPink3", + [C_MAGENTA_3_163] = "Magenta3", + [C_MAGENTA_3_164] = "Magenta3", + [C_MAGENTA_2_165] = "Magenta2", + [C_DARK_ORANGE_3_166] = "DarkOrange3", + [C_INDIAN_RED_167] = "IndianRed", + [C_HOT_PINK_3_168] = "HotPink3", + [C_HOT_PINK_2] = "HotPink2", + [C_ORCHID] = "Orchid", + [C_MEDIUM_ORCHID_1_171] = "MediumOrchid1", + [C_ORANGE_3] = "Orange3", + [C_LIGHT_SALMON_3_173] = "LightSalmon3", + [C_LIGHT_PINK_3] = "LightPink3", + [C_PINK_3] = "Pink3", + [C_PLUM_3] = "Plum3", + [C_VIOLET] = "Violet", + [C_GOLD_3_178] = "Gold3", + [C_LIGHT_GOLDENROD_3] = "LightGoldenrod3", + [C_TAN] = "Tan", + [C_MISTY_ROSE_3] = "MistyRose3", + [C_THISTLE_3] = "Thistle3", + [C_PLUM_2] = "Plum2", + [C_YELLOW_3_184] = "Yellow3", + [C_KHAKI_3] = "Khaki3", + [C_LIGHT_GOLDENROD_2_186] = "LightGoldenrod2", + [C_LIGHT_YELLOW_3] = "LightYellow3", + [C_GREY_84] = "Grey84", + [C_LIGHT_STEEL_BLUE_1] = "LightSteelBlue1", + [C_YELLOW_2] = "Yellow2", + [C_DARK_OLIVE_GREEN_1_191] = "DarkOliveGreen1", + [C_DARK_OLIVE_GREEN_1_192] = "DarkOliveGreen1", + [C_DARK_SEA_GREEN_1_193] = "DarkSeaGreen1", + [C_HONEYDEW_2] = "Honeydew2", + [C_LIGHT_CYAN_1] = "LightCyan1", + [C_RED_1] = "Red1", + [C_DEEP_PINK_2] = "DeepPink2", + [C_DEEP_PINK_1_198] = "DeepPink1", + [C_DEEP_PINK_1_199] = "DeepPink1", + [C_MAGENTA_2_200] = "Magenta2", + [C_MAGENTA_1] = "Magenta1", + [C_ORANGE_RED_1] = "OrangeRed1", + [C_INDIAN_RED_1_203] = "IndianRed1", + [C_INDIAN_RED_1_204] = "IndianRed1", + [C_HOT_PINK_205] = "HotPink", + [C_HOT_PINK_206] = "HotPink", + [C_MEDIUM_ORCHID_1_207] = "MediumOrchid1", + [C_DARK_ORANGE] = "DarkOrange", + [C_SALMON_1] = "Salmon1", + [C_LIGHT_CORAL] = "LightCoral", + [C_PALE_VIOLET_RED_1] = "PaleVioletRed1", + [C_ORCHID_2] = "Orchid2", + [C_ORCHID_1] = "Orchid1", + [C_ORANGE_1] = "Orange1", + [C_SANDY_BROWN] = "SandyBrown", + [C_LIGHT_SALMON_1] = "LightSalmon1", + [C_LIGHT_PINK_1] = "LightPink1", + [C_PINK_1] = "Pink1", + [C_PLUM_1] = "Plum1", + [C_GOLD_1] = "Gold1", + [C_LIGHT_GOLDENROD_2_221] = "LightGoldenrod2", + [C_LIGHT_GOLDENROD_2_222] = "LightGoldenrod2", + [C_NAVAJO_WHITE_1] = "NavajoWhite1", + [C_MISTY_ROSE_1] = "MistyRose1", + [C_THISTLE_1] = "Thistle1", + [C_YELLOW_1] = "Yellow1", + [C_LIGHT_GOLDENROD_1] = "LightGoldenrod1", + [C_KHAKI_1] = "Khaki1", + [C_WHEAT_1] = "Wheat1", + [C_CORNSILK_1] = "Cornsilk1", + [C_GREY_100] = "Grey100", + [C_GREY_3] = "Grey3", + [C_GREY_7] = "Grey7", + [C_GREY_11] = "Grey11", + [C_GREY_15] = "Grey15", + [C_GREY_19] = "Grey19", + [C_GREY_23] = "Grey23", + [C_GREY_27] = "Grey27", + [C_GREY_30] = "Grey30", + [C_GREY_35] = "Grey35", + [C_GREY_39] = "Grey39", + [C_GREY_42] = "Grey42", + [C_GREY_46] = "Grey46", + [C_GREY_50] = "Grey50", + [C_GREY_54] = "Grey54", + [C_GREY_58] = "Grey58", + [C_GREY_62] = "Grey62", + [C_GREY_66] = "Grey66", + [C_GREY_70] = "Grey70", + [C_GREY_74] = "Grey74", + [C_GREY_78] = "Grey78", + [C_GREY_82] = "Grey82", + [C_GREY_85] = "Grey85", + [C_GREY_89] = "Grey89", + [C_GREY_93] = "Grey93", +}; + +static int parse_color(const char *text, uint32_t *color) { + if (strlen(text) == 6 && strspn(text, "0123456789abcdefABCDEF") == 6) { + *color = RGB_FLAG | (uint32_t)strtoul(text, NULL, 16); + return 1; + } + + char name[32]; + size_t len = 0; + while (*text && *text != ':') { + unsigned char ch = (unsigned char)*text++; + if (ch == ' ' || ch == '_' || ch == '-') continue; + if (len == sizeof(name) - 1) return 0; + name[len++] = (char)ch; + } + name[len] = '\0'; + + size_t first = 0; + size_t end = sizeof(xterm_color_names) / sizeof(xterm_color_names[0]); + if (*text == ':') { + char *tail; + if (*++text < '0' || *text > '9') return 0; + unsigned long index = strtoul(text, &tail, 10); + if (*tail || index >= end) return 0; + first = index; + end = first + 1; + } + + for (size_t index = first; index < end; index++) { + if (strcasecmp(name, xterm_color_names[index]) == 0) { + *color = INDEXED_COLOR_FLAG | (uint32_t)index; + return 1; + } + } + return 0; +} + int main(int argc, char **argv) { setlocale(LC_CTYPE, ""); @@ -5350,12 +5652,12 @@ int main(int argc, char **argv) { } argi++; } else if (strcmp(option, "-c") == 0 || strcmp(option, "--color") == 0) { - if (argi >= argc || strlen(argv[argi]) != 6 || - strspn(argv[argi], "0123456789abcdefABCDEF") != 6) { - fprintf(stderr, "murx: %s requires six hexadecimal digits (RRGGBB)\n", option); + if (argi >= argc || !parse_color(argv[argi], &color)) { + fprintf(stderr, "murx: %s requires an xterm color name or six hexadecimal digits (RRGGBB)\n", + option); return 2; } - color = RGB_FLAG | (uint32_t)strtoul(argv[argi++], NULL, 16); + argi++; } else if (strcmp(option, "-s") == 0 || strcmp(option, "--status") == 0) { if (argi >= argc || (strcmp(argv[argi], "top") != 0 && strcmp(argv[argi], "bottom") != 0)) { diff --git a/os/alpine/APKBUILD b/os/alpine/APKBUILD index 8c43a08..621bb07 100644 --- a/os/alpine/APKBUILD +++ b/os/alpine/APKBUILD @@ -26,10 +26,10 @@ package() { } sha512sums=" -299f4fcc053bcf46313ad34655aaf9180b59dc3a86758fd24e848c0cb1933d99ceeb56e4f85c592dd612d625f55b118284ee6a94c991216af61daa343091d518 murx.c +4be5bc2e103687fc38170ccc35957947b7242f6bfe753b0a8439d9c5ef62eac61bae46f7c27e86df188ddd1df8cc67a1ea30609ac9a94993d0a17196ad0b8825 murx.c ac75bfe596fae665ba882a10f5d16551bdd02cd601b786364763ac74dbc651c386d3a464eb63e0344354b953611629135190633e3b8ff3a8ef0f0849d60a3f7b Makefile -7546e0d84cb9094b4b2ac14e05d38a37270c2a4451f3d41aaa7b0b38290acb0ff6de821331634c802d08568817cf1ed0fbb5afd6734ef4a8155720b826ab6ce9 murx.1 -162b917a63a481554368083ba4d285c759c4c62148b073d658a8e32840f1aeffedff369876190cc0d2f164efdb800220bee882d823fa350b2063d022842e1182 MURX-README.md +90f3c8919e88866c22d2bf112edad812d2969a40787b7c9e094fa558966a8f0d61f0f9c9637027254e5d002546631e59cf1a3792f79a638297498f19916c89c7 murx.1 +d148117a37e30c12d0a8d21babfcf2a092c8e3df07f11b1608b194cefe136c597597177142adec87419b05282940bed5b1201b5c5c532c37ae86559976d289da MURX-README.md 2fe33ba22c5f68e124904be594208f050be20f33d115f9a56f60cac93304102da32e6a7e78154e831d3704da7ca8bfefd7025e7b8901e65babcd83e7342f6382 LICENSE 4d32dba475e5f9818fcd008068b011cbae9fc4b8e29897c933775d6660f44a7992d08a1550320d83233af729a42b241ef1d182bf5983ef2f64deab76cab2260d AUTHORS " diff --git a/os/arch/PKGBUILD b/os/arch/PKGBUILD index 624a9de..40fec81 100644 --- a/os/arch/PKGBUILD +++ b/os/arch/PKGBUILD @@ -8,10 +8,10 @@ url='https://codeberg.org/armin/murx' license=('Apache-2.0') depends=('glibc') source=('murx.c' 'Makefile' 'murx.1' 'MURX-README.md' 'LICENSE' 'AUTHORS') -sha256sums=('4ab7d155c3d9b23c22fc5792837ce2dd4e020cf0998edb743e7726edee73b438' +sha256sums=('c678902d48558839b986af75a2b104ab4879f8590b2a6a9542252cc14f97682f' '78a9c19c212e8038422e1bb4bb96d9b25eb19ad1359489cd32edf9e1a76638b2' - 'a4b48ce1c847869956ea52eac50c51446a9e6f720d8e4b211cb97a78a7f53663' - 'd86bb6257dee64ff4709faf4ab8c1dc2d6adfc98b464978389bcfa88568e63fb' + 'cfc3dd6db0e9a1795a84d47b2c172630ad5eaff5fb27c0932e12743910a5c5ff' + '60cd863f73c974d882e3562cb411f090f815061feb886049e8fddbfd21303a83' '31c5556be4cdd9bf52bb55f18ead0c68a4f0e793c2c2dab0a2a2c6d92407d0d4' 'dbc8a4fc569d4cd7bcd45516ccc98c1396fce0682c262103069c8f5150538cdb') From a705aeef692dfbc1ea877ab88daab7ea57928f07 Mon Sep 17 00:00:00 2001 From: hanez Date: Mon, 23 Nov 2026 20:24:19 +0100 Subject: [PATCH 12/18] README.md update. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3176a3e..e261902 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,8 @@ dependencies. ```sh make ./murx # session "0" -./murx work # separate named session -./murx 1 # separate numbered session +./murx work # separate/attache named session +./murx 1 # separate/attache numbered session ./murx -p x work # use Ctrl-X as this client's prefix ./murx --prefix x work # same as -p x ./murx -s bottom work # show the session status line at the bottom From d499d673098689e762c35ebff6b1d93c91dfaefc Mon Sep 17 00:00:00 2001 From: hanez Date: Mon, 23 Nov 2026 20:27:02 +0100 Subject: [PATCH 13/18] pkg build files update. --- os/alpine/APKBUILD | 2 +- os/arch/PKGBUILD | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/os/alpine/APKBUILD b/os/alpine/APKBUILD index 621bb07..37c2984 100644 --- a/os/alpine/APKBUILD +++ b/os/alpine/APKBUILD @@ -29,7 +29,7 @@ sha512sums=" 4be5bc2e103687fc38170ccc35957947b7242f6bfe753b0a8439d9c5ef62eac61bae46f7c27e86df188ddd1df8cc67a1ea30609ac9a94993d0a17196ad0b8825 murx.c ac75bfe596fae665ba882a10f5d16551bdd02cd601b786364763ac74dbc651c386d3a464eb63e0344354b953611629135190633e3b8ff3a8ef0f0849d60a3f7b Makefile 90f3c8919e88866c22d2bf112edad812d2969a40787b7c9e094fa558966a8f0d61f0f9c9637027254e5d002546631e59cf1a3792f79a638297498f19916c89c7 murx.1 -d148117a37e30c12d0a8d21babfcf2a092c8e3df07f11b1608b194cefe136c597597177142adec87419b05282940bed5b1201b5c5c532c37ae86559976d289da MURX-README.md +dfa615bc33378fcd5d6df3e65d28cf709699c51e0cc25c03ffecd609a5c13a7d8f2b05b1fa1122793d125c8e535f84e5629823c9f084a2eda053e155d574679c MURX-README.md 2fe33ba22c5f68e124904be594208f050be20f33d115f9a56f60cac93304102da32e6a7e78154e831d3704da7ca8bfefd7025e7b8901e65babcd83e7342f6382 LICENSE 4d32dba475e5f9818fcd008068b011cbae9fc4b8e29897c933775d6660f44a7992d08a1550320d83233af729a42b241ef1d182bf5983ef2f64deab76cab2260d AUTHORS " diff --git a/os/arch/PKGBUILD b/os/arch/PKGBUILD index 40fec81..3ce763d 100644 --- a/os/arch/PKGBUILD +++ b/os/arch/PKGBUILD @@ -11,7 +11,7 @@ source=('murx.c' 'Makefile' 'murx.1' 'MURX-README.md' 'LICENSE' 'AUTHORS') sha256sums=('c678902d48558839b986af75a2b104ab4879f8590b2a6a9542252cc14f97682f' '78a9c19c212e8038422e1bb4bb96d9b25eb19ad1359489cd32edf9e1a76638b2' 'cfc3dd6db0e9a1795a84d47b2c172630ad5eaff5fb27c0932e12743910a5c5ff' - '60cd863f73c974d882e3562cb411f090f815061feb886049e8fddbfd21303a83' + 'd1153b6129bd762fc16e0940045bc2172ce365cd610d83901dc4a0d6bf665c74' '31c5556be4cdd9bf52bb55f18ead0c68a4f0e793c2c2dab0a2a2c6d92407d0d4' 'dbc8a4fc569d4cd7bcd45516ccc98c1396fce0682c262103069c8f5150538cdb') From 3b3bb7684205e178acbc787b8100ed162580dd79 Mon Sep 17 00:00:00 2001 From: Armin Date: Mon, 23 Nov 2026 21:24:05 +0100 Subject: [PATCH 14/18] Revert "Accept xterm color names for the status bar background" This reverts commit f517cad02546ecd3c4d372af94d3b91c5117d37c. --- README.md | 9 +- murx.1 | 9 +- murx.c | 314 +-------------------------------------------- os/alpine/APKBUILD | 6 +- os/arch/PKGBUILD | 6 +- 5 files changed, 18 insertions(+), 326 deletions(-) diff --git a/README.md b/README.md index e261902..e0e87cc 100644 --- a/README.md +++ b/README.md @@ -396,12 +396,9 @@ Hard-coded: - Menus use a black background with a `colour12` frame, `colour11` titles and selection, `colour14` accents and dim `colour8` hints and separators. -Use `-c COLOR` or `--color COLOR` to set the session's status bar -background for all attached clients. Supply six hexadecimal digits such as -`191a1c`, or an xterm palette name such as `NavyBlue` or `navy-blue`. Names -are case-insensitive, and spaces, hyphens and underscores are ignored. A -repeated name selects the lowest palette index. Use `Blue3:20` to select a -specific entry. The session remembers the color across reattachments. New +Use `-c RRGGBB` or `--color RRGGBB` to set the session's status bar +background for all attached clients. Supply six hexadecimal digits, such as +`000000` for black. The session remembers the color across reattachments. New sessions use the terminal's default background unless a color is supplied. Colours are written to the outer terminal using 256-colour SGR (`38;5;n` / diff --git a/murx.1 b/murx.1 index f985bf1..7bf930f 100644 --- a/murx.1 +++ b/murx.1 @@ -5,7 +5,7 @@ murx \- small persistent terminal multiplexer .B murx .RB [ \-p " letter"] .RB [ \-s " top|bottom"] -.RB [ \-c " COLOR"] +.RB [ \-c " RRGGBB"] .RB [ \-H " lines"] .RB [ \-d ] .RB [ \-C ] @@ -72,12 +72,9 @@ New sessions default to top. An explicit choice changes an existing session for all clients. Omitting this option preserves the session's position. Prompts and messages follow the status line. .TP -.BR \-c " COLOR, " \-\-color " COLOR" +.BR \-c " RRGGBB, " \-\-color " RRGGBB" Set the session's status bar background for all attached clients. -Supply six hexadecimal digits (RRGGBB), such as 191a1c, or an xterm palette -name such as NavyBlue or navy-blue. Names are case-insensitive, and spaces, -hyphens and underscores are ignored. Repeated names select the lowest -palette index. Append :INDEX to choose a specific entry, as in Blue3:20. +Supply six hexadecimal digits, such as 000000 for black. Omitting this option preserves the session's color when reattaching. New sessions use the terminal's default background unless a color is supplied. .TP diff --git a/murx.c b/murx.c index 410230f..9d994dd 100644 --- a/murx.c +++ b/murx.c @@ -52,7 +52,6 @@ #include #include #include -#include #include #include #include @@ -385,7 +384,6 @@ static int send_msg(int fd, uint32_t type, const void *data, size_t len); #define DEFAULT_COLOR (-1) #define RGB_FLAG 0x01000000 -#define INDEXED_COLOR_FLAG 0x02000000 #define WIDE_CONT 0xFFFFFFFFu #define MAX_DIMENSION 1000 /* resource policy, not a C type limit */ @@ -4377,11 +4375,7 @@ static void handle_message(Client *c, Session *s, uint32_t type, const unsigned if (status > 2) { c->dead = 1; return; } uint32_t color = 0; if (len >= 24) memcpy(&color, data + 20, 4); - if (color && (color & 0xff000000u) != RGB_FLAG && - (color & ~0xffu) != INDEXED_COLOR_FLAG) { - c->dead = 1; - return; - } + if (color && (color >> 24) != 1) { c->dead = 1; return; } if (color) s->status_bg = (int32_t)color; if (status) { s->status_bottom = status == 2; @@ -5236,7 +5230,7 @@ static void print_help(FILE *out) { help_row(out, "-l, --list-sessions", "list running sessions without attaching"); help_row(out, "-p, --prefix LETTER", "client prefix Ctrl-LETTER (a-z, default: a)"); help_row(out, "-s, --status POSITION", "status line: top or bottom (new sessions: top)"); - help_row(out, "-c, --color COLOR", "status bar background: xterm name or RRGGBB"); + help_row(out, "-c, --color RRGGBB", "status bar background, six hex digits (e.g. 000000)"); char history_help[96]; snprintf(history_help, sizeof history_help, "history lines per pane in new sessions (0-%d, default: %d)", @@ -5249,7 +5243,6 @@ static void print_help(FILE *out) { help_row(out, "-t, --titles", "show the title row above each pane (default: off)"); fputs("\n" - "For repeated xterm names, add :INDEX (e.g. Blue3:20).\n" "Without -s or -c, an existing session keeps its position and color.\n" "Display options set new session values and can be changed later from\n" "the Configuration menu.\n" @@ -5306,301 +5299,6 @@ static int parse_prefix(const char *text, unsigned char *prefix) { return 1; } -static const char *const xterm_color_names[] = { - [C_BLACK] = "Black", - [C_MAROON] = "Maroon", - [C_DGREEN] = "Green", - [C_OLIVE] = "Olive", - [C_NAVY] = "Navy", - [C_PURPLE] = "Purple", - [C_CYAN] = "Teal", - [C_WHITE] = "Silver", - [C_GREY] = "Grey", - [C_RED] = "Red", - [C_GREEN] = "Lime", - [C_YELLOW] = "Yellow", - [C_BLUE] = "Blue", - [C_MAGENTA] = "Fuchsia", - [C_CYAN2] = "Aqua", - [C_BWHITE] = "White", - [C_GREY_0] = "Grey0", - [C_NAVY_BLUE] = "NavyBlue", - [C_DARK_BLUE] = "DarkBlue", - [C_BLUE_3_19] = "Blue3", - [C_BLUE_3_20] = "Blue3", - [C_BLUE_1] = "Blue1", - [C_DARK_GREEN] = "DarkGreen", - [C_DEEP_SKY_BLUE_4_23] = "DeepSkyBlue4", - [C_DEEP_SKY_BLUE_4_24] = "DeepSkyBlue4", - [C_DEEP_SKY_BLUE_4_25] = "DeepSkyBlue4", - [C_DODGER_BLUE_3] = "DodgerBlue3", - [C_DODGER_BLUE_2] = "DodgerBlue2", - [C_GREEN_4] = "Green4", - [C_SPRING_GREEN_4] = "SpringGreen4", - [C_TURQUOISE_4] = "Turquoise4", - [C_DEEP_SKY_BLUE_3_31] = "DeepSkyBlue3", - [C_DEEP_SKY_BLUE_3_32] = "DeepSkyBlue3", - [C_DODGER_BLUE_1] = "DodgerBlue1", - [C_GREEN_3_34] = "Green3", - [C_SPRING_GREEN_3_35] = "SpringGreen3", - [C_DARK_CYAN] = "DarkCyan", - [C_LIGHT_SEA_GREEN] = "LightSeaGreen", - [C_DEEP_SKY_BLUE_2] = "DeepSkyBlue2", - [C_DEEP_SKY_BLUE_1] = "DeepSkyBlue1", - [C_GREEN_3_40] = "Green3", - [C_SPRING_GREEN_3_41] = "SpringGreen3", - [C_SPRING_GREEN_2_42] = "SpringGreen2", - [C_CYAN_3] = "Cyan3", - [C_DARK_TURQUOISE] = "DarkTurquoise", - [C_TURQUOISE_2] = "Turquoise2", - [C_GREEN_1] = "Green1", - [C_SPRING_GREEN_2_47] = "SpringGreen2", - [C_SPRING_GREEN_1] = "SpringGreen1", - [C_MEDIUM_SPRING_GREEN] = "MediumSpringGreen", - [C_CYAN_2] = "Cyan2", - [C_CYAN_1] = "Cyan1", - [C_DARK_RED_52] = "DarkRed", - [C_DEEP_PINK_4_53] = "DeepPink4", - [C_PURPLE_4_54] = "Purple4", - [C_PURPLE_4_55] = "Purple4", - [C_PURPLE_3] = "Purple3", - [C_BLUE_VIOLET] = "BlueViolet", - [C_ORANGE_4_58] = "Orange4", - [C_GREY_37] = "Grey37", - [C_MEDIUM_PURPLE_4] = "MediumPurple4", - [C_SLATE_BLUE_3_61] = "SlateBlue3", - [C_SLATE_BLUE_3_62] = "SlateBlue3", - [C_ROYAL_BLUE_1] = "RoyalBlue1", - [C_CHARTREUSE_4] = "Chartreuse4", - [C_DARK_SEA_GREEN_4_65] = "DarkSeaGreen4", - [C_PALE_TURQUOISE_4] = "PaleTurquoise4", - [C_STEEL_BLUE] = "SteelBlue", - [C_STEEL_BLUE_3] = "SteelBlue3", - [C_CORNFLOWER_BLUE] = "CornflowerBlue", - [C_CHARTREUSE_3_70] = "Chartreuse3", - [C_DARK_SEA_GREEN_4_71] = "DarkSeaGreen4", - [C_CADET_BLUE_72] = "CadetBlue", - [C_CADET_BLUE_73] = "CadetBlue", - [C_SKY_BLUE_3] = "SkyBlue3", - [C_STEEL_BLUE_1_75] = "SteelBlue1", - [C_CHARTREUSE_3_76] = "Chartreuse3", - [C_PALE_GREEN_3_77] = "PaleGreen3", - [C_SEA_GREEN_3] = "SeaGreen3", - [C_AQUAMARINE_3] = "Aquamarine3", - [C_MEDIUM_TURQUOISE] = "MediumTurquoise", - [C_STEEL_BLUE_1_81] = "SteelBlue1", - [C_CHARTREUSE_2_82] = "Chartreuse2", - [C_SEA_GREEN_2] = "SeaGreen2", - [C_SEA_GREEN_1_84] = "SeaGreen1", - [C_SEA_GREEN_1_85] = "SeaGreen1", - [C_AQUAMARINE_1_86] = "Aquamarine1", - [C_DARK_SLATE_GRAY_2] = "DarkSlateGray2", - [C_DARK_RED_88] = "DarkRed", - [C_DEEP_PINK_4_89] = "DeepPink4", - [C_DARK_MAGENTA_90] = "DarkMagenta", - [C_DARK_MAGENTA_91] = "DarkMagenta", - [C_DARK_VIOLET_92] = "DarkViolet", - [C_PURPLE_93] = "Purple", - [C_ORANGE_4_94] = "Orange4", - [C_LIGHT_PINK_4] = "LightPink4", - [C_PLUM_4] = "Plum4", - [C_MEDIUM_PURPLE_3_97] = "MediumPurple3", - [C_MEDIUM_PURPLE_3_98] = "MediumPurple3", - [C_SLATE_BLUE_1] = "SlateBlue1", - [C_YELLOW_4_100] = "Yellow4", - [C_WHEAT_4] = "Wheat4", - [C_GREY_53] = "Grey53", - [C_LIGHT_SLATE_GREY] = "LightSlateGrey", - [C_MEDIUM_PURPLE] = "MediumPurple", - [C_LIGHT_SLATE_BLUE] = "LightSlateBlue", - [C_YELLOW_4_106] = "Yellow4", - [C_DARK_OLIVE_GREEN_3_107] = "DarkOliveGreen3", - [C_DARK_SEA_GREEN] = "DarkSeaGreen", - [C_LIGHT_SKY_BLUE_3_109] = "LightSkyBlue3", - [C_LIGHT_SKY_BLUE_3_110] = "LightSkyBlue3", - [C_SKY_BLUE_2] = "SkyBlue2", - [C_CHARTREUSE_2_112] = "Chartreuse2", - [C_DARK_OLIVE_GREEN_3_113] = "DarkOliveGreen3", - [C_PALE_GREEN_3_114] = "PaleGreen3", - [C_DARK_SEA_GREEN_3_115] = "DarkSeaGreen3", - [C_DARK_SLATE_GRAY_3] = "DarkSlateGray3", - [C_SKY_BLUE_1] = "SkyBlue1", - [C_CHARTREUSE_1] = "Chartreuse1", - [C_LIGHT_GREEN_119] = "LightGreen", - [C_LIGHT_GREEN_120] = "LightGreen", - [C_PALE_GREEN_1_121] = "PaleGreen1", - [C_AQUAMARINE_1_122] = "Aquamarine1", - [C_DARK_SLATE_GRAY_1] = "DarkSlateGray1", - [C_RED_3_124] = "Red3", - [C_DEEP_PINK_4_125] = "DeepPink4", - [C_MEDIUM_VIOLET_RED] = "MediumVioletRed", - [C_MAGENTA_3_127] = "Magenta3", - [C_DARK_VIOLET_128] = "DarkViolet", - [C_PURPLE_129] = "Purple", - [C_DARK_ORANGE_3_130] = "DarkOrange3", - [C_INDIAN_RED_131] = "IndianRed", - [C_HOT_PINK_3_132] = "HotPink3", - [C_MEDIUM_ORCHID_3] = "MediumOrchid3", - [C_MEDIUM_ORCHID] = "MediumOrchid", - [C_MEDIUM_PURPLE_2_135] = "MediumPurple2", - [C_DARK_GOLDENROD] = "DarkGoldenrod", - [C_LIGHT_SALMON_3_137] = "LightSalmon3", - [C_ROSY_BROWN] = "RosyBrown", - [C_GREY_63] = "Grey63", - [C_MEDIUM_PURPLE_2_140] = "MediumPurple2", - [C_MEDIUM_PURPLE_1] = "MediumPurple1", - [C_GOLD_3_142] = "Gold3", - [C_DARK_KHAKI] = "DarkKhaki", - [C_NAVAJO_WHITE_3] = "NavajoWhite3", - [C_GREY_69] = "Grey69", - [C_LIGHT_STEEL_BLUE_3] = "LightSteelBlue3", - [C_LIGHT_STEEL_BLUE] = "LightSteelBlue", - [C_YELLOW_3_148] = "Yellow3", - [C_DARK_OLIVE_GREEN_3_149] = "DarkOliveGreen3", - [C_DARK_SEA_GREEN_3_150] = "DarkSeaGreen3", - [C_DARK_SEA_GREEN_2_151] = "DarkSeaGreen2", - [C_LIGHT_CYAN_3] = "LightCyan3", - [C_LIGHT_SKY_BLUE_1] = "LightSkyBlue1", - [C_GREEN_YELLOW] = "GreenYellow", - [C_DARK_OLIVE_GREEN_2] = "DarkOliveGreen2", - [C_PALE_GREEN_1_156] = "PaleGreen1", - [C_DARK_SEA_GREEN_2_157] = "DarkSeaGreen2", - [C_DARK_SEA_GREEN_1_158] = "DarkSeaGreen1", - [C_PALE_TURQUOISE_1] = "PaleTurquoise1", - [C_RED_3_160] = "Red3", - [C_DEEP_PINK_3_161] = "DeepPink3", - [C_DEEP_PINK_3_162] = "DeepPink3", - [C_MAGENTA_3_163] = "Magenta3", - [C_MAGENTA_3_164] = "Magenta3", - [C_MAGENTA_2_165] = "Magenta2", - [C_DARK_ORANGE_3_166] = "DarkOrange3", - [C_INDIAN_RED_167] = "IndianRed", - [C_HOT_PINK_3_168] = "HotPink3", - [C_HOT_PINK_2] = "HotPink2", - [C_ORCHID] = "Orchid", - [C_MEDIUM_ORCHID_1_171] = "MediumOrchid1", - [C_ORANGE_3] = "Orange3", - [C_LIGHT_SALMON_3_173] = "LightSalmon3", - [C_LIGHT_PINK_3] = "LightPink3", - [C_PINK_3] = "Pink3", - [C_PLUM_3] = "Plum3", - [C_VIOLET] = "Violet", - [C_GOLD_3_178] = "Gold3", - [C_LIGHT_GOLDENROD_3] = "LightGoldenrod3", - [C_TAN] = "Tan", - [C_MISTY_ROSE_3] = "MistyRose3", - [C_THISTLE_3] = "Thistle3", - [C_PLUM_2] = "Plum2", - [C_YELLOW_3_184] = "Yellow3", - [C_KHAKI_3] = "Khaki3", - [C_LIGHT_GOLDENROD_2_186] = "LightGoldenrod2", - [C_LIGHT_YELLOW_3] = "LightYellow3", - [C_GREY_84] = "Grey84", - [C_LIGHT_STEEL_BLUE_1] = "LightSteelBlue1", - [C_YELLOW_2] = "Yellow2", - [C_DARK_OLIVE_GREEN_1_191] = "DarkOliveGreen1", - [C_DARK_OLIVE_GREEN_1_192] = "DarkOliveGreen1", - [C_DARK_SEA_GREEN_1_193] = "DarkSeaGreen1", - [C_HONEYDEW_2] = "Honeydew2", - [C_LIGHT_CYAN_1] = "LightCyan1", - [C_RED_1] = "Red1", - [C_DEEP_PINK_2] = "DeepPink2", - [C_DEEP_PINK_1_198] = "DeepPink1", - [C_DEEP_PINK_1_199] = "DeepPink1", - [C_MAGENTA_2_200] = "Magenta2", - [C_MAGENTA_1] = "Magenta1", - [C_ORANGE_RED_1] = "OrangeRed1", - [C_INDIAN_RED_1_203] = "IndianRed1", - [C_INDIAN_RED_1_204] = "IndianRed1", - [C_HOT_PINK_205] = "HotPink", - [C_HOT_PINK_206] = "HotPink", - [C_MEDIUM_ORCHID_1_207] = "MediumOrchid1", - [C_DARK_ORANGE] = "DarkOrange", - [C_SALMON_1] = "Salmon1", - [C_LIGHT_CORAL] = "LightCoral", - [C_PALE_VIOLET_RED_1] = "PaleVioletRed1", - [C_ORCHID_2] = "Orchid2", - [C_ORCHID_1] = "Orchid1", - [C_ORANGE_1] = "Orange1", - [C_SANDY_BROWN] = "SandyBrown", - [C_LIGHT_SALMON_1] = "LightSalmon1", - [C_LIGHT_PINK_1] = "LightPink1", - [C_PINK_1] = "Pink1", - [C_PLUM_1] = "Plum1", - [C_GOLD_1] = "Gold1", - [C_LIGHT_GOLDENROD_2_221] = "LightGoldenrod2", - [C_LIGHT_GOLDENROD_2_222] = "LightGoldenrod2", - [C_NAVAJO_WHITE_1] = "NavajoWhite1", - [C_MISTY_ROSE_1] = "MistyRose1", - [C_THISTLE_1] = "Thistle1", - [C_YELLOW_1] = "Yellow1", - [C_LIGHT_GOLDENROD_1] = "LightGoldenrod1", - [C_KHAKI_1] = "Khaki1", - [C_WHEAT_1] = "Wheat1", - [C_CORNSILK_1] = "Cornsilk1", - [C_GREY_100] = "Grey100", - [C_GREY_3] = "Grey3", - [C_GREY_7] = "Grey7", - [C_GREY_11] = "Grey11", - [C_GREY_15] = "Grey15", - [C_GREY_19] = "Grey19", - [C_GREY_23] = "Grey23", - [C_GREY_27] = "Grey27", - [C_GREY_30] = "Grey30", - [C_GREY_35] = "Grey35", - [C_GREY_39] = "Grey39", - [C_GREY_42] = "Grey42", - [C_GREY_46] = "Grey46", - [C_GREY_50] = "Grey50", - [C_GREY_54] = "Grey54", - [C_GREY_58] = "Grey58", - [C_GREY_62] = "Grey62", - [C_GREY_66] = "Grey66", - [C_GREY_70] = "Grey70", - [C_GREY_74] = "Grey74", - [C_GREY_78] = "Grey78", - [C_GREY_82] = "Grey82", - [C_GREY_85] = "Grey85", - [C_GREY_89] = "Grey89", - [C_GREY_93] = "Grey93", -}; - -static int parse_color(const char *text, uint32_t *color) { - if (strlen(text) == 6 && strspn(text, "0123456789abcdefABCDEF") == 6) { - *color = RGB_FLAG | (uint32_t)strtoul(text, NULL, 16); - return 1; - } - - char name[32]; - size_t len = 0; - while (*text && *text != ':') { - unsigned char ch = (unsigned char)*text++; - if (ch == ' ' || ch == '_' || ch == '-') continue; - if (len == sizeof(name) - 1) return 0; - name[len++] = (char)ch; - } - name[len] = '\0'; - - size_t first = 0; - size_t end = sizeof(xterm_color_names) / sizeof(xterm_color_names[0]); - if (*text == ':') { - char *tail; - if (*++text < '0' || *text > '9') return 0; - unsigned long index = strtoul(text, &tail, 10); - if (*tail || index >= end) return 0; - first = index; - end = first + 1; - } - - for (size_t index = first; index < end; index++) { - if (strcasecmp(name, xterm_color_names[index]) == 0) { - *color = INDEXED_COLOR_FLAG | (uint32_t)index; - return 1; - } - } - return 0; -} - int main(int argc, char **argv) { setlocale(LC_CTYPE, ""); @@ -5652,12 +5350,12 @@ int main(int argc, char **argv) { } argi++; } else if (strcmp(option, "-c") == 0 || strcmp(option, "--color") == 0) { - if (argi >= argc || !parse_color(argv[argi], &color)) { - fprintf(stderr, "murx: %s requires an xterm color name or six hexadecimal digits (RRGGBB)\n", - option); + if (argi >= argc || strlen(argv[argi]) != 6 || + strspn(argv[argi], "0123456789abcdefABCDEF") != 6) { + fprintf(stderr, "murx: %s requires six hexadecimal digits (RRGGBB)\n", option); return 2; } - argi++; + color = RGB_FLAG | (uint32_t)strtoul(argv[argi++], NULL, 16); } else if (strcmp(option, "-s") == 0 || strcmp(option, "--status") == 0) { if (argi >= argc || (strcmp(argv[argi], "top") != 0 && strcmp(argv[argi], "bottom") != 0)) { diff --git a/os/alpine/APKBUILD b/os/alpine/APKBUILD index 37c2984..36a641e 100644 --- a/os/alpine/APKBUILD +++ b/os/alpine/APKBUILD @@ -26,10 +26,10 @@ package() { } sha512sums=" -4be5bc2e103687fc38170ccc35957947b7242f6bfe753b0a8439d9c5ef62eac61bae46f7c27e86df188ddd1df8cc67a1ea30609ac9a94993d0a17196ad0b8825 murx.c +299f4fcc053bcf46313ad34655aaf9180b59dc3a86758fd24e848c0cb1933d99ceeb56e4f85c592dd612d625f55b118284ee6a94c991216af61daa343091d518 murx.c ac75bfe596fae665ba882a10f5d16551bdd02cd601b786364763ac74dbc651c386d3a464eb63e0344354b953611629135190633e3b8ff3a8ef0f0849d60a3f7b Makefile -90f3c8919e88866c22d2bf112edad812d2969a40787b7c9e094fa558966a8f0d61f0f9c9637027254e5d002546631e59cf1a3792f79a638297498f19916c89c7 murx.1 -dfa615bc33378fcd5d6df3e65d28cf709699c51e0cc25c03ffecd609a5c13a7d8f2b05b1fa1122793d125c8e535f84e5629823c9f084a2eda053e155d574679c MURX-README.md +7546e0d84cb9094b4b2ac14e05d38a37270c2a4451f3d41aaa7b0b38290acb0ff6de821331634c802d08568817cf1ed0fbb5afd6734ef4a8155720b826ab6ce9 murx.1 +6dce945220e19d90e295c1bdac3c9015f93759c22ba7dcbf467d8c7b9d3c0d6369770bba149da68925e9a02cb0df96e3d1ed2889529288de5cf29202604de090 MURX-README.md 2fe33ba22c5f68e124904be594208f050be20f33d115f9a56f60cac93304102da32e6a7e78154e831d3704da7ca8bfefd7025e7b8901e65babcd83e7342f6382 LICENSE 4d32dba475e5f9818fcd008068b011cbae9fc4b8e29897c933775d6660f44a7992d08a1550320d83233af729a42b241ef1d182bf5983ef2f64deab76cab2260d AUTHORS " diff --git a/os/arch/PKGBUILD b/os/arch/PKGBUILD index 3ce763d..a3daaf1 100644 --- a/os/arch/PKGBUILD +++ b/os/arch/PKGBUILD @@ -8,10 +8,10 @@ url='https://codeberg.org/armin/murx' license=('Apache-2.0') depends=('glibc') source=('murx.c' 'Makefile' 'murx.1' 'MURX-README.md' 'LICENSE' 'AUTHORS') -sha256sums=('c678902d48558839b986af75a2b104ab4879f8590b2a6a9542252cc14f97682f' +sha256sums=('4ab7d155c3d9b23c22fc5792837ce2dd4e020cf0998edb743e7726edee73b438' '78a9c19c212e8038422e1bb4bb96d9b25eb19ad1359489cd32edf9e1a76638b2' - 'cfc3dd6db0e9a1795a84d47b2c172630ad5eaff5fb27c0932e12743910a5c5ff' - 'd1153b6129bd762fc16e0940045bc2172ce365cd610d83901dc4a0d6bf665c74' + 'a4b48ce1c847869956ea52eac50c51446a9e6f720d8e4b211cb97a78a7f53663' + 'c49f2baa2a00da7a73881d6d05cbc07c28530b7f831ebdb2639fa1bb974a9290' '31c5556be4cdd9bf52bb55f18ead0c68a4f0e793c2c2dab0a2a2c6d92407d0d4' 'dbc8a4fc569d4cd7bcd45516ccc98c1396fce0682c262103069c8f5150538cdb') From 37f2527a47877b024e093471fd87548c9ed4410e Mon Sep 17 00:00:00 2001 From: Armin Date: Tue, 24 Nov 2026 03:10:51 +0100 Subject: [PATCH 15/18] Add session handoff and resize-on-input --adopt moves a running session to a new server binary while preserving clients, panes and scrollback. It works without a session name and notifies attached clients when adoption succeeds. Drop --no-resize-on-input in favor of the menu toggle. --- README.md | 43 +- murx.1 | 48 ++- murx.c | 1128 ++++++++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 1114 insertions(+), 105 deletions(-) diff --git a/README.md b/README.md index e0e87cc..12ee0ec 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,9 @@ make ./murx -l # --list-sessions, list running sessions without attaching ./murx -h # --help, usage and shortcuts ./murx -v # --version, print the version and exit +./murx --resize-on-input work # session size follows the last client with input +./murx --adopt # hand the default session to a new server binary +./murx --adopt work # same for a named session ``` Detach with `Ctrl-A d`. Run `murx` again to reattach. @@ -77,13 +80,35 @@ can change them in a running session (see [Menu](#menu)). To restore the previous default display, use `murx --cwd --clock --hostname session`. +By default, the most recently attached or resized client sets the session size. +Use `--resize-on-input` (or the `Resize to last input` toggle in the +Configuration menu) to make any input from a client — a keystroke, menu +navigation, or a scrollback command — make that client the size source instead. +The menu toggle turns it off again. Both change the running session for all +attached clients; omitting the option preserves its current mode. + +`--adopt` asks a running server to hand its session to a freshly started server +process, so an upgraded binary can take over without killing panes or +disconnecting clients. It accepts a session name, or no argument at all for the +default session: `murx --adopt` and `murx --adopt work` both work. Attached +clients keep their connections and see a short `Session adopted by new murx +server` notification. If no session is running, `--adopt` simply starts one. + +Handoff requires cooperation from the server that is already running. Sessions +started by this version (or a later one) can be adopted after an upgrade. +Against an older server, `--adopt` prints a clear message and attaches normally; +those sessions still need one restart. The handoff carries the listening socket, +pty descriptors, client sockets, window layout, pane screens and scrollback, so +shells keep their process IDs and panes keep their contents. + ## Upgrading from moerx The executable, source and manual are now `murx`, `murx.c` and `murx.1`. Update aliases and scripts to use `murx`. The status label is now disabled by default; use `--murx` to enable it. Sessions use a separate `murx-` socket directory; finish -existing sessions with the old executable before removing it. Existing -sessions are not migrated automatically. Replace the optional remote SSH +existing sessions with the old executable before removing it. Sessions started +by a handoff-capable build can be moved forward with `--adopt`; older ones are +not migrated automatically. Replace the optional remote SSH hooks below and reload the remote shell: custom reports now use `murx-cwd` and `murx-root`. @@ -100,10 +125,12 @@ and `murx-root`. works in programs such as Midnight Commander. Menus and prompts use normal cursor-key mode; detaching restores normal cursor keys in the outer terminal. - Home (Pos1) and End use the pane’s `screen-256color` key sequences. -- Multiple clients can attach to the same session. The most recently attached - or resized client sets the session size; a larger client shows the session - centred in its terminal, while a smaller client shows the top-left part. - `Ctrl-A R` forces the session back to the current client's terminal size. +- Multiple clients can attach to the same session. Normally the most recently + attached or resized client sets the session size. With `--resize-on-input`, + the client that most recently sent any input does instead. A larger client + shows the session centred in its terminal, while a smaller client shows the + top-left part. `Ctrl-A R` forces the session back to the current client's + terminal size. - Panes run `$SHELL` as a login shell with `TERM=screen-256color` and `MURX=`. They inherit the launching process's umask, so builds keep their usual file permissions. After upgrading from a version that forced `077`, @@ -324,8 +351,8 @@ scrollback, forced resize and kill server. `Configuration...` contains: - `Status line...` — position (top/bottom) and background (default, black `000000`, grey `191a1c`). - `Prefix...` — this client's Ctrl-key prefix, `a` through `z`. -- Toggles for the current directory, clock, `[murx]` label, hostname and pane - titles. +- Toggles for the current directory, clock, `[murx]` label, hostname, pane + titles and `Resize to last input`. - `Reset display/status defaults`. Press Enter on a toggle to turn it on or off. Settings changes apply diff --git a/murx.1 b/murx.1 index 7bf930f..bf0ea61 100644 --- a/murx.1 +++ b/murx.1 @@ -12,6 +12,8 @@ murx \- small persistent terminal multiplexer .RB [ \-m ] .RB [ \-n ] .RB [ \-t ] +.RB [ \-\-resize\-on\-input ] +.RB [ \-\-adopt ] .RB [ \-\- ] .RI [ session ] .br @@ -95,6 +97,27 @@ Show the hostname: prefix in window names and the outer terminal title. .BR \-t ", " \-\-titles Show the title row above each pane. Pane titles are off by default. .TP +.B \-\-resize\-on\-input +Make the session size follow the client that most recently sent input. +Any bytes from a client count, including keystrokes, menu navigation and +scrollback commands. Attaching and resizing are used only until the first +input arrives. This changes the running session for all attached clients. +.TP +.B \-\-adopt +Ask a running server to hand its session to a newly started server process. +The session name is optional, so both +.B murx \-\-adopt +and +.B murx \-\-adopt session +work; without a name the default session 0 is used. Panes, client connections, +window layout, screens and scrollback survive the swap. Attached clients see a +short +.I Session adopted by new murx server +notification. If no session is running, a new one is started normally. +Handoff requires a cooperating server: sessions started by this version or a +later one can be adopted after an upgrade. Against an older server, murx +prints a clear message and attaches normally. +.TP .BR \-h ", " \-\-help Print the text logo, program version, usage and keyboard shortcuts, then exit. .TP @@ -103,7 +126,9 @@ Print the program version and exit. .PP Display options set a new session's values; the Configuration menu can change them in a running session. The cwd, clock, [murx] label, hostname -and pane title options are off by default. +and pane title options are off by default. The default size mode uses +attach/resize recency; omitting \-\-resize\-on\-input preserves the running +session's mode. To restore the previous default display, use .BR "murx \-\-cwd \-\-clock \-\-hostname session" . .SH KEY BINDINGS @@ -227,10 +252,11 @@ Use Up/Down or j/k to move and Enter to select. Left/Right or h/l enter and leave submenus; q, Escape, or Ctrl-C closes the menu. Long menus scroll. The Configuration submenu sets the status line position and background (default, black or grey), the client prefix, display toggles for the directory, -clock, [murx] label and hostname, and resets display/status defaults (display toggles, status position and -background). Session -settings affect all attached clients; the prefix is per-client. Changes take -effect immediately and are not saved to disk. +clock, [murx] label, hostname and pane titles, a toggle for resizing to the +last client with input, and resets display/status defaults (display toggles, +status position and background). Session settings affect all attached clients; +the prefix is per-client. Changes take effect immediately and are not saved to +disk. In prompts use Enter to accept, Escape or Ctrl-C to cancel, Backspace or Ctrl-H to delete, and Ctrl-U to clear. Confirm destructive actions with y, Y or Enter; n, N, Escape or Ctrl-C cancels. @@ -301,9 +327,11 @@ are passed through as 24-bit SGR when COLORTERM is truecolor or 24bit and TERM does not start with screen, tmux, linux, or dumb; otherwise RGB is mapped to the nearest xterm-256 entry. .SH SESSION SIZE -The most recently attached or resized client determines the session size, -clamped to a minimum of 20 columns by 5 rows and a maximum of 1,000 by 1,000. -Larger clients center the session; smaller clients show its top-left portion. +By default, the most recently attached or resized client determines the session +size, clamped to a minimum of 20 columns by 5 rows and a maximum of 1,000 by +1,000. With the \-\-resize\-on\-input option or the Configuration menu toggle, +the client that most recently sent input determines the size instead; +attaching and resizing are only used before any client has sent input. Ctrl-A R forces the session to the current client's terminal size. Ctrl-A * lists attached clients for size diagnostics. .PP @@ -317,7 +345,9 @@ assume --hostname is enabled. SSH does not expose remote foreground programs or working directories locally. Configure the remote shell to send terminal reports using one of the examples below. Reload the shell configuration or open a new SSH shell afterward. -Restart session servers after upgrading murx to gain newly added features. +Sessions started by a handoff-capable build can move to a new binary with +.BR "murx \-\-adopt [" session "]"; +older session servers still need a restart after upgrading. .PP OSC 0 or OSC 2 titles of the form hostname:program update the SSH window name. Use a hostname containing only letters, digits, dots, underscores or hyphens, diff --git a/murx.c b/murx.c index 9d994dd..809d2d7 100644 --- a/murx.c +++ b/murx.c @@ -56,6 +56,7 @@ #include #include #include +#include #include #include #include @@ -91,9 +92,12 @@ #define DEFAULT_PREFIX 0x01 /* client -> server */ -enum { C_ATTACH = 1, C_INPUT = 2, C_RESIZE = 3 }; +enum { C_ATTACH = 1, C_INPUT = 2, C_RESIZE = 3, C_ADOPT = 6 }; /* server -> client */ -enum { S_DRAW = 4, S_DETACH = 5 }; +enum { S_DRAW = 4, S_DETACH = 5, S_HANDOFF = 7 }; + +/* C_ATTACH session-size mode: 0 preserves the running session's setting. */ +enum { SIZE_MODE_KEEP = 0, SIZE_MODE_ON = 1 }; typedef struct { uint32_t type; @@ -398,6 +402,9 @@ static int send_msg(int fd, uint32_t type, const void *data, size_t len); #define MENU_MAX_DEPTH 8 #define DEFAULT_HISTORY_LINES 2000 #define MAX_HISTORY_LINES 100000 +#define MAX_HANDOFF_FDS 256 /* SCM_RIGHTS cap for a session handoff */ +#define MAX_HANDOFF_BYTES (256u * 1024u * 1024u) +#define ADOPT_TIMEOUT_MS 2000 /* ------------------------------------------------------------------ */ /* small helpers */ @@ -1511,6 +1518,7 @@ struct Client { int cols, rows; int attached; uint64_t order; /* attach/resize sequence, newest client wins */ + uint64_t input_order; /* last input sequence, used by resize-on-input */ int truecolor; unsigned char in[16384]; size_t inlen; @@ -1571,6 +1579,7 @@ struct Session { int w, h; int status_bottom; + int resize_on_input; /* size follows the client that last sent input */ int32_t status_bg; /* 0 uses the terminal default */ DisplayOptions display; int history_limit; @@ -1581,25 +1590,37 @@ struct Session { Client *clients; uint64_t client_order; int running; + int adopted; /* handed off to a new server; do not clean up fds */ int redraw; /* a removed client changed the session size */ long long last_status; long long last_name_check; }; -/* Compact sequence numbers on wrap, preserving the newest-client ordering. */ +/* Compact sequence numbers on wrap, preserving both attach/resize and + input ordering across all clients. */ static uint64_t client_next_order(Session *s) { if (s->client_order == UINT64_MAX) { uint64_t previous = 0, rank = 0; for (;;) { Client *next = NULL; + uint64_t next_value = 0; for (Client *c = s->clients; c; c = c->next) { - if (c->order > previous && (!next || c->order < next->order)) next = c; + uint64_t values[2] = { c->order, c->input_order }; + for (int i = 0; i < 2; i++) { + uint64_t value = values[i]; + if (value > previous && (!next || value < next_value)) { + next = c; + next_value = value; + } + } } if (!next) break; - previous = next->order; if (rank == UINT64_MAX - 1) range_error(); - next->order = ++rank; + if (next->order == next_value) next->order = rank + 1; + if (next->input_order == next_value) next->input_order = rank + 1; + previous = next_value; + rank++; } s->client_order = rank; } @@ -2596,6 +2617,7 @@ enum { SET_SHOW_MURX, SET_SHOW_HOSTNAME, SET_SHOW_PANE_TITLES, + SET_RESIZE_ON_INPUT, SET_PREFIX }; @@ -2671,6 +2693,7 @@ static const MenuItem menu_config_items[] = { { "Show [murx] label", MI_TOGGLE, SET_SHOW_MURX, 1, 0 }, { "Show hostname", MI_TOGGLE, SET_SHOW_HOSTNAME, 1, 0 }, { "Show pane titles", MI_TOGGLE, SET_SHOW_PANE_TITLES, 1, 0 }, + { "Resize to last input", MI_TOGGLE, SET_RESIZE_ON_INPUT, 1, 0 }, MENU_SEP, { "Reset display/status defaults", MI_ACTION, ACT_RESET_DISPLAY, 0, 0 } }; @@ -2767,6 +2790,7 @@ static int menu_setting_on(Session *s, Client *c, const MenuItem *it) { case SET_SHOW_MURX: return s->display.show_murx == it->arg; case SET_SHOW_HOSTNAME: return s->display.show_hostname == it->arg; case SET_SHOW_PANE_TITLES: return s->display.show_pane_titles == it->arg; + case SET_RESIZE_ON_INPUT: return s->resize_on_input == it->arg; case SET_PREFIX: return c->prefix == it->arg; default: return 0; } @@ -3195,6 +3219,94 @@ static int send_msg(int fd, uint32_t type, const void *data, size_t len) { return 0; } +static int read_exact(int fd, void *buf, size_t len) { + unsigned char *p = buf; + while (len > 0) { + ssize_t n = read(fd, p, len); + if (n > 0) { + p += (size_t)n; + len -= (size_t)n; + } else if (n < 0 && errno == EINTR) { + continue; + } else { + return -1; + } + } + return 0; +} + +/* Send a message header with file descriptors attached. The payload follows + as ordinary stream bytes so callers can pass large handoff blobs. */ +static int send_msg_fds(int fd, uint32_t type, const void *data, size_t len, + const int *fds, size_t nfds) { + MsgHdr h; + if (len > UINT32_MAX || nfds > MAX_HANDOFF_FDS) { errno = EMSGSIZE; return -1; } + h.type = type; + h.len = (uint32_t)len; + + char control[CMSG_SPACE(MAX_HANDOFF_FDS * sizeof(int))]; + memset(control, 0, sizeof control); + struct iovec iov = { &h, sizeof h }; + struct msghdr msg; + memset(&msg, 0, sizeof msg); + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + if (nfds) { + msg.msg_control = control; + msg.msg_controllen = CMSG_SPACE(nfds * sizeof(int)); + struct cmsghdr *cm = CMSG_FIRSTHDR(&msg); + cm->cmsg_level = SOL_SOCKET; + cm->cmsg_type = SCM_RIGHTS; + cm->cmsg_len = CMSG_LEN(nfds * sizeof(int)); + memcpy(CMSG_DATA(cm), fds, nfds * sizeof(int)); + } + ssize_t n; + do { + n = sendmsg(fd, &msg, 0); + } while (n < 0 && errno == EINTR); + if (n < 0) return -1; + if (len && write_all(fd, data, len) < 0) return -1; + return 0; +} + +/* Receive exactly one message header, collecting any attached descriptors. */ +static int recv_msg_header(int fd, MsgHdr *h, int *outfds, int maxfds, int *nfds) { + *nfds = 0; + unsigned char *p = (unsigned char *)h; + size_t off = 0; + int got_fds = 0; + while (off < sizeof *h) { + char control[CMSG_SPACE(MAX_HANDOFF_FDS * sizeof(int))]; + memset(control, 0, sizeof control); + struct iovec iov = { p + off, sizeof *h - off }; + struct msghdr msg; + memset(&msg, 0, sizeof msg); + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + msg.msg_control = control; + msg.msg_controllen = sizeof control; + ssize_t n; + do { + n = recvmsg(fd, &msg, 0); + } while (n < 0 && errno == EINTR); + if (n <= 0) return -1; + off += (size_t)n; + if (!got_fds) { + for (struct cmsghdr *cm = CMSG_FIRSTHDR(&msg); cm; cm = CMSG_NXTHDR(&msg, cm)) { + if (cm->cmsg_level != SOL_SOCKET || cm->cmsg_type != SCM_RIGHTS) continue; + size_t count = (cm->cmsg_len - CMSG_LEN(0)) / sizeof(int); + const int *fdp = (const int *)CMSG_DATA(cm); + for (size_t i = 0; i < count; i++) { + if (*nfds < maxfds) outfds[(*nfds)++] = fdp[i]; + else close(fdp[i]); + } + got_fds = 1; + } + } + } + return 0; +} + static void short_hostname(char *out, size_t n) { if (gethostname(out, n) < 0) snprintf(out, n, "localhost"); out[n - 1] = '\0'; @@ -3212,14 +3324,25 @@ static void invalidate_clients(Session *s) { } static void session_recalc_size(Session *s) { - /* The most recently attached or resized client decides the session size. - This makes a reattach from a larger terminal grow the session even if an - older, smaller client is still connected. Such clients render only the - part of the session that fits (see draw_frame). */ + /* Normally the most recently attached or resized client decides the + session size. This makes a reattach from a larger terminal grow the + session even if an older, smaller client is still connected. Such + clients render only the part of the session that fits (see draw_frame). + + With resize-on-input, the last client to send any input decides instead; + attach/resize order is only the fallback until the first input arrives. */ Client *best = NULL; - for (Client *c = s->clients; c; c = c->next) { - if (!c->attached || c->dead || c->fd < 0) continue; - if (!best || c->order > best->order) best = c; + if (s->resize_on_input) { + for (Client *c = s->clients; c; c = c->next) { + if (!c->attached || c->dead || c->fd < 0 || !c->input_order) continue; + if (!best || c->input_order > best->input_order) best = c; + } + } + if (!best) { + for (Client *c = s->clients; c; c = c->next) { + if (!c->attached || c->dead || c->fd < 0) continue; + if (!best || c->order > best->order) best = c; + } } if (!best) return; int cols = best->cols; @@ -3769,6 +3892,10 @@ static void menu_apply_setting(Client *c, Session *s, const MenuItem *it) { session_layout(s); s->redraw = 1; break; + case SET_RESIZE_ON_INPUT: + s->resize_on_input = value ? 1 : 0; + session_recalc_size(s); + break; case SET_PREFIX: c->prefix = (unsigned char)value; break; default: return; } @@ -4358,7 +4485,585 @@ static Client *client_new(int fd) { return c; } -static void handle_message(Client *c, Session *s, uint32_t type, const unsigned char *data, uint32_t len) { +/* ------------------------------------------------------------------ */ +/* session handoff serialization */ +/* ------------------------------------------------------------------ */ + +typedef struct { + unsigned char *p; + size_t len, cap; +} HBuf; + +typedef struct { + const unsigned char *p; + size_t len, off; +} HRdBuf; + +static void buf_reserve(HBuf *b, size_t need) { + if (need <= b->cap) return; + size_t cap = buffer_capacity(b->cap ? b->cap : 65536, need); + b->p = xrealloc(b->p, cap); + b->cap = cap; +} + +static void buf_put(HBuf *b, const void *data, size_t len) { + buf_reserve(b, size_add(b->len, len)); + memcpy(b->p + b->len, data, len); + b->len += len; +} + +static void buf_i32(HBuf *b, int32_t v) { buf_put(b, &v, sizeof v); } +static void buf_u32(HBuf *b, uint32_t v) { buf_put(b, &v, sizeof v); } +static void buf_u64(HBuf *b, uint64_t v) { buf_put(b, &v, sizeof v); } +static void buf_i64(HBuf *b, int64_t v) { buf_put(b, &v, sizeof v); } + +static void buf_double(HBuf *b, double v) { + uint64_t bits; + memcpy(&bits, &v, sizeof bits); + buf_u64(b, bits); +} + +static void buf_str(HBuf *b, const char *s, size_t max) { + size_t n = strlen(s); + if (n >= max) n = max - 1; + buf_u32(b, (uint32_t)n); + buf_put(b, s, n); +} + +static int rd_take(HRdBuf *r, void *data, size_t len) { + if (len > r->len - r->off) return -1; + memcpy(data, r->p + r->off, len); + r->off += len; + return 0; +} + +static int rd_i32(HRdBuf *r, int32_t *v) { return rd_take(r, v, sizeof *v); } +static int rd_u32(HRdBuf *r, uint32_t *v) { return rd_take(r, v, sizeof *v); } +static int rd_u64(HRdBuf *r, uint64_t *v) { return rd_take(r, v, sizeof *v); } +static int rd_i64(HRdBuf *r, int64_t *v) { return rd_take(r, v, sizeof *v); } + +static int rd_double(HRdBuf *r, double *v) { + uint64_t bits; + if (rd_u64(r, &bits) < 0) return -1; + memcpy(v, &bits, sizeof *v); + return 0; +} + +static int rd_str(HRdBuf *r, char *out, size_t max) { + uint32_t n; + if (rd_u32(r, &n) < 0 || n >= max || rd_take(r, out, n) < 0) return -1; + out[n] = '\0'; + return 0; +} + +static void ser_pen(HBuf *b, const Pen *pen) { + buf_i32(b, pen->fg); + buf_i32(b, pen->bg); + buf_u32(b, pen->attr); +} + +static int rd_pen(HRdBuf *r, Pen *pen) { + uint32_t attr; + if (rd_i32(r, &pen->fg) < 0 || rd_i32(r, &pen->bg) < 0 || + rd_u32(r, &attr) < 0) return -1; + pen->attr = (uint8_t)attr; + return 0; +} + +static void ser_grid(HBuf *b, const Grid *g) { + buf_i32(b, g->w); + buf_i32(b, g->h); + if (g->w > 0 && g->h > 0) + buf_put(b, g->c, size_mul((size_t)g->w, (size_t)g->h) * sizeof(Cell)); +} + +static int rd_grid(HRdBuf *r, Grid *g) { + int32_t w, h; + if (rd_i32(r, &w) < 0 || rd_i32(r, &h) < 0) return -1; + if (w < 1 || h < 1 || w > MAX_DIMENSION || h > MAX_DIMENSION) return -1; + size_t cells = size_mul((size_t)w, (size_t)h); + if (cells > SIZE_MAX / sizeof(Cell) || cells * sizeof(Cell) > r->len - r->off) return -1; + grid_free(g); + grid_init(g, w, h); + memcpy(g->c, r->p + r->off, cells * sizeof(Cell)); + r->off += cells * sizeof(Cell); + return 0; +} + +static void ser_layout(HBuf *b, const Layout *l) { + buf_i32(b, l->type); + buf_double(b, l->ratio); + if (l->type == L_LEAF) { + buf_i32(b, l->pane ? l->pane->id : 0); + } else { + ser_layout(b, l->a); + ser_layout(b, l->b); + } +} + +static Layout *rd_layout(HRdBuf *r, Pane **panes, int npane) { + int32_t type; + Layout *l = xcalloc(1, sizeof *l); + if (rd_i32(r, &type) < 0 || rd_double(r, &l->ratio) < 0) { free(l); return NULL; } + l->type = (int)type; + if (l->type == L_LEAF) { + int32_t id; + if (rd_i32(r, &id) < 0) { free(l); return NULL; } + for (int i = 0; i < npane; i++) { + if (panes[i]->id == id) { l->pane = panes[i]; break; } + } + if (!l->pane) { free(l); return NULL; } + return l; + } + if (l->type != L_COLS && l->type != L_ROWS) { free(l); return NULL; } + l->a = rd_layout(r, panes, npane); + l->b = rd_layout(r, panes, npane); + if (!l->a || !l->b) { + layout_free(l); + return NULL; + } + l->a->parent = l; + l->b->parent = l; + return l; +} + +static Pane *find_pane_id(Pane **panes, int npane, int32_t id) { + for (int i = 0; i < npane; i++) if (panes[i]->id == id) return panes[i]; + return NULL; +} + +static void ser_pane(HBuf *b, const Pane *p, int master_idx, int tty_idx) { + buf_i32(b, p->id); + buf_i32(b, master_idx); + buf_i32(b, tty_idx); + buf_i32(b, p->pid); + buf_i32(b, p->alive); + buf_i32(b, p->x); buf_i32(b, p->y); buf_i32(b, p->w); buf_i32(b, p->h); + ser_grid(b, &p->main_grid); + ser_grid(b, &p->alt_grid); + buf_i32(b, p->on_alt); + buf_i32(b, p->history_start); + buf_i32(b, p->history_count); + for (int i = 0; i < p->history_count; i++) { + int slot = (p->history_start + i) % p->history_limit; + ser_grid(b, &p->history[slot]); + } + buf_i32(b, p->cx); buf_i32(b, p->cy); buf_i32(b, p->wrap_pending); + buf_i32(b, p->scroll_top); buf_i32(b, p->scroll_bot); + buf_i32(b, p->cursor_visible); buf_i32(b, p->app_cursor); + buf_i32(b, p->insert_mode); + ser_pen(b, &p->pen); + buf_i32(b, p->saved_x); buf_i32(b, p->saved_y); + ser_pen(b, &p->saved_pen); + buf_i32(b, p->main_x); buf_i32(b, p->main_y); + ser_pen(b, &p->main_pen); + buf_i32(b, p->pstate); + buf_str(b, p->seq, sizeof p->seq); + buf_i32(b, p->seqlen); + buf_i32(b, p->u8_need); buf_i32(b, p->u8_have); + buf_u32(b, p->u8_cp); + buf_str(b, p->title, sizeof p->title); + buf_i32(b, p->title_pgrp); + buf_str(b, p->remote_title, sizeof p->remote_title); + buf_i32(b, p->remote_title_pgrp); + buf_str(b, p->reported_cwd, sizeof p->reported_cwd); + buf_i32(b, p->reported_cwd_pgrp); + buf_i32(b, p->reported_root); + buf_i32(b, p->reported_root_pgrp); +} + +static int rd_pane(HRdBuf *r, Pane *p, int *fds, int nfds, int history_limit) { + int32_t id, master_idx, tty_idx; + if (rd_i32(r, &id) < 0 || rd_i32(r, &master_idx) < 0 || + rd_i32(r, &tty_idx) < 0) return -1; + if (master_idx < 0 || master_idx >= nfds || tty_idx < 0 || tty_idx >= nfds) return -1; + p->id = id; + p->fd = fds[master_idx]; + p->tty_fd = fds[tty_idx]; + if (rd_i32(r, (int32_t *)&p->pid) < 0 || rd_i32(r, &p->alive) < 0) return -1; + if (rd_i32(r, &p->x) < 0 || rd_i32(r, &p->y) < 0 || + rd_i32(r, &p->w) < 0 || rd_i32(r, &p->h) < 0) return -1; + if (rd_grid(r, &p->main_grid) < 0 || rd_grid(r, &p->alt_grid) < 0) return -1; + int32_t on_alt, count, start; + if (rd_i32(r, &on_alt) < 0 || rd_i32(r, &start) < 0 || + rd_i32(r, &count) < 0) return -1; + p->on_alt = on_alt != 0; + p->history_limit = history_limit; + if (count < 0 || count > history_limit || start < 0 || + (history_limit > 0 && start >= history_limit)) return -1; + p->history_start = start; + p->history_count = count; + if (count) { + p->history = xcalloc((size_t)history_limit, sizeof *p->history); + for (int i = 0; i < count; i++) { + int slot = (start + i) % history_limit; + if (rd_grid(r, &p->history[slot]) < 0) return -1; + } + } + if (rd_i32(r, &p->cx) < 0 || rd_i32(r, &p->cy) < 0 || + rd_i32(r, &p->wrap_pending) < 0) return -1; + if (rd_i32(r, &p->scroll_top) < 0 || rd_i32(r, &p->scroll_bot) < 0 || + rd_i32(r, &p->cursor_visible) < 0 || rd_i32(r, &p->app_cursor) < 0 || + rd_i32(r, &p->insert_mode) < 0) return -1; + if (rd_pen(r, &p->pen) < 0 || rd_i32(r, &p->saved_x) < 0 || + rd_i32(r, &p->saved_y) < 0 || rd_pen(r, &p->saved_pen) < 0 || + rd_i32(r, &p->main_x) < 0 || rd_i32(r, &p->main_y) < 0 || + rd_pen(r, &p->main_pen) < 0) return -1; + int32_t pstate, seqlen, u8_need, u8_have, u8cp; + if (rd_i32(r, &pstate) < 0 || rd_str(r, p->seq, sizeof p->seq) < 0 || + rd_i32(r, &seqlen) < 0) return -1; + p->pstate = (ParseState)pstate; + p->seqlen = seqlen; + if (rd_i32(r, &u8_need) < 0 || rd_i32(r, &u8_have) < 0 || + rd_i32(r, (int32_t *)&u8cp) < 0) return -1; + p->u8_need = u8_need; + p->u8_have = u8_have; + p->u8_cp = (uint32_t)u8cp; + if (rd_str(r, p->title, sizeof p->title) < 0 || + rd_i32(r, (int32_t *)&p->title_pgrp) < 0 || + rd_str(r, p->remote_title, sizeof p->remote_title) < 0 || + rd_i32(r, (int32_t *)&p->remote_title_pgrp) < 0 || + rd_str(r, p->reported_cwd, sizeof p->reported_cwd) < 0 || + rd_i32(r, (int32_t *)&p->reported_cwd_pgrp) < 0 || + rd_i32(r, &p->reported_root) < 0 || + rd_i32(r, (int32_t *)&p->reported_root_pgrp) < 0) return -1; + p->grid = p->on_alt ? &p->alt_grid : &p->main_grid; + return 0; +} + +static void ser_client(HBuf *b, const Client *c, int fd_idx, + Pane **panes, int npane, size_t skip_net) { + buf_i32(b, fd_idx); + buf_i32(b, c->cols); buf_i32(b, c->rows); + buf_i32(b, c->attached); + buf_u64(b, c->order); + buf_u64(b, c->input_order); + buf_i32(b, c->truecolor); + buf_u32(b, (uint32_t)c->inlen); + buf_put(b, c->in, c->inlen); + buf_i64(b, c->escape_since); + /* Preserve partially received protocol messages. The invoking client's + C_ADOPT request is stripped by the caller so it is not replayed in the + new server. */ + size_t netoff = skip_net <= c->netlen ? skip_net : c->netlen; + size_t netlen = c->netlen - netoff; + buf_u32(b, (uint32_t)netlen); + buf_put(b, c->net + netoff, netlen); + buf_i32(b, c->locked); buf_i32(b, c->prefix_pending); + buf_i32(b, c->prefix); + buf_i32(b, c->mode); buf_i32(b, c->prompt_kind); + buf_str(b, c->prompt, sizeof c->prompt); + buf_i32(b, c->prompt_len); buf_i32(b, c->prompt_label_len); + buf_i32(b, c->menu_page); buf_i32(b, c->menu_top); + buf_i32(b, c->menu_sel); buf_i32(b, c->menu_depth); + for (int i = 0; i < MENU_MAX_DEPTH; i++) { + buf_i32(b, c->menu_parent[i]); + buf_i32(b, c->menu_parent_sel[i]); + } + buf_i32(b, c->confirm_action); + buf_str(b, c->msg, sizeof c->msg); + buf_i64(b, c->msg_until); + buf_str(b, c->title, sizeof c->title); + buf_i32(b, c->dead); + + uint32_t nscroll = 0; + for (Scrollback *sb = c->scrollbacks; sb; sb = sb->next) nscroll++; + buf_u32(b, nscroll); + for (Scrollback *sb = c->scrollbacks; sb; sb = sb->next) { + int32_t id = 0; + for (int i = 0; i < npane; i++) { + if (panes[i] == sb->pane) { id = panes[i]->id; break; } + } + buf_i32(b, id); + buf_i32(b, sb->offset); + ser_grid(b, &sb->grid); + } +} + +static int rd_client(HRdBuf *r, Client *c, int *fds, int nfds, + Pane **panes, int npane) { + int32_t fd_idx; + if (rd_i32(r, &fd_idx) < 0) return -1; + if (fd_idx < 0 || fd_idx >= nfds) return -1; + c->fd = fds[fd_idx]; + if (rd_i32(r, &c->cols) < 0 || rd_i32(r, &c->rows) < 0 || + rd_i32(r, &c->attached) < 0) return -1; + if (rd_u64(r, &c->order) < 0 || rd_u64(r, &c->input_order) < 0) return -1; + if (rd_i32(r, &c->truecolor) < 0) return -1; + uint32_t inlen; + if (rd_u32(r, &inlen) < 0 || inlen > sizeof c->in || + rd_take(r, c->in, inlen) < 0) return -1; + c->inlen = inlen; + if (rd_i64(r, &c->escape_since) < 0) return -1; + uint32_t netlen; + if (rd_u32(r, &netlen) < 0 || netlen > sizeof c->net || + rd_take(r, c->net, netlen) < 0) return -1; + c->netlen = netlen; + int32_t prefix; + if (rd_i32(r, &c->locked) < 0 || rd_i32(r, &c->prefix_pending) < 0 || + rd_i32(r, &prefix) < 0) return -1; + c->prefix = (unsigned char)prefix; + if (rd_i32(r, &c->mode) < 0 || rd_i32(r, &c->prompt_kind) < 0 || + rd_str(r, c->prompt, sizeof c->prompt) < 0 || + rd_i32(r, &c->prompt_len) < 0 || + rd_i32(r, &c->prompt_label_len) < 0) return -1; + if (rd_i32(r, &c->menu_page) < 0 || rd_i32(r, &c->menu_top) < 0 || + rd_i32(r, &c->menu_sel) < 0 || rd_i32(r, &c->menu_depth) < 0) return -1; + for (int i = 0; i < MENU_MAX_DEPTH; i++) { + if (rd_i32(r, &c->menu_parent[i]) < 0 || + rd_i32(r, &c->menu_parent_sel[i]) < 0) return -1; + } + if (rd_i32(r, &c->confirm_action) < 0 || + rd_str(r, c->msg, sizeof c->msg) < 0 || + rd_i64(r, &c->msg_until) < 0 || + rd_str(r, c->title, sizeof c->title) < 0) return -1; + int32_t dead; + if (rd_i32(r, &dead) < 0) return -1; + c->dead = dead != 0; + + uint32_t nscroll; + if (rd_u32(r, &nscroll) < 0 || nscroll > 512) return -1; + for (uint32_t i = 0; i < nscroll; i++) { + Scrollback *sb = xcalloc(1, sizeof *sb); + int32_t id, offset; + if (rd_i32(r, &id) < 0 || rd_i32(r, &offset) < 0) { + free(sb); + return -1; + } + sb->pane = find_pane_id(panes, npane, id); + if (!sb->pane || rd_grid(r, &sb->grid) < 0) { + free(sb); + return -1; + } + sb->offset = offset; + sb->next = c->scrollbacks; + c->scrollbacks = sb; + } + return 0; +} + +static int session_serialize(Session *s, HBuf *b, int *fds, int *nfds, + Client *adopt_client, size_t adopt_skip) { + Pane *panes[512]; + int npane = 0; + session_panes(s, panes, 512, &npane); + int nclient = 0; + for (Client *c = s->clients; c; c = c->next) nclient++; + /* listening socket + master/tty per pane + every client socket */ + if (count_add(count_add(1, count_add(npane, npane)), nclient) > MAX_HANDOFF_FDS) + return -1; + + buf_u32(b, 0x4d48524c); /* "MHRL" */ + buf_u32(b, 1); + buf_str(b, s->name, sizeof s->name); + buf_str(b, s->cwd, sizeof s->cwd); + buf_str(b, s->sock_path, sizeof s->sock_path); + buf_i32(b, s->w); buf_i32(b, s->h); + buf_i32(b, s->status_bottom); buf_i32(b, s->resize_on_input); + buf_i32(b, s->status_bg); + buf_i32(b, s->history_limit); + buf_i32(b, s->display.show_cwd); buf_i32(b, s->display.show_clock); + buf_i32(b, s->display.show_murx); buf_i32(b, s->display.show_hostname); + buf_i32(b, s->display.show_pane_titles); + buf_u64(b, s->client_order); + + int fd_i = 0; + fds[fd_i++] = s->listen_fd; + buf_u32(b, (uint32_t)npane); + for (int i = 0; i < npane; i++) { + int master = fd_i++; + int tty = fd_i++; + fds[master] = panes[i]->fd; + fds[tty] = panes[i]->tty_fd; + ser_pane(b, panes[i], master, tty); + } + + int nwin = 0; + for (Window *w = s->windows; w; w = w->next) nwin++; + buf_u32(b, (uint32_t)nwin); + int cur_idx = -1, last_idx = -1, wi = 0; + for (Window *w = s->windows; w; w = w->next, wi++) { + if (w == s->cur) cur_idx = wi; + if (w == s->last) last_idx = wi; + buf_str(b, w->name, sizeof w->name); + buf_i32(b, w->index); + buf_i32(b, w->privileged); + buf_i32(b, w->active ? w->active->id : 0); + ser_layout(b, w->root); + } + buf_i32(b, cur_idx); + buf_i32(b, last_idx); + + buf_u32(b, (uint32_t)nclient); + int ci = 0; + for (Client *c = s->clients; c; c = c->next, ci++) { + fds[fd_i++] = c->fd; + ser_client(b, c, fd_i - 1, panes, npane, + c == adopt_client ? adopt_skip : 0); + } + *nfds = fd_i; + return 0; +} + +static Session *session_deserialize(HRdBuf *r, int *fds, int nfds) { + uint32_t magic, version; + if (rd_u32(r, &magic) < 0 || magic != 0x4d48524c || + rd_u32(r, &version) < 0 || version != 1) return NULL; + Session *s = xcalloc(1, sizeof *s); + if (rd_str(r, s->name, sizeof s->name) < 0 || + rd_str(r, s->cwd, sizeof s->cwd) < 0 || + rd_str(r, s->sock_path, sizeof s->sock_path) < 0) goto fail; + if (rd_i32(r, &s->w) < 0 || rd_i32(r, &s->h) < 0 || + rd_i32(r, &s->status_bottom) < 0 || + rd_i32(r, &s->resize_on_input) < 0 || + rd_i32(r, &s->status_bg) < 0 || + rd_i32(r, &s->history_limit) < 0 || + s->history_limit < 0 || s->history_limit > MAX_HISTORY_LINES) goto fail; + if (rd_i32(r, &s->display.show_cwd) < 0 || + rd_i32(r, &s->display.show_clock) < 0 || + rd_i32(r, &s->display.show_murx) < 0 || + rd_i32(r, &s->display.show_hostname) < 0 || + rd_i32(r, &s->display.show_pane_titles) < 0) goto fail; + if (rd_u64(r, &s->client_order) < 0) goto fail; + + s->listen_fd = fds[0]; + uint32_t npane; + if (rd_u32(r, &npane) < 0 || npane > 512) goto fail; + Pane **panes = xcalloc(npane ? npane : 1, sizeof *panes); + for (uint32_t i = 0; i < npane; i++) { + panes[i] = xcalloc(1, sizeof *panes[i]); + if (rd_pane(r, panes[i], fds, nfds, s->history_limit) < 0) + goto fail_panes; + } + + uint32_t nwin; + if (rd_u32(r, &nwin) < 0 || nwin > 512) goto fail_panes; + for (uint32_t i = 0; i < nwin; i++) { + Window *w = xcalloc(1, sizeof *w); + int32_t active_id; + if (rd_str(r, w->name, sizeof w->name) < 0 || + rd_i32(r, &w->index) < 0 || rd_i32(r, &w->privileged) < 0 || + rd_i32(r, &active_id) < 0) { free(w); goto fail_panes; } + w->root = rd_layout(r, panes, (int)npane); + if (!w->root) { free(w); goto fail_panes; } + w->active = find_pane_id(panes, (int)npane, active_id); + w->next = s->windows; + s->windows = w; + } + /* Rebuild in serialization order. */ + Window **order = xcalloc(nwin ? nwin : 1, sizeof *order); + uint32_t n = 0; + for (Window *w = s->windows; w; w = w->next) order[n++] = w; + s->windows = NULL; + for (uint32_t i = n; i > 0; i--) { + order[i - 1]->next = s->windows; + s->windows = order[i - 1]; + } + free(order); + s->nwin = (int)nwin; + int32_t cur_idx, last_idx; + if (rd_i32(r, &cur_idx) < 0 || rd_i32(r, &last_idx) < 0) goto fail_panes; + for (int i = 0; i < (int)nwin; i++) { + Window *w = s->windows; + for (int k = 0; k < i; k++) w = w->next; + if (i == cur_idx) s->cur = w; + if (i == last_idx) s->last = w; + } + + uint32_t nclient; + if (rd_u32(r, &nclient) < 0 || nclient > MAX_HANDOFF_FDS) goto fail_panes; + Client **clients = xcalloc(nclient ? nclient : 1, sizeof *clients); + for (uint32_t i = 0; i < nclient; i++) { + clients[i] = xcalloc(1, sizeof *clients[i]); + if (rd_client(r, clients[i], fds, nfds, panes, (int)npane) < 0) + goto fail_clients; + } + for (uint32_t i = nclient; i > 0; i--) { + clients[i - 1]->next = s->clients; + s->clients = clients[i - 1]; + } + free(clients); + free(panes); + s->running = 1; + s->redraw = 1; + s->last_status = now_ms(); + s->last_name_check = now_ms(); + session_layout(s); + for (Client *c = s->clients; c; c = c->next) { + client_invalidate(c); + client_message(c, "Session adopted by new murx server"); + } + return s; + +fail_clients: + for (uint32_t i = 0; i < nclient; i++) { + if (!clients[i]) continue; + if (clients[i]->prev_valid) grid_free(&clients[i]->prev); + while (clients[i]->scrollbacks) + scrollback_remove(&clients[i]->scrollbacks); + free(clients[i]); + } + free(clients); +fail_panes: + for (uint32_t i = 0; i < npane; i++) { + if (!panes[i]) continue; + grid_free(&panes[i]->main_grid); + grid_free(&panes[i]->alt_grid); + if (panes[i]->history) { + for (int k = 0; k < panes[i]->history_count; k++) + grid_free(&panes[i]->history[k]); + free(panes[i]->history); + } + free(panes[i]); + } + free(panes); +fail: { + /* Panes are freed separately above; free only the window scaffolding. */ + Window *w = s->windows; + while (w) { + Window *next = w->next; + layout_free(w->root); + free(w); + w = next; + } + free(s); + return NULL; +} +} + +static void server_handoff(Client *c, Session *s, int handoff_fd, + uint32_t adopt_len) { + HBuf b; + memset(&b, 0, sizeof b); + int fds[MAX_HANDOFF_FDS]; + int nfds = 0; + MsgHdr fail = { 0, 0 }; + size_t adopt_skip = size_add(sizeof(MsgHdr), adopt_len); + if (handoff_fd < 0 || + session_serialize(s, &b, fds, &nfds, c, adopt_skip) < 0 || + b.len == 0 || b.len > MAX_HANDOFF_BYTES) { + if (handoff_fd >= 0) (void)write_all(handoff_fd, &fail, sizeof fail); + free(b.p); + return; + } + if (send_msg_fds(handoff_fd, S_HANDOFF, b.p, b.len, fds, (size_t)nfds) < 0) { + (void)write_all(handoff_fd, &fail, sizeof fail); + } else { + /* The new server owns duplicates of every descriptor. Exit without + closing our copies, detaching clients or unlinking the socket. */ + s->adopted = 1; + s->running = 0; + } + free(b.p); +} + +static void handle_message(Client *c, Session *s, uint32_t type, + const unsigned char *data, uint32_t len, + int *fds, int nfds) { + if (type == C_ADOPT) { + server_handoff(c, s, nfds > 0 ? fds[0] : -1, len); + return; + } if (type == C_ATTACH) { if (len >= 8) { uint32_t cols, rows, flags = 0; @@ -4376,6 +5081,10 @@ static void handle_message(Client *c, Session *s, uint32_t type, const unsigned uint32_t color = 0; if (len >= 24) memcpy(&color, data + 20, 4); if (color && (color >> 24) != 1) { c->dead = 1; return; } + uint32_t size_mode = SIZE_MODE_KEEP; + if (len >= 28) memcpy(&size_mode, data + 24, 4); + if (size_mode > SIZE_MODE_ON) { c->dead = 1; return; } + if (size_mode == SIZE_MODE_ON) s->resize_on_input = 1; if (color) s->status_bg = (int32_t)color; if (status) { s->status_bottom = status == 2; @@ -4411,38 +5120,72 @@ static void handle_message(Client *c, Session *s, uint32_t type, const unsigned invalidate_clients(s); } } else if (type == C_INPUT) { + /* Track input even while the mode is off so enabling it later (from + the menu or a reattach) already knows the last active client. */ + if (len && c->attached) { + c->input_order = client_next_order(s); + if (s->resize_on_input) session_recalc_size(s); + } client_feed(c, s, data, len); } } static void client_read_socket(Client *c, Session *s) { unsigned char tmp[16384]; - ssize_t n = read(c->fd, tmp, sizeof tmp); + char control[CMSG_SPACE(MAX_HANDOFF_FDS * sizeof(int))]; + memset(control, 0, sizeof control); + struct iovec iov = { tmp, sizeof tmp }; + struct msghdr msg; + memset(&msg, 0, sizeof msg); + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + msg.msg_control = control; + msg.msg_controllen = sizeof control; + + ssize_t n; + do { + n = recvmsg(c->fd, &msg, 0); + } while (n < 0 && errno == EINTR); if (n <= 0) { - if (n < 0 && (errno == EINTR || errno == EAGAIN)) return; + if (n < 0 && (errno == EAGAIN || errno == EWOULDBLOCK)) return; c->dead = 1; return; } + int msgfds[MAX_HANDOFF_FDS]; + int nfds = 0; + for (struct cmsghdr *cm = CMSG_FIRSTHDR(&msg); cm; cm = CMSG_NXTHDR(&msg, cm)) { + if (cm->cmsg_level != SOL_SOCKET || cm->cmsg_type != SCM_RIGHTS) continue; + size_t count = (cm->cmsg_len - CMSG_LEN(0)) / sizeof(int); + const int *fdp = (const int *)CMSG_DATA(cm); + for (size_t i = 0; i < count && nfds < MAX_HANDOFF_FDS; i++) + msgfds[nfds++] = fdp[i]; + } + if ((size_t)n > sizeof c->net - c->netlen) { c->dead = 1; + for (int i = 0; i < nfds; i++) close(msgfds[i]); return; } memcpy(c->net + c->netlen, tmp, (size_t)n); c->netlen += (size_t)n; size_t off = 0; + int first = 1; while (c->netlen - off >= sizeof(MsgHdr)) { MsgHdr h; memcpy(&h, c->net + off, sizeof h); - if (h.len > sizeof c->net - sizeof h) { c->dead = 1; return; } + if (h.len > sizeof c->net - sizeof h) { c->dead = 1; break; } if (h.len > c->netlen - off - sizeof h) break; - handle_message(c, s, h.type, c->net + off + sizeof h, h.len); + handle_message(c, s, h.type, c->net + off + sizeof h, h.len, + first ? msgfds : NULL, first ? nfds : 0); + first = 0; off += sizeof h + h.len; } if (off > 0) { memmove(c->net, c->net + off, c->netlen - off); c->netlen -= off; } + for (int i = 0; i < nfds; i++) close(msgfds[i]); } static void accept_client(Session *s) { @@ -4625,9 +5368,11 @@ static void run_server(Session *s) { } } - char msg[128]; - snprintf(msg, sizeof msg, "[murx: session \"%s\" server exited]", s->name); - server_notify_all(s, msg); + if (!s->adopted) { + char msg[128]; + snprintf(msg, sizeof msg, "[murx: session \"%s\" server exited]", s->name); + server_notify_all(s, msg); + } free(panes); } @@ -4667,7 +5412,8 @@ static void server_fail(int readyfd, const char *stage, int err) { } static void server_start(const char *path, const char *name, int readyfd, - const DisplayOptions *display, int history_limit) { + const DisplayOptions *display, int history_limit, + int adopt_fd, int *adopt_fds, int adopt_nfds) { signal(SIGPIPE, SIG_IGN); signal(SIGHUP, SIG_IGN); signal(SIGCHLD, SIG_DFL); @@ -4678,61 +5424,86 @@ static void server_start(const char *path, const char *name, int readyfd, sigaction(SIGINT, &sa, NULL); sigaction(SIGQUIT, &sa, NULL); - int lfd = socket(AF_UNIX, SOCK_STREAM, 0); - if (lfd < 0) { - server_fail(readyfd, "socket", errno); - _exit(1); - } - struct sockaddr_un saun; - memset(&saun, 0, sizeof saun); - saun.sun_family = AF_UNIX; - size_t path_len = strlen(path); - if (path_len >= sizeof saun.sun_path) { - close(lfd); - server_fail(readyfd, "socket path", ENAMETOOLONG); - _exit(1); - } - memcpy(saun.sun_path, path, path_len + 1); - unlink(path); - /* Protect the socket without imposing private file permissions on pane - shells and their build output (rsync -a preserves those permissions). */ - mode_t saved_umask = umask(077); - int bound = bind(lfd, (struct sockaddr *)&saun, sizeof saun); - int bind_err = errno; - umask(saved_umask); - if (bound < 0) { - close(lfd); - server_fail(readyfd, "bind", bind_err); - _exit(1); - } - if (listen(lfd, 16) < 0) { - int err = errno; - close(lfd); - server_fail(readyfd, "listen", err); - _exit(1); - } - chmod(path, 0600); + Session *s = NULL; + int lfd = -1; + if (adopt_fd >= 0) { + MsgHdr h; + if (adopt_nfds < 1 || read_exact(adopt_fd, &h, sizeof h) < 0 || + h.type != S_HANDOFF || h.len == 0 || h.len > MAX_HANDOFF_BYTES) { + server_fail(readyfd, "adopt handshake", EPROTO); + _exit(1); + } + unsigned char *payload = xmalloc(h.len ? h.len : 1); + if (read_exact(adopt_fd, payload, h.len) < 0) { + free(payload); + server_fail(readyfd, "adopt handshake", EPROTO); + _exit(1); + } + HRdBuf r = { payload, h.len, 0 }; + s = session_deserialize(&r, adopt_fds, adopt_nfds); + free(payload); + if (!s) { + server_fail(readyfd, "adopt state", EPROTO); + _exit(1); + } + lfd = s->listen_fd; + } else { + lfd = socket(AF_UNIX, SOCK_STREAM, 0); + if (lfd < 0) { + server_fail(readyfd, "socket", errno); + _exit(1); + } + struct sockaddr_un saun; + memset(&saun, 0, sizeof saun); + saun.sun_family = AF_UNIX; + size_t path_len = strlen(path); + if (path_len >= sizeof saun.sun_path) { + close(lfd); + server_fail(readyfd, "socket path", ENAMETOOLONG); + _exit(1); + } + memcpy(saun.sun_path, path, path_len + 1); + unlink(path); + /* Protect the socket without imposing private file permissions on pane + shells and their build output (rsync -a preserves those permissions). */ + mode_t saved_umask = umask(077); + int bound = bind(lfd, (struct sockaddr *)&saun, sizeof saun); + int bind_err = errno; + umask(saved_umask); + if (bound < 0) { + close(lfd); + server_fail(readyfd, "bind", bind_err); + _exit(1); + } + if (listen(lfd, 16) < 0) { + int err = errno; + close(lfd); + server_fail(readyfd, "listen", err); + _exit(1); + } + chmod(path, 0600); - Session *s = xcalloc(1, sizeof *s); - snprintf(s->name, sizeof s->name, "%s", name); - snprintf(s->sock_path, sizeof s->sock_path, "%s", path); - if (!getcwd(s->cwd, sizeof s->cwd)) snprintf(s->cwd, sizeof s->cwd, "/"); - s->listen_fd = lfd; - s->w = 80; - s->h = 24; - s->running = 1; - s->display = *display; - s->history_limit = history_limit; - s->last_status = now_ms(); + s = xcalloc(1, sizeof *s); + snprintf(s->name, sizeof s->name, "%s", name); + snprintf(s->sock_path, sizeof s->sock_path, "%s", path); + if (!getcwd(s->cwd, sizeof s->cwd)) snprintf(s->cwd, sizeof s->cwd, "/"); + s->listen_fd = lfd; + s->w = 80; + s->h = 24; + s->running = 1; + s->display = *display; + s->history_limit = history_limit; + s->last_status = now_ms(); - Window *w = window_new(s, NULL); - if (!w) { - server_fail(readyfd, "cannot create pane (openpty)", errno); - server_cleanup(s); - _exit(1); + Window *w = window_new(s, NULL); + if (!w) { + server_fail(readyfd, "cannot create pane (openpty)", errno); + server_cleanup(s); + _exit(1); + } + s->cur = w; + session_layout(s); } - s->cur = w; - session_layout(s); if (readyfd >= 0) { char ok = '1'; @@ -4741,6 +5512,7 @@ static void server_start(const char *path, const char *name, int readyfd, } run_server(s); + if (s->adopted) _exit(0); server_cleanup(s); free(s); _exit(0); @@ -4883,8 +5655,103 @@ static int ensure_socket_dir(void) { return 0; } +/* Result of a successful C_ADOPT exchange. The descriptors were received via + SCM_RIGHTS and are inherited by the new server across fork(). */ +typedef struct { + int client_fd; /* existing connection, kept for the attach below */ + MsgHdr h; + unsigned char *payload; + int *fds; + int nfds; +} AdoptHandoff; + +static void adopt_handoff_free(AdoptHandoff *a) { + if (!a) return; + for (int i = 0; i < a->nfds; i++) { + if (a->fds[i] >= 0) close(a->fds[i]); + } + free(a->fds); + free(a->payload); + memset(a, 0, sizeof *a); +} + +static void close_fds(int *fds, int nfds) { + for (int i = 0; i < nfds; i++) { + if (fds[i] >= 0) close(fds[i]); + } +} + +/* Ask a cooperating server to hand its session to a new process. An older + server ignores C_ADOPT, so a timeout is a clean "cannot adopt" result. */ +static int request_adoption(int client_fd, AdoptHandoff *a) { + memset(a, 0, sizeof *a); + a->client_fd = client_fd; + + int sp[2]; + if (socketpair(AF_UNIX, SOCK_STREAM, 0, sp) < 0) return -1; + int pass_fd = sp[1]; + if (send_msg_fds(client_fd, C_ADOPT, NULL, 0, &pass_fd, 1) < 0) { + int err = errno; + close(sp[0]); + close(sp[1]); + errno = err; + return -1; + } + close(sp[1]); + + struct pollfd pfd; + pfd.fd = sp[0]; + pfd.events = POLLIN; + pfd.revents = 0; + int pr; + do { + pr = poll(&pfd, 1, ADOPT_TIMEOUT_MS); + } while (pr < 0 && errno == EINTR); + if (pr == 0) { + close(sp[0]); + errno = ETIMEDOUT; + return -1; + } + if (pr < 0) { + int err = errno; + close(sp[0]); + errno = err; + return -1; + } + + int fds[MAX_HANDOFF_FDS]; + int nfds = 0; + MsgHdr h; + if (recv_msg_header(sp[0], &h, fds, MAX_HANDOFF_FDS, &nfds) < 0 || + h.type != S_HANDOFF || h.len == 0 || h.len > MAX_HANDOFF_BYTES || + nfds < 1) { + close_fds(fds, nfds); + close(sp[0]); + errno = EPROTO; + return -1; + } + unsigned char *payload = xmalloc(h.len); + if (read_exact(sp[0], payload, h.len) < 0) { + int err = errno ? errno : EPROTO; + close_fds(fds, nfds); + close(sp[0]); + free(payload); + errno = err; + return -1; + } + close(sp[0]); + + a->h = h; + a->payload = payload; + a->nfds = nfds; + a->fds = xmalloc((size_t)nfds * sizeof *a->fds); + memcpy(a->fds, fds, (size_t)nfds * sizeof *a->fds); + return 0; +} + static int spawn_server(const char *path, const char *name, - const DisplayOptions *display, int history_limit) { + const DisplayOptions *display, int history_limit, + const AdoptHandoff *adopt) { if (ensure_socket_dir() < 0) return -1; char dir[PATH_MAX], lockpath[PATH_MAX + 64]; socket_dir(dir, sizeof dir); @@ -4896,11 +5763,14 @@ static int spawn_server(const char *path, const char *name, return -1; } - int fd = connect_session(path); - if (fd >= 0) { - flock(lock, LOCK_UN); - close(lock); - return fd; + int fd = -1; + if (!adopt) { + fd = connect_session(path); + if (fd >= 0) { + flock(lock, LOCK_UN); + close(lock); + return fd; + } } int p[2]; @@ -4909,17 +5779,30 @@ static int spawn_server(const char *path, const char *name, close(lock); return -1; } + int hp[2] = { -1, -1 }; + if (adopt && pipe(hp) < 0) { + close(p[0]); + close(p[1]); + flock(lock, LOCK_UN); + close(lock); + return -1; + } pid_t pid = fork(); if (pid < 0) { close(p[0]); close(p[1]); + if (adopt) { + close(hp[0]); + close(hp[1]); + } flock(lock, LOCK_UN); close(lock); return -1; } if (pid == 0) { close(p[0]); + if (adopt) close(hp[1]); setsid(); pid_t pid2 = fork(); if (pid2 < 0) _exit(1); @@ -4932,10 +5815,25 @@ static int spawn_server(const char *path, const char *name, if (dn > 2) close(dn); } close(lock); - server_start(path, name, p[1], display, history_limit); + if (adopt) { + server_start(path, name, p[1], display, history_limit, hp[0], + adopt->fds, adopt->nfds); + } else { + server_start(path, name, p[1], display, history_limit, -1, NULL, 0); + } _exit(1); } close(p[1]); + + int handoff_err = 0; + if (adopt) { + close(hp[0]); + if (write_all(hp[1], &adopt->h, sizeof adopt->h) < 0 || + write_all(hp[1], adopt->payload, adopt->h.len) < 0) + handoff_err = errno; + close(hp[1]); + } + char msg[256]; size_t used = 0; ssize_t got; @@ -4956,6 +5854,10 @@ static int spawn_server(const char *path, const char *name, flock(lock, LOCK_UN); close(lock); + if (handoff_err) { + errno = handoff_err; + return -1; + } if (used < 1 || msg[0] != '1') { if (used > 0) { fprintf(stderr, "murx: server failed to start: %s\n", msg); @@ -4965,6 +5867,7 @@ static int spawn_server(const char *path, const char *name, } return -1; } + if (adopt) return adopt->client_fd; for (int i = 0; i < 300; i++) { fd = connect_session(path); if (fd >= 0) return fd; @@ -5038,7 +5941,8 @@ static int terminal_truecolor(void) { return 1; } -static int run_client(int fd, const char *name, unsigned char prefix, int status, uint32_t color) { +static int run_client(int fd, const char *name, unsigned char prefix, int status, + uint32_t color, uint32_t resize_mode) { struct termios saved; if (tty_raw(&saved) < 0) { fprintf(stderr, "murx: not a terminal\n"); @@ -5073,8 +5977,9 @@ static int run_client(int fd, const char *name, unsigned char prefix, int status int cols, rows; tty_size(&cols, &rows); - uint32_t attach[6] = { (uint32_t)cols, (uint32_t)rows, - (uint32_t)terminal_truecolor(), prefix, (uint32_t)status, color }; + uint32_t attach[7] = { (uint32_t)cols, (uint32_t)rows, + (uint32_t)terminal_truecolor(), prefix, (uint32_t)status, color, + resize_mode }; if (send_msg(fd, C_ATTACH, attach, sizeof attach) < 0) { /* errno is the only clue: the server accepted the connection but the attach write failed, usually because it closed the socket while @@ -5228,6 +6133,7 @@ static void print_help(FILE *out) { help_row(out, "-h, --help", "show this help and exit"); help_row(out, "-v, --version", "print the version and exit"); help_row(out, "-l, --list-sessions", "list running sessions without attaching"); + help_row(out, "--adopt", "move a session to a new server binary"); help_row(out, "-p, --prefix LETTER", "client prefix Ctrl-LETTER (a-z, default: a)"); help_row(out, "-s, --status POSITION", "status line: top or bottom (new sessions: top)"); help_row(out, "-c, --color RRGGBB", "status bar background, six hex digits (e.g. 000000)"); @@ -5241,11 +6147,19 @@ static void print_help(FILE *out) { help_row(out, "-m, --murx", "show [murx] in status bar unless --cwd is set"); help_row(out, "-n, --hostname", "show hostname: prefix in window titles"); help_row(out, "-t, --titles", "show the title row above each pane (default: off)"); + help_row(out, "--resize-on-input", "session size follows the last client with input"); fputs("\n" + "--adopt asks the running server to hand the session to a new server\n" + "process, so an upgraded binary can take over without restarting panes.\n" + "It works with a session name or with the default session, and needs\n" + "cooperation from the running server; older servers are attached to\n" + "unchanged. Clients see a short notification when adoption succeeds.\n" + "\n" "Without -s or -c, an existing session keeps its position and color.\n" - "Display options set new session values and can be changed later from\n" - "the Configuration menu.\n" + "Without --resize-on-input, a session keeps its current size mode.\n" + "Display options and the size mode can be changed later\n" + "from the Configuration menu.\n" "\n" "Shortcuts (press the prefix, release it, then press the key shown;\n" "Ctrl-A is the default prefix):\n" @@ -5301,6 +6215,9 @@ static int parse_prefix(const char *text, unsigned char *prefix) { int main(int argc, char **argv) { setlocale(LC_CTYPE, ""); + /* The adoption handoff writes to a pipe whose reader is a forked server; + a failed start must surface as EPIPE, not kill this process. */ + signal(SIGPIPE, SIG_IGN); int argi = 1; unsigned char prefix = DEFAULT_PREFIX; @@ -5308,7 +6225,9 @@ int main(int argc, char **argv) { uint32_t color = 0; DisplayOptions display = {0}; int history_limit = DEFAULT_HISTORY_LINES; + uint32_t resize_mode = SIZE_MODE_KEEP; int list = 0; + int adopt = 0; while (argi < argc && argv[argi][0] == '-' && argv[argi][1]) { const char *option = argv[argi++]; if (strcmp(option, "--") == 0) break; @@ -5333,6 +6252,8 @@ int main(int argc, char **argv) { } history_limit = (int)lines; argi++; + } else if (strcmp(option, "--adopt") == 0) { + adopt = 1; } else if (strcmp(option, "-d") == 0 || strcmp(option, "--cwd") == 0) { display.show_cwd = 1; } else if (strcmp(option, "-C") == 0 || strcmp(option, "--clock") == 0) { @@ -5343,6 +6264,8 @@ int main(int argc, char **argv) { display.show_hostname = 1; } else if (strcmp(option, "-t") == 0 || strcmp(option, "--titles") == 0) { display.show_pane_titles = 1; + } else if (strcmp(option, "--resize-on-input") == 0) { + resize_mode = SIZE_MODE_ON; } else if (strcmp(option, "-p") == 0 || strcmp(option, "--prefix") == 0) { if (argi >= argc || !parse_prefix(argv[argi], &prefix)) { fprintf(stderr, "murx: %s requires a letter from a through z\n", option); @@ -5402,7 +6325,36 @@ int main(int argc, char **argv) { make_socket_path(name, path, sizeof path); int fd = connect_session(path); - if (fd < 0) fd = spawn_server(path, name, &display, history_limit); + AdoptHandoff handoff; + memset(&handoff, 0, sizeof handoff); + if (fd >= 0 && adopt) { + if (request_adoption(fd, &handoff) == 0) { + int adopted_fd = spawn_server(path, name, &display, history_limit, + &handoff); + adopt_handoff_free(&handoff); + if (adopted_fd < 0) { + int err = errno; + close(fd); + if (err) { + fprintf(stderr, "murx: cannot hand off session '%s': %s\n", + name, strerror(err)); + } + return 1; + } + fd = adopted_fd; + } else { + int err = errno ? errno : EPROTO; + if (err == ETIMEDOUT) { + fprintf(stderr, + "murx: session '%s' runs a server without adoption support; " + "attaching normally\n", name); + } else { + fprintf(stderr, "murx: cannot adopt session '%s': %s; " + "attaching normally\n", name, strerror(err)); + } + } + } + if (fd < 0) fd = spawn_server(path, name, &display, history_limit, NULL); if (fd < 0) { if (errno != 0) { fprintf(stderr, "murx: cannot start or attach session '%s': %s\n", @@ -5410,5 +6362,5 @@ int main(int argc, char **argv) { } return 1; } - return run_client(fd, name, prefix, status, color); + return run_client(fd, name, prefix, status, color, resize_mode); } From ee0ef444786ca546f16aed78442b4f77c908dc22 Mon Sep 17 00:00:00 2001 From: hanez Date: Tue, 24 Nov 2026 10:42:09 +0100 Subject: [PATCH 16/18] Release murx 1.0.4 and fix the Arch build --- RELEASES.md | 12 +++++++++++- murx.c | 11 +++++------ os/alpine/APKBUILD | 8 ++++---- os/arch/PKGBUILD | 8 ++++---- os/debian/changelog | 6 ++++++ 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/RELEASES.md b/RELEASES.md index 0fda5c4..f10a44d 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,9 +1,19 @@ -# Unreleased +# murx 1.0.4 released + +**November 24, 2026** - Added short options for `--history` (`-H`), `--cwd` (`-d`), `--clock` (`-C`), `--murx` (`-m`), `--hostname` (`-n`), and `--titles` (`-t`). - Renamed `--pane-titles` to `--titles`. +- Use `murx --adopt work` after upgrading to move a running session to the new + server while keeping panes, scrollback, and client connections. The running + server must support handoff. Sessions started by older versions need a + one-time restart. +- Use `--resize-on-input` or the Configuration menu's **Resize to last input** + toggle to make the session size follow the client that last sent input. +- Fixed the build with Arch's compiler flags by reading handoff timestamps + into matching 64-bit types. # murx 1.0.3 released diff --git a/murx.c b/murx.c index 809d2d7..ba29c08 100644 --- a/murx.c +++ b/murx.c @@ -88,7 +88,7 @@ #define MURX_NOIPA #endif -#define MURX_VERSION "1.0.3" +#define MURX_VERSION "1.0.4" #define DEFAULT_PREFIX 0x01 /* client -> server */ @@ -1522,7 +1522,7 @@ struct Client { int truecolor; unsigned char in[16384]; size_t inlen; - long long escape_since; + int64_t escape_since; unsigned char net[65536]; size_t netlen; @@ -1553,7 +1553,7 @@ struct Client { int confirm_action; /* 1 kill pane, 2 kill server, 3 kill window */ char msg[256]; - long long msg_until; + int64_t msg_until; char title[160]; @@ -1849,7 +1849,7 @@ static Pane *pane_new(const char *cwd, int w, int h, const char *title, signal(SIGTERM, SIG_DFL); setenv("TERM", "screen-256color", 1); if (session_name && *session_name) setenv("MURX", session_name, 1); - if (cwd && *cwd) chdir(cwd); + if (cwd && *cwd && chdir(cwd) < 0) perror("murx: chdir"); const char *base = strrchr(shell, '/'); base = base ? base + 1 : shell; char arg0[PATH_MAX]; @@ -4895,8 +4895,7 @@ static int session_serialize(Session *s, HBuf *b, int *fds, int *nfds, buf_i32(b, last_idx); buf_u32(b, (uint32_t)nclient); - int ci = 0; - for (Client *c = s->clients; c; c = c->next, ci++) { + for (Client *c = s->clients; c; c = c->next) { fds[fd_i++] = c->fd; ser_client(b, c, fd_i - 1, panes, npane, c == adopt_client ? adopt_skip : 0); diff --git a/os/alpine/APKBUILD b/os/alpine/APKBUILD index 36a641e..a5ea265 100644 --- a/os/alpine/APKBUILD +++ b/os/alpine/APKBUILD @@ -1,6 +1,6 @@ # Local source snapshot; refresh version and checksums with `make pkgsums`. pkgname=murx -pkgver=1.0.3 +pkgver=1.0.4 pkgrel=0 pkgdesc="Small persistent terminal multiplexer" url="https://codeberg.org/armin/murx" @@ -26,10 +26,10 @@ package() { } sha512sums=" -299f4fcc053bcf46313ad34655aaf9180b59dc3a86758fd24e848c0cb1933d99ceeb56e4f85c592dd612d625f55b118284ee6a94c991216af61daa343091d518 murx.c +9ea57a94318d3b8df8e8e2e4c45ad00a0df9b54cb6d93b9d1cb5f2f0a0c26ab3402a70d141404fb8124b92e58f2581944e4d924094f927e9b035e4fe1836913d murx.c ac75bfe596fae665ba882a10f5d16551bdd02cd601b786364763ac74dbc651c386d3a464eb63e0344354b953611629135190633e3b8ff3a8ef0f0849d60a3f7b Makefile -7546e0d84cb9094b4b2ac14e05d38a37270c2a4451f3d41aaa7b0b38290acb0ff6de821331634c802d08568817cf1ed0fbb5afd6734ef4a8155720b826ab6ce9 murx.1 -6dce945220e19d90e295c1bdac3c9015f93759c22ba7dcbf467d8c7b9d3c0d6369770bba149da68925e9a02cb0df96e3d1ed2889529288de5cf29202604de090 MURX-README.md +16a542970423f761175da657bc54d37c089197cc3428397c2de51a312280c751b03af70ce38cf5b3fea9e0b2ed006d5b892e54ddbc625806e05e41a726b18225 murx.1 +1ce08e99e30b85347bf8f228525440887e083f9cc2175f951693fa2dad9357870fa587ffc1ee98a60edad957468f2b8b8af96ac3bf6ddd38df13deceb429f381 MURX-README.md 2fe33ba22c5f68e124904be594208f050be20f33d115f9a56f60cac93304102da32e6a7e78154e831d3704da7ca8bfefd7025e7b8901e65babcd83e7342f6382 LICENSE 4d32dba475e5f9818fcd008068b011cbae9fc4b8e29897c933775d6660f44a7992d08a1550320d83233af729a42b241ef1d182bf5983ef2f64deab76cab2260d AUTHORS " diff --git a/os/arch/PKGBUILD b/os/arch/PKGBUILD index a3daaf1..7c8de1c 100644 --- a/os/arch/PKGBUILD +++ b/os/arch/PKGBUILD @@ -1,6 +1,6 @@ # Local source snapshot; refresh version and checksums with `make pkgsums`. pkgname=murx -pkgver=1.0.3 +pkgver=1.0.4 pkgrel=1 pkgdesc='Small persistent terminal multiplexer' arch=('x86_64' 'aarch64') @@ -8,10 +8,10 @@ url='https://codeberg.org/armin/murx' license=('Apache-2.0') depends=('glibc') source=('murx.c' 'Makefile' 'murx.1' 'MURX-README.md' 'LICENSE' 'AUTHORS') -sha256sums=('4ab7d155c3d9b23c22fc5792837ce2dd4e020cf0998edb743e7726edee73b438' +sha256sums=('824e06e7e77c57437509fcd9b8eea7eef83d84aba0e6e376abd58f95b89d9b2a' '78a9c19c212e8038422e1bb4bb96d9b25eb19ad1359489cd32edf9e1a76638b2' - 'a4b48ce1c847869956ea52eac50c51446a9e6f720d8e4b211cb97a78a7f53663' - 'c49f2baa2a00da7a73881d6d05cbc07c28530b7f831ebdb2639fa1bb974a9290' + '00496e2c82881dfc10e70d64ebcfde94f25bd3227c1481fa29ce564c81b55c2d' + '615dffa59389202bf7efb1e2a0b672e1e6b1801e1289f4f68728c9dfe98d4ea2' '31c5556be4cdd9bf52bb55f18ead0c68a4f0e793c2c2dab0a2a2c6d92407d0d4' 'dbc8a4fc569d4cd7bcd45516ccc98c1396fce0682c262103069c8f5150538cdb') diff --git a/os/debian/changelog b/os/debian/changelog index 4ee4e82..c7c15ff 100644 --- a/os/debian/changelog +++ b/os/debian/changelog @@ -1,3 +1,9 @@ +murx (1.0.4-1) unstable; urgency=medium + + * Update to upstream version 1.0.4. + + -- Johannes Findeisen Tue, 24 Nov 2026 10:40:26 +0100 + murx (1.0.3-1) unstable; urgency=medium * Add Debian packaging for murx 1.0.3. From 5192e883ce78ed20fa548573aa055724bf33822b Mon Sep 17 00:00:00 2001 From: hanez Date: Tue, 24 Nov 2026 17:07:50 +0100 Subject: [PATCH 17/18] Fixed build warning. --- murx.c | 5 ++++- os/alpine/APKBUILD | 2 +- os/arch/PKGBUILD | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/murx.c b/murx.c index ba29c08..ff9a12b 100644 --- a/murx.c +++ b/murx.c @@ -530,7 +530,10 @@ static int utf8_decode(const unsigned char *s, size_t n, uint32_t *cp) { static int cp_width(uint32_t cp) { int w; if (cp == 0 || cp == WIDE_CONT) return 1; - if (!unicode_scalar(cp) || (uintmax_t)cp > (uintmax_t)WCHAR_MAX) return 1; + if (!unicode_scalar(cp)) return 1; +#if WCHAR_MAX < 0x10FFFF + if (cp > WCHAR_MAX) return 1; +#endif w = wcwidth((wchar_t)cp); if (w < 0) return 1; return w; diff --git a/os/alpine/APKBUILD b/os/alpine/APKBUILD index a5ea265..996287e 100644 --- a/os/alpine/APKBUILD +++ b/os/alpine/APKBUILD @@ -26,7 +26,7 @@ package() { } sha512sums=" -9ea57a94318d3b8df8e8e2e4c45ad00a0df9b54cb6d93b9d1cb5f2f0a0c26ab3402a70d141404fb8124b92e58f2581944e4d924094f927e9b035e4fe1836913d murx.c +fb4a217160f7816b03adb76272a6c477d106d4b5d91a404f3041b579910c233df9fcb84dbef358219e1b9df783a59729458c9418b0277e257661a9d5a5bb7300 murx.c ac75bfe596fae665ba882a10f5d16551bdd02cd601b786364763ac74dbc651c386d3a464eb63e0344354b953611629135190633e3b8ff3a8ef0f0849d60a3f7b Makefile 16a542970423f761175da657bc54d37c089197cc3428397c2de51a312280c751b03af70ce38cf5b3fea9e0b2ed006d5b892e54ddbc625806e05e41a726b18225 murx.1 1ce08e99e30b85347bf8f228525440887e083f9cc2175f951693fa2dad9357870fa587ffc1ee98a60edad957468f2b8b8af96ac3bf6ddd38df13deceb429f381 MURX-README.md diff --git a/os/arch/PKGBUILD b/os/arch/PKGBUILD index 7c8de1c..f26783b 100644 --- a/os/arch/PKGBUILD +++ b/os/arch/PKGBUILD @@ -8,7 +8,7 @@ url='https://codeberg.org/armin/murx' license=('Apache-2.0') depends=('glibc') source=('murx.c' 'Makefile' 'murx.1' 'MURX-README.md' 'LICENSE' 'AUTHORS') -sha256sums=('824e06e7e77c57437509fcd9b8eea7eef83d84aba0e6e376abd58f95b89d9b2a' +sha256sums=('ab974ac7c5aab39c60d8b1c4e13974bd25d4cee3a228a821dc4f83cafc0d2e0d' '78a9c19c212e8038422e1bb4bb96d9b25eb19ad1359489cd32edf9e1a76638b2' '00496e2c82881dfc10e70d64ebcfde94f25bd3227c1481fa29ce564c81b55c2d' '615dffa59389202bf7efb1e2a0b672e1e6b1801e1289f4f68728c9dfe98d4ea2' From b74b1f0664fe1008dd256fea75a3e0640dd74e40 Mon Sep 17 00:00:00 2001 From: hanez Date: Tue, 24 Nov 2026 18:06:41 +0100 Subject: [PATCH 18/18] FeeBSD and OpenBSD ports update. --- os/freebsd/sysutils/murx/Makefile | 2 +- os/openbsd/sysutils/murx/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/os/freebsd/sysutils/murx/Makefile b/os/freebsd/sysutils/murx/Makefile index 9c56547..01888b1 100644 --- a/os/freebsd/sysutils/murx/Makefile +++ b/os/freebsd/sysutils/murx/Makefile @@ -1,5 +1,5 @@ PORTNAME= murx -DISTVERSION= 1.0.3 +DISTVERSION= 1.0.4 CATEGORIES= sysutils MASTER_SITES= https://xw3.org/murx/murx/archive/ diff --git a/os/openbsd/sysutils/murx/Makefile b/os/openbsd/sysutils/murx/Makefile index 4d342b6..3d66363 100644 --- a/os/openbsd/sysutils/murx/Makefile +++ b/os/openbsd/sysutils/murx/Makefile @@ -1,6 +1,6 @@ COMMENT = small persistent terminal multiplexer -DISTNAME = murx-1.0.3 +DISTNAME = murx-1.0.4 CATEGORIES = sysutils HOMEPAGE = https://codeberg.org/armin/murx MAINTAINER = Johannes Findeisen