Skip to content
Closed
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
9 changes: 9 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ and `cargo build --release` directly; CI runs the gate on both systems.
press keys — so a screen that panics while painting fails a test.
* **Never delete anything outside a marked path.** See `removal.rs`; the guards
are load-bearing and are covered by tests.
* **A remote scan is read-only.** Its tree holds another machine's paths, and
the same path may exist here. While `Disktree::remote` is set nothing may
mark, remove, reveal or probe a path; see `Disktree::set_remote`.

## Invariants

Expand Down Expand Up @@ -120,6 +123,12 @@ and `cargo build --release` directly; CI runs the gate on both systems.
| what Windows lists, measures and compares differently | `crates/disktree-core/src/windows.rs` — `unsafe` for Win32 |
| reading a whole NTFS drive from its file table | `crates/disktree-core/src/mft.rs` |
| a key, a screen transition, a mark | `crates/disktree-app/src/state.rs` |
| a view choice kept between launches | `crates/disktree-app/src/settings.rs` |
| which theme is in force | `crates/disktree-app/src/appearance.rs` |
| a Start menu or desktop shortcut, on Windows | `crates/disktree-app/src/shortcut.rs` |
| what a filter matches: name, kind, size | `crates/disktree-core/src/filter.rs` |
| listing another machine over SSH | `crates/disktree-core/src/remote.rs` |
| GiB or GB, and how a size is written | `crates/disktree-core/src/size.rs` |
| spacing, type and size | `crates/disktree-app/src/ui.rs` — tokens only, no `px` in layout |
| the mosaic's painting or labels | `crates/disktree-app/src/treemap_view.rs` |
| layout of a screen | `crates/disktree-app/src/views.rs` |
Expand Down
63 changes: 56 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,28 @@ disktree --help # options: apparent size, follow links, skip hidden, …
### The screen

- **Top:** the trail from `/`, then what is measured — **Size**, **Files** or
**Age**, **Hidden files**, **Apparent size**, and the depth drawn. In the
**Age**, **Hidden files**, **Apparent size**, and the depth drawn; at the
end, the settings (theme, deeper levels, and on Windows a shortcut on the
Start menu or the desktop) and the way to GitHub. The disk button beside
the name opens a page of every disk, with its name, size and room. Click
the empty space beside the trail, or press `ctrl l`, and the trail becomes
a text field holding the path: copy it, or type or paste another and press
Enter to go there. In the
tree a crumb goes there, and its ▾ lists its siblings, largest first with
their share and size, to jump sideways (arrows and Enter work too). Above
the scanned root a crumb is dimmer, and clicking it widens the scan to
there (see below).
- **Under it:** the scan totals, the filter when one is typed, and the legend.
- **Under it:** the scan totals, **Filter** and **Name**, and the legend.
Filter narrows the mosaic to the kinds of data that are ticked, any number
of them, and to files between a **Min** and a **Max** size, each typed
with its own unit, up to the terabyte, and emptied by the cross in its
field. The button counts what is in force and the menu reads it back as
a sentence. The menu works from the keyboard: Tab and Shift+Tab walk it,
Space ticks, Enter applies, Esc closes. Name is the filter `/` opens,
and Esc there drops the name alone. The two combine. The settings page
also chooses
whether sizes read in GiB (1024s) or GB (1000s), and says which version
and build this is.
- **Mosaic:** colour is the *kind* of data — code, agent scratch,
toolchains, synced files, git, media, documents, caches — at one muted
level, lighter with depth. A diagonal hatch is space that can be had back
Expand Down Expand Up @@ -226,8 +242,10 @@ and shows how much free space was actually gained.
| `esc` while scanning | stop the scan |
| `v` | scan another mounted volume |
| `ctrl o` (`⌘O` on macOS) | choose another directory to scan |
| `ctrl l` (`⌘L` on macOS) | type or paste a path to go to; `esc` puts the trail back |
| `g` | the whole disk |
| `p` | show or hide the selection line |
| `T` | the system's theme, light or dark |
| `o` | show it in Finder, File Explorer or the file manager |
| right-click | show that tile in Finder, File Explorer or the file manager |
| `?` | every key |
Expand All @@ -238,6 +256,18 @@ rescan, ⌘[ and ⌘] for back and forward, and ⌘Q, ⌘H and ⌘W (closing the
window quits); other ⌘ chords are left to the system. On Linux and Windows
the same work with ctrl, with F5 to rescan too.

