-
Notifications
You must be signed in to change notification settings - Fork 220
/
hl.nu
56 lines (51 loc) · 1.29 KB
/
hl.nu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
export def combine [txt: string, fg: record, bg: record] {
{
txt: $txt,
fg: $fg.fg,
bg: $bg.fg,
bli: ($fg.bli or $bg.bli),
bol: ($fg.bol or $bg.bol),
dim: ($fg.dim or $bg.dim),
hid: ($fg.hid or $bg.hid),
ita: ($fg.ita or $bg.ita),
rev: ($fg.rev or $bg.rev),
stk: ($fg.stk or $bg.stk),
und: ($fg.und or $bg.und)
}
}
export def create [txt: string,
fg = "n", bg = "n",
bli = false, bol = false, dim = false, hid = false,
ita = false, rev = false, stk = false, und = false] {
{
txt: $txt,
fg: $fg,
bg: $bg,
bli: $bli,
bol: $bol,
dim: $dim,
hid: $hid,
ita: $ita,
rev: $rev,
stk: $stk,
und: $und
}
}
export def render [obj: record] {
let attr = ""
let attr = $"($attr)(if $obj.bli {'l'})"
let attr = $"($attr)(if $obj.bol {'b'})"
let attr = $"($attr)(if $obj.dim {'d'})"
let attr = $"($attr)(if $obj.hid {'h'})"
let attr = $"($attr)(if $obj.ita {'i'})"
let attr = $"($attr)(if $obj.rev {'r'})"
let attr = $"($attr)(if $obj.stk {'s'})"
let attr = $"($attr)(if $obj.und {'u'})"
let color = {fg: $obj.fg, bg: $obj.bg, attr: $attr}
$"(ansi $color)($obj.txt)(ansi reset)"
}
export def reverse [obj: record] {
let r = ($obj | update fg $obj.bg)
let r = ($r | update bg $obj.fg)
$r
}