Skip to content

Commit

Permalink
Add standard pagination keys to fix #3, bump version to 1.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Vonr committed Feb 13, 2023
1 parent 62e9f45 commit 2231211
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 94 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "parui"
description = "Simple TUI frontend for paru or yay."
version = "1.0.4"
version = "1.0.5"
edition = "2021"
license = "MIT"
readme = "README.md"
Expand Down
121 changes: 29 additions & 92 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ async fn main() -> Result<(), io::Error> {
_ => redraw.store(true, Ordering::SeqCst),
},
Mode::Select => match k.code {
KeyCode::Up => {
KeyCode::Up | KeyCode::Char('k') => {
if k.modifiers == KeyModifiers::CONTROL {
if info_scroll > 0 {
info_scroll -= 1;
Expand All @@ -464,7 +464,7 @@ async fn main() -> Result<(), io::Error> {
redraw.store(true, Ordering::SeqCst);
}
}
KeyCode::Down => {
KeyCode::Down | KeyCode::Char('j') => {
if k.modifiers == KeyModifiers::CONTROL {
if !info.lock().is_empty() {
info_scroll += 1;
Expand All @@ -481,7 +481,12 @@ async fn main() -> Result<(), io::Error> {
redraw.store(true, Ordering::SeqCst);
}
}
KeyCode::Left => {
KeyCode::Esc => {
insert_pos = query.len() as u16;
redraw.store(true, Ordering::SeqCst);
mode.store(Mode::Insert, Ordering::SeqCst);
}
KeyCode::Left | KeyCode::PageUp | KeyCode::Char('h') => {
let shown_count = shown.read().len();
if shown_count > per_page {
if current >= per_page {
Expand All @@ -493,7 +498,7 @@ async fn main() -> Result<(), io::Error> {
redraw.store(true, Ordering::SeqCst);
}
}
KeyCode::Right => {
KeyCode::Right | KeyCode::PageDown | KeyCode::Char('l') => {
let shown = shown.read();
if shown.len() > per_page {
if current == shown.len() - 1 {
Expand All @@ -507,71 +512,17 @@ async fn main() -> Result<(), io::Error> {
redraw.store(true, Ordering::SeqCst);
}
}
KeyCode::Esc => {
insert_pos = query.len() as u16;
KeyCode::Home | KeyCode::Char('g') if current != 0 => {
info.lock().clear();
current = 0;
redraw.store(true, Ordering::SeqCst);
}
KeyCode::End | KeyCode::Char('G') if current != shown.read().len() - 1 => {
info.lock().clear();
current = shown.read().len() - 1;
redraw.store(true, Ordering::SeqCst);
mode.store(Mode::Insert, Ordering::SeqCst);
}
KeyCode::Char(c) => match c {
'j' => {
if k.modifiers == KeyModifiers::CONTROL {
if !info.lock().is_empty() {
info_scroll += 1;
redraw.store(true, Ordering::SeqCst);
}
} else {
let result_count = shown.read().len();
if result_count > 1 && current < result_count - 1 {
current += 1;
} else {
current = 0;
}
info.lock().clear();
redraw.store(true, Ordering::SeqCst);
}
}
'k' => {
if k.modifiers == KeyModifiers::CONTROL {
if info_scroll > 0 {
info_scroll -= 1;
redraw.store(true, Ordering::SeqCst);
}
} else {
if current > 0 {
current -= 1;
} else {
current = shown.read().len() - 1;
}
info.lock().clear();
redraw.store(true, Ordering::SeqCst);
}
}
'h' => {
let shown_count = shown.read().len();
if shown_count > per_page {
if current >= per_page {
current -= per_page;
} else {
current = shown_count - 1;
}
info.lock().clear();
redraw.store(true, Ordering::SeqCst);
}
}
'l' => {
let shown = shown.read();
if shown.len() > per_page {
if current == shown.len() - 1 {
current = 0;
} else if current + per_page > shown.len() - 1 {
current = shown.len() - 1;
} else {
current += per_page;
}
info.lock().clear();
redraw.store(true, Ordering::SeqCst);
}
}
' ' => {
let real_current = shown.read()[current];
if selected.contains(&real_current) {
Expand All @@ -581,6 +532,11 @@ async fn main() -> Result<(), io::Error> {
}
redraw.store(true, Ordering::SeqCst);
}
'i' | '/' => {
insert_pos = query.len() as u16;
redraw.store(true, Ordering::SeqCst);
mode.store(Mode::Insert, Ordering::SeqCst);
}
'q' => {
disable_raw_mode()?;
let mut terminal = terminal.lock();
Expand All @@ -590,33 +546,14 @@ async fn main() -> Result<(), io::Error> {

return Ok(());
}
'i' | '/' => {
insert_pos = query.len() as u16;
redraw.store(true, Ordering::SeqCst);
mode.store(Mode::Insert, Ordering::SeqCst);
}
'c' => {
if k.modifiers == KeyModifiers::CONTROL {
disable_raw_mode()?;
let mut terminal = terminal.lock();
execute!(terminal.backend_mut(), LeaveAlternateScreen)?;
terminal.clear()?;
terminal.set_cursor(0, 0)?;
'c' if k.modifiers.contains(KeyModifiers::CONTROL) => {
disable_raw_mode()?;
let mut terminal = terminal.lock();
execute!(terminal.backend_mut(), LeaveAlternateScreen)?;
terminal.clear()?;
terminal.set_cursor(0, 0)?;

return Ok(());
}
selected.clear();
redraw.store(true, Ordering::SeqCst);
}
'g' if current != 0 => {
info.lock().clear();
current = 0;
redraw.store(true, Ordering::SeqCst);
}
'G' if current != shown.read().len() - 1 => {
info.lock().clear();
current = shown.read().len() - 1;
redraw.store(true, Ordering::SeqCst);
return Ok(());
}
'R' => {
if installed.read().contains(&current) {
Expand Down

0 comments on commit 2231211

Please sign in to comment.