Skip to content

Commit

Permalink
Fixed errors in doc/basics.md
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Dec 31, 2023
1 parent b83edb6 commit eb3370d
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions doc/basics.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
All Escritoire terms and types are defined in the `escritoire` package:
```scala
import escritoire.*
```

Creating a table to be displayed in a monospaced font (e.g. for rendering in a console) is easy,
and first requires a `Tabulation` instance to be defined, specifying each column and how it should
be rendered.

For example,
```scala
import anticipation.Text
import gossamer.t

case class Person(name: Text, age: Int, active: Boolean)

val table = Tabulation[Person](
Column("Name", _.name),
Column("Age", _.age),
Column("Active", p => if p.active then "Yes" else "No")
val table = Table[Person](
Column(t"Name")(_.name),
Column(t"Age")(_.age),
Column(t"Active"): person =>
if person.active then t"Yes" else t"No"
)
```
describes a table of three columns, `Name`, `Age` and `Active`, defined for rows of type `Person`,
Expand All @@ -23,10 +32,17 @@ Given such a definition, any collection of instances of `Person`, `ps`, can be r

For example,
```scala
val persons = List(Person("Bill", 48, true), Person("Janet", 54, false))
table.tabulate(100, persons)
import turbulence.Out
import turbulence.stdioSources.virtualMachine
import escritoire.tableStyles.default
import hieroglyph.textWidthCalculation.uniform

val persons = List(Person(t"Bill", 48, true), Person(t"Janet", 54, false))

def renderTable(): Unit =
table.tabulate(persons, 100).foreach(Out.println(_))
```
will return a sequence of `Text`s which will print as,
will return and print a sequence of `Text`s as,
```
┌───────┬─────┬────────┐
│ Name │ Age │ Active │
Expand Down

0 comments on commit eb3370d

Please sign in to comment.