Skip to content

Commit c4a6820

Browse files
committed
wip stuff. it's almost there but a couple of issues in the way
1 parent a0532de commit c4a6820

File tree

4 files changed

+141
-125
lines changed

4 files changed

+141
-125
lines changed

themes/src/asciinema-script

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use .. *
2+
sleep 200ms
3+
source ../nu-themes/$theme_name.nu
4+
clear
5+
print 'Theme: ($theme_name)'
6+
print -n (preview theme small)
7+
sleep 200ms
8+
print ""

themes/src/minicap-script

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
use .. *
2+
source ($theme_name)
3+
clear
4+
sleep 100ms
5+
print `Theme name: '($theme_name)'
6+
print -n (preview theme small | table -e)
7+
sleep 250ms

themes/src/powershell-script

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use .. *
2+
source ($theme_name)
3+
clear
4+
sleep 100ms
5+
print `Theme name: '($theme_name)'`
6+
print -n \(preview theme small | table -e)
7+
sleep 250ms
8+
9+
$Host.UI.RawUI.WindowTitle = 'Theme Preview'
10+
Add-Type -AssemblyName System.Windows.Forms
11+
[Windows.Forms.Sendkeys]::SendWait\('%{Prtsc}')
12+
[Windows.Forms.Sendkeys]::SendWait\('%{Prtsc}')
13+
[Windows.Forms.Sendkeys]::SendWait\('%{Prtsc}')
14+
sleep 1
15+
[Windows.Forms.Clipboard]::GetImage\().Save\('($theme_name).png', [System.Drawing.Imaging.ImageFormat]::Png)

themes/src/preview-generate-screenshots.nu

Lines changed: 111 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# * Place your terminal window against a separate solid
1010
# background to reduce artifacts
1111

12-
def save_screenshot [ method, theme_name ] {
12+
def save_screenshot [ method, theme_name, themes ] {
1313
use ../../stdlib-candidate-archive/stdlib-candidate-older/std-rfc/str/
1414
match $method {
1515
# This method for generating terminal screenshots uses
@@ -22,149 +22,121 @@ def save_screenshot [ method, theme_name ] {
2222
# This method should work from either WSL or Nushell
2323
# for Windows
2424
"powershell" => {
25-
let ps_script = $"
26-
use .. *
27-
source ($theme_name)
28-
clear
29-
sleep 100ms
30-
print `Theme name: '($theme_name)'`
31-
print -n \(preview theme small | table -e)
32-
sleep 250ms
33-
34-
$Host.UI.RawUI.WindowTitle = 'Theme Preview'
35-
Add-Type -AssemblyName System.Windows.Forms
36-
[Windows.Forms.Sendkeys]::SendWait\('%{Prtsc}')
37-
[Windows.Forms.Sendkeys]::SendWait\('%{Prtsc}')
38-
[Windows.Forms.Sendkeys]::SendWait\('%{Prtsc}')
39-
sleep 1
40-
[Windows.Forms.Clipboard]::GetImage\().Save\('($theme_name).png', [System.Drawing.Imaging.ImageFormat]::Png)
41-
"
25+
# in the powershell script template replace "$theme_name" the text holder with $theme_name the actual string passed to this function
26+
let powershell_nu_script = open powershell-script --raw | str replace -a "$theme_name" $theme_name
4227
| str dedent
4328

4429
$"powershell.exe -c \"
45-
($ps_script)
30+
($powershell_nu_script)
4631
\""
4732
}
4833

4934
# Requires MiniCap, a utility for capturing screenshots on Windows
5035
"minicap" => {
51-
$'
52-
use .. *
53-
source ($theme_name)
54-
clear
55-
sleep 100ms
56-
print `Theme name: '($theme_name)'`
57-
print -n \(preview theme small | table -e)
58-
sleep 250ms
59-
60-
c:\\apps\\MiniCap\\MiniCap.exe -captureactivewin -bordershadow -save ($theme_name).png -closeapp -exit
61-
'
36+
# in the script template replace "$theme_name" the text holder with $theme_name the actual string passed to this function
37+
let minicap_nu_script = open minicap-script --raw | str replace -a "$theme_name" $theme_name
38+
39+
6240
}
6341

6442
# Requires asciinema (Linux/Mac only), agg (asciinema to gif), and ffmpeg
6543
# Currently uses Caskaydia Cover Nerd Font installed in user's local fonts
6644
"asciinema" => {
6745
print $theme_name
68-
$"
69-
let asciinema_nu_script = $\"
70-
use .. *
71-
sleep 200ms
72-
source ../nu-themes/($theme_name).nu
73-
clear
74-
print 'Theme: ($theme_name)'
75-
print -n \\\(preview theme small)
76-
sleep 200ms
77-
print ""
78-
\"
79-
80-
mkdir conversions
81-
82-
asciinema rec -c $'nu -c "\($asciinema_nu_script)\"' ./conversions/($theme_name).cast
83-
84-
# Define terminal colors for asciinema-to-gif converter
85-
let sgr_colors = {
86-
black: r#'000000'#
87-
red: r#'800000'#
88-
green: r#'808000'#
89-
yellow: r#'008000'#
90-
blue: r#'000080'#
91-
magenta: r#'800080'#
92-
cyan: r#'008080'#
93-
white: r#'c0c0c0'#
94-
gray: r#'808080'#
95-
bright_red: r#'ff0000'#
96-
bright_green: r#'00ff00'#
97-
bright_yellow: r#'ffff00'#
98-
bright_blue: r#'0000ff'#
99-
bright_magenta: r#'ff00ff'#
100-
bright_cyan: r#'00ffff'#
101-
bright_white: r#'ffffff'#
102-
}
103-
104-
use ../nu-themes/($theme_name).nu
105-
let theme_fg_bg = {
106-
background: \(\(($theme_name)).background | str replace '#' '')
107-
foreground: \(\(($theme_name)).foreground | str replace '#' '')
108-
}
109-
110-
# Combine the theme foreground/background with the SGR colors for an agg theme
111-
let agg_theme = {
112-
...$theme_fg_bg
113-
...$sgr_colors
114-
}
115-
| transpose key value
116-
| get value
117-
| str join ","
118-
119-
# Convert asciinema recording to gif
120-
# Line-height of 1.2 to keep table drawing characters together
121-
agg -v --font-size=24 --renderer=resvg --line-height 1.2 --font-dir ~/.nix-profile/share/fonts/truetype/NerdFonts --font-family \"CaskaydiaCove NFM\" --theme $agg_theme ./conversions/($theme_name).cast ./conversions/($theme_name).gif
122-
rm ./conversions/($theme_name).cast
123-
124-
ffmpeg -i ./conversions/($theme_name).gif -vf 'select=eq\\\(n\\,1)' -fps_mode vfr -q:v 2 -frames:v 1 -update 1 ../screenshots/($theme_name).png
125-
rm ./conversions/($theme_name).gif
46+
47+
# in the asciinema script template replace "$theme_name" the text holder with $theme_name the actual string passed to this function
48+
let asciinema_nu_script = open asciinema-script --raw | str replace -a "$theme_name" $theme_name
49+
50+
mkdir conversions
51+
asciinema rec --overwrite -c $'nu -c "\($asciinema_nu_script)\"' ./conversions/($theme_name).cast
52+
53+
# Define terminal colors for asciinema-to-gif converter
54+
let sgr_colors = {
55+
black: r#'000000'#
56+
red: r#'800000'#
57+
green: r#'808000'#
58+
yellow: r#'008000'#
59+
blue: r#'000080'#
60+
magenta: r#'800080'#
61+
cyan: r#'008080'#
62+
white: r#'c0c0c0'#
63+
gray: r#'808080'#
64+
bright_red: r#'ff0000'#
65+
bright_green: r#'00ff00'#
66+
bright_yellow: r#'ffff00'#
67+
bright_blue: r#'0000ff'#
68+
bright_magenta: r#'ff00ff'#
69+
bright_cyan: r#'00ffff'#
70+
bright_white: r#'ffffff'#
71+
}
72+
73+
const nu_themes = "../nu-themes"
74+
let theme = $themes | where $it == $theme_name
75+
let name_of_theme = $theme | get 0
76+
77+
# need to import one of the themes at ../nu-themes/(some-theme).nu
78+
# but compiler will fail because
79+
# name_of_theme is not a parse time constant
80+
# is there a workaround?
81+
use $"../nu-themes/($theme_name).nu"
82+
use $"($nu_themes)/($name_of_theme).nu"
83+
use $"($nu_themes)/($theme_name).nu"
84+
print "using theme:"
85+
print $theme
86+
87+
let command = $"($theme_name) | get background | str replace '#' ''"
88+
print "command to run:"
89+
print $command
90+
asciinema rec --overwrite -c $'nu -c "\($"($theme) | get background | str replace '#' ''")\"' ./conversions/($theme_name).cast
91+
92+
let theme_fg_bg = {
93+
background: (nu -c $command)
94+
foreground: (nu -c $command)
95+
}
96+
97+
# Combine the theme foreground/background with the SGR colors for an agg theme
98+
let agg_theme = {
99+
...$theme_fg_bg
100+
...$sgr_colors
101+
}
102+
| transpose key value
103+
| get value
104+
| str join ","
105+
106+
# Convert asciinema recording to gif
107+
# Line-height of 1.2 to keep table drawing characters together
108+
agg -v --font-size=24 --renderer=resvg --line-height 1.2 --font-dir ~/.nix-profile/share/fonts/truetype/NerdFonts --font-family \"CaskaydiaCove NFM\" --theme $agg_theme ./conversions/($theme_name).cast ./conversions/($theme_name).gif
109+
rm ./conversions/($theme_name).cast
110+
111+
ffmpeg -i ./conversions/($theme_name).gif -vf 'select=eq\\\(n\\,1)' -fps_mode vfr -q:v 2 -frames:v 1 -update 1 ../screenshots/($theme_name).png
112+
rm ./conversions/($theme_name).gif
126113
"
127114
}
128115
}
129-
130116
}
131117

132-
def "preview generate screenshots" [screenshot_method, theme_count = 10_000] {
118+
def "preview generate screenshots" [screenshot_method, themes, theme_count = 10_000] {
133119
use ../../stdlib-candidate-archive/stdlib-candidate-older/std-rfc/str/
134120

135-
let themes = (
136-
"../nu-themes/"
137-
| path expand
138-
| path join "*.nu"
139-
| into glob
140-
| ls $in
141-
)
142-
143-
for theme in $themes {
144-
let name = $theme.name
145-
let basename = ($theme.name | path parse | get stem)
146-
147-
let filename = (
148-
"../screenshots"
149-
| path join $'($name | path parse | get stem).png'
150-
)
121+
for $theme in $themes {
122+
123+
let filename = "../screenshots" | path join $theme ".png"
124+
125+
let script = $"
126+
#use .. *
127+
#source ($theme)
128+
#clear
129+
#sleep 100ms
130+
#print `Theme name: '($theme)'`
131+
#print -n \(preview theme small | table -e)
132+
#sleep 250ms
133+
(save_screenshot $screenshot_method $theme $themes)
134+
"
151135

152-
let script = $"
153-
#use .. *
154-
#source ($name)
155-
#clear
156-
#sleep 100ms
157-
#print `Theme name: '($basename)'`
158-
#print -n \(preview theme small | table -e)
159-
#sleep 250ms
160-
(save_screenshot $screenshot_method $basename)
161-
"
162-
163-
# Run with default config
164-
# nu -n -c $script
165-
nu -n -c $"(save_screenshot $screenshot_method $basename)"
136+
# Run with default config
137+
# nu -n -c $script
138+
nu -n -c $"(save_screenshot $screenshot_method $theme $themes)"
166139
}
167-
168140
}
169141

170142
def "preview generate readme" [] {
@@ -217,8 +189,22 @@ def main [screenshot_method] {
217189

218190
return
219191
} else {
220-
mkdir ../screenshots
221-
preview generate screenshots $screenshot_method
222-
preview generate readme
192+
let nu_themes = (
193+
"../nu-themes/"
194+
| path expand
195+
| path join "*.nu"
196+
| into glob
197+
| ls $in
198+
)
199+
200+
# this is the file name of all the files in ../nu-themes
201+
let themes = $nu_themes | each { $in.name | path parse | get stem }
202+
203+
mkdir ../screenshots
204+
preview generate screenshots $screenshot_method $themes
205+
preview generate readme
223206
}
224-
}
207+
208+
209+
}
210+

0 commit comments

Comments
 (0)