Fix command syntax; Modify shell prompt

This commit is contained in:
Jeff 2024-01-26 15:10:46 -05:00
parent 54790bc0db
commit c2fc3362c8
7 changed files with 21022 additions and 20713 deletions

View File

@ -4,8 +4,8 @@ use clap::{Parser, Subcommand};
use crossterm::event::{KeyCode, KeyModifiers}; use crossterm::event::{KeyCode, KeyModifiers};
use nu_ansi_term::Style; use nu_ansi_term::Style;
use reedline::{ use reedline::{
default_emacs_keybindings, DefaultPrompt, EditCommand, Emacs, Highlighter, Reedline, default_emacs_keybindings, DefaultPrompt, DefaultPromptSegment, EditCommand, Emacs,
ReedlineEvent, Signal, SqliteBackedHistory, StyledText, Highlighter, Reedline, ReedlineEvent, Signal, SqliteBackedHistory, StyledText,
}; };
use std::{fs::read_to_string, path::PathBuf}; use std::{fs::read_to_string, path::PathBuf};
@ -172,27 +172,30 @@ impl Highlighter for DustHighlighter {
fn run_shell(context: Map) -> Result<()> { fn run_shell(context: Map) -> Result<()> {
let mut interpreter = Interpreter::new(context.clone()); let mut interpreter = Interpreter::new(context.clone());
let prompt = DefaultPrompt::default(); let mut prompt = DefaultPrompt::default();
prompt.left_prompt = DefaultPromptSegment::Basic(">".to_string());
let mut keybindings = default_emacs_keybindings(); let mut keybindings = default_emacs_keybindings();
keybindings.add_binding( keybindings.add_binding(
KeyModifiers::NONE, KeyModifiers::CONTROL,
KeyCode::Enter, KeyCode::Char(' '),
ReedlineEvent::Edit(vec![EditCommand::InsertNewline]), ReedlineEvent::Edit(vec![EditCommand::InsertNewline]),
); );
keybindings.add_binding( keybindings.add_binding(
KeyModifiers::CONTROL, KeyModifiers::CONTROL,
KeyCode::Char(' '),
ReedlineEvent::Submit,
);
keybindings.add_binding(
KeyModifiers::NONE,
KeyCode::Tab, KeyCode::Tab,
ReedlineEvent::UntilFound(vec![ ReedlineEvent::UntilFound(vec![
ReedlineEvent::Menu("completion_menu".to_string()), ReedlineEvent::Menu("completion_menu".to_string()),
ReedlineEvent::MenuNext, ReedlineEvent::MenuNext,
]), ]),
); );
keybindings.add_binding(
KeyModifiers::NONE,
KeyCode::Tab,
ReedlineEvent::Edit(vec![EditCommand::InsertString(" ".to_string())]),
);
let edit_mode = Box::new(Emacs::new(keybindings)); let edit_mode = Box::new(Emacs::new(keybindings));
let history = Box::new( let history = Box::new(

View File

@ -9,11 +9,10 @@ Simple Command
(root (root
(statement (statement
(expression (expression
(command (command))))
(command_text)))))
================================================================================ ================================================================================
Nested Command Command Sequence
================================================================================ ================================================================================
*less *ls *less *ls
@ -23,17 +22,16 @@ Nested Command
(root (root
(statement (statement
(expression (expression
(command (command)))
(command_text) (statement
(command_text))))) (expression
(command))))
================================================================================ ================================================================================
Command with Arguments Command with Arguments
================================================================================ ================================================================================
*ls --long -a; *ls --long -a
(*git status)
*git log;
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -41,19 +39,15 @@ Command with Arguments
(statement (statement
(expression (expression
(command (command
(command_text) (command_argument)
(command_text) (command_argument)))))
(command_text)
(command_text)
(command_text)
(command_text)
(command_text)))))
================================================================================ ================================================================================
Nested Command with Arguments Command Sequence with Arguments
================================================================================ ================================================================================
*less *ls --long -a *cargo run -- -c "output('hi there')"
*ls --long -a
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -61,7 +55,12 @@ Nested Command with Arguments
(statement (statement
(expression (expression
(command (command
(command_text) (command_argument)
(command_text) (command_argument)
(command_text) (command_argument)
(command_text))))) (command_argument))))
(statement
(expression
(command
(command_argument)
(command_argument)))))

View File

@ -9,10 +9,8 @@ Simple Command Pipe
(root (root
(statement (statement
(pipe (pipe
(command (command)
(command_text)) (command))))
(command
(command_text)))))
================================================================================ ================================================================================
Simple Function Pipe Simple Function Pipe

View File

@ -86,13 +86,14 @@ module.exports = grammar({
prec.right( prec.right(
seq( seq(
'*', '*',
repeat($.command_text), /\S+/,
repeat($.command_argument),
), ),
), ),
command_text: $ => command_argument: $ =>
choice( choice(
/\S+/, /[^*\s]+/,
/("[^"]*?")|('[^']*?')|(`[^`]*?`)/, /("[^"]*?")|('[^']*?')|(`[^`]*?`)/,
), ),

View File

@ -235,22 +235,26 @@
"type": "STRING", "type": "STRING",
"value": "*" "value": "*"
}, },
{
"type": "PATTERN",
"value": "\\S+"
},
{ {
"type": "REPEAT", "type": "REPEAT",
"content": { "content": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "command_text" "name": "command_argument"
} }
} }
] ]
} }
}, },
"command_text": { "command_argument": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
"type": "PATTERN", "type": "PATTERN",
"value": "\\S+" "value": "[^*\\s]+"
}, },
{ {
"type": "PATTERN", "type": "PATTERN",

View File

@ -65,14 +65,14 @@
"required": false, "required": false,
"types": [ "types": [
{ {
"type": "command_text", "type": "command_argument",
"named": true "named": true
} }
] ]
} }
}, },
{ {
"type": "command_text", "type": "command_argument",
"named": true, "named": true,
"fields": {} "fields": {}
}, },

File diff suppressed because it is too large Load Diff