A command line tool to view objects (JSON/YAML/TOML/XML) in TUI tree widget.
Find a file
June 5fda276e21
fix: check file size before reading to prevent OOM (#134)
* fix: check file size before reading to prevent OOM

The previous implementation read the entire file into memory before
checking if it exceeded max_data_size. For very large files, this
could cause out-of-memory errors before the size check could reject
the file.

This fix uses fs::metadata() to check the file size BEFORE reading
its contents. This prevents OOM errors when users accidentally try
to open multi-gigabyte files.

For stdin input, the size check still happens after reading (since
we can't know stdin size beforehand), but this is unavoidable.

Changes:
- Check file metadata.len() before fs::read() for file paths
- Add integration test that verifies rejection of >30 MiB files
- Improve error message to show both file size and limit

The fix maintains backward compatibility - stdin behavior is
unchanged, and the default 30 MiB limit remains the same.

* fix: avoid u64-to-usize truncation in file size check

Compare metadata.len() (u64) against max_data_size widened to u64
instead of narrowing the file size to usize, which would silently
wrap on 32-bit targets and let oversized files through.
2026-05-16 23:58:01 +08:00
.github build(deps): bump actions/checkout from 5 to 6 (#114) 2025-12-23 10:37:17 +08:00
assets docs: update screenshot 2024-06-28 10:20:36 +08:00
config chore: add missing option in default config 2025-08-26 10:47:08 +08:00
docs chore: release v0.6.5 2026-03-03 18:46:12 +08:00
examples feat(parse): support hcl (#99) 2025-08-26 15:15:23 +08:00
src fix: check file size before reading to prevent OOM (#134) 2026-05-16 23:58:01 +08:00
tests fix: check file size before reading to prevent OOM (#134) 2026-05-16 23:58:01 +08:00
.gitignore fix: pin ratatui ecosystem deps to compatible versions 2026-04-13 18:39:35 +08:00
build.rs feat(parse): support xml (#92) 2025-08-25 10:29:20 +08:00
Cargo.lock fix: check file size before reading to prevent OOM (#134) 2026-05-16 23:58:01 +08:00
Cargo.toml fix: check file size before reading to prevent OOM (#134) 2026-05-16 23:58:01 +08:00
LICENSE Initial commit 2024-05-11 18:39:35 +08:00
README.md feat(ui): support highlighting filter keyword in tree (#94) 2025-08-25 13:57:32 +08:00
typos.toml feat(data): support wrap mode (#108) 2025-10-15 17:56:24 +08:00

OTree - Object Tree TUI Viewer

screenshot

A command line tool to view objects (JSON/YAML/TOML/XML) in TUI tree widget.

Install

Download binary files from release page.

You can also build it from source (require cargo installed):

cargo install --git https://github.com/fioncat/otree

Arch Linux (AUR)

You can install otree from the AUR with using an AUR helper.

paru -S otree

macOS and Linux (Homebrew)

You can install otree using Homebrew.

brew install otree

Usage

Open a JSON/YAML/TOML file in TUI tree viewer:

otree /path/to/file.json
otree /path/to/file.yaml
otree /path/to/file.toml
otree /path/to/file.xml

For more command usage, please run otree --help.

You can configure TUI keys, colors, and more in ~/.config/otree.toml, the default configuration is here.

For all available actions and their default key bindings, please refer to: All Available Actions.

For how to configure TUI colors, please refer to: Colors Document.

Roadmap

  • UI: Header (v0.1)
  • UI: Tree Overview (v0.1)
  • UI: Data Block (v0.1)
  • UI: Footer to show current root and identify (and other messages) (v0.2)
  • UI: Filter Input (v0.5)
  • UI: Popup widget to show error or help messages (v0.2)
  • UI: Highlight filtering keywords (v0.6)
  • Action: Change current selected item as root (v0.1)
  • Action: Back to previous root (v0.1)
  • Action: Scale up/down tree widget (v0.1)
  • Action: Mouse click actions
  • Action: Mouse scroll actions
  • Action: Open current selected item in editor ReadOnly (v0.2)
  • Action: Switch between tree overview and data block (v0.1)
  • Action: Jump to parent item (v0.1)
  • Action: Jump to parent item and close (v0.1)
  • Action: Expand selected item's children (v0.5)
  • Action: Expand all items (v0.5)
  • Action: Close all opened items (v0.1)
  • Action: Popup to show help messages (v0.5)
  • Action: Clipboard support, copy current item's content (might need to call external program like wl-copy, pbcopy) (v0.2)
  • Syntax highlighting in data block (v0.2)
  • Allow user to customize TUI colors and key bindings (and other things you can imagine) (v0.1)
  • Filter items! (Like jnv) (v0.5)
  • With --debug flag, write some debug logs to a file (v0.4)

If you have any great ideas, please create an issue, thanks!

Thanks

I created this tool to better view those super deep YAML files of Kubernetes while jnv only supports JSON.

This is based on the amazing TUI framework ratatui and its tree widget tui-tree-widget.