docs: use asciinema's web player for screenshots
I've wanted to avoid checking in all the screenshot pics as the png files change every time I run the generation script, and it bloats the repo over time. This commit changes the doc generation step to use the asciinema web player with the equivalent contents. Really, it's only a smallish step to go from this to just emitting the html directly in the doc pages, but I think I might use the player for some examples in the future. I think this is still a fine step for now in any case. While comparing this with the existing screenshots, I noticed the the Alabaster screen shot png has the wrong color for its rightmost column: there's an issue in wezterm in parsing the dynamic color escapes that causes it to pick up the wrong color. Loading the scheme by name has the correct color and matches how it is shown as of this commit.
This commit is contained in:
1 parent
8bad7dee58
commit
d5060ec3c1
4 files changed
+2670
-17
No files matched your search
+159
-15
@@ -1,9 +1,12 @@
|
||||
#!/usr/bin/env python3
|
||||
import sys
|
||||
import os
|
||||
import base64
|
||||
import configparser
|
||||
import glob
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
class Page(object):
|
||||
@@ -55,6 +58,120 @@ class Gen(object):
|
||||
idx.write(f" - [{page.title}]({page.title}.md)\n")
|
||||
|
||||
|
||||
def load_scheme(name):
|
||||
config = configparser.ConfigParser()
|
||||
config.read(name)
|
||||
|
||||
name = os.path.splitext(os.path.basename(name))[0]
|
||||
ident = name.lower()
|
||||
for c in ["-", " ", "+"]:
|
||||
ident = ident.replace(c, "_")
|
||||
|
||||
colors = eval(config["colors"]["ansi"]) + eval(config["colors"]["brights"])
|
||||
|
||||
selection_bg = eval(config["colors"]["selection_bg"])
|
||||
selection_fg = eval(config["colors"]["selection_fg"])
|
||||
|
||||
scheme = {
|
||||
"name": name,
|
||||
"ident": ident,
|
||||
"fg": eval(config["colors"]["foreground"]),
|
||||
"bg": eval(config["colors"]["background"]),
|
||||
"cursor": eval(config["colors"]["cursor_border"]),
|
||||
}
|
||||
|
||||
# <https://github.com/asciinema/asciinema-player/wiki/Custom-terminal-themes>
|
||||
css = f"""
|
||||
.asciinema-theme-{ident} .asciinema-terminal {{
|
||||
color: {scheme["fg"]};
|
||||
background-color: {scheme["bg"]};
|
||||
border-color: {scheme["bg"]};
|
||||
}}
|
||||
|
||||
.asciinema-theme-{ident} .fg-bg {{
|
||||
color: {scheme["bg"]};
|
||||
}}
|
||||
|
||||
.asciinema-theme-{ident} .bg-fg {{
|
||||
background-color: {scheme["fg"]};
|
||||
}}
|
||||
|
||||
.asciinema-theme-{ident} .cursor-b {{
|
||||
background-color: {scheme["cursor"]} !important;
|
||||
}}
|
||||
|
||||
.asciinema-theme-{ident} .asciinema-terminal ::selection {{
|
||||
color: {selection_fg};
|
||||
background-color: {selection_bg};
|
||||
}}
|
||||
"""
|
||||
|
||||
for idx, color in enumerate(colors):
|
||||
css += f"""
|
||||
.asciinema-theme-{ident} .fg-{idx} {{
|
||||
color: {color};
|
||||
}}
|
||||
.asciinema-theme-{ident} .bg-{idx} {{
|
||||
background-color: {color};
|
||||
}}
|
||||
"""
|
||||
|
||||
scheme["css"] = css
|
||||
|
||||
return scheme
|
||||
|
||||
|
||||
def screen_shot_table(scheme):
|
||||
T = "gYw"
|
||||
lines = [
|
||||
scheme["name"],
|
||||
"",
|
||||
" def 40m 41m 42m 43m 44m 45m 46m 47m",
|
||||
]
|
||||
for fg_space 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",
|
||||
]:
|
||||
fg = fg_space.strip()
|
||||
line = f" {fg_space} \033[{fg} {T} "
|
||||
|
||||
for bg in ["40m", "41m", "42m", "43m", "44m", "45m", "46m", "47m"]:
|
||||
line += f" \033[{fg}\033[{bg} {T} \033[0m"
|
||||
lines.append(line)
|
||||
|
||||
lines.append("")
|
||||
lines.append("")
|
||||
|
||||
screen = "\r\n".join(lines)
|
||||
|
||||
header = {
|
||||
"version": 2,
|
||||
"width": 80,
|
||||
"height": 24,
|
||||
"title": scheme["name"],
|
||||
}
|
||||
header = json.dumps(header, sort_keys=True)
|
||||
data = json.dumps([0.0, "o", screen])
|
||||
|
||||
return base64.b64encode(f"{header}\n{data}\n".encode("UTF-8")).decode("UTF-8")
|
||||
|
||||
|
||||
class GenColorScheme(object):
|
||||
def __init__(self, title, dirname, index=None):
|
||||
self.title = title
|
||||
@@ -62,23 +179,50 @@ class GenColorScheme(object):
|
||||
self.index = index
|
||||
|
||||
def render(self, output, depth=0):
|
||||
names = sorted(glob.glob(f"{self.dirname}/*"))
|
||||
children = []
|
||||
for scheme_prefix in names:
|
||||
title = os.path.basename(scheme_prefix).rsplit(".", 1)[0]
|
||||
if title == "index":
|
||||
continue
|
||||
schemes = [load_scheme(f) for f in sorted(glob.glob("../assets/colors/*.toml"))]
|
||||
by_prefix = {}
|
||||
for scheme in schemes:
|
||||
prefix = scheme["name"][0].lower()
|
||||
if prefix not in by_prefix:
|
||||
by_prefix[prefix] = []
|
||||
by_prefix[prefix].append(scheme)
|
||||
|
||||
scheme_filename = f"{scheme_prefix}/index.md"
|
||||
children.append(Page(title, scheme_filename))
|
||||
children = []
|
||||
for scheme_prefix in sorted(by_prefix.keys()):
|
||||
scheme_filename = f"{self.dirname}/{scheme_prefix}/index.md"
|
||||
children.append(Page(scheme_prefix, scheme_filename))
|
||||
|
||||
with open(scheme_filename, "w") as idx:
|
||||
images = sorted(glob.glob(f"{scheme_prefix}/*.png"))
|
||||
for img in images:
|
||||
img = os.path.basename(img)
|
||||
title = os.path.basename(img).rsplit(".", 1)[0]
|
||||
|
||||
for scheme in by_prefix[scheme_prefix]:
|
||||
title = scheme["name"]
|
||||
idx.write(f"# {title}\n")
|
||||
idx.write(f'<img src="{img}" alt="{title}">\n\n')
|
||||
|
||||
data = screen_shot_table(scheme)
|
||||
ident = scheme["ident"]
|
||||
|
||||
idx.write(
|
||||
f"""
|
||||
<div id="{ident}"></div>
|
||||
|
||||
<style>
|
||||
{scheme["css"]}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
window.addEventListener('load', function () {{
|
||||
AsciinemaPlayer.create(
|
||||
'data:text/plain;base64,{data}',
|
||||
document.getElementById('{ident}'), {{
|
||||
theme: "{ident}",
|
||||
autoPlay: true,
|
||||
}});
|
||||
}});
|
||||
|
||||
</script>
|
||||
"""
|
||||
)
|
||||
|
||||
idx.write("To use this scheme, add this to your config:\n")
|
||||
idx.write(
|
||||
f"""
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
Vendored
+1
@@ -0,0 +1 @@
|
||||
var AsciinemaPlayer=function(A){"use strict";function g(A,g,I,B,Q,C,E){try{var t=A[C](E),e=t.value}catch(A){return void I(A)}t.done?g(e):Promise.resolve(e).then(B,Q)}function I(A){return function(){var I=this,B=arguments;return new Promise((function(Q,C){var E=A.apply(I,B);function t(A){g(E,Q,C,t,e,"next",A)}function e(A){g(E,Q,C,t,e,"throw",A)}t(void 0)}))}}function B(A,g){if(!(A instanceof g))throw new TypeError("Cannot call a class as a function")}function Q(A,g){for(var I=0;I<g.length;I++){var B=g[I];B.enumerable=B.enumerable||!1,B.configurable=!0,"value"in B&&(B.writable=!0),Object.defineProperty(A,B.key,B)}}function C(A,g,I){return g&&Q(A.prototype,g),I&&Q(A,I),A}var E={exports:{}};!function(A){var g=function(A){var g,I=Object.prototype,B=I.hasOwnProperty,Q="function"==typeof Symbol?Symbol:{},C=Q.iterator||"@@iterator",E=Q.asyncIterator||"@@asyncIterator",t=Q.toStringTag||"@@toStringTag";function e(A,g,I){return Object.defineProperty(A,g,{value:I,enumerable:!0,configurable:!0,writable:!0}),A[g]}try{e({},"")}catch(A){e=function(A,g,I){return A[g]=I}}function i(A,g,I,B){var Q=g&&g.prototype instanceof u?g:u,C=Object.create(Q.prototype),E=new M(B||[]);return C._invoke=function(A,g,I){var B=o;return function(Q,C){if(B===s)throw new Error("Generator is already running");if(B===a){if("throw"===Q)throw C;return p()}for(I.method=Q,I.arg=C;;){var E=I.delegate;if(E){var t=N(E,I);if(t){if(t===c)continue;return t}}if("next"===I.method)I.sent=I._sent=I.arg;else if("throw"===I.method){if(B===o)throw B=a,I.arg;I.dispatchException(I.arg)}else"return"===I.method&&I.abrupt("return",I.arg);B=s;var e=n(A,g,I);if("normal"===e.type){if(B=I.done?a:r,e.arg===c)continue;return{value:e.arg,done:I.done}}"throw"===e.type&&(B=a,I.method="throw",I.arg=e.arg)}}}(A,I,E),C}function n(A,g,I){try{return{type:"normal",arg:A.call(g,I)}}catch(A){return{type:"throw",arg:A}}}A.wrap=i;var o="suspendedStart",r="suspendedYield",s="executing",a="completed",c={};function u(){}function w(){}function D(){}var h={};e(h,C,(function(){return this}));var l=Object.getPrototypeOf,y=l&&l(l(R([])));y&&y!==I&&B.call(y,C)&&(h=y);var f=D.prototype=u.prototype=Object.create(h);function G(A){["next","throw","return"].forEach((function(g){e(A,g,(function(A){return this._invoke(g,A)}))}))}function k(A,g){function I(Q,C,E,t){var e=n(A[Q],A,C);if("throw"!==e.type){var i=e.arg,o=i.value;return o&&"object"==typeof o&&B.call(o,"__await")?g.resolve(o.__await).then((function(A){I("next",A,E,t)}),(function(A){I("throw",A,E,t)})):g.resolve(o).then((function(A){i.value=A,E(i)}),(function(A){return I("throw",A,E,t)}))}t(e.arg)}var Q;this._invoke=function(A,B){function C(){return new g((function(g,Q){I(A,B,g,Q)}))}return Q=Q?Q.then(C,C):C()}}function N(A,I){var B=A.iterator[I.method];if(B===g){if(I.delegate=null,"throw"===I.method){if(A.iterator.return&&(I.method="return",I.arg=g,N(A,I),"throw"===I.method))return c;I.method="throw",I.arg=new TypeError("The iterator does not provide a 'throw' method")}return c}var Q=n(B,A.iterator,I.arg);if("throw"===Q.type)return I.method="throw",I.arg=Q.arg,I.delegate=null,c;var C=Q.arg;return C?C.done?(I[A.resultName]=C.value,I.next=A.nextLoc,"return"!==I.method&&(I.method="next",I.arg=g),I.delegate=null,c):C:(I.method="throw",I.arg=new TypeError("iterator result is not an object"),I.delegate=null,c)}function d(A){var g={tryLoc:A[0]};1 in A&&(g.catchLoc=A[1]),2 in A&&(g.finallyLoc=A[2],g.afterLoc=A[3]),this.tryEntries.push(g)}function F(A){var g=A.completion||{};g.type="normal",delete g.arg,A.completion=g}function M(A){this.tryEntries=[{tryLoc:"root"}],A.forEach(d,this),this.reset(!0)}function R(A){if(A){var I=A[C];if(I)return I.call(A);if("function"==typeof A.next)return A;if(!isNaN(A.length)){var Q=-1,E=function I(){for(;++Q<A.length;)if(B.call(A,Q))return I.value=A[Q],I.done=!1,I;return I.value=g,I.done=!0,I};return E.next=E}}return{next:p}}function p(){return{value:g,done:!0}}return w.prototype=D,e(f,"constructor",D),e(D,"constructor",w),w.displayName=e(D,t,"GeneratorFunction"),A.isGeneratorFunction=function(A){var g="function"==typeof A&&A.constructor;return!!g&&(g===w||"GeneratorFunction"===(g.displayName||g.name))},A.mark=function(A){return Object.setPrototypeOf?Object.setPrototypeOf(A,D):(A.__proto__=D,e(A,t,"GeneratorFunction")),A.prototype=Object.create(f),A},A.awrap=function(A){return{__await:A}},G(k.prototype),e(k.prototype,E,(function(){return this})),A.AsyncIterator=k,A.async=function(g,I,B,Q,C){void 0===C&&(C=Promise);var E=new k(i(g,I,B,Q),C);return A.isGeneratorFunction(I)?E:E.next().then((function(A){return A.done?A.value:E.next()}))},G(f),e(f,t,"Generator"),e(f,C,(function(){return this})),e(f,"toString",(function(){return"[object Generator]"})),A.keys=function(A){var g=[];for(var I in A)g.push(I);return g.reverse(),function I(){for(;g.length;){var B=g.pop();if(B in A)return I.value=B,I.done=!1,I}return I.done=!0,I}},A.values=R,M.prototype={constructor:M,reset:function(A){if(this.prev=0,this.next=0,this.sent=this._sentLine truncated
|
||||
+2
-2
@@ -8,11 +8,11 @@ build-dir = "../gh_pages"
|
||||
create-missing = false
|
||||
|
||||
[output.html]
|
||||
additional-css = ["custom.css"]
|
||||
additional-css = ["custom.css", "asciinema-player.css"]
|
||||
default-theme = "ayu"
|
||||
preferred-dark-theme = "ayu"
|
||||
git-repository-url = "https://github.com/wez/wezterm"
|
||||
additional-js = ["mermaid.min.js", "mermaid-init.js"]
|
||||
additional-js = ["mermaid.min.js", "mermaid-init.js", "asciinema-player.min.js"]
|
||||
|
||||
[output.html.fold]
|
||||
enable = true
|
||||
|
||||
Reference in new issue
Block a user