Commit Graph

400 Commits

Author SHA1 Message Date
Stefan Holderbach
f2ee704642
Update workflow to new actions (alternative) (#505)
Alternative to #503

Using `actions-rust-lang` instead of `actions-rs` for
setup. (nushell uses them for setup with integrated caching)

Remove build stage as this should also be covered by test.
clippy --all to see if this checks the examples as well.
2022-10-30 17:05:24 +01:00
Jan Christian Grünhage
698f4eb428
fix: actually use sqlite-dynlib feature (#504)
7d721a1 introduced the sqlite-dynlib feature, but using it in places
where sqlite is currently used was not possible, because the cfg gates
weren't adjusted yet. This commit replaces each `feature = "sqlite"`
with `any(feature = "sqlite",feature = "sqlite-dynlib")`, meaning that
it doesn't matter which sqlite feature you use, reedline will expose the
same API.
2022-10-30 16:09:53 +01:00
nibon7
39e6bc8eb3
show right prompt on indicator line in last line mode (#501) 2022-10-23 15:57:24 +02:00
Dan Davison
30713abe87
Tab inline completion (#498)
* On backspace, deactivate menu and do not complete

Fixes #5497

* Make Tab insert (partial) completion instead of select next menu item

* Fix history search filtering
2022-10-22 22:52:11 +02:00
Carl Schierig
da27f0041a
change cursor shape depending on edit mode (#494) 2022-10-21 09:03:53 +02:00
nibon7
8e1511ad05
render right prompt on the last line of the left prompt (#492)
* render right prompt on the last line of the left prompt

Closes nushell/nushell#4909

* make rendering the right prompt on the last line configurable

* calculate width of the line where right prompt will be rendered
2022-10-20 21:57:01 +02:00
Stefan Holderbach
21f5e125de
Prepare 0.13 release (#495) 2022-10-17 23:00:38 +02:00
Stefan Holderbach
5061d2288c
Fix completion example in README/lib.rs (#497)
Adapted from examples added in #493
2022-10-16 23:41:57 +02:00
Stefan Holderbach
c08ce5ef7f
Fix examples in README based on lib.rs (#496)
The first two README examples became rotten and were out of sync with
the doctested version from the `lib.rs`
2022-10-16 23:20:35 +02:00
Paul Colomiets
f949f560f7
Add Submit and SubmitOrNewline editor events (#490)
* `Submit` is used to return data unconditionally. This is useful for
  example if you want compiler to show you where the unclosed paren that
  doesn't pass validation actually is.
* `SubmitOrNewline` is similar to `Enter` but inserts a new line if the
  cursor is not at the end of the buffer. It's useful to insert newlines
  in the middle of the text when editing.

This also removes unconditional `KeyCode::Enter` to
`ReedlineEvent::Enter` event mapping and sets it in the keybindings
normally (so you can rebind to `Submit` or `SubmitOrNewline`)
2022-10-16 22:24:08 +02:00
perlindgren
835d2e9f25
examples updated (#493)
Puts the minimal examples from the documentation as separate example executables to play around with
2022-10-16 22:13:55 +02:00
Paul Colomiets
3042289df4
Remove flicker on external print (#488)
* Remove flicker on external print

Previously each external print was causing a visible flicker on at least
two terminal emulators I've tested (alacritty, xfce4-terminal).

* Make `Painter.print_external_message()` crate local

* Put external_printer Painter members behind flag

* Add `external_printer` feature to CI

Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com>
2022-09-29 16:36:04 +02:00
Stefan Holderbach
f994cc9d38
Prepare 0.12.0 release (#487)
* Prepare 0.12.0 release

* Widen author metadata
2022-09-28 12:00:54 +13:00
sholderbach
3e92f97da2 Parse motions properly, fix #449, add combinations (#484)
This change truly separates the actions and the motions on the parsing
side. Bare motions are parsed by the motion parser instead of the
command parser. (This requires a separate `ParseResult` to distinguish
valid but incomplete motions like `f` from invalid motions.)

Fixes #449 by making `.` its own command. Also introduces the
possibility of multiplying the `.` repeat and resticts its effect to the
action commands and ignores the bare moves.

Simplify and make the `;` and `,` behavior more correct:
- Place info in the `Vi` state instead of complicated in-band signal
- Support using it with `d;` and `c;`
- Store the character search when combined with an action
- Rename `ViToTill` more explictly to `ViCharSearch`
- **Missing:** the old tests were removed as they tested old quirks

The above change also leads to proper separation of concern between
parsing and translation to emacs commands (and subsequent execution).

Add support for combining `d/c` with `h/l`.
**Note:** `j/k` are still omitted as they require new behavior in the
linebuffer/editor. Also `dj` has to add 1 to the multiplier to achieve
the correct behavior as we do not model line ex-/inclusive behavior.

Rename `ParseResult` to `ParsedViSequence`

Simplify validity checking in `mod.rs` and have explicit check methods
on the types. This fixes problems with `r` and `f/t/T/F` in their
partial and complete state and adds a missing test.

Rename `last_to_till` to `last_char_search`
2022-09-25 23:55:58 +02:00
sholderbach
07a9a7463f Add tests for cut_right_until_char (#484)
I discovered a limitation in how we handle character searches with a
multiplier in the case the search character appears in a consecutive
sequence.
Fixing this correctly probably requires performing the search with
knowledge of the multiplier.
2022-09-25 23:55:58 +02:00
sholderbach
26a09b7a54 Simplify application of multiplier (#484)
Take into account that only the product of the `multiplier` and `count`
are relevant to execute motions.

From 140f6d0eda/runtime/doc/motion.txt (L63-L70)

> If the motion includes a count and the operator also had a count before it,
> the two counts are multiplied.  For example: "2d3w" deletes six words.
> When doubling the operator it operates on a line.  When using a count, before
> or after the first character, that many lines are operated upon.  Thus `3dd`
> deletes three lines. A count before and after the first character is
> multiplied, thus `2y3y` yanks six lines.
2022-09-25 23:55:58 +02:00
sholderbach
a7dababdd0 Make the c action translation more explicit (#484)
Move the `Repaint` addition outside to ensure it is always added.
Currently required to detect the mode change visually.
2022-09-25 23:55:58 +02:00
Stefan Holderbach
710393a037
List that space can be bound through Char(' ') (#486)
Necessary to complete nushell/nushell#6590

(Comment: this whole module feels intricately linked to the nushell
implementation as we do not implement the string parsing in reedline)
2022-09-20 12:19:03 +02:00
Darren Schroeder
9a6fdd78dc
enable easier history session id conversion (#485) 2022-09-19 07:47:16 +02:00
Darren Schroeder
3fa87ef1e2
change history session_id to a systematically generated number (#481)
* change history session_id to a systematically generated number

* added env var, removed comments

* tweak test

* add public function to get the history session id

* switch from reedline commit date to unix_epoch
2022-09-18 17:04:42 -05:00
Stefan Holderbach
1bf9ad6bc7
Fix vi character search parsing (#483)
* Fix vi character search parsing

Fixes #473

The parser has to consume the items from the iterator to be in a
consistent state!

* Move `ViToTill` logically to `motion.rs`

* Add basic regression test for #473
2022-09-18 23:42:08 +02:00
Jan Christian Grünhage
7d721a10e8
Don't bundle sqlite by default (#474)
* Don't bundle sqlite by default

* Split feature into `sqlite` & `sqlite-dynlib`

Also add feature documentation

* Copy feature doc to `lib.rs`

Co-authored-by: sholderbach <sholderbach@users.noreply.github.com>
2022-09-18 14:17:34 +02:00
Stefan Holderbach
db646e9ff5
Fix documentation string formatting and linking (#482) 2022-09-18 14:08:26 +02:00
Gregor
70118f732c
Basic external printer (#467)
Addresses #320, #236

* Adding External printer

* Made ExternalPrinter as an optional feature. Clippy is happy, test pass, docs added.

* ExternalPrinter: prints multiple messages if available, more on error-handling.

* Bug(s) fixed. Prints messages. Working example in examples folder. Code formatted, clippyed, tests pass.

* Generic ExternalPrinter<T> where T: Display.

* Fixed: Works with buffers larger than a line.

* Fixed: Works with buffers larger than a line, refactored.

* Different approach, seems to look like what is expected. Gives the "illusion" of one line being entered. Needs more testing, could have some off by one errors ;)

Co-authored-by: Gregor Engberding <gregor@meinkopter.de>
2022-09-14 21:58:45 +02:00
unrelentingtech
dc091e8285
Allow external manipulation of the command line buffer (#472)
This allows nushell to implement a command similar to fish's `commandline`:

https://fishshell.com/docs/current/cmds/commandline.html

that would allow commands run via `executehostcommand` bindings to do interesting
things to the contents of the input buffer.
2022-09-09 21:12:30 +02:00
Stefan Holderbach
d636eefd64
Prepare 0.11.0 release (#471) 2022-09-06 10:54:16 +02:00
unrelentingtech
fe889ae5c4
Add Reedline::has_last_command_context to allow checking if update_last_command_context will fail (#470)
This is necessary to avoid the problem with running executehostcommand keybindings in nushell
right after launching it (without having run actual user-input commands yet).

Since the error types are not exposed outside of the crate, we have to use a check instead of
matching on the error.
2022-09-05 11:53:03 +02:00
nibon7
069d902bcb
Fix panic when using sqlite as history backend (#469)
Fixes nushell/nushell#6251
2022-08-27 05:59:55 -05:00
morzel85
d4ab1a753f
README.md outline cleanup (#466)
- Fixed anchor links (some links were not pointing to correct headings).
- Updated headings (some headings in outline didn't match the content).
- Fixed heading level for "Integrate with History" (was 2 should be 3).
2022-08-22 10:06:33 +02:00
Stefan Holderbach
b11109bbe8
Prepare 0.10.0 release (#463) 2022-08-15 12:21:26 +02:00
bnprks
174255535d
Improve undo functionality (#460)
* Delete unused code in `CircularCompletionHandler`

I could not find anywhere that the `Reedline::ActionHandler` event is
actually created, except for a bit of deserialization code in nushell
(reedline_config.rs:817). I suspect its functionality is no longer
needed in the current version of reedline.

* Improve word-level undo and completions undo

* Adds completions and history searches to the undo stack

This required changing all the menu interfaces to do their edits through
the `Editor` struct, so it can track undo state

* Improves the system of coalescing word-level edits on the undo stack

This involved expanding the `UndoBehavior` system. Now, every edit gets
tagged with `UndoBehavior`, and by comparing the `UndoBehavior` of the
current and previous edit, we can decide whether these changes should
be grouped together on the undo stack.

Chains of repeated backspace, delete, insertion, or history naviagition
can each be grouped together to form a single undo entry when
appropriate.

* Removing low-usage wrapper methods from editor.rs

Removes LineBuffer wrappers from Editor wherever the wrapper is used
only once, or only internally to the `editor.rs` file.

* Run cargo fmt

* Fixed undo coalescing for backspace/delete with \n

The logic was a bit trickier than I thought. Added some tests
to confirm the intended behavior where adding/deleting newlines creates
additional undo points

* Remove debugging logging code

* Revert "Removing low-usage wrapper methods from editor.rs"

- Also revert reintroduction of `CutFromStart` bug in vi mode
8b5e70fc0e

* Fix undo coalescing for CRLF deletions

* Ensure proper undo tracking in public Editor fns

Delete or make private all Editor functions that modify the line buffer
without tracking UndoBehavior

* Make Editor crate level pub

Added documentation for pub methods on Editor. Kept the public API
smaller by making many convenience methods pub(crate) if they can be
implemented via the pub methods

* Cleanup changes

* word_starts and word_ends functions no longer needed with current
  word-level undo tracking algorithm
* `undo` and `redo` don't need to call `update_undo_behavior` because they are
  private methods and `run_edit_command` already calls `update_undo_behavior`

* Fix for new clippy warning

* Editor+LineBuffer API updates for nushell merge

* Make `LineBuffer::replace_range` pub rather than pub(crate)
* Make `Editor::set_line_buffer` and `Editor::set_buffer` pub(crate) in
  favor of the new `Editor::edit_buffer`.

I believe the `edit_buffer` change is a better API to expose for
`Menu` implementations, as it avoids the need for `clones` while
enforcing proper undo tracking.
2022-08-15 00:09:06 +02:00
Stefan Holderbach
f41a5c2605
Clippy fix for tests (#462) 2022-08-14 19:51:18 +02:00
morzel85
e72f927db3
Ctrl+h edit binding moved from emacs to common (#461) 2022-08-10 15:12:59 +02:00
Stefan Holderbach
d29730a809
Export the crossterm key types (#457)
Export `crossterm::event::{KeyCode, KeyModifiers}` as our own.
This way users of the library don't have to import crossterm with the
same version explicitly to set their own keybindings.

Closes #456
2022-08-03 11:52:01 +02:00
bnprks
b750db6516
Vi mode add support for d0, d^, c0, and c^ (#459)
* Vi mode add support for d0, d^, c0, and c^

Also changes d$ to delete just current line for
multiline inputs

* Make `d0` line aware

* Make `c0` line aware

Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com>
2022-08-03 11:49:36 +02:00
Stefan Holderbach
f4aa6921b4
Reduce dev-deps by narrowing rstest features (#458)
`rstest = 0.12` added support for asynchronous timeouts during testing
thus requiring a larger set of dependencies. Since `rstest = 0.14` this
can be disabled if not used.

Should keep build times for local or CI tests in check.
2022-08-03 11:47:17 +02:00
Darren Schroeder
770faebfe0
update gitignore (#455) 2022-07-30 08:03:46 -05:00
Stefan Holderbach
a406bfc662
Update crossterm to 0.24 (#447)
This new crossterm version includes a breaking change to the indexing of
certain cursor move operations:

https://github.com/crossterm-rs/crossterm/releases/tag/0.24

While reedline itself might not be affected, check the code of the
consuming application that needs to match the crossterm version!
2022-07-28 23:09:32 +02:00
JT
a535eda62b
bump to 0.9 (#454) 2022-07-27 06:49:02 +12:00
Darren Schroeder
2e7483fe4d
update some deps (#453) 2022-07-25 20:32:57 -05:00
Eric Hodel
79e7d8da92
Support switching the case of a char with ~ in vi (#452)
> Switch case of the character under the cursor and move the cursor to
> the right.

vi behavior is to only swap the case of an ASCII character so this is
implementation matches that behavior
2022-07-13 10:31:40 +02:00
JT
59f7144d72
remove anims and resize repaint (#451) 2022-07-12 13:06:46 +12:00
Eric Hodel
5ec17664af
Support vi mode ; and , motions (#450)
* Support vi mode ; and , motions

The f, F, t, and T left-right motions can be repeated with the ; motion,
or reversed with the , motion:

> ;    Repeat latest f, t, F or T [count] times. See cpo-;
>
> ,    Repeat latest f, t, F or T in opposite direction
>      [count] times. See also cpo-;

I named these "to-till" motions as the first word of the description for
the f and T motions are "To" and "Till" respectively.

Add storage for the last To or Till motion on the `Vi` struct, and pass
it through to `parse_command()` so `;` or `,` can re-use it.

When a to-till motion is fully parsed the new to-till motion is stored
in the `Vi` struct.

* Correctly implement ,

The last to or till motion should be recorded from f, F, t, or T.
Using , to reverse the to/till motion must not change the motion that
will be replayed.

In other words, if you f to move to the right then pressing , will only
move you left.  Pressing , will not swap between the two matching
characters your cursor is on or between.

* Fix clippy
2022-07-12 07:46:17 +12:00
Stefan Holderbach
117f13b005
Prepare the 0.8.0 release (#448) 2022-07-05 10:38:36 +02:00
Eric Hodel
64476ca5af
Add vi r (replace) (#442)
This is an incomplete implementation as it omits the behaviors for
CTRL-V, CTRL-E, and CTRL-Y:

> Replace the character under the cursor with {char}. If {char} is a
> <CR> or <NL>, a line break replaces the character.  To replace with a
> real <CR>, use CTRL-V <CR>.  CTRL-V <NL> replaces with a <Nul>.
>
> If {char} is CTRL-E or CTRL-Y the character from the line below or
> above is used, just like with |i_CTRL-E| and |i_CTRL-Y|.  This also
> works with a count, thus `10r<C-E>` copies 10 characters from the line
> below.

The similarly-named ReplaceChars is used for history substitution and
is more complicated than we need (n_chars will always be 1, string will
always be a single character string), but could be used if the extra
replace_char() function is too much.
2022-07-05 09:30:48 +02:00
nibon7
13ff774bcc
Avoid subtraction overflow when using usize. (#446)
Fixes nushell/nushell#5854

Signed-off-by: nibon7 <nibon7@163.com>
2022-06-25 12:29:44 +02:00
WindSoilder
d57867a411
introduce LastCommand variant for parse bang result (#445)
* introduce LastCommand variant for parse bang result

* fix ut
2022-06-17 19:17:55 -05:00
WindSoilder
2aaa58f93a
fix double bang (#444) 2022-06-17 10:57:42 -05:00
Darren Schroeder
680bc7a162
add impl Display to HistoryItemId and HistorySessionId (#443) 2022-06-17 08:38:32 -05:00
Eric Hodel
0680bb584a
Add vi WORD motions B, E, W (#441)
* Add vi W motion

This moves forward by WORD which is a sequence of non-blank characters
separated by whitespace.

* Add vi B motion

Support deleting backward for word (db) and WORD (dB)

* Add vi E motion
2022-06-16 11:58:19 +02:00