Skip to content

Reset the indent state for -R sub-listings - #52

Open
Kenta11 wants to merge 1 commit into
Old-Man-Programmer:masterfrom
Kenta11:fix/rerun-indent-state
Open

Kenta11 wants to merge 1 commit into
Old-Man-Programmer:masterfrom
Kenta11:fix/rerun-indent-state

Conversation

@Kenta11

@Kenta11 Kenta11 commented Aug 23, 2026

Copy link
Copy Markdown

Overview

With -R, tree writes a sub-listing (00Tree.html) into each directory at the -L limit by calling emit_tree() recursively. The indent state lives in the global array dirs[], and indent() picks the glyph for level i by checking dirs[i+1]: nonzero means "a deeper level is still open", so it prints a continuation line instead of a branch. The recursive call inherits the outer walk's leftover dirs[] entries, so at the sub-listing's deepest level every branch prints as a continuation line. This change clears dirs[] before the nested emit_tree() — it is already saved and restored around it — so the sub-listing starts from the same state as a top-level run. The outer listing (top.html) is byte-identical before and after.

Steps to reproduce

$ mkdir -p r/a/{b/c,tail}
$ touch r/a/{b/f1,b/c/deep,tail/f2}
$ cd r && tree -L 2 -R -o top.html .
$ cat a/b/00Tree.html
./a/b
│   00Tree.html
│   c
│   └── deep
└── f1

2 directories, 3 files

After this change

$ mkdir -p r/a/{b/c,tail}
$ touch r/a/{b/f1,b/c/deep,tail/f2}
$ cd r && tree -L 2 -R -o top.html .
$ cat a/b/00Tree.html
./a/b
├── 00Tree.html
├── c
│   └── deep
└── f1

2 directories, 3 files

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.

1 participant