def strip_go

cli@0.2.0.0 · cli.bend:76

import cli@0.2.0.0/cli.bend as Cli
import Base

76def strip_go(s: String, state: StripState) -> String:
77  match s:
78    case SNil{}:
79      match state:
80        case StripPlain{}: ""
81        case StripEsc{}: "\u{1B}"
82        case StripBody{pending}: pending
83    case SCon{+h, t}:
84      match state:
85        case StripPlain{}:
86          +esc = Char.is_eq(h, '\u{1B}')
87          String.append(Bool.pick(String, esc, "", Char.show(h)),
88            strip_go(t, Bool.pick(StripState, esc, StripEsc{}, StripPlain{})))
89        case StripEsc{}:
90          +bracket = Char.is_eq(h, '[')
91          +esc = Char.is_eq(h, '\u{1B}')
92          +prefix = Bool.pick(String, bracket, "",
93            Bool.pick(String, esc, "\u{1B}",
94              String.append("\u{1B}", Char.show(h))))
95          +next = Bool.pick(StripState, bracket, StripBody{"\u{1B}["},
96            Bool.pick(StripState, esc, StripEsc{}, StripPlain{}))
97          String.append(prefix, strip_go(t, next))
98        case StripBody{+pending}:
99          +end = Char.is_eq(h, 'm')
100          +esc = Char.is_eq(h, '\u{1B}')
101          +ok = sgr_body_char(h)
102          +grown = String.append(pending, Char.show(h))
103          +prefix = Bool.pick(String, end, "",
104            Bool.pick(String, esc, pending,
105              Bool.pick(String, ok, "", grown)))
106          +next = Bool.pick(StripState, end, StripPlain{},
107            Bool.pick(StripState, esc, StripEsc{},
108              Bool.pick(StripState, ok, StripBody{grown}, StripPlain{})))
109          String.append(prefix, strip_go(t, next))

Uses (8)

Used by (1)