Skip to content

ggfix: no need to have the escape there in the time and some listhers change#20

Merged
vimlinuz merged 7 commits intomainfrom
handle_deletion
Dec 29, 2025
Merged

ggfix: no need to have the escape there in the time and some listhers change#20
vimlinuz merged 7 commits intomainfrom
handle_deletion

Conversation

@vimlinuz
Copy link
Copy Markdown
Owner

@vimlinuz vimlinuz commented Dec 29, 2025

Summary by CodeRabbit

  • New Features

    • New keyboard shortcuts: 'q' to close popups/menus, Ctrl+C to exit, 'd' to trigger delete confirmation, 'h'/'?' to open help, and '(s)' to view saved networks.
    • Improved delete flow: confirmation cancels/accepts correctly, deletes from the appropriate list, closes the dialog and rescans networks.
  • Bug Fixes

    • Fixed timestamp parsing for saved connections.
  • Documentation

    • Help menu text updated for clarity.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Dec 29, 2025

📝 Walkthrough

Walkthrough

Adds and standardizes keyboard shortcuts across UI popups (Ctrl+C to exit, 'q' to close/cancel, 'd' to delete, 'h'/'?' for help), extends delete logic to handle saved vs scanned networks, tweaks saved-timestamp parsing, updates help text, and reorders popup input priority to ensure delete confirmation is handled first.

Changes

Cohort / File(s) Summary
Input & Delete Handling
src/apps/core/delete_handler.rs, src/apps/core/saved_connection.rs, src/apps/handlers/status.rs, src/apps/core/help_handlers.rs
Expanded input event match arms: added Ctrl+C (exit), q (close/cancel), d (show delete confirmation), h/? (show help). Status popup now also closes on q. Delete logic now removes SSID from saved list when show_saved is true, otherwise from scanned wifi list; then hides confirmation and rescans.
Popup Priority / Main Loop
src/apps/core/run.rs
Reordered popup handling so delete confirmation is checked before saved-popup; removed duplicate check and added comments clarifying top-popup precedence.
Saved Connections Parsing
src/apps/core/saved_connection.rs
Strip backslashes when collecting last_used timestamps in fetch_saved_connections.
Help Menu Text
src/apps/core/widget.rs
Updated displayed help text: changed "(?) toggle this help menu" to "(?) help" and added "(s) view saved networks" (HELP_TEST length increased).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Saved connection #18 — Related prior changes to saved_connection handling and popup priority that overlap with this PR's input and popup reordering modifications.

Poem

🐰
I nibble keys and tap the sky,
'q' hops close, Ctrl+C says goodbye,
'd' digs out networks tucked away,
'?' and 'h' show help today,
Popups tidy, all in play.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The title is vague and unclear. It uses non-descriptive phrasing like 'ggfix' and 'some listhers change' without clearly conveying what the main changes are. Revise the title to clearly describe the main objective, such as 'Add missing keyboard shortcuts (Ctrl+C and q) to popup handlers' or 'Add consistent exit and close keybindings across UI popups'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch handle_deletion

Comment @coderabbitai help to get the list of available commands and usage tips.

@vimlinuz
Copy link
Copy Markdown
Owner Author

vimlinuz commented Dec 29, 2025

@coderabbitai are there any missing listhers

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Dec 29, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Get the PR diff to see what changes were made
gh pr diff 20

# Search for listener-related code in the codebase
echo "=== Searching for listener patterns ==="
rg -n -C3 "listener|addEventListener|on\(|emit" --type=js --type=ts

# Search for event handling patterns
echo "=== Searching for event handling ==="
rg -n -C3 "\.on\(|\.off\(|\.once\(" --type=js --type=ts

# List all JavaScript/TypeScript files to understand the codebase structure
echo "=== JavaScript/TypeScript files ==="
fd -e js -e ts -e jsx -e tsx

Length of output: 8183


🏁 Script executed:

