Cargo fmt and update
This commit is contained in:
parent
2e75abd893
commit
494537a2cf
9 changed files with 184 additions and 81 deletions
32
Cargo.lock
generated
32
Cargo.lock
generated
|
@ -453,9 +453,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "crossbeam-channel"
|
||||
version = "0.5.2"
|
||||
version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e54ea8bc3fb1ee042f5aace6e3c6e025d3874866da222930f70ce62aceba0bfa"
|
||||
checksum = "fdbfe11fe19ff083c48923cf179540e8cd0535903dc35e178a1fdeeb59aef51f"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"crossbeam-utils",
|
||||
|
@ -474,10 +474,11 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "crossbeam-epoch"
|
||||
version = "0.9.7"
|
||||
version = "0.9.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c00d6d2ea26e8b151d99093005cb442fb9a37aeaca582a03ec70946f49ab5ed9"
|
||||
checksum = "1145cf131a2c6ba0615079ab6a638f7e1973ac9c2634fcbeaaad6114246efe8c"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"cfg-if",
|
||||
"crossbeam-utils",
|
||||
"lazy_static 1.4.0",
|
||||
|
@ -487,9 +488,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "crossbeam-queue"
|
||||
version = "0.3.4"
|
||||
version = "0.3.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4dd435b205a4842da59efd07628f921c096bc1cc0a156835b4fa0bcb9a19bcce"
|
||||
checksum = "1f25d8400f4a7a5778f0e4e52384a48cbd9b5c495d110786187fc750075277a2"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"crossbeam-utils",
|
||||
|
@ -497,9 +498,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "crossbeam-utils"
|
||||
version = "0.8.7"
|
||||
version = "0.8.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b5e5bed1f1c269533fa816a0a5492b3545209a205ca1a54842be180eb63a16a6"
|
||||
checksum = "0bf124c720b7686e3c2663cf54062ab0f68a88af2fb6a030e87e30bf721fcb38"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"lazy_static 1.4.0",
|
||||
|
@ -929,9 +930,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.119"
|
||||
version = "0.2.120"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4"
|
||||
checksum = "ad5c14e80759d0939d013e6ca49930e59fc53dd8e5009132f76240c179380c09"
|
||||
|
||||
[[package]]
|
||||
name = "libdbus-sys"
|
||||
|
@ -987,7 +988,7 @@ version = "3.0.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "50fe05791a7f418b59d6cddebdc293d77c9c1f652adbff855c071d4507cd883b"
|
||||
dependencies = [
|
||||
"nom 7.1.0",
|
||||
"nom 7.1.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1272,13 +1273,12 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "nom"
|
||||
version = "7.1.0"
|
||||
version = "7.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1b1d11e1ef389c76fe5b81bcaf2ea32cf88b62bc494e19f493d0b30e7a930109"
|
||||
checksum = "a8903e5a29a317527874d0402f867152a3d21c908bb0b933e416c65e301d4c36"
|
||||
dependencies = [
|
||||
"memchr 2.4.1",
|
||||
"minimal-lexical",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -2246,9 +2246,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.86"
|
||||
version = "1.0.88"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a65b3f4ffa0092e9887669db0eae07941f023991ab58ea44da8fe8e2d511c6b"
|
||||
checksum = "ebd69e719f31e88618baa1eaa6ee2de5c9a1c004f1e9ecdb58e8352a13f20a01"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::fmt::{Debug, Display, Error, Formatter};
|
||||
use std::convert::From;
|
||||
use std::fmt::{Debug, Display, Error, Formatter};
|
||||
|
||||
use crate::lang::{SyntaxError, RuntimeError, MpsLanguageError};
|
||||
use crate::lang::{MpsLanguageError, RuntimeError, SyntaxError};
|
||||
use crate::tokens::ParseError;
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
|
@ -6,8 +6,8 @@ use std::path::Path;
|
|||
use super::lang::{MpsLanguageDictionary, MpsLanguageError, MpsOp};
|
||||
use super::tokens::MpsToken;
|
||||
use super::MpsContext;
|
||||
use super::MpsItem;
|
||||
use super::MpsError;
|
||||
use super::MpsItem;
|
||||
|
||||
/// The script interpreter.
|
||||
/// Use MpsRunner for a better interface.
|
||||
|
@ -91,8 +91,7 @@ where
|
|||
if next_item.is_none() {
|
||||
is_stmt_done = true;
|
||||
}
|
||||
next_item
|
||||
.map(|item| item.map_err(|e| error_with_ctx(e, self.tokenizer.current_line())))
|
||||
next_item.map(|item| item.map_err(|e| error_with_ctx(e, self.tokenizer.current_line())))
|
||||
} else {
|
||||
/*if self.tokenizer.end_of_file() {
|
||||
return None;
|
||||
|
|
|
@ -347,12 +347,12 @@ fn find_last_open_curly(tokens: &VecDeque<MpsToken>) -> Option<usize> {
|
|||
if bracket_depth == 0 && curly_found {
|
||||
return Some(i + 1);
|
||||
}
|
||||
},
|
||||
}
|
||||
MpsToken::OpenBracket | MpsToken::CloseBracket => {
|
||||
if bracket_depth == 0 {
|
||||
return None;
|
||||
}
|
||||
},
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
if token.is_open_curly() {
|
||||
|
|
|
@ -16,8 +16,8 @@ mod type_primitives;
|
|||
pub(crate) mod utility;
|
||||
|
||||
pub use dictionary::MpsLanguageDictionary;
|
||||
pub use error::{RuntimeError, RuntimeMsg, RuntimeOp, SyntaxError};
|
||||
pub(crate) use error::MpsLanguageError;
|
||||
pub use error::{RuntimeError, RuntimeMsg, RuntimeOp, SyntaxError};
|
||||
pub use filter::{
|
||||
MpsFilterFactory, MpsFilterPredicate, MpsFilterStatement, MpsFilterStatementFactory,
|
||||
};
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::iter::Iterator;
|
|||
|
||||
use super::lang::MpsLanguageDictionary;
|
||||
use super::tokens::{MpsTokenReader, MpsTokenizer};
|
||||
use super::{MpsContext, MpsInterpretor, MpsItem, MpsError};
|
||||
use super::{MpsContext, MpsError, MpsInterpretor, MpsItem};
|
||||
|
||||
pub struct MpsRunnerSettings<T: MpsTokenReader> {
|
||||
pub vocabulary: MpsLanguageDictionary,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use mps_interpreter::MpsError;
|
||||
use mps_interpreter::tokens::{MpsToken, MpsTokenizer, ParseError};
|
||||
use mps_interpreter::MpsError;
|
||||
use mps_interpreter::*;
|
||||
use std::collections::VecDeque;
|
||||
use std::io::Cursor;
|
||||
|
|
|
@ -179,7 +179,10 @@ impl SystemControlWrapper {
|
|||
|
||||
fn enqueued(item: MpsItem, dbus_ctrl: &Sender<DbusControl>) {
|
||||
//println!("Got enqueued item {}", &item.title);
|
||||
let file_uri = item.field("filename").and_then(|x| x.to_owned().to_str()).map(|x| format!("file://{}", x));
|
||||
let file_uri = item
|
||||
.field("filename")
|
||||
.and_then(|x| x.to_owned().to_str())
|
||||
.map(|x| format!("file://{}", x));
|
||||
dbus_ctrl
|
||||
.send(DbusControl::SetMetadata(Metadata {
|
||||
length: None,
|
||||
|
|
209
src/repl.rs
209
src/repl.rs
|
@ -2,7 +2,7 @@
|
|||
|
||||
use std::io::{self, Write};
|
||||
|
||||
use console::{Term, Key};
|
||||
use console::{Key, Term};
|
||||
|
||||
use mps_interpreter::MpsRunner;
|
||||
use mps_player::{MpsController, MpsPlayer};
|
||||
|
@ -58,7 +58,12 @@ pub fn repl(args: CliArgs) {
|
|||
};
|
||||
let mut state = ReplState::new(writer, term);
|
||||
if let Some(playlist_file) = &args.playlist {
|
||||
writeln!(state.terminal, "Playlist mode (output: `{}`)", playlist_file).expect("Failed to write to terminal output");
|
||||
writeln!(
|
||||
state.terminal,
|
||||
"Playlist mode (output: `{}`)",
|
||||
playlist_file
|
||||
)
|
||||
.expect("Failed to write to terminal output");
|
||||
let mut player = player_builder();
|
||||
let mut playlist_writer =
|
||||
io::BufWriter::new(std::fs::File::create(playlist_file).unwrap_or_else(|_| {
|
||||
|
@ -80,7 +85,8 @@ pub fn repl(args: CliArgs) {
|
|||
.expect("Failed to flush playlist to file");
|
||||
});
|
||||
} else {
|
||||
writeln!(state.terminal, "Playback mode (output: audio device)").expect("Failed to write to terminal output");
|
||||
writeln!(state.terminal, "Playback mode (output: audio device)")
|
||||
.expect("Failed to write to terminal output");
|
||||
let ctrl = MpsController::create_repl(player_builder);
|
||||
read_loop(&args, &mut state, || {
|
||||
if args.wait {
|
||||
|
@ -107,20 +113,38 @@ pub fn repl(args: CliArgs) {
|
|||
fn read_loop<F: FnMut()>(args: &CliArgs, state: &mut ReplState, mut execute: F) -> ! {
|
||||
prompt(state, args);
|
||||
loop {
|
||||
match state.terminal.read_key().expect("Failed to read terminal input") {
|
||||
match state
|
||||
.terminal
|
||||
.read_key()
|
||||
.expect("Failed to read terminal input")
|
||||
{
|
||||
Key::Char(read_c) => {
|
||||
if state.cursor_rightward_position == 0 {
|
||||
write!(state.terminal, "{}", read_c).expect("Failed to write to terminal output");
|
||||
write!(state.terminal, "{}", read_c)
|
||||
.expect("Failed to write to terminal output");
|
||||
state.statement_buf.push(read_c);
|
||||
state.current_line.push(read_c);
|
||||
} else {
|
||||
write!(state.terminal, "{}", read_c).expect("Failed to write to terminal output");
|
||||
for i in state.current_line.len() - state.cursor_rightward_position .. state.current_line.len() {
|
||||
write!(state.terminal, "{}", state.current_line[i]).expect("Failed to write to terminal output");
|
||||
write!(state.terminal, "{}", read_c)
|
||||
.expect("Failed to write to terminal output");
|
||||
for i in state.current_line.len() - state.cursor_rightward_position
|
||||
..state.current_line.len()
|
||||
{
|
||||
write!(state.terminal, "{}", state.current_line[i])
|
||||
.expect("Failed to write to terminal output");
|
||||
}
|
||||
state.terminal.move_cursor_left(state.cursor_rightward_position).expect("Failed to write to terminal output");
|
||||
state.statement_buf.insert(state.statement_buf.len() - state.cursor_rightward_position, read_c);
|
||||
state.current_line.insert(state.current_line.len() - state.cursor_rightward_position, read_c);
|
||||
state
|
||||
.terminal
|
||||
.move_cursor_left(state.cursor_rightward_position)
|
||||
.expect("Failed to write to terminal output");
|
||||
state.statement_buf.insert(
|
||||
state.statement_buf.len() - state.cursor_rightward_position,
|
||||
read_c,
|
||||
);
|
||||
state.current_line.insert(
|
||||
state.current_line.len() - state.cursor_rightward_position,
|
||||
read_c,
|
||||
);
|
||||
}
|
||||
match read_c {
|
||||
'"' | '`' => {
|
||||
|
@ -133,9 +157,17 @@ fn read_loop<F: FnMut()>(args: &CliArgs, state: &mut ReplState, mut execute: F)
|
|||
}
|
||||
}
|
||||
'(' => state.bracket_depth += 1,
|
||||
')' => if state.bracket_depth != 0 { state.bracket_depth -= 1 },
|
||||
')' => {
|
||||
if state.bracket_depth != 0 {
|
||||
state.bracket_depth -= 1
|
||||
}
|
||||
}
|
||||
'{' => state.curly_depth += 1,
|
||||
'}' => if state.curly_depth != 0 { state.curly_depth -= 1 },
|
||||
'}' => {
|
||||
if state.curly_depth != 0 {
|
||||
state.curly_depth -= 1
|
||||
}
|
||||
}
|
||||
';' => {
|
||||
if state.in_literal.is_none() {
|
||||
state
|
||||
|
@ -153,7 +185,10 @@ fn read_loop<F: FnMut()>(args: &CliArgs, state: &mut ReplState, mut execute: F)
|
|||
//println!("Got {}", statement_result.unwrap());
|
||||
repl_commands(statement_result);
|
||||
state.statement_buf.clear();
|
||||
} else if state.bracket_depth == 0 && state.in_literal.is_none() && state.curly_depth == 0 {
|
||||
} else if state.bracket_depth == 0
|
||||
&& state.in_literal.is_none()
|
||||
&& state.curly_depth == 0
|
||||
{
|
||||
state.statement_buf.push(';');
|
||||
state
|
||||
.writer
|
||||
|
@ -166,7 +201,7 @@ fn read_loop<F: FnMut()>(args: &CliArgs, state: &mut ReplState, mut execute: F)
|
|||
}
|
||||
_ => {}
|
||||
}
|
||||
},
|
||||
}
|
||||
Key::Backspace => {
|
||||
if state.cursor_rightward_position == 0 {
|
||||
if let Some(c) = state.statement_buf.pop() {
|
||||
|
@ -180,32 +215,54 @@ fn read_loop<F: FnMut()>(args: &CliArgs, state: &mut ReplState, mut execute: F)
|
|||
} else {
|
||||
state.in_literal = Some(c);
|
||||
}
|
||||
},
|
||||
'(' => if state.bracket_depth != 0 { state.bracket_depth -= 1 },
|
||||
}
|
||||
'(' => {
|
||||
if state.bracket_depth != 0 {
|
||||
state.bracket_depth -= 1
|
||||
}
|
||||
}
|
||||
')' => state.bracket_depth += 1,
|
||||
'{' => if state.curly_depth != 0 { state.curly_depth -= 1 },
|
||||
'{' => {
|
||||
if state.curly_depth != 0 {
|
||||
state.curly_depth -= 1
|
||||
}
|
||||
}
|
||||
'}' => state.curly_depth += 1,
|
||||
_ => {},
|
||||
_ => {}
|
||||
}
|
||||
match c {
|
||||
'\n' | '\r' => {
|
||||
// another line, cannot backspace that far
|
||||
state.statement_buf.push(c);
|
||||
},
|
||||
}
|
||||
_ => {
|
||||
state.current_line.pop();
|
||||
state.terminal.move_cursor_left(1).expect("Failed to write to terminal output");
|
||||
write!(state.terminal, " ").expect("Failed to write to terminal output");
|
||||
state.terminal.flush().expect("Failed to flush terminal output");
|
||||
state.terminal.move_cursor_left(1).expect("Failed to write to terminal output");
|
||||
state
|
||||
.terminal
|
||||
.move_cursor_left(1)
|
||||
.expect("Failed to write to terminal output");
|
||||
write!(state.terminal, " ")
|
||||
.expect("Failed to write to terminal output");
|
||||
state
|
||||
.terminal
|
||||
.flush()
|
||||
.expect("Failed to flush terminal output");
|
||||
state
|
||||
.terminal
|
||||
.move_cursor_left(1)
|
||||
.expect("Failed to write to terminal output");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if state.current_line.len() != state.cursor_rightward_position {
|
||||
// if not at start of line
|
||||
let removed_char = state.current_line.remove(state.current_line.len()-state.cursor_rightward_position-1);
|
||||
state.statement_buf.remove(state.statement_buf.len()-state.cursor_rightward_position-1);
|
||||
let removed_char = state
|
||||
.current_line
|
||||
.remove(state.current_line.len() - state.cursor_rightward_position - 1);
|
||||
state.statement_buf.remove(
|
||||
state.statement_buf.len() - state.cursor_rightward_position - 1,
|
||||
);
|
||||
// re-sync unclosed syntax tracking
|
||||
match removed_char {
|
||||
'"' | '`' => {
|
||||
|
@ -216,33 +273,55 @@ fn read_loop<F: FnMut()>(args: &CliArgs, state: &mut ReplState, mut execute: F)
|
|||
} else {
|
||||
state.in_literal = Some(removed_char);
|
||||
}
|
||||
},
|
||||
'(' => if state.bracket_depth != 0 { state.bracket_depth -= 1 },
|
||||
}
|
||||
'(' => {
|
||||
if state.bracket_depth != 0 {
|
||||
state.bracket_depth -= 1
|
||||
}
|
||||
}
|
||||
')' => state.bracket_depth += 1,
|
||||
'{' => if state.curly_depth != 0 { state.curly_depth -= 1 },
|
||||
'{' => {
|
||||
if state.curly_depth != 0 {
|
||||
state.curly_depth -= 1
|
||||
}
|
||||
}
|
||||
'}' => state.curly_depth += 1,
|
||||
_ => {},
|
||||
_ => {}
|
||||
}
|
||||
// re-print end of line to remove character in middle
|
||||
state.terminal.move_cursor_left(1).expect("Failed to write to terminal output");
|
||||
for i in state.current_line.len() - state.cursor_rightward_position .. state.current_line.len() {
|
||||
write!(state.terminal, "{}", state.current_line[i]).expect("Failed to write to terminal output");
|
||||
state
|
||||
.terminal
|
||||
.move_cursor_left(1)
|
||||
.expect("Failed to write to terminal output");
|
||||
for i in state.current_line.len() - state.cursor_rightward_position
|
||||
..state.current_line.len()
|
||||
{
|
||||
write!(state.terminal, "{}", state.current_line[i])
|
||||
.expect("Failed to write to terminal output");
|
||||
}
|
||||
write!(state.terminal, " ").expect("Failed to write to terminal output");
|
||||
state.terminal.move_cursor_left(state.cursor_rightward_position + 1).expect("Failed to write to terminal output");
|
||||
state
|
||||
.terminal
|
||||
.move_cursor_left(state.cursor_rightward_position + 1)
|
||||
.expect("Failed to write to terminal output");
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
}
|
||||
Key::Enter => {
|
||||
state.terminal.write_line("").expect("Failed to write to terminal output");
|
||||
state
|
||||
.terminal
|
||||
.write_line("")
|
||||
.expect("Failed to write to terminal output");
|
||||
let statement = state.statement_buf.iter().collect::<String>();
|
||||
let statement_result = statement.trim();
|
||||
if statement_result.starts_with('?') {
|
||||
//println!("Got {}", statement_result.unwrap());
|
||||
repl_commands(statement_result);
|
||||
state.statement_buf.clear();
|
||||
} else if state.bracket_depth == 0 && state.in_literal.is_none() && state.curly_depth == 0 {
|
||||
} else if state.bracket_depth == 0
|
||||
&& state.in_literal.is_none()
|
||||
&& state.curly_depth == 0
|
||||
{
|
||||
state.statement_buf.push(';');
|
||||
let complete_statement = state.statement_buf.iter().collect::<String>();
|
||||
state
|
||||
|
@ -257,19 +336,23 @@ fn read_loop<F: FnMut()>(args: &CliArgs, state: &mut ReplState, mut execute: F)
|
|||
// history
|
||||
let last_line = state.current_line.iter().collect::<String>();
|
||||
state.current_line.clear();
|
||||
if !last_line.is_empty() && ((!state.history.is_empty() && state.history[state.history.len()-1] != last_line) || state.history.is_empty()) {
|
||||
if !last_line.is_empty()
|
||||
&& ((!state.history.is_empty()
|
||||
&& state.history[state.history.len() - 1] != last_line)
|
||||
|| state.history.is_empty())
|
||||
{
|
||||
state.history.push(last_line);
|
||||
}
|
||||
state.selected_history = 0;
|
||||
|
||||
prompt(state, args);
|
||||
},
|
||||
}
|
||||
Key::ArrowUp => {
|
||||
if state.selected_history != state.history.len() {
|
||||
state.selected_history += 1;
|
||||
display_history_line(state, args);
|
||||
}
|
||||
},
|
||||
}
|
||||
Key::ArrowDown => {
|
||||
if state.selected_history > 1 {
|
||||
state.selected_history -= 1;
|
||||
|
@ -277,7 +360,10 @@ fn read_loop<F: FnMut()>(args: &CliArgs, state: &mut ReplState, mut execute: F)
|
|||
} else if state.selected_history == 1 {
|
||||
state.selected_history = 0;
|
||||
state.line_number -= 1;
|
||||
state.terminal.clear_line().expect("Failed to write to terminal output");
|
||||
state
|
||||
.terminal
|
||||
.clear_line()
|
||||
.expect("Failed to write to terminal output");
|
||||
prompt(state, args);
|
||||
// clear stale input buffer
|
||||
state.statement_buf.clear();
|
||||
|
@ -286,42 +372,57 @@ fn read_loop<F: FnMut()>(args: &CliArgs, state: &mut ReplState, mut execute: F)
|
|||
state.bracket_depth = 0;
|
||||
state.curly_depth = 0;
|
||||
}
|
||||
},
|
||||
}
|
||||
Key::ArrowLeft => {
|
||||
if state.current_line.len() > state.cursor_rightward_position {
|
||||
state.terminal.move_cursor_left(1).expect("Failed to write to terminal output");
|
||||
state
|
||||
.terminal
|
||||
.move_cursor_left(1)
|
||||
.expect("Failed to write to terminal output");
|
||||
state.cursor_rightward_position += 1;
|
||||
}
|
||||
},
|
||||
}
|
||||
Key::ArrowRight => {
|
||||
if state.cursor_rightward_position != 0 {
|
||||
state.terminal.move_cursor_right(1).expect("Failed to write to terminal output");
|
||||
state
|
||||
.terminal
|
||||
.move_cursor_right(1)
|
||||
.expect("Failed to write to terminal output");
|
||||
state.cursor_rightward_position -= 1;
|
||||
}
|
||||
},
|
||||
_ => continue
|
||||
}
|
||||
_ => continue,
|
||||
}
|
||||
|
||||
|
||||
//println!("Read {}", read_buf[0]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn prompt(state: &mut ReplState, args: &CliArgs) {
|
||||
write!(state.terminal, "{}{}", state.line_number, args.prompt).expect("Failed to write to terminal output");
|
||||
write!(state.terminal, "{}{}", state.line_number, args.prompt)
|
||||
.expect("Failed to write to terminal output");
|
||||
state.line_number += 1;
|
||||
state.terminal.flush().expect("Failed to flush terminal output");
|
||||
state
|
||||
.terminal
|
||||
.flush()
|
||||
.expect("Failed to flush terminal output");
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn display_history_line(state: &mut ReplState, args: &CliArgs) {
|
||||
// get historical line
|
||||
state.line_number -= 1;
|
||||
state.terminal.clear_line().expect("Failed to write to terminal output");
|
||||
state
|
||||
.terminal
|
||||
.clear_line()
|
||||
.expect("Failed to write to terminal output");
|
||||
prompt(state, args);
|
||||
let new_statement = state.history[state.history.len() - state.selected_history].trim();
|
||||
state.terminal.write(new_statement.as_bytes()).expect("Failed to write to terminal output");
|
||||
state
|
||||
.terminal
|
||||
.write(new_statement.as_bytes())
|
||||
.expect("Failed to write to terminal output");
|
||||
// clear stale input buffer
|
||||
state.statement_buf.clear();
|
||||
state.current_line.clear();
|
||||
|
|
Loading…
Reference in a new issue