Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add status bar tips #1462

Merged
merged 3 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 8 additions & 18 deletions default-plugins/status-bar/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,14 @@ fn color_elements(palette: Palette, different_color_alternates: bool) -> Colored
unselected_single_letter_char_shortcut: style!(palette.red, palette.fg).bold().dimmed(),
unselected_single_letter_suffix_separator: style!(palette.fg, background),

unselected_alternate_single_letter_prefix_separator: style!(
palette.fg,
alternate_background_color
),
unselected_alternate_single_letter_prefix_separator: style!(background, palette.fg),
unselected_alternate_single_letter_char_shortcut: style!(
palette.red,
alternate_background_color
)
.bold(),
unselected_alternate_single_letter_suffix_separator: style!(
palette.fg,
alternate_background_color
),
.bold()
.dimmed(),
unselected_alternate_single_letter_suffix_separator: style!(palette.fg, background),

superkey_prefix: style!(foreground, background).bold(),
superkey_suffix_separator: style!(background, background),
Expand Down Expand Up @@ -209,19 +204,14 @@ fn color_elements(palette: Palette, different_color_alternates: bool) -> Colored
unselected_single_letter_char_shortcut: style!(palette.red, palette.fg).bold(),
unselected_single_letter_suffix_separator: style!(palette.fg, background),

unselected_alternate_single_letter_prefix_separator: style!(
palette.fg,
alternate_background_color
),
unselected_alternate_single_letter_prefix_separator: style!(background, palette.fg),
unselected_alternate_single_letter_char_shortcut: style!(
palette.red,
alternate_background_color
)
.bold(),
unselected_alternate_single_letter_suffix_separator: style!(
palette.fg,
alternate_background_color
),
.bold()
.dimmed(),
unselected_alternate_single_letter_suffix_separator: style!(palette.fg, background),

superkey_prefix: style!(background, palette.fg).bold(),
superkey_suffix_separator: style!(palette.fg, background),
Expand Down
2 changes: 1 addition & 1 deletion default-plugins/status-bar/src/tip/consts.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub const DEFAULT_CACHE_FILE_PATH: &str = "/tmp/status-bar-tips.cache";
pub const MAX_CACHE_HITS: usize = 10;
pub const MAX_CACHE_HITS: usize = 20; // this should be 10, but right now there's a bug where the plugin load function is called twice, and sot he cache is hit twice
87 changes: 87 additions & 0 deletions default-plugins/status-bar/src/tip/data/compact_layout.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
use ansi_term::{
unstyled_len, ANSIString, ANSIStrings,
Color::{Fixed, RGB},
Style,
};

use crate::LinePart;
use zellij_tile::prelude::*;
use zellij_tile_utils::palette_match;

