Commit Graph

253 Commits

Author SHA1 Message Date
Stefan Holderbach
8a8dd44aad
Small fix to document need to configure completion (#325)
Keybindings are currently configured to require the completion menu. To
use the completions you have to manually add it.

Undocumented: Changing the keybindings to use the old bash style
completions with `CircularCompletionHandler`

Track #307
2022-02-24 20:41:45 +01:00
Stefan Holderbach
65cfd6bcbd
Bump dependencies and edition to 2021 (#310) 2022-02-24 00:09:58 +01:00
Fernando Herrera
2db0ffd1c4
extra row for empty menu (#322)
* extra row for empty menu

* simple syntax
2022-02-21 19:38:53 +00:00
Fernando Herrera
e87e9d1fd3
corrected padding for menu (#319) 2022-02-19 15:33:39 +00:00
Fernando Herrera
42ec23f083
edit mode for quick completions (#318) 2022-02-18 18:47:37 +00:00
JT
8c565e4f1d
Make up/down be one-press-per-history (#306) 2022-02-09 10:40:46 -05:00
Fernando Herrera
da21703840
Revising quick completions (#305)
* increase default page size

* revising quick completions

* not default quick completions
2022-02-07 18:36:44 +00:00
JT
ca727ff4a7
Fix one item completions (#304) 2022-02-07 07:06:09 -05:00
Fernando Herrera
805daea8b6
Vi menus (#303)
* increase default page size

* navigation in normal mode
2022-02-06 17:24:14 +00:00
Fernando Herrera
7a232a1f0e
Menu events (#302)
* increase default page size

* menu events

* removed empty space variable

* removed width variable
2022-02-06 14:15:50 +00:00
Stefan Holderbach
92b299916e
Make appending and truncating history file thread safe (#299)
Add safe `sync` method to `History`

This method both reads from the file and writes local additions. Is safe
when multiple `History` instances try to truncate the history file on
disk.

To avoid race conditions on the file uses the `fd_lock` crate for file
advisory locks. (Inspiration for that thanks to rustyline: https://github.com/kkawakam/rustyline/blob/master/src/history.rs)



Fixes #221

- Cover history file ops with tests
- Add test for conflicting writes that should truncate
- Add safe `sync` method to `History`
- Test `FileBackedHistory` for threadsafety
2022-02-06 00:20:44 +01:00
Fernando Herrera
18f5383612
Keybindings functions (#297)
* increase default page size

* keybinding functions
2022-02-04 22:23:53 +00:00
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