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 nu_ansi_term::Style;
use reedline::{
default_emacs_keybindings, DefaultPrompt, EditCommand, Emacs, Highlighter, Reedline,
ReedlineEvent, Signal, SqliteBackedHistory, StyledText,
default_emacs_keybindings, DefaultPrompt, DefaultPromptSegment, EditCommand, Emacs,
Highlighter, Reedline, ReedlineEvent, Signal, SqliteBackedHistory, StyledText,
};
use std::{fs::read_to_string, path::PathBuf};
@ -172,27 +172,30 @@ impl Highlighter for DustHighlighter {
fn run_shell(context: Map) -> Result<()> {
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();
keybindings.add_binding(
KeyModifiers::NONE,
KeyCode::Enter,
KeyModifiers::CONTROL,
KeyCode::Char(' '),
ReedlineEvent::Edit(vec![EditCommand::InsertNewline]),
);
keybindings.add_binding(
KeyModifiers::CONTROL,
KeyCode::Char(' '),
ReedlineEvent::Submit,
);
keybindings.add_binding(
KeyModifiers::NONE,
KeyCode::Tab,
ReedlineEvent::UntilFound(vec![
ReedlineEvent::Menu("completion_menu".to_string()),
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 history = Box::new(

View File

@ -9,11 +9,10 @@ Simple Command
(root
(statement
(expression
(command
(command_text)))))
(command))))
================================================================================
Nested Command
Command Sequence
================================================================================
*less *ls
@ -23,17 +22,16 @@ Nested Command
(root
(statement
(expression
(command
(command_text)
(command_text)))))
(command)))
(statement
(expression
(command))))
================================================================================
Command with Arguments
================================================================================
*ls --long -a;
(*git status)
*git log;
*ls --long -a
--------------------------------------------------------------------------------
@ -41,19 +39,15 @@ Command with Arguments
(statement
(expression
(command
(command_text)
(command_text)
(command_text)
(command_text)
(command_text)
(command_text)
(command_text)))))
(command_argument)
(command_argument)))))
================================================================================
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
(expression
(command
(command_text)
(command_text)
(command_text)
(command_text)))))
(command_argument)
(command_argument)
(command_argument)
(command_argument))))
(statement
(expression
(command
(command_argument)
(command_argument)))))

View File

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

View File

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

View File

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

View File

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

File diff suppressed because it is too large Load Diff