Refactor: Sorting items when generating files

Make the files generated in different environments consistent.
This commit is contained in:
pagedown 2022-01-29 20:14:56 +08:00
parent a22f37b919
commit 74921c1373
No known key found for this signature in database
GPG Key ID: E921CF18AC8FF6EB
3 changed files with 20 additions and 20 deletions

View File

@ -1,6 +1,7 @@
#!/usr/bin/env python3
# License: GPLv3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
import os
import subprocess
from collections import defaultdict
from typing import Any, DefaultDict, Dict, FrozenSet, List, Tuple, Union
@ -42,7 +43,7 @@ def parse_flag(keymap: KeymapType, type_map: Dict[str, Any], command_class: str)
lines = []
for ch in type_map['flag']:
attr, allowed_values = keymap[ch]
q = ' && '.join(f"g.{attr} != '{x}'" for x in allowed_values)
q = ' && '.join(f"g.{attr} != '{x}'" for x in sorted(allowed_values))
lines.append(f'''
case {attr}: {{
g.{attr} = screen->parser_buf[pos++] & 0xff;
@ -240,7 +241,7 @@ def generate(
def write_header(text: str, path: str) -> None:
with open(path, 'w') as f:
print(f'// This file is generated by {__file__} do not edit!', file=f, end='\n\n')
print(f'// This file is generated by {os.path.basename(__file__)} do not edit!', file=f, end='\n\n')
print('#pragma once', file=f)
print(text, file=f)
subprocess.check_call(['clang-format', '-i', path])

View File

@ -219,7 +219,6 @@ encode_function_key(const KeyEvent *ev, char *output) {
case GLFW_FKEY_PAGE_UP: S(5, '~');
case GLFW_FKEY_PAGE_DOWN: S(6, '~');
case GLFW_FKEY_HOME: S(1, 'H');
case GLFW_FKEY_KP_BEGIN: S(1, 'E');
case GLFW_FKEY_END: S(1, 'F');
case GLFW_FKEY_F1: S(1, 'P');
case GLFW_FKEY_F2: S(1, 'Q');
@ -233,6 +232,7 @@ encode_function_key(const KeyEvent *ev, char *output) {
case GLFW_FKEY_F10: S(21, '~');
case GLFW_FKEY_F11: S(23, '~');
case GLFW_FKEY_F12: S(24, '~');
case GLFW_FKEY_KP_BEGIN: S(1, 'E');
/* end special numbers */
case GLFW_FKEY_MENU:
// use the same encoding as xterm for this key in legacy mode (F16)

View File

@ -1,5 +1,4 @@
// This file is generated by /home/kovid/work/kitty/./gen-apc-parsers.py do not
// edit!
// This file is generated by gen-apc-parsers.py do not edit!
#pragma once
@ -148,9 +147,9 @@ static inline void parse_graphics_code(Screen *screen,
case action: {
g.action = screen->parser_buf[pos++] & 0xff;
if (g.action != 'q' && g.action != 'p' && g.action != 't' &&
g.action != 'd' && g.action != 'c' && g.action != 'a' &&
g.action != 'T' && g.action != 'f') {
if (g.action != 'T' && g.action != 'a' && g.action != 'c' &&
g.action != 'd' && g.action != 'f' && g.action != 'p' &&
g.action != 'q' && g.action != 't') {
REPORT_ERROR("Malformed GraphicsCommand control block, unknown flag "
"value for action: 0x%x",
g.action);
@ -160,16 +159,16 @@ static inline void parse_graphics_code(Screen *screen,
case delete_action: {
g.delete_action = screen->parser_buf[pos++] & 0xff;
if (g.delete_action != 'q' && g.delete_action != 'Q' &&
g.delete_action != 'c' && g.delete_action != 'C' &&
g.delete_action != 'N' && g.delete_action != 'i' &&
g.delete_action != 'A' && g.delete_action != 'y' &&
g.delete_action != 'a' && g.delete_action != 'I' &&
g.delete_action != 'F' && g.delete_action != 'p' &&
g.delete_action != 'z' && g.delete_action != 'x' &&
g.delete_action != 'n' && g.delete_action != 'X' &&
g.delete_action != 'Y' && g.delete_action != 'P' &&
g.delete_action != 'Z' && g.delete_action != 'f') {
if (g.delete_action != 'A' && g.delete_action != 'C' &&
g.delete_action != 'F' && g.delete_action != 'I' &&
g.delete_action != 'N' && g.delete_action != 'P' &&
g.delete_action != 'Q' && g.delete_action != 'X' &&
g.delete_action != 'Y' && g.delete_action != 'Z' &&
g.delete_action != 'a' && g.delete_action != 'c' &&
g.delete_action != 'f' && g.delete_action != 'i' &&
g.delete_action != 'n' && g.delete_action != 'p' &&
g.delete_action != 'q' && g.delete_action != 'x' &&
g.delete_action != 'y' && g.delete_action != 'z') {
REPORT_ERROR("Malformed GraphicsCommand control block, unknown flag "
"value for delete_action: 0x%x",
g.delete_action);
@ -179,8 +178,8 @@ static inline void parse_graphics_code(Screen *screen,
case transmission_type: {
g.transmission_type = screen->parser_buf[pos++] & 0xff;
if (g.transmission_type != 's' && g.transmission_type != 't' &&
g.transmission_type != 'd' && g.transmission_type != 'f') {
if (g.transmission_type != 'd' && g.transmission_type != 'f' &&
g.transmission_type != 's' && g.transmission_type != 't') {
REPORT_ERROR("Malformed GraphicsCommand control block, unknown flag "
"value for transmission_type: 0x%x",
g.transmission_type);