uds ipc working
This commit is contained in:
196
src/main.rs
196
src/main.rs
@ -11,6 +11,7 @@ use crossterm::{
|
||||
};
|
||||
use ratatui::{Terminal, backend::CrosstermBackend};
|
||||
use std::io;
|
||||
use std::time::Duration;
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
enable_raw_mode()?;
|
||||
@ -39,105 +40,120 @@ fn run_app(terminal: &mut Terminal<CrosstermBackend<io::Stdout>>, app: &mut App)
|
||||
loop {
|
||||
terminal.draw(|f| ui::render(f, app))?;
|
||||
|
||||
if let Event::Key(key) = event::read()? {
|
||||
match app.mode {
|
||||
Mode::Normal => match key.code {
|
||||
KeyCode::Char('j') => {
|
||||
app.next();
|
||||
last_key_was_d = false;
|
||||
}
|
||||
KeyCode::Char('k') => {
|
||||
app.previous();
|
||||
last_key_was_d = false;
|
||||
}
|
||||
KeyCode::Char('d') => {
|
||||
if last_key_was_d {
|
||||
app.delete_selected();
|
||||
last_key_was_d = false;
|
||||
} else {
|
||||
last_key_was_d = true;
|
||||
if event::poll(Duration::from_millis(500))? {
|
||||
if let Event::Key(key) = event::read()? {
|
||||
match app.mode {
|
||||
Mode::Normal => match key.code {
|
||||
KeyCode::Enter => {
|
||||
if let Some(selected) = app.get_selected_item() {
|
||||
crate::ipc::set_clipboard(selected.clone());
|
||||
app.should_quit = true;
|
||||
}
|
||||
}
|
||||
last_key_was_g = false;
|
||||
}
|
||||
KeyCode::Char('u') => {
|
||||
app.undo_delete();
|
||||
last_key_was_d = false;
|
||||
}
|
||||
KeyCode::Char('g') => {
|
||||
if last_key_was_g {
|
||||
if !app.filtered_items.is_empty() {
|
||||
app.list_state.select(Some(0));
|
||||
KeyCode::Char('j') => {
|
||||
app.next();
|
||||
last_key_was_d = false;
|
||||
}
|
||||
KeyCode::Char('k') => {
|
||||
app.previous();
|
||||
last_key_was_d = false;
|
||||
}
|
||||
KeyCode::Char('d') => {
|
||||
if last_key_was_d {
|
||||
app.delete_selected();
|
||||
last_key_was_d = false;
|
||||
} else {
|
||||
last_key_was_d = true;
|
||||
}
|
||||
last_key_was_g = false;
|
||||
} else {
|
||||
last_key_was_g = true;
|
||||
}
|
||||
last_key_was_d = false;
|
||||
}
|
||||
KeyCode::Char('G') => {
|
||||
if !app.filtered_items.is_empty() {
|
||||
app.list_state.select(Some(app.filtered_items.len() - 1));
|
||||
KeyCode::Char('u') => {
|
||||
app.undo_delete();
|
||||
last_key_was_d = false;
|
||||
}
|
||||
last_key_was_d = false;
|
||||
}
|
||||
KeyCode::Char(':') => {
|
||||
app.mode = Mode::Command;
|
||||
app.input_buffer.clear();
|
||||
last_key_was_d = false;
|
||||
}
|
||||
KeyCode::Char('/') => {
|
||||
app.mode = Mode::Search;
|
||||
app.input_buffer.clear();
|
||||
app.update_search();
|
||||
last_key_was_d = false;
|
||||
}
|
||||
KeyCode::Char('q') => {
|
||||
app.should_quit = true;
|
||||
}
|
||||
_ => {
|
||||
last_key_was_d = false;
|
||||
}
|
||||
},
|
||||
|
||||
Mode::Command => match key.code {
|
||||
KeyCode::Esc => {
|
||||
app.mode = Mode::Normal;
|
||||
app.input_buffer.clear();
|
||||
app.update_search();
|
||||
}
|
||||
KeyCode::Char(c) => app.input_buffer.push(c),
|
||||
KeyCode::Backspace => {
|
||||
app.input_buffer.pop();
|
||||
}
|
||||
KeyCode::Enter => {
|
||||
if app.input_buffer == "q" {
|
||||
KeyCode::Char('g') => {
|
||||
if last_key_was_g {
|
||||
if !app.filtered_items.is_empty() {
|
||||
app.list_state.select(Some(0));
|
||||
}
|
||||
last_key_was_g = false;
|
||||
} else {
|
||||
last_key_was_g = true;
|
||||
}
|
||||
last_key_was_d = false;
|
||||
}
|
||||
KeyCode::Char('G') => {
|
||||
if !app.filtered_items.is_empty() {
|
||||
app.list_state.select(Some(app.filtered_items.len() - 1));
|
||||
}
|
||||
last_key_was_d = false;
|
||||
}
|
||||
KeyCode::Char(':') => {
|
||||
app.mode = Mode::Command;
|
||||
app.input_buffer.clear();
|
||||
last_key_was_d = false;
|
||||
}
|
||||
KeyCode::Char('/') => {
|
||||
app.mode = Mode::Search;
|
||||
app.input_buffer.clear();
|
||||
app.update_search();
|
||||
last_key_was_d = false;
|
||||
}
|
||||
KeyCode::Char('q') => {
|
||||
app.should_quit = true;
|
||||
}
|
||||
app.mode = Mode::Normal;
|
||||
app.input_buffer.clear();
|
||||
app.update_search();
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
_ => {
|
||||
last_key_was_d = false;
|
||||
}
|
||||
},
|
||||
|
||||
Mode::Search => match key.code {
|
||||
// ... ton code de recherche ...
|
||||
KeyCode::Esc | KeyCode::Enter => {
|
||||
app.mode = Mode::Normal;
|
||||
app.input_buffer.clear();
|
||||
app.update_search();
|
||||
}
|
||||
KeyCode::Char(c) => {
|
||||
app.input_buffer.push(c);
|
||||
app.update_search();
|
||||
}
|
||||
KeyCode::Backspace => {
|
||||
app.input_buffer.pop();
|
||||
app.update_search();
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
Mode::Command => match key.code {
|
||||
KeyCode::Esc => {
|
||||
app.mode = Mode::Normal;
|
||||
app.input_buffer.clear();
|
||||
app.update_search();
|
||||
}
|
||||
KeyCode::Char(c) => app.input_buffer.push(c),
|
||||
KeyCode::Backspace => {
|
||||
app.input_buffer.pop();
|
||||
}
|
||||
KeyCode::Enter => {
|
||||
if app.input_buffer == "q" {
|
||||
app.should_quit = true;
|
||||
}
|
||||
app.mode = Mode::Normal;
|
||||
app.input_buffer.clear();
|
||||
app.update_search();
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
|
||||
Mode::Search => match key.code {
|
||||
KeyCode::Esc => {
|
||||
app.mode = Mode::Normal;
|
||||
app.input_buffer.clear();
|
||||
app.update_search();
|
||||
}
|
||||
KeyCode::Enter => {
|
||||
if let Some(selected) = app.get_selected_item() {
|
||||
crate::ipc::set_clipboard(selected.clone());
|
||||
app.should_quit = true;
|
||||
}
|
||||
}
|
||||
KeyCode::Char(c) => {
|
||||
app.input_buffer.push(c);
|
||||
app.update_search();
|
||||
}
|
||||
KeyCode::Backspace => {
|
||||
app.input_buffer.pop();
|
||||
app.update_search();
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
}
|
||||
}
|
||||
} else {
|
||||
app.sync_with_daemon();
|
||||
}
|
||||
|
||||
if app.should_quit {
|
||||
|
||||
Reference in New Issue
Block a user