Skip to content

Commit c1ec858

Browse files
committed
Fix fg/bg colors sequences in WezTerm on Windows
1 parent ea30429 commit c1ec858

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

src/client.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,45 @@ async fn client_main_loop(
120120
))
121121
}
122122
};
123-
write!(std::io::stdout(), "{}", action)?;
123+
// WezTerm on Windows doesn't support colors in form
124+
// `CSI 38:2::0:0:0m`, use ';' instead.
125+
match action {
126+
Action::CSI(CSI::Sgr(Sgr::Foreground(fg))) => match fg {
127+
ColorSpec::Default => write!(std::io::stdout(), "\x1b[39m")?,
128+
ColorSpec::PaletteIndex(idx @ 0..=7) => {
129+
write!(std::io::stdout(), "\x1b[{}m", 30 + idx)?;
130+
}
131+
ColorSpec::PaletteIndex(idx @ 8..=15) => {
132+
write!(std::io::stdout(), "\x1b[{}m", 90 - 8 + idx)?;
133+
}
134+
ColorSpec::PaletteIndex(idx) => {
135+
write!(std::io::stdout(), "\x1b[38;5;{}m", idx)?;
136+
}
137+
ColorSpec::TrueColor(srgba_tuple) => {
138+
let (r, g, b, _a) = srgba_tuple.as_rgba_u8();
139+
write!(std::io::stdout(), "\x1b[38;2;{};{};{}m", r, g, b)?;
140+
}
141+
},
142+
Action::CSI(CSI::Sgr(Sgr::Background(bg))) => match bg {
143+
ColorSpec::Default => write!(std::io::stdout(), "\x1b[49m")?,
144+
ColorSpec::PaletteIndex(idx @ 0..=7) => {
145+
write!(std::io::stdout(), "\x1b[{}m", 40 + idx)?;
146+
}
147+
ColorSpec::PaletteIndex(idx @ 8..=15) => {
148+
write!(std::io::stdout(), "\x1b[{}m", 100 + idx)?;
149+
}
150+
ColorSpec::PaletteIndex(idx) => {
151+
write!(std::io::stdout(), "\x1b[48;5;{}m", idx)?;
152+
}
153+
ColorSpec::TrueColor(srgba_tuple) => {
154+
let (r, g, b, _a) = srgba_tuple.as_rgba_u8();
155+
write!(std::io::stdout(), "\x1b[48;2;{};{};{}m", r, g, b)?;
156+
}
157+
},
158+
_ => {
159+
write!(std::io::stdout(), "{}", action)?;
160+
}
161+
}
124162
}
125163
SrvToClt::ResetAttrs => {
126164
let action = Action::CSI(CSI::Sgr(Sgr::Reset));

src/theme.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ impl Theme {
1818
}
1919
}
2020

21-
pub fn pane(&self, active: bool) -> Block {
21+
pub fn pane(&'_ self, active: bool) -> Block<'_> {
2222
let type_ = match active {
2323
true => BorderType::Thick,
2424
false => BorderType::Plain,

0 commit comments

Comments
 (0)