Generate color names and table for Go

Also exclude generated files from gofmt checking
This commit is contained in:
Kovid Goyal 2022-08-27 12:57:07 +05:30
parent 9c58cb3f41
commit 387333492b
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
2 changed files with 16 additions and 6 deletions

View file

@ -133,8 +133,10 @@ def main():
elif action == 'gofmt':
q = subprocess.check_output('gofmt -s -l tools'.split())
if q.strip():
print(q.decode())
raise SystemExit(1)
q = '\n'.join(filter(lambda x: not x.endswith('_generated.go'), q.decode().strip().splitlines())).strip()
if q:
print(q)
raise SystemExit(1)
else:
raise SystemExit(f'Unknown action: {action}')

View file

@ -4,13 +4,14 @@
import json
import io
import os
import subprocess
from contextlib import contextmanager, suppress
from typing import Dict, Iterator, List, Tuple, Union
import kitty.constants as kc
from kittens.tui.operations import Mode
from kitty.rgb import color_names
from kitty.cli import OptionDict, OptionSpecSeq, parse_option_spec
from kitty.options.types import Options
from kitty.key_encoding import config_mod_map
from kitty.key_names import (
character_key_name_aliases, functional_key_name_aliases
@ -210,6 +211,14 @@ def build_go_code(name: str, cmd: RemoteCommand, seq: OptionSpecSeq, template: s
# Constants {{{
def generate_color_names() -> str:
return 'package style\n\nvar ColorNames = map[string]RGBA{' + '\n'.join(
f'\t"{name}": RGBA{{ Red:{val.red}, Green:{val.green}, Blue:{val.blue} }},'
for name, val in color_names.items()
) + '\n}' + '\n\nvar ColorTable = [256]uint32{' + ', '.join(
f'{x}' for x in Options.color_table) + '}\n'
def load_ref_map() -> Dict[str, Dict[str, str]]:
with open('kitty/docs_ref_map_generated.h') as f:
raw = f.read()
@ -273,14 +282,13 @@ def update_at_commands() -> None:
os.remove(dest)
with open(dest, 'w') as f:
f.write(code)
cp = subprocess.run('gofmt -s -w tools/cmd/at'.split())
if cp.returncode != 0:
raise SystemExit(cp.returncode)
def main() -> None:
with replace_if_needed('constants_generated.go') as f:
f.write(generate_constants())
with replace_if_needed('tools/utils/style/color-names_generated.go') as f:
f.write(generate_color_names())
update_at_commands()
print(json.dumps(changed, indent=2))