myreadline

package
v0.12.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 15, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInterrupt = errors.New("KeyboardInterrupt")

ErrInterrupt is returned when the reader is aborted by Ctrl-C. The REPL distinguishes this from EOF so it can print KeyboardInterrupt and continue prompting.

CPython: Parser/myreadline.c:117 return 1 (Interrupt) path

Functions

func Readline

func Readline(stdin io.Reader, stdout io.Writer, prompt string) (string, error)

Readline is the public entry. It dispatches to the installed reader when one is registered and otherwise falls back to StdioReadline. The re-entrancy guard mirrors the _PyOS_ReadlineTState check in PyOS_Readline.

CPython: Parser/myreadline.c:372 PyOS_Readline

func SetReader

func SetReader(r Reader)

SetReader installs r as the line reader. Pass nil to fall back to StdioReadline. Mirrors the readline module's startup wiring of PyOS_ReadlineFunctionPointer.

CPython: Modules/readline.c PyInit_readline (sets the pointer)

func StdioReadline

func StdioReadline(stdin io.Reader, stdout io.Writer, prompt string) (string, error)

StdioReadline is the unedited reader: write the prompt and pull one line off stdin. The returned line keeps its trailing '\n' (or is shorter on EOF). Matches PyOS_StdioReadline's contract: a blank return on a clean EOF means "no more input".

CPython: Parser/myreadline.c:262 PyOS_StdioReadline

Types

type Reader

type Reader func(stdin io.Reader, stdout io.Writer, prompt string) (string, error)

Reader is the signature an alternative line reader must satisfy. stdin / stdout pair the streams CPython hands to PyOS_ReadlineFunctionPointer; prompt is the PS1 / PS2 string the reader should display before reading input. The returned line includes the trailing '\n' (or is empty at EOF, matching PyOS_StdioReadline). io.EOF on a clean EOF, ErrInterrupt on Ctrl-C.

CPython: Parser/myreadline.c:366 PyOS_ReadlineFunctionPointer

func CurrentReader

func CurrentReader() Reader

CurrentReader returns the installed reader (or nil if none). Mainly useful for tests that want to swap and restore.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL