From 802cf8e9d3192a0e69b881e835d9872e32a1a379 Mon Sep 17 00:00:00 2001 From: Shaun Reed Date: Sun, 25 Jan 2026 15:20:06 -0500 Subject: [PATCH] [tui] Open application with no editor tab. The explorer can be used to open the first tab. --- src/tui/about.rs | 1 - src/tui/app.rs | 13 +------------ src/tui/editor_tab.rs | 24 ++++++++++++++++++------ 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/tui/about.rs b/src/tui/about.rs index e7a7acc..c5f222a 100644 --- a/src/tui/about.rs +++ b/src/tui/about.rs @@ -1,4 +1,3 @@ -use log::trace; use ratatui::buffer::Buffer; use ratatui::layout::{Constraint, Direction, Layout, Rect}; use ratatui::style::{Modifier, Style}; diff --git a/src/tui/app.rs b/src/tui/app.rs index 04932c5..55e2654 100644 --- a/src/tui/app.rs +++ b/src/tui/app.rs @@ -48,7 +48,7 @@ impl<'a> App<'a> { pub fn new(root_path: PathBuf) -> Result { trace!(target:Self::id(), "Building {}", Self::id()); let app = Self { - editor_tabs: EditorTab::new(&root_path.join("src/tui/app.rs")), + editor_tabs: EditorTab::new(None), explorer: Explorer::new(&root_path)?, logger: Logger::new(), menu_bar: MenuBar::new(), @@ -61,17 +61,6 @@ impl<'a> App<'a> { /// Logic that should be executed once on application startup. pub fn start(&mut self) -> Result<()> { trace!(target:Self::id(), "Starting App"); - let root_path = self.explorer.root_path.clone(); - let editor = self - .editor_tabs - .current_editor_mut() - .context("Failed to get current editor in App::start")?; - editor - .set_contents(&root_path.join("src/tui/app.rs")) - .context(format!( - "Failed to initialize editor contents to path: {root_path:?}" - ))?; - editor.component_state.set_focus(Focus::Active); Ok(()) } diff --git a/src/tui/editor_tab.rs b/src/tui/editor_tab.rs index 9965b16..1a5fb01 100644 --- a/src/tui/editor_tab.rs +++ b/src/tui/editor_tab.rs @@ -23,13 +23,25 @@ impl EditorTab { "EditorTab" } - pub fn new(path: &std::path::PathBuf) -> Self { + pub fn new(path: Option<&std::path::PathBuf>) -> Self { trace!(target:Self::id(), "Building EditorTab with path {path:?}"); - let tab_order = vec![path.to_string_lossy().to_string()]; - Self { - editors: HashMap::from([(tab_order.first().unwrap().to_owned(), Editor::new(path))]), - tab_order, - current_editor: 0, + match path { + None => Self { + editors: HashMap::new(), + tab_order: Vec::new(), + current_editor: 0, + }, + Some(path) => { + let tab_order = vec![path.to_string_lossy().to_string()]; + Self { + editors: HashMap::from([( + tab_order.first().unwrap().to_owned(), + Editor::new(path), + )]), + tab_order, + current_editor: 0, + } + } } }