#!/bin/bash
# Search for event handling patterns in Rust files
echo "=== All Rust files in apps/core ==="
fd -e rs . src/apps/core

echo -e "\n=== Event::Key patterns in the codebase ==="
rg -n "Event::Key" --type=rust -C2

echo -e "\n=== All event handler functions ==="
rg -n "pub fn handle_|fn handle_" --type=rust -A5

echo -e "\n=== Main event loop and dispatch ==="
rg -n "else if self\.|if self\.show_|KeyCode::Char" --type=rust src/apps/core/run.rs src/apps/mod.rs

echo -e "\n=== Check for wifi_credentials handler ==="
rg -n "wifi_credentials.*handle" --type=rust

echo -e "\n=== Check main app handler ==="
cat src/apps/core/app_handler.rs 2>/dev/null || echo "app_handler.rs not found"
fd "handler" -e rs . src/apps/core

Length of output: 23307


@santoshxshrestha Yes, there are missing listeners in some of the popup handlers!

Based on the PR changes, you've added Ctrl+C (force quit) and q (close/quit) key handlers to several popups for consistency. However, three popup handlers are still missing these new keybindings:

Missing Listeners:

1. src/apps/handlers/ssid_handler.rs (SSID input popup)

Missing:

  • Ctrl+C to force quit the application
  • q to close the popup
  • Currently only has Esc to close

2. src/apps/handlers/password_handler.rs (Password input popup)

Missing:

  • Ctrl+C to force quit the application
  • q to close the popup
  • Currently only has Esc to close

3. src/apps/handlers/status.rs (Status message popup)

Missing:

  • Ctrl+C to force quit the application
  • q to close the popup
  • Currently only has Esc and Enter to close

Impact:

This creates an inconsistent user experience where:

  • ✅ Help, delete confirmation, and saved connections popups: Support both q and Ctrl+C
  • ❌ SSID input, password input, and status popups: Only support Esc

Recommendation:

Add the missing Ctrl+C and q handlers to these three files to maintain consistency across all popups, following the same pattern you used in the other handlers updated in this PR.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/apps/core/widget.rs (1)

22-34: Consider consolidating duplicate help entries and fixing the constant name typo.

Two observations:

  1. Lines 31-32 both show help shortcuts but as separate entries. Consider merging them: "(h|?) help".
  2. The constant is named HELP_TEST — likely a typo for HELP_TEXT.
