Skip to content

Add --cli: print the scanned tree to standard output - #85

Open
armada45-pixel wants to merge 1 commit into
tobi:mainfrom
armada45-pixel:cli-text-tree
Open

armada45-pixel wants to merge 1 commit into
tobi:mainfrom
armada45-pixel:cli-text-tree

Conversation

@armada45-pixel

@armada45-pixel armada45-pixel commented Oct 12, 2026 •

Copy link
Copy Markdown

Closes #74, to the shape proposed there.

disktree --cli [--depth N] [PATH] scans through the existing pipeline and prints the tree instead of opening a window:

$ disktree --cli --depth 2 crates
947 KiB  H:\code\disktree\crates
├──    498 KiB   53%  disktree-core/
│   ├──    493 KiB   99%  src/ …
│   ├──    4.0 KiB    1%  examples/ …
│   └──    1.5 KiB    0%  Cargo.toml
└──    449 KiB   47%  disktree-app/
    ├──    444 KiB   99%  src/ …
    ├──    4.0 KiB    1%  build.rs
    └──      904 B    0%  Cargo.toml

947 KiB in 34 files, 6 directories
  • Largest first, each row with its share of its parent; directories end in /.
  • --depth is how many levels print. A directory the limit stops at ends in … rather than reading as empty.
  • Past 96 children (report::CHILDREN_KEPT, the same number as LayoutOptions::max_children) the rest share one … N more row with the summed value.
  • Every scan flag applies unchanged; --metric files ranks and prints counts.
  • A name holding a control character is escaped, so it cannot read as two rows.
  • A closed pipe (| head) is not an error; a failed scan exits non-zero.

Where it lives

crates/disktree-core/src/report.rs renders, with its tests beside it; main.rs gains the flag and print_tree, which returns before any GPUI setup. README has an "In the terminal" section and AGENTS.md's map lists the module.

Notes for review

  • The author of disktree --cli: print the tree to stdout, for agents and headless sessions #74 (@X-SCI-TECH) said there that they have their own implementation and offered a PR. If that one is preferred, close this — it is written to the issue's spec so the two should look alike.
  • The count of unreadable directories is taken from read_error on the tree, not from ScanProgress, because the blocking scan does not hand its progress back. Unreadable files are therefore not in that number.
  • On Windows the binary is a windows_subsystem program that attaches to the parent console; output there and through a pipe both work, but a console on a legacy code page may not draw the box characters.

Testing

Windows 11, Rust 1.97.1: cargo xtask lint green, cargo xtask test green (69 app, 163 core). Run by hand against this repository, also piped into head. Not run on Linux or macOS.

🤖 Generated with Claude Code

For a caller that can only read output: an agent, an SSH session, a
script. The scan is the window's own; `report::text_tree` prints it
largest first, each row with its share of its parent, `--depth` levels
deep. A directory the depth limit stops at ends in an ellipsis instead of
reading as empty, the tail past the 96 children the mosaic keeps shares
one row, and a name with a control character is escaped so it stays on
its row. A closed pipe is the reader having had enough, not an error.

Closes tobi#74

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

disktree --cli: print the tree to stdout, for agents and headless sessions

1 participant