Skip to content

Commit

Permalink
Merge pull request #2 from expobrain/unix_line_endings
Browse files Browse the repository at this point in the history
Use Unix line endings
  • Loading branch information
phsym authored Jun 24, 2018
2 parents 9c856b7 + 1ef0b60 commit e407cd6
Show file tree
Hide file tree
Showing 7 changed files with 532 additions and 532 deletions.
28 changes: 14 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[package]
name = "shrust"
version = "0.0.4"
description = "A library for creating interactive command line shells in Rust"
authors = ["Pierre-Henri Symoneaux"]
repository = "https://github.com/phsym/shrust"
homepage = "https://github.com/phsym/shrust"
documentation = "http://phsym.github.io/shrust"
readme = "README.md"
license = "MIT"
keywords = ["shell", "console", "interactive", "terminal", "command"]

[dependencies]
prettytable-rs = "^0.6"
[package]
name = "shrust"
version = "0.0.4"
description = "A library for creating interactive command line shells in Rust"
authors = ["Pierre-Henri Symoneaux"]
repository = "https://github.com/phsym/shrust"
homepage = "https://github.com/phsym/shrust"
documentation = "http://phsym.github.io/shrust"
readme = "README.md"
license = "MIT"
keywords = ["shell", "console", "interactive", "terminal", "command"]

[dependencies]
prettytable-rs = "^0.6"
42 changes: 21 additions & 21 deletions examples/data.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
extern crate shrust;
use shrust::{Shell, ShellIO};
use std::io::prelude::*;

fn main() {
let v = Vec::new();
let mut shell = Shell::new(v);
shell.new_command("push", "Add string to the list", 1, |io, v, s| {
try!(writeln!(io, "Pushing {}", s[0]));
v.push(s[0].to_string());
Ok(())
});
shell.new_command_noargs("list", "List strings", |io, v| {
for s in v {
try!(writeln!(io, "{}", s));
}
Ok(())
});

shell.run_loop(&mut ShellIO::default());
}
extern crate shrust;
use shrust::{Shell, ShellIO};
use std::io::prelude::*;

fn main() {
let v = Vec::new();
let mut shell = Shell::new(v);
shell.new_command("push", "Add string to the list", 1, |io, v, s| {
try!(writeln!(io, "Pushing {}", s[0]));
v.push(s[0].to_string());
Ok(())
});
shell.new_command_noargs("list", "List strings", |io, v| {
for s in v {
try!(writeln!(io, "{}", s));
}
Ok(())
});

shell.run_loop(&mut ShellIO::default());
}
24 changes: 12 additions & 12 deletions examples/default.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
extern crate shrust;
use shrust::{Shell, ShellIO};
use std::io::prelude::*;

fn main() {
let mut shell = Shell::new(());
shell.set_default(|io, _, cmd| {
try!(writeln!(io, "Hello from default handler !!! Received: {}", cmd));
Ok(())
});
shell.run_loop(&mut ShellIO::default());
}
extern crate shrust;
use shrust::{Shell, ShellIO};
use std::io::prelude::*;

fn main() {
let mut shell = Shell::new(());
shell.set_default(|io, _, cmd| {
try!(writeln!(io, "Hello from default handler !!! Received: {}", cmd));
Ok(())
});
shell.run_loop(&mut ShellIO::default());
}
26 changes: 13 additions & 13 deletions examples/dummy.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
extern crate shrust;
use shrust::{Shell, ShellIO};
use std::io::prelude::*;

fn main() {
let mut shell = Shell::new(());
shell.new_command_noargs("hello", "Say 'hello' to the world", |io, _| {
try!(writeln!(io, "Hello World !!!"));
Ok(())
});

shell.run_loop(&mut ShellIO::default());
}
extern crate shrust;
use shrust::{Shell, ShellIO};
use std::io::prelude::*;

fn main() {
let mut shell = Shell::new(());
shell.new_command_noargs("hello", "Say 'hello' to the world", |io, _| {
try!(writeln!(io, "Hello World !!!"));
Ok(())
});

shell.run_loop(&mut ShellIO::default());
}
78 changes: 39 additions & 39 deletions examples/map.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
extern crate shrust;
use shrust::{Shell, ShellIO};
use std::io::prelude::*;

use std::collections::HashMap;
use std::str::FromStr;

fn main() {
let map = HashMap::new();
let mut shell = Shell::new(map);

shell.new_command("put", "Insert a value", 2, |_, map, args| {
map.insert(try!(usize::from_str(args[0])), args[1].to_string());
Ok(())
});
shell.new_command("get", "Get a value", 1, |mut io, map, args| {
match map.get(&try!(usize::from_str(args[0]))) {
Some(val) => writeln!(io, "{}", val).unwrap(),
None => writeln!(io, "Not found").unwrap()
};
Ok(())
});
shell.new_command("remove", "Remove a value", 1, |_, map, args| {
map.remove(&try!(usize::from_str(args[0])));
Ok(())
});
shell.new_command("list", "List all values", 0, |mut io, map, _| {
for (k, v) in map {
writeln!(io, "{} = {}", k, v).unwrap();
}
Ok(())
});
shell.new_command_noargs("clear", "Clear all values", |_, map| {
map.clear();
Ok(())
});

shell.run_loop(&mut ShellIO::default());
}
extern crate shrust;
use shrust::{Shell, ShellIO};
use std::io::prelude::*;

use std::collections::HashMap;
use std::str::FromStr;

fn main() {
let map = HashMap::new();
let mut shell = Shell::new(map);

shell.new_command("put", "Insert a value", 2, |_, map, args| {
map.insert(try!(usize::from_str(args[0])), args[1].to_string());
Ok(())
});
shell.new_command("get", "Get a value", 1, |mut io, map, args| {
match map.get(&try!(usize::from_str(args[0]))) {
Some(val) => writeln!(io, "{}", val).unwrap(),
None => writeln!(io, "Not found").unwrap()
};
Ok(())
});
shell.new_command("remove", "Remove a value", 1, |_, map, args| {
map.remove(&try!(usize::from_str(args[0])));
Ok(())
});
shell.new_command("list", "List all values", 0, |mut io, map, _| {
for (k, v) in map {
writeln!(io, "{} = {}", k, v).unwrap();
}
Ok(())
});
shell.new_command_noargs("clear", "Clear all values", |_, map| {
map.clear();
Ok(())
});

shell.run_loop(&mut ShellIO::default());
}
102 changes: 51 additions & 51 deletions examples/socket.rs
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
extern crate shrust;
use shrust::{Shell, ShellIO};
use std::io::prelude::*;

use std::sync::{Arc, Mutex};
use std::thread;

use std::collections::HashMap;
use std::str::FromStr;

use std::net::TcpListener;

fn main() {
let map = Arc::new(Mutex::new(HashMap::new()));

let mut shell = Shell::new(map);

shell.new_command("put", "Insert a value", 2, |_, map, args| {
map.lock().unwrap().insert(try!(usize::from_str(args[0])), args[1].to_string());
Ok(())
});
shell.new_command("get", "Get a value", 1, |mut io, map, args| {
match map.lock().unwrap().get(&try!(usize::from_str(args[0]))) {
Some(val) => writeln!(io, "{}", val).unwrap(),
None => writeln!(io, "Not found").unwrap()
};
Ok(())
});
shell.new_command("remove", "Remove a value", 1, |_, map, args| {
map.lock().unwrap().remove(&try!(usize::from_str(args[0])));
Ok(())
});
shell.new_command("list", "List all values", 0, |mut io, map, _| {
for (k, v) in &*map.lock().unwrap() {
writeln!(io, "{} = {}", k, v).unwrap();
}
Ok(())
});
shell.new_command_noargs("clear", "Clear all values", |_, map| {
map.lock().unwrap().clear();
Ok(())
});

let serv = TcpListener::bind("0.0.0.0:1234").expect("Cannot open socket");
for sock in serv.incoming() {
let sock = sock.unwrap();
let mut shell = shell.clone();
let mut io = ShellIO::new_io(sock);
thread::spawn(move || shell.run_loop(&mut io));
}
}
extern crate shrust;
use shrust::{Shell, ShellIO};
use std::io::prelude::*;

use std::sync::{Arc, Mutex};
use std::thread;

use std::collections::HashMap;
use std::str::FromStr;

use std::net::TcpListener;

fn main() {
let map = Arc::new(Mutex::new(HashMap::new()));

let mut shell = Shell::new(map);

shell.new_command("put", "Insert a value", 2, |_, map, args| {
map.lock().unwrap().insert(try!(usize::from_str(args[0])), args[1].to_string());
Ok(())
});
shell.new_command("get", "Get a value", 1, |mut io, map, args| {
match map.lock().unwrap().get(&try!(usize::from_str(args[0]))) {
Some(val) => writeln!(io, "{}", val).unwrap(),
None => writeln!(io, "Not found").unwrap()
};
Ok(())
});
shell.new_command("remove", "Remove a value", 1, |_, map, args| {
map.lock().unwrap().remove(&try!(usize::from_str(args[0])));
Ok(())
});
shell.new_command("list", "List all values", 0, |mut io, map, _| {
for (k, v) in &*map.lock().unwrap() {
writeln!(io, "{} = {}", k, v).unwrap();
}
Ok(())
});
shell.new_command_noargs("clear", "Clear all values", |_, map| {
map.lock().unwrap().clear();
Ok(())
});

let serv = TcpListener::bind("0.0.0.0:1234").expect("Cannot open socket");
for sock in serv.incoming() {
let sock = sock.unwrap();
let mut shell = shell.clone();
let mut io = ShellIO::new_io(sock);
thread::spawn(move || shell.run_loop(&mut io));
}
}
Loading

0 comments on commit e407cd6

Please sign in to comment.