bhcli

"Strange's fork of n0tr1v's bhcli (onion)"
git clone https://git.dasho.dev/Strange/bhcli.git
Log | Files | Refs | README

commit 478509cc692c49fdd391d6c64a98f7d0289abf67
parent 201d6c89e5faf95efaecd7b30fa3de3711e88ce8
Author: Strange <StrangeGuy6228@protonmail.com>
Date:   Tue, 12 Dec 2023 22:56:04 +0530

added Shortcut 'gg' to jump back to top message, updated readme.md accordingly

Diffstat:
MREADME.md | 1+
Msrc/main.rs | 21++++++++++++++++++++-
Msrc/util/mod.rs | 7+++++++
3 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md @@ -45,6 +45,7 @@ Pre-buit binaries can be found on the [official website](http://dkforestseeaaq2d - Page up the messages list `ctrl+U` | `page up` - Going down 1 message `j` | `down arrow` - Going up 1 message `k` | `up arrow` +- Jump to Top Message `gg` ## Build from source diff --git a/src/main.rs b/src/main.rs @@ -217,6 +217,7 @@ struct LeChatPHPClient { client: Client, session: Option<String>, config: LeChatPHPConfig, + last_key_event: Option<KeyCode>, manual_captcha: bool, refresh_rate: u64, max_login_retry: isize, @@ -642,11 +643,28 @@ impl LeChatPHPClient { KeyEvent { code: KeyCode::PageDown, modifiers: KeyModifiers::NONE, .. } => self.handle_normal_mode_key_event_page_down(app), KeyEvent { code: KeyCode::Esc, modifiers: KeyModifiers::NONE, .. } => self.handle_normal_mode_key_event_esc(app), KeyEvent { code: KeyCode::Char('u'), modifiers: KeyModifiers::SHIFT, .. } => self.handle_normal_mode_key_event_shift_u(app), + KeyEvent { code: KeyCode::Char('g'), modifiers: KeyModifiers::NONE, .. } => { + // Handle "gg" key combination + if self.last_key_event.map_or(false, |last_event| last_event == KeyCode::Char('g')) { + self.handle_gg_key_combination(app); + } else { + // Store the current key event for future comparison + self.last_key_event = Some(KeyCode::Char('g')); + } + } + _ => {} } Ok(()) } + fn handle_gg_key_combination(&mut self, app: &mut App) { + app.items.select_top(); + //println!("Handling 'gg' key combination"); + // Reset the stored key event + self.last_key_event = None; + } + fn handle_editing_mode_key_event(&mut self, app: &mut App, key_event: KeyEvent, users: &Arc<Mutex<Users>>) -> Result<(), ExitSignal> { app.input_mode = InputMode::Editing; match key_event { @@ -697,7 +715,7 @@ impl LeChatPHPClient { fn handle_normal_mode_key_event_down(&mut self, app: &mut App) { app.items.next() } - + fn handle_normal_mode_key_event_slash(&mut self, app: &mut App) { app.items.unselect(); app.input = "/".to_owned(); @@ -1669,6 +1687,7 @@ fn new_default_le_chat_php_client(params: Params) -> LeChatPHPClient { max_login_retry: params.max_login_retry, guest_color: params.guest_color, session: None, + last_key_event: None, client: params.client, manual_captcha: params.manual_captcha, refresh_rate: params.refresh_rate, diff --git a/src/util/mod.rs b/src/util/mod.rs @@ -52,4 +52,11 @@ impl<T> StatefulList<T> { pub fn unselect(&mut self) { self.state.select(None); } + + pub fn select_top(&mut self) { + if self.items.is_empty() { + return; + } + self.state.select(Some(0)); + } }