🔎 Proposed fix
-const HELP_TEST: [&str; 11] = [
+const HELP_TEXT: [&str; 10] = [
     "[Esc] quit",
     "(Ctrl+c) force quit",
     "(Ctrl+R) scan for networks",
     "(Enter) connect to network",
     "(o) connect to network",
     "(d) delete saved network",
     "(↑|k) move up",
     "(↓|j) move down",
-    "(h) help",
-    "(?) help",
+    "(h|?) help",
     "(s) view saved networks",
 ];

Note: Update the reference on line 163 from HELP_TEST to HELP_TEXT as well.

src/apps/core/saved_connection.rs (1)

123-136: Consider consolidating duplicate match arms for 'h' and '?'.

Both key handlers perform the same action. You can combine them using an OR pattern.

🔎 Proposed fix
-                Event::Key(KeyEvent {
-                    code: event::KeyCode::Char('h'),
-                    kind: event::KeyEventKind::Press,
-                    ..
-                }) => {
-                    self.show_help = true;
-                }
-                Event::Key(KeyEvent {
-                    code: event::KeyCode::Char('?'),
-                    kind: event::KeyEventKind::Press,
-                    ..
-                }) => {
-                    self.show_help = true;
-                }
+                Event::Key(KeyEvent {
+                    code: event::KeyCode::Char('h') | event::KeyCode::Char('?'),
+                    kind: event::KeyEventKind::Press,
+                    ..
+                }) => {
+                    self.show_help = true;
+                }
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3bff34c and 991f540.

📒 Files selected for processing (5)
  • src/apps/core/delete_handler.rs
  • src/apps/core/help_handlers.rs
  • src/apps/core/run.rs
  • src/apps/core/saved_connection.rs
  • src/apps/core/widget.rs
🔇 Additional comments (5)
src/apps/core/help_handlers.rs (1)

25-39: LGTM!

The added shortcuts for 'q' to close help and Ctrl+C to force quit are consistent with the behavior in other popup handlers across the PR.

src/apps/core/run.rs (1)

11-23: LGTM! The popup priority reordering is correct.

The delete confirmation popup now takes precedence over the saved connections popup, which matches the intended layering behavior.

Minor: Typos in comments — "preceeding" → "preceding" (line 12), "becuase" → "because" (line 19).

src/apps/core/saved_connection.rs (2)

45-50: LGTM!

Filtering out backslash characters from the timestamp is a reasonable fix for escaped colons in the nmcli output.


64-93: LGTM!

The new shortcuts ('q' to close, Ctrl+C to exit, 'd' to delete) are consistent with the other popup handlers in this PR.

src/apps/core/delete_handler.rs (1)

49-70: LGTM!

The Ctrl+C and 'q' shortcuts for exiting and canceling the delete confirmation are consistent with the other popup handlers.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Dec 29, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Get the PR diff to see what changes were made
gh pr diff 20

# List files changed in the PR
gh pr view 20 --json files --jq '.files[].path'

Length of output: 7914


🏁 Script executed:

#!/bin/bash
# Find all handler files and the main event handling logic
fd -e rs . src/apps/core/

# Search for event handling patterns in the main app
rg -n "impl App" -A 3 src/apps/core/

# Look for the main event handler (non-popup handler)
ast-grep --pattern 'pub fn handle_$_(&mut self) -> $_'

# Check for any other key event patterns we might have missed
rg -n "KeyCode::" src/apps/core/ -C 2

Length of output: 13941


🏁 Script executed:

#!/bin/bash
# Get the full content of event_handlers.rs to see the main event handler
cat src/apps/core/event_handlers.rs

# Also check if there are any other handler files we might have missed
fd handler src/apps/

Length of output: 3742


🏁 Script executed:

#!/bin/bash
# Check the password and ssid handlers for completeness
cat src/apps/handlers/password_handler.rs
cat src/apps/handlers/ssid_handler.rs

# Also check if there's a parent handlers.rs file
cat src/apps/handlers.rs

Length of output: 5715


@santoshxshrestha Good catch! After analyzing all the event handlers in the codebase, I found that the SSID and password input handlers are missing the Ctrl+C listener.

Here's what I found:

Current Handler Coverage

Handlers WITH Ctrl+C force exit:

  • Main screen (event_handlers.rs)
  • Help popup (help_handlers.rs) - added in this PR
  • Delete confirmation popup (delete_handler.rs) - added in this PR
  • Saved networks popup (saved_connection.rs) - added in this PR

Handlers MISSING Ctrl+C:

  • SSID input popup (ssid_handler.rs)
  • Password input popup (password_handler.rs)

Issue

Currently, when users are in the SSID or password input popups, they cannot use Ctrl+C to force exit the application. They can only press Esc to close the popup, but this is inconsistent with the pattern established in all other handlers.

Suggested Fix

Add Ctrl+C handlers to both input handlers:

For src/apps/handlers/ssid_handler.rs:

Event::Key(KeyEvent {
    code: KeyCode::Char('c'),
    modifiers: KeyModifiers::CONTROL,
    kind: Press,
    ..
}) => {
    // Force exit the application
    // You'll need to pass the app reference or have access to exit()
}

For src/apps/handlers/password_handler.rs:

Event::Key(KeyEvent {
    code: KeyCode::Char('c'),
    modifiers: KeyModifiers::CONTROL,
    kind: Press,
    ..
}) => {
    // Force exit the application
    // You'll need to pass the app reference or have access to exit()
}

Note: The input handlers are implemented on WifiInputState, which doesn't have direct access to the App instance's exit() method. You may need to refactor to either:

  1. Pass a mutable reference to the App to these handlers
  2. Return a signal that indicates the app should exit
  3. Use a shared state pattern

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/apps/handlers/status.rs (1)

44-52: LGTM! 'q' handler added for consistency.

The addition of the 'q' key handler achieves the PR's goal of standardizing close behavior across popups. The logic correctly mirrors the Esc and Enter handlers.

Optional: reduce duplication by extracting common closure

Since Esc, 'q', and Enter all execute identical logic, you could optionally extract a closure to reduce duplication:

 impl WifiInputState {
     pub fn handle_status_message(&mut self) -> io::Result<()> {
         if poll(Duration::from_micros(1))? {
+            let close_status = || {
+                self.flags.show_status_popup = false;
+                self.status.status_message.clear();
+                self.status.status_code = ExitStatus::default();
+            };
+
             match event::read()? {
                 Event::Key(KeyEvent {
                     code: KeyCode::Esc,
                     kind: Press,
                     ..
-                }) => {
-                    self.flags.show_status_popup = false;
-                    self.status.status_message.clear();
-                    self.status.status_code = ExitStatus::default();
-                }
+                }) => close_status(),
                 Event::Key(KeyEvent {
                     code: KeyCode::Char('q'),
                     kind: Press,
                     ..
-                }) => {
-                    self.flags.show_status_popup = false;
-                    self.status.status_message.clear();
-                    self.status.status_code = ExitStatus::default();
-                }
+                }) => close_status(),
                 Event::Key(KeyEvent {
                     code: KeyCode::Enter,
                     kind: Press,
                     ..
-                }) => {
-                    self.flags.show_status_popup = false;
-                    self.status.status_message.clear();
-                    self.status.status_code = ExitStatus::default();
-                }
+                }) => close_status(),
                 _ => {}
             }
         };
         Ok(())
     }
 }

