[tui] Clean up logging.
This commit is contained in:
@@ -2,14 +2,14 @@ use crate::tui::component::{Action, Component};
|
||||
use crate::tui::editor::Editor;
|
||||
use crate::tui::explorer::Explorer;
|
||||
use crate::tui::logger::Logger;
|
||||
use anyhow::{Context, Result, anyhow, bail};
|
||||
use anyhow::{Context, Result, bail};
|
||||
use log::{debug, error, info, trace, warn};
|
||||
use ratatui::buffer::Buffer;
|
||||
use ratatui::crossterm::event;
|
||||
use ratatui::crossterm::event::{Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers};
|
||||
use ratatui::layout::{Constraint, Direction, Layout, Rect};
|
||||
use ratatui::prelude::{Color, Style, Widget};
|
||||
use ratatui::widgets::{Block, Borders, Padding, Paragraph, Tabs, Wrap};
|
||||
use ratatui::widgets::{Block, Borders, Padding, Tabs};
|
||||
use ratatui::{DefaultTerminal, symbols};
|
||||
use std::path::PathBuf;
|
||||
use std::time::Duration;
|
||||
@@ -27,56 +27,11 @@ pub enum AppComponents<'a> {
|
||||
/// Usage: get_component_mut::<Editor>() OR get_component::<Editor>()
|
||||
///
|
||||
/// Implementing this trait for each AppComponent allows for easy lookup in the vector.
|
||||
trait ComponentOf<T> {
|
||||
pub(crate) trait ComponentOf<T> {
|
||||
fn as_ref(&self) -> Option<&T>;
|
||||
fn as_mut(&mut self) -> Option<&mut T>;
|
||||
}
|
||||
|
||||
impl<'a> ComponentOf<Logger> for AppComponents<'a> {
|
||||
fn as_ref(&self) -> Option<&Logger> {
|
||||
if let AppComponents::AppLogger(ref e) = *self {
|
||||
return Some(e);
|
||||
}
|
||||
None
|
||||
}
|
||||
fn as_mut(&mut self) -> Option<&mut Logger> {
|
||||
if let AppComponents::AppLogger(ref mut e) = *self {
|
||||
return Some(e);
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ComponentOf<Editor> for AppComponents<'a> {
|
||||
fn as_ref(&self) -> Option<&Editor> {
|
||||
if let AppComponents::AppEditor(ref e) = *self {
|
||||
return Some(e);
|
||||
}
|
||||
None
|
||||
}
|
||||
fn as_mut(&mut self) -> Option<&mut Editor> {
|
||||
if let AppComponents::AppEditor(ref mut e) = *self {
|
||||
return Some(e);
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ComponentOf<Explorer<'a>> for AppComponents<'a> {
|
||||
fn as_ref(&self) -> Option<&Explorer<'a>> {
|
||||
if let AppComponents::AppExplorer(ref e) = *self {
|
||||
return Some(e);
|
||||
}
|
||||
None
|
||||
}
|
||||
fn as_mut(&mut self) -> Option<&mut Explorer<'a>> {
|
||||
if let AppComponents::AppExplorer(ref mut e) = *self {
|
||||
return Some(e);
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub struct App<'a> {
|
||||
components: Vec<AppComponents<'a>>,
|
||||
}
|
||||
@@ -94,8 +49,7 @@ impl<'a> App<'a> {
|
||||
.unwrap()
|
||||
.set_contents(&root_path.join("src/tui/app.rs"))
|
||||
.context(format!(
|
||||
"Failed to initialize editor contents to path: {}",
|
||||
root_path.to_string_lossy()
|
||||
"Failed to initialize editor contents to path: {root_path:?}"
|
||||
))?;
|
||||
Ok(app)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use crate::tui::component::{Action, Component};
|
||||
|
||||
use crate::tui::app::{AppComponents, ComponentOf};
|
||||
use anyhow::{Context, Result, bail};
|
||||
use edtui::{
|
||||
EditorEventHandler, EditorState, EditorTheme, EditorView, LineNumbers, Lines, SyntaxHighlighter,
|
||||
@@ -22,6 +23,21 @@ pub struct Editor {
|
||||
syntax_set: SyntaxSet,
|
||||
}
|
||||
|
||||
impl<'a> ComponentOf<Editor> for AppComponents<'a> {
|
||||
fn as_ref(&self) -> Option<&Editor> {
|
||||
if let AppComponents::AppEditor(ref e) = *self {
|
||||
return Some(e);
|
||||
}
|
||||
None
|
||||
}
|
||||
fn as_mut(&mut self) -> Option<&mut Editor> {
|
||||
if let AppComponents::AppEditor(ref mut e) = *self {
|
||||
return Some(e);
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl Editor {
|
||||
pub fn new() -> Self {
|
||||
Editor {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use crate::tui::app::{AppComponents, ComponentOf};
|
||||
use crate::tui::component::{Action, Component};
|
||||
use anyhow::{Context, Result, bail};
|
||||
use ratatui::buffer::Buffer;
|
||||
@@ -16,6 +17,21 @@ pub struct Explorer<'a> {
|
||||
tree_state: TreeState<String>,
|
||||
}
|
||||
|
||||
impl<'a> ComponentOf<Explorer<'a>> for AppComponents<'a> {
|
||||
fn as_ref(&self) -> Option<&Explorer<'a>> {
|
||||
if let AppComponents::AppExplorer(ref e) = *self {
|
||||
return Some(e);
|
||||
}
|
||||
None
|
||||
}
|
||||
fn as_mut(&mut self) -> Option<&mut Explorer<'a>> {
|
||||
if let AppComponents::AppExplorer(ref mut e) = *self {
|
||||
return Some(e);
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Explorer<'a> {
|
||||
pub fn new(path: &std::path::PathBuf) -> Result<Self> {
|
||||
let explorer = Explorer {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use crate::tui::app::{AppComponents, ComponentOf};
|
||||
use crate::tui::component::{Action, Component};
|
||||
use ratatui::buffer::Buffer;
|
||||
use ratatui::crossterm::event::{Event, KeyCode, KeyEvent};
|
||||
@@ -12,6 +13,21 @@ pub struct Logger {
|
||||
state: TuiWidgetState,
|
||||
}
|
||||
|
||||
impl<'a> ComponentOf<Logger> for AppComponents<'a> {
|
||||
fn as_ref(&self) -> Option<&Logger> {
|
||||
if let AppComponents::AppLogger(ref e) = *self {
|
||||
return Some(e);
|
||||
}
|
||||
None
|
||||
}
|
||||
fn as_mut(&mut self) -> Option<&mut Logger> {
|
||||
if let AppComponents::AppLogger(ref mut e) = *self {
|
||||
return Some(e);
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl Logger {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
|
||||
Reference in New Issue
Block a user