From b04690aae97fd4cad5dd5cc8a8156687ab1552f0 Mon Sep 17 00:00:00 2001 From: Christian Dassy <18606875+inxbit@users.noreply.github.com> Date: Tue, 17 Nov 2026 02:42:48 -0500 Subject: [PATCH] Close two gaps in the 1.3.1 fixes - --local-echo took any byte after `ESC O` for the end of an SS3 key, so Escape, `O`, Enter typed in turn lost the echoed line break. Only a final byte completes the key now. - generic: the red `not connected` rule accepted spacing the green rule did not exclude, so `not` plus a space and a tab, or three spaces, still left `connected` green. The good-state rule now skips any good word that follows `not` and spacing of any length. --- src/cli/pty.rs | 15 ++++++++++----- src/profiles/builtin/generic.yml | 4 ++-- tests/config_and_highlight.rs | 17 +++++++++++++++-- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/cli/pty.rs b/src/cli/pty.rs index 1764154..edd0fa8 100644 --- a/src/cli/pty.rs +++ b/src/cli/pty.rs @@ -1476,12 +1476,13 @@ fn local_echo_escape_step(input: &[u8], idx: usize) -> LocalEchoStep { return LocalEchoStep::Incomplete; }; // SS3: an arrow or function key in application mode, `ESC O` plus one - // final byte. + // final byte. Anything else after `ESC O` is not a key: the `O` and what + // follows are handled as typed. if *next == b'O' { - return if idx + 2 < input.len() { - LocalEchoStep::Skip(idx + 3) - } else { - LocalEchoStep::Incomplete + return match input.get(idx + 2) { + None => LocalEchoStep::Incomplete, + Some(0x40..=0x7e) => LocalEchoStep::Skip(idx + 3), + Some(_) => LocalEchoStep::Skip(idx + 1), }; } if *next != b'[' { @@ -2806,6 +2807,10 @@ mod tests { let mut echo = super::LocalEchoState::default(); assert!(echo.push(b"\x1bO").is_empty()); assert_eq!(echo.push(b"Ax"), b"x"); + + // Only a final byte completes the key. Escape, `O`, Enter typed one + // after the other must still echo the line break. + assert_eq!(super::local_echo_bytes(b"x\x1bO\ry\r"), b"xO\r\ny\r\n"); } #[test] diff --git a/src/profiles/builtin/generic.yml b/src/profiles/builtin/generic.yml index 0599329..73bc421 100644 --- a/src/profiles/builtin/generic.yml +++ b/src/profiles/builtin/generic.yml @@ -18,13 +18,13 @@ rules: color: f#ff9aff exclusive: true - description: bad operational state - regex: '(?i)\b(password|abnormal(ly)?|down|los(t|s|ing)|err(or(s)?)?|den(y|ies|ied)|reject(ing|ed)?|drop(ped|s)?|fail(s|ed|ures?)?|not[ \t-]{1,2}(connect(ed)?|reachable)|disconnect(ed)?|unreachable|invalid|bad|notconnect|unusable|blocking|blocked|collision(s)?|unsynchronized|mismatch|runts|CRC|resets)\b' + regex: '(?i)\b(password|abnormal(ly)?|down|los(t|s|ing)|err(or(s)?)?|den(y|ies|ied)|reject(ing|ed)?|drop(ped|s)?|fail(s|ed|ures?)?|not[ \t-]+(connect(ed)?|reachable)|disconnect(ed)?|unreachable|invalid|bad|notconnect|unusable|blocking|blocked|collision(s)?|unsynchronized|mismatch|runts|CRC|resets)\b' color: f#ff0000 bold - description: warning state regex: '(?i)\b(warning(s)?|degraded|standby|learning|listening|passive)\b' color: f#ffff00 - description: good operational state - regex: '(?i)\b(?up|ok(ay)?|permit(t?ed|s)?|accept(s|ed)?|enable(d)?|online|succe((ss(ful|fully)?)|ed(ed)?)?|connect(ed)?|reachable|valid|forwarding|synchronized|active)\b' color: f#00ff00 - description: syslog severe regex: '(%\w+(?:-\w+)?-[0-3]-\w+)\b' diff --git a/tests/config_and_highlight.rs b/tests/config_and_highlight.rs index 3808227..21ff580 100644 --- a/tests/config_and_highlight.rs +++ b/tests/config_and_highlight.rs @@ -286,6 +286,7 @@ fn highlight_with_builtin(profile: &str, input: &str) -> String { } const GREEN: &str = "\x1b[38;2;0;255;0m"; +const GREEN_FOREGROUND: &str = "38;2;0;255;0m"; const RED_BOLD: &str = "\x1b[1;38;2;255;0;0m"; // A good-state word after `not` reports a fault. It must not be painted @@ -296,16 +297,22 @@ fn generic_profile_does_not_paint_a_negated_good_state_green() { "route is not reachable\n", "interface is not connected\n", "peer is not\tconnected\n", + "peer is not \tconnected\n", + "peer is not connected\n", + "peer is not reachable\n", "clock is not synchronized\n", "license is not valid\n", "port is not-connected\n", ] { let output = highlight_with_builtin("generic", line); - assert!(!output.contains(GREEN), "{line:?} -> {output:?}"); + // Whatever attributes it is merged with, no green foreground. + assert!(!output.contains(GREEN_FOREGROUND), "{line:?} -> {output:?}"); } for (line, phrase) in [ ("route is not reachable\n", "not reachable"), ("interface is not connected\n", "not connected"), + ("peer is not \tconnected\n", "not \tconnected"), + ("peer is not reachable\n", "not reachable"), ] { let output = highlight_with_builtin("generic", line); assert!( @@ -314,7 +321,13 @@ fn generic_profile_does_not_paint_a_negated_good_state_green() { ); } // The plain forms keep their color. - for line in ["route is reachable\n", "port is connected\n", "link up\n"] { + for line in [ + "route is reachable\n", + "port is connected\n", + "link up\n", + "cannot connect, then connected\n", + "notable uptime: link up\n", + ] { let output = highlight_with_builtin("generic", line); assert!(output.contains(GREEN), "{line:?} -> {output:?}"); }