From c201f7b5554a19869a7ef2e93fa70e1dfe9cd1f7 Mon Sep 17 00:00:00 2001 From: Dmitrii Kovanikov Date: Sun, 25 Feb 2024 12:08:17 +0000 Subject: [PATCH] Display current directory --- lib/fs.ml | 5 +++++ lib/tui/view.ml | 28 +++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/lib/fs.ml b/lib/fs.ml index 856ed7c..f33296b 100644 --- a/lib/fs.ml +++ b/lib/fs.ml @@ -61,6 +61,11 @@ let zip_it trees = current = { pos = 0; files = trees; } } +let zipper_parents zipper = + List.filter_map + (fun cursor -> Option.map file_name (file_at cursor)) + zipper.parents + let go_down zipper = let cursor = zipper.current in let len = Array.length cursor.files in diff --git a/lib/tui/view.ml b/lib/tui/view.ml index ce80f9d..6569de5 100644 --- a/lib/tui/view.ml +++ b/lib/tui/view.ml @@ -4,6 +4,9 @@ let style_repo = let style_selected = ANSITerminal.([Bold; green]) +let style_directory = + ANSITerminal.([Bold; magenta]) + let tabs_section cur_tab = let open Pretty in let p_tab tab txt = @@ -41,6 +44,19 @@ let tabs_section cur_tab = ]; ] +let current_path_to_doc root_path parents = + let nested_path = + match parents with + | [] -> "" + | last :: previous -> + List.fold_right + (fun cur acc -> Filename.concat acc cur) + (List.rev previous) + last + in + let full_path = Filename.concat root_path nested_path in + Pretty.fmt style_directory full_path + let current_level_to_doc (cursor: Fs.cursor) has_next = let open Pretty in @@ -183,7 +199,15 @@ let fs_doc (fs : Fs.zipper) = Pretty.row [ current_level_doc; next_level_doc] let code_section (code_tab: Model.code_tab) = - fs_doc code_tab.fs + let current_path_doc = current_path_to_doc + code_tab.dirname + (Fs.zipper_parents code_tab.fs) + in + Pretty.col + [ + current_path_doc; + fs_doc code_tab.fs; + ] let tab_content_section (model: Model.t) = match model.current_tab with @@ -204,8 +228,6 @@ let to_doc (model: Model.t) = empty; tabs; - empty; - content; empty; ]