Commit Graph

161 Commits

Author SHA1 Message Date
Jiang Yi
da57784037 Set history size to ${CLING_HISTSIZE}
It was left unset. Then the default hist size was

static_cast<size_t>(-1), which is practically equivalent to unlimited

history size.
2023-01-30 10:29:07 +01:00
ferdymercury
c3dd723262 fix some more warnings in core 2023-01-30 10:29:07 +01:00
Sergey Linev
f4d11176e6 Use nullptr in core/textinput classes 2023-01-30 10:29:07 +01:00
ferdymercury
a78c5a41eb Implement .help edit (show line editor keybindings)
Co-authored-by: Javier Lopez-Gomez <javier.lopez.gomez@cern.ch>
Co-authored-by: Olivier Couet <Olivier.Couet@cern.ch>
2023-01-30 10:29:07 +01:00
Javier Lopez-Gomez
401f877780 Do not assign ESC a special meaning on history search mode
UNIX terminals, e.g. vt100, send escape sequences for many special
key combinations. Entering the history search mode assigned a specific
meaning to the ESC character and disabled the processing of escape
sequences, thus accidentally printing some characters that are part
of a CSI.

As a workaround, avoid changing the meaning of ESC; users can still
use the well-known `ESC ESC` sequence (or any other editor command,
e.g. move left/right) to exit the history search mode.

This change only affects UNIX terminals.

Closes issue #10209.
2023-01-30 10:29:07 +01:00
ferdymercury
0d46b6dead Implement forward history search
Co-authored-by: Javier Lopez-Gomez <javier.lopez.gomez@cern.ch>

Fixes #10137
2023-01-30 10:29:07 +01:00
Javier Lopez-Gomez
07120b98da Clear undo buffer after taking an input line
The undo buffer should only be kept for the current line (as in GNU readline).

Fixes #10182.
2023-01-30 10:29:07 +01:00
ferdymercury
97166bc3b2 prevent accessing empty vector
Fixes https://github.com/root-project/root/issues/10180
2023-01-30 10:29:07 +01:00
Javier Lopez-Gomez
a575990cfc Fix implementation of the kCmdWordTo{Lower,Upper} editor commands
These commands, bound respectively to `ESC l` and `ESC u`, should {lower,upper}case
the next word; however, only the first character was changed.

Fixes #10136.
2023-01-30 10:29:07 +01:00
Javier Lopez-Gomez
01ffa06f0a Add a missing new-line after .q if quitting a ROOT session via Ctrl+D (EOF)
Fixes #10135.
2023-01-30 10:29:07 +01:00
Javier Lopez-Gomez
2dd8debdfb Fix implementation of kCmdSwapThisAndLeftThenMoveRight
This editor command (usually binded to Ctrl+T), transposes the character located
at the cursor and the one to its left.
However, its behavior was incorrect if the cursor was at end of the line,
invoking `std::string::operator[]()` passing an index that is out of bounds.

In that case, as per GNU Readline behavior, it should swap the two last
characters.

Closes #10133.
2023-01-30 10:29:07 +01:00
Javier Lopez-Gomez
3914be144e Bind Ctrl+Del to Editor::kCmdCutNextWord (kill next word)
This change is equivalent to the popular GNU Readline keybinding
```
"\e[3;5~": kill-word
```

