Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- Added `Console.enable_readline` method.

### Fixed

- Fixed `readline` support: correct cursor position https://github.com/Textualize/rich/pull/4135

## [15.0.0] - 2026-04-12

### Changed
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ The following people have contributed to the development of Rich:
- [chthollyphile](https://github.com/chthollyphile)
- [Jonathan Helmus](https://github.com/jjhelmus)
- [Brandon Capener](https://github.com/bcapener)
- [Florent Xicluna](https://github.com/florentx)
- [Alex Zheng](https://github.com/alexzheng111)
- [Sebastian Speitel](https://github.com/SebastianSpeitel)
- [Kevin Turcios](https://github.com/KRRT7)
6 changes: 5 additions & 1 deletion docs/source/console.rst
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,11 @@ The console class has an :meth:`~rich.console.Console.input` method which works
console = Console()
console.input("What is [i]your[/i] [bold red]name[/]? :smiley: ")

If Python's builtin :mod:`readline` module is previously loaded, elaborate line editing and history features will be available.
Python's builtin :mod:`readline` module can be loaded, in order to get elaborate line editing and history features::

from rich.console import Console

Console.enable_readline()

Exporting
---------
Expand Down
22 changes: 18 additions & 4 deletions rich/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,14 @@ def _theme_stack(self) -> ThemeStack:
"""Get the thread local theme stack."""
return self._thread_locals.theme_stack

@staticmethod
def enable_readline():
"""Load :mod:`readline` globally, if available."""
try:
import readline
except ImportError:
pass

def _detect_color_system(self) -> Optional[ColorSystem]:
"""Detect color system from env vars."""
if self.is_jupyter:
Expand Down Expand Up @@ -2176,17 +2184,23 @@ def input(
Returns:
str: Text read from stdin.
"""
if prompt:
self.print(prompt, markup=markup, emoji=emoji, end="")
if prompt and not stream and not WINDOWS and self.file == sys.stdout:
with self.capture() as capture:
self.print(prompt, markup=markup, emoji=emoji, end="")
rendered = capture.get()
else:
if prompt:
self.print(prompt, markup=markup, emoji=emoji, end="")
rendered = ""
if password:
import getpass as _getpass_mod

result = _getpass_mod.getpass("", stream=stream)
result = _getpass_mod.getpass(rendered, stream=stream)
else:
if stream:
result = stream.readline()
else:
result = input()
result = input(rendered)
return result

def export_text(self, *, clear: bool = True, styles: bool = False) -> str:
Expand Down