Commit Graph

366 Commits

Author SHA1 Message Date
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
Stefan Holderbach
f14583526a
Prepare 0.7.0 release (#440)
Includes the new History API and their backends
2022-06-14 22:46:04 +02:00
Stefan Holderbach
12dc30ce0a
Expose the History query functionality (#439)
Makes the history querying structs and enums pub as it seems reasonable
for now. Useful to create nushells `history` command.

Might make sense to change that API to something simpler cleaner later.
2022-06-14 16:16:54 +02:00
phiresky
4f25ce5633
SQLite History and replaceable History backends (#401)
Changes the history API to support different storage backends and more rich information to be used as metadata/filtering criterions.

Includes a SQLite backed history with additional fields and ports the simple `FileBackedHistory` format consistent.

Includes a `HistoryCursor` to abstract the internal interactive browsing.
Updates `History` trait to cover the API to load and store to the storage backend. 

Commits

* basic sqlite history

* fix test compilation

* final touches for MVP

* better documentation

* fix for empty history

* partial change to non-generic history

* mostly working

* fix tests and ci

* fixes, format

* move history item to new file

* fix some comments, fix test compile errors

todo: fix tests

* ci features matrix

* fix index creation

* fix file-based tests

* move logic for not saving empty entries to engine

* fix update last command on empty, set up application_id and check version

* add specific error variants

* format

* fix compile errors

* fix fmt

* sqlite with bashisms

* hide with features

* cargo fmt

* improve performance of bashisms selectors

* Style: Remove commented out code

Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
Co-authored-by: Fernando Herrera <fernando.j.herrera@gmail.com>
Co-authored-by: sholderbach <sholderbach@users.noreply.github.com>
2022-06-06 18:11:02 +02:00
Stefan Holderbach
09bbb24bfd
Update nu-ansi-term and crate patches (#437)
- Update `nu-ansi-term` to remove `Deref` impl
- General `cargo update`
2022-06-03 21:11:59 +02:00
Stefan Holderbach
265e59966c
Fix clippy lints that will become warnings (#435)
* Fix clippy lints that will become warnings

clippy from the nightly future

* Revent false positive `.to_string()` removal

This [lint](https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_to_owned) is nasty as `ansi_term` and thus `nu_ansi_term` on their `AnsiGenericString` implement `Display` to apply the styling and `Deref` to just return the underlying `&str`.
As [`ToString` is implemented for any `T: Display + ?Sized` ](https://doc.rust-lang.org/std/string/trait.ToString.html#impl-ToString-6) the to_string implementation relies on the `Display` defined for the type alias `AnsiString` and not on the `impl ToString for str` for the `&str` accessible through `Deref`.

Applying the suggested fix will remove syntax highlighting!!!
2022-06-03 10:47:43 +02:00
WindSoilder
59379bf5b4
Don't panic when parent directory does not exist (#436)
* don't panic whan parent directory is not exists

* no need to check parent exists

Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com>

Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com>
2022-06-03 10:46:27 +02:00
Artturi
a3dbc6232b
Move ctrl+a & ctrl+e to common navigation binds (#434)
* Move ctrl+a & ctrl+e to common navigation binds

* ctrl+w DeleteWord -> BackspaceWord

See fe795caabc (r74631178)
2022-05-29 17:00:35 +02:00
Stefan Holderbach
fe795caabc
Organize the common keybindings (#433)
Group the common keybindings into three functions:
- `add_common_control_bindings`
- `add_common_navigation_bindings`
- `add_common_edit_bindings`

Vi normal uses the first two
Vi insert uses all of them

Emacs extends upon those
2022-05-26 23:17:50 +02:00
Artturi
e7f1dab8f4
Move some commonly used keybinds to common keybinds (#432)
* Move ctrl+d keybinding from emacs to common keybinds
* Move ctrl+w keybinding from emacs to common keybinds
2022-05-26 22:00:10 +02:00
Stefan Holderbach
d8ff270f94
Prepare the v0.6.0 release (#430) 2022-05-23 23:59:07 +02:00
Stefan Holderbach
d2e0d320a9
Start developer documentation (#424)
Goals:

- Provide pointers to further reading for folks not too familiar with the
problem set on the terminal
- Explain the architecture a bit to get people up to speed
2022-05-23 23:14:17 +02:00
Dhruv Dhamani
4fedec4ad0
Support non-compliant terms with default size (#402)
if reported size is 0, 0 -
use a default size to avoid divide by 0 panics


Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com>
2022-05-23 23:13:45 +02:00
petrisch
28514478e3
Typo (#429)
Reedline has now... instead of Nushell has now...
2022-05-23 15:25:03 +02:00
ahkrr
c49845e3e0
fix: list_menu not accounting for index + indicator (#428)
The code didn't account for the index
and the indicator in its calculation for
the number of lines in the list_menu.
Now the unicode_width of the indicator and the
number of digits of the index are accountet for.
2022-05-23 12:58:07 +02:00
Stefan Holderbach
85daf4e4fc
Do not allocate eagerly for full history capacity (#427)
Amortized growing of the history based on the amount read from the file
is cheap. Allocating for the capacity is expensive and can cause OOM for
large capacities.

Fix for nushell/nushell#5593
2022-05-20 17:09:19 +02:00
Casey Dahlin
9b5d033dce
Fix vi-mode word motions (#425)
* Fix vi-mode word motions

The 'w' motion goes to the beginning of the next word to the right, not
the end. The 'e' motion, which is introduced here, goes to the end, but
lands on the last character, not after it.

* Add test case for `move_word_right_end`

Ensure Unicode safety as well as that the cursor will move to the next
word end when already at a word end

Co-authored-by: sholderbach <sholderbach@users.noreply.github.com>
2022-05-11 08:04:51 +02:00
Stefan Holderbach
ef6499202a
Prepare the 0.5.0 release (#421)
`Cargo.toml` version bump
2022-05-03 21:16:00 +02:00
Stefan Holderbach
33a91e53a2
Change keybinding for external editor (#422)
Current `Ctrl-i` is overloaded as `Tab` in the ASCII/ANSI world.

Use `Ctrl-o` (mnenomic "o"pen in editor) currently not bound to anything
2022-05-03 21:06:44 +02:00
Stefan Holderbach
3aaa776858
Fix README and lib.rs code examples (#419)
- Fix README and lib.rs code examples
  - Add missing doctests
  - Fix the completion example in README
  - Fix the edit mode example
- Try to run more of the doctests
  - They should not block with the IO loop or do file IO as this was failing the CI
2022-05-02 14:23:01 +02:00
Yuheng Su
29f30a8f79
Append whitespace after selecting menu (#410)
Adding a space when accepting a completion avoids rerunning the same already accepted completion when working with a space tokenized language like nushell

* Add append_whitespace choice for suggestion

Signed-off-by: gipsyh <gipsyh.icu@gmail.com>

* Update src/completion/base.rs

Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com>

* Update src/menu/columnar_menu.rs

Signed-off-by: gipsyh <gipsyh.icu@gmail.com>

Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com>
2022-05-02 11:13:38 +02:00
Stefan Holderbach
60b9b91e13
Add doctests back to the CI (#418)
`cargo nextest` currently doesn't support running the doctests.

Thus, add an additional job for them with cargo's default test runner.
2022-05-02 11:10:52 +02:00
Stefan Holderbach
2947a94fef
Vi additions and fixes by @zim0369 (#417)
- vim's 'S' binding
- copy char while deleting in vi mode
  - Fixes the behavior of `x` so the removed char/grapheme can be pasted with `p`
- vim's 's' binding
- Minor clarifications by @sholderbach 
  - Fix doccomments and clarify an enum variant's name

Rebased the commits from #406

Co-authored-by: zim0369 <zim@onionmail.org>
2022-05-02 00:15:35 +02:00
Stefan Holderbach
0311da5e83
Attempt fix of ClearScrollback (#416)
Clearing the scrollback did not work on most terminal emulators.
By reordering two ANSI control sequences, this seems to work on Linux
with most terminal emulators.
Due to a missing implementation of the exact details this will probably
not clear the scrollback under the old Windows API.

Related to the discussion in #120 and nushell/nushell#5089
2022-05-02 00:13:52 +02:00
Stefan Holderbach
23cbd8a74b
Fix the ci badge (#415) 2022-05-01 20:04:16 +02:00
Stefan Holderbach
e5c2709202
Change the CI to use caching (#414)
* Change the CI to use caching

This tries to replicate the cargo caching techniques developed by @rgwood on the [nushell](https://github.com/nushell/nushell) repo to save time (and energy) on the CI pipeline.

## Further reading:

[Reilly's blog post](https://www.reillywood.com/blog/rust-faster-ci/)

* Simplify to one job per build matrix combination

This should save some setup time.
And as rebuilds and tests of reedline are fast enough we can just be parallel over the feature
configurations.
2022-05-01 19:52:10 +02:00
Richard
43c495818f
Only partial complete suggestions when input is a prefix (#412)
* Add unit tests for can_partially_complete

* Add partial-completion-tests for fuzzy matches

* Partially complete only if the input is extended
2022-05-01 07:48:14 -05:00
Fernando Herrera
ed0e420083
change keybinding (#413) 2022-05-01 08:35:12 +01:00
Fernando Herrera
39c70136bb
line buffer editor (#411)
* line buffer editor

* corrected message in docstring

* formated example

* allow file extension for buffer

* change editor command
2022-04-30 15:09:43 +01:00
Invader Zim
229c729898
Add vim's C binding (#405)
`C` to change the content from the cursor to the end of the current line.
2022-04-20 14:05:26 +02:00
Stefan Holderbach
2e2bdc5462
Add better options for screen clearing (#400)
- Remove the `Signal::CtrlL` as it requires explicit handling and
cooperation but we offer configurable keybindings already
- Default keybinding of `Ctrl-l` is `ReedlineEvent::ClearScreen` that
directly performs the scrollback buffer preserving clear of the current
screen.
- Add `ReedlineEvent::ClearScrollback` to perform screen clearing with
removal of the scrollback buffer. (Demo will now do that on clear as
seen in bash, zsh etc.)

Fixes #120

Helps with nushell/nushell#5089
2022-04-20 10:10:58 +02:00
Stefan Holderbach
77344ebafb
Add explicit EditCommand::InsertNewline (#399)
Uses the system newline separator

Example in main with `Alt+Enter` (according to @fdncred `cmd-option-enter` or `shift-option-enter` on macOS to get the same key event)
2022-04-20 09:58:10 +02:00
Invader Zim
b8c7efc907
Implements vim's I prepend to start binding (#403)
* Implement vi's `I` normal mode binding to start insert mode at the lines start.

* Use `MoveToLineStart/End` instead to correctly work on lines

Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com>
2022-04-20 09:53:06 +02:00
sholderbach
2176424cec
Finalize v0.4.0 2022-04-12 11:39:54 +02:00
Stefan Holderbach
7aca406f13
Use better word definition (#396)
Follow UAX29: http://www.unicode.org/reports/tr29/#Word_Boundaries

This behavior is closer to VIs definition respecting identifiers and
respects special characters like fish

Fixes #346

Fixes #377
2022-04-12 11:33:37 +02:00