allow configuring the tab bar
The defaults are pretty neutral. You can get a little more fancy with something like this: ``` [colors.tab_bar] background = "#0b0022" [colors.tab_bar.active_tab] bg_color = "#2b2042" fg_color = "#c0c0c0" [colors.tab_bar.inactive_tab] bg_color = "#1b1032" fg_color = "#808080" [colors.tab_bar.inactive_tab_hover] bg_color = "#3b3052" fg_color = "#909090" italic = true ```
This commit is contained in:
1 parent
d716578735
commit
ac7a509dbb
4 files changed
+117
-35
No files matched your search
+82
-1
@@ -18,7 +18,8 @@ use std::fs::{File, OpenOptions};
|
||||
use std::io::prelude::*;
|
||||
use std::path::PathBuf;
|
||||
use term;
|
||||
use term::color::RgbColor;
|
||||
use termwiz::cell::CellAttributes;
|
||||
use termwiz::color::{ColorSpec, RgbColor};
|
||||
use termwiz::hyperlink;
|
||||
use termwiz::input::{KeyCode, Modifiers};
|
||||
use toml;
|
||||
@@ -980,6 +981,8 @@ pub struct Palette {
|
||||
/// A list of 8 colors corresponding to bright versions of the
|
||||
/// ANSI palette
|
||||
pub brights: Option<[RgbColor; 8]>,
|
||||
/// Configure the colors and styling of the tab bar
|
||||
pub tab_bar: Option<TabBarColors>,
|
||||
}
|
||||
|
||||
impl From<Palette> for term::color::ColorPalette {
|
||||
@@ -1012,3 +1015,81 @@ impl From<Palette> for term::color::ColorPalette {
|
||||
p
|
||||
}
|
||||
}
|
||||
|
||||
/// Specify the text styling for a tab in the tab bar
|
||||
#[derive(Debug, Deserialize, Clone, Default)]
|
||||
pub struct TabBarColor {
|
||||
/// Specifies the intensity attribute for the tab title text
|
||||
#[serde(default)]
|
||||
pub intensity: term::Intensity,
|
||||
/// Specifies the underline attribute for the tab title text
|
||||
#[serde(default)]
|
||||
pub underline: term::Underline,
|
||||
/// Specifies the italic attribute for the tab title text
|
||||
#[serde(default)]
|
||||
pub italic: bool,
|
||||
/// Specifies the strikethrough attribute for the tab title text
|
||||
#[serde(default)]
|
||||
pub strikethrough: bool,
|
||||
/// The background color for the tab
|
||||
pub bg_color: RgbColor,
|
||||
/// The forgeground/text color for the tab
|
||||
pub fg_color: RgbColor,
|
||||
}
|
||||
|
||||
impl TabBarColor {
|
||||
pub fn as_cell_attributes(&self) -> CellAttributes {
|
||||
let mut attr = CellAttributes::default();
|
||||
attr.set_intensity(self.intensity)
|
||||
.set_underline(self.underline)
|
||||
.set_italic(self.italic)
|
||||
.set_strikethrough(self.strikethrough)
|
||||
.set_background(ColorSpec::TrueColor(self.bg_color))
|
||||
.set_foreground(ColorSpec::TrueColor(self.fg_color));
|
||||
attr
|
||||
}
|
||||
}
|
||||
|
||||
/// Specifies the colors to use for the tab bar portion of the UI.
|
||||
/// These are not part of the terminal model and cannot be updated
|
||||
/// in the same way that the dynamic color schemes are.
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
pub struct TabBarColors {
|
||||
/// The background color for the tab bar
|
||||
pub background: RgbColor,
|
||||
|
||||
/// Styling for the active tab
|
||||
pub active_tab: TabBarColor,
|
||||
/// Styling for other inactive tabs
|
||||
pub inactive_tab: TabBarColor,
|
||||
/// Styling for an inactive tab with a mouse hovering
|
||||
pub inactive_tab_hover: TabBarColor,
|
||||
}
|
||||
|
||||
impl Default for TabBarColors {
|
||||
fn default() -> Self {
|
||||
let black = RgbColor::new(0x05, 0x05, 0x05);
|
||||
let hover_gray = RgbColor::new(0x20, 0x20, 0x20);
|
||||
let active_gray = RgbColor::new(0x30, 0x30, 0x30);
|
||||
let fg_color = RgbColor::new(0xd0, 0xd0, 0xd0);
|
||||
let fg_hover = RgbColor::new(0xe7, 0xe7, 0xe7);
|
||||
Self {
|
||||
background: black,
|
||||
inactive_tab: TabBarColor {
|
||||
bg_color: black,
|
||||
fg_color,
|
||||
..TabBarColor::default()
|
||||
},
|
||||
inactive_tab_hover: TabBarColor {
|
||||
bg_color: hover_gray,
|
||||
fg_color: fg_hover,
|
||||
..TabBarColor::default()
|
||||
},
|
||||
active_tab: TabBarColor {
|
||||
bg_color: active_gray,
|
||||
fg_color,
|
||||
..TabBarColor::default()
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
+22
-34
@@ -1,9 +1,10 @@
|
||||
use crate::config::TabBarColors;
|
||||
use crate::mux::window::Window as MuxWindow;
|
||||
use std::cell::Ref;
|
||||
use term::Line;
|
||||
use termwiz::cell::unicode_column_width;
|
||||
use termwiz::cell::{Cell, CellAttributes};
|
||||
use termwiz::color::{ColorSpec, RgbColor};
|
||||
use termwiz::color::ColorSpec;
|
||||
use unicode_segmentation::UnicodeSegmentation;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
@@ -28,7 +29,12 @@ impl TabBarState {
|
||||
/// mouse_x is some if the mouse is on the same row as the tab bar.
|
||||
/// title_width is the total number of cell columns in the window.
|
||||
/// window allows access to the tabs associated with the window.
|
||||
pub fn new(title_width: usize, mouse_x: Option<usize>, window: &Ref<MuxWindow>) -> Self {
|
||||
pub fn new(
|
||||
title_width: usize,
|
||||
mouse_x: Option<usize>,
|
||||
window: &Ref<MuxWindow>,
|
||||
colors: Option<&TabBarColors>,
|
||||
) -> Self {
|
||||
// We ultimately want to produce a line looking like this:
|
||||
// ` | tab1-title x | tab2-title x | + . - X `
|
||||
// Where the `+` sign will spawn a new tab (or show a context
|
||||
@@ -50,31 +56,7 @@ impl TabBarState {
|
||||
available_cells / number_of_tabs
|
||||
};
|
||||
|
||||
let black = RgbColor::new(0x05, 0x05, 0x05);
|
||||
let white = RgbColor::new(0xe7, 0xe7, 0xe7);
|
||||
let hover_gray = RgbColor::new(0x20, 0x20, 0x20);
|
||||
let active_gray = RgbColor::new(0x30, 0x30, 0x30);
|
||||
let black_cell = Cell::new(
|
||||
' ',
|
||||
CellAttributes::default()
|
||||
.set_background(ColorSpec::TrueColor(black))
|
||||
.set_foreground(ColorSpec::TrueColor(white))
|
||||
.clone(),
|
||||
);
|
||||
let hover_cell = Cell::new(
|
||||
' ',
|
||||
CellAttributes::default()
|
||||
.set_background(ColorSpec::TrueColor(hover_gray))
|
||||
.set_foreground(ColorSpec::TrueColor(white))
|
||||
.clone(),
|
||||
);
|
||||
let active_cell = Cell::new(
|
||||
' ',
|
||||
CellAttributes::default()
|
||||
.set_background(ColorSpec::TrueColor(active_gray))
|
||||
.set_foreground(ColorSpec::TrueColor(white))
|
||||
.clone(),
|
||||
);
|
||||
let colors = colors.cloned().unwrap_or_else(|| TabBarColors::default());
|
||||
|
||||
let mut line = Line::with_width(title_width);
|
||||
|
||||
@@ -90,17 +72,17 @@ impl TabBarState {
|
||||
.unwrap_or(false);
|
||||
let active = tab_idx == active_tab_no;
|
||||
|
||||
let bg_cell = if active {
|
||||
active_cell.clone()
|
||||
let cell_attrs = if active {
|
||||
colors.active_tab.as_cell_attributes()
|
||||
} else if hover {
|
||||
hover_cell.clone()
|
||||
colors.inactive_tab_hover.as_cell_attributes()
|
||||
} else {
|
||||
black_cell.clone()
|
||||
colors.inactive_tab.as_cell_attributes()
|
||||
};
|
||||
|
||||
let tab_start_idx = x;
|
||||
|
||||
line.set_cell(x, bg_cell.clone());
|
||||
line.set_cell(x, Cell::new(' ', cell_attrs.clone()));
|
||||
x += 1;
|
||||
|
||||
for (idx, sub) in tab_title.graphemes(true).enumerate() {
|
||||
@@ -108,16 +90,22 @@ impl TabBarState {
|
||||
break;
|
||||
}
|
||||
|
||||
line.set_cell(x, Cell::new_grapheme(sub, bg_cell.attrs().clone()));
|
||||
line.set_cell(x, Cell::new_grapheme(sub, cell_attrs.clone()));
|
||||
x += 1;
|
||||
}
|
||||
|
||||
widths.push(x - tab_start_idx);
|
||||
|
||||
line.set_cell(x, bg_cell.clone());
|
||||
line.set_cell(x, Cell::new(' ', cell_attrs));
|
||||
x += 1;
|
||||
}
|
||||
|
||||
let black_cell = Cell::new(
|
||||
' ',
|
||||
CellAttributes::default()
|
||||
.set_background(ColorSpec::TrueColor(colors.background))
|
||||
.clone(),
|
||||
);
|
||||
for idx in x..title_width {
|
||||
line.set_cell(idx, black_cell.clone());
|
||||
}
|
||||
|
||||
@@ -572,6 +572,7 @@ impl TermWindow {
|
||||
None
|
||||
},
|
||||
&window,
|
||||
self.config.colors.as_ref().and_then(|c| c.tab_bar.as_ref()),
|
||||
);
|
||||
if new_tab_bar != self.tab_bar {
|
||||
self.tab_bar = new_tab_bar;
|
||||
|
||||
@@ -94,6 +94,12 @@ pub enum Intensity {
|
||||
Half = 2,
|
||||
}
|
||||
|
||||
impl Default for Intensity {
|
||||
fn default() -> Self {
|
||||
Self::Normal
|
||||
}
|
||||
}
|
||||
|
||||
/// Specify just how underlined you want your `Cell` to be
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[repr(u16)]
|
||||
@@ -106,6 +112,12 @@ pub enum Underline {
|
||||
Double = 2,
|
||||
}
|
||||
|
||||
impl Default for Underline {
|
||||
fn default() -> Self {
|
||||
Self::None
|
||||
}
|
||||
}
|
||||
|
||||
/// Allow converting to boolean; true means some kind of
|
||||
/// underline, false means none. This is used in some
|
||||
/// generic code to determine whether to enable underline.
|
||||
|
||||
Reference in new issue
Block a user