Skip to content

Antimonit/DirectoryTree

Repository files navigation

Maven Central Maven Central License CircleCI Codecov

DirectoryTree

A tiny Kotlin DSL to pretty-print hierarchies of directories and files.

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.

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.
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:

implementation("io.github.antimonit:directory-tree:1.3.0")

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages