Open DanielHe4rt opened 3 weeks ago
I've come up with this, visually I think it's pleasant, it lacks behavior as of right now, but I think that's the idea for this issue as of right now.
I just will just have to refactor a LOT of code to follow the Elm Architecture which works better to handle this stuff. To better test this approach I just create another project to try without having to refactor stuff here, @DanielHe4rt can you give me your thoughts on this? If it's worth and all.
sequenceDiagram
participant User
participant TUI Application
User->>TUI Application: Input/Event/Message
TUI Application->>TUI Application: Update (based on Model and Message)
TUI Application->>TUI Application: Render View (from Model)
TUI Application-->>User: Display UI
The current solution looks like this:
stateDiagram-v2
[*] --> Running
Running --> [*]: Quit
state Running {
[*] --> Navigation
state Navigation {
[*] --> NoHover
NoHover --> HoverSidebar: Left
NoHover --> HoverREPL: Right
HoverSidebar --> NoHover: Right
HoverREPL --> NoHover: Left
HoverSidebar --> FocusSidebar: Enter
HoverREPL --> FocusREPL: Enter
}
Navigation --> FocusSidebar: Enter on HoverSidebar
Navigation --> FocusREPL: Enter on HoverREPL
state FocusSidebar {
[*] --> TreeNavigation
TreeNavigation --> TreeToggle: Enter/Space
TreeNavigation --> TreeLeft: Left
TreeNavigation --> TreeRight: Right
TreeNavigation --> TreeUp: Up
TreeNavigation --> TreeDown: Down
TreeNavigation --> TreeFirst: Home
TreeNavigation --> TreeLast: End
TreeNavigation --> TreeScrollUp: PageUp
TreeNavigation --> TreeScrollDown: PageDown
}
state FocusREPL {
[*] --> REPLInput
REPLInput --> REPLExecute: Enter
REPLExecute --> REPLOutput
REPLOutput --> REPLInput
}
FocusSidebar --> Navigation: Esc
FocusREPL --> Navigation: Esc
}
```rust
use ratatui::{
backend::CrosstermBackend,
crossterm::{
event::{self, Event, KeyCode},
execute,
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
},
layout::{Constraint, Direction, Layout},
style::{Color, Modifier, Style},
widgets::{Block, Borders, Paragraph},
Frame, Terminal,
};
use std::io;
use tui_tree_widget::{Tree, TreeItem, TreeState};
#[derive(Clone, Copy, PartialEq, Eq)]
enum FocusState {
Navigation,
Repl,
Sidebar,
}
type Identifier = String;
struct Model {
keyspaces: Vec
Feature
The first area which we can work on in this project is the Left Bar, which will be placed a Tree View for navigate through.
First Approach
My first glimpse on it was something around the File Explorer, where you can
list keyspaces and enter a Keyspace which will list all tables, mvs and udts
. Fortunately @Daniel-Boll found in advance the lib ratatui-explorer, which works perfectly but we would need to fork it (I GUESS) to make it work based on our needs.Second Approach
Also we have the possibility to just bring a Tree View on it and make it work faster, since it's simple do add new nodes to it. @Daniel-Boll also brought this crate which is tui-rs-tree-widget and solves our problem in a short term.
So, what would you like to implement in a first moment?