Skip to content

Adds attempt at activating GNU readline for input()#61

Draft
dbosk wants to merge 2 commits intomasterfrom
readline
Draft

Adds attempt at activating GNU readline for input()#61
dbosk wants to merge 2 commits intomasterfrom
readline

Conversation

@dbosk
Copy link
Copy Markdown
Owner

@dbosk dbosk commented May 14, 2025

This does not work.

@dbosk dbosk linked an issue May 14, 2025 that may be closed by this pull request
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR attempts to enhance the user experience of interactive input prompts by importing Python's readline module, which provides line editing and command history capabilities. However, as noted in the PR description, the implementation doesn't work as intended. The change adds documentation explaining the intent and imports the readline module in the noweb literate programming structure.

Key changes:

  • Adds documentation explaining the intent to use GNU readline for improved input usability
  • Imports the readline module via a <<imports>>= code chunk

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread examgen.nw
For the above input methods, we want improved usability, so we will use the GNU
readline version of input.
<<imports>>=
import readline
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

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

The readline import should be wrapped in a try-except block to handle platforms where it's not available (e.g., Windows). The module will fail to import on systems without GNU readline support.

Suggested fix:

try:
    import readline
except ImportError:
    pass  # readline not available, input() will work without enhanced features

This approach is the standard Python pattern for optional readline support.

Suggested change
import readline
try:
import readline
except ImportError:
pass # readline not available, input() will work without enhanced features

Copilot uses AI. Check for mistakes.
Comment thread examgen.nw
Comment on lines +1005 to +1006
For the above input methods, we want improved usability, so we will use the GNU
readline version of input.
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

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

The documentation is misleading. Python's readline module doesn't provide a separate "readline version of input" - it automatically enhances the built-in input() function when imported. The comment should clarify this behavior.

Suggested rewording:

For the above input methods, we want improved usability. By importing the
readline module, the built-in input() function is automatically enhanced with
line editing capabilities and command history (when available).
Suggested change
For the above input methods, we want improved usability, so we will use the GNU
readline version of input.
For the above input methods, we want improved usability. By importing the
readline module, the built-in input() function is automatically enhanced with
line editing capabilities and command history (when available).

Copilot uses AI. Check for mistakes.
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.

Finalize (GNU) readline use

2 participants