Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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 ¶
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.