sqishrc ok
This commit is contained in:
70
src/lib.rs
70
src/lib.rs
@ -16,6 +16,7 @@ pub mod shell {
|
||||
use termion::color;
|
||||
use termion;
|
||||
use unicode_segmentation::UnicodeSegmentation;
|
||||
use std::collections::HashMap;
|
||||
|
||||
mod history;
|
||||
use crate::shell::history::*;
|
||||
@ -23,8 +24,8 @@ pub mod shell {
|
||||
mod autocomplete;
|
||||
use crate::shell::autocomplete::*;
|
||||
|
||||
mod prompt;
|
||||
use crate::shell::prompt::*;
|
||||
mod config;
|
||||
use crate::shell::config::*;
|
||||
|
||||
//used for home directory
|
||||
extern crate dirs;
|
||||
@ -58,11 +59,11 @@ pub mod shell {
|
||||
Err(e) => eprintln!(" Err: {}", e),
|
||||
}
|
||||
},
|
||||
"ssh" => {
|
||||
let ssh_args = args.peekable().peek().map_or(" ", |x| *x);
|
||||
let mut child = Command::new("ssh").arg(ssh_args).spawn().unwrap();
|
||||
let _ = child.wait().unwrap();
|
||||
},
|
||||
// "ssh" => {
|
||||
// let ssh_args = args.peekable().peek().map_or(" ", |x| *x);
|
||||
// let mut child = Command::new("ssh").arg(ssh_args).spawn().unwrap();
|
||||
// let _ = child.wait().unwrap();
|
||||
// },
|
||||
command => {
|
||||
if commands.peek().is_some() {
|
||||
let stdin = match previous_command {
|
||||
@ -230,14 +231,30 @@ pub mod shell {
|
||||
//Used in conjunction with Up arrow to go back in history
|
||||
//Resetted by pressing Enter
|
||||
let mut current_number = get_curr_history_number();
|
||||
let mut prompt = build_prompt(¤t_number);
|
||||
|
||||
//Used to track the location of the cursor inside the command
|
||||
let mut current_pos: usize = 0;
|
||||
let mut max_pos: usize = 0;
|
||||
|
||||
let mut conf = match SqishConf::from_sqishrc() {
|
||||
Ok(c) => c,
|
||||
Err(e) => {
|
||||
let ret_line = format!("Could not build conf, got {}\r\nUsing default\r\n", e);
|
||||
write!(stdout, "{}", ret_line);
|
||||
let conf = SqishConf {
|
||||
promptline: String::from("$COLORGREEN_ [$USER_@$HOSTNAME_] "),
|
||||
promptline_base: String::from("$COLORGREEN_ [$USER_@$HOSTNAME_] "),
|
||||
aliases: HashMap::new(),
|
||||
hotkeys: HashMap::new(),
|
||||
};
|
||||
conf
|
||||
},
|
||||
};
|
||||
&conf.update_prompt(get_curr_history_number());
|
||||
|
||||
|
||||
//Initialize
|
||||
write!(stdout, "\r\n SquiShell (sqish)--- \r\n{}", prompt);
|
||||
write!(stdout, "\r\n SquiShell (sqish)--- \r\n{}", conf.promptline);
|
||||
stdout.flush();
|
||||
|
||||
for c in stdin.keys() {
|
||||
@ -248,44 +265,42 @@ pub mod shell {
|
||||
if *&mycommand.len() == 0 {
|
||||
continue;
|
||||
}
|
||||
|
||||
//Search
|
||||
*&mut mycommand = replace_signs(&mycommand);
|
||||
let (res, list) = Search::build(&mycommand).unwrap().autocomplete();
|
||||
write!(stdout, "\r\n{}\r\n", list);
|
||||
mycommand.clear();
|
||||
mycommand.push_str(&res);
|
||||
max_pos = res.len();
|
||||
current_pos = max_pos;
|
||||
write!(stdout, "\r\n{}{}", prompt, res);
|
||||
write!(stdout, "\r\n{}{}", conf.promptline, res);
|
||||
stdout.flush();
|
||||
}
|
||||
|
||||
Key::Char('\n') => {
|
||||
current_number = get_curr_history_number();
|
||||
prompt = build_prompt(¤t_number);
|
||||
current_pos = 0;
|
||||
max_pos = 0;
|
||||
if (mycommand != String::from("\n")) && (mycommand != String::from("exit")) {
|
||||
let comm = replace_signs(&mycommand);
|
||||
RawTerminal::suspend_raw_mode(&stdout);
|
||||
let res = handle_input(&comm);
|
||||
let _res = handle_input(&comm);
|
||||
RawTerminal::activate_raw_mode(&stdout);
|
||||
mycommand.clear();
|
||||
//Proper printing
|
||||
for line in res.split('\n') {
|
||||
if line != "\r" {
|
||||
write!(stdout, "\r\n{}", line);
|
||||
}
|
||||
}
|
||||
current_number = get_curr_history_number();
|
||||
prompt = build_prompt(¤t_number);
|
||||
write!(stdout, "{}", prompt).unwrap();
|
||||
//for line in res.split('\n') {
|
||||
// if line != "\r" {
|
||||
// write!(stdout, "\r\n{}", line);
|
||||
// }
|
||||
//}
|
||||
&conf.update_prompt(get_curr_history_number());
|
||||
write!(stdout, "\r\n{}", conf.promptline).unwrap();
|
||||
stdout.flush();
|
||||
} else if mycommand == String::from("exit") {
|
||||
write!(stdout, "\r\n Sayonara \r\n");
|
||||
break;
|
||||
} else {
|
||||
write!(stdout, "\r\n{}", prompt).unwrap();
|
||||
&conf.update_prompt(get_curr_history_number());
|
||||
write!(stdout, "\r\n{}", conf.promptline).unwrap();
|
||||
stdout.flush();
|
||||
}
|
||||
},
|
||||
@ -300,9 +315,7 @@ pub mod shell {
|
||||
max_pos = 0;
|
||||
mycommand.clear();
|
||||
write!(stdout, "\r\n--CANCEL--\r\n");
|
||||
current_number = get_curr_history_number();
|
||||
prompt = build_prompt(¤t_number);
|
||||
write!(stdout, "{}", prompt);
|
||||
write!(stdout, "{}", conf.promptline);
|
||||
},
|
||||
|
||||
Key::Ctrl('t') => {
|
||||
@ -327,6 +340,7 @@ pub mod shell {
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Key::Char(c) => {
|
||||
//if at the end of the command...
|
||||
if current_pos == max_pos {
|
||||
@ -350,7 +364,7 @@ pub mod shell {
|
||||
},
|
||||
|
||||
Key::Delete => {
|
||||
if current_pos >= 0 && current_pos < max_pos {
|
||||
if current_pos < max_pos {
|
||||
mycommand.remove(current_pos);
|
||||
if current_pos > 0 {
|
||||
current_pos -= 1;
|
||||
@ -388,7 +402,6 @@ pub mod shell {
|
||||
};
|
||||
mycommand = lastcmd.trim().to_string();
|
||||
(max_pos, current_pos) = get_cmd_curs_pos(&mycommand);
|
||||
//let prompt = build_prompt();
|
||||
write!(stdout, "{}", mycommand);
|
||||
},
|
||||
|
||||
@ -401,7 +414,6 @@ pub mod shell {
|
||||
};
|
||||
mycommand = lastcmd.trim().to_string();
|
||||
(max_pos, current_pos) = get_cmd_curs_pos(&mycommand);
|
||||
//let prompt = build_prompt();
|
||||
write!(stdout, "{}", mycommand);
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user