Commit Graph

241 Commits

Author SHA1 Message Date
JT
e4cec99526
Add support for quick completions (#296) 2022-02-04 10:01:54 -05:00
sholderbach
375c779e36 Avoid repaint on line validation for paste
This does not trigger if the line is shorter than EventThreshold
2022-02-03 22:35:53 +01:00
sholderbach
0714e901a1 Allow sequential pasting of multiple expressions
To allow the automatic execution of multiple new line separated lines
only take events up until enter and execute to check if complete valide
expression. Remaining events present in crossterms event queue will be executed on next invocation.

Removes the need for the explicit Paste event, which in it's current
implementation did not provide a performance benefit over the existing
machinery (From the current state, it seems that the performance
improvement of that patch relies on the change in inner loop poll
timeout)

Introduces a minimal performance regression for pasting large text
containing many newlines which is a single valid entry as after the
validation step a repaint is triggered

Fixes #282
2022-02-03 22:35:53 +01:00
sholderbach
b385d3a215 Clean engine by coalesced painting and abstraction
All `repaint`/`buffer_paint` calls are removed from the event handling,
instead the `EventStatus` determines if a repaint is necessary:
- `Handled` -> repaint
- `Inapplicable` -> no action was taken, thus no need to repaint

Additionally some conditions to check and repeatedly used patterns
abstracted as methods.
2022-02-03 22:35:53 +01:00
Stefan Holderbach
43788def68
Improve default keybindings slightly for vi (#293)
* Make cntrl-arrow keys available with vi insert

Move the key bindings based on cntrl arrow keys to the shared defaults
and place the emacs only alt-special keys to emacs

* Move emacs keybindings to eponymous file
2022-02-02 23:56:19 +01:00
Stefan Holderbach
e633499335
Polishing in the painter (#292)
* Correct allocation behavior of `coerce_crlf`

Empty string optimization of Cow<str> has to be avoided when trying to
use pre-sized buffers

* Consolidate names to `screen_width/height`

* Simplify the `PromptCoordinate` down to the row

Column of the prompt origin is never different from 0, can thus be
elided.

* Encapsulate the large buffer state readonly

* Consolidate line requirement calculion

Currently several places exists that try to estimate the number of lines
required for a given content

Extract for obvious places in the painter

Rename 'estimated_wrapped_line_count` due to misleading name to
`estimate_single_line_wraps`

* Unify painter initialization step

Prevents misuse of the painter that would cause overflows in position
calculations due to size and prompt positions being out of lockstep

* Fix painter debug output
2022-02-02 21:31:33 +01:00
Darren Schroeder
8a22413d52
Merge pull request #285 from nushell/list_things
list things with `reedline --list`
2022-02-02 08:35:41 -06:00
Darren Schroeder
4b4e16f29a move get_all_keybinding_info() to main 2022-02-02 07:25:48 -06:00
Darren Schroeder
a00b61fb65 updated get_reedline_default_keybindings to return vec of tuple 2022-02-01 15:12:24 -06:00
Darren Schroeder
606a537bd2 tweaked output 2022-02-01 05:12:41 -06:00
Darren Schroeder
03c197ffbc print/get default keybindings 2022-02-01 05:03:18 -06:00
Fernando Herrera
054b04cebb
Continous history index (#290)
* increase default page size

* countinous history index
2022-02-01 07:12:20 +00:00
Fernando Herrera
1ac359694b
increase default page size (#289)
* increase default page size

* respect full page
2022-01-31 21:44:33 +00:00
Fernando Herrera
c5003d81e3
continue history (#288) 2022-01-31 20:41:00 +00:00
Darren Schroeder
a9b8fe4af3 moved some thing around 2022-01-30 19:48:09 -06:00
Stefan Holderbach
c8e3ea270c
Init prompt without superfluous line at the bottom (#287)
The prompt initialization was still hardcoded for the two line prompt.
Now all adaptation to account for the number of prompt lines is done
during repaint
2022-01-30 20:20:15 -05:00
Darren Schroeder
abf710b53b cleanup a few more uses 2022-01-30 13:40:37 -06:00
Darren Schroeder
23ad1d02a7 cleanup uses 2022-01-30 13:35:31 -06:00
Darren Schroeder
9a9697436e quite complaining already, clippy 2022-01-30 13:29:07 -06:00
Darren Schroeder
30f4dc0e7a add functions to get items 2022-01-30 13:21:19 -06:00
Fernando Herrera
3305799947
growing menu (#286) 2022-01-30 17:35:39 +00:00
Darren Schroeder
bb942dcd47 clippy 2022-01-30 07:38:01 -06:00
Darren Schroeder
4020a99dc1 add impl Disply prototype 2022-01-30 07:20:25 -06:00
Darren Schroeder
a55884390e list things 2022-01-29 15:50:05 -06:00
Fernando Herrera
4b50d29959
dynamic menu (#284)
* dynamic menu

* corrected string

* no hints when a menu is active

* status bar style

* changed default page size

* cargo clippy

* status bar for empty list
2022-01-29 14:31:13 +00:00
Stefan Holderbach
998ddd5452
Coerce LF to CRLF lazily for lines and prompt (#281)
* Coerce to CRLF lazily

Will only introduce a CR if LF is not part of CRLF.

Only allocates if necessary

* Coerce CRLF for prompt as well

In this case handled right before painting as lifetime construct would
be tricky otherwise.

Hopeful fix for nushell/engine-q#575
2022-01-28 20:26:11 +01:00
Fernando Herrera
c786217329
chronological order search (#280) 2022-01-27 22:34:35 +00:00
Stefan Holderbach
98713c53fe
Fix after entry cursor positioning at the bottom (#279)
Now take into account that the new cursor position might have to be at
the last line of the screen that is already used. (Was hidden when on
the last line of a multiline buffer due to superfluous `CRLF` in the
event handler)

Fixes #261
2022-01-27 21:43:01 +01:00
Stefan Holderbach
cfeaf9b909
Small Painting changes to improve readability and correctness (#278)
* Doc and integerify `estimated_wrapped_line_count`

Avoid unnecessary float conversion and use usize properties

* Correct and doc `line_width`

- Fix the unlikely failure case for strip_ansi_escapes (Fallibility seems
to be driven mostly by the std::io::Write implementation of that crate)
to also compute a correct width.
- Remove unnecessary type conversions

* Single alloc strip_ansi

* Collapse ANSI handling in wrapping

* Remove superfluous fluff from painter
2022-01-27 20:00:18 +01:00
Stefan Holderbach
d10a2e7bcb
Remove outdated CompletionActionHandler(s) (#270)
* Remove outdated ListCompletionActionHandler

The implementation is incompatible with the line estimation of the
painter and superseded by the selection supporting menu.

* Internalize Completer and the related UI

- Remove the `CompletionActionHandler` trait
- Make a single `Completer` member of the `Reedline` engine
- Provide a `CircularCompletionHandler` in the engine

Open question: How to manage configuration, whether circular completions
or the interactive completion menu are preferred

* Rename `ContextMenu` to `CompletionMenu`

Clarifies the exact purpose
2022-01-27 15:43:24 +01:00
Fernando Herrera
ec2a2aebec
add return for multiline (#277) 2022-01-27 13:22:28 +00:00
Fernando Herrera
c0ec7dc2fd
Generic menus (#276)
* list of menus

* menus for main

* send trait for menu
2022-01-27 06:59:14 +00:00
Fernando Herrera
d7f42e5de4
History menu (#275)
* long menu

* comment typo

* menu with query

* history search

* row selector and input

* row parser to mod file

* constructor for engine
2022-01-25 08:44:50 +00:00
Fernando Herrera
e889bf5170
Long menu (#273)
* long menu

* comment typo
2022-01-23 18:15:42 +00:00
Stefan Holderbach
7a07ab2bcc
Support "token by token" hint completion (#269)
* Remove noop as hints are completed only at the end

* Clarify names for hint completion

* Support "token by token"-hint completion

Hints can now be completed partially

Keybindings: `Alt-right` `Alt-f` `Ctrl-right`

Uses whitespace as token/word boundary for now

* Fix event dispatch for history search mode

* Support Ctrl-Right in vi insert as well

Hint partial completion for vi
Also move word in insert mode like vim (Ctrl supported Alt unsupported)
2022-01-22 05:16:53 +11:00
Fernando Herrera
180d3dd6c4
menu performance (#268) 2022-01-21 07:55:03 +00:00
Stefan Holderbach
cd3516c0d5
Ensure easy mapping of (key)events to different context dependent event handlers (#267)
Changes initiated by @elferherrera in #266 to enable flexibility in the keymapping and simplify the individual event handlers in `handle_editor_events`

To make complex keybindings that behave differently based on context use the `ReedlineEvent::UntilFound(Vec<ReedlineEvent>)` start with the most special case that will fail to handle if conditions are not met and end with the most general handler.

TODO: Check how this interacts with vi normal mode

* multiple options for keybindings

* corrected tests and keybindings

* with handled flag

* Fix repaint usage

Don't repaint on inapplicable cases

Repaint for the ctrl-d Delete action

* Use enum to indicate the handling status of event

* Revert to explicit event keybinding method

Makes the unique situation with UntilFound more prominent

* Fix ordering of Arrow events

* Make emacs arrow commands fully compatible

Co-authored-by: Fernando Herrera <fernando.j.herrera@gmail.com>
2022-01-20 23:07:04 +01:00
Stefan Holderbach
52675664d2
Distill DefaultHinter down to history suggestions (#265)
* Show content after cursor when completing

Currently the content after the cursor was completely omitted when
entering the completion menu

Addresses it for the simple case of everything fitting on the screen

Question what should take priority if the entry and menu together exceed
the hight of the screen remains open!

* Place the hint obligatory behind the line content

In line with the behavior in fish and zsh autosuggestions hints are
displayed after the line.

Next step would be to make the DefaultHinter/Hinter trait conformant to
this behavior and also allow history hint suggestions based on the whole
line content, while editing inside the line.

* Simplify hinter internals/capabilities

DefaultHinter now only supports history

Requires no copies of the whole history anymore

* Remove `HistoryCompleter` (was never pub)

* Fix doctest `Reedline::with_hinter`

* Add configurable character threshold for Hinter

Only hint if a certain number of characters has been typed

Default: 1
2022-01-21 05:25:40 +11:00
Stefan Holderbach
2a20ca6e87
Remove Reedline::print_line from the API (#263)
As this function can only be called outside running
`Reedline::read_line` it is not relevant for raw mode reasons and can be
replaced by standard `println!()`
2022-01-20 11:06:51 +01:00
Stefan Holderbach
86712ed485
Remove superfluous insertion of carriage return (#262)
In the hinter logic `LF` was always replaced by `CRLF` thus inserting unnecessary `CR`'s into the linebuffer that accumulate if a multiline entry is recalled via hint autosuggestion from history multiple times.

Carriage returns, that are not introduced at the end of the line as part of the painter or the OS convention, break the painting of multilines, as the cursor position might jump to the start of the multiline continuation prompt and start painting from there!
2022-01-20 00:09:47 +01:00
Fernando Herrera
caebe19742
action and complete events (#260) 2022-01-18 18:54:09 +00:00
Fernando Herrera
b0ff0eb4d1
Parsing keybindings (#257)
* reduce string print

* menu input struct

* exposing keybindings
2022-01-17 21:36:21 +00:00
Fernando Herrera
32338dc18a
Tab backwards (#255)
* reduce string print

* menu input struct

* back tab

* spelling correction
2022-01-16 08:25:13 +00:00
Fernando Herrera
c0fbcf0ed1
Tab correction (#254)
* reduce string print

* menu input struct

* corrected tab movement
2022-01-15 18:56:15 +00:00
Fernando Herrera
4c3c23c959
Menu config (#253)
* reduce string print

* menu input struct

* context menu options

* removed pub from structs
2022-01-15 16:41:07 +00:00
Darren Schroeder
56025adb65
Merge pull request #252 from fdncred/fix_windows_typeo
fix windows type-o
2022-01-14 15:32:06 -06:00
Darren Schroeder
b1c5c8c60a fix windows type-o 2022-01-14 15:27:27 -06:00
Stefan Holderbach
c0e3dd791e
Move running of EditCommands to the editor (#251)
* Move running of EditCommands to the editor

- Moves the big match statement for `EditCommand`s into `Editor`
- Removes the need for many `pub` wrappers around the `LineBuffer`
- Make `Left` a `ReedlineEvent` as well
- Fix left, right, up, down for vi mode

* Fix left move in vi insert mode
2022-01-14 17:23:17 +11:00
Stefan Holderbach
b6f47f020a
Hide hint when finishing line entry (#250)
Fixes #239
2022-01-13 22:39:03 +01:00
Fernando Herrera
9ec02cb738
menu improvements (#249) 2022-01-14 02:48:26 +11:00