Note: The absence of a Ctrl+C handler is understood given the architectural constraint that WifiInputState does not have direct access to App::exit(), as noted in the PR objectives.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 991f540 and 7c883dd.

📒 Files selected for processing (1)
  • src/apps/handlers/status.rs
🧰 Additional context used
🧬 Code graph analysis (1)
src/apps/handlers/status.rs (1)
src/apps/core.rs (1)
  • default (29-42)

@vimlinuz
Copy link
Copy Markdown
Owner Author

@coderabbitai the share of the app will be heavy again and it will make the condition of the program more worst rn so will not add the ctrl+ c and other one there for the input fields also there will be no help global as it will make the call to polling so will consume more resources or it will be laggy as more polling

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Dec 29, 2025

Tip

For best results, initiate chat on the files or code changes.

@santoshxshrestha Thank you for the clarification! I completely understand your concern about the architectural overhead and performance implications.

You're right that passing the app reference to the input field handlers would add complexity and potentially impact performance, especially with the polling considerations for a global help feature. It makes sense to keep the input handlers lightweight and focused on their core functionality.

The current implementation where input fields only use Esc to close is reasonable given these constraints. The consistency you've achieved across the other popups (help, delete confirmation, saved connections, and main screen) with Ctrl+C and q handlers is a good improvement on its own.


✏️ Learnings added
Learnt from: santoshxshrestha
URL: https://github.com/santoshxshrestha/nmtui/pull/20

Timestamp: 2025-12-29T17:44:05.883Z
Learning: In the santoshxshrestha/nmtui project, input field handlers (SSID and password handlers in src/apps/handlers/ssid_handler.rs and src/apps/handlers/password_handler.rs) intentionally do not include Ctrl+C or global help handlers to avoid the performance overhead of sharing app state and additional polling that would make the program laggy.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

@vimlinuz vimlinuz merged commit 8799201 into main Dec 29, 2025
3 checks passed
@vimlinuz vimlinuz deleted the handle_deletion branch December 29, 2025 17:47
@coderabbitai coderabbitai bot mentioned this pull request Feb 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant