Fleche haut marche un peu, à finir
This commit is contained in:
parent
dc7855de8a
commit
8c92b82656
@ -12,3 +12,4 @@ dirs = "4.0.0"
|
|||||||
users = "0.11.0"
|
users = "0.11.0"
|
||||||
gethostname = "0.4.1"
|
gethostname = "0.4.1"
|
||||||
termion = "2.0.1"
|
termion = "2.0.1"
|
||||||
|
unicode-segmentation = "1.6.0"
|
||||||
|
21
src/lib.rs
21
src/lib.rs
@ -13,6 +13,7 @@ pub mod shell {
|
|||||||
use termion::input::TermRead;
|
use termion::input::TermRead;
|
||||||
use termion::raw::IntoRawMode;
|
use termion::raw::IntoRawMode;
|
||||||
use termion::color;
|
use termion::color;
|
||||||
|
use unicode_segmentation::UnicodeSegmentation;
|
||||||
|
|
||||||
mod history;
|
mod history;
|
||||||
use crate::shell::history::*;
|
use crate::shell::history::*;
|
||||||
@ -178,6 +179,20 @@ pub mod shell {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn rewrite(current_cmd: String) -> String {
|
||||||
|
//Deletes currently written command
|
||||||
|
|
||||||
|
let mut stdout = stdout().into_raw_mode().unwrap();
|
||||||
|
let nbr_of_chars = current_cmd.graphemes(true).count();
|
||||||
|
while nbr_of_chars > 0 {
|
||||||
|
write!(stdout, "\x1b[D").unwrap();
|
||||||
|
write!(stdout, "\x1b[K").unwrap();
|
||||||
|
}
|
||||||
|
return String::new();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pub fn run_raw() {
|
pub fn run_raw() {
|
||||||
let stdin = stdin();
|
let stdin = stdin();
|
||||||
let mut stdout = stdout().into_raw_mode().unwrap();
|
let mut stdout = stdout().into_raw_mode().unwrap();
|
||||||
@ -243,6 +258,7 @@ pub mod shell {
|
|||||||
},
|
},
|
||||||
|
|
||||||
Key::Up => {
|
Key::Up => {
|
||||||
|
mycommand = rewrite(mycommand);
|
||||||
let lastnumber = match get_history_number() {
|
let lastnumber = match get_history_number() {
|
||||||
Ok(e) => e,
|
Ok(e) => e,
|
||||||
Err(_) => continue,
|
Err(_) => continue,
|
||||||
@ -251,8 +267,9 @@ pub mod shell {
|
|||||||
Some(c) => c,
|
Some(c) => c,
|
||||||
None => continue
|
None => continue
|
||||||
};
|
};
|
||||||
let prompt = build_prompt();
|
mycommand = lastcmd.trim().to_string();
|
||||||
write!(stdout, "\r\n{}{}", prompt, lastcmd.trim());
|
//let prompt = build_prompt();
|
||||||
|
write!(stdout, "{}", mycommand);
|
||||||
mycommand = lastcmd;
|
mycommand = lastcmd;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user