Support comments in `skysh`

Also support multiline pasting in the interactive shell

Signed-off-by: Sayan Nandan <nandansayan@outlook.com>
next
Sayan Nandan 3 years ago
parent eb22456b18
commit 01ab66f64c
No known key found for this signature in database
GPG Key ID: 5EDED89A1ADA6273

@ -6,8 +6,11 @@ All changes in this project will be noted in this file.
### Improvements
- `skysh` now handles special character strings more reliably
- `skysh` now supports splitting a command across multiple lines
- `skysh`:
- handles special character strings more reliably
- now supports splitting a command across multiple lines
- now supports multi-line pastes
- now supports comments (beginning with `#`)
## Version 0.7.1

@ -57,19 +57,27 @@ macro_rules! inner_eval {
}
macro_rules! inner_repl {
($runner:expr) => {
($runner:expr, $lplt:lifetime) => {
println!("Skytable v{} | {}", VERSION, URL);
let mut editor = Editor::<()>::new();
editor.set_auto_add_history(true);
editor.set_history_ignore_dups(true);
editor.bind_sequence(
rustyline::KeyEvent(
rustyline::KeyCode::BracketedPasteStart,
rustyline::Modifiers::NONE,
),
rustyline::Cmd::Noop,
);
let _ = editor.load_history(SKYSH_HISTORY_FILE);
loop {
$lplt: loop {
match editor.readline(SKYSH_PROMPT) {
Ok(mut line) => match line.to_lowercase().as_str() {
"exit" => break,
"clear" => {
let mut stdout = stdout();
execute!(stdout, Clear(ClearType::All)).expect("Failed to clear screen");
execute!(stdout, Clear(ClearType::All))
.expect("Failed to clear screen");
execute!(stdout, cursor::MoveTo(0, 0))
.expect("Failed to move cursor to origin");
drop(stdout); // aggressively drop stdout
@ -79,11 +87,15 @@ macro_rules! inner_repl {
if line.is_empty() {
continue;
}
while line.len() >= 2 && line[line.len() - 2..].as_bytes().eq(br#" \"#) {
if (line.as_bytes()[0]) == b'#' {
continue;
}
while line.len() >= 2 && line[line.len() - 2..].as_bytes().eq(br#" \"#)
{
// continuation on next line
let cl = match editor.readline(SKYSH_BLANK) {
Ok(l) => l,
Err(ReadlineError::Interrupted) => break,
Err(ReadlineError::Interrupted) => break $lplt,
Err(err) => {
eprintln!("ERROR: Failed to read line with error: {}", err);
exit(1);
@ -138,7 +150,7 @@ pub async fn start_repl() {
let mut runner = Runner::new(con);
inner_eval!(runner, matches);
println!("Connected to skyhash-secure://{}:{}", host, port);
inner_repl!(runner);
inner_repl!(runner, 'tls);
} else {
let con = match AsyncConnection::new(host, port).await {
Ok(c) => c,
@ -150,7 +162,7 @@ pub async fn start_repl() {
let mut runner = Runner::new(con);
inner_eval!(runner, matches);
println!("Connected to skyhash://{}:{}", host, port);
inner_repl!(runner);
inner_repl!(runner, 'insecure);
}
println!("Goodbye!");
}

@ -77,7 +77,7 @@ macro_rules! write_binstr {
println!("{}", BinaryData($st));
};
($idx:ident, $st:ident) => {
println!("({}) {}", $idx, BinaryData($st));
println!("({}) {}", $idx, BinaryData($st))
};
}

Loading…
Cancel
Save