macro_rules! strings {
($ANSIStrings:expr) => {{
let strings: &[ANSIString<'static>] = $ANSIStrings;

let ansi_strings = ANSIStrings(strings);

LinePart {
part: format!("{}", ansi_strings),
len: unstyled_len(&ansi_strings),
}
}};
}

pub fn compact_layout_full(palette: Palette) -> LinePart {
// Tip: UI taking up too much space? Start Zellij with
// zellij -l compact or remove pane frames with Ctrl + <p> + <z>
let green_color = palette_match!(palette.green);
let orange_color = palette_match!(palette.orange);

strings!(&[
Style::new().paint(" Tip: "),
Style::new().paint("UI taking up too much space? Start Zellij with "),
Style::new()
.fg(green_color)
.bold()
.paint("zellij -l compact"),
Style::new().paint(" or remove pane frames with "),
Style::new().fg(orange_color).bold().paint("Ctrl"),
Style::new().paint(" + "),
Style::new().fg(green_color).bold().paint("<p>"),
Style::new().paint(" + "),
Style::new().fg(green_color).bold().paint("<z>"),
])
}

pub fn compact_layout_medium(palette: Palette) -> LinePart {
// Tip: To save screen space, start Zellij with
// zellij -l compact or remove pane frames with Ctrl + <p> + <z>
let green_color = palette_match!(palette.green);
let orange_color = palette_match!(palette.orange);

strings!(&[
Style::new().paint(" Tip: "),
Style::new().paint("To save screen space, start Zellij with "),
Style::new()
.fg(green_color)
.bold()
.paint("zellij -l compact"),
Style::new().paint(" or remove frames with "),
Style::new().fg(orange_color).bold().paint("Ctrl"),
Style::new().paint(" + "),
Style::new().fg(green_color).bold().paint("<p>"),
Style::new().paint(" + "),
Style::new().fg(green_color).bold().paint("<z>"),
])
}

pub fn compact_layout_short(palette: Palette) -> LinePart {
// Save screen space, start Zellij with
// zellij -l compact or remove pane frames with Ctrl + <p> + <z>
let green_color = palette_match!(palette.green);
let orange_color = palette_match!(palette.orange);

strings!(&[
Style::new().paint(" Save screen space, start with: "),
Style::new()
.fg(green_color)
.bold()
.paint("zellij -l compact"),
Style::new().paint(" or remove frames with "),
Style::new().fg(orange_color).bold().paint("Ctrl"),
Style::new().paint(" + "),
Style::new().fg(green_color).bold().paint("<p>"),
Style::new().paint(" + "),
Style::new().fg(green_color).bold().paint("<z>"),
])
}
78 changes: 78 additions & 0 deletions default-plugins/status-bar/src/tip/data/edit_scrollbuffer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
use ansi_term::{
unstyled_len, ANSIString, ANSIStrings,
Color::{Fixed, RGB},
Style,
};

use crate::LinePart;
use zellij_tile::prelude::*;
use zellij_tile_utils::palette_match;

macro_rules! strings {
($ANSIStrings:expr) => {{
let strings: &[ANSIString<'static>] = $ANSIStrings;

let ansi_strings = ANSIStrings(strings);

LinePart {
part: format!("{}", ansi_strings),
len: unstyled_len(&ansi_strings),
}
}};
}

pub fn edit_scrollbuffer_full(palette: Palette) -> LinePart {
// Tip: Search through the scrollbuffer using your default $EDITOR with
// Ctrl + <s> + <e>
let green_color = palette_match!(palette.green);
let orange_color = palette_match!(palette.orange);

strings!(&[
Style::new().paint(" Tip: "),
Style::new().paint("Search through the scrollbuffer using your default "),
Style::new().fg(green_color).bold().paint("$EDITOR"),
Style::new().paint(" with "),
Style::new().fg(orange_color).bold().paint("Ctrl"),
Style::new().paint(" + "),
Style::new().fg(green_color).bold().paint("<s>"),
Style::new().paint(" + "),
Style::new().fg(green_color).bold().paint("<e>"),
])
}

pub fn edit_scrollbuffer_medium(palette: Palette) -> LinePart {
// Tip: Search the scrollbuffer using your $EDITOR with
// Ctrl + <s> + <e>
let green_color = palette_match!(palette.green);
let orange_color = palette_match!(palette.orange);

strings!(&[
Style::new().paint(" Tip: "),
Style::new().paint("Search the scrollbuffer using your "),
Style::new().fg(green_color).bold().paint("$EDITOR"),
Style::new().paint(" with "),
Style::new().fg(orange_color).bold().paint("Ctrl"),
Style::new().paint(" + "),
Style::new().fg(green_color).bold().paint("<s>"),
Style::new().paint(" + "),
Style::new().fg(green_color).bold().paint("<e>"),
])
}

pub fn edit_scrollbuffer_short(palette: Palette) -> LinePart {
// Search using $EDITOR with
// Ctrl + <s> + <e>
let green_color = palette_match!(palette.green);
let orange_color = palette_match!(palette.orange);

strings!(&[
Style::new().paint(" Search using "),
Style::new().fg(green_color).bold().paint("$EDITOR"),
Style::new().paint(" with "),
Style::new().fg(orange_color).bold().paint("Ctrl"),
Style::new().paint(" + "),
Style::new().fg(green_color).bold().paint("<s>"),
Style::new().paint(" + "),
Style::new().fg(green_color).bold().paint("<e>"),
])
}
69 changes: 69 additions & 0 deletions default-plugins/status-bar/src/tip/data/floating_panes_mouse.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
use ansi_term::{
unstyled_len, ANSIString, ANSIStrings,
Color::{Fixed, RGB},
Style,
};

use crate::LinePart;
use zellij_tile::prelude::*;
use zellij_tile_utils::palette_match;

macro_rules! strings {
($ANSIStrings:expr) => {{
let strings: &[ANSIString<'static>] = $ANSIStrings;

let ansi_strings = ANSIStrings(strings);

LinePart {
part: format!("{}", ansi_strings),
len: unstyled_len(&ansi_strings),
}
}};
}

pub fn floating_panes_mouse_full(palette: Palette) -> LinePart {
// Tip: Toggle floating panes with Ctrl + <p> + <w> and move them with keyboard or mouse
let green_color = palette_match!(palette.green);
let orange_color = palette_match!(palette.orange);

strings!(&[
Style::new().paint(" Tip: "),
Style::new().paint("Toggle floating panes with "),
Style::new().fg(orange_color).bold().paint("Ctrl"),
Style::new().paint(" + "),
Style::new().fg(green_color).bold().paint("<p>"),
Style::new().paint(" + "),
Style::new().fg(green_color).bold().paint("<w>"),
Style::new().paint(" and move them with keyboard or mouse"),
])
}

pub fn floating_panes_mouse_medium(palette: Palette) -> LinePart {
// Tip: Toggle floating panes with Ctrl + <p> + <w>
let green_color = palette_match!(palette.green);
let orange_color = palette_match!(palette.orange);
strings!(&[
Style::new().paint(" Tip: "),
Style::new().paint("Toggle floating panes with "),
Style::new().fg(orange_color).bold().paint("Ctrl"),
Style::new().paint(" + "),
Style::new().fg(green_color).bold().paint("<p>"),
Style::new().paint(" + "),
Style::new().fg(green_color).bold().paint("<w>"),
])
}

pub fn floating_panes_mouse_short(palette: Palette) -> LinePart {
// Ctrl + <p> + <w> => floating panes
let green_color = palette_match!(palette.green);
let orange_color = palette_match!(palette.orange);

strings!(&[
Style::new().fg(orange_color).bold().paint(" Ctrl"),
Style::new().paint(" + "),
Style::new().fg(green_color).bold().paint("<p>"),
Style::new().paint(" + "),
Style::new().fg(green_color).bold().paint("<w>"),
Style::new().paint(" => floating panes"),
])
}
92 changes: 92 additions & 0 deletions default-plugins/status-bar/src/tip/data/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
use std::collections::HashMap;

use lazy_static::lazy_static;

use crate::tip::TipBody;

mod compact_layout;
mod edit_scrollbuffer;
mod floating_panes_mouse;
mod move_focus_hjkl_tab_switch;
mod quicknav;
mod send_mouse_click_to_terminal;
mod sync_tab;
mod use_mouse;
mod zellij_setup_check;

lazy_static! {
pub static ref TIPS: HashMap<&'static str, TipBody> = HashMap::from([
(
"quicknav",
TipBody {
short: quicknav::quicknav_short,
medium: quicknav::quicknav_medium,
full: quicknav::quicknav_full,
}
),
(
"floating_panes_mouse",
TipBody {
short: floating_panes_mouse::floating_panes_mouse_short,
medium: floating_panes_mouse::floating_panes_mouse_medium,
full: floating_panes_mouse::floating_panes_mouse_full,
}
),
(
"send_mouse_clicks_to_terminal",
TipBody {
short: send_mouse_click_to_terminal::mouse_click_to_terminal_short,
medium: send_mouse_click_to_terminal::mouse_click_to_terminal_medium,
full: send_mouse_click_to_terminal::mouse_click_to_terminal_full,
}
),
(
"move_focus_hjkl_tab_switch",
TipBody {
short: move_focus_hjkl_tab_switch::move_focus_hjkl_tab_switch_short,
medium: move_focus_hjkl_tab_switch::move_focus_hjkl_tab_switch_medium,
full: move_focus_hjkl_tab_switch::move_focus_hjkl_tab_switch_full,
}
),
(
"zellij_setup_check",
TipBody {
short: zellij_setup_check::zellij_setup_check_short,
medium: zellij_setup_check::zellij_setup_check_medium,
full: zellij_setup_check::zellij_setup_check_full,
}
),
(
"use_mouse",
TipBody {
short: use_mouse::use_mouse_short,
medium: use_mouse::use_mouse_medium,
full: use_mouse::use_mouse_full,
}
),
(
"sync_tab",
TipBody {
short: sync_tab::sync_tab_short,
medium: sync_tab::sync_tab_medium,
full: sync_tab::sync_tab_full,
}
),
(
"edit_scrollbuffer",
TipBody {
short: edit_scrollbuffer::edit_scrollbuffer_short,
medium: edit_scrollbuffer::edit_scrollbuffer_medium,
full: edit_scrollbuffer::edit_scrollbuffer_full,
}
),
(
"compact_layout",
TipBody {
short: compact_layout::compact_layout_short,
medium: compact_layout::compact_layout_medium,
full: compact_layout::compact_layout_full,
}
),
]);
}
Loading