Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

menu refactor #723

Merged
merged 29 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f98df65
get correct cursor pos when menu indicator contains newline
maxomatic458 Jan 19, 2024
b53ebc8
add tests
maxomatic458 Jan 19, 2024
425bb23
fix cursor pos in multiline prompt
maxomatic458 Jan 19, 2024
da5b239
make description mode enum public
maxomatic458 Jan 20, 2024
1f612dc
add doc comment
maxomatic458 Jan 20, 2024
070d600
respect windows newline in update_values
maxomatic458 Jan 20, 2024
75bdae3
Revert "respect windows newline in update_values"
maxomatic458 Jan 20, 2024
8ebc6fe
Merge branch 'main' of https://github.com/maxomatic458/reedline
maxomatic458 Jan 21, 2024
36245bc
add complete_with_base_ranges to Completer
maxomatic458 Jan 22, 2024
5f65d77
add builder for correct_cursor_pos
maxomatic458 Jan 22, 2024
ce4bf9a
add config options to completion examples
maxomatic458 Jan 22, 2024
bf42db0
Merge branch 'main' of https://github.com/maxomatic458/reedline
maxomatic458 Jan 24, 2024
a5fbf9e
add style to ide menu
maxomatic458 Jan 25, 2024
3f0dd62
run fmt
maxomatic458 Jan 25, 2024
62726f2
start menu refactor
maxomatic458 Jan 25, 2024
65c3241
Revert "start menu refactor"
maxomatic458 Jan 25, 2024
e369e09
start menu refactor
maxomatic458 Jan 26, 2024
7d39fc8
Merge branch 'main' of https://github.com/maxomatic458/reedline
maxomatic458 Jan 26, 2024
d02400f
Merge branch 'main' into menu-refactor
maxomatic458 Jan 26, 2024
824b41a
fix ci
maxomatic458 Jan 26, 2024
dc6ccff
Merge branch 'main' of https://github.com/maxomatic458/reedline
maxomatic458 Jan 26, 2024
7082ad8
use MenuSettings struct
maxomatic458 Jan 27, 2024
cf9f6dc
Merge branch 'menu-refactor'
maxomatic458 Jan 27, 2024
23a0781
add test case for unix newline
maxomatic458 Jan 27, 2024
43bb16c
more tests
maxomatic458 Jan 27, 2024
0493c0d
fix newline replace
maxomatic458 Jan 27, 2024
d6ab845
add explicit panic to stay backwards compatible
maxomatic458 Jan 27, 2024
95e1558
fix ci
maxomatic458 Jan 27, 2024
37268ed
Update columnar_menu.rs
maxomatic458 Jan 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use reedline::{
default_emacs_keybindings, ColumnarMenu, DefaultCompleter, DefaultPrompt, EditCommand, Emacs,
KeyCode, KeyModifiers, Keybindings, Reedline, ReedlineEvent, ReedlineMenu, Signal,
KeyCode, KeyModifiers, Keybindings, MenuBuilder, Reedline, ReedlineEvent, ReedlineMenu, Signal,
};
use std::io;

Expand Down
2 changes: 1 addition & 1 deletion examples/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ use {
},
};

use reedline::CursorConfig;
#[cfg(not(any(feature = "sqlite", feature = "sqlite-dynlib")))]
use reedline::FileBackedHistory;
use reedline::{CursorConfig, MenuBuilder};

