Compare commits
1 Commits
802cf8e9d3
...
439d3af7d3
| Author | SHA1 | Date | |
|---|---|---|---|
| 439d3af7d3 |
@ -1,4 +1,3 @@
|
|||||||
use log::trace;
|
|
||||||
use ratatui::buffer::Buffer;
|
use ratatui::buffer::Buffer;
|
||||||
use ratatui::layout::{Constraint, Direction, Layout, Rect};
|
use ratatui::layout::{Constraint, Direction, Layout, Rect};
|
||||||
use ratatui::style::{Modifier, Style};
|
use ratatui::style::{Modifier, Style};
|
||||||
|
|||||||
@ -20,9 +20,6 @@ use ratatui::widgets::{Paragraph, Wrap};
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
// TODO: Need a way to dynamically run Widget::render on all widgets.
|
|
||||||
// TODO: + Need a way to map Rect to Component::id() to position each widget?
|
|
||||||
// TODO: Need a good way to dynamically run Component methods on all widgets.
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub enum AppComponent {
|
pub enum AppComponent {
|
||||||
AppEditor,
|
AppEditor,
|
||||||
@ -48,7 +45,7 @@ impl<'a> App<'a> {
|
|||||||
pub fn new(root_path: PathBuf) -> Result<Self> {
|
pub fn new(root_path: PathBuf) -> Result<Self> {
|
||||||
trace!(target:Self::id(), "Building {}", Self::id());
|
trace!(target:Self::id(), "Building {}", Self::id());
|
||||||
let app = Self {
|
let app = Self {
|
||||||
editor_tabs: EditorTab::new(&root_path.join("src/tui/app.rs")),
|
editor_tabs: EditorTab::new(None),
|
||||||
explorer: Explorer::new(&root_path)?,
|
explorer: Explorer::new(&root_path)?,
|
||||||
logger: Logger::new(),
|
logger: Logger::new(),
|
||||||
menu_bar: MenuBar::new(),
|
menu_bar: MenuBar::new(),
|
||||||
@ -61,17 +58,6 @@ impl<'a> App<'a> {
|
|||||||
/// Logic that should be executed once on application startup.
|
/// Logic that should be executed once on application startup.
|
||||||
pub fn start(&mut self) -> Result<()> {
|
pub fn start(&mut self) -> Result<()> {
|
||||||
trace!(target:Self::id(), "Starting App");
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -23,13 +23,25 @@ impl EditorTab {
|
|||||||
"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:?}");
|
trace!(target:Self::id(), "Building EditorTab with path {path:?}");
|
||||||
let tab_order = vec![path.to_string_lossy().to_string()];
|
match path {
|
||||||
Self {
|
None => Self {
|
||||||
editors: HashMap::from([(tab_order.first().unwrap().to_owned(), Editor::new(path))]),
|
editors: HashMap::new(),
|
||||||
tab_order,
|
tab_order: Vec::new(),
|
||||||
current_editor: 0,
|
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,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user