Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/antimonit/directorytree
https://github.com/antimonit/directorytree
Last synced: 7 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/antimonit/directorytree
- Owner: Antimonit
- License: apache-2.0
- Created: 2022-05-08T01:28:15.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-07-10T16:40:22.000Z (over 2 years ago)
- Last Synced: 2023-07-04T02:13:38.761Z (over 1 year ago)
- Language: Kotlin
- Size: 109 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![Maven Central](https://img.shields.io/badge/Kotlin-Multiplatform-blueviolet)
[![Maven Central](https://img.shields.io/maven-central/v/io.github.antimonit/directory-tree.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22io.github.antimonit%22%20AND%20a:%22directory-tree%22)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![CircleCI](https://img.shields.io/circleci/build/gh/Antimonit/DirectoryTree?label=CircleCI)](https://circleci.com/gh/Antimonit/DirectoryTree/tree/main)
[![Codecov](https://img.shields.io/codecov/c/gh/Antimonit/DirectoryTree?label=Codecov)](https://codecov.io/gh/Antimonit/DirectoryTree)# DirectoryTree
A tiny Kotlin DSL to pretty-print hierarchies of directories and files.
```kotlin
val hierarchy = directory {
directory("featureOne") {
file("build.gradle.kts")
}
directory("featureTwo") {
file("build.gradle.kts")
}
directory("gradle-common") {
file("build.gradle.kts")
// optional shorthand form for multiple nested directories
directory("src", "main", "kotlin") {
directory("com", "sample", "gradle") {
// optional shorthand form for a single file in one or more nested directories
file("android", "library.gradle.kts")
file("jacoco", "android.gradle.kts")
file("sonarqube", "android.gradle.kts")
}
}
}
}println(hierarchy)
``````
├── featureOne
│ ╰── build.gradle.kts
├── featureTwo
│ ╰── build.gradle.kts
╰── gradle-common
├── build.gradle.kts
╰── src
╰── main
╰── kotlin
╰── com
╰── sample
╰── gradle
├── android
│ ╰── library.gradle.kts
├── jacoco
│ ╰── android.gradle.kts
╰── sonarqube
╰── android.gradle.kts
```## Configuration
Additional configuration can be specified by passing a `DirectoryContext` to the top-level `directory` function.
```kotlin
directory(
context = DirectoryContext(
separators = Separators(
empty = " ",
pipe = "│ ",
split = "├── ",
corner = "╰── ",
),
sortMode = SortMode.NONE,
directoriesFirst = false,
compactMode = CompactMode.NONE,
)
) {
file("file.txt")
}
```### Separators
Customize separators.```
empty = " "
pipe = "│ "
split = "├── "
corner = "╰── "
``````
empty = " "
pipe = "║ "
split = "╟─╴"
corner = "╙─╴"
``````
empty = " "
pipe = "│ "
split = "┝━━━ "
corner = "┕━━━ "
``````
├── one
│ ╰── a.txt
╰── two
╰── b.txt
``````
╟─╴one
║ ╙─╴a.txt
╙─╴two
╙─╴b.txt
``````
┝━━━ one
│ ┕━━━ a.txt
┕━━━ two
┕━━━ b.txt
```### Sort mode
* `NONE` - Do not sort.
* `ASC` - Sort ascending by file/directory names.
* `DESC` - Sort descending by file/directory names.`NONE`
`ASC`
`DESC`
├── one
├── two
╰── three├── one
├── three
╰── two├── two
├── three
╰── one### Directories first
* `false` - Do not reorganize files/directories.
* `true` - Place directories before files.`false`
`true`
├── z.txt
├── one
│ ╰── file.txt
╰── a.txt├── one
│ ╰── file.txt
├── z.txt
╰── a.txt### Compact mode
* `NONE` - No directories and files will be merged and each will display on a separate line.
* `EXACT` - Directories and files defined in a single call to `directory` or `file` will be merged.
* `DIRECTORIES` - Directories with no sibling directories or files will be merged with their parents.
* `ALL` - Directories and files with no sibling directories or files will be merged with their parents.```kotlin
directory(
DirectoryContext(compactMode = compactMode)
) {
directory("one") {
file("two", "file.txt")
}
}```
`NONE`
`EXACT`
`DIRECTORIES`
`ALL`
╰── one
╰── two
╰── file.txt╰── one
╰── two/file.txt╰── one/two
╰── file.txt╰── one/two/file.txt
# Download
The library is available from the MavenCentral repository as a Kotlin Multiplatform library targeting JVM, JS and
native:```kotlin
implementation("io.github.antimonit:directory-tree:1.3.0")
```