Commit Graph

424 Commits

Author SHA1 Message Date
Stefan Holderbach
51cc0cc020
Escape Ctrl-R history search with ESC (#385)
Fixes #384
2022-04-06 13:45:52 +02:00
Stefan Holderbach
6332747730
[API] Allow the Completer impl to be stateful (#379)
Changes the completer trait to take a mutable reference of itself on
calling `Completer::complete`

This enables the `Completer` to do caching or other smart things on the fly.
2022-04-04 23:21:13 +02:00
Fernando Herrera
698190c534
generic reedline menus (#378)
* generic reedline menus

* change word in description

* correct tests in examples

* corrected menu names

* renamed menu

* option for menus to take full line buffer

* corrected list menu insertion
2022-04-04 11:04:57 +01:00
Fernando Herrera
accce4af7f
bashisms feature for reedline (#374)
* bashisms feature for reedline

* cargo fmt
2022-04-01 18:27:51 +01:00
Fernando Herrera
246706c971
format descriptions to the left (#375) 2022-04-01 18:27:41 +01:00
Stefan Holderbach
60386ac610
API break: remove unnecessary fallibility (#367)
The fallible std::io::Results were originally introduced for the history
file but the critical points are completely separated from the builder
pattern now.

Makes the public API nicer
2022-03-31 23:32:31 +02:00
Stefan Holderbach
0f92985c69
Expose the history as syncable and readable (#373)
Useful for nushell repl loop lifting
2022-03-30 22:11:49 +02:00
Sherub Thakur
5240130c9f
Edit stack (#368)
* Add edit stack

* Use edit stack in the core editor

* Edit stack is just a struct

* Test undo-redo behaviour instead of implementation details
2022-03-29 18:17:51 +02:00
Fernando Herrera
bc18ba3260
corrects menu selection (#369) 2022-03-28 07:37:48 +01:00
Tomoki Aonuma
7b5e761c8e
Fix menu::menu_functions::string_difference (#364) 2022-03-27 13:34:11 +01:00
Fernando Herrera
072f961107
Vim normal keybingings (#365)
* corrected normal keybindings and caps

* insert checks first for mode

* vi parser test
2022-03-27 13:24:17 +01:00
Tomoki Aonuma
7c594b16ba
Fix menu::menu_functions::find_common_string (#363)
* Fix `menu::menu_functions::find_common_string`

* Add test for `DefaultCompleter`

* Add test strings
2022-03-27 11:46:57 +01:00
Fernando Herrera
e982abf7e2
update history menu (#362) 2022-03-27 08:47:40 +01:00
Fernando Herrera
69fad67b90
Descriptions for completion suggestions (#358)
* add description to completion suggestions

* completion menu with help

* corrected doc tests

* moved menu functions to module

* menu type with its own completer

* corrected doc tests

* function for menus to quick complete
2022-03-27 08:30:08 +01:00
Jacob Rothstein
0ecf800f22
end/control-e selects the current completion (#354) 2022-03-23 23:16:30 +01:00
Jacob Rothstein
bf66f2e103
add missing alt-f for parity with the existing alt-b (#353) 2022-03-23 22:55:09 +01:00
Stefan Holderbach
2eea8fa66a
Update developer focussed documentation (#351)
* Update developer focussed documentation

- CONTRIBUTING guide
- Update Readme and lib.rs
- remove old checklist
2022-03-16 23:39:08 +01:00
sholderbach
7802d85475 Simplify insertion_point in LineBuffer
- Remove the usize wrapping type `InsertionPoint`
- Remove redundant functions returning the same result
2022-03-14 20:56:14 +01:00
sholderbach
dcabfb1990 Improve visibility and documentation of internals
Painter is currently leaked by `Menu` trait. Thus document the safe part
that is used for this implementation.
Also define the responsibility of editor
2022-03-14 20:56:14 +01:00
sholderbach
8ff0147927 Folderize validator 2022-03-14 20:56:14 +01:00
sholderbach
56ea39ec32 Folderize hinter 2022-03-14 20:56:14 +01:00
sholderbach
804f31d181 Folderize prompt
- Fix docs for Prompt trait
- Separate trait and default implementation
- Hide constants that are of little use
2022-03-14 20:56:14 +01:00
sholderbach
ebafcdfe20 Create utils folder 2022-03-14 20:56:14 +01:00
sholderbach
5bc9d6c747 Folderize painting code
- Move painter and styled_text into a common folder
- Separate out `PromptLines` and freestanding utility functions
2022-03-14 20:56:14 +01:00
sholderbach
ad4760e476 Remove painter debug output 2022-03-14 20:56:14 +01:00
sholderbach
efbbd2f766 Pedantic clippy and code style polish
- Terminate with semicolon, where return type `()`
- Invert some conditionals for readability
- `match` to `if let` if binary
- pass by value vs by reference
- `must_use` attribute where applicable (builder patterns)
- make internal `Mode` enum explicitly `ViMode`
- Docstring fixes
- Format explicit identifiers in docs
2022-03-14 20:56:14 +01:00
sholderbach
4416270877 Distill DefaultPrompt impl
Unnecessary redirection in the codebase removed
2022-03-14 20:56:14 +01:00
sholderbach
de49cdaf4e Use quick_completions in the demo app
Reflects the defaults from nushell.
2022-03-14 20:56:14 +01:00
Fernando Herrera
4e5a20d127
backward history bang (#344) 2022-03-12 09:26:51 +00:00
Fernando Herrera
87a32d5147
History menu pages (#342)
* history menu page error

* checking before update

* remove in_edit variable

* remove redundant none
2022-03-10 19:05:24 +00:00
Fernando Herrera
f60bbb2939
history menu page error (#341) 2022-03-10 12:03:43 +00:00
Fernando Herrera
e1767338eb
can complete case insensitive (#340) 2022-03-08 08:03:27 +00:00
Fernando Herrera
5cd2fa2655
space before bang (#338) 2022-03-07 17:24:02 +00:00
Fernando Herrera
56bc4a00bb
Space required before bang (#337)
* bang command expands only alone in buffer

* bang command requires space before
2022-03-07 17:11:12 +00:00
Fernando Herrera
8394b62f3d
bang command expands only alone in buffer (#336) 2022-03-07 16:42:19 +00:00
Fernando Herrera
0d6e26276a
menu partial completions to menu function (#335) 2022-03-06 16:34:56 +00:00
Fernando Herrera
7c5f20d252
History improved (#334)
* undo for history replace

* history improvements

* replaced history comment
2022-03-05 19:27:50 -05:00
Fernando Herrera
3209848ddb
history bang (#333) 2022-03-05 08:53:54 +00:00
Fernando Herrera
e75a3c340a
update values after common string (#332) 2022-03-04 17:24:19 +00:00
Fernando Herrera
75489c02b4
Partial completions (#331)
* partial completions

* cargo fmt

* avoid extra partial completion
2022-03-03 09:48:05 +00:00
Fernando Herrera
e9c1e37d7c
partial completions for menu (#330)
* partial completions

* cargo fmt
2022-03-03 08:43:11 +00:00
JT
3d933d52ce
Better crossterm fix (#329)
* Move to crossterm on git

* Better fix for crossterm
2022-03-01 06:32:14 -05:00
Stefan Holderbach
97230d73bc
Provide cursor position for highlighting (#324)
Changes the `Highlighter` trait to include the position of the cursor in
the buffer. This allows it to make cursor aware highlighting such as
highlighting matching braces or code blocks

Prerequisite to address nushell/nushell#4325
2022-02-26 14:51:16 +01:00
Stefan Holderbach
bb7179cd9c
Use chars in str::replace where applicable (#327)
Fixes ci fail due to new clippy lint in rust 1.59
2022-02-26 14:17:30 +01:00
Stefan Holderbach
de97702cea
Add event to keybind a command in the hosting app (#323)
Instead of affecting the editor this lets `Reedline::read_line` return
with `Ok(Signal::Success)` containing a predefined command to be executed or
consumed by the app using `reedline` as a line editor.
The state of the editor is preserved. After the command execution in a
REPL the host would call `Reedline::read_line` again and the line editor
would be redrawn on the next free line.
Command will not be added to the history in this config.

Open for debate if this should not expect printed output from the
command and try to redraw on top or reset some state.

Addresses #312
2022-02-26 12:16:33 +01:00
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
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
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
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
Fernando Herrera
63aeeb62e4
menu with tab (#248) 2022-01-12 09:53:15 +00:00
Fernando Herrera
2cb2e40195
Context menu with completer (#247)
* menu filler builder

* context menu with completer
2022-01-11 21:17:15 +00:00
Fernando Herrera
4c75c36e4d
menu filler builder (#246) 2022-01-10 20:39:09 +00:00
Fernando Herrera
af19a7bfc6
Context menu (#243)
* vi keybinding events

* context menu for reedline

* corrected tests

* text style for menu
2022-01-10 20:17:31 +00:00
JT
a5b6cc079b
Right arrow is full hint completion (#244) 2022-01-10 11:06:45 +11:00
Fernando Herrera
eed17392cb
remove position function (#242) 2022-01-07 18:33:18 +11:00
JT
373c76a383
Double prompt (#241)
* support double prompt

* clippy warning

* better cursor position

* Move to estimating the right prompt cutoff

* refactor to use line_width

* refactor to use line_width

Co-authored-by: Fernando Herrera <fernando.j.herrera@gmail.com>
2022-01-06 22:01:47 +11:00
Fernando Herrera
811dde6d03
corrected extra line (#238)
* corrected extra line

* corrected extra line

* calculating remainig lines
2022-01-03 13:30:29 +00:00
Fernando Herrera
4b6055dccf
corrected extra line (#237) 2022-01-03 10:24:23 +00:00
Fernando Herrera
dcf8ff3f7a
Big buffer (#230)
* test big buffer

* clippy error

* more clippy corrections

* extra else for position

* debug cursor

* moving to debug section

* hints in big buffer

* case for prompt one line

* corrected extra line
2022-01-03 10:13:08 +00:00
Stefan Holderbach
a2682b50f9
Improve and highlight history search (#234)
Fixes `history_search_paint`:
- Fix unnecessary clear of single line
- Ensure LF to CRLF in search results

Fixes `Painter`:
- Make sure that Color is cleared after prompt (Currently depends on
Highlighter to provide a new color)
- Remove unnecessary fn

Introduce simple highlighting of the search term in the search result:
- Introduce `SingleMatchHighlighter` that will highlight all matches of
the search string
- Rename `DefaultHighlighter` to `ExampleHightlighter` as the behavior
seems not very useful for default use.
- Extract styling operations into styled text
2022-01-02 20:26:30 +01:00
Stefan Holderbach
1da1e848bf
Insert strings directly (#233)
There are latent concerns about unicode correctness, but as long as
crossterm/hints are providing correct chars/strs this is neither a security risk
(no unchecked/unsafe string ops on our side) nor
a DoS risk.
2022-01-02 20:24:17 +01:00
Stefan Holderbach
c1021f6f35
Improve correctness of move operations (#231)
- Made move up and move down unicode safe
- Added the option to constrict the char search (vi `f` `F` `t` `T`) to
the current line as usual in vi
- Improved test coverage
2022-01-02 20:17:57 +01:00
JT
07696fe06d
strip ansi before estimate (#229) 2022-01-01 15:50:06 +11:00
JT
b82b6ebd35
Estimate wrapping (#228)
* Add wrap estimates to line counting

* Remove adjust_prompt_position
2022-01-01 11:25:32 +11:00
JT
3292aaa2b4
Let anims handle resize (#227) 2022-01-01 08:33:19 +11:00
Fernando Herrera
5401b4ec58
adjust position to insert in middle (#226) 2021-12-31 21:42:29 +11:00
Fernando Herrera
913e58d4a9
prompt moves based on hint (#217)
* prompt moves based on hint

* checked sub for the prompt

* checked sub for the prompt

* using promplines

* clean flush

* split lines before print

* test with full print

* test with full print

* removed flush

* no split

* drawing function with prompt

* replacing space return to string

* history search in repaint buffer

* using last row

* removed extra required lines
2021-12-31 10:34:11 +11:00
Stefan Holderbach
1553c77e40
Test and fix line buffer utils (#224)
- current line detection was off on the first position of a following
line
- find_current_line_end was not correctly aware of CRLF platforms
- Increase of coverage for some old functions
2021-12-31 08:25:14 +11:00
JT
a8153cf69a
Make StyledText easier to work with (#225)
* Make StyledText easier to work with

Make the contents of StyledText pub to make it easier to work with

* Update styled_text.rs
2021-12-30 22:25:07 +01:00
Leo Kettmeir
b3eec539b8
fix: make traits Send (#223)
* send sync

* fmt

* only Send

* add test
2021-12-31 08:23:22 +11:00
Stefan Holderbach
b242a030aa
Make the editing operations aware of multiline (#219)
- Moves to start and beginning of the line
- Make start and end of buffer available for move via `Ctrl-Home` and
`Ctrl-End`
- Support vi style cutting of whole lines in the cut buffer.
- add vi style `p` after paste in addition to before cursor paste with
`P` or in emacs mode
- Enables vi style `dd` and paste
- Make sure the line to end cut and clear operations work only on the
line
2021-12-29 18:07:27 +11:00
Stefan Holderbach
afa83d9e70
Disable hints during history traversal (#215)
* Disable hints during history traversal

Additional autosuggestion (history) hints are confusing while
navigating through the history.

Example history:
```
hello test
hello
something else
hello world
whatever
```

- Type `h`
- Press up arrow
- Prefix based history search will return `hello world`
- Press up arrow again
- Previously `hello <hint>world</hint>` now just `hello`

* Reduce code duplication before painting
2021-12-27 19:21:18 +01:00
Fernando Herrera
7c75ed6c62
vi insert mode kept after enter (#214) 2021-12-27 12:16:37 +01:00
Fernando Herrera
f9a6806e01
vi insert mode default (#213) 2021-12-27 11:28:07 +01:00
Stefan Holderbach
8895756054
Improve history internals (#212)
* Move history newline escape to the file IO

Avoids potential interference with history search, makes
`History::iter_chronologic` nice again, simplifies it regarding hints
and should address the `history` command in a better way.
+ Extract escape
+ Remove unwrap

* Remove unnecessary optional history allocation

No need to clone if entry is duplicate or empty
2021-12-27 00:05:50 +01:00
Fernando Herrera
fbd7b20e8c
vi mode commands (#211)
* vi mode commands

* added search to left

* reordered files

* clippy corrections

* utf8 character offsets

* check valid input

* test has garbage

* Fix `f<char>` move starting on multibyte char

* Fix formatting

* added append command

* correcting failing tests

* append command doesnt require repaint

* Pedantic fixes

- Terminate statements with ;
- Make char references copies for performance

Co-authored-by: sholderbach <sholderbach@users.noreply.github.com>
2021-12-26 18:13:44 +00:00
JT
3acf7da71a
Minor history fix (#210) 2021-12-23 12:35:39 +11:00
JT
5d0e803b9d
Another multiline decode (#209) 2021-12-23 10:58:20 +11:00
JT
328c86e38d
improve multiline paste (#208) 2021-12-23 09:32:07 +11:00
Stefan Holderbach
adc6b1f649
Attempt at consolidating offset calculations and streamlining the painting (#164)
* Offset setting changes

* Rename `PromptWidget` to `PromptCoordinates`
* Explicit setters
* Set offset implicitly on `full_repaint`

* Rename origin and offset

As suggested by JT

origin -> prompt_start

offset -> input_start

* Move tracking of offsets and size into painter

Relatively basic refactor of all tracking of prompt/input offsets as
well as the terminal size into the painter.

Some cooperative behavior in the engine is still required

Wrapping handler is currently still a crutch in the engine as it is not
`InsertChar` specific and should be handled for every buffer change
instead

* Simplify restore from history stearch

Prompt is simply updated via full repaint

* Fix ansi coloring for history prompt

also ignore reset color in non ansi colored mode

* Make pedantic clippy happier

* Ensure prompt creation is tight and not wrapping

Fix additional line that is created upon prompt creation if the previous
output was printing a new line. Also ensures that line clearing and
regular prompt creation at the bottom of the screen doesn't cause
scrolling issues (Currently a hardcoded solution for the two line
prompt)

Also reduces the API surface for tools only necessary to deal within raw
mode.

* Fix doctests for internals removal

`print_crlf()` was removed from the public API as it should only be used
in raw mode for internal stuff.
As soon as we leave `Reedline.read_line()` raw mode should be disabled
and the regular print macros should work as expected
2021-12-22 23:14:58 +01:00
JT
2ddeb76ff4
Simple multiline history (#207) 2021-12-23 06:59:55 +11:00
JT
fb152af5f4
Adjust prompt position after paste (#206) 2021-12-23 06:27:09 +11:00
Fernando Herrera
792ee12344
defining paste event (#205) 2021-12-23 06:17:18 +11:00
JT
ae7e930119
Complete to the latest history (#204) 2021-12-22 20:18:47 +11:00
JT
c810d65a9d
Add a history-specific completer (#203)
* Add a history-specific completer

* Document api
2021-12-22 19:38:24 +11:00
JT
349f66b7b3
Apply history on tab (#202) 2021-12-22 19:12:45 +11:00
Stefan Holderbach
0f0a557479
Disable raw mode with Drop for panics (#201)
Panicking inside reedline (or bubbling up an Err inside reedline's
critical sections that gets unwrapped/expected by the hosting
application) leaves the terminal in a bad state. Workaround that should
also work without cooperation by the consumer would be to include a call
to `disable_raw_mode` in the `Drop` trait. With standard stack-unwinding
panics will call the drop.

Calling `crossterm::terminal::disable_raw_mode` twice seems to be fine
if the program started in non-raw mode (under linux)
2021-12-20 21:16:28 +11:00
Stefan Holderbach
44826d2f6d
Remove additional line on line clear via Ctrl-C (#200)
Additional line was a crutch introduced to counteract misbehavior fixed
in #77

Similar behavior was already sneaked into engine-q with https://github.com/nushell/engine-q/pull/508
2021-12-19 22:34:32 +01:00
JT
e512512dd4
Crlf fixes (#199)
* Add some wrapping estimate when adjusting prompt

* Add some crlf fixes for Windows multiline
2021-12-15 06:47:53 +11:00
JT
4da6a82ae6
Add some wrapping estimate when adjusting prompt (#198) 2021-12-14 06:34:29 +11:00
Darren Schroeder
6884ec4062
add the ability to optionally turn off ansi coloring (#197)
* add the ability to optionally turn off ansi coloring

* also strip from the hinter
2021-12-09 21:48:08 +01:00
Stefan Holderbach
a44a590b25
Fix clippy style and remove unecessary stuff (#192)
- remove unused members, found after update to Rust 1.57
- semicolon termination in void blocks
- other clippy pedantic prompted fixes (e.g. docstrings, unnecessary borrows)
2021-12-02 23:22:12 +01:00
Stefan Holderbach
2d34d100bd
Improve undo of EditCommands (#191)
* Improve undo of EditCommands

Address #190

Formalize the undo role of different edit commands via exhaustive
matching

Will track every move, but won't cause inconsistent cursor jumps while
undoing
2021-12-02 23:21:09 +01:00
Antonio Natilla
82bc3acb64
Forwarding Prompt's multiline indicator (#185)
* Multiline continuation prompt introduced

* Hardcoded multiline continuation prompt styling

A way to convert `crossterm::style::Color` in `nu_ansi_term::Color` must
be found/implemented. This enables creating a Style from it.
Otherwise, it is necessary that the Style of the prompt is accessible
from everywhere.

* Forward Prompt's multline prompt to rendering func

* Finish #185

Co-authored-by: Antonio Natilla <antonio.natilla@studenti.unimi.it>
Co-authored-by: sholderbach <ho.steve@web.de>
2021-12-01 12:18:49 +01:00
Stefan Holderbach
2bc7046066
Fix busy polling when animation is disabled (#188)
Addresses https://github.com/nushell/engine-q/issues/386

Breaks the API for variable refresh times, standardizes on one second
and simply optionally disables the automatic repaint.
2021-11-30 16:25:06 +01:00
Stefan Holderbach
b19ea8d9b4
Fix cursor flickering for full repaint (#187)
Avoids jumping cursor to the prompt on full repaints of the standard
buffer. Does not completely remove a perceptable flicker at the fixed
position if animation is active.

Partially addresses #174 as other cases still need to be checked for
cursor updates
2021-11-29 23:00:58 +01:00
Antonio Natilla
75d9b4b52d
Simple multiline continuation prompt (#184)
* Multiline continuation prompt introduced

* Hardcoded multiline continuation prompt styling

A way to convert `crossterm::style::Color` in `nu_ansi_term::Color` must
be found/implemented. This enables creating a Style from it.
Otherwise, it is necessary that the Style of the prompt is accessible
from everywhere.

Co-authored-by: Antonio Natilla <antonio.natilla@studenti.unimi.it>
2021-11-24 20:10:55 +13:00
JT
c11aef2d9b
Handle the bottom resize a little better (#182) 2021-11-11 19:00:17 +13:00
JT
730147167c
Handle the bottom resize a little better (#181) 2021-11-11 16:55:38 +13:00
Josh
a16f96863d
fn queue_buffer probably didn't mean to flush; Simplified engine->insert_char and removed the need to create a String at each insert. (#180)
* `fn queue_buffer` probably didn't mean to flush :)

* Simplified insert_char, and removed the need to create a String at each insert

* rust fmt
2021-11-11 08:19:10 +13:00
Stefan Holderbach
1b24499298
Improvements to handling of incoming events (#179)
* Drain crossterm events, prioritize last resize

This attempts to address #166, some slowness is still observed

Co-authored-by: JT <547158+jntrnr@users.noreply.github.com>

* Fix timing of repaint with drained events

* Initial code to coalesce edit commands

Co-authored-by: JT <547158+jntrnr@users.noreply.github.com>
2021-11-10 13:59:17 +13:00
Antonio Natilla
9218158903
Curly braces fix in vim events (#173)
Support for Shift-AltGr is required for several European keyboards (e.g. italian) #169 #136 #139 #171

* Curly braces fix

* Curly braces fix for vim events

Co-authored-by: Antonio Natilla <antonio.natilla@studenti.unimi.it>
2021-11-06 14:20:18 +01:00
Stefan Holderbach
ee0c274600
Fix printing in #170 (#172)
Small printing bug introduced due to raw mode had to be fixed
2021-11-05 23:19:07 +01:00
Antonio Natilla
e159f3fd0d
Curly braces fix (#171)
Co-authored-by: Antonio Natilla <antonio.natilla@studenti.unimi.it>
2021-11-05 22:56:20 +01:00
Stefan Holderbach
d832449a51
Provide more details in the keyevent debugger (#170)
Inform about the character code and the bit pattern of the modifier to
debug more subtle problems with key events
2021-11-06 10:22:42 +13:00
Josh
75a2ca0761
Builder to customize and disable idle animations (#168)
* Introduced 'repaint' flag on struct ReedLine, and associated builder function

* Added builder to configure and disable idle animations

* Ran `cargo fmt` and `cargo clippy`
2021-11-06 07:17:32 +13:00
JT
68a6ab4e5b
Expose line buffer (#165)
* Add list style completions

* Expose the LineBuffer struct
2021-10-16 07:28:53 +13:00
JT
88bded3417
Add list style completions (#162) 2021-10-05 10:32:21 +13:00
Marco Zanrosso
de0f399650
[BugFix] undo function (#143)
* [BugFix] undo function

This commit solves the problem that when the undo function is performed,
for some reason the buffer remained with 1 character.

The FIX consists in correcting the logic of the current implementation
by bringing it to the initial design state; Where the vector of the
buffer had been initialized with an empty entry so that when performing
many times the undo brought you back to an initial condition with
the blank buffer rather than show you the first character.

* [Add] doc-test for set_previous_lines

This test was created specifically to check that the insertion
of characters and words in the Editor.edits vector works properly.

* Replace doctest with unittest

This does not require exposing private functionality as pub

* Fix naming according to #160

Co-authored-by: sholderbach <ho.steve@web.de>
2021-10-03 23:01:01 +02:00
Stefan Holderbach
f03c036ba4
Fix links in lib.rs 2021-10-03 22:16:42 +02:00
Stefan Holderbach
8a09f75dee
Clarify method names for undo-interface (#160)
Minimal change to make undo machinery of `Editor` more explicit.
2021-10-04 09:11:59 +13:00
Stefan Holderbach
38bf8e469c
Simplify and document history trait (#159)
Inspired by #158
2021-10-04 09:05:58 +13:00
Stefan Holderbach
87ce437d89
Fix CtrlD/CtrlC and reverse-history-search + stuff (#155)
* Fix CtrlD/CtrlC and reverse-history-search + stuff

- `Ctrl+C` and `Ctrl+D` did not work after the changes in #138 and #146
  - Fixed by only registering the `ReedlineEvent` and defering
potentially necessary edits to the `handle_event` stage
  - Defined their behavior for the reverse history search
  - Corrected interactions with undo (as best as I could understand it)
- Reverse history search did not allow for browsing through its results
  - Fixed `handle_history_search_event` and simplified the cases
- Register undo steps for the reverse history search (when entering and
leaving via enter)
- Added comments to similar sounding methods and variants (UPDATE IF
NECESSARY!)
- Moved the repaint stuff closer together in engine.rs for better
readability
- Noncritical stuff that caught my eye

* Test first/last line detection
2021-10-03 19:44:23 +02:00
Sherub Thakur
bfddc5870c
Add tests line buffer (and fix methods) (#150)
* Ignore tarpaulin coverage build folder and html report

* Add tests for line buffer

* Capitalize char only moves a character to right

* Uppercasing and lowercasing words works

* Fix the swap grapheme function

I have made this to be close to what I inferred the intent to be. I
really think we should probably have two functions which do this:
`swap_grapheme_left` and `swap_grapheme_right` which work in the
mentioned direction.

* Fix swap words

Swap words only swap words and there is no change in position.
2021-09-27 14:37:57 +13:00
JT
93c2146fcf
Bump version (#152)
* Bump to 0.2

* Add to README

* Improve top docs

* Clear to the end of each newline to remove any leftovers
2021-09-24 07:40:32 +12:00
Fernando Herrera
5048cc50e7
Incomplete brackets (#149)
* incomplete brackets

* check type of brackets

* comment and tests
2021-09-24 07:01:42 +12:00
JT
a6ad37ced9
Improve rendering of multiline (#151) 2021-09-24 06:58:40 +12:00
JT
30ad477832
Multiline improvements (#148)
* Multiline overlow in navigation fix

* Remove line from insertion point

* Finish adding scrolling to the adjustment

* fix test
2021-09-23 12:21:31 +12:00
JT
22fc31c68d
Add simple validation to check for multiline completion (#147)
* Add simple validation to check for multiline completion

* fix test
2021-09-22 17:12:26 +12:00
Sherub Thakur
30f9d419f3
Add tests to emacs and vi edit mode (#146)
* Add equality derive for EditCommand and ReedlineEvent

* Move matches to keybinds for emacs edit mode

* Simplify event matching in emacs edit mode

* Bugfix: All matches happening at same point

* Add failing test to check keybinding override

* Bugfix: Inserting capital character works

* Unknown requirement: test to be to capture currently unknown requirement

* Add rstest

The reason is to easily write parameterized tests

* Add test: for emoji input to emacs

* Add tests and fixes for vi edit mode

* Reedline None event and vi keybinds

* Keybindings are overridable

* Vi Reedline::None
2021-09-22 16:37:19 +12:00
JT
cd87851ad9
Cleanup some deps and improve build times (#144) 2021-09-06 05:39:19 +12:00
Fernando Herrera
1233b450b9
Modifier for altgr (#139)
* modifier for altgr

* change reedline event
2021-09-05 09:48:01 +12:00
JT
ab3666a0ac
Fix update to TODO (#142)
* Fix update to TODO

* Fix tests

* remove test ci
2021-09-05 07:57:23 +12:00
JT
ccce8d5fa1
Fix double chars (#140)
* Fix double chars

* Fix double chars

* Updates

* doctest fixes

* see if it's paying attention

* see if it's paying attention
2021-09-05 07:32:02 +12:00
JT
1bd9e9fe01 Fix clippy 2021-09-05 06:09:39 +12:00
Sherub Thakur
8c6fe225ab
Pull some events from EditCommand to ReedlineEvent (#138)
* Extract hinter and highlighter out of Painter

* Cleanup unused variables, add comments

* Remove AppendToHistory Event

* Keybindings talk in terms of ReedlineEvent

* Add placeholder docs

* Push History handling one-level up

* Modify Enter handling to match others

* Extract Previous and Next History commands from EditCommand to ReedlineEvent

* Remove reduncant EditCommand -> ViFragment

* Pull Up/Down from EditCommand to ReedlineEvent

* Pull SearchHistory from EditCommand to ReedlineEvent

* Refactor insertion wrapping code

* Push History handling one more level up

* Fix doc test: keybind interface change

* Remove redundant indirections

* Reorganize methods in engine

* Update vi binds from history to up/down operations

* Remove the hacky EditInsert brach from ReedlineEvent
2021-09-05 06:04:58 +12:00
Sherub Thakur
aebbc24188
Modularization of the main struct (#134)
* Remove vagueness from position method

* Pull terminal size into the main struct

* WIP: prompt widget

* Remove a bunch of stuff

- clock
- vi stuff
- requirement to do full repaint state management

* Remove edit mode from event matcher

* Extract out event handling into a function

* Add reedline specific enum

* Rebase fixes

* Update docs

* Re-add clock functionality

* Add event-parser

* Pull out Input Parsing out of the main struct

* Move input parsing stuff into a directory

* Move vi stuff into input parsing

* Re-introduce Vi-Mode

* Remove EditMode enum

* Emacs mode uses non-default keybindings

* Basic hygine for edit_mode

- Rename: input_parsing to edit_mode
- Rename: EmacsInputParser to Emacs
- Rename: ViInputParser to Vi
- Rename: InputParser to EditMode
- Add docs: EditMode
- Add docs: Vi
- Add docs: Emacs

* Remove update_keybindings interface

* Vi sends Repaint events on mode switch

* Rename new to create
2021-08-29 06:10:16 +12:00
Sherub Thakur
12ba36f8be
Less intrusive tab completion (#133)
* Organise tab handling into files

* Concretise assumptions as manul tests

* Add expectation (failing test)

* Store one-level history for tab handler

* Remove reset index from the public interface of TabCompletion

* Update note on cycling though the tab-completions
2021-08-15 08:14:10 +12:00
Sherub Thakur
ade4172046
Cleanup (#130)
* Cleanup: Remove un-necessary indirections from engine to editor functions

* Cleanup: Remove dead code - partial_command

* Cleanup: Make undo/redo interface consistent with other editor functions

* Cleanup: abstract up/down command logic to appropriate units
2021-08-13 07:29:44 +12:00
Sherub Thakur
d8684f50af
Pull undo redo to editor (#129)
* Pull undo/redo functionality out from line_buffer to editor

* Update editor.rs

Co-authored-by: JT <547158+jntrnr@users.noreply.github.com>
2021-08-13 06:29:46 +12:00
Sherub Thakur
f490dd4f93
Core editor (#128)
* Add a core-editor folder

* Add editor

Currently this is more of less line_buffer the integration with engine
has a few hacky edges that need to taken care off.

* Pull cut buffer operations into editor
2021-08-13 05:28:28 +12:00
JT
289188eee7 Allow the read_line to fail in the demo 2021-08-07 10:10:00 +12:00
JT
5822306504
Exposed the styled text struct (#127) 2021-07-27 14:58:30 +12:00
JT
28dbd03953
Fix enter during history traversal (#126) 2021-07-27 14:38:56 +12:00
JT
1caf34339d
Add more rustdoc comments (#124)
* Add more rustdoc comments

* Add more rustdoc comments
2021-07-26 16:24:02 +12:00
JT
2023222d6b
Add clippy to ci (#123) 2021-07-26 08:36:15 +12:00
Marco Zanrosso
df7c24b651
[StyleFix] compact engine.rs match arms (#121) 2021-07-26 08:12:08 +12:00
JT
79ae22ed50
Fix the build (#118) 2021-07-25 20:50:06 +12:00
Sherub Thakur
858eabf940
Outside world does not know about insertion point (#111) 2021-07-25 20:37:41 +12:00
Marco Zanrosso
d251df31ac
[Add] CtrlZ (undo) and CtrlG (redo) features (#107)
* [Add] CtrlZ and CtrlY features

* [Update] undo and redo features to work with words

* [StyleFix] resolved cargo clippy warnings in lib.rs

* [BugFix] change redo keybinding

* [BugFix] reset stored linebuffer when reedline return

* [StyleFix] de-duplicate lines

* [StyleFix] simplify EditCommand enum

* [Improve] set_previous_line logic

* [StyleFix] avoid glob imports
2021-07-25 20:36:21 +12:00
Stefan Holderbach
653223f595
Change cursor pos in prefix search to the end (#115)
* Change cursor pos in prefix search to the end

Approach discussed in #113

* Shrink mem footprint of test

Just sneaking in a commit
2021-07-22 16:53:12 +12:00
Stefan Holderbach
3dae21fe34
Fix the history behavior (#94) (#110)
* [WIP] Fixing the history behavior

* Repaint mode switching after the 1sec case
* Back to history cursor with len for not used -> fixes the skipping the
most recent
* unit tests not yet adapted
* None logic not yet smart to be able to leave history traversal

* Rewriting history with JT

Fixing the basic traversal as well as the prefix based search.

Ctrl-R search still dysfunctional. Missing the duplicate detection, thus
not passing tests. Missing test coverage for moving forward in a search.

* Complete basic history test suite

* Test the forward behavior in prefix search
* Skip consecutive equal matches

* Fix Ctrl-R search

* Update file_backed.rs

Co-authored-by: JT <547158+jntrnr@users.noreply.github.com>
2021-07-21 06:11:26 +12:00
Sherub Thakur
b4748acfb5
History fix cursor update (#97)
* Cursor updates with the appropriate history command

* History command inserts after the end

we will most likely store multiline commands in history as `String`s so
I have opted for a converstion of this string to a vector separated by
newlines in `set_buffer`.

* History Traversal paining rules

- On normal up down we update the cursor to the end of the line
- On prefix based up and down we do not update the cursor

Rationale for this is that when we are doing prefix search a user might
want to add more to his query so as to get better prefix matching and
having to delete through all the chars we would otherwise fill in might
be annoying.

* Fix prefix search not updating properly

* Normal traversal sets history string at cursor to line buffer

Co-authored-by: JT <547158+jntrnr@users.noreply.github.com>
2021-07-20 05:59:49 +12:00
JT
4056abe4c2
Add multiline support (#108) 2021-07-19 11:08:29 +12:00