rust: integrate TUI and app; all modules wired
This commit is contained in:
@@ -11,13 +11,13 @@ use std::hint::black_box;
|
|||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
fn bench(name: &str, mut f: impl FnMut(u64)) {
|
fn bench<R>(name: &str, mut f: impl FnMut(u64) -> R) {
|
||||||
f(0);
|
black_box(f(0));
|
||||||
let budget = Duration::from_secs(2);
|
let budget = Duration::from_secs(2);
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
let mut n = 0u64;
|
let mut n = 0u64;
|
||||||
while start.elapsed() < budget {
|
while start.elapsed() < budget {
|
||||||
f(n);
|
black_box(f(n));
|
||||||
n += 1;
|
n += 1;
|
||||||
}
|
}
|
||||||
let per = start.elapsed() / n as u32;
|
let per = start.elapsed() / n as u32;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
//! mapsize: interactive terminal disk usage analyser (Rust port).
|
//! mapsize: interactive terminal disk usage analyser (Rust port).
|
||||||
|
|
||||||
|
pub mod app;
|
||||||
pub mod brand;
|
pub mod brand;
|
||||||
pub mod cancel;
|
pub mod cancel;
|
||||||
pub mod config;
|
pub mod config;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
use super::canvas::{Canvas, Style, BOLD};
|
use super::canvas::{Canvas, Style, BOLD};
|
||||||
use super::model::{Cmd, Model};
|
use super::model::{Cmd, Model};
|
||||||
use super::table::{col, Table, TableRow};
|
use super::table::{col, Table, TableRow};
|
||||||
use super::{san, si_units};
|
use super::san;
|
||||||
use crate::inventory::{ErrKind, Tree, FLAG_ALLOC_UNKNOWN};
|
use crate::inventory::{ErrKind, Tree, FLAG_ALLOC_UNKNOWN};
|
||||||
use crate::textutil;
|
use crate::textutil;
|
||||||
use crate::treemap::Rect;
|
use crate::treemap::Rect;
|
||||||
@@ -107,7 +107,7 @@ impl InfoView {
|
|||||||
line(cv, &mut y, "One filesystem", &st.one_file_system.to_string(), value);
|
line(cv, &mut y, "One filesystem", &st.one_file_system.to_string(), value);
|
||||||
line(cv, &mut y, "Follow symlinks", &textutil::sanitize(&st.follow), value);
|
line(cv, &mut y, "Follow symlinks", &textutil::sanitize(&st.follow), value);
|
||||||
line(cv, &mut y, "Size mode", m.size_mode.name(), value);
|
line(cv, &mut y, "Size mode", m.size_mode.name(), value);
|
||||||
line(cv, &mut y, "Units", if si_units() { "SI (1000)" } else { "IEC (1024)" }, value);
|
line(cv, &mut y, "Units", if crate::textutil::si() { "SI (1000)" } else { "IEC (1024)" }, value);
|
||||||
if root.has(FLAG_ALLOC_UNKNOWN) {
|
if root.has(FLAG_ALLOC_UNKNOWN) {
|
||||||
line(cv, &mut y, "Note", "allocated size unavailable on this platform", Style::new(t.warn, t.bg));
|
line(cv, &mut y, "Note", "allocated size unavailable on this platform", Style::new(t.warn, t.bg));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,11 +55,6 @@ pub(crate) fn san(b: &[u8]) -> String {
|
|||||||
textutil::sanitize_bytes(b)
|
textutil::sanitize_bytes(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether decimal (SI) units are selected. textutil keeps the switch
|
|
||||||
/// private, so it is inferred from the formatting.
|
|
||||||
pub(crate) fn si_units() -> bool {
|
|
||||||
textutil::size(1000).ends_with("kB")
|
|
||||||
}
|
|
||||||
|
|
||||||
fn local_tm(unix_nanos: i64) -> libc::tm {
|
fn local_tm(unix_nanos: i64) -> libc::tm {
|
||||||
let secs = unix_nanos.div_euclid(1_000_000_000) as libc::time_t;
|
let secs = unix_nanos.div_euclid(1_000_000_000) as libc::time_t;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use super::mapview::Group;
|
|||||||
use super::modal::{kv, styled, txt, wrap, Line, Modal, Span};
|
use super::modal::{kv, styled, txt, wrap, Line, Modal, Span};
|
||||||
use super::model::{Cmd, Model};
|
use super::model::{Cmd, Model};
|
||||||
use super::search::LineEditor;
|
use super::search::LineEditor;
|
||||||
use super::{fmt_time, pad_left, pad_right, san, si_units, trunc, tw};
|
use super::{fmt_time, pad_left, pad_right, san, trunc, tw};
|
||||||
use crate::export;
|
use crate::export;
|
||||||
use crate::filter;
|
use crate::filter;
|
||||||
use crate::inventory::{NodeId, Tree, FLAG_ALLOC_UNKNOWN, FLAG_HARDLINK_DUP, FLAG_INCOMPLETE, FLAG_LOOP, FLAG_SCANNED, FLAG_SKIPPED_FS, FLAG_SPARSE, FLAG_VIRTUAL_FS, NO_NODE};
|
use crate::inventory::{NodeId, Tree, FLAG_ALLOC_UNKNOWN, FLAG_HARDLINK_DUP, FLAG_INCOMPLETE, FLAG_LOOP, FLAG_SCANNED, FLAG_SKIPPED_FS, FLAG_SPARSE, FLAG_VIRTUAL_FS, NO_NODE};
|
||||||
@@ -321,7 +321,7 @@ impl Modal for HelpModal {
|
|||||||
row(&mut out, "Ctrl+C", "cancel scan; press again to quit");
|
row(&mut out, "Ctrl+C", "cancel scan; press again to quit");
|
||||||
row(&mut out, "q", "quit");
|
row(&mut out, "q", "quit");
|
||||||
out.push(txt(""));
|
out.push(txt(""));
|
||||||
let units = if si_units() { "SI (kB = 1000 bytes)" } else { "IEC (KiB = 1024 bytes)" };
|
let units = if crate::textutil::si() { "SI (kB = 1000 bytes)" } else { "IEC (KiB = 1024 bytes)" };
|
||||||
out.push(styled(format!("Sizes: {} · units: {units}", m.size_mode.name()), muted));
|
out.push(styled(format!("Sizes: {} · units: {units}", m.size_mode.name()), muted));
|
||||||
out
|
out
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user