Sudo auto fill password #441
Reference in New Issue
Block a user
Delete Branch "sudo-auto-fill-password"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Overview
Short summary of what this PR does
Changes Made
Sudo Password Auto-Fill Implementation
For this feature, I focused on creating a seamless interaction between the terminal's data stream and the user interface, allowing for quick authentication when sudo prompts appear. Here is a technical breakdown of the changes.
1. Pattern Detection in Terminal Stream
The core logic resides in [Terminal.tsx].
I intercepted the WebSocket
onmessagehandler to inspect incoming data chunks from the server. I implemented a regex pattern match to detect standard sudo prompts (e.g.,[sudo] password for user:).When a match is detected—and provided the feature is enabled in the host configuration—the application pauses standard input processing momentarily to render the [SudoPasswordPopup] component.
This ensures the user sees the prompt immediately when authentication is requested.
2. UI Component and Event Interception
I created a new component, [SudoPasswordPopup.tsx], to handle the user interaction.
The most critical technical challenge here was managing keyboard focus and event propagation.
Since xterm.js aggressively captures keyboard input, I implemented a window-level
keydownevent listener using the capture phase. This allows the popup to interceptEnter(to confirm) andEscape(to dismiss) keys before they bubble down to the terminal instance. I explicitly usede.stopImmediatePropagation()ande.preventDefault()to ensure that confirming the password doesn't accidentally send a newline character to the shell, and dismissing the popup doesn't send an escape code.3. Configuration and Type Definitions
To persist this setting, I updated the data models in [src/types/index.ts].
I added a
sudoPasswordAutoFillboolean property to the [TerminalConfig] interface.I then updated [HostManagerEditor.tsx] to include a toggle switch within the "Advanced terminal settings" tab. This required updating the Zod validation schema to correctly handle the new field during form submission and persistence.
4. Localization
I standardized the translation keys for this feature across all supported languages.
I placed the keys (title, hint, confirm, dismiss) under the
terminalnamespace in the [translation.json].This ensures the feature feels native regardless of the selected interface language.
In the Terminal.tsx file, unfortunately the code ended up indented differently; it might be difficult to spot the differences. I hope that’s not a problem.
Screenshots / Demos
Terminal Settings
Terminal
Checklist
LGTM. Termix has a built in alert system for managing alerts which I will migrate your auto-fill alert to use. Thanks.
Thanks for the approval, actually, sorry if I didn't notice that there was already an ad-hoc component, if you want you can reopen the PR and I can do the migration
No worries, it’s not an issue. I have it taken care of already.