mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-02 07:07:46 +00:00
feat: added coloring/hl.nu, a highlighting module (#299)
This commit is contained in:
parent
7a7051e9a7
commit
646dec4406
1 changed files with 56 additions and 0 deletions
56
coloring/hl.nu
Normal file
56
coloring/hl.nu
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
export def combine [txt: string, fg: record, bg: record] {
|
||||||
|
{
|
||||||
|
txt: $txt,
|
||||||
|
fg: $fg.fg,
|
||||||
|
bg: $bg.fg,
|
||||||
|
bli: ($fg.bli || $bg.bli),
|
||||||
|
bol: ($fg.bol || $bg.bol),
|
||||||
|
dim: ($fg.dim || $bg.dim),
|
||||||
|
hid: ($fg.hid || $bg.hid),
|
||||||
|
ita: ($fg.ita || $bg.ita),
|
||||||
|
rev: ($fg.rev || $bg.rev),
|
||||||
|
stk: ($fg.stk || $bg.stk),
|
||||||
|
und: ($fg.und || $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
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue