diff --git a/before_v0.60/coloring/24bit-1.nu b/before_v0.60/coloring/24bit-1.nu deleted file mode 100644 index 484840d4..00000000 --- a/before_v0.60/coloring/24bit-1.nu +++ /dev/null @@ -1,39 +0,0 @@ -let term_cols = ((term size -w) - 1) - -# let's itertate through each of the columns of our terminal -for col inc 0..$term_cols { - 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 | autoview - } { - build-colorstr $r $g $b $col | autoview - } -} - -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)" - } { - $"\(ansi reset)" - }) - $"($bg)($fg)($slash_str)" -} - -# This is a first attempt and some type of logging -def log [message:any] { - let now = (date now | date format '%Y%m%d_%H%M%S.%f') - let mess = $"($now)|DBG|($message)(char nl)" - echo $mess | autoview -} \ No newline at end of file diff --git a/before_v0.60/coloring/256-color.sh b/before_v0.60/coloring/256-color.sh deleted file mode 100644 index e79cd6be..00000000 --- a/before_v0.60/coloring/256-color.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -# This program is free software. It comes without any warranty, to -# the extent permitted by applicable law. You can redistribute it -# and/or modify it under the terms of the Do What The Fuck You Want -# To Public License, Version 2, as published by Sam Hocevar. See -# http://sam.zoy.org/wtfpl/COPYING for more details. - -for fgbg in 38 48 ; do # Foreground / Background - for color in {0..255} ; do # Colors - # Display the color - printf "\e[${fgbg};5;%sm %3s \e[0m" $color $color - # Display 6 colors per lines - if [ $((($color + 1) % 6)) == 4 ] ; then - echo # New line - fi - done - echo # New line -done - -exit 0 \ No newline at end of file diff --git a/before_v0.60/coloring/256_color_testpattern.nu b/before_v0.60/coloring/256_color_testpattern.nu deleted file mode 100644 index e73b20c2..00000000 --- a/before_v0.60/coloring/256_color_testpattern.nu +++ /dev/null @@ -1,77 +0,0 @@ - -let printable_colours = 256 - -def contrast_colour [ colour:int ] { - # The first 16 colors - if $colour < 16 { - if $colour == 0 { - 15 - } { - 0 - } - } { - # The gray colors - if $colour > 231 { - if $colour < 244 { - 15 - } { - 0 - } - } { - # The rest - let r = ($colour - 16) / 36 - let g = (($colour - 16) mod 36) / 6 - let b = ($colour - 16) mod 6 - - # if $g > 2 { - # 0 - # } { - # 15 - # } - - let luminance = ($r * 299) + ($g * 587) + ($b * 114) - if $luminance > 2500 { - 0 - } { - 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 | str lpad -c ' ' -l 3)(ansi reset)" - $bg_color + $fg_color + $text + " " -} - -def print_run [start:int, amount:int] { - for i in $start..<($start + $amount) { - if $i < $printable_colours { - print_colour $i - } { - "" - } - } | append " " | str collect -} - -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)) - for i in 0..<$end { - for row in 0..<$block-rows { - for block in 0..<$blocks-per-line { - print_run ($start + $block * $block-length + $row * $block-cols + $i * $block-length * $blocks-per-line) $block-cols - } | append (char nl) | str collect | autoview - } - char nl | autoview - } -} - -print_run 0 16 # The first 16 colours are spread over the whole spectrum -char nl -char nl -print_blocks 16 231 6 6 3 # 6x6x6 colour cube between 16 and 231 inclusive -print_blocks 232 255 12 2 1 # Not 50, but 24 Shades of Grey diff --git a/before_v0.60/coloring/256_color_testpattern.sh b/before_v0.60/coloring/256_color_testpattern.sh deleted file mode 100644 index 8a53f3bc..00000000 --- a/before_v0.60/coloring/256_color_testpattern.sh +++ /dev/null @@ -1,96 +0,0 @@ -#!/bin/bash - -# Tom Hale, 2016. MIT Licence. -# Print out 256 colours, with each number printed in its corresponding colour -# See http://askubuntu.com/questions/821157/print-a-256-color-test-pattern-in-the-terminal/821163#821163 - -set -eu # Fail on errors or undeclared variables - -printable_colours=256 - -# Return a colour that contrasts with the given colour -# Bash only does integer division, so keep it integral -function contrast_colour { - local r g b luminance - colour="$1" - - if (( colour < 16 )); then # Initial 16 ANSI colours - (( colour == 0 )) && printf "15" || printf "0" - return - fi - - # Greyscale # rgb_R = rgb_G = rgb_B = (number - 232) * 10 + 8 - if (( colour > 231 )); then # Greyscale ramp - (( colour < 244 )) && printf "15" || printf "0" - return - fi - - # All other colours: - # 6x6x6 colour cube = 16 + 36*R + 6*G + B # Where RGB are [0..5] - # See http://stackoverflow.com/a/27165165/5353461 - - # r=$(( (colour-16) / 36 )) - g=$(( ((colour-16) % 36) / 6 )) - # b=$(( (colour-16) % 6 )) - - # If luminance is bright, print number in black, white otherwise. - # Green contributes 587/1000 to human perceived luminance - ITU R-REC-BT.601 - (( g > 2)) && printf "0" || printf "15" - return - - # Uncomment the below for more precise luminance calculations - - # # Calculate perceived brightness - # # See https://www.w3.org/TR/AERT#color-contrast - # # and http://www.itu.int/rec/R-REC-BT.601 - # # Luminance is in range 0..5000 as each value is 0..5 - # luminance=$(( (r * 299) + (g * 587) + (b * 114) )) - # (( $luminance > 2500 )) && printf "0" || printf "15" -} - -# Print a coloured block with the number of that colour -function print_colour { - local colour="$1" contrast - contrast=$(contrast_colour "$1") - printf "\e[48;5;%sm" "$colour" # Start block of colour - printf "\e[38;5;%sm%3d" "$contrast" "$colour" # In contrast, print number - printf "\e[0m " # Reset colour -} - -# Starting at $1, print a run of $2 colours -function print_run { - local i - for (( i = "$1"; i < "$1" + "$2" && i < printable_colours; i++ )) do - print_colour "$i" - done - printf " " -} - -# Print blocks of colours -function print_blocks { - local start="$1" i - local end="$2" # inclusive - local block_cols="$3" - local block_rows="$4" - local blocks_per_line="$5" - local block_length=$((block_cols * block_rows)) - - # Print sets of blocks - for (( i = start; i <= end; i += (blocks_per_line-1) * block_length )) do - printf "\n" # Space before each set of blocks - # For each block row - for (( row = 0; row < block_rows; row++ )) do - # Print block columns for all blocks on the line - for (( block = 0; block < blocks_per_line; block++ )) do - print_run $(( i + (block * block_length) )) "$block_cols" - done - (( i += block_cols )) # Prepare to print the next row - printf "\n" - done - done -} - -print_run 0 16 # The first 16 colours are spread over the whole spectrum -printf "\n" -print_blocks 16 231 6 6 3 # 6x6x6 colour cube between 16 and 231 inclusive -print_blocks 232 255 12 2 1 # Not 50, but 24 Shades of Grey diff --git a/before_v0.60/coloring/README.md b/before_v0.60/coloring/README.md deleted file mode 100644 index 40b61109..00000000 --- a/before_v0.60/coloring/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# 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. diff --git a/before_v0.60/coloring/color_and_formatting.sh b/before_v0.60/coloring/color_and_formatting.sh deleted file mode 100644 index 2c8a2dd5..00000000 --- a/before_v0.60/coloring/color_and_formatting.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -# This program is free software. It comes without any warranty, to -# the extent permitted by applicable law. You can redistribute it -# and/or modify it under the terms of the Do What The Fuck You Want -# To Public License, Version 2, as published by Sam Hocevar. See -# http://sam.zoy.org/wtfpl/COPYING for more details. - -#Background -for clbg in {40..47} {100..107} 49 ; do - #Foreground - for clfg in {30..37} {90..97} 39 ; do - #Formatting - for attr in 0 1 2 4 5 7 ; do - #Print the result - echo -en "\033[${attr};${clbg};${clfg}m ^[${attr};${clbg};${clfg}m \033[0m" - done - echo #Newline - done -done - -exit 0 diff --git a/before_v0.60/coloring/color_table.nu b/before_v0.60/coloring/color_table.nu deleted file mode 100644 index 0fae41cd..00000000 --- a/before_v0.60/coloring/color_table.nu +++ /dev/null @@ -1,84 +0,0 @@ -def make_header [hi] { - if $hi == $true { - let ansi100m = ('100m' | str lpad -l 11 -c ' ') - let ansi101m = ('101m' | str lpad -l 9 -c ' ') - let ansi102m = ('102m' | str lpad -l 9 -c ' ') - let ansi103m = ('103m' | str lpad -l 9 -c ' ') - let ansi104m = ('104m' | str lpad -l 9 -c ' ') - let ansi105m = ('105m' | str lpad -l 9 -c ' ') - let ansi106m = ('106m' | str lpad -l 9 -c ' ') - let ansi107m = ('107m' | str lpad -l 9 -c ' ') - $"(char newline)($ansi100m)($ansi101m)($ansi102m)($ansi103m)($ansi104m)($ansi105m)($ansi106m)($ansi107m)(char newline)" - } { - let ansi40m = ('40m' | str lpad -l 10 -c ' ') - let ansi41m = ('41m' | str lpad -l 8 -c ' ') - let ansi42m = ('42m' | str lpad -l 8 -c ' ') - let ansi43m = ('43m' | str lpad -l 8 -c ' ') - let ansi44m = ('44m' | str lpad -l 8 -c ' ') - let ansi45m = ('45m' | str lpad -l 8 -c ' ') - let ansi46m = ('46m' | str lpad -l 8 -c ' ') - let ansi47m = ('47m' | str lpad -l 8 -c ' ') - $"(char newline)($ansi40m)($ansi41m)($ansi42m)($ansi43m)($ansi44m)($ansi45m)($ansi46m)($ansi47m)(char newline)" - } -} - -# mk_header and make_header do the same thing in different ways -# make_header is far easier to read and understand -# mk_header is more convoluted but less repetitive - -def mk_header [color_range:range] { - let min_rng = (echo $color_range | math min) - let hi_start_pad = 11 - let hi_regular_pad = 9 - let lo_start_pad = 10 - let lo_regular_pad = 8 - echo $color_range | each { |color| - let ansi_color = $"($color)m" - if $color == $min_rng { - if $min_rng == 100 { - ($ansi_color | str lpad -l $hi_start_pad -c ' ') - } { - ($ansi_color | str lpad -l $lo_start_pad -c ' ') - } - } { - if $min_rng >= 100 { - ($ansi_color | str lpad -l $hi_regular_pad -c ' ') - } { - ($ansi_color | str lpad -l $lo_regular_pad -c ' ') - } - } - } | str collect - echo (char newline) -} - -def color_row_range [num:int bg_rg:range] { - let reset = (ansi reset) - let row_header = $"($num)m ($reset)" - let row_data = (echo $bg_rg | each { |back| - let row_name = $"($num);($back)m" - let ansi_color = (ansi -e $row_name) - $"($ansi_color) ($row_name) ($reset)" - } | append (char newline) | str collect) - $"($row_header)($row_data)" -} - -def create_color_tables [fg_range:range bg_range:range] { - echo $fg_range | each { |fg| - color_row_range $fg $bg_range - } | str collect -} - -def color_table [] { - # make_header $false - mk_header 40..47 - create_color_tables 30..37 40..47 - - # put a line between tables - char newline - - #make_header $true - mk_header 100..107 - create_color_tables 90..97 100..107 -} - -color_table \ No newline at end of file diff --git a/before_v0.60/coloring/color_tables.nu b/before_v0.60/coloring/color_tables.nu deleted file mode 100644 index 27018c33..00000000 --- a/before_v0.60/coloring/color_tables.nu +++ /dev/null @@ -1,35 +0,0 @@ -# Bash script -# for x in {0..8}; do -# for i in {30..37}; do -# for a in {40..47}; do -# echo -ne "\e[$x;$i;$a""m\\\e[$x;$i;$a""m\e[0;37;40m " -# done -# echo -# done -# echo -# done -# echo "" - -# Nushell 0.32.0 -for x in 0..8 { - let row = (for i in 30..37 { - let row = (for a in 40..47 { - let color = $"($x);($i);($a)" - $"(ansi -e $color)m\e[($color)(ansi -e '0;37;40')m " - } | str collect) - $"($row)(char newline)" - } | str collect) - $"($row)(char newline)" -} | str collect - -# Nushell 0.31.0 -# echo 0..8 | each { |style| -# let row = (echo 30..37 | each { |fg| -# let row = (echo 40..47 | each { |bg| -# let color = $"($style);($fg);($bg)m" -# $"(ansi -e $color)($color)(ansi reset) " -# } | str collect) -# $"($row)(char newline)" -# } | str collect) -# $"($row)(char newline)" -# } | str collect \ No newline at end of file diff --git a/before_v0.60/coloring/color_tables.sh b/before_v0.60/coloring/color_tables.sh deleted file mode 100644 index 8a1659dc..00000000 --- a/before_v0.60/coloring/color_tables.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -for x in {0..8}; do - for i in {30..37}; do - for a in {40..47}; do - echo -ne "\e[$x;$i;$a""m\\\e[$x;$i;$a""m\e[0;37;40m " - done - echo - done - echo -done -echo "" diff --git a/before_v0.60/coloring/colors.sh b/before_v0.60/coloring/colors.sh deleted file mode 100644 index e5d05cfe..00000000 --- a/before_v0.60/coloring/colors.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash -# -# This is slightly altered from the original which is found here: -# http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html -# -# Each line is the color code of one foreground color, out of 17 -# (default + 16 escapes), followed by a test use of that color -# on all nine background colors (default + 8 escapes). -# - -text="xYz"; # Some test text - -echo -e "\n 40m 41m 42m 43m 44m 45m 46m 47m"; - -for FGs in ' m' ' 1m' ' 30m' '1;30m' ' 31m' '1;31m' ' 32m' \ - '1;32m' ' 33m' '1;33m' ' 34m' '1;34m' ' 35m' '1;35m' \ - ' 36m' '1;36m' ' 37m' '1;37m'; do - FG=${FGs// /} - echo -en " $FGs \033[$FG ${text} "; - for BG in 40m 41m 42m 43m 44m 45m 46m 47m; do - echo -en "$EINS \033[$FG\033[${BG} ${text} \033[0m"; - done - echo; -done -echo; \ No newline at end of file diff --git a/before_v0.60/coloring/gradient.nu b/before_v0.60/coloring/gradient.nu deleted file mode 100644 index 23cacee5..00000000 --- a/before_v0.60/coloring/gradient.nu +++ /dev/null @@ -1,41 +0,0 @@ -# this script will print a blue gradient on the screen - -# We can get the terminal width and height now with term size -# but we like to use the script as a benchmark, so let's keep -# it a constant size for now -let height = 40 # really need to get the terminal height here -let width = 160 # really need to get the terminal width here -let stamp = 'Nu' -seq 0 $height | each { - let row_data = (seq 0 $width | each { |col| - let fgcolor = (iter_inc 2 2 $col) - if $fgcolor > 200 and $fgcolor < 210 { - $"(ansi -e '48;2;0;0;')($fgcolor)m($stamp)(ansi -e '0m')" - } { - $"(ansi -e '48;2;0;0;')($fgcolor)m(char sp)(ansi -e '0m')" - } - } | str collect) - $"($row_data)(char newline)" | autoview -} | str collect - -def iter_inc [incr mult iter] { - $incr + $mult * $iter -} - -# ╭────┬────────────────────┬───────────────────────────────────────────────────────────────────────────────────────────────────╮ -# │ # │ key │ value │ -# ├────┼────────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────┤ -# │ 0 │ version │ 0.31.1 │ -# │ 1 │ branch │ main │ -# │ 2 │ short_commit │ 751de20f │ -# │ 3 │ commit_hash │ 751de20f938ed200ae6128a30d06a5dd24a4fd33 │ -# │ 4 │ commit_date │ 2021-05-21 02:04:27 │ -# │ 5 │ build_os │ windows-x86_64 │ -# │ 6 │ rust_version │ rustc 1.52.1 (9bc8c42bb 2021-05-09) │ -# │ 7 │ rust_channel │ stable (default) │ -# │ 8 │ cargo_version │ cargo 1.52.0 (69767412a 2021-04-21) │ -# │ 9 │ pkg_version │ 0.31.1 │ -# │ 10 │ build_time │ 2021-05-21 07:20:25 │ -# │ 11 │ build_rust_channel │ release │ -# │ 12 │ features │ clipboard-cli, ctrlc, default, directories, dirs, ptree, rustyline, term, trash, uuid, which, zip │ -# ╰────┴────────────────────┴───────────────────────────────────────────────────────────────────────────────────────────────────╯ \ No newline at end of file diff --git a/before_v0.60/coloring/gradient.ps1 b/before_v0.60/coloring/gradient.ps1 deleted file mode 100644 index 0fa3c18d..00000000 --- a/before_v0.60/coloring/gradient.ps1 +++ /dev/null @@ -1,27 +0,0 @@ -function Set-Cursor { - [CmdletBinding()] - param ([int] $x, [int] $y) - $Host.UI.RawUI.CursorPosition = @{x = $x; y = $y } -} - -function Get-Character { - [CmdletBinding()] - param ([int]$index) - $mystring = ' Trevor Sullivan' - return $index -ge ($mystring.Length) ? ' ' : $mystring[$index] -} - -function main { - - for ($y = 0; $y -le ($host.ui.RawUI.BufferSize.Height - 1); $y++) { - $Color = 25 - Set-Cursor -x $PSItem -y $y - 0..($Host.UI.RawUI.BufferSize.Width - 1) | ForEach-Object { - Write-Host -Object ("`e[48;2;0;0;$Color`m{0}" -f (Get-Character -Index $PSItem)) -NoNewline - $Color += 2 - } - } - Start-Sleep -Seconds 5 -} - -main diff --git a/before_v0.60/coloring/gradient.py b/before_v0.60/coloring/gradient.py deleted file mode 100644 index 98ee8ebd..00000000 --- a/before_v0.60/coloring/gradient.py +++ /dev/null @@ -1,24 +0,0 @@ -# this script will print a blue gradient on the screen -# this is a port of the gradient.nu script used for comparison - -from colors import * - -def iter_inc(incr, mult, it): - return incr + mult * it - -height = 40 -width = 160 -stamp = "py" - -for line in range(0, height): - row_data = "" - - for col in range(0, width): - fgcolor = iter_inc(2, 2, col) - if fgcolor > 200 and fgcolor < 210: - row_data = row_data + color(stamp, bg='rgb(0, 0, %d)' % fgcolor) - else: - fg = fgcolor % 256 - row_data = row_data + color(' ', bg='rgb(0, 0, %d)' % fg) - - print(row_data) diff --git a/before_v0.60/coloring/gradient_40x160.ps1 b/before_v0.60/coloring/gradient_40x160.ps1 deleted file mode 100644 index 8b4dcb9c..00000000 --- a/before_v0.60/coloring/gradient_40x160.ps1 +++ /dev/null @@ -1,86 +0,0 @@ -function Set-Cursor { - [CmdletBinding()] - param ([int] $x, [int] $y) - $Host.UI.RawUI.CursorPosition = @{x = $x; y = $y } -} - -function Get-Character { - [CmdletBinding()] - param ([int]$index) - $mystring = ' Trevor Sullivan' - return $index -ge ($mystring.Length) ? ' ' : $mystring[$index] -} - -# write one cell at at time moving the cursor across the screen -# ~1900 ms -function main { - # This is the same script as gradient.ps1 but hard coded - # to 40x160 for nushell comparisons - for ($y = 0; $y -le 39; $y++) { - $Color = 25 - Set-Cursor -x $PSItem -y $y - 0..159 | ForEach-Object { - Write-Host -Object ("`e[48;2;0;0;$Color`m{0}" -f (Get-Character -Index $PSItem)) -NoNewline - $Color += 2 - } - } -} - -# Store the row in an array and then iterate the array to print it out a row at a time -# ~180 ms - This is printing double bytes or something - not sure what's going on -# Note that the x loop has half the characters so it doesn't count -function main2 { - # This is the same script as gradient.ps1 but hard coded - # to 40x160 for nushell comparisons - for ($y = 0; $y -le 39; $y++) { - $Color = 25 - $row = @() - for ($x = 0; $x -le 79; $x++) { - $row += ("`e[48;2;0;0;$Color`m{0}" -f (Get-Character -Index $x)) - $Color += 2 - } - $row += "`e[0m`n" - ,$row | foreach{Write-Host $_ -NoNewline} - } -} - -# Store the characters in a string and concatenate, then output a row at a time -# ~265 ms -function main3 { - # This is the same script as gradient.ps1 but hard coded - # to 40x160 for nushell comparisons - for ($y = 0; $y -le 39; $y++) { - $Color = 25 - $row = "" - for ($x = 0; $x -le 159; $x++) { - $row += ("`e[48;2;0;0;$Color`m{0}" -f (Get-Character -Index $x)) - $Color += 2 - } - $row += "`e[0m" - Write-Host $row - } -} - -# Store as a stringbuilder object -# ~240 ms -function main4 { - # This is the same script as gradient.ps1 but hard coded - # to 40x160 for nushell comparisons - $row = [System.Text.StringBuilder]"" - for ($y = 0; $y -le 39; $y++) { - $Color = 25 - $row.Clear() | out-null - for ($x = 0; $x -le 159; $x++) { - $row.Append("`e[48;2;0;0;$Color`m{0}" -f (Get-Character -Index $x)) | out-null - $Color += 2 - } - $row.Append("`e[0m") | out-null - Write-Host $row.ToString() - } -} - -# measure-command -expression { .\gradient_40x160.ps1 } -# main -# main2 -# main3 -main4 diff --git a/before_v0.60/coloring/nu_index_fg.nu b/before_v0.60/coloring/nu_index_fg.nu deleted file mode 100644 index b69f9155..00000000 --- a/before_v0.60/coloring/nu_index_fg.nu +++ /dev/null @@ -1,16 +0,0 @@ -def show_index_colors [] { - let prefix = "38;5;" - echo 1..256 | each { |fg| - let cr = ($"($fg) % 16" | math eval) - if $cr == 0 { - $"(ansi -e $prefix)($fg)m($fg | into string | str lpad -l 3 -c '0') (char newline)" - } { - $"(ansi -e $prefix)($fg)m($fg | into string | str lpad -l 3 -c '0') " - } - } | str collect -} - -show_index_colors - -#one-liner -#echo 0..255 | each { |fg| echo [(ansi -e '38;5;') ($fg | into string) 'm' ($fg | into string) ' ']} | str collect \ No newline at end of file diff --git a/before_v0.60/coloring/ref_table.nu b/before_v0.60/coloring/ref_table.nu deleted file mode 100644 index 7e97acaa..00000000 --- a/before_v0.60/coloring/ref_table.nu +++ /dev/null @@ -1,30 +0,0 @@ -# This script will print a table 8 rows by 36 columns -# of background colors using ansi index coloring - -# This prints the column headers -let nl = (char newline) -let plus = $"($nl) + " -let cols = (seq 0 35 | each { |col| $"($col)" | str lpad -c ' ' -l 3 } | str collect) -$"($plus)($cols)" - -let ansi_bg = (ansi -e '48;5;') -let ansi_reset = (ansi reset) -$"($nl)($nl)" - -# This prints the row headers -let row_header = ' 0 ' -let row_data = (seq 0 15 | each { |row| - $"($ansi_bg)($row)m ($ansi_reset)" -} | str collect) -$"($row_header)($row_data)($nl)($nl)" - -# This is the meat of the script that prints the little squares of color -seq 0 6 | each { |row_idx| - let r = ($"($row_idx) * 36 + 16" | math eval) - let row_header = (echo $r | into string -d 0 | str lpad -c ' ' -l 4) - let row_data = (seq 0 35 | each { |row| - let val = ($"($r + $row)" | math eval | into string -d 0) - $"($ansi_bg)($val)m (ansi -e 'm') " - } | str collect) - $"($row_header) ($row_data)($nl)($nl)" -} | str collect diff --git a/before_v0.60/coloring/table.sh b/before_v0.60/coloring/table.sh deleted file mode 100644 index a7961b35..00000000 --- a/before_v0.60/coloring/table.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash -# -# generates an 8 bit color table (256 colors) for reference, -# using the ANSI CSI+SGR \033[48;5;${val}m for background and -# \033[38;5;${val}m for text (see "ANSI Code" on Wikipedia) -# -echo -en "\n + " -for i in {0..35}; do -printf "%2b " $i -done -printf "\n\n %3b " 0 -for i in {0..15}; do - echo -en "\033[48;5;${i}m \033[m " -done -#for i in 16 52 88 124 160 196 232; do -for i in {0..6}; do - let "i = i*36 +16" - printf "\n\n %3b " $i - for j in {0..35}; do - let "val = i+j" - echo -en "\033[48;5;${val}m \033[m " - done -done -echo -e "\n" diff --git a/modules/coloring/256_color_testpattern.nu b/modules/coloring/256_color_testpattern.nu index 88827eac..3c707794 100644 --- a/modules/coloring/256_color_testpattern.nu +++ b/modules/coloring/256_color_testpattern.nu @@ -52,7 +52,7 @@ def print_run [start:int, amount:int] { 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)) + let end = (($end - $start) / (($blocks_per_line) * $block_length)) | math round 0..<$end | each { |i| 0..<$block_rows | each { |row| 0..<$blocks_per_line | each { |block| @@ -66,4 +66,104 @@ 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 \ No newline at end of file +print (print_blocks 232 255 12 2 1) # Not 50, but 24 Shades of Grey + + +# bash: + +# #!/bin/bash +# +# # Tom Hale, 2016. MIT Licence. +# # Print out 256 colours, with each number printed in its corresponding colour +# # See http://askubuntu.com/questions/821157/print-a-256-color-test-pattern-in-the-terminal/821163#821163 +# +# set -eu # Fail on errors or undeclared variables +# +# printable_colours=256 +# +# # Return a colour that contrasts with the given colour +# # Bash only does integer division, so keep it integral +# function contrast_colour { +# local r g b luminance +# colour="$1" +# +# if (( colour < 16 )); then # Initial 16 ANSI colours +# (( colour == 0 )) && printf "15" || printf "0" +# return +# fi +# +# # Greyscale # rgb_R = rgb_G = rgb_B = (number - 232) * 10 + 8 +# if (( colour > 231 )); then # Greyscale ramp +# (( colour < 244 )) && printf "15" || printf "0" +# return +# fi +# +# # All other colours: +# # 6x6x6 colour cube = 16 + 36*R + 6*G + B # Where RGB are [0..5] +# # See http://stackoverflow.com/a/27165165/5353461 +# +# # r=$(( (colour-16) / 36 )) +# g=$(( ((colour-16) % 36) / 6 )) +# # b=$(( (colour-16) % 6 )) +# +# # If luminance is bright, print number in black, white otherwise. +# # Green contributes 587/1000 to human perceived luminance - ITU R-REC-BT.601 +# (( g > 2)) && printf "0" || printf "15" +# return +# +# # Uncomment the below for more precise luminance calculations +# +# # # Calculate percieved brightness +# # # See https://www.w3.org/TR/AERT#color-contrast +# # # and http://www.itu.int/rec/R-REC-BT.601 +# # # Luminance is in range 0..5000 as each value is 0..5 +# # luminance=$(( (r * 299) + (g * 587) + (b * 114) )) +# # (( $luminance > 2500 )) && printf "0" || printf "15" +# } +# +# # Print a coloured block with the number of that colour +# function print_colour { +# local colour="$1" contrast +# contrast=$(contrast_colour "$1") +# printf "\e[48;5;%sm" "$colour" # Start block of colour +# printf "\e[38;5;%sm%3d" "$contrast" "$colour" # In contrast, print number +# printf "\e[0m " # Reset colour +# } +# +# # Starting at $1, print a run of $2 colours +# function print_run { +# local i +# for (( i = "$1"; i < "$1" + "$2" && i < printable_colours; i++ )) do +# print_colour "$i" +# done +# printf " " +# } +# +# # Print blocks of colours +# function print_blocks { +# local start="$1" i +# local end="$2" # inclusive +# local block_cols="$3" +# local block_rows="$4" +# local blocks_per_line="$5" +# local block_length=$((block_cols * block_rows)) +# +# # Print sets of blocks +# for (( i = start; i <= end; i += (blocks_per_line-1) * block_length )) do +# printf "\n" # Space before each set of blocks +# # For each block row +# for (( row = 0; row < block_rows; row++ )) do +# # Print block columns for all blocks on the line +# for (( block = 0; block < blocks_per_line; block++ )) do +# print_run $(( i + (block * block_length) )) "$block_cols" +# done +# (( i += block_cols )) # Prepare to print the next row +# printf "\n" +# done +# done +# } +# +# print_run 0 16 # The first 16 colours are spread over the whole spectrum +# printf "\n" +# print_blocks 16 231 6 6 3 # 6x6x6 colour cube between 16 and 231 inclusive +# print_blocks 232 255 12 2 1 # Not 50, but 24 Shades of Grey diff --git a/modules/coloring/color_table.nu b/modules/coloring/color_table.nu new file mode 100644 index 00000000..a7d3327a --- /dev/null +++ b/modules/coloring/color_table.nu @@ -0,0 +1,94 @@ +def make_header [hi] { + if $hi == true { + let ansi100m = ('100m' | fill -a l -w 11 -c ' ') + let ansi101m = ('101m' | fill -a l -w 9 -c ' ') + let ansi102m = ('102m' | fill -a l -w 9 -c ' ') + let ansi103m = ('103m' | fill -a l -w 9 -c ' ') + let ansi104m = ('104m' | fill -a l -w 9 -c ' ') + let ansi105m = ('105m' | fill -a l -w 9 -c ' ') + let ansi106m = ('106m' | fill -a l -w 9 -c ' ') + let ansi107m = ('107m' | fill -a l -w 9 -c ' ') + $"(char newline)($ansi100m)($ansi101m)($ansi102m)($ansi103m)($ansi104m)($ansi105m)($ansi106m)($ansi107m)(char newline)" + + } else { + let ansi40m = ('40m' | fill -a l -w 10 -c ' ') + let ansi41m = ('41m' | fill -a l -w 8 -c ' ') + let ansi42m = ('42m' | fill -a l -w 8 -c ' ') + let ansi43m = ('43m' | fill -a l -w 8 -c ' ') + let ansi44m = ('44m' | fill -a l -w 8 -c ' ') + let ansi45m = ('45m' | fill -a l -w 8 -c ' ') + let ansi46m = ('46m' | fill -a l -w 8 -c ' ') + let ansi47m = ('47m' | fill -a l -w 8 -c ' ') + $"(char newline)($ansi40m)($ansi41m)($ansi42m)($ansi43m)($ansi44m)($ansi45m)($ansi46m)($ansi47m)(char newline)" + } +} + +# mk_header and make_header do the same thing in different ways +# make_header is far easier to read and understand +# mk_header is more convoluted but less repetitive + +def mk_header [color_range:range] { + let min_rng = (echo $color_range | math min) + let hi_start_pad = 11 + let hi_regular_pad = 9 + let lo_start_pad = 10 + let lo_regular_pad = 8 + echo $color_range | each { |color| + let ansi_color = $"($color)m" + if $color == $min_rng { + if $min_rng == 100 { + ($ansi_color | fill -a l -w $hi_start_pad -c ' ') + + } else { + ($ansi_color | fill -a l -w $lo_start_pad -c ' ') + + } + + } else { + if $min_rng >= 100 { + ($ansi_color | fill -a l -w $hi_regular_pad -c ' ') + + } else { + ($ansi_color | fill -a l -w $lo_regular_pad -c ' ') + + } + + } + } | str join + echo (char newline) +} + +def color_row_range [num:int bg_rg:range] { + let reset = (ansi reset) + let row_header = $"($num)m ($reset)" + let row_data = (echo $bg_rg | each { |back| + let row_name = $"($num);($back)m" + let ansi_color = (ansi -e $row_name) + $"($ansi_color) ($row_name) ($reset)" + } | append (char newline) | str join) + $"($row_header)($row_data)" +} + +def create_color_tables [fg_range:range bg_range:range] { + echo $fg_range | each { |fg| + color_row_range $fg $bg_range + } | str join +} + +def color_table [] { + [ + # make_header $false + (mk_header 40..47) + (create_color_tables 30..37 40..47) + + # put a line between tables + (char newline) + + #make_header $true + (mk_header 100..107) + (create_color_tables 90..97 100..107) + ] | str join +} + +color_table + diff --git a/modules/coloring/color_tables.nu b/modules/coloring/color_tables.nu new file mode 100644 index 00000000..42b4fc23 --- /dev/null +++ b/modules/coloring/color_tables.nu @@ -0,0 +1,23 @@ +# Bash script +# for x in {0..8}; do +# for i in {30..37}; do +# for a in {40..47}; do +# echo -ne "\e[$x;$i;$a""m\\\e[$x;$i;$a""m\e[0;37;40m " +# done +# echo +# done +# echo +# done +# echo "" + +0..8 | each {|x| + let row = (30..37 | each {|i| + let row = (40..47 | each {|a| + let color = $"($x);($i);($a)" + $"(ansi -e $color)m\\e[($color)(ansi -e '0;37;40')m " + } | str join) + $"($row)(char newline)" + } | str join) + $"($row)(char newline)" +} | str join + diff --git a/modules/coloring/gradient.nu b/modules/coloring/gradient.nu new file mode 100644 index 00000000..37e0bf86 --- /dev/null +++ b/modules/coloring/gradient.nu @@ -0,0 +1,82 @@ +# this script will print a blue gradient on the screen + +# We can get the terminal width and height now with term size +# but we like to use the script as a benchmark, so let's keep +# it a constant size for now +let height = 40 # really need to get the terminal height here +let width = 160 # really need to get the terminal width here +let stamp = 'Nu' + +def iter_inc [incr mult iter] { + $incr + $mult * $iter +} + +seq 0 $height | each { + let row_data = (seq 0 $width | each { |col| + let fgcolor = (iter_inc 2 2 $col) + if $fgcolor > 200 and $fgcolor < 210 { + $"(ansi -e '48;2;0;0;')($fgcolor)m($stamp)(ansi -e '0m')" + } else { + $"(ansi -e '48;2;0;0;')($fgcolor)m(char sp)(ansi -e '0m')" + } + } | str join) + $"($row_data)(char newline)" +} | str join + + +# python: +# +# #!/usr/bin/env python +# from colors import * +# +# def iter_inc(incr, mult, it): +# return incr + mult * it +# +# height = 40 +# width = 160 +# stamp = "py" +# +# for line in range(0, height): +# row_data = "" +# +# for col in range(0, width): +# fgcolor = iter_inc(2, 2, col) +# if fgcolor > 200 and fgcolor < 210: +# row_data = row_data + color(stamp, bg='rgb(0, 0, %d)' % fgcolor) +# else: +# fg = fgcolor % 256 +# row_data = row_data + color(' ', bg='rgb(0, 0, %d)' % fg) +# +# print(row_data) + + +# powershell: + +# function Set-Cursor { +# [CmdletBinding()] +# param ([int] $x, [int] $y) +# $Host.UI.RawUI.CursorPosition = @{x = $x; y = $y } +# } +# +# function Get-Character { +# [CmdletBinding()] +# param ([int]$index) +# $mystring = ' Trevor Sullivan' +# return $index -ge ($mystring.Length) ? ' ' : $mystring[$index] +# } +# +# function main { +# +# for ($y = 0; $y -le ($host.ui.RawUI.BufferSize.Height - 1); $y++) { +# $Color = 25 +# Set-Cursor -x $PSItem -y $y +# 0..($Host.UI.RawUI.BufferSize.Width - 1) | ForEach-Object { +# Write-Host -Object ("`e[48;2;0;0;$Color`m{0}" -f (Get-Character -Index $PSItem)) -NoNewline +# $Color += 2 +# } +# } +# Start-Sleep -Seconds 5 +# } +# +# main + diff --git a/before_v0.60/coloring/nu_index_bg.nu b/modules/coloring/nu_index_bg.nu similarity index 61% rename from before_v0.60/coloring/nu_index_bg.nu rename to modules/coloring/nu_index_bg.nu index be99e70c..4dbe36d0 100644 --- a/before_v0.60/coloring/nu_index_bg.nu +++ b/modules/coloring/nu_index_bg.nu @@ -1,15 +1,15 @@ def show_index_colors [] { let prefix = "48;5;" - echo 1..256 | each { |idx| - let cr = ($"($idx) % 16" | math eval) + 1..256 | each { |idx| let color = $"(ansi -e $prefix)($idx)m" - let padded_number = ($"($idx)" | str lpad -l 3 -c '0') + let padded_number = ($"($idx)" | fill -a l -w 3 -c '0') + let cr = ($idx mod 16) if $cr == 0 { $"($color)($padded_number) (ansi -e 0m)(char newline)" - } { + } else { $"($color)($padded_number) (ansi -e 0m)" } - } | str collect + } | str join } show_index_colors diff --git a/before_v0.60/coloring/nu_index_fg2.nu b/modules/coloring/nu_index_fg.nu similarity index 58% rename from before_v0.60/coloring/nu_index_fg2.nu rename to modules/coloring/nu_index_fg.nu index d665f24b..01022be6 100644 --- a/before_v0.60/coloring/nu_index_fg2.nu +++ b/modules/coloring/nu_index_fg.nu @@ -1,25 +1,27 @@ # this script uses foreground ansi index colors to print -# a table of 16 rows by 16 columns where each item is a +# a table of 16 rows by 16 colums where each item is a # different color def show_index_colors [] { let prefix = "38;5;" echo 1..256 | each { |idx| - let cr = ($"($idx) % 16" | math eval) + let cr = (($idx) mod 16) let color = ($"(ansi -e $prefix)($idx)m") - let padded_number = ($"($idx)" | str lpad -l 3 -c '0') + let padded_number = ($"($idx)" | fill -a l -w 3 -c '0') if $cr == 0 { $"($color)($padded_number) (char newline)" - } { + } else { $"($color)($padded_number) " } - } | str collect + } | str join } -show_index_colors - # one-liner version that just prints # it all on one line which wraps in # your terminal +def one_liner [] { + 0..255 | each {|fg| [(ansi -e '38;5;') ($fg | into string) 'm' ($fg | into string) ' ']} | flatten | str join +} -#echo 1..256 | each { |idx| echo [(ansi -e '38;5;') (build-string $idx) 'm' (build-string $idx) ' ']} | str collect \ No newline at end of file + +show_index_colors diff --git a/before_v0.60/coloring/python_index_table.nu b/modules/coloring/python_index_table.nu similarity index 69% rename from before_v0.60/coloring/python_index_table.nu rename to modules/coloring/python_index_table.nu index ec127a60..421aa4e9 100644 --- a/before_v0.60/coloring/python_index_table.nu +++ b/modules/coloring/python_index_table.nu @@ -7,23 +7,23 @@ # print u"\u001b[0m" # Foreground Colors -echo 0..16 | each { |col| +print (0..16 | each { |col| let row = (echo 0..16 | each { |row| let code = ($col * 16 + $row) if $code < 256 { - $"(ansi -e '38;5;')($code | into string)m($code | into string | str lpad -l 4 -c ' ')(ansi reset)" - } {} # Do nothing in the else - } | str collect) + $"(ansi -e '38;5;')($code | into string)m($code | into string | fill -a l -w 4 -c ' ')(ansi reset)" + } + } | str join) $"($row)(char newline)" -} | str collect +} | str join) # Background Colors -echo 0..16 | each { |col| +print (0..16 | each { |col| let row = (echo 0..16 | each { |row| let code = ($col * 16 + $row) if $code < 256 { - $"(ansi -e '48;5;')($code | into string)m($code | into string | str lpad -l 4 -c ' ')(ansi reset)" - } {} # do nothing in the else - } | str collect) + $"(ansi -e '48;5;')($code | into string)m($code | into string | fill -a l -w 4 -c ' ')(ansi reset)" + } + } | str join) $"($row)(char newline)" -} | str collect +} | str join) diff --git a/modules/coloring/ref_table.nu b/modules/coloring/ref_table.nu new file mode 100644 index 00000000..62512611 --- /dev/null +++ b/modules/coloring/ref_table.nu @@ -0,0 +1,51 @@ +# This script will print a table 8 rows by 36 columns +# of background colors using ansi index coloring + +# #!/bin/bash +# echo -en "\n + " +# for i in {0..35}; do +# printf "%2b " $i +# done +# printf "\n\n %3b " 0 +# for i in {0..15}; do +# echo -en "\033[48;5;${i}m \033[m " +# done +# #for i in 16 52 88 124 160 196 232; do +# for i in {0..6}; do +# let "i = i*36 +16" +# printf "\n\n %3b " $i +# for j in {0..35}; do +# let "val = i+j" +# echo -en "\033[48;5;${val}m \033[m " +# done +# done +# echo -e "\n" + + +# This prints the column headers +let nl = (char newline) +let plus = $"($nl) + " +let cols = (seq 0 35 | each { |col| $"($col)" | fill -a l -c ' ' -w 3 } | str join) +print $"($plus)($cols)" + +let ansi_bg = (ansi -e '48;5;') +let ansi_reset = (ansi reset) +print $"($nl)($nl)" + +# This prints the row headers +let row_header = ' 0 ' +let row_data = (seq 0 15 | each { |row| + $"($ansi_bg)($row)m ($ansi_reset)" +} | str join) +print $"($row_header)($row_data)($nl)($nl)" + +# This is the meat of the script that prints the little squares of color +seq 0 6 | each { |row_idx| + let r = ($row_idx * 36 + 16) + let row_header = (echo $r | into string -d 0 | fill -a l -c ' ' -w 4) + let row_data = (seq 0 35 | each { |row| + let val = (($r + $row) | into string -d 0) + $"($ansi_bg)($val)m (ansi -e 'm') " + } | str join) + $"($row_header) ($row_data)($nl)($nl)" +} | str join diff --git a/before_v0.60/coloring/sample.nu b/modules/coloring/sample.nu similarity index 56% rename from before_v0.60/coloring/sample.nu rename to modules/coloring/sample.nu index c2e5fd25..29deda12 100644 --- a/before_v0.60/coloring/sample.nu +++ b/modules/coloring/sample.nu @@ -1,7 +1,7 @@ # Background Colors -echo 40..47 100..107 49 | each { |clbg| +[40..47 100..107 49] | each { flatten } | flatten | each { |clbg| # Foreground Colors - echo 30..37 90..97 39 | each { |clfg| + [30..37 90..97 39] | each { flatten } | flatten | each { |clfg| # 0 Normal # 1 Bold or increased intensity # 2 Faint or decreased intensity @@ -12,15 +12,25 @@ echo 40..47 100..107 49 | each { |clbg| # 7 Reverse Video # 8 Conceal (not widely supported) # 9 Strike-through - let row = (echo 0..9 | each { |attr| + let row = (0..9 | each { |attr| let ansi_str = $"($attr);($clbg);($clfg)m" $"(ansi -e $ansi_str) ($ansi_str) (ansi reset)" - } | str collect) - $"($row)(char newline)" | autoview - } | str collect -} | str collect + } | str join) + $"($row)(char newline)" + } | str join +} | str join # Bash Script + +# #!/bin/bash +# +# # This program is free software. It comes without any warranty, to +# # the extent permitted by applicable law. You can redistribute it +# # and/or modify it under the terms of the Do What The Fuck You Want +# # To Public License, Version 2, as published by Sam Hocevar. See +# # http://sam.zoy.org/wtfpl/COPYING for more details. +# +# #Background # for clbg in {40..47} {100..107} 49 ; do # #Foreground # for clfg in {30..37} {90..97} 39 ; do @@ -32,5 +42,5 @@ echo 40..47 100..107 49 | each { |clbg| # echo #Newline # done # done - -# exit 0 \ No newline at end of file +# +# exit 0 diff --git a/before_v0.60/coloring/short_list.nu b/modules/coloring/short_list.nu similarity index 100% rename from before_v0.60/coloring/short_list.nu rename to modules/coloring/short_list.nu