mirror of
https://github.com/wez/wezterm.git
synced 2024-12-23 21:32:13 +03:00
CellAttribute: move fg/bg color accesses to accesors
This facilitates hiding the raw fields in the next diff
This commit is contained in:
parent
1a673a5e5b
commit
47839adf95
@ -18,9 +18,9 @@ use unicode_width::UnicodeWidthStr;
|
||||
pub struct CellAttributes {
|
||||
attributes: u16,
|
||||
/// The foreground color
|
||||
pub foreground: ColorAttribute,
|
||||
foreground: ColorAttribute,
|
||||
/// The background color
|
||||
pub background: ColorAttribute,
|
||||
background: ColorAttribute,
|
||||
/// Relatively rarely used attributes spill over to a heap
|
||||
/// allocated struct in order to keep CellAttributes
|
||||
/// smaller in the common case.
|
||||
@ -231,11 +231,19 @@ impl CellAttributes {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn foreground(&self) -> ColorAttribute {
|
||||
self.foreground
|
||||
}
|
||||
|
||||
pub fn set_background<C: Into<ColorAttribute>>(&mut self, background: C) -> &mut Self {
|
||||
self.background = background.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn background(&self) -> ColorAttribute {
|
||||
self.background
|
||||
}
|
||||
|
||||
fn allocate_fat_attributes(&mut self) {
|
||||
if self.fat.is_none() {
|
||||
self.fat.replace(Box::new(FatAttributes {
|
||||
|
@ -63,8 +63,8 @@ impl TerminfoRenderer {
|
||||
}
|
||||
|
||||
if let Some(attr) = self.pending_attr.take() {
|
||||
let mut current_foreground = self.current_attr.foreground;
|
||||
let mut current_background = self.current_attr.background;
|
||||
let mut current_foreground = self.current_attr.foreground();
|
||||
let mut current_background = self.current_attr.background();
|
||||
|
||||
if !attr.attribute_bits_equal(&self.current_attr) {
|
||||
// Updating the attribute bits also resets the colors.
|
||||
@ -130,8 +130,8 @@ impl TerminfoRenderer {
|
||||
None => 0,
|
||||
};
|
||||
|
||||
if attr.foreground != current_foreground {
|
||||
match (has_true_color, attr.foreground) {
|
||||
if attr.foreground() != current_foreground {
|
||||
match (has_true_color, attr.foreground()) {
|
||||
(true, ColorAttribute::TrueColorWithPaletteFallback(tc, _))
|
||||
| (true, ColorAttribute::TrueColorWithDefaultFallback(tc)) => {
|
||||
write!(
|
||||
@ -164,8 +164,8 @@ impl TerminfoRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
if attr.background != current_background {
|
||||
match (has_true_color, attr.background) {
|
||||
if attr.background() != current_background {
|
||||
match (has_true_color, attr.background()) {
|
||||
(true, ColorAttribute::TrueColorWithPaletteFallback(tc, _))
|
||||
| (true, ColorAttribute::TrueColorWithDefaultFallback(tc)) => {
|
||||
write!(
|
||||
@ -335,7 +335,8 @@ impl TerminfoRenderer {
|
||||
}
|
||||
self.pending_attr = None;
|
||||
|
||||
if self.current_attr.background == ColorAttribute::Default || self.caps.bce() {
|
||||
if self.current_attr.background() == ColorAttribute::Default || self.caps.bce()
|
||||
{
|
||||
// The erase operation respects "background color erase",
|
||||
// or we're clearing to the default background color, so we can
|
||||
// simply emit a clear screen op.
|
||||
@ -427,10 +428,14 @@ impl TerminfoRenderer {
|
||||
record!(set_underline, value);
|
||||
}
|
||||
Change::Attribute(AttributeChange::Foreground(col)) => {
|
||||
self.attr_apply(|attr| attr.foreground = *col);
|
||||
self.attr_apply(|attr| {
|
||||
attr.set_foreground(*col);
|
||||
});
|
||||
}
|
||||
Change::Attribute(AttributeChange::Background(col)) => {
|
||||
self.attr_apply(|attr| attr.background = *col);
|
||||
self.attr_apply(|attr| {
|
||||
attr.set_background(*col);
|
||||
});
|
||||
}
|
||||
Change::Attribute(AttributeChange::Hyperlink(link)) => {
|
||||
self.attr_apply(|attr| {
|
||||
|
@ -534,7 +534,7 @@ impl Line {
|
||||
// to emit ClearToEndOfLine instead.
|
||||
if attr
|
||||
== CellAttributes::default()
|
||||
.set_background(attr.background)
|
||||
.set_background(attr.background())
|
||||
.clone()
|
||||
{
|
||||
let left = text_run.trim_end_matches(' ').to_string();
|
||||
@ -558,8 +558,8 @@ impl Line {
|
||||
// background color, we don't need to emit an instruction
|
||||
// to clear the remainder of the line unless it has a different
|
||||
// background color.
|
||||
if attr.background != Default::default() {
|
||||
result.push(Change::ClearToEndOfLine(attr.background));
|
||||
if attr.background() != Default::default() {
|
||||
result.push(Change::ClearToEndOfLine(attr.background()));
|
||||
}
|
||||
} else {
|
||||
result.push(Change::Text(text_run));
|
||||
|
@ -480,8 +480,12 @@ impl Surface {
|
||||
Invisible(value) => {
|
||||
self.attributes.set_invisible(*value);
|
||||
}
|
||||
Foreground(value) => self.attributes.foreground = *value,
|
||||
Background(value) => self.attributes.background = *value,
|
||||
Foreground(value) => {
|
||||
self.attributes.set_foreground(*value);
|
||||
}
|
||||
Background(value) => {
|
||||
self.attributes.set_background(*value);
|
||||
}
|
||||
Hyperlink(value) => {
|
||||
self.attributes.set_hyperlink(value.clone());
|
||||
}
|
||||
|
@ -658,8 +658,8 @@ impl RenderableState {
|
||||
.saturating_sub(wezterm_term::unicode_column_width(&status));
|
||||
|
||||
let mut attr = CellAttributes::default();
|
||||
attr.foreground = AnsiColor::White.into();
|
||||
attr.background = AnsiColor::Blue.into();
|
||||
attr.set_foreground(AnsiColor::White);
|
||||
attr.set_background(AnsiColor::Blue);
|
||||
|
||||
result
|
||||
.last_mut()
|
||||
|
@ -417,14 +417,14 @@ fn parse_status_text(text: &str, default_cell: CellAttributes) -> Vec<Cell> {
|
||||
}
|
||||
Sgr::Foreground(col) => {
|
||||
if let ColorSpec::Default = col {
|
||||
pen.set_foreground(default_cell.foreground);
|
||||
pen.set_foreground(default_cell.foreground());
|
||||
} else {
|
||||
pen.set_foreground(col);
|
||||
}
|
||||
}
|
||||
Sgr::Background(col) => {
|
||||
if let ColorSpec::Default = col {
|
||||
pen.set_background(default_cell.background);
|
||||
pen.set_background(default_cell.background());
|
||||
} else {
|
||||
pen.set_background(col);
|
||||
}
|
||||
|
@ -694,10 +694,10 @@ impl super::TermWindow {
|
||||
attrs.overline(),
|
||||
)?
|
||||
.texture_coords();
|
||||
let bg_is_default = attrs.background == ColorAttribute::Default;
|
||||
let bg_color = params.palette.resolve_bg(attrs.background);
|
||||
let bg_is_default = attrs.background() == ColorAttribute::Default;
|
||||
let bg_color = params.palette.resolve_bg(attrs.background());
|
||||
|
||||
let fg_color = resolve_fg_color_attr(&attrs, &attrs.foreground, ¶ms, style);
|
||||
let fg_color = resolve_fg_color_attr(&attrs, attrs.foreground(), ¶ms, style);
|
||||
|
||||
let (fg_color, bg_color, bg_is_default) = {
|
||||
let mut fg = fg_color;
|
||||
@ -715,7 +715,7 @@ impl super::TermWindow {
|
||||
let glyph_color = rgbcolor_to_window_color(fg_color);
|
||||
let underline_color = match attrs.underline_color() {
|
||||
ColorAttribute::Default => fg_color,
|
||||
c => resolve_fg_color_attr(&attrs, &c, ¶ms, style),
|
||||
c => resolve_fg_color_attr(&attrs, c, ¶ms, style),
|
||||
};
|
||||
let underline_color = rgbcolor_to_window_color(underline_color);
|
||||
|
||||
@ -1317,7 +1317,7 @@ fn rgbcolor_alpha_to_window_color(color: RgbColor, alpha: u8) -> LinearRgba {
|
||||
|
||||
fn resolve_fg_color_attr(
|
||||
attrs: &CellAttributes,
|
||||
fg: &ColorAttribute,
|
||||
fg: ColorAttribute,
|
||||
params: &RenderScreenLineOpenGLParams,
|
||||
style: &config::TextStyle,
|
||||
) -> RgbColor {
|
||||
@ -1326,24 +1326,24 @@ fn resolve_fg_color_attr(
|
||||
if let Some(fg) = style.foreground {
|
||||
fg
|
||||
} else {
|
||||
params.palette.resolve_fg(attrs.foreground)
|
||||
params.palette.resolve_fg(attrs.foreground())
|
||||
}
|
||||
}
|
||||
wezterm_term::color::ColorAttribute::PaletteIndex(idx)
|
||||
if *idx < 8 && params.config.bold_brightens_ansi_colors =>
|
||||
if idx < 8 && params.config.bold_brightens_ansi_colors =>
|
||||
{
|
||||
// For compatibility purposes, switch to a brighter version
|
||||
// of one of the standard ANSI colors when Bold is enabled.
|
||||
// This lifts black to dark grey.
|
||||
let idx = if attrs.intensity() == wezterm_term::Intensity::Bold {
|
||||
*idx + 8
|
||||
idx + 8
|
||||
} else {
|
||||
*idx
|
||||
idx
|
||||
};
|
||||
params
|
||||
.palette
|
||||
.resolve_fg(wezterm_term::color::ColorAttribute::PaletteIndex(idx))
|
||||
}
|
||||
_ => params.palette.resolve_fg(*fg),
|
||||
_ => params.palette.resolve_fg(fg),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user