1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-27 12:23:46 +03:00

osc 4 accepts multiple parameters

This commit is contained in:
Wez Furlong 2019-06-01 19:59:44 -07:00
parent 4193442ec8
commit 276e9aef91
2 changed files with 37 additions and 16 deletions

View File

@ -2107,15 +2107,16 @@ impl<'a> Performer<'a> {
OperatingSystemCommand::SystemNotification(message) => {
eprintln!("Application sends SystemNotification: {}", message);
}
OperatingSystemCommand::ChangeColorNumber(palette_index, colorspec) => {
eprintln!(
"ChangeColorNumber {} to {}",
palette_index,
colorspec.to_rgb_string()
);
if palette_index < 256 {
self.palette.colors.0[palette_index] = colorspec;
OperatingSystemCommand::ChangeColorNumber(specs) => {
for pair in specs {
eprintln!(
"ChangeColorNumber {} to {}",
pair.palette_index,
pair.color.to_rgb_string()
);
self.palette.colors.0[pair.palette_index as usize] = pair.color;
}
self.make_all_lines_dirty();
}
}
}

View File

@ -21,11 +21,17 @@ pub enum OperatingSystemCommand {
SetSelection(Selection, String),
SystemNotification(String),
ITermProprietary(ITermProprietary),
ChangeColorNumber(usize, RgbColor),
ChangeColorNumber(Vec<ChangeColorPair>),
Unspecified(Vec<Vec<u8>>),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ChangeColorPair {
pub palette_index: u8,
pub color: RgbColor,
}
bitflags! {
pub struct Selection :u16{
const NONE = 0;
@ -128,14 +134,23 @@ impl OperatingSystemCommand {
}
fn parse_change_color_number(osc: &[&[u8]]) -> Fallible<Self> {
ensure!(osc.len() == 3, "wrong number of params");
let mut pairs = vec![];
let mut iter = osc.iter();
iter.next(); // skip the command word that we already know is present
let index: usize = str::from_utf8(osc[1])?.parse()?;
let spec = str::from_utf8(osc[2])?;
let spec = RgbColor::from_named_or_rgb_string(spec)
.ok_or_else(|| err_msg("invalid color spec"))?;
while let (Some(index), Some(spec)) = (iter.next(), iter.next()) {
let index: u8 = str::from_utf8(index)?.parse()?;
let spec = str::from_utf8(spec)?;
let spec = RgbColor::from_named_or_rgb_string(spec)
.ok_or_else(|| err_msg("invalid color spec"))?;
Ok(OperatingSystemCommand::ChangeColorNumber(index, spec))
pairs.push(ChangeColorPair {
palette_index: index,
color: spec,
});
}
Ok(OperatingSystemCommand::ChangeColorNumber(pairs))
}
fn internal_parse(osc: &[&[u8]]) -> Fallible<Self> {
@ -235,7 +250,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)?,
ChangeColorNumber(index, spec) => write!(f, "4;{};{}", index, spec.to_rgb_string())?,
ChangeColorNumber(specs) => {
write!(f, "4;")?;
for pair in specs {
write!(f, "{};{}", pair.palette_index, pair.color.to_rgb_string())?
}
}
};
write!(f, "\x07")?;
Ok(())