Add foreground/background request escape codes
This commit is contained in:
parent
dea7a0890a
commit
f79007035c
|
@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
- Config group `debug` with the options `debug.log_level`, `debug.print_events`
|
- Config group `debug` with the options `debug.log_level`, `debug.print_events`
|
||||||
and `debug.ref_test`
|
and `debug.ref_test`
|
||||||
- Select until next matching bracket when double-clicking a bracket
|
- Select until next matching bracket when double-clicking a bracket
|
||||||
|
- Added foreground/background escape code request sequences
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
|
|
@ -332,6 +332,9 @@ pub trait Handler {
|
||||||
/// Set an indexed color value
|
/// Set an indexed color value
|
||||||
fn set_color(&mut self, _: usize, _: Rgb) {}
|
fn set_color(&mut self, _: usize, _: Rgb) {}
|
||||||
|
|
||||||
|
/// Write a foreground/background color escape sequence with the current color
|
||||||
|
fn dynamic_color_sequence<W: io::Write>(&mut self, _: &mut W, _: u8, _: usize) {}
|
||||||
|
|
||||||
/// Reset an indexed color to original value
|
/// Reset an indexed color to original value
|
||||||
fn reset_color(&mut self, _: usize) {}
|
fn reset_color(&mut self, _: usize) {}
|
||||||
|
|
||||||
|
@ -741,6 +744,8 @@ where
|
||||||
// TODO replace OSC parsing with parser combinators
|
// TODO replace OSC parsing with parser combinators
|
||||||
#[inline]
|
#[inline]
|
||||||
fn osc_dispatch(&mut self, params: &[&[u8]]) {
|
fn osc_dispatch(&mut self, params: &[&[u8]]) {
|
||||||
|
let writer = &mut self.writer;
|
||||||
|
|
||||||
fn unhandled(params: &[&[u8]]) {
|
fn unhandled(params: &[&[u8]]) {
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
for items in params {
|
for items in params {
|
||||||
|
@ -788,23 +793,37 @@ where
|
||||||
unhandled(params);
|
unhandled(params);
|
||||||
},
|
},
|
||||||
|
|
||||||
// Set foreground color
|
// Get/set foreground color
|
||||||
b"10" => {
|
b"10" => {
|
||||||
if params.len() >= 2 {
|
if params.len() >= 2 {
|
||||||
if let Some(color) = parse_rgb_color(params[1]) {
|
if let Some(color) = parse_rgb_color(params[1]) {
|
||||||
self.handler.set_color(NamedColor::Foreground as usize, color);
|
self.handler.set_color(NamedColor::Foreground as usize, color);
|
||||||
return;
|
return;
|
||||||
|
} else if params[1] == b"?" {
|
||||||
|
self.handler.dynamic_color_sequence(
|
||||||
|
writer,
|
||||||
|
10,
|
||||||
|
NamedColor::Foreground as usize,
|
||||||
|
);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unhandled(params);
|
unhandled(params);
|
||||||
},
|
},
|
||||||
|
|
||||||
// Set background color
|
// Get/set background color
|
||||||
b"11" => {
|
b"11" => {
|
||||||
if params.len() >= 2 {
|
if params.len() >= 2 {
|
||||||
if let Some(color) = parse_rgb_color(params[1]) {
|
if let Some(color) = parse_rgb_color(params[1]) {
|
||||||
self.handler.set_color(NamedColor::Background as usize, color);
|
self.handler.set_color(NamedColor::Background as usize, color);
|
||||||
return;
|
return;
|
||||||
|
} else if params[1] == b"?" {
|
||||||
|
self.handler.dynamic_color_sequence(
|
||||||
|
writer,
|
||||||
|
11,
|
||||||
|
NamedColor::Background as usize,
|
||||||
|
);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unhandled(params);
|
unhandled(params);
|
||||||
|
|
|
@ -1870,6 +1870,14 @@ impl ansi::Handler for Term {
|
||||||
self.color_modified[index] = true;
|
self.color_modified[index] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Write a foreground/background color escape sequence with the current color
|
||||||
|
#[inline]
|
||||||
|
fn dynamic_color_sequence<W: io::Write>(&mut self, writer: &mut W, code: u8, index: usize) {
|
||||||
|
trace!("Writing escape sequence for dynamic color code {}: color[{}]", code, index);
|
||||||
|
let color = self.colors[index];
|
||||||
|
let _ = write!(writer, "\x1b]{};rgb:{:x}/{:x}/{:x}\x07", code, color.r, color.g, color.b);
|
||||||
|
}
|
||||||
|
|
||||||
/// Reset the indexed color to original value
|
/// Reset the indexed color to original value
|
||||||
#[inline]
|
#[inline]
|
||||||
fn reset_color(&mut self, index: usize) {
|
fn reset_color(&mut self, index: usize) {
|
||||||
|
|
Loading…
Reference in New Issue