WIP: ratatui app init
This commit is contained in:
21
src/main.rs
21
src/main.rs
@@ -1,13 +1,15 @@
|
||||
use std::*;
|
||||
|
||||
use std::io::{self, Error};
|
||||
|
||||
mod modules;
|
||||
use modules::config::{Config, read_config};
|
||||
|
||||
use crate::modules::source::{FileDatabase, Word, WordSource};
|
||||
use modules::source::{FileDatabase, Word, WordSource};
|
||||
use modules::ui::app::App;
|
||||
|
||||
const DEFAULT_CONFIG_PATH: &'static str = "./src/assets/wordsmith_default.conf";
|
||||
|
||||
fn main() {
|
||||
fn main() -> io::Result<()> {
|
||||
dotenv::dotenv().ok();
|
||||
|
||||
let args: Vec<String> = env::args().collect();
|
||||
@@ -34,12 +36,19 @@ fn main() {
|
||||
|
||||
match word_source_result {
|
||||
Ok(word_source) => {
|
||||
// TODO: interface and loop
|
||||
let mut app = App::new();
|
||||
return ratatui::run(|terminal| app.run(terminal));
|
||||
}
|
||||
Err(word_source_error) => {
|
||||
println!("!! {0}", word_source_error);
|
||||
return Err(Error::new(
|
||||
io::ErrorKind::ConnectionRefused,
|
||||
word_source_error,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
println!("Hello, world! {:?}", config);
|
||||
Err(Error::new(
|
||||
io::ErrorKind::Interrupted,
|
||||
"Exit with abnormal procedure.",
|
||||
))
|
||||
}
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
pub mod config;
|
||||
pub mod source;
|
||||
pub mod ui;
|
||||
|
||||
62
src/modules/ui/app.rs
Normal file
62
src/modules/ui/app.rs
Normal file
@@ -0,0 +1,62 @@
|
||||
use crossterm::event::{self, Event, KeyCode, KeyEvent, KeyEventKind};
|
||||
use ratatui::{
|
||||
DefaultTerminal, Frame,
|
||||
buffer::Buffer,
|
||||
layout::Rect,
|
||||
style::Stylize,
|
||||
symbols::border,
|
||||
text::{Line, Text},
|
||||
widgets::{Block, Paragraph, Widget},
|
||||
};
|
||||
|
||||
enum UiState {
|
||||
LIST,
|
||||
FILTER,
|
||||
EDIT,
|
||||
ADD,
|
||||
DELETE,
|
||||
}
|
||||
|
||||
enum FilterVariant {
|
||||
WORD,
|
||||
LANG,
|
||||
}
|
||||
|
||||
struct Filter {
|
||||
variant: FilterVariant,
|
||||
value: String,
|
||||
}
|
||||
|
||||
pub struct App {
|
||||
state: UiState,
|
||||
scroll_percentage: u32,
|
||||
filters: Vector<Filter>,
|
||||
exit: bool,
|
||||
}
|
||||
|
||||
impl App {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
state: UiState.LIST,
|
||||
scroll_percentage: 0,
|
||||
filters: vec![],
|
||||
exit: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run(&mut self, terminal: &mut DefaultTerminal) -> io::Result<()> {
|
||||
while !self.exit {
|
||||
terminal.draw(|frame| self.draw(frame))?;
|
||||
self.handle_events()?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn draw(&self, frame: &mut Frame) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn handle_events(&mut self) -> io::Result<()> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
1
src/modules/ui/mod.rs
Normal file
1
src/modules/ui/mod.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod app;
|
||||
Reference in New Issue
Block a user