fn main() -> reedline::Result<()> {
println!("Ctrl-D to quit");
Expand Down
4 changes: 2 additions & 2 deletions examples/ide_completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

use reedline::{
default_emacs_keybindings, DefaultCompleter, DefaultPrompt, DescriptionMode, EditCommand,
Emacs, IdeMenu, KeyCode, KeyModifiers, Keybindings, Reedline, ReedlineEvent, ReedlineMenu,
Signal,
Emacs, IdeMenu, KeyCode, KeyModifiers, Keybindings, MenuBuilder, Reedline, ReedlineEvent,
ReedlineMenu, Signal,
};
use std::io;

Expand Down
2 changes: 1 addition & 1 deletion examples/transient_prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use nu_ansi_term::{Color, Style};
use reedline::SqliteBackedHistory;
use reedline::{
default_emacs_keybindings, ColumnarMenu, DefaultCompleter, DefaultHinter, DefaultPrompt, Emacs,
ExampleHighlighter, KeyCode, KeyModifiers, Keybindings, Prompt, PromptEditMode,
ExampleHighlighter, KeyCode, KeyModifiers, Keybindings, MenuBuilder, Prompt, PromptEditMode,
PromptHistorySearch, PromptHistorySearchStatus, Reedline, ReedlineEvent, ReedlineMenu, Signal,
ValidationResult, Validator,
};
Expand Down
13 changes: 9 additions & 4 deletions src/completion/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ impl Completer for DefaultCompleter {
/// ]);
///
/// assert_eq!(
/// completions.complete("to the bat",10),
/// completions.complete("to the\r\nbat",11),
/// vec![
/// Suggestion {value: "batcave".into(), description: None, style: None, extra: None, span: Span { start: 7, end: 10 }, append_whitespace: false},
/// Suggestion {value: "batman".into(), description: None, style: None, extra: None, span: Span { start: 7, end: 10 }, append_whitespace: false},
/// Suggestion {value: "batmobile".into(), description: None, style: None, extra: None, span: Span { start: 7, end: 10 }, append_whitespace: false},
/// Suggestion {value: "batcave".into(), description: None, style: None, extra: None, span: Span { start: 8, end: 11 }, append_whitespace: false},
/// Suggestion {value: "batman".into(), description: None, style: None, extra: None, span: Span { start: 8, end: 11 }, append_whitespace: false},
/// Suggestion {value: "batmobile".into(), description: None, style: None, extra: None, span: Span { start: 8, end: 11 }, append_whitespace: false},
/// ]);
/// ```
fn complete(&mut self, line: &str, pos: usize) -> Vec<Suggestion> {
Expand All @@ -75,6 +75,10 @@ impl Completer for DefaultCompleter {
// `only_buffer_difference` is false
let line = if line.len() > pos { &line[..pos] } else { line };
if !line.is_empty() {
// When editing a multiline buffer, there can be new line characters in it.
// Also, by replacing the new line character with a space, the insert
// position is maintain in the line buffer.
let line = line.replace("\r\n", " ").replace('\n', " ");
let mut split = line.split(' ').rev();
let mut span_line: String = String::new();
for _ in 0..split.clone().count() {
Expand Down Expand Up @@ -119,6 +123,7 @@ impl Completer for DefaultCompleter {
completions
}
}

impl DefaultCompleter {
/// Construct the default completer with a list of commands/keywords to highlight
pub fn new(external_commands: Vec<String>) -> Self {
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
//! ```rust
//! // Create a reedline object with tab completions support
//!
//! use reedline::{default_emacs_keybindings, ColumnarMenu, DefaultCompleter, Emacs, KeyCode, KeyModifiers, Reedline, ReedlineEvent, ReedlineMenu};
//! use reedline::{default_emacs_keybindings, ColumnarMenu, DefaultCompleter, Emacs, KeyCode, KeyModifiers, Reedline, ReedlineEvent, ReedlineMenu, MenuBuilder};
//!
//! let commands = vec![
//! "test".into(),
Expand Down Expand Up @@ -277,8 +277,8 @@ pub use validator::{DefaultValidator, ValidationResult, Validator};

mod menu;
pub use menu::{
menu_functions, ColumnarMenu, DescriptionMode, IdeMenu, ListMenu, Menu, MenuEvent,
MenuTextStyle, ReedlineMenu,
menu_functions, ColumnarMenu, DescriptionMenu, DescriptionMode, IdeMenu, ListMenu, Menu,
MenuBuilder, MenuEvent, MenuTextStyle, ReedlineMenu,
};

mod terminal_extensions;
Expand Down
Loading
Loading