tui/fmt.bend checks
raw source on the hub · import cswap-bend-cli@0.1.0.0/tui/fmt.bend as Fmt
1 import
import Base
Types
type Role source · line 8 · raw
Data
What a segment looks like. RPlain carries no escape at all.
RPlainRole
RBoldRole
RAccentRole
RAccentBRole
RMutedRole
ROkRole
RWarnRole
RCritRole
RTrackRole
type Seg source · line 20 · raw
Data
A run of text in one style; dim fades it (a stale measurement).
Seg@text:String -> @role:Role -> @dim:Bool -> Seg
Definitions
def sg source · line 23 · raw
@+t:String -> @+r:Role -> Seg
def sel.s source · line 26 · raw
@+c:Bool -> @+x:String -> @+y:String -> String
def sel.u source · line 33 · raw
@+c:Bool -> @+x:U32 -> @+y:U32 -> U32
def spaces source · line 40 · raw
@+n:Nat -> String
def pad_right source · line 44 · raw
@+s:String -> @+w:Nat -> String
Pad on the right / left to w characters (never truncates).
def pad_left source · line 47 · raw
@+s:String -> @+w:Nat -> String
def round_even source · line 54 · raw
@+c:U32 -> U32
Centi-percent (4750 = 47.5 %) to a whole percent, halves to even as Python's
f"{pct:.0f}" does.
def pct_text source · line 60 · raw
@+c:U32 -> String
" 47%" (width 4), as the reference's {pct:3.0f}%.
def hm source · line 63 · raw
@+s:U32 -> String
def dh source · line 67 · raw
@+s:U32 -> String
def duration source · line 74 · raw
@+s:U32 -> String
The shortest honest duration: 45s, 12m, 2h 13m, 2h, 3d 4h, 3d.
def seg_len source · line 79 · raw
@+s:Seg -> Nat
def line_len source · line 84 · raw
@+l:List<&2, Seg> -> Nat
def cut source · line 91 · raw
@+s:Seg -> @+n:Nat -> Seg
def take_pick source · line 96 · raw
@+over:Bool -> @+s:Seg -> @+n:Nat -> @+rest:List<&2, Seg> -> List<&2, Seg>
def take_chars source · line 104 · raw
@+l:List<&2, Seg> -> @+n:Nat -> List<&2, Seg>
The first n characters of a line.
def ellipsized source · line 111 · raw
@+l:List<&2, Seg> -> @+w:Nat -> List<&2, Seg>
def fit_if source · line 114 · raw
@+over:Bool -> @+l:List<&2, Seg> -> @+w:Nat -> List<&2, Seg>
def fit source · line 124 · raw
@+l:List<&2, Seg> -> @+w:Nat -> List<&2, Seg>
A line no wider than w: longer ones end in an ellipsis.
def sev_ok source · line 127 · raw
@+warn:Bool -> Role
def sev_warn source · line 134 · raw
@+c:U32 -> Role
def sev_pick source · line 137 · raw
@+crit:Bool -> @+c:U32 -> Role
def severity source · line 145 · raw
@+c:U32 -> Role
Bar colour from the centi-percent: red from 90 %, amber from 70 %.
def is_tick source · line 148 · raw
@+t:Maybe<&2, Nat> -> @+i:Nat -> Bool
def cell_kind source · line 155 · raw
@+tick:Bool -> @+filled:Bool -> @+half:Bool -> @+r:Role -> @+dim:Bool -> Seg
def cell source · line 166 · raw
@+i:Nat -> @+full:Nat -> @+half:Bool -> @+tick:Maybe<&2, Nat> -> @+r:Role -> @+dim:Bool -> Seg
def cells source · line 170 · raw
@+n:Nat -> @+i:Nat -> @+full:Nat -> @+half:Bool -> @+tick:Maybe<&2, Nat> -> @+r:Role -> @+dim:Bool -> List<&2, Seg>
n cells from index i.
def tick_at source · line 178 · raw
@+thr:Maybe<&2, U32> -> @+w:Nat -> Maybe<&2, Nat>
Where the threshold tick sits: round(threshold / 100 * width), kept in range.
def bar source · line 186 · raw
@+pct:Maybe<&2, U32> -> @+w:Nat -> @+thr:Maybe<&2, U32> -> @+stale:Bool -> List<&2, Seg>
A usage bar of w cells for a centi-percent (None: an empty track).
def sgr source · line 195 · raw
@+r:Role -> String
def codes source · line 216 · raw
@+r:Role -> @+dim:Bool -> String
def paint_with source · line 219 · raw
@+color:Bool -> @+t:String -> @+c:String -> String
def paint_seg source · line 222 · raw
@+s:Seg -> @+color:Bool -> String
def paint_all source · line 227 · raw
@+l:List<&2, Seg> -> @+color:Bool -> String
def style_key source · line 234 · raw
@+s:Seg -> String
def same_style source · line 239 · raw
@+a:Seg -> @+b:Seg -> Bool
def join_seg source · line 242 · raw
@+a:Seg -> @+b:Seg -> Seg
def merge_acc source · line 247 · raw
@+same:Bool -> @+cur:Seg -> @+s:Seg -> Seg
def merge_emit source · line 254 · raw
@+same:Bool -> @+cur:Seg -> @+rest:List<&2, Seg> -> List<&2, Seg>
def merge_go source · line 261 · raw
@+l:List<&2, Seg> -> @+cur:Seg -> List<&2, Seg>
def merged source · line 269 · raw
@+l:List<&2, Seg> -> List<&2, Seg>
Neighbouring segments in one style become one (one escape per run).
def paint source · line 276 · raw
@+l:List<&2, Seg> -> @+color:Bool -> String
def render_rest source · line 279 · raw
@+ls:List<&2, List<&2, Seg>> -> @+color:Bool -> String
def render source · line 287 · raw
@+ls:List<&2, List<&2, Seg>> -> @+color:Bool -> String
Lines joined with newlines, each painted (or plain under NO_COLOR).