feat: basic control implemented
This commit is contained in:
@@ -12,6 +12,7 @@ use ratatui::{
|
|||||||
};
|
};
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
|
#[derive(PartialEq)]
|
||||||
pub enum UiState {
|
pub enum UiState {
|
||||||
LIST,
|
LIST,
|
||||||
FILTERWORD,
|
FILTERWORD,
|
||||||
@@ -79,13 +80,27 @@ impl App {
|
|||||||
.flex(Flex::Center)
|
.flex(Flex::Center)
|
||||||
.split(main_layout[2]);
|
.split(main_layout[2]);
|
||||||
|
|
||||||
|
let word_filter: String = {
|
||||||
|
if let Some(l) = &self.word_filter {
|
||||||
|
l.to_string()
|
||||||
|
} else {
|
||||||
|
"".to_string()
|
||||||
|
}
|
||||||
|
};
|
||||||
frame.render_widget(
|
frame.render_widget(
|
||||||
Paragraph::new("test word").block(Block::new().title("Word").borders(Borders::ALL)),
|
Paragraph::new(word_filter).block(Block::new().title("Word").borders(Borders::ALL)),
|
||||||
filters_layout[0],
|
filters_layout[0],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let lang_filter: String = {
|
||||||
|
if let Some(l) = &self.lang_filter {
|
||||||
|
l.to_string()
|
||||||
|
} else {
|
||||||
|
"".to_string()
|
||||||
|
}
|
||||||
|
};
|
||||||
frame.render_widget(
|
frame.render_widget(
|
||||||
Paragraph::new("en").block(Block::new().title("Lang").borders(Borders::ALL)),
|
Paragraph::new(lang_filter).block(Block::new().title("Lang").borders(Borders::ALL)),
|
||||||
filters_layout[1],
|
filters_layout[1],
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -99,7 +114,7 @@ impl App {
|
|||||||
words_layout[1],
|
words_layout[1],
|
||||||
);
|
);
|
||||||
|
|
||||||
let help_text = Text::raw("(m)ove | (f)ilter | (d)elete | (e)dit | (a)dd | (q)uit ")
|
let help_text = Text::raw("(f)ilter | lan(g) | (d)elete | (e)dit | (a)dd | (q)uit ")
|
||||||
.style(Style::new().fg(Color::DarkGray));
|
.style(Style::new().fg(Color::DarkGray));
|
||||||
let help_area = help_layout[0].centered(
|
let help_area = help_layout[0].centered(
|
||||||
Constraint::Length(help_text.width() as u16),
|
Constraint::Length(help_text.width() as u16),
|
||||||
@@ -113,9 +128,41 @@ impl App {
|
|||||||
if let Event::Key(key) = event::read()? {
|
if let Event::Key(key) = event::read()? {
|
||||||
match key.code {
|
match key.code {
|
||||||
event::KeyCode::Char(c) => {
|
event::KeyCode::Char(c) => {
|
||||||
if c == 'q' {
|
match self.state {
|
||||||
|
UiState::FILTERWORD => {
|
||||||
|
if let Some(mut prev_word) = self.word_filter.clone() {
|
||||||
|
prev_word.push(c);
|
||||||
|
self.word_filter = Some(prev_word);
|
||||||
|
} else {
|
||||||
|
self.word_filter = Some(c.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
if c == 'q' || c == 'x' {
|
||||||
return Err(io::Error::last_os_error()); // FIXME: this is not right
|
return Err(io::Error::last_os_error()); // FIXME: this is not right
|
||||||
}
|
}
|
||||||
|
if c == 'f' || c == '/' {
|
||||||
|
self.state = UiState::FILTERWORD;
|
||||||
|
}
|
||||||
|
if c == 'g' {
|
||||||
|
self.state = UiState::FILTERLANG;
|
||||||
|
}
|
||||||
|
if c == 'd' {
|
||||||
|
self.state = UiState::DELETE;
|
||||||
|
}
|
||||||
|
if c == 'e' {
|
||||||
|
self.state = UiState::EDIT;
|
||||||
|
}
|
||||||
|
if c == 'a' {
|
||||||
|
self.state = UiState::ADD;
|
||||||
|
}
|
||||||
|
// TODO: remove, just for testing
|
||||||
|
self.lang_filter = Some(format!("{0} >> {1}", c, key.code));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
event::KeyCode::Esc => {
|
||||||
|
self.state = UiState::LIST;
|
||||||
}
|
}
|
||||||
_ => return Ok(()),
|
_ => return Ok(()),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user