Skip to content

Commit fce391b

Browse files
authored
Merge branch 'main' into history_size
2 parents f56a7ec + ef7b96c commit fce391b

29 files changed

+384
-264
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
run: cargo fmt --all -- --check
4545

4646
- name: Clippy
47-
run: cargo clippy ${{ matrix.flags }} --all -- -D warnings
47+
run: cargo clippy ${{ matrix.flags }} --all-targets --all -- -D warnings
4848

4949

5050
- name: Tests

.typos.toml

+2
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ extend-exclude = ["src/core_editor/line_buffer.rs"]
66
iterm = "iterm"
77
# For testing completion of the word build
88
bui = "bui"
9+
# for sqlite backed history
10+
wheres = "wheres"

Cargo.lock

+4-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+19-3
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,22 @@ license = "MIT"
66
name = "reedline"
77
repository = "https://github.com/nushell/reedline"
88
rust-version = "1.62.1"
9-
version = "0.25.0"
9+
version = "0.28.0"
1010

1111
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1212
[lib]
1313
doctest = true
1414

1515
[dependencies]
16-
chrono = { version = "0.4.19", default-features = false, features = ["clock"] }
16+
chrono = { version = "0.4.19", default-features = false, features = [
17+
"clock",
18+
"serde",
19+
] }
1720
clipboard = { version = "0.5.0", optional = true }
1821
crossbeam = { version = "0.8.2", optional = true }
1922
crossterm = { version = "0.27.0", features = ["serde"] }
2023
fd-lock = "3.0.3"
21-
itertools = "0.10.3"
24+
itertools = "0.12.0"
2225
nu-ansi-term = "0.49.0"
2326
rusqlite = { version = "0.29.0", optional = true }
2427
serde = { version = "1.0", features = ["derive"] }
@@ -42,3 +45,16 @@ external_printer = ["crossbeam"]
4245
sqlite = ["rusqlite/bundled", "serde_json"]
4346
sqlite-dynlib = ["rusqlite", "serde_json"]
4447
system_clipboard = ["clipboard"]
48+
49+
[[example]]
50+
name = "cwd_aware_hinter"
51+
required-features = ["sqlite"]
52+
53+
[[example]]
54+
name = "external_printer"
55+
required-features = ["external_printer"]
56+
57+
[package.metadata.docs.rs]
58+
# Whether to pass `--all-features` to Cargo (default: false)
59+
all-features = false
60+
features = ["bashisms", "external_printer", "sqlite"]

examples/cwd_aware_hinter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ fn main() -> io::Result<()> {
5858

5959
let mut line_editor = Reedline::create()
6060
.with_hinter(Box::new(
61-
CwdAwareHinter::default().with_style(Style::new().italic().fg(Color::Yellow)),
61+
CwdAwareHinter::default().with_style(Style::new().bold().italic().fg(Color::Yellow)),
6262
))
6363
.with_history(history);
6464

examples/demo.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ use std::process::Command;
33
use {
44
crossterm::{
55
cursor::SetCursorStyle,
6-
event::{DisableBracketedPaste, KeyCode, KeyModifiers},
7-
execute,
6+
event::{KeyCode, KeyModifiers},
87
},
98
nu_ansi_term::{Color, Style},
109
reedline::{
@@ -13,7 +12,6 @@ use {
1312
EditCommand, EditMode, Emacs, ExampleHighlighter, Keybindings, ListMenu, Reedline,
1413
ReedlineEvent, ReedlineMenu, Signal, Vi,
1514
},
16-
std::io::stdout,
1715
};
1816

1917
use reedline::CursorConfig;
@@ -89,17 +87,14 @@ fn main() -> std::io::Result<()> {
8987
.with_quick_completions(true)
9088
.with_partial_completions(true)
9189
.with_cursor_config(cursor_config)
90+
.use_bracketed_paste(true)
91+
.use_kitty_keyboard_enhancement(true)
9292
.with_highlighter(Box::new(ExampleHighlighter::new(commands)))
9393
.with_hinter(Box::new(
9494
DefaultHinter::default().with_style(Style::new().fg(Color::DarkGray)),
9595
))
9696
.with_validator(Box::new(DefaultValidator))
9797
.with_ansi_colors(true);
98-
let res = line_editor.enable_bracketed_paste();
99-
let bracketed_paste_enabled = res.is_ok();
100-
if !bracketed_paste_enabled {
101-
println!("Warn: failed to enable bracketed paste mode: {res:?}");
102-
}
10398

10499
// Adding default menus for the compiled reedline
105100
line_editor = line_editor
@@ -226,9 +221,6 @@ fn main() -> std::io::Result<()> {
226221
}
227222
}
228223

229-
if bracketed_paste_enabled {
230-
let _ = execute!(stdout(), DisableBracketedPaste);
231-
}
232224
println!();
233225
Ok(())
234226
}

examples/external_printer.rs

-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// to run:
33
// cargo run --example external_printer --features=external_printer
44

5-
#[cfg(feature = "external_printer")]
65
use {
76
reedline::ExternalPrinter,
87
reedline::{DefaultPrompt, Reedline, Signal},
@@ -11,7 +10,6 @@ use {
1110
std::time::Duration,
1211
};
1312

14-
#[cfg(feature = "external_printer")]
1513
fn main() {
1614
let printer = ExternalPrinter::default();
1715
// make a clone to use it in a different thread
@@ -59,8 +57,3 @@ fn main() {
5957
break;
6058
}
6159
}
62-
63-
#[cfg(not(feature = "external_printer"))]
64-
fn main() {
65-
println!("Please enable the feature: ‘external_printer‘")
66-
}

src/completion/base.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ impl Span {
2424
}
2525
}
2626

27-
/// A trait that defines how to convert a line and position to a list of potential completions in that position.
27+
/// A trait that defines how to convert some text and a position to a list of potential completions in that position.
28+
/// The text could be a part of the whole line, and the position is the index of the end of the text in the original line.
2829
pub trait Completer: Send {
2930
/// the action that will take the line and position and convert it to a vector of completions, which include the
3031
/// span to replace and the contents of that replacement

src/completion/default.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,11 @@ impl Completer for DefaultCompleter {
7171
fn complete(&mut self, line: &str, pos: usize) -> Vec<Suggestion> {
7272
let mut span_line_whitespaces = 0;
7373
let mut completions = vec![];
74+
// Trimming in case someone passes in text containing stuff after the cursor, if
75+
// `only_buffer_difference` is false
76+
let line = if line.len() > pos { &line[..pos] } else { line };
7477
if !line.is_empty() {
75-
let mut split = line[0..pos].split(' ').rev();
78+
let mut split = line.split(' ').rev();
7679
let mut span_line: String = String::new();
7780
for _ in 0..split.clone().count() {
7881
if let Some(s) = split.next() {

src/completion/history.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ impl<'menu> HistoryCompleter<'menu> {
5252

5353
fn create_suggestion(&self, line: &str, pos: usize, value: &str) -> Suggestion {
5454
let span = Span {
55-
start: pos,
56-
end: pos + line.len(),
55+
start: pos - line.len(),
56+
end: pos,
5757
};
5858

5959
Suggestion {

src/edit_mode/vi/command.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,10 @@ impl Command {
210210
ReedlineOption::Edit(EditCommand::MoveToStart),
211211
ReedlineOption::Edit(EditCommand::ClearToLineEnd),
212212
]),
213-
Motion::NextWord => {
214-
Some(vec![ReedlineOption::Edit(EditCommand::CutWordRightToNext)])
213+
Motion::NextWord => Some(vec![ReedlineOption::Edit(EditCommand::CutWordRight)]),
214+
Motion::NextBigWord => {
215+
Some(vec![ReedlineOption::Edit(EditCommand::CutBigWordRight)])
215216
}
216-
Motion::NextBigWord => Some(vec![ReedlineOption::Edit(
217-
EditCommand::CutBigWordRightToNext,
218-
)]),
219217
Motion::NextWordEnd => {
220218
Some(vec![ReedlineOption::Edit(EditCommand::CutWordRight)])
221219
}

src/edit_mode/vi/parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl ParsedViSequence {
6767
///
6868
/// ### Note:
6969
///
70-
/// https://github.com/vim/vim/blob/140f6d0eda7921f2f0b057ec38ed501240903fc3/runtime/doc/motion.txt#L64-L70
70+
/// <https://github.com/vim/vim/blob/140f6d0eda7921f2f0b057ec38ed501240903fc3/runtime/doc/motion.txt#L64-L70>
7171
fn total_multiplier(&self) -> usize {
7272
self.multiplier.unwrap_or(1) * self.count.unwrap_or(1)
7373
}

0 commit comments

Comments
 (0)