diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2020-10-11 20:26:23 +0300 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2020-10-11 20:27:22 +0300 |
commit | fe2b66ed1547663aa353bfb05763305fbcdea88b (patch) | |
tree | 1e08d94b758d2d0c87d64f2be15eed198095e96c | |
parent | Properly read username and hostname (diff) | |
download | rshell-fe2b66ed1547663aa353bfb05763305fbcdea88b.tar.xz |
Add dummy SIGINT handler
-rw-r--r-- | Cargo.lock | 11 | ||||
-rw-r--r-- | Cargo.toml | 8 | ||||
-rw-r--r-- | LICENSE.md | 23 | ||||
-rw-r--r-- | src/main.rs | 26 | ||||
-rw-r--r-- | src/prompt.rs | 2 | ||||
-rw-r--r-- | src/user.rs | 1 |
6 files changed, 55 insertions, 16 deletions
@@ -1,5 +1,14 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. [[package]] -name = "rshell" +name = "libc" +version = "0.2.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2448f6066e80e3bfc792e9c98bf705b4b0fc6e8ef5b43e5889aff0eaa9c58743" + +[[package]] +name = "rs" version = "0.1.0" +dependencies = [ + "libc", +] @@ -1,9 +1,13 @@ [package] -name = "rshell" +name = "rs" version = "0.1.0" authors = ["Aqua-sama <aqua@iserlohn-fortress.net>"] +license = "BSD-2-Clause" edition = "2018" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +# See more keys and their definitions at +# https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +libc = "0.2" + diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..c0a3081 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,23 @@ +Copyright (c) 2020 aqua@iserlohn-fortress.net
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
diff --git a/src/main.rs b/src/main.rs index 403fd33..01e5fbd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,23 +1,26 @@ -use std::process::Command; -use std::process::Stdio; +use std::process::{Command, Stdio}; mod builtins; mod prompt; +fn sigint_handler(dummy: i32) { + println!("sigint_handler: {}", dummy); +} + fn main() { + + unsafe { + // capture Ctrl+C (SIGINT) + libc::signal(libc::SIGINT, sigint_handler as libc::sighandler_t); + } + match std::fs::read_to_string("/etc/motd") { - Ok(motd) => println!("{}", motd), + Ok(motd) => print!("{}", motd), Err(_) => {} } - let prompt = match prompt::Prompt::new() { - Ok(p) => p, - Err(e) => panic!(e), - }; - let mut cwd = match std::env::current_dir() { - Ok(p) => p, - Err(e) => panic!(e), - }; + let prompt = prompt::Prompt::new().unwrap(); + let mut cwd = std::env::current_dir().unwrap(); loop { prompt.print(&cwd); @@ -91,4 +94,5 @@ fn main() { } } } // loop + } diff --git a/src/prompt.rs b/src/prompt.rs index 40c96cc..acb11e4 100644 --- a/src/prompt.rs +++ b/src/prompt.rs @@ -14,7 +14,7 @@ impl Prompt { let hostname = user::hostname()?; let ready = if username == "root" { "#" } else { "$" }.to_owned(); - let ps1 = match std::env::var("PS1") { + let ps1 = match std::env::var("PRMOPT") { Ok(val) => val, Err(_) => String::from(" {USER}@{HOST} [{PWD}]\n{$} "), } diff --git a/src/user.rs b/src/user.rs index fedf12b..9744928 100644 --- a/src/user.rs +++ b/src/user.rs @@ -46,4 +46,3 @@ fn test_username() { }; assert_eq!(username__, username().unwrap()); } - |