diff options
| author | Aram Drevekenin <aram@poor.dev> | 2025-02-13 17:12:47 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-13 17:12:47 +0100 |
| commit | 7aaa7aea8f9a378660492d03ff5736dbf846978d (patch) | |
| tree | 2b9884e135d73c82da442d1de649eb2b5df3fc54 /default-plugins/about/src/pages.rs | |
| parent | docs(changelog): about plugin (diff) | |
| download | sl0ppij-7aaa7aea8f9a378660492d03ff5736dbf846978d.tar.gz sl0ppij-7aaa7aea8f9a378660492d03ff5736dbf846978d.tar.xz sl0ppij-7aaa7aea8f9a378660492d03ff5736dbf846978d.zip | |
feat(ux): tips on startup (#3988)
* add some tips
* refactoring and max tip index
* add config to disable release notes and startup tips
* allow dismissing startup tips from plugin
* random tip at startup
* custom launch about
* fix tests
* style(fmt): rustfmt
Diffstat (limited to 'default-plugins/about/src/pages.rs')
| -rw-r--r-- | default-plugins/about/src/pages.rs | 72 |
1 files changed, 63 insertions, 9 deletions
diff --git a/default-plugins/about/src/pages.rs b/default-plugins/about/src/pages.rs index 2951c1b0..9bf82200 100644 --- a/default-plugins/about/src/pages.rs +++ b/default-plugins/about/src/pages.rs @@ -20,10 +20,11 @@ impl Page { link_executable: Rc<RefCell<String>>, zellij_version: String, base_mode: Rc<RefCell<InputMode>>, + is_release_notes: bool, ) -> Self { Page::new() .main_screen() - .with_title(main_screen_title(zellij_version.clone())) + .with_title(main_screen_title(zellij_version.clone(), is_release_notes)) .with_bulletin_list(BulletinList::new(whats_new_title()).with_items(vec![ ActiveComponent::new(TextOrCustomRender::Text(main_menu_item( "Stacked Resize", @@ -102,9 +103,15 @@ impl Page { link_executable.clone(), )), ])]) - .with_help(Box::new(|hovering_over_link, menu_item_is_selected| { - main_screen_help_text(hovering_over_link, menu_item_is_selected) - })) + .with_help(if is_release_notes { + Box::new(|hovering_over_link, menu_item_is_selected| { + release_notes_main_help(hovering_over_link, menu_item_is_selected) + }) + } else { + Box::new(|hovering_over_link, menu_item_is_selected| { + main_screen_help_text(hovering_over_link, menu_item_is_selected) + }) + }) } pub fn new_stacked_resize(link_executable: Rc<RefCell<String>>) -> Page { Page::new() @@ -543,7 +550,7 @@ impl Page { row_count += self.components_to_render.len(); row_count } - pub fn render(&mut self, rows: usize, columns: usize) { + pub fn render(&mut self, rows: usize, columns: usize, error: &Option<String>) { let base_x = columns.saturating_sub(self.ui_column_count()) / 2; let base_y = rows.saturating_sub(self.ui_row_count()) / 2; let mut current_y = base_y; @@ -562,12 +569,23 @@ impl Page { RenderedComponent::HelpText(_) => true, _ => false, }; + if is_help { + if let Some(error) = error { + render_error(error, rows); + continue; + } + } let y = if is_help { rows } else { current_y }; + let columns = if is_help { + columns + } else { + columns.saturating_sub(base_x * 2) + }; let rendered_rows = rendered_component.render( base_x, y, rows, - columns.saturating_sub(base_x * 2), + columns, self.hovering_over_link, self.menu_item_is_selected, ); @@ -576,6 +594,16 @@ impl Page { } } +fn render_error(error: &str, y: usize) { + print_text_with_coordinates( + Text::new(format!("ERROR: {}", error)).color_range(3, ..), + 0, + y, + None, + None, + ); +} + fn changelog_link_unselected(version: String) -> Text { let full_changelog_text = format!( "https://github.com/zellij-org/zellij/releases/tag/v{}", @@ -647,9 +675,14 @@ fn whats_new_title() -> Text { Text::new("What's new?") } -fn main_screen_title(version: String) -> Text { - let title_text = format!("Hi there, welcome to Zellij {}!", &version); - Text::new(title_text).color_range(2, 21..=27 + version.chars().count()) +fn main_screen_title(version: String, is_release_notes: bool) -> Text { + if is_release_notes { + let title_text = format!("Hi there, welcome to Zellij {}!", &version); + Text::new(title_text).color_range(2, 21..=27 + version.chars().count()) + } else { + let title_text = format!("Zellij {}", &version); + Text::new(title_text).color_range(2, ..) + } } fn main_screen_help_text(hovering_over_link: bool, menu_item_is_selected: bool) -> Text { @@ -665,6 +698,27 @@ fn main_screen_help_text(hovering_over_link: bool, menu_item_is_selected: bool) .color_range(1, 23..=29) .color_range(1, 45..=49) } else { + let help_text = format!("Help: <↓↑> - Navigate, <ESC> - Dismiss, <?> - Usage Tips"); + Text::new(help_text) + .color_range(1, 6..=9) + .color_range(1, 23..=27) + .color_range(1, 40..=42) + } +} + +fn release_notes_main_help(hovering_over_link: bool, menu_item_is_selected: bool) -> Text { + if hovering_over_link { + let help_text = format!("Help: Click or Shift-Click to open in browser"); + Text::new(help_text) + .color_range(3, 6..=10) + .color_range(3, 15..=25) + } else if menu_item_is_selected { + let help_text = format!("Help: <↓↑> - Navigate, <ENTER> - Learn More, <ESC> - Dismiss"); + Text::new(help_text) + .color_range(1, 6..=9) + .color_range(1, 23..=29) + .color_range(1, 45..=49) + } else { let help_text = format!("Help: <↓↑> - Navigate, <ESC> - Dismiss"); Text::new(help_text) .color_range(1, 6..=9) |
