From 12b56a4b6877492c143e489263a4aeb5e2567c77 Mon Sep 17 00:00:00 2001 From: r1w1s1 Date: Wed, 22 Apr 2026 17:24:55 -0300 Subject: [PATCH] mtm: add patches/ layout with series file; add -c empty arg and SGR truecolor fixes --- system/mtm/mtm.SlackBuild | 9 ++--- .../0001-fix-empty-commandkey-arg.patch | 19 +++++++++ ...-fix-sgr-truecolor-param-consumption.patch | 39 +++++++++++++++++++ .../{ => patches}/mtm-1.2.1-man-nuke.patch | 0 system/mtm/{ => patches}/mtm-1.2.1-nuke.patch | 0 system/mtm/patches/series | 4 ++ 6 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 system/mtm/patches/0001-fix-empty-commandkey-arg.patch create mode 100644 system/mtm/patches/0002-fix-sgr-truecolor-param-consumption.patch rename system/mtm/{ => patches}/mtm-1.2.1-man-nuke.patch (100%) rename system/mtm/{ => patches}/mtm-1.2.1-nuke.patch (100%) create mode 100644 system/mtm/patches/series diff --git a/system/mtm/mtm.SlackBuild b/system/mtm/mtm.SlackBuild index 6353014fa23..b58298e2b9e 100644 --- a/system/mtm/mtm.SlackBuild +++ b/system/mtm/mtm.SlackBuild @@ -78,11 +78,10 @@ fi tar xvf $CWD/$PRGNAM-$VERSION.tar.?z* cd $PRGNAM-$VERSION -# Backport upstream commit 6af156e (Add nuke keystroke) -patch -p1 < $CWD/mtm-1.2.1-nuke.patch - -# Add documentation for Ctrl+g k (nuke) keystroke to man page -patch -p1 < $CWD/mtm-1.2.1-man-nuke.patch +cat $CWD/patches/series | while read patch ; do + echo "*** Applying patch $patch" + cat $CWD/patches/$patch | patch -p1 --verbose || exit 1 +done || exit 1 chown -R root:root . diff --git a/system/mtm/patches/0001-fix-empty-commandkey-arg.patch b/system/mtm/patches/0001-fix-empty-commandkey-arg.patch new file mode 100644 index 00000000000..d99338e760a --- /dev/null +++ b/system/mtm/patches/0001-fix-empty-commandkey-arg.patch @@ -0,0 +1,19 @@ +From: r1w1s1 +Date: Wed, 22 Apr 2026 +Subject: Reject empty argument to -c flag + +Without this check, `mtm -c ""` dereferences optarg[0] which is '\0', +making CTL('\0') == 0 the command prefix. Every NUL byte in PTY input +then triggers command mode. Ignore empty strings and keep the default. +--- +--- a/mtm.c ++++ b/mtm.c +@@ -665,7 +665,7 @@ main(int argc, char **argv) + + int c = 0; + while ((c = getopt(argc, argv, "c:T:t:")) != -1) switch (c){ +- case 'c': commandkey = CTL(optarg[0]); break; ++ case 'c': if (optarg[0]) commandkey = CTL(optarg[0]); break; + case 'T': setenv("TERM", optarg, 1); break; + case 't': term = optarg; break; + default: quit(EXIT_FAILURE, USAGE); break; diff --git a/system/mtm/patches/0002-fix-sgr-truecolor-param-consumption.patch b/system/mtm/patches/0002-fix-sgr-truecolor-param-consumption.patch new file mode 100644 index 00000000000..0a3a55b187b --- /dev/null +++ b/system/mtm/patches/0002-fix-sgr-truecolor-param-consumption.patch @@ -0,0 +1,39 @@ +From: r1w1s1 +Date: Wed, 22 Apr 2026 +Subject: Fix SGR parameter consumption for truecolor sequences + +SGR 38/48 can take either `;5;N` (256-color) or `;2;R;G;B` (truecolor). +The old code assumed ;5;N and always skipped 2 params, so `;2;R;G;B` +caused R, G, B to be reinterpreted as SGR codes, producing garbage +attributes. Handle both forms and skip the correct number of params. +Truecolor values are not rendered (ncurses pair limitation) but are +now consumed cleanly. +--- +--- a/mtm.c ++++ b/mtm.c +@@ -449,7 +449,11 @@ + case 35: fg = COLOR_MAGENTA; doc = do8; break; + case 36: fg = COLOR_CYAN; doc = do8; break; + case 37: fg = COLOR_WHITE; doc = do8; break; +- case 38: fg = P0(i+1) == 5? P0(i+2) : s->fg; i += 2; doc = do256; break; ++ case 38: ++ if (P0(i+1) == 5) { fg = P0(i+2); i += 2; doc = do256; } ++ else if (P0(i+1) == 2) { i += 4; } ++ else i += 1; ++ break; + case 39: fg = -1; doc = true; break; + case 40: bg = COLOR_BLACK; doc = do8; break; + case 41: bg = COLOR_RED; doc = do8; break; +@@ -459,7 +463,11 @@ + case 45: bg = COLOR_MAGENTA; doc = do8; break; + case 46: bg = COLOR_CYAN; doc = do8; break; + case 47: bg = COLOR_WHITE; doc = do8; break; +- case 48: bg = P0(i+1) == 5? P0(i+2) : s->bg; i += 2; doc = do256; break; ++ case 48: ++ if (P0(i+1) == 5) { bg = P0(i+2); i += 2; doc = do256; } ++ else if (P0(i+1) == 2) { i += 4; } ++ else i += 1; ++ break; + case 49: bg = -1; doc = true; break; + case 90: fg = COLOR_BLACK; doc = do16; break; + case 91: fg = COLOR_RED; doc = do16; break; diff --git a/system/mtm/mtm-1.2.1-man-nuke.patch b/system/mtm/patches/mtm-1.2.1-man-nuke.patch similarity index 100% rename from system/mtm/mtm-1.2.1-man-nuke.patch rename to system/mtm/patches/mtm-1.2.1-man-nuke.patch diff --git a/system/mtm/mtm-1.2.1-nuke.patch b/system/mtm/patches/mtm-1.2.1-nuke.patch similarity index 100% rename from system/mtm/mtm-1.2.1-nuke.patch rename to system/mtm/patches/mtm-1.2.1-nuke.patch diff --git a/system/mtm/patches/series b/system/mtm/patches/series new file mode 100644 index 00000000000..1511b6c9005 --- /dev/null +++ b/system/mtm/patches/series @@ -0,0 +1,4 @@ +mtm-1.2.1-man-nuke.patch +mtm-1.2.1-nuke.patch +0001-fix-empty-commandkey-arg.patch +0002-fix-sgr-truecolor-param-consumption.patch