mirror of
https://github.com/wez/wezterm.git
synced 2024-12-24 05:42:03 +03:00
Add support for OSC 104 (ResetColors)
This commit is contained in:
parent
3bc30d2d47
commit
ee70ec3ae0
@ -1817,7 +1817,7 @@ impl<'a> Performer<'a> {
|
||||
self.current_dir = Url::parse(&url).ok();
|
||||
}
|
||||
OperatingSystemCommand::ChangeColorNumber(specs) => {
|
||||
error!("ChangeColorNumber: {:?}", specs);
|
||||
log::trace!("ChangeColorNumber: {:?}", specs);
|
||||
for pair in specs {
|
||||
match pair.color {
|
||||
ColorOrQuery::Query => {
|
||||
@ -1837,8 +1837,28 @@ impl<'a> Performer<'a> {
|
||||
}
|
||||
self.make_all_lines_dirty();
|
||||
}
|
||||
|
||||
OperatingSystemCommand::ResetColors(colors) => {
|
||||
log::trace!("ResetColors: {:?}", colors);
|
||||
if colors.is_empty() {
|
||||
// Reset all colors
|
||||
self.palette.take();
|
||||
} else {
|
||||
// Reset individual colors
|
||||
if self.palette.is_none() {
|
||||
// Already at the defaults
|
||||
} else {
|
||||
let base = self.config.color_palette();
|
||||
for c in colors {
|
||||
let c = c as usize;
|
||||
self.palette_mut().colors.0[c] = base.colors.0[c];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
OperatingSystemCommand::ChangeDynamicColors(first_color, colors) => {
|
||||
error!("ChangeDynamicColors: {:?} {:?}", first_color, colors);
|
||||
log::trace!("ChangeDynamicColors: {:?} {:?}", first_color, colors);
|
||||
use termwiz::escape::osc::DynamicColorNumber;
|
||||
let mut idx: u8 = first_color as u8;
|
||||
for color in colors {
|
||||
|
@ -39,6 +39,7 @@ pub enum OperatingSystemCommand {
|
||||
ChangeColorNumber(Vec<ChangeColorPair>),
|
||||
ChangeDynamicColors(DynamicColorNumber, Vec<ColorOrQuery>),
|
||||
CurrentWorkingDirectory(String),
|
||||
ResetColors(Vec<u8>),
|
||||
|
||||
Unspecified(Vec<Vec<u8>>),
|
||||
}
|
||||
@ -141,11 +142,16 @@ impl Display for Selection {
|
||||
|
||||
impl OperatingSystemCommand {
|
||||
pub fn parse(osc: &[&[u8]]) -> Self {
|
||||
Self::internal_parse(osc).unwrap_or_else(|_| {
|
||||
Self::internal_parse(osc).unwrap_or_else(|err| {
|
||||
let mut vec = Vec::new();
|
||||
for slice in osc {
|
||||
vec.push(slice.to_vec());
|
||||
}
|
||||
log::trace!(
|
||||
"OSC internal parse err: {}, track as Unspecified {:?}",
|
||||
err,
|
||||
vec
|
||||
);
|
||||
OperatingSystemCommand::Unspecified(vec)
|
||||
})
|
||||
}
|
||||
@ -165,6 +171,22 @@ impl OperatingSystemCommand {
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_reset_colors(osc: &[&[u8]]) -> anyhow::Result<Self> {
|
||||
let mut colors = vec![];
|
||||
let mut iter = osc.iter();
|
||||
iter.next(); // skip the command word that we already know is present
|
||||
|
||||
while let Some(index) = iter.next() {
|
||||
if index.is_empty() {
|
||||
continue;
|
||||
}
|
||||
let index: u8 = str::from_utf8(index)?.parse()?;
|
||||
colors.push(index);
|
||||
}
|
||||
|
||||
Ok(OperatingSystemCommand::ResetColors(colors))
|
||||
}
|
||||
|
||||
fn parse_change_color_number(osc: &[&[u8]]) -> anyhow::Result<Self> {
|
||||
let mut pairs = vec![];
|
||||
let mut iter = osc.iter();
|
||||
@ -244,6 +266,7 @@ impl OperatingSystemCommand {
|
||||
self::ITermProprietary::parse(osc).map(OperatingSystemCommand::ITermProprietary)
|
||||
}
|
||||
ChangeColorNumber => Self::parse_change_color_number(osc),
|
||||
ResetColors => Self::parse_reset_colors(osc),
|
||||
|
||||
SetTextForegroundColor
|
||||
| SetTextBackgroundColor
|
||||
@ -291,6 +314,7 @@ pub enum OperatingSystemCommandCode {
|
||||
SetFont = 50,
|
||||
EmacsShell = 51,
|
||||
ManipulateSelectionData = 52,
|
||||
ResetColors = 104,
|
||||
RxvtProprietary = 777,
|
||||
ITermProprietary = 1337,
|
||||
}
|
||||
@ -325,6 +349,12 @@ impl Display for OperatingSystemCommand {
|
||||
SetSelection(s, val) => write!(f, "52;{};{}", s, base64::encode(val))?,
|
||||
SystemNotification(s) => write!(f, "9;{}", s)?,
|
||||
ITermProprietary(i) => i.fmt(f)?,
|
||||
ResetColors(colors) => {
|
||||
write!(f, "104")?;
|
||||
for c in colors {
|
||||
write!(f, ";{}", c)?;
|
||||
}
|
||||
}
|
||||
ChangeColorNumber(specs) => {
|
||||
write!(f, "4;")?;
|
||||
for pair in specs {
|
||||
@ -750,6 +780,22 @@ mod test {
|
||||
result
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reset_colors() {
|
||||
assert_eq!(
|
||||
parse(&["104"], "\x1b]104\x07"),
|
||||
OperatingSystemCommand::ResetColors(vec![])
|
||||
);
|
||||
assert_eq!(
|
||||
parse(&["104", ""], "\x1b]104\x07"),
|
||||
OperatingSystemCommand::ResetColors(vec![])
|
||||
);
|
||||
assert_eq!(
|
||||
parse(&["104", "1"], "\x1b]104;1\x07"),
|
||||
OperatingSystemCommand::ResetColors(vec![1])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn title() {
|
||||
assert_eq!(
|
||||
|
Loading…
Reference in New Issue
Block a user