Every hint in the bar along the bottom is also a button for its key. The
key list, the settings and the page of disks close with `esc`, their Close
button, or a click outside them.

The depth stops at 6 levels unless the settings allow 10: deeper draws many
more tiles, most too small to read, and is slow on a whole disk.

The theme, the depth, Size / Files / Age, hidden files, apparent size and
the panel's width are remembered between launches, in `disktree/settings`
beside the Power Efficiency preset; an option on the command line still
overrules what was saved.

On the review screen: `m` trash, `p` permanent, `!` unmark all, `enter`
commits, `esc` goes back. Or hand the list on instead of acting on it: `s`
saves it as a text file, one path per line, and `a` copies a prompt for a
Expand Down Expand Up @@ -270,11 +300,30 @@ and removes duplicate hardlinks.

## Switching volumes

Press `v` (or click **Volumes** beside the disk name in the side panel) to
bring up the volume picker. It lists every candidate volume mounted on the
system together with its free space, ordered fullest first, filtering out
pseudo-filesystems and duplicate btrfs/APFS mount points. Selecting any
entry resets the scan root directly to that volume.
Press `v`, or click the disk's name or **Volumes** beside it in the side
panel, to bring up the volume picker. When the scan is of a whole volume,
its crumb in the trail (`C:\` or `/`) opens it too. It lists every
candidate volume mounted on the system together with its free space, by
name, filtering out pseudo-filesystems and duplicate btrfs/APFS mount
points. Selecting any entry resets the scan root directly to that volume.

## Another machine, over SSH

The page of disks has an address field: `user@host:/path`, or
`ssh://user@host:2222/path`, scans that directory on another machine. The
path field (`ctrl l`) takes the same address. The other machine runs
`find` and the tree is built from what it lists, so nothing is installed
there, but it has to have GNU `find`: a Linux machine, not macOS or a BSD.

The connection is your own `ssh`: its keys, agent, config and
`known_hosts`. disktree never asks for a password, and a host it has not
seen before is refused rather than trusted, so connect once from a
terminal first.

A remote scan is **read-only**. Its paths are the other machine's, and the
same path may exist on this one, so nothing can be marked or removed, and
the file manager, git and the free-space meter are off until a local
directory is scanned again.

## The whole disk

Expand Down
38 changes: 37 additions & 1 deletion crates/disktree-app/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
fn main() {
use std::{env, fs, path::PathBuf, process::Command};

build_number();

let icon = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap())
.join("../../assets/disktree.ico")
.canonicalize()
Expand Down Expand Up @@ -62,4 +64,38 @@ fn main() {
}

#[cfg(not(windows))]
fn main() {}
fn main() {
build_number();
}

/// Which build this is, for the settings page: the number of commits it
/// was built from and the last one's short name, `412.6c8d4ce`. A build
/// from a source archive has no history to count and says so.
fn build_number() {
let git = |args: &[&str]| {
std::process::Command::new("git")
.args(args)
.output()
.ok()
.filter(|output| output.status.success())
.and_then(|output| String::from_utf8(output.stdout).ok())
.map(|text| text.trim().to_owned())
.filter(|text| !text.is_empty())
};
let build = git(&["rev-list", "--count", "HEAD"])
.zip(git(&["rev-parse", "--short", "HEAD"]))
.map_or_else(
|| "unknown".to_owned(),
|(count, commit)| format!("{count}.{commit}"),
);
println!("cargo:rustc-env=DISKTREE_BUILD={build}");
// Every commit, checkout and merge appends to this log, so the number
// is never left over from an older one. git is asked where it is: in
// a worktree it is not under `.git` here. Only a log that exists is
// named, since cargo takes a missing one as changed on every build.
if let Some(log) = git(&["rev-parse", "--git-path", "logs/HEAD"])
.filter(|log| std::path::Path::new(log).exists())
{
println!("cargo:rerun-if-changed={log}");
}
}
94 changes: 93 additions & 1 deletion crates/disktree-app/src/appearance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,84 @@
//! are none, and gpui-omarchy would then stay on its dark default whatever
//! the system is set to; there the app follows the system appearance instead,
//! with the crate's own dark and light palettes, and switches when it does.
//!
//! Either can be overruled: a [`ThemeChoice`] of light or dark stays put
//! whatever the desktop does, until the choice goes back to the system's.

use std::path::Path;

use gpui_kit::{App, Window, WindowAppearance};
use gpui_omarchy::Theme;

/// Whose palette is drawn: the system's, or one picked here.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum ThemeChoice {
/// The Omarchy theme, or the system's light or dark setting.
#[default]
System,
Light,
Dark,
}

