1
1
mirror of https://github.com/wez/wezterm.git synced 2024-09-21 03:39:16 +03:00

wezterm: display tab indices in tab bar by default

More details in the included changelog update

refs: https://github.com/wez/wezterm/issues/157#issuecomment-699520149
This commit is contained in:
Wez Furlong 2020-09-26 09:52:16 -07:00
parent 6708ea4b36
commit 81ba73d5b8
4 changed files with 31 additions and 5 deletions

View File

@ -17,6 +17,11 @@ brief notes about them may accumulate here.
you would write `{key="T", mods="CTRL|SHIFT"}`, after updating to
this release you need to write `{key="T", mods="CTRL"}` in order
for your key bindings to take effect.
* Added `show_tab_index_in_tab_bar` option which defaults to true.
Causes the tab's ordinal index to be prefixed to tab titles.
The displayed number is 1-based. You can set
`tab_and_split_indices_are_zero_based=true` if you prefer the
number to be zero based.
* Experimental support for splits/panes. Not currently
supported for multiplexer connections.
See [#157](https://github.com/wez/wezterm/issues/157) for

View File

@ -464,6 +464,15 @@ pub struct Config {
#[serde(default = "default_true")]
pub enable_tab_bar: bool,
/// If true, tab bar titles are prefixed with the tab index
#[serde(default = "default_true")]
pub show_tab_index_in_tab_bar: 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.
#[serde(default)]
pub tab_and_split_indices_are_zero_based: bool,
/// Specifies the maximum width that a tab can have in the
/// tab bar. Defaults to 16 glyphs in width.
#[serde(default = "default_tab_max_width")]

View File

@ -1,4 +1,4 @@
use crate::config::TabBarColors;
use crate::config::{ConfigHandle, TabBarColors};
use crate::mux::window::Window as MuxWindow;
use std::cell::Ref;
use termwiz::cell::unicode_column_width;
@ -48,7 +48,7 @@ impl TabBarState {
mouse_x: Option<usize>,
window: &Ref<MuxWindow>,
colors: Option<&TabBarColors>,
tab_width_max: usize,
config: &ConfigHandle,
) -> Self {
// We ultimately want to produce a line looking like this:
// ` | tab1-title x | tab2-title x | + . - X `
@ -60,9 +60,21 @@ impl TabBarState {
let tab_titles: Vec<String> = window
.iter()
.map(|tab| {
.enumerate()
.map(|(idx, tab)| {
if let Some(pane) = tab.get_active_pane() {
let mut title = pane.get_title();
if config.show_tab_index_in_tab_bar {
title = format!(
"{}: {}",
idx + if config.tab_and_split_indices_are_zero_based {
0
} else {
1
},
title
);
}
// We have a preferred soft minimum on tab width to make it
// easier to click on tab titles, but we'll still go below
// this if there are too many tabs to fit the window at
@ -88,7 +100,7 @@ impl TabBarState {
// We need to clamp the length to balance them out
available_cells / number_of_tabs
}
.min(tab_width_max);
.min(config.tab_max_width);
let colors = colors.cloned().unwrap_or_else(TabBarColors::default);

View File

@ -1287,7 +1287,7 @@ impl TermWindow {
},
&window,
config.colors.as_ref().and_then(|c| c.tab_bar.as_ref()),
config.tab_max_width,
&config,
);
if new_tab_bar != self.tab_bar {
self.tab_bar = new_tab_bar;