From 4dc38e7ec69c2d8e24471156ea9e684e14bdf542 Mon Sep 17 00:00:00 2001 From: Taehoon Moon Date: Sat, 18 Jan 2025 22:57:19 +0900 Subject: [PATCH] Make editor breadcrumb look better --- tui/src/color.rs | 3 ++ tui/src/views/body/notebook/editor.rs | 58 ++++++++++++++++++++------- 2 files changed, 47 insertions(+), 14 deletions(-) diff --git a/tui/src/color.rs b/tui/src/color.rs index ce74304..3fc9c4d 100644 --- a/tui/src/color.rs +++ b/tui/src/color.rs @@ -17,3 +17,6 @@ pub const GRAY_LIGHT: Color = Color::Indexed(250); pub const GRAY_WHITE: Color = Color::Indexed(253); pub const WHITE: Color = Color::White; pub const BLACK: Color = Color::Black; + +pub const GRAY_A: Color = Color::Indexed(246); +pub const GRAY_B: Color = Color::Indexed(248); diff --git a/tui/src/views/body/notebook/editor.rs b/tui/src/views/body/notebook/editor.rs index f1fe611..af8650a 100644 --- a/tui/src/views/body/notebook/editor.rs +++ b/tui/src/views/body/notebook/editor.rs @@ -18,7 +18,7 @@ const NOTE_SYMBOL: &str = "󱇗 "; pub fn draw(frame: &mut Frame, area: Rect, context: &mut Context) { context.notebook.editor_height = area.height - 2; - let (title, breadcrumb) = if let Some(tab_index) = context.notebook.tab_index { + let (title, mut bottom_left) = if let Some(tab_index) = context.notebook.tab_index { let mut title = vec![]; for (i, tab) in context.notebook.tabs.iter().enumerate() { let name = format!(" {NOTE_SYMBOL}{} ", tab.note.name.clone()); @@ -36,25 +36,55 @@ pub fn draw(frame: &mut Frame, area: Rect, context: &mut Context) { } let title = Line::from(title); - let breadcrumb = Span::raw(format!( - " {} ", - context.notebook.tabs[tab_index].breadcrumb.join("/") - )) - .fg(BLACK) - .bg(GREEN); + let mut breadcrumb = vec![]; + let last_index = context.notebook.tabs[tab_index].breadcrumb.len() - 1; + + for (i, name) in context.notebook.tabs[tab_index] + .breadcrumb + .iter() + .enumerate() + { + let (color_a, color_b) = if i % 2 == 0 { + (GRAY_A, GRAY_B) + } else { + (GRAY_B, GRAY_A) + }; + + let name = if i == 0 { + breadcrumb.push(Span::raw(" 󰝰 ").fg(YELLOW).bg(color_a)); + format!("{name} ") + } else if i == last_index { + format!(" 󱇗 {name} ") + } else { + breadcrumb.push(Span::raw(" 󰝰 ").fg(YELLOW).bg(color_a)); + format!("{name} ") + }; + + breadcrumb.push(Span::raw(name).fg(BLACK).bg(color_a)); + + if i < last_index { + breadcrumb.push(Span::raw("").fg(color_a).bg(color_b)); + } else { + breadcrumb.push(Span::raw("").fg(color_a).bg(GRAY_BLACK)); + } + } + (title, breadcrumb) } else { - (Line::from("[Editor]".fg(GRAY_DIM)), Span::default()) + (Line::from("[Editor]".fg(GRAY_DIM)), vec![Span::default()]) }; - let mode = match context.notebook.state { - ContextState::EditorNormalMode { .. } => Span::raw(" NORMAL ").fg(WHITE).bg(BLACK), - ContextState::EditorInsertMode => Span::raw(" INSERT ").fg(BLACK).bg(YELLOW), - ContextState::EditorVisualMode => Span::raw(" VISUAL ").fg(WHITE).bg(RED), - _ => Span::raw(" ").bg(GRAY_DARK), + let (mode, bg) = match context.notebook.state { + ContextState::EditorNormalMode { .. } => (Span::raw(" NORMAL ").fg(WHITE).bg(BLACK), BLACK), + ContextState::EditorInsertMode => (Span::raw(" INSERT ").fg(BLACK).bg(YELLOW), YELLOW), + ContextState::EditorVisualMode => (Span::raw(" VISUAL ").fg(WHITE).bg(RED), RED), + _ => (Span::raw(" ").bg(GRAY_DARK), GRAY_DARK), }; - let bottom_left = Line::from(vec![mode, breadcrumb]); + bottom_left.insert(0, mode); + bottom_left.insert(1, Span::raw("").fg(bg).bg(GRAY_A)); + + let bottom_left = Line::from(bottom_left); let block = Block::new().title(title).title_bottom(bottom_left); let block = match ( context.last_log.as_ref(),