mirror of
https://github.com/nushell/nushell.git
synced 2025-01-31 02:32:55 +01:00
Accomodate reedline#270 (#863)
Rename `ContextMenu` to `CompletionMenu` Supply the completer directly to the line editor
This commit is contained in:
parent
9926561dd7
commit
bfb9822475
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -2863,7 +2863,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "reedline"
|
name = "reedline"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
source = "git+https://github.com/nushell/reedline?branch=main#c0ec7dc2fd4181c11065f7e19c59fed2ffc83653"
|
source = "git+https://github.com/nushell/reedline?branch=main#d10a2e7bcb8f3bef2ca349617c19e9504a8e5117"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"crossterm",
|
"crossterm",
|
||||||
|
@ -1,34 +1,26 @@
|
|||||||
use crossterm::event::{KeyCode, KeyModifiers};
|
use crossterm::event::{KeyCode, KeyModifiers};
|
||||||
use nu_cli::NuCompleter;
|
|
||||||
use nu_color_config::lookup_ansi_color_style;
|
use nu_color_config::lookup_ansi_color_style;
|
||||||
use nu_protocol::{
|
use nu_protocol::{extract_value, Config, ParsedKeybinding, ShellError, Span, Type, Value};
|
||||||
engine::EngineState, extract_value, Config, ParsedKeybinding, ShellError, Span, Type, Value,
|
|
||||||
};
|
|
||||||
use reedline::{
|
use reedline::{
|
||||||
default_emacs_keybindings, default_vi_insert_keybindings, default_vi_normal_keybindings,
|
default_emacs_keybindings, default_vi_insert_keybindings, default_vi_normal_keybindings,
|
||||||
ContextMenu, EditCommand, HistoryMenu, Keybindings, Reedline, ReedlineEvent,
|
CompletionMenu, EditCommand, HistoryMenu, Keybindings, Reedline, ReedlineEvent,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Creates an input object for the context menu based on the dictionary
|
// Creates an input object for the completion menu based on the dictionary
|
||||||
// stored in the config variable
|
// stored in the config variable
|
||||||
pub(crate) fn add_context_menu(
|
pub(crate) fn add_completion_menu(line_editor: Reedline, config: &Config) -> Reedline {
|
||||||
line_editor: Reedline,
|
let mut completion_menu = CompletionMenu::default();
|
||||||
engine_state: &EngineState,
|
|
||||||
config: &Config,
|
|
||||||
) -> Reedline {
|
|
||||||
let mut context_menu = ContextMenu::default();
|
|
||||||
context_menu = context_menu.with_completer(Box::new(NuCompleter::new(engine_state.clone())));
|
|
||||||
|
|
||||||
context_menu = match config
|
completion_menu = match config
|
||||||
.menu_config
|
.menu_config
|
||||||
.get("columns")
|
.get("columns")
|
||||||
.and_then(|value| value.as_integer().ok())
|
.and_then(|value| value.as_integer().ok())
|
||||||
{
|
{
|
||||||
Some(value) => context_menu.with_columns(value as u16),
|
Some(value) => completion_menu.with_columns(value as u16),
|
||||||
None => context_menu,
|
None => completion_menu,
|
||||||
};
|
};
|
||||||
|
|
||||||
context_menu = context_menu.with_column_width(
|
completion_menu = completion_menu.with_column_width(
|
||||||
config
|
config
|
||||||
.menu_config
|
.menu_config
|
||||||
.get("col_width")
|
.get("col_width")
|
||||||
@ -36,43 +28,43 @@ pub(crate) fn add_context_menu(
|
|||||||
.map(|value| value as usize),
|
.map(|value| value as usize),
|
||||||
);
|
);
|
||||||
|
|
||||||
context_menu = match config
|
completion_menu = match config
|
||||||
.menu_config
|
.menu_config
|
||||||
.get("col_padding")
|
.get("col_padding")
|
||||||
.and_then(|value| value.as_integer().ok())
|
.and_then(|value| value.as_integer().ok())
|
||||||
{
|
{
|
||||||
Some(value) => context_menu.with_column_padding(value as usize),
|
Some(value) => completion_menu.with_column_padding(value as usize),
|
||||||
None => context_menu,
|
None => completion_menu,
|
||||||
};
|
};
|
||||||
|
|
||||||
context_menu = match config
|
completion_menu = match config
|
||||||
.menu_config
|
.menu_config
|
||||||
.get("text_style")
|
.get("text_style")
|
||||||
.and_then(|value| value.as_string().ok())
|
.and_then(|value| value.as_string().ok())
|
||||||
{
|
{
|
||||||
Some(value) => context_menu.with_text_style(lookup_ansi_color_style(&value)),
|
Some(value) => completion_menu.with_text_style(lookup_ansi_color_style(&value)),
|
||||||
None => context_menu,
|
None => completion_menu,
|
||||||
};
|
};
|
||||||
|
|
||||||
context_menu = match config
|
completion_menu = match config
|
||||||
.menu_config
|
.menu_config
|
||||||
.get("selected_text_style")
|
.get("selected_text_style")
|
||||||
.and_then(|value| value.as_string().ok())
|
.and_then(|value| value.as_string().ok())
|
||||||
{
|
{
|
||||||
Some(value) => context_menu.with_selected_text_style(lookup_ansi_color_style(&value)),
|
Some(value) => completion_menu.with_selected_text_style(lookup_ansi_color_style(&value)),
|
||||||
None => context_menu,
|
None => completion_menu,
|
||||||
};
|
};
|
||||||
|
|
||||||
context_menu = match config
|
completion_menu = match config
|
||||||
.menu_config
|
.menu_config
|
||||||
.get("marker")
|
.get("marker")
|
||||||
.and_then(|value| value.as_string().ok())
|
.and_then(|value| value.as_string().ok())
|
||||||
{
|
{
|
||||||
Some(value) => context_menu.with_marker(value),
|
Some(value) => completion_menu.with_marker(value),
|
||||||
None => context_menu,
|
None => completion_menu,
|
||||||
};
|
};
|
||||||
|
|
||||||
line_editor.with_menu(Box::new(context_menu))
|
line_editor.with_menu(Box::new(completion_menu))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates an input object for the history menu based on the dictionary
|
// Creates an input object for the history menu based on the dictionary
|
||||||
@ -151,7 +143,7 @@ fn add_menu_keybindings(keybindings: &mut Keybindings) {
|
|||||||
KeyModifiers::NONE,
|
KeyModifiers::NONE,
|
||||||
KeyCode::Tab,
|
KeyCode::Tab,
|
||||||
ReedlineEvent::UntilFound(vec![
|
ReedlineEvent::UntilFound(vec![
|
||||||
ReedlineEvent::Menu("context_menu".to_string()),
|
ReedlineEvent::Menu("completion_menu".to_string()),
|
||||||
ReedlineEvent::MenuNext,
|
ReedlineEvent::MenuNext,
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use std::{sync::atomic::Ordering, time::Instant};
|
use std::{sync::atomic::Ordering, time::Instant};
|
||||||
|
|
||||||
use crate::reedline_config::{add_context_menu, add_history_menu};
|
use crate::reedline_config::{add_completion_menu, add_history_menu};
|
||||||
use crate::{config_files, prompt_update, reedline_config};
|
use crate::{config_files, prompt_update, reedline_config};
|
||||||
use crate::{
|
use crate::{
|
||||||
reedline_config::KeybindingsMode,
|
reedline_config::KeybindingsMode,
|
||||||
@ -8,7 +8,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use log::trace;
|
use log::trace;
|
||||||
use miette::{IntoDiagnostic, Result};
|
use miette::{IntoDiagnostic, Result};
|
||||||
use nu_cli::{NuHighlighter, NuValidator, NushellPrompt};
|
use nu_cli::{NuCompleter, NuHighlighter, NuValidator, NushellPrompt};
|
||||||
use nu_color_config::get_color_config;
|
use nu_color_config::get_color_config;
|
||||||
use nu_engine::convert_env_values;
|
use nu_engine::convert_env_values;
|
||||||
use nu_parser::lex;
|
use nu_parser::lex;
|
||||||
@ -106,9 +106,10 @@ pub(crate) fn evaluate(engine_state: &mut EngineState) -> Result<()> {
|
|||||||
.with_validator(Box::new(NuValidator {
|
.with_validator(Box::new(NuValidator {
|
||||||
engine_state: engine_state.clone(),
|
engine_state: engine_state.clone(),
|
||||||
}))
|
}))
|
||||||
|
.with_completer(Box::new(NuCompleter::new(engine_state.clone())))
|
||||||
.with_ansi_colors(config.use_ansi_coloring);
|
.with_ansi_colors(config.use_ansi_coloring);
|
||||||
|
|
||||||
line_editor = add_context_menu(line_editor, engine_state, &config);
|
line_editor = add_completion_menu(line_editor, &config);
|
||||||
line_editor = add_history_menu(line_editor, &config);
|
line_editor = add_history_menu(line_editor, &config);
|
||||||
|
|
||||||
//FIXME: if config.use_ansi_coloring is false then we should
|
//FIXME: if config.use_ansi_coloring is false then we should
|
||||||
|
Loading…
Reference in New Issue
Block a user