Advertisement
Guest User

Untitled

a guest
Nov 25th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #[macro_use] extern crate text_io;
  2. extern crate libc;
  3.  
  4. use std::process::Command;
  5. use std::process;
  6.  
  7. fn main() {
  8.  
  9. initialize_ui();
  10.  
  11. }
  12.  
  13. fn initialize_ui(){
  14.  
  15. eprint!("$");
  16. let mut history: Vec<String> = Vec::new();
  17. loop{
  18. let line: String = read!("{}\n");
  19. let to_hist = line.clone();
  20. history.push(to_hist);
  21. let vec: Vec<&str> = line.split(" ").collect();
  22. process_cmd(vec, &history);
  23. eprint!("$");
  24. }
  25.  
  26. }
  27.  
  28. fn process_cmd(vec: Vec<&str>, history: &Vec<String> ){
  29.  
  30. if vec[0].trim() == "exit"{
  31. process::exit(1);
  32. };
  33.  
  34. if vec[0].trim() == "history"{
  35. let mut count: i32 = 0;
  36. for x in history {
  37. eprint!("[{}] {}\n", count, x);
  38. count = count + 1;
  39. }
  40. }else{
  41. let binary: &str = vec[0];
  42. let args: Vec<&str> =vec.iter().map(|v| *v).skip(1).collect();
  43. let mut child = Command::new(binary).args(&args).spawn().unwrap();
  44. let _result = child.wait().unwrap();
  45. }
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement