Commit Diff


commit - 44230002c414f3b5b22800f8c58cc83bf16bdccd
commit + 6e9ad3b1d5f0edc4e4faa842bbdbf49a91f09569
blob - /dev/null
blob + d1869cad1aa3259156b8583bad330c18cee625ce (mode 644)
--- /dev/null
+++ Cargo.toml
@@ -0,0 +1,12 @@
+[package]
+name = "sflogbook"
+version = "0.1.0"
+authors = ["matthiaschmidt"]
+edition = "2018"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+log = "0.4.14"
+env_logger = "0.9.0"
+rustyline = "9.0.0"
blob - /dev/null
blob + d282eb32999b540c8826925331902ddd35740de1 (mode 644)
--- /dev/null
+++ src/character.rs
@@ -0,0 +1,62 @@
+#[derive(Debug)]
+pub struct Character {
+    name:       String,
+    edge:       u8,
+    heart:      u8,
+    iron:       u8,
+    shadow:     u8,
+    wits:       u8,
+    momentum:   u8,
+    max_mom:    u8,
+    reset_mom:  u8,
+    health:     u8,
+    spirit:     u8,
+    supply:     u8,
+    exp:        u8,
+    exp_spent:  u8,
+    wounded:    bool,
+    shaken:     bool,
+    unprepared: bool,
+    harmed:     bool,
+    traumatized:bool,
+    doomed:     bool,
+    tormented:  bool,
+    indebted:   bool,
+    battered:   bool,
+    cursed:     bool,
+}
+
+impl Character {
+    pub fn print(self) {
+        println!("Name: {}", self.name);
+    }
+
+    pub fn new() -> Character {
+        Character {
+            name:       String::from(""),
+            edge:       0,
+            heart:      0,
+            iron:       0,
+            shadow:     0,
+            wits:       0,
+            momentum:   0,
+            max_mom:    0,
+            reset_mom:  0,
+            health:     0,
+            spirit:     0,
+            supply:     0,
+            exp:        0,
+            exp_spent:  0,
+            wounded:    false,
+            shaken:     false,
+            unprepared: false,
+            harmed:     false,
+            traumatized:false,
+            doomed:     false,
+            tormented:  false,
+            indebted:   false,
+            battered:   false,
+            cursed:     false,
+        }
+    }
+}
blob - /dev/null
blob + 44bc31887f4caf96315ba36c23d1c25f8b560ae2 (mode 644)
--- /dev/null
+++ src/main.rs
@@ -0,0 +1,99 @@
+#[macro_use] extern crate log;
+extern crate env_logger;
+
+use rustyline::error::ReadlineError;
+use rustyline::Editor;
+use std::env;
+
+mod character;
+
+pub use character::Character;
+
+struct Game {
+	curchar:	Character,
+	command:	String,
+	prompt:     String,
+	sfpath:     String,
+	rl:         Editor::<()>,
+}
+
+impl Game {
+    fn execute_command(&mut self) {
+        match self.command.as_str() {
+            "q" => self.shutdown(),
+            _ => println!("Unkown command"),
+        }
+    }
+
+    fn new() -> Game {
+        Game {
+            curchar:    Character::new(),
+            command:    String::from(""),
+            prompt:     String::from("> "),
+            sfpath:     String::from(""),
+            rl:         Editor::<()>::new(),
+        }
+    }
+
+    fn init(&mut self) {
+        self.init_path();
+        self.load_history();
+    }
+
+    fn init_path(&mut self) {
+        let home = match env::var("XDG_HOME") {
+            Ok(val) => val,
+            Err(_) => match env::var("HOME") {
+                Ok(val) => val,
+                Err(_) => "none".to_string(),
+            },
+        };
+
+        log::info!("var is set to {}", home);
+    }
+
+    fn load_history(&mut self) {
+        if self.rl.load_history("history.txt").is_err() {
+            println!("No previous history.");
+        }
+    }
+
+    fn shutdown(&mut self) {
+        self.rl.save_history("history.txt").unwrap();
+        std::process::exit(0)
+    }
+
+}
+
+fn main() {
+    env_logger::init();
+    let mut game = Game::new();
+    log::info!("Hallo");
+
+    game.init();
+
+    loop {
+		let readline = game.rl.readline(game.prompt.as_str());
+        match readline {
+            Ok(line) => {
+                game.rl.add_history_entry(line.as_str());
+                println!("Line: {}", line);
+				game.command = line.to_string();
+				game.execute_command();
+            },
+            Err(ReadlineError::Interrupted) => {
+                println!("CTRL-C");
+                break
+            },
+            Err(ReadlineError::Eof) => {
+                println!("CTRL-D");
+                break
+            },
+            Err(err) => {
+                println!("Error: {:?}", err);
+                break
+            }
+        }
+    }
+}
+