aboutsummaryrefslogtreecommitdiffstats
path: root/src/system_info.rs
blob: cec17fd090b628d93cab0b928b35dacb3d07bebf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use chrono;
use hostname;
use term_size;
use std;
use users;

use power;
use vcs;

pub fn hostname() -> Option<String> {
    hostname::get_hostname()
}

pub fn terminal_cols() -> Option<usize> {
    if let Some((w, _h)) = term_size::dimensions() {
        Some(w)
    }
    else {
        None
    }
}

pub fn pwd() -> Option<std::path::PathBuf> {
    std::env::var("PWD")
        .map(|pwd| std::path::PathBuf::from(pwd))
        .ok()
}

pub fn home() -> Option<std::path::PathBuf> {
    std::env::var("HOME")
        .map(|dir| std::path::PathBuf::from(dir))
        .ok()
}

pub fn user() -> Option<String> {
    users::get_current_username()
}

pub fn is_root() -> bool {
    users::get_current_uid() == 0
}

pub fn time() -> chrono::DateTime<chrono::Local> {
    chrono::Local::now()
}

pub fn power_info() -> power::PowerInfo {
    power::PowerInfo::new()
}

pub fn vcs_info() -> Option<Box<vcs::VcsInfo>> {
    vcs::detect()
}