lipstick
Safe HaskellNone
LanguageGHC2024

Lipstick.Outline

Description

Lists and trees.

Both are outlines: items with an enumerator (a bullet, a number, a tree branch) and nested items indented below them. A tree has a root; forest, list and nestedList do not. By default tree and forest use tree branches, list and nestedList bullets.

Items are blocks, so anything can go in an outline, tables included.

Examples

>>> let os = Node "." [Node "macOS" [], Node "Linux" [Node "NixOS" [], Node "Arch" []], Node "BSD" []]
>>> putBlock (tree mempty os)
.
├── macOS
├── Linux
│   ├── NixOS
│   └── Arch
└── BSD
>>> putBlock (tree (enumerator roundedTreeEnumerator) os)
.
├── macOS
├── Linux
│   ├── NixOS
│   ╰── Arch
╰── BSD
>>> let shops = ["Glossier", "Claire's Boutique", "Nyx"]
>>> putBlock (list mempty shops)
• Glossier
• Claire's Boutique
• Nyx
>>> putBlock (list (enumerator arabic) shops)
1. Glossier
2. Claire's Boutique
3. Nyx

Nested lists, with an enumerator for each depth:

>>> let products = [Node "Glossier" [Node "Cloud Paint" [], Node "Boy Brow" []], Node "Nyx" []]
>>> putBlock (nestedList (enumerator (byDepth (\d -> if d == 0 then roman else dash))) products)
 I. Glossier
    - Cloud Paint
    - Boy Brow
II. Nyx

Items wrap in the width left after their enumerator:

>>> putBlock (fromGrid (layout (Just 16) (list mempty ["A long item that wraps", "short"])))
• A long item
  that wraps
• short

Items can be styled by position, and are blocks themselves:

>>> putBlock (list (itemStyleWith (\p -> if isLast p then border roundedBorder else mempty)) ["one", "two", "last"])
• one
• two
• ╭────╮
  │last│
  ╰────╯

An enumerator of your own:

>>> let arrows = markers (const "→ ")
>>> putBlock (list (enumerator arrows) shops)
→ Glossier
→ Claire's Boutique
→ Nyx
Synopsis

Documentation

data Outline Source #

The settings of a list or tree: its enumerator and indenter, the styles of the root, items, enumerators and indentation, its size, and the items it shows. Change them with the Mod Outline passed to tree, forest, list or nestedList.

Items are laid out in the width left after their indentation and enumerator, so their text wraps to fit. width is the width of the outline when there is room for it, as for a style: items wrap to fit it, and every line is padded to it with the background of its item's style. fillWidth pads to the width the outline is given, and height pads with blank lines up to that many.

Instances

Instances details
HasSize Outline Source # 
Instance details

Defined in Lipstick.Outline

Methods

overSize :: (Size -> Size) -> Outline -> Outline

HasCrop Outline Source # 
Instance details

Defined in Lipstick.Outline

tree :: Mod Outline -> Tree Block -> Block Source #

A tree: the root, then its children, with tree branches by default.

forest :: Mod Outline -> Forest Block -> Block Source #

Trees without a common root, with tree branches by default.

list :: Mod Outline -> [Block] -> Block Source #

A list of items, with bullets by default.

nestedList :: Mod Outline -> Forest Block -> Block Source #

A list whose items can have nested items, with bullets by default.

Styling

data ItemPos Source #

Where an item is: its depth (0 for the top level), its index among its siblings (from 0), and how many siblings there are, itself included. At the top level, only the items that itemOffset shows count.

Instances

Instances details
Eq ItemPos Source # 
Instance details

Defined in Lipstick.Outline

Methods

(==) :: ItemPos -> ItemPos -> Bool #

(/=) :: ItemPos -> ItemPos -> Bool #

Show ItemPos Source # 
Instance details

Defined in Lipstick.Outline

rootStyle :: Mod Style -> Mod Outline Source #

Style the root of a tree.

itemStyle :: Mod Style -> Mod Outline Source #

Style every item.

itemStyleWith :: (ItemPos -> Mod Style) -> Mod Outline Source #

Style items by position. Successive item styles add up.

enumeratorStyle :: Mod Style -> Mod Outline Source #

Style every enumerator (and the indentation below it).

enumeratorStyleWith :: (ItemPos -> Mod Style) -> Mod Outline Source #

Style enumerators by position. Successive enumerator styles add up.

indenterStyle :: Mod Style -> Mod Outline Source #

Style the indentation before an item's further lines and its children. Until an indenter style is set, the enumerator style is used.

indenterStyleWith :: (ItemPos -> Mod Style) -> Mod Outline Source #

Style the indentation by position. Successive indenter styles add up.

itemOffset :: Int -> Int -> Mod Outline Source #

itemOffset start end shows only part of the top-level items, leaving out start at the beginning and end at the end. Enumerators and ItemPos count only the items shown.

Enumerators

data Enumerator Source #

How items are marked. Markers of different widths at one level are right-aligned to the widest. Make one with markers, and change its fields with record update syntax:

>>> let arrows = (markers (\p -> if isLast p then "└> " else "├> ")) {enumIndent = \p -> Just (if isLast p then "   " else "│  ")}
>>> putBlock (tree (enumerator arrows) (Node "root" [Node "a" [Node "a.1" []], Node "b" []]))
root
├> a
│  └> a.1
└> b

markers :: (ItemPos -> Text) -> Enumerator Source #

An enumerator with these markers, and further lines and children indented by spaces as wide as the widest marker at their level.

>>> putBlock (list (enumerator (markers (\p -> if isLast p then "> " else "- "))) ["a", "b", "c"])
- a
- b
> c

enumerator :: Enumerator -> Mod Outline Source #

Mark items with this enumerator.

>>> putBlock (nestedList (enumerator (byDepth (\d -> if d == 0 then roman else bullet))) [Node "one" [Node "two" []]])
I. one
   • two

byDepth :: (Int -> Enumerator) -> Enumerator Source #

An enumerator chosen by depth (0 for the top level).

isLast :: ItemPos -> Bool Source #

Whether an item is the last among its siblings.

indenter :: (ItemPos -> Text) -> Mod Outline Source #

What goes before an item's further lines and its children, instead of the enumerator's own indentation.

treeEnumerator :: Enumerator Source #

├── and └── , with │ continuing the branch.

roundedTreeEnumerator :: Enumerator Source #

Like treeEnumerator with a rounded last branch: ╰── .

arabic :: Enumerator Source #

1. , 2. , …

alphabet :: Enumerator Source #

A. , B. , … Z. , AA. , …

roman :: Enumerator Source #

I. , II. , III. , IV. , …