Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #[macro_use] extern crate text_io;
- extern crate libc;
- use std::process::Command;
- use std::process;
- fn main() {
- initialize_ui();
- }
- fn initialize_ui(){
- eprint!("$");
- let mut history: Vec<String> = Vec::new();
- loop{
- let line: String = read!("{}\n");
- let to_hist = line.clone();
- history.push(to_hist);
- let vec: Vec<&str> = line.split(" ").collect();
- process_cmd(vec, &history);
- eprint!("$");
- }
- }
- fn process_cmd(vec: Vec<&str>, history: &Vec<String> ){
- if vec[0].trim() == "exit"{
- process::exit(1);
- };
- if vec[0].trim() == "history"{
- let mut count: i32 = 0;
- for x in history {
- eprint!("[{}] {}\n", count, x);
- count = count + 1;
- }
- }else{
- let binary: &str = vec[0];
- let args: Vec<&str> =vec.iter().map(|v| *v).skip(1).collect();
- let mut child = Command::new(binary).args(&args).spawn().unwrap();
- let _result = child.wait().unwrap();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement