Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ and `cargo build --release` directly; CI runs the gate on both systems.
| parallel scan, arena, Protobuf cache DB, SWR | `crates/disktree-scanner/src/` (`walk.rs`, `tree.rs`, `db.rs`, `session.rs`) |
| bounded-memory streaming walk | `crates/disktree-scanner/src/stream.rs` (wired into `disktree-core/src/remote_walk.rs`) |
| terminal TUI and `--json` / `--ndjson` CLI | `crates/disktree-cli/src/` |
| visual terminal treemap, keys, and review | `crates/disktree-cli/src/treemap/` |
| SSH protocol, discovery and transport | `crates/disktree-core/src/remote.rs` |
| joining, splitting or comparing a scanned path | `crates/disktree-core/src/path_style.rs` |
| arena-to-treemap projection and `ScanHandle` | `crates/disktree-core/src/scan.rs` |
Expand Down
5 changes: 5 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,37 @@ windowrule = float, class:^(disktree)$
windowrule = size 1400 900, class:^(disktree)$
```

## In the terminal

![A nested treemap, selection details, and disk space in a 120-column terminal](assets/tui/120.png)

Run the visual treemap with the `disktree-cli` release binary:

```sh
disktree-cli treemap # scan your home directory
disktree-cli treemap ~/src # scan a chosen directory
disktree-cli treemap --disk # scan the volume containing your home
```

The treemap shows an inspector at 120 columns, a
[compact map](assets/tui/80.png) around 80, and a
[list](assets/tui/45.png) around 45. It scans the machine where it runs,
including in an SSH session, and follows Omarchy colours when available.
Use `--theme dark` or `--theme light` to override the palette.

Use **h/j/k/l** or the arrow keys to move, **Enter** to open a directory,
**Backspace** to go up, and **?** for the key guide. **t** rotates Size,
Files, and Age. **i** and **d** change hidden and apparent size views from
the same scan. Use **V** to select a volume and **r** to scan again.

**Space** marks a path and **c** opens review. From there **a** writes an
agent prompt to stdout after restoring the terminal, and **s** saves it
to a file. Local cleanup uses the shared removal guards and asks for
confirmation before permanent deletion.

Build from source with `cargo build --release --locked -p disktree-cli`.
On macOS, give the terminal Full Disk Access to scan protected folders.

## Develop

```sh
Expand All @@ -585,6 +616,7 @@ gone while their neighbours are not.
| path | what lives there |
| --- | --- |
| `crates/disktree-core` | scanning, the tree, the squarified layout, free space and removal — no UI |
| `crates/disktree-cli/src/treemap` | terminal treemap, navigation, themes, and review |
| `crates/disktree-app/src/state.rs` | every action the interface can take, and the key map |
| `crates/disktree-app/src/views.rs` | the screens |
| `crates/disktree-app/src/treemap_view.rs` | painting the mosaic and its labels |
Expand Down
Binary file added assets/tui/120.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/tui/45.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/tui/80.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/tui/fixture.tar.gz
Binary file not shown.
5 changes: 1 addition & 4 deletions crates/disktree-app/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::time::{Duration, Instant};

