Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/cli/pty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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'[' {
Expand Down Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions src/profiles/builtin/generic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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(?<!not )(?<!not-)(?<!not )(?<!not\t)(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'
regex: '(?i)\bnot[ \t-]+(?&good)\b(*SKIP)(*F)|\b(?<good>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'
Expand Down
17 changes: 15 additions & 2 deletions tests/config_and_highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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!(
Expand All @@ -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:?}");
}
Expand Down
Loading