Skip to content

feat: give InputRedirect a command-line interface - #11

Merged
kerogenesis merged 9 commits into
mainfrom
feat/cli-redirect-flags
Jul 30, 2026
Merged

feat: give InputRedirect a command-line interface#11
kerogenesis merged 9 commits into
mainfrom
feat/cli-redirect-flags

Conversation

@kerogenesis

@kerogenesis kerogenesis commented Jul 30, 2026

Copy link
Copy Markdown
Owner

Why

Starting the tool from a shortcut, a scheduled task, or a script had no way to say what you wanted - the only path was the interactive menu, which needs a person at the keyboard. This gives InputRedirect a small command-line interface so the common cases can be named up front.

What

Redirect flags

  • -m, --mouse - start as usual and switch the mouse redirect on
  • -k, --keyboard - start as usual and switch the keyboard redirect on
  • the two combine (order does not matter); with either present the menu is skipped and one green line (the same green the menu uses for an active switch) says what is running:
    • Mouse redirect active
    • Keyboard redirect active
    • Mouse and keyboard redirect active
  • the thread then parks. There is deliberately no exit logic of its own: closing the window or pressing Ctrl+C is delivered to the console control handler exit::watch_for_close already installs, which switches the redirects back and ends the process - the exact same teardown the menu relies on.

Remove the driver

  • -r, --remove-driver - confirms, removes the installed driver package, and offers the restart, then ends.
  • if the package is not installed, it prints InputRedirect: no driver is installed, so there is nothing to remove. and exits without calling Driver::connect, so a removal request can never install the driver it was asked to remove.
  • declining the confirmation prints Nothing was removed directly before the CLI session ends; it is not left waiting for a menu redraw that never happens.
  • the menu key for this is now R (was D), so the key, the flag and the wording ("remove") all line up.

Help

  • -h, --help - prints the usage and exits at once. No "press any key": help is something you typed, not a startup message a double-click user would otherwise miss.

Errors

  • an unrecognised argument is refused with a new Error::Usage and exit code 5, rather than silently opening the menu, so a misspelt flag cannot look like it did nothing.
  • the error points to InputRedirect --help, keeping the guidance complete as options are added.

When more than one thing is asked for, the request that undoes the most wins, so nothing is half-done and then thrown away: --help first, then --remove-driver, then the redirects. With no arguments the behaviour is unchanged: the interactive menu opens as before.

Files

  • src/app/cli.rs (new) - parses the arguments into a Request (Menu, Redirect(Requested), RemoveDriver, Help) and produces the one status line the flag mode prints.
  • src/app/mod.rs - run parses the command line first; --help answers before anything is claimed, --remove-driver checks for an installed package before startup and reports both no-op outcomes directly, and a redirect hands off to run_headless.
  • src/main.rs - usage errors point to --help rather than carrying a partial hard-coded flag list.
  • src/ui/prompt.rs - the remove-driver menu key moves from d to r.
  • src/ui/screen.rs - the menu row shows R.
  • README.md - new Command line section with the usage/options block, and the Quick Start key table now shows R.

Tests

src/app/cli.rs unit tests cover: no arguments (menu), each flag alone (long and short), both redirects together, order independence, a repeated flag, --help and --remove-driver each winning over a redirect alongside them, --help winning over --remove-driver, an unknown argument (alone and after a valid one), and each redirect combination mapping to the right status line. src/ui/prompt.rs tests are updated for the R scan code.

Verification

The Windows CI runs cargo fmt --all --check, cargo clippy --locked --all-targets -- -D warnings, cargo test --locked --all-targets, and cargo build --locked --release; the dependency audit runs separately. No dependencies were added, so Cargo.lock is unchanged.

Starting the tool from a shortcut or a script had no way to switch a
redirect on: the only path was the interactive menu, which needs a
person at the keyboard. This adds --mouse and --keyboard so the redirect
that is wanted can be named up front.

With either flag the program starts as usual, switches on exactly what
was asked for, and prints one green line saying what is running instead
of drawing the menu. Both flags together turn on both. Closing the
window or pressing Ctrl+C still switches everything back and ends the
program, on the same console control handler the menu already relies on,
so the flag mode needs no teardown of its own.

An unrecognised argument is refused with its own message and exit code
rather than silently opening the menu, so a misspelt flag cannot look
like it did nothing.
The first commit rewrote the whole of app/mod.rs and, in doing so,
dropped shut_down, the Default and Drop impls, and rebuilt the dashboard
against driver methods that do not exist. Restore the original file
verbatim and keep only the three intended additions: the cli module, the
command-line branch in run, and run_headless.
Many command-line tools take a short spelling of every long flag and a
--help that lists them, and people reach for both by habit. Without them
-m or -h just fell into the "unknown argument" path, which is a confusing
way to greet someone typing what they expect to work.

-m and -k are now accepted as exact synonyms for --mouse and --keyboard,
and --help / -h prints the list of flags and exits. Help is answered
before the console is prepared, the single-instance lock is taken or the
driver is touched, so it is plain text and costs nothing; it wins over a
redirect given on the same line, since someone reading the flags did not
mean to start one. wait_before_the_window_closes keeps the text on screen
for a double-click launch and returns at once from a shell.

parse now returns a Request enum (Menu / Redirect / Help) rather than a
bare Requested, so "show the menu", "run these redirects" and "print help"
are distinct outcomes the caller matches on instead of inferring.
Help was pausing on "Press any key to close this window", which is menu
behaviour: a command-line tool asked for its usage prints it and returns
at once. The pause only made sense for a startup error a double-click
user would otherwise never see; help is something they typed, so it just
prints and the program leaves.
The line describing what --mouse and --keyboard do to the menu repeated
what the options table already says. Help stays to the point: what the
flags are, and how the program ends.
In flag mode the line naming what is running sat flush against the setup
lines that scrolled past, so the one line worth reading did not stand
out. A blank line before it gives it room, the same way the menu spaces
its blocks.

The --help entry said "show this help and exit"; that a command-line tool
returns after printing its usage is a given, so the entry is just "show
this help".
The driver-removal action was called "remove" everywhere in the code and
the README, but the menu key was D, the odd one out. This settles on
"remove": the menu key is now R, and a matching -r / --remove-driver
flag runs the very same flow from the command line - it confirms, removes
the driver package and offers the restart, then ends.

Help lists the new flag, README gains a Command line section describing
all of them, and the Quick Start key table shows R.
@kerogenesis kerogenesis changed the title feat: run redirects from --mouse and --keyboard without the menu feat: give InputRedirect a command-line interface Jul 30, 2026
@kerogenesis
kerogenesis merged commit 7e4a0cb into main Jul 30, 2026
2 checks passed
@kerogenesis
kerogenesis deleted the feat/cli-redirect-flags branch July 30, 2026 09:44
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