(cherry picked from commit 0c5151bc81)
Co-authored-by: Sergey Miryanov <sergey.miryanov@gmail.com>
Co-authored-by: Tomas R. <tomas.roun8@gmail.com>
Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com>
(cherry picked from commit 07f416a3f0)
Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
To support virtual terminal mode in Windows PYREPL, we need a scanner
to read over the supported escaped VT sequences.
Windows REPL input was using virtual key mode, which does not support
terminal escape sequences. This patch calls `SetConsoleMode` properly
when initializing and send sequences to enable bracketed-paste modes
to support verbatim copy-and-paste.
(cherry picked from commit a65366ed87)
Co-authored-by: Y5 <124019959+y5c4l3@users.noreply.github.com>
Signed-off-by: y5c4l3 <y5c4l3@proton.me>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Co-authored-by: Dustin L. Howett <dustin@howett.net>
Co-authored-by: wheeheee <104880306+wheeheee@users.noreply.github.com>
gh-129098: avoid using content of `_pyrepl/__main__.py` when reporting tracebacks (GH-130721)
(cherry picked from commit 492e3e6976)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
gh-128231: Use `runcode()` return value for failing early (GH-129488)
(cherry picked from commit 7ed3dc6392)
Co-authored-by: Bartosz Sławecki <bartoszpiotrslawecki@gmail.com>
gh-131507: Refactor screen and cursor position calculations (GH-131547)
This is based off GH-131509.
(cherry picked from commit 4cc82ffa37)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
gh-117174: Add a new route in linecache to fetch interactive source code (GH-117500)
(cherry picked from commit a931a8b324)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
gh-124927: Fix conversion issue between coordinates and position in REPL (GH-125001)
(cherry picked from commit 6ab5c4aa05)
Co-authored-by: FeH2 <i@feh2.im>
gh-128388: pyrepl on Windows: add meta and ctrl+arrow keybindings (GH-128389)
Fix `Lib/_pyrepl/windows_console.py` to support more keybindings, like the
`Ctrl`+`←` and `Ctrl`+`→` word-skipping keybindings and those with meta (i.e. Alt),
e.g. to `kill-word` or `backward-kill-word`.
Specifics: if Ctrl is pressed, emit "ctrl left" and "ctrl right" instead of just "left" or
"right," and if Meta/Alt is pressed, emit the special key code for meta before
emitting the other key that was pressed.
(cherry picked from commit 688f3a0d4b)
Co-authored-by: Paulie Peña <203125+paulie4@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
gh-118878: Pyrepl: show completions menu below the current line (GH-118939)
(cherry picked from commit 29caec62ee)
Co-authored-by: Daniel Hollas <daniel.hollas@bristol.ac.uk>
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
gh-128330: Terminal control characters should be restored on repl exit (GH-128331)
(cherry picked from commit 0b15d9c0d2)
Co-authored-by: Andy Fiddaman <andy@omnios.org>
gh-128636: Fix crash in PyREPL when `os.environ` is overwritten with an invalid value (GH-128653)
(cherry picked from commit ba9a4b6215)
Co-authored-by: Tomas R <tomas.roun8@gmail.com>
gh-122273: Support PyREPL history on Windows (#127141)
Co-authored-by: devdanzin <74280297+devdanzin@users.noreply.github.com>
(cherry picked from commit 3c7a90a831)
gh-124960: Fixed `barry_as_FLUFL` future flag does not work in new REPL (#124999)
Co-authored-by: Wulian <xiguawulian@gmail.com>
Co-authored-by: Nice Zombies <nineteendo19d0@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit 6a08a753b7)
Support the "pager" binary in _pyrepl (GH-122878)
Debian (and derivatives) provide a /usr/bin/pager binary, managed by the
alternatives system, that always points to an available pager utility.
Allow _pyrepl to use it, to follow system policy.
This is a very trivial change, from a patch that Debian has been
carrying since 2.7 era. Seems appropriate to upstream.
https://bugs.debian.org/799555
(cherry picked from commit 426569eb8c)
Co-authored-by: Stefano Rivera <stefano@rivera.za.net>
Co-authored-by: T. Wouters <thomas@python.org>
gh-124628: Pyrepl inputs on Windows shouldn't always be blocking reads (GH-124629)
(cherry picked from commit 83e5dc0f4d)
Co-authored-by: Dino Viehland <dinoviehland@meta.com>
gh-123856: Fix PyREPL failure when a keyboard interrupt is triggered after using a history search (GH-124396)
(cherry picked from commit c1600c78e4)
Co-authored-by: Emily Morehouse <emily@cuttlesoft.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
gh-124027: Support Del, PgUp, and PgDn on TERM=vt100 (GH-124028)
pyrepl: Support Del, PgUp, and PgDn on TERM=vt100
From Fedora's /etc/inputrc:
"\e[5~": history-search-backward
"\e[6~": history-search-forward
"\e[3~": delete-char
Fixes https://github.com/python/cpython/issues/124027
(cherry picked from commit f4e5643df6)
Co-authored-by: Miro Hrončok <miro@hroncok.cz>
This switches the main pyrepl event loop to always be non-blocking so that it
can listen to incoming interruptions from other threads.
This also resolves invalid display of exceptions from other threads
(gh-123178).
This also fixes freezes with pasting and an active input hook.
(cherry picked from commit 033510e11d)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Change <page up> and <page down> keys of the Python REPL to history
search forward/backward.
(cherry picked from commit 8311b11800)
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
gh-123177: Fix prompt for wrapped lines in pyrepl (GH-123324)
When display lines above the cursor come from the cache, the first line
to not come from the cache may be a wrapped line, starting half way
through a logical line in the buffer. Detect and handle this case to
avoid accidentally drawing a stray prompt in the middle of a logical
line.
(cherry picked from commit 602fcf97df)
Co-authored-by: Matt Wozniski <mwozniski@bloomberg.net>
gh-123177: Deactivate line wrap for Apple Terminal via scape codes in the new REPL (GH-123267)
(cherry picked from commit fdb3f9b588)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
gh-123228: fix return type for _ReadlineWrapper.get_line_buffer() (GH-123281)
(cherry picked from commit ca18ff2a34)
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Co-authored-by: Carl Friedrich Bolz-Tereick <cfbolz@gmx.de>
Make sure that pyrepl uses the same logic for sys.tracebacklimit as both
the basic repl and the standard sys.excepthook
(cherry picked from commit 63603bca35)
gh-119896: Fix CTRL-Z behavior in the new REPL on Windows (GH-122217)
(cherry picked from commit d1a1bca1f0)
Co-authored-by: Dino Viehland <dinoviehland@meta.com>
Relatedly, emit the `cpython.run_startup` event from the Python version of
`PYTHONSTARTUP` handling.
(cherry picked from commit dc93d1125f)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
console.compile with the "single" param throws an exception when
there are multiple statements, never allowing to adding newlines
to a pasted code block (gh-121610)
This adds a few extra checks to allow extending when in an indented
block, and tests for a few examples.
(cherry picked from commit 7d111dac16)
Co-authored-by: saucoide <32314353+saucoide@users.noreply.github.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>