End the mnemonic prompt at end of input (closes #78) #90

Merged
clawbot merged 1 commits from issue-78-prompt-end-of-input into next 2026-10-14 23:35:25 +02:00
Collaborator

Ctrl-D at the mnemonic prompt did nothing: term.ReadPassword reads the terminal with a raw read that returns 0 bytes at the end of input, and takes that as nothing yet. On the Unix systems, readWithoutEcho() in internal/mnemonic/prompt_unix.go now sets the terminal as ReadPassword does (echo off, lines and signals on) and reads the line through os.Stdin, which reports the end of input. Elsewhere, such as Windows, prompt_notunix.go keeps term.ReadPassword. Ctrl-D with nothing typed gives an empty mnemonic, refused with the existing message and status 1. The terminal settings are put back afterwards.

The request numbers for reading and setting the terminal differ by system, so they are in termios_bsd.go and termios_other.go, named and split by system as in golang.org/x/term.

internal/cli/prompt_test.go runs age pub on a pseudo-terminal from github.com/creack/pty (at a commit past v1.1.24, whose Open on Linux can return another pty's terminal), types Ctrl-D at the prompt, and checks the status, the message, and that the terminal settings are restored.

The README's "Giving it the mnemonic" says what Ctrl-D does: once with nothing typed, twice after typed text.

Built with make build for linux, darwin, freebsd, openbsd, netbsd, dragonfly, windows, solaris, illumos, aix, plan9, android and wasip1, as next is; ios and js fail on next too.

  • Judgement call: text typed before Ctrl-D is taken as the mnemonic, as ssh and sudo do.
  • Unverified: the prompt was run only on Linux; the other systems were built, not run.
  • Deviation from ReadPassword: a Ctrl-H byte is no longer a backspace; the terminal's own erase key still works.

Model: opus-5-5

Ctrl-D at the mnemonic prompt did nothing: `term.ReadPassword` reads the terminal with a raw read that returns 0 bytes at the end of input, and takes that as nothing yet. On the Unix systems, `readWithoutEcho()` in `internal/mnemonic/prompt_unix.go` now sets the terminal as `ReadPassword` does (echo off, lines and signals on) and reads the line through `os.Stdin`, which reports the end of input. Elsewhere, such as Windows, `prompt_notunix.go` keeps `term.ReadPassword`. Ctrl-D with nothing typed gives an empty mnemonic, refused with the existing message and status 1. The terminal settings are put back afterwards. The request numbers for reading and setting the terminal differ by system, so they are in `termios_bsd.go` and `termios_other.go`, named and split by system as in `golang.org/x/term`. `internal/cli/prompt_test.go` runs `age pub` on a pseudo-terminal from `github.com/creack/pty` (at a commit past v1.1.24, whose `Open` on Linux can return another pty's terminal), types Ctrl-D at the prompt, and checks the status, the message, and that the terminal settings are restored. The README's "Giving it the mnemonic" says what Ctrl-D does: once with nothing typed, twice after typed text. Built with `make build` for `linux`, `darwin`, `freebsd`, `openbsd`, `netbsd`, `dragonfly`, `windows`, `solaris`, `illumos`, `aix`, `plan9`, `android` and `wasip1`, as `next` is; `ios` and `js` fail on `next` too. - Judgement call: text typed before Ctrl-D is taken as the mnemonic, as `ssh` and `sudo` do. - Unverified: the prompt was run only on Linux; the other systems were built, not run. - Deviation from `ReadPassword`: a Ctrl-H byte is no longer a backspace; the terminal's own erase key still works. Model: opus-5-5
clawbot added the needs-review label 2026-10-14 22:30:17 +02:00
clawbot self-assigned this 2026-10-14 22:30:17 +02:00
Author
Collaborator

Two findings.

  1. The tool no longer builds for Windows, Solaris, illumos or AIX. ask() in internal/mnemonic/mnemonic.go now calls golang.org/x/sys/unix from a file built on every system, and the terminal request numbers exist only in termios_linux.go and termios_bsd.go. next builds for all four systems; this branch fails on each, so the judgement call that Windows was never a target loses a build that worked. Acceptable: it builds wherever next does. For example, use the Linux request numbers for aix, solaris and zos too, as golang.org/x/term's own file does. Put the code in ask() that turns echo off in a file built only for those systems, and keep term.ReadPassword for Windows.

  2. The README overstates Ctrl-D. Item 4 of "Giving it the mnemonic" says the mnemonic is what is typed up to Enter or Ctrl-D. After text has been typed, one Ctrl-D does nothing visible; only a second ends the prompt, because a terminal treats Ctrl-D as the end of input only on an empty line. Acceptable: the README says that Ctrl-D ends the prompt at once when nothing is typed, and has to be pressed twice after typed text.

Model: opus-5-5

Two findings. 1. **The tool no longer builds for Windows, Solaris, illumos or AIX.** `ask()` in `internal/mnemonic/mnemonic.go` now calls `golang.org/x/sys/unix` from a file built on every system, and the terminal request numbers exist only in `termios_linux.go` and `termios_bsd.go`. `next` builds for all four systems; this branch fails on each, so the judgement call that Windows was never a target loses a build that worked. Acceptable: it builds wherever `next` does. For example, use the Linux request numbers for `aix`, `solaris` and `zos` too, as `golang.org/x/term`'s own file does. Put the code in `ask()` that turns echo off in a file built only for those systems, and keep `term.ReadPassword` for Windows. 2. **The README overstates Ctrl-D.** Item 4 of "Giving it the mnemonic" says the mnemonic is what is typed up to Enter or Ctrl-D. After text has been typed, one Ctrl-D does nothing visible; only a second ends the prompt, because a terminal treats Ctrl-D as the end of input only on an empty line. Acceptable: the README says that Ctrl-D ends the prompt at once when nothing is typed, and has to be pressed twice after typed text. Model: opus-5-5
clawbot added needs-rework and removed needs-review labels 2026-10-14 22:48:57 +02:00
clawbot added 1 commit 2026-10-14 23:09:18 +02:00
term.ReadPassword reads the terminal with a raw read that returns 0
bytes at the end of input and takes that as nothing yet, so Ctrl-D at
the prompt did nothing. On the Unix systems the prompt now sets the
terminal as ReadPassword does and reads the line from standard input,
which reports the end of input; elsewhere, such as Windows, it still
uses ReadPassword. Ctrl-D with nothing typed gives an empty mnemonic,
refused with status 1, and the terminal settings are put back.

A test runs the tool on a pseudo-terminal (github.com/creack/pty, at a
commit past v1.1.24, whose Open on Linux can return another pty's
terminal) and types Ctrl-D at the prompt.

Model: opus-5-5
clawbot force-pushed issue-78-prompt-end-of-input from 2d4e0bc335 to d3ca2e0d57 2026-10-14 23:09:18 +02:00 Compare
Author
Collaborator

Rework:

  1. The code that turns echo off moved from ask() into internal/mnemonic/prompt_unix.go, built only for the systems golang.org/x/term handles with Unix terminal settings; termios_linux.go became termios_other.go, which also covers aix, solaris and zos. Every other system, Windows included, keeps term.ReadPassword through prompt_notunix.go. The branch now builds for every system next does.
  2. The README now says Ctrl-D ends the prompt at once when nothing is typed, and has to be pressed twice after typed text.

Rebased onto current next; still one commit.

Model: opus-5-5

Rework: 1. The code that turns echo off moved from `ask()` into `internal/mnemonic/prompt_unix.go`, built only for the systems `golang.org/x/term` handles with Unix terminal settings; `termios_linux.go` became `termios_other.go`, which also covers `aix`, `solaris` and `zos`. Every other system, Windows included, keeps `term.ReadPassword` through `prompt_notunix.go`. The branch now builds for every system `next` does. 2. The README now says Ctrl-D ends the prompt at once when nothing is typed, and has to be pressed twice after typed text. Rebased onto current `next`; still one commit. Model: opus-5-5
clawbot added needs-review and removed needs-rework labels 2026-10-14 23:13:38 +02:00
Author
Collaborator

Review passed: Ctrl-D at the prompt now ends the tool as #78 asks, and both earlier findings are fixed.

Model: opus-5-5

Review passed: Ctrl-D at the prompt now ends the tool as https://git.eeqj.de/sneak/keyfunc/issues/78 asks, and both earlier findings are fixed. Model: opus-5-5
clawbot merged commit a08eb28359 into next 2026-10-14 23:35:25 +02:00
clawbot deleted branch issue-78-prompt-end-of-input 2026-10-14 23:35:26 +02:00
Sign in to join this conversation.