diff --git a/src/tui/app.rs b/src/tui/app.rs index 1ea198e..574497c 100644 --- a/src/tui/app.rs +++ b/src/tui/app.rs @@ -1,7 +1,7 @@ use crate::tui::component::{Action, Component}; use crate::tui::editor::Editor; use crate::tui::explorer::Explorer; -use anyhow::{Context, Result, anyhow}; +use anyhow::{Context, Result, anyhow, bail}; use ratatui::buffer::Buffer; use ratatui::crossterm::event; use ratatui::crossterm::event::{Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers}; @@ -46,7 +46,7 @@ impl<'a> App<'a> { return Ok(explorer); } } - Err(anyhow::anyhow!("Failed to find project explorer widget.")) + bail!("Failed to find project explorer widget.") } fn get_explorer_mut(&mut self) -> Result<&mut Explorer<'a>> { @@ -55,7 +55,7 @@ impl<'a> App<'a> { return Ok(explorer); } } - Err(anyhow::anyhow!("Failed to find project explorer widget.")) + bail!("Failed to find project explorer widget.") } fn get_editor(&self) -> Option<&Editor> { @@ -95,7 +95,7 @@ impl<'a> App<'a> { Action::Quit => break, Action::Handled => {} _ => { - // anyhow::anyhow!("Unhandled event: {:?}", event); + // bail!("Unhandled event: {:?}", event); } } } @@ -165,7 +165,7 @@ impl<'a> App<'a> { } return editor.set_contents(&selected_pathbuf); } - Err(anyhow!("Failed to refresh editor contents")) + bail!("Failed to refresh editor contents") } } @@ -203,7 +203,11 @@ impl<'a> Widget for &mut App<'a> { self.draw_status(vertical[0], buf); self.draw_terminal(vertical[2], buf); if let Ok(explorer) = self.get_explorer_mut() { - explorer.render(horizontal[0], buf); + // TODO: What to do about errors during rendering? + // Once there is a debug console, maybe log it and discard? Panic isn't great. + explorer + .render(horizontal[0], buf) + .expect("Failed to render Explorer"); } self.draw_tabs(editor_layout[0], buf); self.get_editor_mut().unwrap().render(editor_layout[1], buf); diff --git a/src/tui/editor.rs b/src/tui/editor.rs index 411edfd..d6dc3a7 100644 --- a/src/tui/editor.rs +++ b/src/tui/editor.rs @@ -1,6 +1,6 @@ use crate::tui::component::{Action, Component}; -use anyhow::{Context, Result}; +use anyhow::{bail, Context, Result}; use edtui::{ EditorEventHandler, EditorState, EditorTheme, EditorView, LineNumbers, Lines, SyntaxHighlighter, }; @@ -48,7 +48,7 @@ impl Editor { if let Some(path) = &self.file_path { return std::fs::write(path, self.state.lines.to_string()).map_err(|e| e.into()); }; - Err(anyhow::anyhow!("File not saved. No file path set.")) + bail!("File not saved. No file path set.") } } diff --git a/src/tui/explorer.rs b/src/tui/explorer.rs index aa39ae5..c63e810 100644 --- a/src/tui/explorer.rs +++ b/src/tui/explorer.rs @@ -1,5 +1,5 @@ use crate::tui::component::{Action, Component}; -use anyhow::{Context, Result}; +use anyhow::{bail, Context, Result}; use ratatui::buffer::Buffer; use ratatui::crossterm::event::{Event, KeyCode, KeyEvent, MouseEvent, MouseEventKind}; use ratatui::layout::{Alignment, Position, Rect}; @@ -107,7 +107,7 @@ impl<'a> Explorer<'a> { if let Some(path) = self.tree_state.selected().last() { return Ok(std::path::absolute(path)?.to_str().unwrap().to_string()); } - Err(anyhow::anyhow!("Failed to get selected TreeItem")) + bail!("Failed to get selected TreeItem") } }