[tui] Use anyhow::bail!() macro.
This commit is contained in:
parent
42a40fe7f3
commit
1e635ee059
@ -1,7 +1,7 @@
|
|||||||
use crate::tui::component::{Action, Component};
|
use crate::tui::component::{Action, Component};
|
||||||
use crate::tui::editor::Editor;
|
use crate::tui::editor::Editor;
|
||||||
use crate::tui::explorer::Explorer;
|
use crate::tui::explorer::Explorer;
|
||||||
use anyhow::{Context, Result, anyhow};
|
use anyhow::{Context, Result, anyhow, bail};
|
||||||
use ratatui::buffer::Buffer;
|
use ratatui::buffer::Buffer;
|
||||||
use ratatui::crossterm::event;
|
use ratatui::crossterm::event;
|
||||||
use ratatui::crossterm::event::{Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers};
|
use ratatui::crossterm::event::{Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers};
|
||||||
@ -46,7 +46,7 @@ impl<'a> App<'a> {
|
|||||||
return Ok(explorer);
|
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>> {
|
fn get_explorer_mut(&mut self) -> Result<&mut Explorer<'a>> {
|
||||||
@ -55,7 +55,7 @@ impl<'a> App<'a> {
|
|||||||
return Ok(explorer);
|
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> {
|
fn get_editor(&self) -> Option<&Editor> {
|
||||||
@ -95,7 +95,7 @@ impl<'a> App<'a> {
|
|||||||
Action::Quit => break,
|
Action::Quit => break,
|
||||||
Action::Handled => {}
|
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);
|
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_status(vertical[0], buf);
|
||||||
self.draw_terminal(vertical[2], buf);
|
self.draw_terminal(vertical[2], buf);
|
||||||
if let Ok(explorer) = self.get_explorer_mut() {
|
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.draw_tabs(editor_layout[0], buf);
|
||||||
self.get_editor_mut().unwrap().render(editor_layout[1], buf);
|
self.get_editor_mut().unwrap().render(editor_layout[1], buf);
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
use crate::tui::component::{Action, Component};
|
use crate::tui::component::{Action, Component};
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{bail, Context, Result};
|
||||||
use edtui::{
|
use edtui::{
|
||||||
EditorEventHandler, EditorState, EditorTheme, EditorView, LineNumbers, Lines, SyntaxHighlighter,
|
EditorEventHandler, EditorState, EditorTheme, EditorView, LineNumbers, Lines, SyntaxHighlighter,
|
||||||
};
|
};
|
||||||
@ -48,7 +48,7 @@ impl Editor {
|
|||||||
if let Some(path) = &self.file_path {
|
if let Some(path) = &self.file_path {
|
||||||
return std::fs::write(path, self.state.lines.to_string()).map_err(|e| e.into());
|
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.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
use crate::tui::component::{Action, Component};
|
use crate::tui::component::{Action, Component};
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{bail, Context, Result};
|
||||||
use ratatui::buffer::Buffer;
|
use ratatui::buffer::Buffer;
|
||||||
use ratatui::crossterm::event::{Event, KeyCode, KeyEvent, MouseEvent, MouseEventKind};
|
use ratatui::crossterm::event::{Event, KeyCode, KeyEvent, MouseEvent, MouseEventKind};
|
||||||
use ratatui::layout::{Alignment, Position, Rect};
|
use ratatui::layout::{Alignment, Position, Rect};
|
||||||
@ -107,7 +107,7 @@ impl<'a> Explorer<'a> {
|
|||||||
if let Some(path) = self.tree_state.selected().last() {
|
if let Some(path) = self.tree_state.selected().last() {
|
||||||
return Ok(std::path::absolute(path)?.to_str().unwrap().to_string());
|
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")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user