Add ´?´ support to OSC 4
This commit is contained in:
parent
e38f51c6bd
commit
60ef17e8e9
|
@ -15,6 +15,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
|
|
||||||
- The `--help` output was reworked with a new colorful syntax
|
- The `--help` output was reworked with a new colorful syntax
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- OSC 4 not handling `?`
|
||||||
|
- `?` in OSC strings reporting default colors instead of modified ones
|
||||||
|
|
||||||
## 0.10.0
|
## 0.10.0
|
||||||
|
|
||||||
### Packaging
|
### Packaging
|
||||||
|
|
|
@ -1076,8 +1076,9 @@ impl input::Processor<EventProxy, ActionContext<'_, Notifier, EventProxy>> {
|
||||||
self.ctx.write_to_pty(text.into_bytes());
|
self.ctx.write_to_pty(text.into_bytes());
|
||||||
},
|
},
|
||||||
TerminalEvent::ColorRequest(index, format) => {
|
TerminalEvent::ColorRequest(index, format) => {
|
||||||
let text = format(self.ctx.display.colors[index]);
|
let color = self.ctx.terminal().colors()[index]
|
||||||
self.ctx.write_to_pty(text.into_bytes());
|
.unwrap_or(self.ctx.display.colors[index]);
|
||||||
|
self.ctx.write_to_pty(format(color).into_bytes());
|
||||||
},
|
},
|
||||||
TerminalEvent::PtyWrite(text) => self.ctx.write_to_pty(text.into_bytes()),
|
TerminalEvent::PtyWrite(text) => self.ctx.write_to_pty(text.into_bytes()),
|
||||||
TerminalEvent::MouseCursorDirty => self.reset_mouse_cursor(),
|
TerminalEvent::MouseCursorDirty => self.reset_mouse_cursor(),
|
||||||
|
|
|
@ -972,17 +972,28 @@ where
|
||||||
|
|
||||||
// Set color index.
|
// Set color index.
|
||||||
b"4" => {
|
b"4" => {
|
||||||
if params.len() > 1 && params.len() % 2 != 0 {
|
if params.len() <= 1 || params.len() % 2 == 0 {
|
||||||
for chunk in params[1..].chunks(2) {
|
unhandled(params);
|
||||||
let index = parse_number(chunk[0]);
|
|
||||||
let color = xparse_color(chunk[1]);
|
|
||||||
if let (Some(i), Some(c)) = (index, color) {
|
|
||||||
self.handler.set_color(i as usize, c);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
for chunk in params[1..].chunks(2) {
|
||||||
|
let index = match parse_number(chunk[0]) {
|
||||||
|
Some(index) => index,
|
||||||
|
None => {
|
||||||
unhandled(params);
|
unhandled(params);
|
||||||
|
continue;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Some(c) = xparse_color(chunk[1]) {
|
||||||
|
self.handler.set_color(index as usize, c);
|
||||||
|
} else if chunk[1] == b"?" {
|
||||||
|
self.handler.dynamic_color_sequence(index, index as usize, terminator);
|
||||||
|
} else {
|
||||||
|
unhandled(params);
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// Get/set Foreground, Background, Cursor colors.
|
// Get/set Foreground, Background, Cursor colors.
|
||||||
|
@ -1494,6 +1505,7 @@ mod tests {
|
||||||
charset: StandardCharset,
|
charset: StandardCharset,
|
||||||
attr: Option<Attr>,
|
attr: Option<Attr>,
|
||||||
identity_reported: bool,
|
identity_reported: bool,
|
||||||
|
color: Option<Rgb>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Handler for MockHandler {
|
impl Handler for MockHandler {
|
||||||
|
@ -1517,6 +1529,10 @@ mod tests {
|
||||||
fn reset_state(&mut self) {
|
fn reset_state(&mut self) {
|
||||||
*self = Self::default();
|
*self = Self::default();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_color(&mut self, _: usize, c: Rgb) {
|
||||||
|
self.color = Some(c);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for MockHandler {
|
impl Default for MockHandler {
|
||||||
|
@ -1526,6 +1542,7 @@ mod tests {
|
||||||
charset: StandardCharset::Ascii,
|
charset: StandardCharset::Ascii,
|
||||||
attr: None,
|
attr: None,
|
||||||
identity_reported: false,
|
identity_reported: false,
|
||||||
|
color: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1724,4 +1741,18 @@ mod tests {
|
||||||
fn parse_number_too_large() {
|
fn parse_number_too_large() {
|
||||||
assert_eq!(parse_number(b"321"), None);
|
assert_eq!(parse_number(b"321"), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_osc4_set_color() {
|
||||||
|
let bytes: &[u8] = b"\x1b]4;0;#fff\x1b\\";
|
||||||
|
|
||||||
|
let mut parser = Processor::new();
|
||||||
|
let mut handler = MockHandler::default();
|
||||||
|
|
||||||
|
for byte in bytes {
|
||||||
|
parser.advance(&mut handler, *byte);
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_eq!(handler.color, Some(Rgb { r: 0xf0, g: 0xf0, b: 0xf0 }));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -818,6 +818,10 @@ impl<T> Term<T> {
|
||||||
cursor_cell.bg = bg;
|
cursor_cell.bg = bg;
|
||||||
cursor_cell.flags = flags;
|
cursor_cell.flags = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn colors(&self) -> &Colors {
|
||||||
|
&self.colors
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Dimensions for Term<T> {
|
impl<T> Dimensions for Term<T> {
|
||||||
|
|
Loading…
Reference in New Issue