Skip to content

Replace native GNU readline with JLine (#5)#134

Open
cansin wants to merge 3 commits into
useocl:mainfrom
cansin:claude/relaxed-brown-hpdcid
Open

Replace native GNU readline with JLine (#5)#134
cansin wants to merge 3 commits into
useocl:mainfrom
cansin:claude/relaxed-brown-hpdcid

Conversation

@cansin

@cansin cansin commented Jun 9, 2026

Copy link
Copy Markdown

Replace native GNU readline with JLine

Closes #5.

Motivation

USE's interactive command line relied on the native Unix GNU readline
library via a JNI binding (GNUReadline + natGNUReadline.c). This required a
platform-dependent native compilation step as part of the build and was
effectively unavailable on Windows, so most users silently fell back to a bare
input stream with no line editing or history.

This PR replaces that with the pure-Java JLine
library — which was already declared as a dependency but never wired up —
giving line editing and a persistent command history on Linux, macOS and
Windows
with no native build steps.

What changed

  • New JLineReadline — a Readline implementation backed by JLine's
    ConsoleReader with a FileHistory. History expansion is disabled so the
    SOIL ! / !! commands are passed through verbatim.
  • LineInput.getUserInputReadline() now returns the JLine implementation
    for interactive terminals and falls back to the existing StreamReadline
    when no console is available (piped/headless), preserving current
    non-interactive behaviour.
  • Removed the JNI GNUReadline class and the natGNUReadline.c native
    source, and the System.loadLibrary call; declared the jline module in
    module-info.
  • Dropped the obsolete "GNU readline not available" warning from the shell.
    The -nr command-line switch is kept as an accepted no-op for backward
    compatibility (it is still passed by the Windows launcher and the integration
    tests, and unknown flags abort startup).
  • Docs & scripts: updated INSTALL, README, and NEWS; removed the
    native-only LD_LIBRARY_PATH from bin/use and the now-obsolete -nr from
    bin/start_use.bat.

Behaviour & compatibility

  • Interactive terminals gain bash/emacs-style line editing and history
    (~/.use_history) on all platforms.
  • Non-interactive/piped input is unchanged (StreamReadline).
  • No native toolchain is required to build USE anymore.
  • No new dependency is introduced — jline:jline:2.14.6 was already on the
    classpath.

Testing

Developed test-first (red → green) with a regression safety net:

  1. Added characterization tests for the existing StreamReadline / LineInput
    behaviour and confirmed they pass against the current implementation.
  2. Added JLineReadlineTest and a LineInput factory test for the new
    behaviour (red before the change).
  3. Implemented the migration; all of the above pass (green).

Verified locally:

  • use-core unit tests: green
  • use-gui unit tests: green
  • ShellIT end-to-end shell integration suite: 129 tests, 0 failures
    (exercises real command files in-process and confirms -nr still works)

claude added 3 commits June 9, 2026 03:22
Pin down the existing behaviour of the StreamReadline fallback and the
stable LineInput.getStreamReadline factory before migrating the
interactive input from the native GNU readline library to JLine.

These tests pass against the current implementation and act as a
regression safety net for the upcoming change.

https://claude.ai/code/session_01Dve366yx4bjiFecJpbsZ7q
Resolves useocl#5.

USE's interactive command line previously relied on the native Unix
GNU readline library through a JNI binding (GNUReadline + natGNUReadline.c),
which required a platform-dependent native build step and was effectively
unavailable on Windows. Replace it with the pure-Java JLine library
(already a declared dependency), giving line editing and a persistent
command history on Linux, macOS and Windows with no native build steps.

- Add JLineReadline, a Readline implementation backed by JLine's
  ConsoleReader with a FileHistory. History expansion is disabled so the
  SOIL '!' / '!!' commands are passed through verbatim.
- LineInput.getUserInputReadline() now returns the JLine implementation
  for interactive terminals and falls back to the existing StreamReadline
  when no console is available (piped/headless), preserving current
  non-interactive behaviour.
- Remove the JNI GNUReadline class and the natGNUReadline.c native source;
  declare the jline module in module-info.
- Drop the obsolete "GNU readline not available" warning from the shell.
  The -nr command line switch is kept as an accepted no-op for backward
  compatibility (it is still passed by the Windows launcher and tests).
- Cover the new behaviour with JLineReadlineTest and an additional
  LineInput test; the StreamReadline safety net continues to pass.

https://claude.ai/code/session_01Dve366yx4bjiFecJpbsZ7q
Reflect the move from the native GNU readline library to the pure-Java
JLine library:

- INSTALL: describe JLine-based line editing/history; no native build step.
- README: list JLine among the bundled third-party libraries.
- NEWS: add an entry for the readline -> JLine change.
- bin/use: drop LD_LIBRARY_PATH, which only existed for the native
  readline library.
- bin/start_use.bat: drop the now-obsolete -nr switch (the missing
  readline warning it suppressed no longer exists).
- .gitignore: ignore the .claude directory.

https://claude.ai/code/session_01Dve366yx4bjiFecJpbsZ7q
@cansin cansin changed the title Claude/relaxed brown hpdcid Replace native GNU readline with JLine (resolves #5) Jun 9, 2026
@ichxorya

ichxorya commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Very nice, I would love to review this asap. I also found this problem while working on my PR, which I hadn't fixed due to not relevant to the PR itself.

@cansin cansin changed the title Replace native GNU readline with JLine (resolves #5) Replace native GNU readline with JLine (#5) Jun 9, 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.

Replace readline with native Java shell library

3 participants