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 #!/usr/bin/env python3
# License: GPLv3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net> # License: GPLv3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
import os
import subprocess import subprocess
from collections import defaultdict from collections import defaultdict
from typing import Any, DefaultDict, Dict, FrozenSet, List, Tuple, Union 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 = [] lines = []
for ch in type_map['flag']: for ch in type_map['flag']:
attr, allowed_values = keymap[ch] 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''' lines.append(f'''
case {attr}: {{ case {attr}: {{
g.{attr} = screen->parser_buf[pos++] & 0xff; g.{attr} = screen->parser_buf[pos++] & 0xff;
@ -240,7 +241,7 @@ static inline void
def write_header(text: str, path: str) -> None: def write_header(text: str, path: str) -> None:
with open(path, 'w') as f: 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('#pragma once', file=f)
print(text, file=f) print(text, file=f)
subprocess.check_call(['clang-format', '-i', path]) 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_UP: S(5, '~');
case GLFW_FKEY_PAGE_DOWN: S(6, '~'); case GLFW_FKEY_PAGE_DOWN: S(6, '~');
case GLFW_FKEY_HOME: S(1, 'H'); 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_END: S(1, 'F');
case GLFW_FKEY_F1: S(1, 'P'); case GLFW_FKEY_F1: S(1, 'P');
case GLFW_FKEY_F2: S(1, 'Q'); 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_F10: S(21, '~');
case GLFW_FKEY_F11: S(23, '~'); case GLFW_FKEY_F11: S(23, '~');
case GLFW_FKEY_F12: S(24, '~'); case GLFW_FKEY_F12: S(24, '~');
case GLFW_FKEY_KP_BEGIN: S(1, 'E');
/* end special numbers */ /* end special numbers */
case GLFW_FKEY_MENU: case GLFW_FKEY_MENU:
// use the same encoding as xterm for this key in legacy mode (F16) // 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 // This file is generated by gen-apc-parsers.py do not edit!
// edit!
#pragma once #pragma once
@ -148,9 +147,9 @@ static inline void parse_graphics_code(Screen *screen,
case action: { case action: {
g.action = screen->parser_buf[pos++] & 0xff; g.action = screen->parser_buf[pos++] & 0xff;
if (g.action != 'q' && g.action != 'p' && g.action != 't' && if (g.action != 'T' && g.action != 'a' && g.action != 'c' &&
g.action != 'd' && g.action != 'c' && g.action != 'a' && g.action != 'd' && g.action != 'f' && g.action != 'p' &&
g.action != 'T' && g.action != 'f') { g.action != 'q' && g.action != 't') {
REPORT_ERROR("Malformed GraphicsCommand control block, unknown flag " REPORT_ERROR("Malformed GraphicsCommand control block, unknown flag "
"value for action: 0x%x", "value for action: 0x%x",
g.action); g.action);
@ -160,16 +159,16 @@ static inline void parse_graphics_code(Screen *screen,
case delete_action: { case delete_action: {
g.delete_action = screen->parser_buf[pos++] & 0xff; g.delete_action = screen->parser_buf[pos++] & 0xff;
if (g.delete_action != 'q' && g.delete_action != 'Q' && if (g.delete_action != 'A' && g.delete_action != 'C' &&
g.delete_action != 'c' && g.delete_action != 'C' && g.delete_action != 'F' && g.delete_action != 'I' &&
g.delete_action != 'N' && g.delete_action != 'i' && g.delete_action != 'N' && g.delete_action != 'P' &&
g.delete_action != 'A' && g.delete_action != 'y' && g.delete_action != 'Q' && g.delete_action != 'X' &&
g.delete_action != 'a' && g.delete_action != 'I' && g.delete_action != 'Y' && g.delete_action != 'Z' &&
g.delete_action != 'F' && g.delete_action != 'p' && g.delete_action != 'a' && g.delete_action != 'c' &&
g.delete_action != 'z' && g.delete_action != 'x' && g.delete_action != 'f' && g.delete_action != 'i' &&
g.delete_action != 'n' && g.delete_action != 'X' && g.delete_action != 'n' && g.delete_action != 'p' &&
g.delete_action != 'Y' && g.delete_action != 'P' && g.delete_action != 'q' && g.delete_action != 'x' &&
g.delete_action != 'Z' && g.delete_action != 'f') { g.delete_action != 'y' && g.delete_action != 'z') {
REPORT_ERROR("Malformed GraphicsCommand control block, unknown flag " REPORT_ERROR("Malformed GraphicsCommand control block, unknown flag "
"value for delete_action: 0x%x", "value for delete_action: 0x%x",
g.delete_action); g.delete_action);
@ -179,8 +178,8 @@ static inline void parse_graphics_code(Screen *screen,
case transmission_type: { case transmission_type: {
g.transmission_type = screen->parser_buf[pos++] & 0xff; g.transmission_type = screen->parser_buf[pos++] & 0xff;
if (g.transmission_type != 's' && g.transmission_type != 't' && if (g.transmission_type != 'd' && g.transmission_type != 'f' &&
g.transmission_type != 'd' && g.transmission_type != 'f') { g.transmission_type != 's' && g.transmission_type != 't') {
REPORT_ERROR("Malformed GraphicsCommand control block, unknown flag " REPORT_ERROR("Malformed GraphicsCommand control block, unknown flag "
"value for transmission_type: 0x%x", "value for transmission_type: 0x%x",
g.transmission_type); g.transmission_type);