@@ -63,12 +63,15 @@ impl<'a> App<'a> {
|
||||
graph_explorer: GraphExplorer<'a>,
|
||||
) -> Self {
|
||||
Self {
|
||||
state,
|
||||
root: root.into(),
|
||||
mode: Mode::View,
|
||||
|
||||
dialog: None,
|
||||
command: None,
|
||||
state,
|
||||
|
||||
graph_explorer,
|
||||
|
||||
mode: Mode::View,
|
||||
focus: AppFocus::Graph,
|
||||
}
|
||||
}
|
||||
@@ -109,6 +112,7 @@ impl<'a> App<'a> {
|
||||
}
|
||||
|
||||
if command.is_quit() {
|
||||
self.focus = AppFocus::Graph;
|
||||
self.dialog = None;
|
||||
}
|
||||
}
|
||||
@@ -138,6 +142,7 @@ impl<'a> App<'a> {
|
||||
let root = self.root.clone();
|
||||
let path = self.graph_explorer.get_current_path();
|
||||
|
||||
self.focus = AppFocus::Dialog;
|
||||
self.dialog = Some(Dialog::CreateItem {
|
||||
state: CreateItemState::new(root, path),
|
||||
});
|
||||
@@ -151,7 +156,7 @@ impl<'a> Widget for &mut App<'a> {
|
||||
Self: Sized,
|
||||
{
|
||||
StatefulWidget::render(
|
||||
GraphExplorer::new(self.state.clone()),
|
||||
GraphExplorer::new(self.root.clone(), self.state.clone()),
|
||||
area,
|
||||
buf,
|
||||
&mut self.graph_explorer.inner,
|
||||
|
@@ -5,7 +5,7 @@ use hyperlog_core::log::GraphItem;
|
||||
use itertools::Itertools;
|
||||
use ratatui::{prelude::*, widgets::*};
|
||||
|
||||
use crate::{command_parser::Commands, state::SharedState};
|
||||
use crate::{command_parser::Commands, commands::Command, state::SharedState};
|
||||
|
||||
pub struct GraphExplorer<'a> {
|
||||
state: SharedState,
|
||||
@@ -14,17 +14,20 @@ pub struct GraphExplorer<'a> {
|
||||
}
|
||||
|
||||
pub struct GraphExplorerState<'a> {
|
||||
root: String,
|
||||
|
||||
current_path: Option<&'a str>,
|
||||
current_position: Vec<usize>,
|
||||
|
||||
graph: Option<GraphItem>,
|
||||
}
|
||||
|
||||
impl GraphExplorer<'_> {
|
||||
pub fn new(state: SharedState) -> Self {
|
||||
impl<'a> GraphExplorer<'a> {
|
||||
pub fn new(root: String, state: SharedState) -> Self {
|
||||
Self {
|
||||
state,
|
||||
inner: GraphExplorerState::<'_> {
|
||||
inner: GraphExplorerState::<'a> {
|
||||
root,
|
||||
current_path: None,
|
||||
current_position: Vec::new(),
|
||||
graph: None,
|
||||
@@ -151,6 +154,13 @@ impl GraphExplorer<'_> {
|
||||
pub(crate) fn interact(&mut self) -> anyhow::Result<()> {
|
||||
if !self.get_current_path().is_empty() {
|
||||
tracing::info!("toggling state of items");
|
||||
|
||||
self.state
|
||||
.commander
|
||||
.execute(hyperlog_core::commander::Command::ToggleItem {
|
||||
root: self.inner.root.to_string(),
|
||||
path: self.get_current_path(),
|
||||
})?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@@ -39,10 +39,12 @@ pub async fn execute(state: State) -> Result<()> {
|
||||
}
|
||||
|
||||
fn run(terminal: &mut Terminal<CrosstermBackend<Stdout>>, state: SharedState) -> Result<()> {
|
||||
let mut graph_explorer = GraphExplorer::new(state.clone());
|
||||
let root = "kjuulh".to_string();
|
||||
|
||||
let mut graph_explorer = GraphExplorer::new(root.clone(), state.clone());
|
||||
graph_explorer.update_graph()?;
|
||||
|
||||
let mut app = App::new("kjuulh", state.clone(), graph_explorer);
|
||||
let mut app = App::new(&root, state.clone(), graph_explorer);
|
||||
|
||||
loop {
|
||||
terminal.draw(|f| render_app(f, &mut app))?;
|
||||
|
Reference in New Issue
Block a user