---
title: "Feature tour"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Feature tour}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

```{r setup}
library(printtree)
```

This article walks through the output features added in `printtree` 0.2.1.

```{r demo-tree}
demo <- file.path(tempdir(), "printtree-feature-tour")
if (dir.exists(demo)) unlink(demo, recursive = TRUE, force = TRUE)

dir.create(file.path(demo, "R"), recursive = TRUE)
dir.create(file.path(demo, "data", "raw"), recursive = TRUE)
dir.create(file.path(demo, "logs"), recursive = TRUE)
dir.create(file.path(demo, "empty"), recursive = TRUE)

file.create(file.path(demo, "R", "helpers.R"))
file.create(file.path(demo, "README.md"))
file.create(file.path(demo, "data", "raw", "sales.csv"))
file.create(file.path(demo, "logs", "debug.log"))
file.create(file.path(demo, "test_cache"))
```

## Count summaries

By default, `print_rtree()` ends with a displayed directory/file count.

```{r count-summary}
print_rtree(demo, max_depth = 2)
```

Set `count_footer = FALSE` for compact output.

```{r compact-output}
print_rtree(demo, max_depth = 1, count_footer = FALSE)
```

## Pattern ignores

The `ignore` argument still supports exact basenames, but with
`ignore_type = "auto"` it also treats wildcard entries as glob patterns.

```{r glob-ignore}
print_rtree(demo, ignore = c("*.log", "test_*"), max_depth = 2)
```

You can opt into regular expression matching for more control.

```{r regex-ignore}
print_rtree(demo, ignore = "^(README|test_)", ignore_type = "regex", max_depth = 1)
```

## Prune empty directories

Use `prune = TRUE` to hide directories with no displayable children after
ignores and depth limits are applied.

```{r prune}
print_rtree(demo, ignore = "*.log", prune = TRUE)
```

## Quiet capture

Use `quiet = TRUE` with `return_lines = TRUE` when you want to work with the
tree programmatically.

```{r quiet-capture}
lines <- print_rtree(demo, return_lines = TRUE, quiet = TRUE)
head(lines, 4)
```

## Text and Markdown export

`write_tree()` writes the same tree output to a text or Markdown file. Parent
directories are created automatically by default.

```{r write-tree}
tree_md <- file.path(tempdir(), "printtree-feature-tour-output", "tree.md")
write_tree(demo, tree_md, format = "md", title = "Feature Tour Tree")
readLines(tree_md, n = 8)
```

## Git status annotations

When the target folder is inside a Git work tree, `git = TRUE` annotates changed
paths with simple status markers and includes a legend.

The example is not evaluated when building the vignette so automated checks do
not depend on an external Git executable or repository configuration.

```{r git-status, eval = FALSE}
# From inside an existing Git repository:
print_rtree(".", git = TRUE)

# Hide the legend when you already know the markers:
print_rtree(".", git = TRUE, git_legend = FALSE)
```
