mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-01 06:37:46 +00:00
refactor: ✨ (#418)
* refactor: ✨ move in one commit Eveything in modules should probably be changed to `exported` defs. The idea is to move everything first to keep proper history. * refactor: 📝 add modules readme (wip) * refactor: ✨ small move * refactor: 📝 changed nestring, updated modules readme * refactor: 📝 to document or not to document * fix: 🐛 themes replaced the template to use `main` and regenerated them from lemnos themes. * Revert "fix: 🐛 themes" This reverts commit 4918d3633c8d2d81950a0ed0cfd9eb84241bc886. * refactor: ✨ introduce sourced - Created a source `root` in which sourcable demos are stored. Some might get converted to modules later on. - Moved some files to bin too. * fix: 🐛 fehbg.nu * fix: 🐛 modules/after.nu * moved some other stuff around --------- Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
This commit is contained in:
parent
382696cd21
commit
c47ccd42b8
128 changed files with 185 additions and 12 deletions
37
modules/coloring/24bit-1.nu
Normal file
37
modules/coloring/24bit-1.nu
Normal file
|
@ -0,0 +1,37 @@
|
|||
export def draw [] {
|
||||
let term_cols = ((term size).columns - 1)
|
||||
|
||||
# let's itertate through each of the columns of our terminal
|
||||
0..$term_cols | each { |col|
|
||||
let r = (255 - ($col * 255 / $term_cols) | math round)
|
||||
let g = ($col * 510 / $term_cols | math round)
|
||||
let b = ($col * 255 / $term_cols | math round)
|
||||
if $g > 255 {
|
||||
let g = (510 - $g)
|
||||
build-colorstr $r $g $b $col
|
||||
} else {
|
||||
build-colorstr $r $g $b $col
|
||||
}
|
||||
} | str join
|
||||
}
|
||||
|
||||
def build-colorstr [
|
||||
r:int # Red
|
||||
g:int # Green
|
||||
b:int # Blue
|
||||
c:int # Column
|
||||
] {
|
||||
# Heavy use of string interpolation below
|
||||
let bg = $"(ansi rgb_bg)($r);($g);($b)m"
|
||||
let fg = $"(ansi rgb_fg)(255 - $r);(255 - $g);(255 - $b)m"
|
||||
let idx = ($c mod 2)
|
||||
let slash_str = (if $idx == 0 {
|
||||
$'/(ansi reset)'
|
||||
} else {
|
||||
$'\(ansi reset)'
|
||||
})
|
||||
$"($bg)($fg)($slash_str)"
|
||||
# sleep 10ms | ignore
|
||||
}
|
||||
|
||||
draw
|
69
modules/coloring/256_color_testpattern.nu
Normal file
69
modules/coloring/256_color_testpattern.nu
Normal file
|
@ -0,0 +1,69 @@
|
|||
def contrast_colour [ colour:int ] {
|
||||
# The first 16 colors
|
||||
if $colour < 16 {
|
||||
if $colour == 0 {
|
||||
15
|
||||
} else {
|
||||
0
|
||||
}
|
||||
} else {
|
||||
# The gray colors
|
||||
if $colour > 231 {
|
||||
if $colour < 244 {
|
||||
15
|
||||
} else {
|
||||
0
|
||||
}
|
||||
} else {
|
||||
# The rest
|
||||
let r = ($colour - 16) / 36
|
||||
let g = (($colour - 16) mod 36) / 6
|
||||
let b = ($colour - 16) mod 6
|
||||
|
||||
let luminance = ($r * 299) + ($g * 587) + ($b * 114)
|
||||
if $luminance > 2500 {
|
||||
0
|
||||
} else {
|
||||
15
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def print_colour [ colour:int ] {
|
||||
let contrast = (contrast_colour $colour)
|
||||
let bg_color = $"(ansi idx_bg)($colour)m" # Start block of colour
|
||||
let fg_color = $"(ansi idx_fg)($contrast)m" # In contrast, print number
|
||||
let text = $"($colour | into string | fill -c ' ' -w 3 -a r)(ansi reset)"
|
||||
$bg_color + $fg_color + $text + " "
|
||||
}
|
||||
|
||||
let printable_colours = 256
|
||||
|
||||
def print_run [start:int, amount:int] {
|
||||
$start..<($start + $amount) | each { |i|
|
||||
if $i < $printable_colours {
|
||||
print_colour $i
|
||||
} else {
|
||||
""
|
||||
}
|
||||
} | append " " | str join
|
||||
}
|
||||
|
||||
def print_blocks [start:int, end:int, block_cols:int, block_rows:int, blocks_per_line:int] {
|
||||
let block_length = ($block_cols * $block_rows)
|
||||
let end = (($end - $start) / (($blocks_per_line) * $block_length))
|
||||
0..<$end | each { |i|
|
||||
0..<$block_rows | each { |row|
|
||||
0..<$blocks_per_line | each { |block|
|
||||
print_run ($start + $block * $block_length + $row * $block_cols + $i * $block_length * $blocks_per_line) $block_cols
|
||||
} | append (char nl) | str join
|
||||
} | str join
|
||||
} | str join
|
||||
}
|
||||
|
||||
print (print_run 0 16) # The first 16 colours are spread over the whole spectrum
|
||||
print "" # Single line
|
||||
print (print_blocks 16 123 6 6 3) # 6x6x6 colour cube between 16 and 123 inclusive
|
||||
print (print_blocks 124 231 6 6 3) # 6x6x6 colour cube between 124 and 231 inclusive
|
||||
print (print_blocks 232 255 12 2 1) # Not 50, but 24 Shades of Grey
|
5
modules/coloring/README.md
Normal file
5
modules/coloring/README.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
# Coloring Scripts
|
||||
|
||||
### Definition
|
||||
|
||||
These scripts are used to demonstrate the `ansi` command using `ansi` coloring. This is mainly a demo area where we have taken typical `bash` scripts and ported them to nushell scripts. It would be nice if all scripts here showed the "other" version of script and the ported nushell version. We can show "other" flavors of scripts by including them as comments in the nushell scripts or by naming the nushell script and the other script the same basename.
|
56
modules/coloring/hl.nu
Normal file
56
modules/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 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
|
||||
}
|
149
modules/coloring/html_colors.nu
Normal file
149
modules/coloring/html_colors.nu
Normal file
|
@ -0,0 +1,149 @@
|
|||
# these are common colors from https://en.wikipedia.org/wiki/web_colors
|
||||
let aliceblue = "#f0f8ff"
|
||||
let antiquewhite = "#faebd7"
|
||||
let aqua = "#00ffff"
|
||||
let aquamarine = "#7fffd4"
|
||||
let azure = "#f0ffff"
|
||||
let beige = "#f5f5dc"
|
||||
let bisque = "#ffe4c4"
|
||||
let black = "#000000"
|
||||
let blanchedalmond = "#ffebcd"
|
||||
let blue = "#0000ff"
|
||||
let blueviolet = "#8a2be2"
|
||||
let brown = "#a52a2a"
|
||||
let burlywood = "#deb887"
|
||||
let cadetblue = "#5f9ea0"
|
||||
let chartreuse = "#7fff00"
|
||||
let chocolate = "#d2691e"
|
||||
let coral = "#ff7f50"
|
||||
let cornflowerblue = "#6495ed"
|
||||
let cornsilk = "#fff8dc"
|
||||
let crimson = "#dc143c"
|
||||
let cyan = "#00ffff"
|
||||
let darkblue = "#00008b"
|
||||
let darkcyan = "#008b8b"
|
||||
let darkgoldenrod = "#b8860b"
|
||||
let darkgray = "#a9a9a9"
|
||||
let darkgrey = "#a9a9a9"
|
||||
let darkgreen = "#006400"
|
||||
let darkkhaki = "#bdb76b"
|
||||
let darkmagenta = "#8b008b"
|
||||
let darkolivegreen = "#556b2f"
|
||||
let darkorange = "#ff8c00"
|
||||
let darkorchid = "#9932cc"
|
||||
let darkred = "#8b0000"
|
||||
let darksalmon = "#e9967a"
|
||||
let darkseagreen = "#8fbc8f"
|
||||
let darkslateblue = "#483d8b"
|
||||
let darkslategray = "#2f4f4f"
|
||||
let darkslategrey = "#2f4f4f"
|
||||
let darkturquoise = "#00ced1"
|
||||
let darkviolet = "#9400d3"
|
||||
let deeppink = "#ff1493"
|
||||
let deepskyblue = "#00bfff"
|
||||
let dimgray = "#696969"
|
||||
let dimgrey = "#696969"
|
||||
let dodgerblue = "#1e90ff"
|
||||
let firebrick = "#b22222"
|
||||
let floralwhite = "#fffaf0"
|
||||
let forestgreen = "#228b22"
|
||||
let fuchsia = "#ff00ff"
|
||||
let gainsboro = "#dcdcdc"
|
||||
let ghostwhite = "#f8f8ff"
|
||||
let gold = "#ffd700"
|
||||
let goldenrod = "#daa520"
|
||||
let gray = "#808080"
|
||||
let grey = "#808080"
|
||||
let green = "#008000"
|
||||
let greenyellow = "#adff2f"
|
||||
let honeydew = "#f0fff0"
|
||||
let hotpink = "#ff69b4"
|
||||
let indianred = "#cd5c5c"
|
||||
let indigo = "#4b0082"
|
||||
let ivory = "#fffff0"
|
||||
let khaki = "#f0e68c"
|
||||
let lavender = "#e6e6fa"
|
||||
let lavenderblush = "#fff0f5"
|
||||
let lawngreen = "#7cfc00"
|
||||
let lemonchiffon = "#fffacd"
|
||||
let lightblue = "#add8e6"
|
||||
let lightcoral = "#f08080"
|
||||
let lightcyan = "#e0ffff"
|
||||
let lightgoldenrodyellow = "#fafad2"
|
||||
let lightgray = "#d3d3d3"
|
||||
let lightgrey = "#d3d3d3"
|
||||
let lightgreen = "#90ee90"
|
||||
let lightpink = "#ffb6c1"
|
||||
let lightsalmon = "#ffa07a"
|
||||
let lightseagreen = "#20b2aa"
|
||||
let lightskyblue = "#87cefa"
|
||||
let lightslategray = "#778899"
|
||||
let lightslategrey = "#778899"
|
||||
let lightsteelblue = "#b0c4de"
|
||||
let lightyellow = "#ffffe0"
|
||||
let lime = "#00ff00"
|
||||
let limegreen = "#32cd32"
|
||||
let linen = "#faf0e6"
|
||||
let magenta = "#ff00ff"
|
||||
let maroon = "#800000"
|
||||
let mediumaquamarine = "#66cdaa"
|
||||
let mediumblue = "#0000cd"
|
||||
let mediumorchid = "#ba55d3"
|
||||
let mediumpurple = "#9370d8"
|
||||
let mediumseagreen = "#3cb371"
|
||||
let mediumslateblue = "#7b68ee"
|
||||
let mediumspringgreen = "#00fa9a"
|
||||
let mediumturquoise = "#48d1cc"
|
||||
let mediumvioletred = "#c71585"
|
||||
let midnightblue = "#191970"
|
||||
let mintcream = "#f5fffa"
|
||||
let mistyrose = "#ffe4e1"
|
||||
let moccasin = "#ffe4b5"
|
||||
let navajowhite = "#ffdead"
|
||||
let navy = "#000080"
|
||||
let oldlace = "#fdf5e6"
|
||||
let olive = "#808000"
|
||||
let olivedrab = "#6b8e23"
|
||||
let orange = "#ffa500"
|
||||
let orangered = "#ff4500"
|
||||
let orchid = "#da70d6"
|
||||
let palegoldenrod = "#eee8aa"
|
||||
let palegreen = "#98fb98"
|
||||
let paleturquoise = "#afeeee"
|
||||
let palevioletred = "#d87093"
|
||||
let papayawhip = "#ffefd5"
|
||||
let peachpuff = "#ffdab9"
|
||||
let peru = "#cd853f"
|
||||
let pink = "#ffc0cb"
|
||||
let plum = "#dda0dd"
|
||||
let powderblue = "#b0e0e6"
|
||||
let purple = "#800080"
|
||||
let rebeccapurple = "#663399"
|
||||
let red = "#ff0000"
|
||||
let rosybrown = "#bc8f8f"
|
||||
let royalblue = "#4169e1"
|
||||
let saddlebrown = "#8b4513"
|
||||
let salmon = "#fa8072"
|
||||
let sandybrown = "#f4a460"
|
||||
let seagreen = "#2e8b57"
|
||||
let seashell = "#fff5ee"
|
||||
let sienna = "#a0522d"
|
||||
let silver = "#c0c0c0"
|
||||
let skyblue = "#87ceeb"
|
||||
let slateblue = "#6a5acd"
|
||||
let slategray = "#708090"
|
||||
let slategrey = "#708090"
|
||||
let snow = "#fffafa"
|
||||
let springgreen = "#00ff7f"
|
||||
let steelblue = "#4682b4"
|
||||
let tan = "#d2b48c"
|
||||
let teal = "#008080"
|
||||
let thistle = "#d8bfd8"
|
||||
let tomato = "#ff6347"
|
||||
let turquoise = "#40e0d0"
|
||||
let violet = "#ee82ee"
|
||||
let wheat = "#f5deb3"
|
||||
let white = "#ffffff"
|
||||
let whitesmoke = "#f5f5f5"
|
||||
let yellow = "#ffff00"
|
||||
let yellowgreen = "#9acd32"
|
Loading…
Add table
Add a link
Reference in a new issue