As a requirement, the `[3;5~` CSI was added in StreamReaderUnix.cpp. No
additional changes required to StreamReaderWin.cpp.
2023-01-30 10:29:07 +01:00
Javier Lopez-Gomez
3a448596c6 Fix [-Winconsistent-missing-override] warnings on Apple's clang 2023-01-30 10:29:07 +01:00
Javier Lopez-Gomez
d654717749 Clear the terminal screen on Ctrl+L
Fixes #10057.
2023-01-30 10:29:07 +01:00
Javier Lopez-Gomez
106c95fb1b Add Display::Clear(): clear the terminal screen
Writes the `\033[2J\033[H` sequence to clear the visible part of the screen.
For Windows, this requires to temporarily enable processing of VT control
sequences.
2023-01-30 10:29:07 +01:00
Javier Lopez-Gomez
d077fb1048 Enable Xterm-like movement between words, i.e. using Ctrl+{Left,Right}
Enable fast word movement à la Xterm (using Ctrl+Left and Ctrl+Right). Most
users coming from a GUI (GTK+, Win32, etc.) will find this convenient, but also
Archlinux users, given that the default `inputrc` file for GNU Readline providesthese bindings (see https://wiki.archlinux.org/title/Readline#Fast_word_movement).
2023-01-30 10:29:07 +01:00
Sergey Linev
677d59246c Remove unused variable 2023-01-30 10:29:07 +01:00
Sergey Linev
3c40fef28b Modernize core/thread core/textinput includes
Declare non-implmented constructors as delete;
2023-01-30 10:29:07 +01:00
Jiang Yi
90a7639461 Support setting cmd history file by ${CLING_HISTFILE} 2023-01-25 13:59:06 +01:00
Jiang Yi
392d5365d5 Set history size to ${CLING_HISTSIZE}
It was left unset. Then the default hist size was

static_cast<size_t>(-1), which is practically equivalent to unlimited

history size.
2023-01-25 13:59:06 +01:00
Jiang Yi
7c1e968336 Delete UITabCompletion* with unique_ptr 2022-11-19 16:14:05 +01:00
Enrico Guiraud
9969d52ace Do not segfault when root_hist has zero lines
Pressing ctrl-r when no ~/.root_hist file is present or possibly
when it contains 0 lines used to cause a segfault. The culprit
if an out-of-bound access in History::GetLine, as the case in which
the history has zero entries was not taken into account.

With this patch, Histoy::GetLine returns an empty string instead.
This fixes ROOT-10917.

Co-authored-by: Axel Naumann <Axel.Naumann@cern.ch>
2020-08-18 16:09:42 +02:00
Bertrand Bellenot
d0e77739a7 Fix redirection (.> blah.txt) on Windows
Fix output redirection (`.> blah.txt`) which is curently freezing the console input on Windows
When a file (or console) has been created without the `FILE_SHARE_READ | FILE_SHARE_WRITE` flags, there is no way to change this, but by closing it and re-opening it (or a new one) . And I suspect that a standard console doesn't have those flags, so when redirecting the output to a file with `.> blah.txt`, all the output is going to the file, without any echo on the console, and when typing `.>` to suppress the redirection, the file contains this kind of errors:
```
Error 6 in textinput::TerminalDisplayWin attaching to console output: The handle is invalid.

Error 6 in textinput::TerminalDisplayWin attaching / getting console info: The handle is invalid.

Error 6 in textinput::TerminalDisplayWin writing to output: The handle is invalid.
```
This patch solves those issues, even if I'm not sure if it is the root of the problem (it might be something else deep in the `MetaSema::actOnRedirectCommand` function).
NB I don't know if this can have any side effect, but I didn't see any so far...

And for info, one could Enable Console Virtual Terminal Sequences (ANSI escape code) that can control cursor movement, color/font mode, and other operations when written to the output stream by adding the ENABLE_VIRTUAL_TERMINAL_PROCESSING flag, but then it breaks the WRAP_AT_EOL_OUTPUT. With this feature, the escape sequences like `\033[39m` would work in the Windows 10 command prompt as well.
This is a known issue, see https://github.com/microsoft/terminal/issues/349
2020-08-18 16:09:42 +02:00
Philippe Canal
6c1d592420 Fix array index in assignment.
V519 The 'Line[Cursor]' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 352, 353. Editor.cpp 353
2020-08-18 16:09:42 +02:00
Javier Lopez-Gomez
ed3b079e93 Fixes issue ROOT-10285; introduced in 0e90d01afe13c12fafd1002a5bf9fd6f8bc2fbb0.
Defer translation of Ctrl-D to a delete command.

(cherry picked from commit 9d86ce6ae5df200749a70a27956d194a6978e871)
2019-09-27 15:02:15 +02:00
Bertrand Bellenot
8352541d0a Remove the -DUNICODE and -D_UNICODE definitions on Windows
Don't use Unicode in the User Interface (command prompt), it has side effects (the prompt displays empty squares instead of readable characters)
2019-07-22 11:14:11 +02:00
Bertrand Bellenot
a75d9436bc Fix potential issue with Unicode
Fix potential compilation error C2664: 'HANDLE CreateFileW(LPCWSTR,DWORD,DWORD,LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE)': cannot convert argument 1 from 'const char [8]' to 'LPCWSTR' with Unicode/MBCS, as reported here: https://github.com/root-project/cling/issues/186#issuecomment-404902026
2018-11-15 15:39:52 +01:00
Saagar Jha
d57fbe37d5 Handle Control+C and Control+D (mostly) correctly 2018-06-12 08:41:07 +02:00
Saagar Jha
68c93f9743 Fix unfortunate typo 2018-06-12 08:41:03 +02:00
Guilherme Amadio
cbaac95d07 Replace deprecated std::ptr_fun and std::mem_fun with equivalent code
Removed in C++17. No functionality change intended.
2018-06-12 08:40:00 +02:00
Bertrand Bellenot
a561c61888 disable unicode (UTF-8) in the console for the time being, since it causes problems on Windows 10 2018-06-12 08:40:00 +02:00
Raphael Isemann
345a13cef6 Don't assume fileno is a function.
This otherwise leads to compilation errors when we do `::fileno`
as OpenBSD implemented fileno as a macro (which seems to be allowed).
2018-06-12 08:40:00 +02:00
Bertrand Bellenot
ed135557e7 disambiguate the else branch 2018-06-12 08:40:00 +02:00
Bertrand Bellenot
c4990cff45 Fix uninitialized fDefaultAttributes (makes terminal black on black) 2018-06-12 08:40:00 +02:00
Vassil Vassilev
c2a28b097f Remove redundant include. 2018-02-20 13:44:05 +01:00
Frederich Munch
da655d2e8e TextInput: Remove unused method. 2017-09-13 17:16:13 +02:00
Frederich Munch
808cd70864 UserInterface: Enforce destruction order with TextInputHolder. 2017-07-05 10:29:07 +02:00
Frederich Munch
329de59275 Windows: Fix infinite loop when piping to cling with < operator. 2017-07-04 15:36:52 +02:00
Frederich Munch
aad084a75a UserInterface: cling is discarding the last line if it does not have a newline. 2017-07-04 15:29:09 +02:00
Frederich Munch
38c757e36d Have MetaProcessor::process take an llvm::StringRef. Remove unnecessary std::string -> const char* -> std::string conversions. 2017-06-21 11:29:07 +02:00
Frederich Munch
7ab0d2ca97 Remove useless lines. 2017-03-24 13:44:13 +01:00
Frederich Munch
49aacfc5e6 Revert "Must flush stdout, else a "lazy" stdout will not flush before prompt."
This reverts commit bd6cbaf3b6.
2017-02-08 15:37:40 +01:00
Axel Naumann
bd6cbaf3b6 Must flush stdout, else a "lazy" stdout will not flush before prompt.
This situation can happen if stdout is redirected and back. stdout's FILE* has
now changed, and the prompt and stdout end up on different buffers, meaning that
stdout is not flushed before the next prompt.
2017-02-07 15:14:37 +01:00
Frederich Munch
976800d396 Fix return type from read and allow a debugger to be attached on OS X. 2017-02-02 08:20:41 +01:00
Frederich Munch
811840740d Windows: Force console output to UTF-8. 2017-01-18 16:43:26 +01:00
Frederich Munch
f846990f8d Windows: Fix InterpreterException not being caught and terminating. 2016-12-20 12:59:08 +01:00
Frederich Munch
4d41bd315f Make InterpreterException::diagnose virtual and return a boolean. Refactor inheritance chain for InterpreterException. 2016-12-20 12:59:08 +01:00
Axel Naumann
c1e79e499d From Roman Zulak: Flush stdout less (textinput part). 2016-12-19 15:04:23 +01:00
Frederich Munch
075f4ffa83 Add cling output streams to cling/Utils/Output.h 2016-12-19 13:59:11 +01:00
Frederich Munch
e0ddb56b20 Fixes for output redirection.
Decouple redirection state from MetaProcessor and MaybeRedirectOutputRAII.
Only suspend redirection when writing to the prompt.
Allow user to redirect to files named 1, 2, &1, &2.
Allow stderr and stdout to be redirected to one another.
Don't create _IO_2_1_stdout_ file.
2016-12-14 09:29:10 +01:00