From a46bad17d27794c7b2408849ffadc3bee10e4011 Mon Sep 17 00:00:00 2001 From: Aleksey Kuznetsov Date: Sat, 13 Jul 2024 11:32:54 -0700 Subject: [PATCH] config: show/hide close-tab button --- config/src/config.rs | 3 + .../config/show_close_tab_button_in_tabs.md | 16 +++ .../src/termwindow/render/fancy_tab_bar.rs | 122 ++++++++++-------- 3 files changed, 84 insertions(+), 57 deletions(-) create mode 100644 docs/config/lua/config/show_close_tab_button_in_tabs.md diff --git a/config/src/config.rs b/config/src/config.rs index 5b099edc7..e51b4d790 100644 --- a/config/src/config.rs +++ b/config/src/config.rs @@ -469,6 +469,9 @@ pub struct Config { #[dynamic(default = "default_true")] pub show_new_tab_button_in_tab_bar: bool, + #[dynamic(default = "default_true")] + pub show_close_tab_button_in_tabs: bool, + /// If true, show_tab_index_in_tab_bar uses a zero-based index. /// The default is false and the tab shows a one-based index. #[dynamic(default)] diff --git a/docs/config/lua/config/show_close_tab_button_in_tabs.md b/docs/config/lua/config/show_close_tab_button_in_tabs.md new file mode 100644 index 000000000..56a2ca0c7 --- /dev/null +++ b/docs/config/lua/config/show_close_tab_button_in_tabs.md @@ -0,0 +1,16 @@ +--- +tags: + - appearance + - tab_bar +--- + +# `show_close_tab_button_in_tabs = true` + +{{since('nightly')}} + +When set to `false`, the close-tab button will not be drawn in tabs when the +fancy tab bar is in use. Default is `true`. + +```lua +config.show_close_tab_button_in_tabs = false +``` diff --git a/wezterm-gui/src/termwindow/render/fancy_tab_bar.rs b/wezterm-gui/src/termwindow/render/fancy_tab_bar.rs index 180d9bb66..ebf393686 100644 --- a/wezterm-gui/src/termwindow/render/fancy_tab_bar.rs +++ b/wezterm-gui/src/termwindow/render/fancy_tab_bar.rs @@ -7,6 +7,8 @@ use crate::termwindow::render::window_buttons::window_button_element; use crate::termwindow::{UIItem, UIItemType}; use crate::utilsprites::RenderMetrics; use config::{Dimension, DimensionContext, TabBarColors}; +use std::rc::Rc; +use wezterm_font::LoadedFont; use wezterm_term::color::{ColorAttribute, ColorPalette}; use window::{IntegratedTitleButtonAlignment, IntegratedTitleButtonStyle}; @@ -343,63 +345,9 @@ impl crate::TermWindow { ElementContent::Text(_) => unreachable!(), ElementContent::Poly { .. } => unreachable!(), ElementContent::Children(mut kids) => { - let x_button = Element::new( - &font, - ElementContent::Poly { - line_width: metrics.underline_height.max(2), - poly: SizedPoly { - poly: X_BUTTON, - width: Dimension::Pixels( - metrics.cell_size.height as f32 / 2., - ), - height: Dimension::Pixels( - metrics.cell_size.height as f32 / 2., - ), - }, - }, - ) - // Ensure that we draw our background over the - // top of the rest of the tab contents - .zindex(1) - .vertical_align(VerticalAlign::Middle) - .float(Float::Right) - .item_type(UIItemType::CloseTab(tab_idx)) - .hover_colors({ - let inactive_tab_hover = colors.inactive_tab_hover(); - let active_tab = colors.active_tab(); - - Some(ElementColors { - border: BorderColor::default(), - bg: (if active { - inactive_tab_hover.bg_color - } else { - active_tab.bg_color - }) - .to_linear() - .into(), - text: (if active { - inactive_tab_hover.fg_color - } else { - active_tab.fg_color - }) - .to_linear() - .into(), - }) - }) - .padding(BoxDimension { - left: Dimension::Cells(0.25), - right: Dimension::Cells(0.25), - top: Dimension::Cells(0.25), - bottom: Dimension::Cells(0.25), - }) - .margin(BoxDimension { - left: Dimension::Cells(0.5), - right: Dimension::Cells(0.), - top: Dimension::Cells(0.), - bottom: Dimension::Cells(0.), - }); - - kids.push(x_button); + if self.config.show_close_tab_button_in_tabs { + kids.push(make_x_button(&font, &metrics, &colors, tab_idx, active)); + } ElementContent::Children(kids) } }; @@ -522,3 +470,63 @@ impl crate::TermWindow { Ok(ui_items) } } + +fn make_x_button( + font: &Rc, + metrics: &RenderMetrics, + colors: &TabBarColors, + tab_idx: usize, + active: bool, +) -> Element { + Element::new( + &font, + ElementContent::Poly { + line_width: metrics.underline_height.max(2), + poly: SizedPoly { + poly: X_BUTTON, + width: Dimension::Pixels(metrics.cell_size.height as f32 / 2.), + height: Dimension::Pixels(metrics.cell_size.height as f32 / 2.), + }, + }, + ) + // Ensure that we draw our background over the + // top of the rest of the tab contents + .zindex(1) + .vertical_align(VerticalAlign::Middle) + .float(Float::Right) + .item_type(UIItemType::CloseTab(tab_idx)) + .hover_colors({ + let inactive_tab_hover = colors.inactive_tab_hover(); + let active_tab = colors.active_tab(); + + Some(ElementColors { + border: BorderColor::default(), + bg: (if active { + inactive_tab_hover.bg_color + } else { + active_tab.bg_color + }) + .to_linear() + .into(), + text: (if active { + inactive_tab_hover.fg_color + } else { + active_tab.fg_color + }) + .to_linear() + .into(), + }) + }) + .padding(BoxDimension { + left: Dimension::Cells(0.25), + right: Dimension::Cells(0.25), + top: Dimension::Cells(0.25), + bottom: Dimension::Cells(0.25), + }) + .margin(BoxDimension { + left: Dimension::Cells(0.5), + right: Dimension::Cells(0.), + top: Dimension::Cells(0.), + bottom: Dimension::Cells(0.), + }) +}