use chrono; use hostname; use term_size; use std; use users; use args; use colors; use power; use vcs; pub struct PromptData { pub shell: colors::ShellType, pub error_code: u8, pub hostname: Option, pub terminal_cols: Option, pub pwd: Option, pub home: Option, pub user: Option, pub is_root: bool, pub time: chrono::DateTime, pub power_info: power::PowerInfo, pub vcs_info: Option>, } pub fn collect(opts: args::CommandLineOptions) -> PromptData { start_talking_about_time!("collecting data"); let hostname = hostname(); talk_about_time!("hostname"); let terminal_cols = terminal_cols(); talk_about_time!("terminal_cols"); let pwd = pwd(); talk_about_time!("pwd"); let home = home(); talk_about_time!("home"); let user = user(); talk_about_time!("user"); let is_root = is_root(); talk_about_time!("is_root"); let time = time(); talk_about_time!("time"); let power_info = power_info(); talk_about_time!("power_info"); let vcs_info = vcs_info(); talk_about_time!("vcs_info"); stop_talking_about_time!(); PromptData { shell: opts.shell, error_code: opts.error_code, hostname, terminal_cols, pwd, home, user, is_root, time, power_info, vcs_info, } } fn hostname() -> Option { hostname::get_hostname() } fn terminal_cols() -> Option { if let Some((w, _h)) = term_size::dimensions() { Some(w) } else { None } } fn pwd() -> Option { std::env::var("PWD").map(std::path::PathBuf::from).ok() } fn home() -> Option { std::env::var("HOME").map(std::path::PathBuf::from).ok() } fn user() -> Option { users::get_current_username() } fn is_root() -> bool { users::get_current_uid() == 0 } fn time() -> chrono::DateTime { chrono::Local::now() } fn power_info() -> power::PowerInfo { power::PowerInfo::new() } fn vcs_info() -> Option> { vcs::detect() }