use disktree_core::access::file_table_readable;
use disktree_core::filter::{Keep, filter};
use disktree_core::insights::{Candidate, worth_a_look};
use disktree_core::insights::{Candidate, INSIGHT_LIMIT, worth_a_look};
use disktree_core::path_style::PathStyle;
use disktree_core::removal::{
Plan, RemovalEvent, RemovalHandle, RemovalMode, Target, TrashBackend,
Expand Down Expand Up @@ -109,9 +109,6 @@ pub fn panel_width(pointer_x: f32, viewport: f32, rem: f32) -> f32 {
width.clamp(PANEL_MIN_REMS, max)
}

/// How many "worth a look" findings the panel lists.
const INSIGHT_LIMIT: usize = 6;

/// Duration of the tile freshness colour fade when a square becomes fresh.
const FRESHNESS_FADE_MS: f32 = 200.0;
/// Duration of smooth per-tile rectangle gliding when sizes update during a
Expand Down
7 changes: 7 additions & 0 deletions crates/disktree-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ ratatui = "0.29"
rustc-hash = { workspace = true }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
toml = "0.8"
unicode-segmentation = "1"
unicode-width = "0.2"

[target.'cfg(windows)'.dependencies]
dunce = "1"
windows-sys = { version = "0.61", features = ["Win32_System_Console"] }

[target.'cfg(target_os = "linux")'.dependencies]
rustix = { version = "1.1", features = ["process"] }
Expand Down
3 changes: 3 additions & 0 deletions crates/disktree-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ pub enum BackendArg {

#[derive(Clone, Debug, Subcommand)]
pub enum Command {
/// Explore a local directory as a visual treemap.
Treemap(crate::treemap::Args),

/// Mark one or more paths dirty in the cache DB (e.g. after deleting files)
/// so subsequent runs revalidate them immediately.
Invalidate {
Expand Down
70 changes: 39 additions & 31 deletions crates/disktree-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod cli;
mod format;
mod json_out;
mod stdio;
mod treemap;
mod tui;

use std::io::{self, IsTerminal as _, Write as _};
Expand Down Expand Up @@ -184,9 +185,10 @@ fn run_subcommand(
mode: StorageMode,
policy: disktree_scanner::CachePolicy,
) -> Result<()> {
let scanner = Scanner::new(mode, policy)?;
match command {
Command::Treemap(options) => return treemap::run(options),
Command::Invalidate { paths, json } => {
let scanner = Scanner::new(mode, policy)?;
let report = scanner.invalidate(&HostKey::Local, paths)?;
if *json {
#[derive(Serialize)]
Expand All @@ -212,41 +214,47 @@ fn run_subcommand(
);
}
}
Command::Cache { action } => match action {
CacheAction::Status { json } => {
let stats = scanner.cache_stats()?;
if *json {
let mut stdout = io::stdout().lock();
serde_json::to_writer_pretty(&mut stdout, &stats)?;
writeln!(stdout)?;
} else {
println!("mode: {:?}", scanner.active_mode());
if let Some(path) = &stats.db_path {
println!("db_path: {}", path.display());
Command::Cache { action } => {
let scanner = Scanner::new(mode, policy)?;
match action {
CacheAction::Status { json } => {
let stats = scanner.cache_stats()?;
if *json {
let mut stdout = io::stdout().lock();
serde_json::to_writer_pretty(&mut stdout, &stats)?;
writeln!(stdout)?;
} else {
println!("mode: {:?}", scanner.active_mode());
if let Some(path) = &stats.db_path {
println!("db_path: {}", path.display());
}
println!(
"db_size: {}",
human_bytes(stats.db_bytes)
);
println!("hosts: {}", stats.hosts);
println!("indexed_dirs: {}", stats.indexed_dirs);
println!("chunks: {}", stats.chunks);
}
println!("db_size: {}", human_bytes(stats.db_bytes));
println!("hosts: {}", stats.hosts);
println!("indexed_dirs: {}", stats.indexed_dirs);
println!("chunks: {}", stats.chunks);
}
}
CacheAction::Clear { json } => {
scanner.clear_cache()?;
if *json {
println!(r#"{{"cleared":true}}"#);
} else {
println!("Cache cleared.");
CacheAction::Clear { json } => {
scanner.clear_cache()?;
if *json {
println!(r#"{{"cleared":true}}"#);
} else {
println!("Cache cleared.");
}
}
}
CacheAction::Prune { older_than, json } => {
let pruned = scanner.prune_cache(*older_than)?;
if *json {
println!(r#"{{"pruned_chunks":{pruned}}}"#);
} else {
println!("Pruned {pruned} expired chunk(s).");
CacheAction::Prune { older_than, json } => {
let pruned = scanner.prune_cache(*older_than)?;
if *json {
println!(r#"{{"pruned_chunks":{pruned}}}"#);
} else {
println!("Pruned {pruned} expired chunk(s).");
}
}
}
},
}
}
Ok(())
}
Expand Down
Loading