Text-tree output.
This package provides a simple interface to output tree-structured data. The single function write-text-tree writes the provided racket data structures out to a port.
procedure
(write-text-tree value [out]) → void?
value : tree-input/c out : output-port? = (current-output-port) 
> (require racket/port) 
> (displayln (with-output-to-string (λ () (write-text-tree (make-hash `((collection . "text-tree") (deps base) (build-deps scribble-lib racket-doc rackunit-lib) (scribblings "scribblings/text-tree.scrbl") (test-omit-paths "scribblings") (pkg-desc . "Function to output tree-structured data.") (version . 1.0) (pkg-authors johnstonskj) (license . Apache-2.0))))))) 
├── build-deps
│ ├── scribble-lib
│ ├── racket-doc
│ └── rackunit-lib
├── collection
│ └── text-tree
├── deps
│ └── base
├── license
│ └── Apache-2.0
├── pkg-authors
│ └── johnstonskj
├── pkg-desc
│ └── Function to output tree-structured data.
├── scribblings
│ └── scribblings/text-tree.scrbl
├── test-omit-paths
│ └── scribblings
└── version
└── 1.0
procedure
(text-tree->string value) → string?
value : tree-input/c 
predicate
(dotted-pair? val) → boolean?
val : any/c 
predicate
(simple-dictionary? val) → boolean?
val : any/c 
predicate
(simple-sequence? val) → boolean?
val : any/c 
value
- atom? – Individual value. 
- simple-sequence? – Where every member is a tree-input/c. 
- simple-sequence? – Where every key is a atom? and every value is a tree-input/c. 
1 Parameters
parameter
→ (list/c char? char? char? char? char?) (tree-representation-line-chars line-chars) → void? line-chars : (list/c char? char? char? char? char?) 
- Horizontal bar character, default #\─. 
- Vertical bar character, default #\│. 
- Bottom-left corner character, default #\└. 
- Right-facing tee character, default #\├. 
- Spacing character, default #\space. 
> (require racket/port) 
> (parameterize ((tree-representation-line-chars ascii-line-chars)) (displayln (with-output-to-string (λ () (write-text-tree (make-hash '((collection . "text-tree") (deps "base") (build-deps "scribble-lib" "racket-doc" "rackunit-lib") (license . Apache-2.0)))))))) 
+-- build-deps
| +-- scribble-lib
| +-- racket-doc
| '-- rackunit-lib
+-- collection
| '-- text-tree
+-- deps
| '-- base
'-- license
'-- Apache-2.0
> (require racket/port) 
> (parameterize ((tree-representation-line-chars unicode-line-chars)) (displayln (with-output-to-string (λ () (write-text-tree (make-hash '((collection . "text-tree") (deps "base") (build-deps "scribble-lib" "racket-doc" "rackunit-lib") (license . Apache-2.0)))))))) 
├── build-deps
│ ├── scribble-lib
│ ├── racket-doc
│ └── rackunit-lib
├── collection
│ └── text-tree
├── deps
│ └── base
└── license
└── Apache-2.0
parameter
→ 
(or/c string? (-> (or/c simple-dictionary? simple-sequence?) string?)) (unnamed-sequence-string unnamed) → void? 
unnamed : 
(or/c string? (-> (or/c simple-dictionary? simple-sequence?) string?)) 
= "<empty>" 
> (displayln (text-tree->string (list (list "date" "May 2024")))) 
└── <empty>
├── date
└── May 2024
> (parameterize ((unnamed-sequence-string "nil")) (displayln (text-tree->string (list (list "date" "May 2024"))))) 
└── nil
├── date
└── May 2024
> (define (name-for-unnamed val) (cond ((list? val) "empty?") ((hash? val) "hash-empty?"))) 
> (parameterize ((unnamed-sequence-string name-for-unnamed)) (displayln (text-tree->string (list (list "date" "May 2024"))))) 
└── empty?
├── date
└── May 2024