impl ThemeChoice {
pub const ALL: [Self; 3] = [Self::System, Self::Light, Self::Dark];

pub const fn key(self) -> &'static str {
match self {
Self::System => "system",
Self::Light => "light",
Self::Dark => "dark",
}
}

pub const fn name(self) -> &'static str {
match self {
Self::System => "System",
Self::Light => "Light",
Self::Dark => "Dark",
}
}

pub fn parse(value: &str) -> Option<Self> {
Self::ALL.into_iter().find(|choice| choice.key() == value)
}

/// The choice after this one, for a control that steps through them.
#[must_use]
pub const fn next(self) -> Self {
match self {
Self::System => Self::Light,
Self::Light => Self::Dark,
Self::Dark => Self::System,
}
}
}

/// The choice in force, where the appearance observer can see it: a system
/// that turns dark at dusk must not repaint a window that was told light.
struct Chosen(ThemeChoice);

impl gpui_kit::Global for Chosen {}

/// Draw with `choice` from now on. `appearance` is the window's, used when
/// the choice is the system's and there is no Omarchy theme to follow.
pub fn choose(
choice: ThemeChoice,
appearance: WindowAppearance,
home: Option<&Path>,
cx: &mut App,
) {
cx.set_global(Chosen(choice));
match choice {
ThemeChoice::Light => Theme::flexoki_light().apply(cx),
ThemeChoice::Dark => Theme::tokyo_night().apply(cx),
ThemeChoice::System if follows_system(home) => apply(appearance, cx),
// Back to the Omarchy theme files, which an explicit theme stopped
// watching.
ThemeChoice::System => Theme::follow_system(cx),
}
}

/// Whether the system appearance, rather than an Omarchy theme, decides the
/// colours: unless an Omarchy theme is installed, on macOS and Windows, and
/// on a Linux desktop that states a preference.
Expand Down Expand Up @@ -52,14 +124,34 @@ pub fn apply(appearance: WindowAppearance, cx: &mut App) {
/// Follow `window`'s appearance from now on.
pub fn follow(window: &Window) {
window
.observe_window_appearance(|window, cx| apply(window.appearance(), cx))
.observe_window_appearance(|window, cx| {
let chosen = cx
.try_global::<Chosen>()
.map_or(ThemeChoice::System, |chosen| chosen.0);
if chosen == ThemeChoice::System {
apply(window.appearance(), cx);
}
})
.detach();
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn the_theme_control_steps_through_every_choice_and_back() {
let mut choice = ThemeChoice::default();
for expected in
[ThemeChoice::Light, ThemeChoice::Dark, ThemeChoice::System]
{
choice = choice.next();
assert_eq!(choice, expected);
assert_eq!(ThemeChoice::parse(choice.key()), Some(choice));
}
assert_eq!(ThemeChoice::parse("plaid"), None);
}

#[test]
fn a_linux_desktop_is_followed_only_if_it_states_a_preference() {
let native = cfg!(any(target_os = "macos", windows));
Expand Down
Loading