1.0
top
← prev up next →

Text-tree output.πŸ”— i

Simon Johnston <johnstonskj@gmail.com>

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
TBD

Examples:
> (require racket/port)
`((collection. "text-tree")
(depsbase)
(build-depsscribble-libracket-docrackunit-lib)
(scribblings"scribblings/text-tree.scrbl")
(test-omit-paths"scribblings")
(pkg-desc. "Function to output tree-structured data.")
(version. 1.0)
(pkg-authorsjohnstonskj)
(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
A convenience wrapper around write-text-tree that writes value to, and returns, a string.

predicate

( atom? val)boolean?

val:any/c
Returns #t if the val is one of boolean? , char? , number? , string? , bytes , or symbol? . Atoms are written out using the ~a format function.

predicate

( dotted-pair? val)boolean?

val:any/c
Returns #t if the val is an dotted or improper pair where the cdr is not a list.

predicate

( simple-dictionary? val)boolean?

val:any/c
Returns #t if the val is either a hash? or a structure implementing gen:dict?.

predicate

( simple-sequence? val)boolean?

val:any/c
Returns #t if the val is one of list? , vector? , flvector?, fxvector?, or set?.

This is the value accepted by the function and consists of atomic values, sequences (restricted to lists, mutable lists, vectors, fixnum vectors, flonum vectors, hash tables, sets, and streams), and dictionaries.

1ParametersπŸ”— i

A parameter that is used in drawing the tree’s connecting lines. The default value is unicode-line-chars , whereas the value ascii-line-chars may be more broadly supported but is a lower quality output.

  1. Horizontal bar character, default #\─.

  2. Vertical bar character, default #\│.

  3. Bottom-left corner character, default #\└.

  4. Right-facing tee character, default #\├.

  5. Spacing character, default #\space.

A set of simple ASCII characters for a low-fi tree.

Examples:
> (require racket/port)
'((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

A set of Unicode line-drawing characters for a higher fidelity tree.

Examples:
> (require racket/port)
'((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

This parameter determines the string to use as the root value for anonymous sequences and dictionaries.

Example:
> (displayln (text-tree->string (list (list "date""May 2024"))))

└── <empty>

├── date

└── May 2024

Example:

└── nil

├── date

└── May 2024

Examples:
> (define (name-for-unnamedval)
(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

top
← prev up next →

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /