Skip to content

Commit

Permalink
Merge branch 'main' into history_size
Browse files Browse the repository at this point in the history
  • Loading branch information
andreistan26 authored Jan 12, 2024
2 parents f56a7ec + ef7b96c commit fce391b
Show file tree
Hide file tree
Showing 29 changed files with 384 additions and 264 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
run: cargo fmt --all -- --check

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


- name: Tests
Expand Down
2 changes: 2 additions & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ extend-exclude = ["src/core_editor/line_buffer.rs"]
iterm = "iterm"
# For testing completion of the word build
bui = "bui"
# for sqlite backed history
wheres = "wheres"
7 changes: 4 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 19 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@ license = "MIT"
name = "reedline"
repository = "https://github.com/nushell/reedline"
rust-version = "1.62.1"
version = "0.25.0"
version = "0.28.0"

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

[dependencies]
chrono = { version = "0.4.19", default-features = false, features = ["clock"] }
chrono = { version = "0.4.19", default-features = false, features = [
"clock",
"serde",
] }
clipboard = { version = "0.5.0", optional = true }
crossbeam = { version = "0.8.2", optional = true }
crossterm = { version = "0.27.0", features = ["serde"] }
fd-lock = "3.0.3"
itertools = "0.10.3"
itertools = "0.12.0"
nu-ansi-term = "0.49.0"
rusqlite = { version = "0.29.0", optional = true }
serde = { version = "1.0", features = ["derive"] }
Expand All @@ -42,3 +45,16 @@ external_printer = ["crossbeam"]
sqlite = ["rusqlite/bundled", "serde_json"]
sqlite-dynlib = ["rusqlite", "serde_json"]
system_clipboard = ["clipboard"]

[[example]]
name = "cwd_aware_hinter"
required-features = ["sqlite"]

[[example]]
name = "external_printer"
required-features = ["external_printer"]

[package.metadata.docs.rs]
# Whether to pass `--all-features` to Cargo (default: false)
all-features = false
features = ["bashisms", "external_printer", "sqlite"]
2 changes: 1 addition & 1 deletion examples/cwd_aware_hinter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn main() -> io::Result<()> {

let mut line_editor = Reedline::create()
.with_hinter(Box::new(
CwdAwareHinter::default().with_style(Style::new().italic().fg(Color::Yellow)),
CwdAwareHinter::default().with_style(Style::new().bold().italic().fg(Color::Yellow)),
))
.with_history(history);

Expand Down
14 changes: 3 additions & 11 deletions examples/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use std::process::Command;
use {
crossterm::{
cursor::SetCursorStyle,
event::{DisableBracketedPaste, KeyCode, KeyModifiers},
execute,
event::{KeyCode, KeyModifiers},
},
nu_ansi_term::{Color, Style},
reedline::{
Expand All @@ -13,7 +12,6 @@ use {
EditCommand, EditMode, Emacs, ExampleHighlighter, Keybindings, ListMenu, Reedline,
ReedlineEvent, ReedlineMenu, Signal, Vi,
},
std::io::stdout,
};

use reedline::CursorConfig;
Expand Down Expand Up @@ -89,17 +87,14 @@ fn main() -> std::io::Result<()> {
.with_quick_completions(true)
.with_partial_completions(true)
.with_cursor_config(cursor_config)
.use_bracketed_paste(true)
.use_kitty_keyboard_enhancement(true)
.with_highlighter(Box::new(ExampleHighlighter::new(commands)))
.with_hinter(Box::new(
DefaultHinter::default().with_style(Style::new().fg(Color::DarkGray)),
))
.with_validator(Box::new(DefaultValidator))
.with_ansi_colors(true);
let res = line_editor.enable_bracketed_paste();
let bracketed_paste_enabled = res.is_ok();
if !bracketed_paste_enabled {
println!("Warn: failed to enable bracketed paste mode: {res:?}");
}

// Adding default menus for the compiled reedline
line_editor = line_editor
Expand Down Expand Up @@ -226,9 +221,6 @@ fn main() -> std::io::Result<()> {
}
}

if bracketed_paste_enabled {
let _ = execute!(stdout(), DisableBracketedPaste);
}
println!();
Ok(())
}
Expand Down
7 changes: 0 additions & 7 deletions examples/external_printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// to run:
// cargo run --example external_printer --features=external_printer

#[cfg(feature = "external_printer")]
use {
reedline::ExternalPrinter,
reedline::{DefaultPrompt, Reedline, Signal},
Expand All @@ -11,7 +10,6 @@ use {
std::time::Duration,
};

#[cfg(feature = "external_printer")]
fn main() {
let printer = ExternalPrinter::default();
// make a clone to use it in a different thread
Expand Down Expand Up @@ -59,8 +57,3 @@ fn main() {
break;
}
}

#[cfg(not(feature = "external_printer"))]
fn main() {
println!("Please enable the feature: ‘external_printer‘")
}
3 changes: 2 additions & 1 deletion src/completion/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ impl Span {
}
}

/// A trait that defines how to convert a line and position to a list of potential completions in that position.
/// A trait that defines how to convert some text and a position to a list of potential completions in that position.
/// 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.
pub trait Completer: Send {
/// the action that will take the line and position and convert it to a vector of completions, which include the
/// span to replace and the contents of that replacement
Expand Down
5 changes: 4 additions & 1 deletion src/completion/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,11 @@ impl Completer for DefaultCompleter {
fn complete(&mut self, line: &str, pos: usize) -> Vec<Suggestion> {
let mut span_line_whitespaces = 0;
let mut completions = vec![];
// Trimming in case someone passes in text containing stuff after the cursor, if
// `only_buffer_difference` is false
let line = if line.len() > pos { &line[..pos] } else { line };
if !line.is_empty() {
let mut split = line[0..pos].split(' ').rev();
let mut split = line.split(' ').rev();
let mut span_line: String = String::new();
for _ in 0..split.clone().count() {
if let Some(s) = split.next() {
Expand Down
4 changes: 2 additions & 2 deletions src/completion/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ impl<'menu> HistoryCompleter<'menu> {

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

Suggestion {
Expand Down
8 changes: 3 additions & 5 deletions src/edit_mode/vi/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,10 @@ impl Command {
ReedlineOption::Edit(EditCommand::MoveToStart),
ReedlineOption::Edit(EditCommand::ClearToLineEnd),
]),
Motion::NextWord => {
Some(vec![ReedlineOption::Edit(EditCommand::CutWordRightToNext)])
Motion::NextWord => Some(vec![ReedlineOption::Edit(EditCommand::CutWordRight)]),
Motion::NextBigWord => {
Some(vec![ReedlineOption::Edit(EditCommand::CutBigWordRight)])
}
Motion::NextBigWord => Some(vec![ReedlineOption::Edit(
EditCommand::CutBigWordRightToNext,
)]),
Motion::NextWordEnd => {
Some(vec![ReedlineOption::Edit(EditCommand::CutWordRight)])
}
Expand Down
2 changes: 1 addition & 1 deletion src/edit_mode/vi/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl ParsedViSequence {
///
/// ### Note:
///
/// https://github.com/vim/vim/blob/140f6d0eda7921f2f0b057ec38ed501240903fc3/runtime/doc/motion.txt#L64-L70
/// <https://github.com/vim/vim/blob/140f6d0eda7921f2f0b057ec38ed501240903fc3/runtime/doc/motion.txt#L64-L70>
fn total_multiplier(&self) -> usize {
self.multiplier.unwrap_or(1) * self.count.unwrap_or(1)
}
Expand Down
Loading

0 comments on commit fce391b

Please sign in to comment.