From c20f1310fb3417cb1b0bf41e2d31db373751e392 Mon Sep 17 00:00:00 2001 From: Iago Garrido Date: Tue, 12 Nov 2019 16:53:13 +0100 Subject: get player name from env --- src/main.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index b59d587..ab93eb5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,16 +16,23 @@ use pancurses::{ Input, noecho }; +use std::env; use state::State; use world::{Dungeon}; +fn get_player_name() -> String { + match env::var_os("USER") { + Some(val) => val.into_string().unwrap(), + None => String::from("Kshar") + } +} fn main() { let window = initscr(); let mut state = State::new( Player::new( - "Kshar".to_string(), + get_player_name(), "Warrior".to_string(), 30, 10, -- cgit v1.2.3