-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathlib.rs
52 lines (43 loc) · 1.36 KB
/
lib.rs
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
mod app;
mod event;
mod worker;
pub use app::{settings, App};
use clipboard::ClipboardProvider;
pub use event::{EventRequest, EventResponse, ImageInspectInfo};
pub use worker::DockerWorker;
pub const APP_NAME: &str = "dockeye";
fn conv_metric(value: f64, unit: &str) -> String {
const KILO: f64 = 1000.;
const MEGA: f64 = KILO * KILO;
const GIGA: f64 = KILO * KILO * KILO;
const TERA: f64 = KILO * KILO * KILO * KILO;
let (val, u) = if value < KILO {
(value, "")
} else if KILO <= value && value < MEGA {
(value / KILO, "K")
} else if MEGA <= value && value < GIGA {
(value / MEGA, "M")
} else if GIGA <= value && value < TERA {
(value / GIGA, "G")
} else {
(value / TERA, "T")
};
format!("{:.2}{}{}", val, u, unit)
}
pub fn conv_fbs(bytes: f64) -> String {
conv_metric(bytes, "B/s")
}
pub fn conv_fb(bytes: f64) -> String {
conv_metric(bytes, "B")
}
pub fn conv_b(bytes: u64) -> String {
conv_fb(bytes as f64)
}
fn save_to_clipboard(text: String) -> Result<(), Box<dyn std::error::Error>> {
let mut ctx: clipboard::ClipboardContext = ClipboardProvider::new()?;
ctx.set_contents(text)
}
#[cfg(not(target_os = "macos"))]
pub const DEFAULT_DOCKER_ADDR: &str = "unix:///var/run/docker.sock";
#[cfg(target_os = "macos")]
pub const DEFAULT_DOCKER_ADDR: &str = "unix:///run/docker.sock";