@@ -39,31 +39,49 @@ children:
3939## Usage
4040
4141` ` ` bash
42- treemapper . # YAML to stdout
42+ treemapper . # YAML to stdout + token count
4343treemapper . -o tree.yaml # save to file
44+ treemapper . -o # save to tree.yaml (default filename)
4445treemapper . -o - # explicit stdout output
45- treemapper . --format json # JSON format
46- treemapper . --format text # tree-style text
46+ treemapper . -f json # JSON format
47+ treemapper . -f txt # plain text with indentation
48+ treemapper . -f md # Markdown with headings and fenced code blocks
49+ treemapper . -f yml # YAML format (alias for yaml)
4750treemapper . --no-content # structure only (no file contents)
4851treemapper . --max-depth 3 # limit directory depth
4952treemapper . --max-file-bytes 10000 # skip files larger than 10KB
53+ treemapper . --max-file-bytes 0 # no limit (include all files)
5054treemapper . -i custom.ignore # custom ignore patterns
5155treemapper . --no-default-ignores # disable .gitignore/.treemapperignore (custom -i still works)
52- treemapper . -v 2 # verbose output (0=ERROR, 1=WARNING, 2=INFO, 3=DEBUG)
53- treemapper . -c # copy output to clipboard (also outputs to stdout)
54- treemapper . --copy-only # copy to clipboard only (no stdout output)
55- treemapper --version # show version
56+ treemapper . --log-level info # log level (error/warning/info/debug)
57+ treemapper . -c # copy to clipboard (no stdout)
58+ treemapper . -c -o tree.yaml # copy to clipboard + save to file
59+ treemapper -v # show version
60+ ```
61+
62+ ## Token Counting
63+
64+ Token count and size are always displayed on stderr:
65+
66+ ```
67+ 12,847 tokens (o200k_base), 52.3 KB
68+ Copied to clipboard
5669```
5770
71+ For large outputs (>1MB), approximate counts are shown with ` ~ ` prefix:
72+ ```
73+ ~125,000 tokens (o200k_base), 5.2 MB
74+ ```
75+
76+ Uses tiktoken with ` o200k_base ` encoding (GPT-4o tokenizer).
77+
5878## Clipboard Support
5979
6080Copy output directly to clipboard with ` -c ` or ` --copy ` :
6181
6282``` bash
63- treemapper . -c # copy to clipboard + stdout
83+ treemapper . -c # copy to clipboard (no stdout)
6484treemapper . -c -o tree.yaml # copy to clipboard + save to file
65- treemapper . --copy-only # copy to clipboard only
66- treemapper . --copy-only -o tree.yaml # copy to clipboard + save to file (no stdout)
6785```
6886
6987** System Requirements:**
@@ -72,10 +90,12 @@ treemapper . --copy-only -o tree.yaml # copy to clipboard + save to file (no std
7290- ** Linux/FreeBSD (Wayland):** ` wl-copy ` (install: ` sudo apt install wl-clipboard ` )
7391- ** Linux/FreeBSD (X11):** ` xclip ` or ` xsel ` (install: ` sudo apt install xclip ` )
7492
93+ If clipboard is unavailable, output falls back to stdout with a warning on stderr.
94+
7595## Python API
7696
7797``` python
78- from treemapper import map_directory, to_yaml, to_json, to_text
98+ from treemapper import map_directory, to_yaml, to_json, to_text, to_markdown
7999
80100# Full function signature
81101tree = map_directory(
@@ -95,7 +115,8 @@ tree = map_directory(".", max_file_bytes=50000, ignore_file="custom.ignore")
95115# Serialize to string
96116yaml_str = to_yaml(tree)
97117json_str = to_json(tree)
98- text_str = to_text(tree)
118+ text_str = to_text(tree) # or to_txt(tree)
119+ md_str = to_markdown(tree) # or to_md(tree)
99120```
100121
101122## Ignore Patterns
@@ -111,8 +132,8 @@ Features:
111132## Content Placeholders
112133
113134When file content cannot be read normally, placeholders are used:
114- - ` <file too large: N bytes> ` — file exceeds ` --max-file-bytes ` limit
115- - ` <binary file: N bytes> ` — file detected as binary (contains null bytes)
135+ - ` <file too large: N bytes> ` — file exceeds ` --max-file-bytes ` limit (default: 10 MB)
136+ - ` <binary file: N bytes> ` — binary file ( detected by extension or null bytes)
116137- ` <unreadable content: not utf-8> ` — file is not valid UTF-8
117138- ` <unreadable content> ` — file cannot be read (permission denied, I/O error)
118139
@@ -134,8 +155,9 @@ Integration tests only - test against real filesystem. No mocking.
134155src/treemapper/
135156├── cli.py # argument parsing
136157├── ignore.py # gitignore/treemapperignore handling
158+ ├── tokens.py # token counting (tiktoken)
137159├── tree.py # directory traversal
138- ├── writer.py # YAML/JSON/text output
160+ ├── writer.py # YAML/JSON/text/Markdown output
139161└── treemapper.py # main entry point
140162```
141163
0 commit comments