fork/wezterm
git clone https://git.julia.blue/fork/wezterm
b38726532
vtparse-0.7.0
1#!/usr/bin/env python3 2import base64 3import glob 4import json 5import os 6import re 7import subprocess 8import sys 9 10 11class Page (object ): 12def __init__ (self ,title ,filename ,children = None ): 13self .title = title 14self .filename = filename 15self .children = children or [] 16 17def render (self ,output ,depth = 0 ,mode = "mdbook" ): 18indent = " " * depth 19bullet = "- " if depth > 0 else "" 20if mode == "mdbook" : 21if self .filename : 22output .write (f" { indent } { bullet } [ { self . title } ]( { self . filename } )\n" ) 23elif mode == "mkdocs" : 24if depth > 0 : 25if len (self .children )== 0 : 26output .write (f' { indent } { bullet } " { self . title } ": { self . filename } \n' ) 27else : 28output .write (f' { indent } { bullet } " { self . title } ":\n' ) 29if self .filename : 30output .write ( 31f' { indent } { bullet } " { self . title } ": { self . filename } \n' 32 ) 33for kid in self .children : 34kid .render (output ,depth + 1 ,mode ) 35 36 37# autogenerate an index page from the contents of a directory 38class Gen (object ): 39def __init__ (self ,title ,dirname ,index = None ,extract_title = False ): 40self .title = title 41self .dirname = dirname 42self .index = index 43self .extract_title = extract_title 44 45def render (self ,output ,depth = 0 ,mode = "mdbook" ): 46names = sorted (glob .glob (f" { self . dirname } /*.md" )) 47children = [] 48for filename in names : 49title = os .path .basename (filename ).rsplit ("." ,1 )[0 ] 50if title == "index" : 51continue 52 53if self .extract_title : 54with open (filename ,"r" )as f : 55title = f .readline ().strip ("#" ).strip () 56 57children .append (Page (title ,filename )) 58 59index_filename = f" { self . dirname } /index.md" 60index_page = Page (self .title ,index_filename ,children = children ) 61index_page .render (output ,depth ,mode ) 62with open (f" { self . dirname } /index.md" ,"w" )as idx : 63if self .index : 64idx .write (self .index ) 65idx .write ("\n\n" ) 66else : 67try : 68with open (f" { self . dirname } /index.markdown" ,"r" )as f : 69idx .write (f .read ()) 70idx .write ("\n\n" ) 71except FileNotFoundError : 72pass 73for page in children : 74idx .write (f" - [ { page . title } ]( { os . path . basename ( page . filename ) } )\n" ) 75 76 77def load_scheme (scheme ): 78ident = re .sub ( 79"[^a-z0-9_]" ,"_" ,scheme ["metadata" ]["name" ].lower ().replace ("+" ,"plus" ) 80 ) 81 82if "ansi" not in scheme ["colors" ]: 83raise Exception (f"scheme { scheme } is missing ansi colors!!?" ) 84colors = scheme ["colors" ]["ansi" ]+ scheme ["colors" ]["brights" ] 85 86data = { 87"name" :scheme ["metadata" ]["name" ], 88"prefix" :scheme ["metadata" ]["prefix" ], 89"ident" :ident , 90"fg" :scheme ["colors" ]["foreground" ], 91"bg" :scheme ["colors" ]["background" ], 92"metadata" :scheme ["metadata" ], 93 } 94 95# <https://github.com/asciinema/asciinema-player/wiki/Custom-terminal-themes> 96css = f""" 97.asciinema-theme- { ident } .asciinema-terminal {{ 98color: { data [ "fg" ] } ; 99background-color: { data [ "bg" ] } ; 100border-color: { data [ "bg" ] } ; 101}} 102 103.asciinema-theme- { ident } .fg-bg {{ 104color: { data [ "bg" ] } ; 105}} 106 107.asciinema-theme- { ident } .bg-fg {{ 108background-color: { data [ "fg" ] } ; 109}} 110""" 111 112if "cursor_border" in scheme ["colors" ]: 113data ["cursor" ]= scheme ["colors" ]["cursor_border" ] 114 115css += f""" 116.asciinema-theme- { ident } .cursor-b {{ 117background-color: { data [ "cursor" ] } !important; 118}} 119""" 120 121if "selection_fg" in scheme ["colors" ]and "selection_bg" in scheme ["colors" ]: 122selection_bg = scheme ["colors" ]["selection_bg" ] 123selection_fg = scheme ["colors" ]["selection_fg" ] 124 125css += f""" 126.asciinema-theme- { ident } .asciinema-terminal ::selection {{ 127color: { selection_fg } ; 128background-color: { selection_bg } ; 129}} 130""" 131 132for idx ,color in enumerate (colors ): 133css += f""" 134.asciinema-theme- { ident } .fg- { idx } {{ 135color: { color } ; 136}} 137.asciinema-theme- { ident } .bg- { idx } {{ 138background-color: { color } ; 139}} 140""" 141 142data ["css" ]= css 143return data 144 145 146def screen_shot_table (scheme ): 147T = "gYw" 148lines = [ 149scheme ["name" ], 150"" , 151" def 40m 41m 42m 43m 44m 45m 46m 47m" , 152 ] 153for fg_space in [ 154" m" , 155" 1m" , 156" 30m" , 157"1;30m" , 158" 31m" , 159"1;31m" , 160" 32m" , 161"1;32m" , 162" 33m" , 163"1;33m" , 164" 34m" , 165"1;34m" , 166" 35m" , 167"1;35m" , 168" 36m" , 169"1;36m" , 170" 37m" , 171"1;37m" , 172 ]: 173fg = fg_space .strip () 174line = f" { fg_space } \033[ { fg } { T } " 175 176for bg in ["40m" ,"41m" ,"42m" ,"43m" ,"44m" ,"45m" ,"46m" ,"47m" ]: 177line += f" \033[ { fg } \033[ { bg } { T } \033[0m" 178lines .append (line ) 179 180lines .append ("" ) 181lines .append ("" ) 182 183screen = "\r\n" .join (lines ) 184 185header = { 186"version" :2 , 187"width" :80 , 188"height" :24 , 189"title" :scheme ["name" ], 190 } 191header = json .dumps (header ,sort_keys = True ) 192data = json .dumps ([0.0 ,"o" ,screen ]) 193 194return base64 .b64encode (f" { header } \n { data } \n" .encode ("UTF-8" )).decode ("UTF-8" ) 195 196 197class GenColorScheme (object ): 198def __init__ (self ,title ,dirname ,index = None ): 199self .title = title 200self .dirname = dirname 201self .index = index 202 203def render (self ,output ,depth = 0 ,mode = "mdbook" ): 204with open ("colorschemes/data.json" )as f : 205scheme_data = json .load (f ) 206by_prefix = {} 207by_name = {} 208for scheme in scheme_data : 209scheme = load_scheme (scheme ) 210prefix = scheme ["prefix" ] 211if prefix not in by_prefix : 212by_prefix [prefix ]= [] 213by_prefix [prefix ].append (scheme ) 214by_name [scheme ["name" ]]= scheme 215 216style_filename = f" { self . dirname } /scheme.css" 217with open (style_filename ,"w" )as style_file : 218for scheme in by_name .values (): 219style_file .write (scheme ["css" ]) 220style_file .write ("\n" ) 221js_filename = f" { self . dirname } /scheme.js" 222with open (js_filename ,"w" )as js_file : 223data_by_scheme = {} 224for scheme in by_name .values (): 225ident = scheme ["ident" ] 226data = screen_shot_table (scheme ) 227data_by_scheme [ident ]= data 228 229js_file .write (f"SCHEME_DATA = { json . dumps ( data_by_scheme ) } ;\n" ) 230js_file .write ( 231f""" 232function load_scheme_player(ident) {{ 233var data = SCHEME_DATA[ident]; 234AsciinemaPlayer.create( 235'data:text/plain;base64,' + data, 236document.getElementById(ident + '-player'), {{ 237theme: ident, 238autoPlay: true, 239}}); 240}} 241""" 242 ) 243 244children = [] 245for scheme_prefix in sorted (by_prefix .keys ()): 246scheme_filename = f" { self . dirname } / { scheme_prefix } /index.md" 247os .makedirs (os .path .dirname (scheme_filename ),exist_ok = True ) 248children .append (Page (scheme_prefix ,scheme_filename )) 249 250with open (scheme_filename ,"w" )as idx : 251idents_to_load = [] 252 253idx .write ( 254f"""--- 255title: Color Schemes with first letter " { scheme_prefix } " 256--- 257 258""" 259 ) 260 261for scheme in by_prefix [scheme_prefix ]: 262title = scheme ["name" ] 263idx .write (f"## { title } \n" ) 264 265data = screen_shot_table (scheme ) 266ident = scheme ["ident" ] 267idents_to_load .append (ident ) 268 269idx .write ( 270f""" 271<div id=" { ident } -player"></div> 272""" 273 ) 274 275author = scheme ["metadata" ].get ("author" ,None ) 276if author : 277idx .write (f"Author: ` { author } `<br/>\n" ) 278origin_url = scheme ["metadata" ].get ("origin_url" ,None ) 279if origin_url : 280idx .write (f"Source: < { origin_url } ><br/>\n" ) 281version = scheme ["metadata" ].get ("wezterm_version" ,None ) 282if version and version != "Always" : 283idx .write (f"{{{{since(' { version } ')}}}}<br/>\n" ) 284 285aliases = scheme ["metadata" ]["aliases" ] 286if len (aliases )> 0 : 287alias_list = [] 288for a in aliases : 289alias_list .append (f"` { a } `" ) 290aliases = ", " .join (alias_list ) 291idx .write (f"This scheme is also known as { aliases } .<br/>\n" ) 292 293idx .write ("\nTo use this scheme, add this to your config:\n" ) 294idx .write ( 295f""" 296```lua 297config.color_scheme = ' { title } ' 298``` 299 300""" 301 ) 302 303idents_to_load = json .dumps (idents_to_load ) 304idx .write ( 305f""" 306<script> 307document.addEventListener("DOMContentLoaded", function() {{ 308{ idents_to_load } .forEach(ident => load_scheme_player(ident)); 309}}); 310</script> 311""" 312 ) 313 314index_filename = f" { self . dirname } /index.md" 315index_page = Page (self .title ,index_filename ,children = children ) 316index_page .render (output ,depth ,mode ) 317 318with open (f" { self . dirname } /index.md" ,"w" )as idx : 319idx .write (f" { len ( scheme_data ) } Color schemes listed by first letter\n\n" ) 320for page in children : 321upper = page .title .upper () 322idx .write (f" - [ { upper } ]( { page . title } /index.md)\n" ) 323 324 325TOC = [ 326Page ( 327"WezTerm" , 328"index.md" , 329children = [ 330Page ("Features" ,"features.md" ), 331Page ("Scrollback" ,"scrollback.md" ), 332Page ("Quick Select Mode" ,"quickselect.md" ), 333Page ("Copy Mode" ,"copymode.md" ), 334Page ("Hyperlinks" ,"hyperlinks.md" ), 335Page ("Shell Integration" ,"shell-integration.md" ), 336Page ("iTerm Image Protocol" ,"imgcat.md" ), 337Page ("SSH" ,"ssh.md" ), 338Page ("Serial Ports & Arduino" ,"serial.md" ), 339Page ("Multiplexing" ,"multiplexing.md" ), 340 ], 341 ), 342Page ( 343"Download" , 344"installation.md" , 345children = [ 346Page ("Windows" ,"install/windows.md" ), 347Page ("macOS" ,"install/macos.md" ), 348Page ("Linux" ,"install/linux.md" ), 349Page ("FreeBSD" ,"install/freebsd.md" ), 350Page ("NetBSD" ,"install/netbsd.md" ), 351Page ("Build from source" ,"install/source.md" ), 352 ], 353 ), 354Page ( 355"Configuration" , 356"config/files.md" , 357children = [ 358Page ("Colors & Appearance" ,"config/appearance.md" ), 359Page ("Launching Programs" ,"config/launch.md" ), 360Page ("Fonts" ,"config/fonts.md" ), 361Page ("Font Shaping" ,"config/font-shaping.md" ), 362Page ("Keyboard Concepts" ,"config/keyboard-concepts.md" ), 363Page ("Key Binding" ,"config/keys.md" ), 364Page ("Key Tables" ,"config/key-tables.md" ), 365Page ("Default Key Assignments" ,"config/default-keys.md" ), 366Page ("Keyboard Encoding" ,"config/key-encoding.md" ), 367Page ("Mouse Binding" ,"config/mouse.md" ), 368Page ("Plugins" ,"config/plugins.md" ), 369GenColorScheme ("Color Schemes" ,"colorschemes" ), 370Gen ("Recipes" ,"recipes" ,extract_title = True ), 371 ], 372 ), 373Page ( 374"Full Config & Lua Reference" , 375"config/lua/general.md" , 376children = [ 377Gen ( 378"Config Options" , 379"config/lua/config" , 380 ), 381Gen ( 382"module: wezterm" , 383"config/lua/wezterm" , 384 ), 385Gen ( 386"module: wezterm.color" , 387"config/lua/wezterm.color" , 388 ), 389Gen ( 390"module: wezterm.gui" , 391"config/lua/wezterm.gui" , 392 ), 393Gen ( 394"module: wezterm.mux" , 395"config/lua/wezterm.mux" , 396 ), 397Gen ( 398"module: wezterm.plugin" , 399"config/lua/wezterm.plugin" , 400 ), 401Gen ( 402"module: wezterm.procinfo" , 403"config/lua/wezterm.procinfo" , 404 ), 405Gen ( 406"module: wezterm.serde" , 407"config/lua/wezterm.serde" , 408 ), 409Gen ( 410"module: wezterm.time" , 411"config/lua/wezterm.time" , 412 ), 413Gen ( 414"module: wezterm.url" , 415"config/lua/wezterm.url" , 416 ), 417Gen ( 418"enum: KeyAssignment" , 419"config/lua/keyassignment" , 420 ), 421Gen ( 422"enum: CopyModeAssignment" , 423"config/lua/keyassignment/CopyMode" , 424 ), 425Gen ("object: Color" ,"config/lua/color" ), 426Page ("object: ExecDomain" ,"config/lua/ExecDomain.md" ), 427Page ("object: LocalProcessInfo" ,"config/lua/LocalProcessInfo.md" ), 428Gen ("object: MuxDomain" ,"config/lua/MuxDomain" ), 429Gen ("object: MuxWindow" ,"config/lua/mux-window" ), 430Gen ("object: MuxTab" ,"config/lua/MuxTab" ), 431Page ("object: PaneInformation" ,"config/lua/PaneInformation.md" ), 432Page ("object: TabInformation" ,"config/lua/TabInformation.md" ), 433Page ("object: SshDomain" ,"config/lua/SshDomain.md" ), 434Page ("object: SpawnCommand" ,"config/lua/SpawnCommand.md" ), 435Gen ("object: Time" ,"config/lua/wezterm.time/Time" ), 436Page ("object: TlsDomainClient" ,"config/lua/TlsDomainClient.md" ), 437Page ("object: TlsDomainServer" ,"config/lua/TlsDomainServer.md" ), 438Gen ( 439"object: Pane" , 440"config/lua/pane" , 441 ), 442Gen ( 443"object: Window" , 444"config/lua/window" , 445 ), 446Page ("object: WslDomain" ,"config/lua/WslDomain.md" ), 447Gen ( 448"events: Gui" , 449"config/lua/gui-events" , 450 ), 451Gen ( 452"events: Multiplexer" , 453"config/lua/mux-events" , 454 ), 455Gen ( 456"events: Window" , 457"config/lua/window-events" , 458 ), 459 ], 460 ), 461Page ( 462"CLI Reference" , 463"cli/general.md" , 464children = [ 465Gen ("wezterm cli" ,"cli/cli" ), 466Page ("wezterm connect" ,"cli/connect.md" ), 467Page ("wezterm imgcat" ,"cli/imgcat.md" ), 468Page ("wezterm ls-fonts" ,"cli/ls-fonts.md" ), 469Page ("wezterm record" ,"cli/record.md" ), 470Page ("wezterm replay" ,"cli/replay.md" ), 471Page ("wezterm serial" ,"cli/serial.md" ), 472Page ("wezterm set-working-directory" ,"cli/set-working-directory.md" ), 473Page ("wezterm show-keys" ,"cli/show-keys.md" ), 474Page ("wezterm ssh" ,"cli/ssh.md" ), 475Page ("wezterm start" ,"cli/start.md" ), 476 ], 477 ), 478Page ( 479"Reference" , 480None , 481children = [ 482Page ("Escape Sequences" ,"escape-sequences.md" ), 483Page ("What is a Terminal?" ,"what-is-a-terminal.md" ), 484 ], 485 ), 486Page ( 487"Get Help" , 488None , 489children = [ 490Page ("Troubleshooting" ,"troubleshooting.md" ), 491Page ("F.A.Q." ,"faq.md" ), 492Page ("Getting Help" ,"help.md" ), 493Page ("Contributing" ,"contributing.md" ), 494 ], 495 ), 496Page ("Change Log" ,"changelog.md" ), 497Page ("Sponsor" ,"sponsor.md" ), 498] 499 500os .chdir ("docs" ) 501 502with open ("../mkdocs.yml" ,"w" )as f : 503f .write ("# this is auto-generated by docs/generate-toc.py, do not edit\n" ) 504f .write ("INHERIT: docs/mkdocs-base.yml\n" ) 505f .write ("nav:\n" ) 506for page in TOC : 507page .render (f ,depth = 1 ,mode = "mkdocs" ) 508 509 510with open ("SUMMARY.md" ,"w" )as f : 511f .write ("[root](index.md)\n" ) 512for page in TOC : 513page .render (f ,depth = 1 ,mode = "mdbook" )