some styles
This commit is contained in:
+17
-10
@@ -1,19 +1,12 @@
|
|||||||
pub mod components;
|
pub mod components;
|
||||||
pub mod key;
|
pub mod key;
|
||||||
pub mod macros;
|
pub mod macros;
|
||||||
|
pub mod style;
|
||||||
pub mod utils;
|
pub mod utils;
|
||||||
|
|
||||||
use crossterm;
|
use crossterm::{self, ExecutableCommand};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
|
||||||
pub enum UpdateResponse {
|
|
||||||
Exit,
|
|
||||||
Done,
|
|
||||||
None,
|
|
||||||
Tick(Vec<u32>),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub struct Component {
|
pub struct Component {
|
||||||
pub render: fn(&mut Component) -> String,
|
pub render: fn(&mut Component) -> String,
|
||||||
@@ -30,6 +23,7 @@ pub struct Component {
|
|||||||
pub clicked: bool,
|
pub clicked: bool,
|
||||||
pub toggle: bool,
|
pub toggle: bool,
|
||||||
pub binds: HashMap<key::KeyKind, String>,
|
pub binds: HashMap<key::KeyKind, String>,
|
||||||
|
pub style: style::Style,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Component {
|
impl Component {
|
||||||
@@ -50,6 +44,7 @@ impl Component {
|
|||||||
clicked: false,
|
clicked: false,
|
||||||
toggle: false,
|
toggle: false,
|
||||||
binds: HashMap::new(),
|
binds: HashMap::new(),
|
||||||
|
style: style::Style::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,14 +92,18 @@ impl App {
|
|||||||
pub fn run(&mut self) {
|
pub fn run(&mut self) {
|
||||||
utils::hide_cursor();
|
utils::hide_cursor();
|
||||||
utils::clear();
|
utils::clear();
|
||||||
|
let mut stdout = std::io::stdout();
|
||||||
|
stdout
|
||||||
|
.execute(crossterm::terminal::EnterAlternateScreen)
|
||||||
|
.unwrap();
|
||||||
crossterm::terminal::enable_raw_mode().unwrap();
|
crossterm::terminal::enable_raw_mode().unwrap();
|
||||||
loop {
|
loop {
|
||||||
self.render();
|
self.render();
|
||||||
match (self.component.update)(&mut self.component, key::read_key()) {
|
match (self.component.update)(&mut self.component, key::read_key()) {
|
||||||
UpdateResponse::Exit => {
|
UpdateResponse::Exit => {
|
||||||
crossterm::terminal::disable_raw_mode().unwrap();
|
crossterm::terminal::disable_raw_mode().unwrap();
|
||||||
utils::clear();
|
|
||||||
utils::show_cursor();
|
utils::show_cursor();
|
||||||
|
utils::clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
UpdateResponse::Tick(ticks) => {
|
UpdateResponse::Tick(ticks) => {
|
||||||
@@ -119,3 +118,11 @@ impl App {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
pub enum UpdateResponse {
|
||||||
|
Exit,
|
||||||
|
Done,
|
||||||
|
None,
|
||||||
|
Tick(Vec<u32>),
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user