diff options
| author | Jonah Caplan <jonahcaplan@gmail.com> | 2021-03-08 04:06:23 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-08 10:06:23 +0100 |
| commit | 44b0246e91ae65b09f3e2d9b111772a6b093135b (patch) | |
| tree | c1a422e0f9ffb02cb978ae4d5bb68018deb2a998 /default-tiles/tab-bar/src/tab.rs | |
| parent | New tab styling (#216) (diff) | |
| download | sl0ppij-44b0246e91ae65b09f3e2d9b111772a6b093135b.tar.gz sl0ppij-44b0246e91ae65b09f3e2d9b111772a6b093135b.tar.xz sl0ppij-44b0246e91ae65b09f3e2d9b111772a6b093135b.zip | |
feat(tabs): add ability to set tab name (#212)
* send all tabs in vec
* works but no input filtering
* add event types
* add event handler for tab events
* fmt fixups
* update tab name in place, and escape rename works
* rename handle_tab_event handle_tab_rename_keypress
* handle empty new_name when renaming
* fix(tabs): pad active tab name too
* fix(tabs): report proper length
* fix(tabs): always render active tab
* style(fmt): rustfmt
Co-authored-by: Aram Drevekenin <aram@poor.dev>
Diffstat (limited to '')
| -rw-r--r-- | default-tiles/tab-bar/src/tab.rs | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/default-tiles/tab-bar/src/tab.rs b/default-tiles/tab-bar/src/tab.rs index 78a9ba0b..fa345ba0 100644 --- a/default-tiles/tab-bar/src/tab.rs +++ b/default-tiles/tab-bar/src/tab.rs @@ -9,11 +9,11 @@ pub fn active_tab(text: String, is_furthest_to_the_left: bool) -> LinePart { ARROW_SEPARATOR.black().on_magenta() }; let right_separator = ARROW_SEPARATOR.magenta().on_black(); - let tab_styled_text = format!("{}{}{}", left_separator, text, right_separator) + let tab_styled_text = format!("{} {} {}", left_separator, text, right_separator) .black() .bold() .on_magenta(); - let tab_text_len = text.chars().count() + 2; // 2 for left and right separators + let tab_text_len = text.chars().count() + 4; // 2 for left and right separators, 2 for the text padding LinePart { part: format!("{}", tab_styled_text), len: tab_text_len, @@ -27,26 +27,27 @@ pub fn non_active_tab(text: String, is_furthest_to_the_left: bool) -> LinePart { ARROW_SEPARATOR.black().on_green() }; let right_separator = ARROW_SEPARATOR.green().on_black(); - let tab_styled_text = format!("{}{}{}", left_separator, text, right_separator) + let tab_styled_text = format!("{} {} {}", left_separator, text, right_separator) .black() .bold() .on_green(); - let tab_text_len = text.chars().count() + 2; // 2 for the left and right separators + let tab_text_len = text.chars().count() + 4; // 2 for the left and right separators, 2 for the text padding LinePart { part: format!("{}", tab_styled_text), len: tab_text_len, } } -pub fn tab(text: String, is_active_tab: bool, is_furthest_to_the_left: bool) -> LinePart { +pub fn tab_style(text: String, is_active_tab: bool, position: usize) -> LinePart { + let tab_text; + if text.is_empty() { + tab_text = format!("Tab #{}", position + 1); + } else { + tab_text = text; + } if is_active_tab { - active_tab(text, is_furthest_to_the_left) + active_tab(tab_text, position == 0) } else { - non_active_tab(text, is_furthest_to_the_left) + non_active_tab(tab_text, position == 0) } } - -pub fn nameless_tab(index: usize, is_active_tab: bool) -> LinePart { - let tab_text = format!(" Tab #{} ", index + 1); - tab(tab_text, is_active_tab, index == 0) -} |
