diff --git a/kittens/ask/main.py b/kittens/ask/main.py index 6df8f98a4..f366812a9 100644 --- a/kittens/ask/main.py +++ b/kittens/ask/main.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2018, Kovid Goyal import os diff --git a/kittens/broadcast/main.py b/kittens/broadcast/main.py index 4c137fb28..06cd555c9 100644 --- a/kittens/broadcast/main.py +++ b/kittens/broadcast/main.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal import sys diff --git a/kittens/choose/main.py b/kittens/choose/main.py index 9dc4e90f3..e7194601a 100644 --- a/kittens/choose/main.py +++ b/kittens/choose/main.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2018, Kovid Goyal import sys diff --git a/kittens/choose/match.py b/kittens/choose/match.py index d0cfe2bbf..15ef54103 100644 --- a/kittens/choose/match.py +++ b/kittens/choose/match.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2021, Kovid Goyal from typing import Iterable, List, Union diff --git a/kittens/clipboard/main.py b/kittens/clipboard/main.py index ce39281e0..be694800e 100644 --- a/kittens/clipboard/main.py +++ b/kittens/clipboard/main.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2018, Kovid Goyal import os @@ -94,7 +93,7 @@ def main(args: List[str]) -> NoReturn: data: Optional[bytes] = None if not sys.stdin.isatty(): data = sys.stdin.buffer.read() - sys.stdin = open(os.ctermid(), 'r') + sys.stdin = open(os.ctermid()) loop = Loop() handler = Clipboard(data, cli_opts) loop.loop(handler) diff --git a/kittens/diff/collect.py b/kittens/diff/collect.py index 0f479c35a..0f39659c4 100644 --- a/kittens/diff/collect.py +++ b/kittens/diff/collect.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2018, Kovid Goyal import os diff --git a/kittens/diff/config.py b/kittens/diff/config.py index 59836b386..60d2dda74 100644 --- a/kittens/diff/config.py +++ b/kittens/diff/config.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2018, Kovid Goyal import os diff --git a/kittens/diff/highlight.py b/kittens/diff/highlight.py index f81bbeb65..6a3ce3ece 100644 --- a/kittens/diff/highlight.py +++ b/kittens/diff/highlight.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2018, Kovid Goyal import concurrent @@ -31,7 +30,7 @@ class DiffFormatter(Formatter): except ClassNotFound: initialized = False if not initialized: - raise StyleNotFound('pygments style "{}" not found'.format(style)) + raise StyleNotFound(f'pygments style "{style}" not found') self.styles: Dict[str, Tuple[str, str]] = {} for token, token_style in self.style: @@ -153,7 +152,7 @@ def highlight_collection(collection: Collection, aliases: Optional[Dict[str, str try: highlights = future.result() except Exception as e: - return 'Running syntax highlighting for {} generated an exception: {}'.format(path, e) + return f'Running syntax highlighting for {path} generated an exception: {e}' ans[path] = highlights return ans @@ -166,5 +165,5 @@ def main() -> None: with open(sys.argv[-1]) as f: highlighted = highlight_data(f.read(), f.name, defaults.syntax_aliases) if highlighted is None: - raise SystemExit('Unknown filetype: {}'.format(sys.argv[-1])) + raise SystemExit(f'Unknown filetype: {sys.argv[-1]}') print(highlighted) diff --git a/kittens/diff/main.py b/kittens/diff/main.py index dd77bd6b5..a10ff8c70 100644 --- a/kittens/diff/main.py +++ b/kittens/diff/main.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2018, Kovid Goyal import atexit @@ -428,7 +427,7 @@ class DiffHandler(Handler): elif self.state is MESSAGE: self.cmd.styled(self.message, reverse=True) else: - sp = '{:.0%}'.format(self.scroll_pos/self.max_scroll_pos) if self.scroll_pos and self.max_scroll_pos else '0%' + sp = f'{self.scroll_pos/self.max_scroll_pos:.0%}' if self.scroll_pos and self.max_scroll_pos else '0%' scroll_frac = styled(sp, fg=self.opts.margin_fg) if self.current_search is None: counts = '{}{}{}'.format( @@ -437,7 +436,7 @@ class DiffHandler(Handler): styled(str(self.removed_count), fg=self.opts.highlight_removed_bg) ) else: - counts = styled('{} matches'.format(len(self.current_search)), fg=self.opts.margin_fg) + counts = styled(f'{len(self.current_search)} matches', fg=self.opts.margin_fg) suffix = counts + ' ' + scroll_frac prefix = styled(':', fg=self.opts.margin_fg) filler = self.screen_size.cols - wcswidth(prefix) - wcswidth(suffix) @@ -632,7 +631,7 @@ def main(args: List[str]) -> None: raise SystemExit('The items to be diffed should both be either directories or files. Comparing a directory to a file is not valid.') for f in left, right: if not os.path.exists(f): - raise SystemExit('{} does not exist'.format(f)) + raise SystemExit(f'{f} does not exist') loop = Loop() handler = DiffHandler(cli_opts, opts, left, right) diff --git a/kittens/diff/patch.py b/kittens/diff/patch.py index dae419e51..2e791d47a 100644 --- a/kittens/diff/patch.py +++ b/kittens/diff/patch.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2018, Kovid Goyal import concurrent.futures @@ -151,9 +150,9 @@ class Hunk: # Sanity check c = self.chunks[-1] if c.left_start + c.left_count != self.left_start + self.left_count: - raise ValueError('Left side line mismatch {} != {}'.format(c.left_start + c.left_count, self.left_start + self.left_count)) + raise ValueError(f'Left side line mismatch {c.left_start + c.left_count} != {self.left_start + self.left_count}') if c.right_start + c.right_count != self.right_start + self.right_count: - raise ValueError('Left side line mismatch {} != {}'.format(c.right_start + c.right_count, self.right_start + self.right_count)) + raise ValueError(f'Left side line mismatch {c.right_start + c.right_count} != {self.right_start + self.right_count}') for c in self.chunks: c.finalize() @@ -240,18 +239,18 @@ class Differ: try: ok, returncode, output = future.result() except FileNotFoundError as err: - return 'Could not find the {} executable. Is it in your PATH?'.format(err.filename) + return f'Could not find the {err.filename} executable. Is it in your PATH?' except Exception as e: - return 'Running git diff for {} vs. {} generated an exception: {}'.format(left_path, right_path, e) + return f'Running git diff for {left_path} vs. {right_path} generated an exception: {e}' if not ok: - return output + '\nRunning git diff for {} vs. {} failed'.format(left_path, right_path) + return output + f'\nRunning git diff for {left_path} vs. {right_path} failed' left_lines = lines_for_path(left_path) right_lines = lines_for_path(right_path) try: patch = parse_patch(output) except Exception: import traceback - return traceback.format_exc() + '\nParsing diff for {} vs. {} failed'.format(left_path, right_path) + return traceback.format_exc() + f'\nParsing diff for {left_path} vs. {right_path} failed' else: ans[key] = patch return ans diff --git a/kittens/diff/render.py b/kittens/diff/render.py index 4bb2a490e..08f7cfe26 100644 --- a/kittens/diff/render.py +++ b/kittens/diff/render.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2018, Kovid Goyal import warnings @@ -42,7 +41,7 @@ class Ref: def __repr__(self) -> str: return '{}({})'.format(self.__class__.__name__, ', '.join( - '{}={}'.format(n, getattr(self, n)) for n in self.__slots__ if n != '_hash')) + f'{n}={getattr(self, n)}' for n in self.__slots__ if n != '_hash')) class LineRef(Ref): @@ -264,7 +263,7 @@ def render_diff_pair( def hunk_title(hunk_num: int, hunk: Hunk, margin_size: int, available_cols: int) -> str: m = hunk_margin_format(' ' * margin_size) - t = '@@ -{},{} +{},{} @@ {}'.format(hunk.left_start + 1, hunk.left_count, hunk.right_start + 1, hunk.right_count, hunk.title) + t = f'@@ -{hunk.left_start + 1},{hunk.left_count} +{hunk.right_start + 1},{hunk.right_count} @@ {hunk.title}' return m + hunk_format(place_in(t, available_cols)) @@ -539,7 +538,7 @@ class RenderDiff: assert other_path is not None ans = yield_lines_from(rename_lines(path, other_path, args, columns, margin_size), item_ref) else: - raise ValueError('Unsupported item type: {}'.format(item_type)) + raise ValueError(f'Unsupported item type: {item_type}') yield from ans if i < last_item_num: yield Line('', item_ref) diff --git a/kittens/diff/search.py b/kittens/diff/search.py index 7aba9fb0b..01f42db3e 100644 --- a/kittens/diff/search.py +++ b/kittens/diff/search.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2018, Kovid Goyal import re @@ -30,7 +29,7 @@ class Search: try: self.pat = re.compile(query, flags=re.UNICODE | re.IGNORECASE) except Exception: - raise BadRegex('Not a valid regex: {}'.format(query)) + raise BadRegex(f'Not a valid regex: {query}') def __call__(self, diff_lines: Iterable['Line'], margin_size: int, cols: int) -> bool: self.matches = {} @@ -68,6 +67,6 @@ class Search: return False write(self.style) for start, text in highlights: - write('\r\x1b[{}C{}'.format(start, text)) + write(f'\r\x1b[{start}C{text}') write('\x1b[m') return True diff --git a/kittens/hints/main.py b/kittens/hints/main.py index e77ebb749..cda7d8d35 100644 --- a/kittens/hints/main.py +++ b/kittens/hints/main.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2018, Kovid Goyal import os @@ -366,7 +365,7 @@ def functions_for(args: HintsCLIOptions) -> Tuple[str, List[PostprocessorFunc]]: chars = args.word_characters if chars is None: chars = kitty_common_opts()['select_by_word_characters'] - pattern = r'(?u)[{}\w]{{{},}}'.format(escape(chars), args.minimum_match_length) + pattern = fr'(?u)[{escape(chars)}\w]{{{args.minimum_match_length},}}' post_processors.extend((brackets, quotes)) else: pattern = args.regex diff --git a/kittens/hyperlinked_grep/main.py b/kittens/hyperlinked_grep/main.py index 79a7df406..680a121e4 100644 --- a/kittens/hyperlinked_grep/main.py +++ b/kittens/hyperlinked_grep/main.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal import os diff --git a/kittens/icat/main.py b/kittens/icat/main.py index 927a5395b..fbd494163 100755 --- a/kittens/icat/main.py +++ b/kittens/icat/main.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2017, Kovid Goyal import contextlib @@ -145,7 +144,7 @@ def get_screen_size() -> ScreenSize: @run_once def options_spec() -> str: - return OPTIONS.format(appname='{}-icat'.format(appname)) + return OPTIONS.format(appname=f'{appname}-icat') def write_gr_cmd(cmd: GraphicsCommand, payload: Optional[bytes] = None) -> None: @@ -195,7 +194,7 @@ def set_cursor_for_place(place: 'Place', cmd: GraphicsCommand, width: int, heigh extra_cells = (place.width - num_of_cells_needed) // 2 elif align == 'right': extra_cells = place.width - num_of_cells_needed - sys.stdout.buffer.write('\033[{};{}H'.format(place.top + 1, x + extra_cells).encode('ascii')) + sys.stdout.buffer.write(f'\033[{place.top + 1};{x + extra_cells}H'.encode('ascii')) def write_chunked(cmd: GraphicsCommand, data: bytes) -> None: @@ -369,7 +368,7 @@ def scan(d: str) -> Generator[Tuple[str, str], None, None]: def detect_support(wait_for: float = 10, silent: bool = False) -> bool: global can_transfer_with_files if not silent: - print('Checking for graphics ({}s max. wait)...'.format(wait_for), end='\r') + print(f'Checking for graphics ({wait_for}s max. wait)...', end='\r') sys.stdout.flush() try: received = b'' @@ -466,7 +465,7 @@ def process_single_item( with socket_timeout(30): urlretrieve(item, filename=tf.name) except Exception as e: - raise SystemExit('Failed to download image at URL: {} with error: {}'.format(item, e)) + raise SystemExit(f'Failed to download image at URL: {item} with error: {e}') item = tf.name is_tempfile = True file_removed = process(item, args, parsed_opts, is_tempfile) @@ -493,14 +492,14 @@ def process_single_item( def main(args: List[str] = sys.argv) -> None: global can_transfer_with_files - cli_opts, items_ = parse_args(args[1:], options_spec, usage, help_text, '{} +kitten icat'.format(appname), result_class=IcatCLIOptions) + cli_opts, items_ = parse_args(args[1:], options_spec, usage, help_text, f'{appname} +kitten icat', result_class=IcatCLIOptions) items: List[Union[str, bytes]] = list(items_) if cli_opts.print_window_size: screen_size_function.cache_clear() with open(os.ctermid()) as tty: ss = screen_size_function(tty)() - print('{}x{}'.format(ss.width, ss.height), end='') + print(f'{ss.width}x{ss.height}', end='') raise SystemExit(0) if not sys.stdout.isatty(): @@ -511,7 +510,7 @@ def main(args: List[str] = sys.argv) -> None: if stdin_data: items.insert(0, stdin_data) sys.stdin.close() - sys.stdin = open(os.ctermid(), 'r') + sys.stdin = open(os.ctermid()) screen_size = get_screen_size_function() signal.signal(signal.SIGWINCH, lambda signum, frame: setattr(screen_size, 'changed', True)) @@ -526,12 +525,12 @@ def main(args: List[str] = sys.argv) -> None: try: parsed_opts.place = parse_place(cli_opts.place) except Exception: - raise SystemExit('Not a valid place specification: {}'.format(cli_opts.place)) + raise SystemExit(f'Not a valid place specification: {cli_opts.place}') try: parsed_opts.z_index = parse_z_index(cli_opts.z_index) except Exception: - raise SystemExit('Not a valid z-index specification: {}'.format(cli_opts.z_index)) + raise SystemExit(f'Not a valid z-index specification: {cli_opts.z_index}') if cli_opts.detect_support: if not detect_support(wait_for=cli_opts.detection_timeout, silent=True): diff --git a/kittens/mouse_demo/main.py b/kittens/mouse_demo/main.py index 79580d0ae..2d4e0dcb3 100644 --- a/kittens/mouse_demo/main.py +++ b/kittens/mouse_demo/main.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2021, Kovid Goyal import sys diff --git a/kittens/panel/main.py b/kittens/panel/main.py index 7f22e797a..19c89b835 100644 --- a/kittens/panel/main.py +++ b/kittens/panel/main.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2018, Kovid Goyal import os @@ -116,7 +115,7 @@ def setup_x11_window(win_id: int) -> None: '-id', str(win_id), '-format', '_NET_WM_WINDOW_TYPE', '32a', '-set', '_NET_WM_WINDOW_TYPE', '_NET_WM_WINDOW_TYPE_DOCK' ) - func = globals()['create_{}_strut'.format(args.edge)] + func = globals()[f'create_{args.edge}_strut'] func(win_id, window_width, window_height) diff --git a/kittens/query_terminal/main.py b/kittens/query_terminal/main.py index 1565f4bfa..86af00615 100644 --- a/kittens/query_terminal/main.py +++ b/kittens/query_terminal/main.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal import re @@ -28,10 +27,10 @@ class Query: def __init__(self) -> None: self.encoded_query_name = hexlify(self.query_name.encode('utf-8')).decode('ascii') - self.pat = re.compile('\x1bP([01])\\+r{}(.*?)\x1b\\\\'.format(self.encoded_query_name).encode('ascii')) + self.pat = re.compile(f'\x1bP([01])\\+r{self.encoded_query_name}(.*?)\x1b\\\\'.encode('ascii')) def query_code(self) -> str: - return "\x1bP+q{}\x1b\\".format(self.encoded_query_name) + return f"\x1bP+q{self.encoded_query_name}\x1b\\" def decode_response(self, res: bytes) -> str: return unhexlify(res).decode('utf-8') @@ -234,7 +233,7 @@ def main(args: List[str] = sys.argv) -> None: options_spec, usage, help_text, - '{} +kitten query_terminal'.format(appname), + f'{appname} +kitten query_terminal', result_class=QueryTerminalCLIOptions ) queries: List[str] = list(items_) diff --git a/kittens/remote_file/main.py b/kittens/remote_file/main.py index fa3255258..4ba8f07e9 100644 --- a/kittens/remote_file/main.py +++ b/kittens/remote_file/main.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal diff --git a/kittens/resize_window/main.py b/kittens/resize_window/main.py index ab7a15c50..80f19bf83 100644 --- a/kittens/resize_window/main.py +++ b/kittens/resize_window/main.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2018, Kovid Goyal @@ -43,7 +42,7 @@ class Resize(Handler): if is_decrease: increment *= -1 axis = 'reset' if reset else ('horizontal' if is_horizontal else 'vertical') - cmdline = [resize_window.name, '--self', '--increment={}'.format(increment), '--axis=' + axis] + cmdline = [resize_window.name, '--self', f'--increment={increment}', '--axis=' + axis] opts, items = parse_subcommand_cli(resize_window, cmdline) payload = resize_window.message_to_kitty(global_opts, opts, items) send = {'cmd': resize_window.name, 'version': version, 'payload': payload, 'no_response': False} @@ -96,7 +95,7 @@ class Resize(Handler): print('Hold down {} to double step size'.format(styled('Ctrl', italic=True))) print() print(styled('Sizes', bold=True, fg='white', fg_intense=True)) - print('Original: {} rows {} cols'.format(self.original_size.rows, self.original_size.cols)) + print(f'Original: {self.original_size.rows} rows {self.original_size.cols} cols') print('Current: {} rows {} cols'.format( styled(str(self.screen_size.rows), fg='magenta'), styled(str(self.screen_size.cols), fg='magenta'))) diff --git a/kittens/runner.py b/kittens/runner.py index bd7f50731..27d0b6fc8 100644 --- a/kittens/runner.py +++ b/kittens/runner.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2018, Kovid Goyal @@ -61,7 +60,7 @@ def import_kitten_main_module(config_dir: str, kitten: str) -> Dict[str, Any]: return {'start': g['main'], 'end': hr} kitten = resolved_kitten(kitten) - m = importlib.import_module('kittens.{}.main'.format(kitten)) + m = importlib.import_module(f'kittens.{kitten}.main') return {'start': getattr(m, 'main'), 'end': getattr(m, 'handle_result', lambda *a, **k: None)} @@ -111,7 +110,7 @@ def deserialize(output: str) -> Any: prefix, sz, rest = output.split(' ', 2) return json.loads(rest[:int(sz)]) except Exception: - raise ValueError('Failed to parse kitten output: {!r}'.format(output)) + raise ValueError(f'Failed to parse kitten output: {output!r}') def run_kitten(kitten: str, run_name: str = '__main__') -> None: @@ -120,7 +119,7 @@ def run_kitten(kitten: str, run_name: str = '__main__') -> None: kitten = resolved_kitten(kitten) set_debug(kitten) try: - runpy.run_module('kittens.{}.main'.format(kitten), run_name=run_name) + runpy.run_module(f'kittens.{kitten}.main', run_name=run_name) return except ImportError: pass diff --git a/kittens/show_error/main.py b/kittens/show_error/main.py index 880b6be38..e55cba7a8 100644 --- a/kittens/show_error/main.py +++ b/kittens/show_error/main.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2018, Kovid Goyal import os diff --git a/kittens/show_key/kitty_mode.py b/kittens/show_key/kitty_mode.py index 1e28ec35b..a1113440d 100644 --- a/kittens/show_key/kitty_mode.py +++ b/kittens/show_key/kitty_mode.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2018, Kovid Goyal from kitty.key_encoding import ( diff --git a/kittens/show_key/main.py b/kittens/show_key/main.py index 8217697c2..635074ea0 100644 --- a/kittens/show_key/main.py +++ b/kittens/show_key/main.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2021, Kovid Goyal diff --git a/kittens/ssh/completion.py b/kittens/ssh/completion.py index f74726deb..b6d0ed4dd 100644 --- a/kittens/ssh/completion.py +++ b/kittens/ssh/completion.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2021, Kovid Goyal import os diff --git a/kittens/ssh/main.py b/kittens/ssh/main.py index e6bac3698..293e18e36 100644 --- a/kittens/ssh/main.py +++ b/kittens/ssh/main.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2018, Kovid Goyal import os @@ -245,7 +244,7 @@ def parse_ssh_args(args: List[str]) -> Tuple[List[str], List[str], bool]: else: expecting_option_val = True break - raise InvalidSSHArgs('unknown option -- {}'.format(arg[1:])) + raise InvalidSSHArgs(f'unknown option -- {arg[1:]}') continue if expecting_option_val: ssh_args.append(arg) diff --git a/kittens/themes/collection.py b/kittens/themes/collection.py index 14701163c..6416af6e7 100644 --- a/kittens/themes/collection.py +++ b/kittens/themes/collection.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2021, Kovid Goyal import datetime diff --git a/kittens/themes/main.py b/kittens/themes/main.py index 64d25b893..2c3f59a47 100644 --- a/kittens/themes/main.py +++ b/kittens/themes/main.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2021, Kovid Goyal import os diff --git a/kittens/transfer/librsync.py b/kittens/transfer/librsync.py index 12e6abe8f..eb96fc07d 100644 --- a/kittens/transfer/librsync.py +++ b/kittens/transfer/librsync.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2021, Kovid Goyal import os diff --git a/kittens/transfer/main.py b/kittens/transfer/main.py index 46f9733de..2154229cf 100644 --- a/kittens/transfer/main.py +++ b/kittens/transfer/main.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2021, Kovid Goyal diff --git a/kittens/transfer/receive.py b/kittens/transfer/receive.py index fa693e589..e062d03be 100644 --- a/kittens/transfer/receive.py +++ b/kittens/transfer/receive.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2021, Kovid Goyal from enum import auto diff --git a/kittens/transfer/send.py b/kittens/transfer/send.py index de85c95d2..5ed7244b2 100644 --- a/kittens/transfer/send.py +++ b/kittens/transfer/send.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2021, Kovid Goyal diff --git a/kittens/transfer/utils.py b/kittens/transfer/utils.py index 1167c8973..20d3d992a 100644 --- a/kittens/transfer/utils.py +++ b/kittens/transfer/utils.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2021, Kovid Goyal import os diff --git a/kittens/tui/dircolors.py b/kittens/tui/dircolors.py index 524150444..6d0fd304e 100644 --- a/kittens/tui/dircolors.py +++ b/kittens/tui/dircolors.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal import os @@ -336,11 +335,11 @@ class Dircolors: def _format_code(self, text: str, code: str) -> str: val = self.codes.get(code) - return '\033[%sm%s\033[%sm' % (val, text, self.codes.get('rs', '0')) if val else text + return '\033[{}m{}\033[{}m'.format(val, text, self.codes.get('rs', '0')) if val else text def _format_ext(self, text: str, ext: str) -> str: val = self.extensions.get(ext, '0') - return '\033[%sm%s\033[%sm' % (val, text, self.codes.get('rs', '0')) if val else text + return '\033[{}m{}\033[{}m'.format(val, text, self.codes.get('rs', '0')) if val else text def format_mode(self, text: str, sr: os.stat_result) -> str: mode = sr.st_mode diff --git a/kittens/tui/handler.py b/kittens/tui/handler.py index 51ce42f7f..766d88096 100644 --- a/kittens/tui/handler.py +++ b/kittens/tui/handler.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2018, Kovid Goyal diff --git a/kittens/tui/images.py b/kittens/tui/images.py index f5b12a45c..5d18f888c 100644 --- a/kittens/tui/images.py +++ b/kittens/tui/images.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2018, Kovid Goyal import codecs @@ -105,7 +104,7 @@ class OpenFailed(ValueError): def __init__(self, path: str, message: str): ValueError.__init__( - self, 'Failed to open image: {} with error: {}'.format(path, message) + self, f'Failed to open image: {path} with error: {message}' ) self.path = path @@ -114,7 +113,7 @@ class ConvertFailed(ValueError): def __init__(self, path: str, message: str): ValueError.__init__( - self, 'Failed to convert image: {} with error: {}'.format(path, message) + self, f'Failed to convert image: {path} with error: {message}' ) self.path = path @@ -212,7 +211,7 @@ def render_image( scaled = True if scaled or width > available_width or height > available_height: width, height = fit_image(width, height, available_width, available_height) - resize_cmd = ['-resize', '{}x{}!'.format(width, height)] + resize_cmd = ['-resize', f'{width}x{height}!'] if get_multiple_frames: # we have to coalesce, resize and de-coalesce all frames resize_cmd = ['-coalesce'] + resize_cmd + ['-deconstruct'] @@ -373,7 +372,7 @@ class GraphicsCommand: def serialize(self, payload: Union[bytes, str] = b'') -> bytes: items = [] for k, val in self._actual_values.items(): - items.append('{}={}'.format(k, val)) + items.append(f'{k}={val}') ans: List[bytes] = [] w = ans.append diff --git a/kittens/tui/line_edit.py b/kittens/tui/line_edit.py index c648d49fa..fba7524a4 100644 --- a/kittens/tui/line_edit.py +++ b/kittens/tui/line_edit.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2018, Kovid Goyal from typing import Callable, Tuple diff --git a/kittens/tui/loop.py b/kittens/tui/loop.py index dff673602..982c5431b 100644 --- a/kittens/tui/loop.py +++ b/kittens/tui/loop.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2018, Kovid Goyal import asyncio diff --git a/kittens/tui/operations.py b/kittens/tui/operations.py index 08133e941..634d29f0c 100644 --- a/kittens/tui/operations.py +++ b/kittens/tui/operations.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2018, Kovid Goyal import sys @@ -57,13 +56,13 @@ def cmd(f: F) -> F: @cmd def set_mode(which: Mode) -> str: num, private = which.value - return '\033[{}{}h'.format(private, num) + return f'\033[{private}{num}h' @cmd def reset_mode(which: Mode) -> str: num, private = which.value - return '\033[{}{}l'.format(private, num) + return f'\033[{private}{num}l' @cmd @@ -127,7 +126,7 @@ def set_cursor_visible(yes_or_no: bool) -> str: @cmd def set_cursor_position(x: int = 0, y: int = 0) -> str: # (0, 0) is top left - return '\033[{};{}H'.format(y + 1, x + 1) + return f'\033[{y + 1};{x + 1}H' @cmd @@ -141,7 +140,7 @@ def set_cursor_shape(shape: str = 'block', blink: bool = True) -> str: val = {'block': 1, 'underline': 3, 'bar': 5}.get(shape, 1) if not blink: val += 1 - return '\033[{} q'.format(val) + return f'\033[{val} q' @cmd @@ -156,7 +155,7 @@ def set_scrolling_region(screen_size: Optional['ScreenSize'] = None, top: Option bottom = screen_size.rows - 1 + bottom else: bottom += 1 - return '\033[{};{}r'.format(top + 1, bottom + 1) + return f'\033[{top + 1};{bottom + 1}r' @cmd @@ -178,7 +177,7 @@ def color_code(color: ColorSpec, intense: bool = False, base: int = 30) -> str: if isinstance(color, str): e = str((base + 60 if intense else base) + STANDARD_COLORS[color]) elif isinstance(color, int): - e = '{}:5:{}'.format(base + 8, max(0, min(color, 255))) + e = f'{base + 8}:5:{max(0, min(color, 255))}' else: e = '{}:2:{}:{}:{}'.format(base + 8, *color) return e @@ -198,7 +197,7 @@ def colored( reset_to_intense: bool = False ) -> str: e = color_code(color, intense) - return '\033[{}m{}\033[{}m'.format(e, text, 39 if reset_to is None else color_code(reset_to, reset_to_intense)) + return f'\033[{e}m{text}\033[{39 if reset_to is None else color_code(reset_to, reset_to_intense)}m' @cmd @@ -233,7 +232,7 @@ def styled( start.append(color_code(underline_color, base=50)) end.append('59') if underline is not None: - start.append('4:{}'.format(UNDERLINE_STYLES[underline])) + start.append(f'4:{UNDERLINE_STYLES[underline]}') end.append('4:0') if italic is not None: s, e = (start, end) if italic else (end, start) @@ -383,7 +382,7 @@ def set_default_colors( def item(which: Optional[Union[Color, str]], num: int) -> None: nonlocal ans if which is None: - ans += '\x1b]1{}\x1b\\'.format(num) + ans += f'\x1b]1{num}\x1b\\' else: if isinstance(which, Color): q = color_as_sharp(which) @@ -391,7 +390,7 @@ def set_default_colors( x = to_color(which) assert x is not None q = color_as_sharp(x) - ans += '\x1b]{};{}\x1b\\'.format(num, q) + ans += f'\x1b]{num};{q}\x1b\\' item(fg, 10) item(bg, 11) @@ -464,7 +463,7 @@ def as_type_stub() -> str: args = ', '.join(func_sig(func)) if args: args = ', ' + args - methods.append(' def {}(self{}) -> str: pass'.format(name, args)) + methods.append(f' def {name}(self{args}) -> str: pass') ans += ['', '', 'class CMD:'] + methods return '\n'.join(ans) + '\n\n\n' diff --git a/kittens/tui/operations_stub.py b/kittens/tui/operations_stub.py index 70860a37a..73404afd3 100644 --- a/kittens/tui/operations_stub.py +++ b/kittens/tui/operations_stub.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal diff --git a/kittens/tui/path_completer.py b/kittens/tui/path_completer.py index 969bc6f87..3291fbc57 100644 --- a/kittens/tui/path_completer.py +++ b/kittens/tui/path_completer.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal diff --git a/kittens/tui/progress.py b/kittens/tui/progress.py index 73ff724a2..8162124d0 100644 --- a/kittens/tui/progress.py +++ b/kittens/tui/progress.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2021, Kovid Goyal diff --git a/kittens/tui/spinners.py b/kittens/tui/spinners.py index 81fab576e..5c70f628d 100644 --- a/kittens/tui/spinners.py +++ b/kittens/tui/spinners.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2021, Kovid Goyal from time import monotonic diff --git a/kittens/tui/utils.py b/kittens/tui/utils.py index fe5fb57a8..15ed4efa2 100644 --- a/kittens/tui/utils.py +++ b/kittens/tui/utils.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal import sys diff --git a/kittens/unicode_input/main.py b/kittens/unicode_input/main.py index 233784d6b..2167c05f6 100644 --- a/kittens/unicode_input/main.py +++ b/kittens/unicode_input/main.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2018, Kovid Goyal import os import string @@ -110,7 +109,7 @@ def serialize_favorites(favorites: Iterable[int]) -> str: '''.splitlines() for cp in favorites: - ans.append('{:x} # {} {}'.format(cp, chr(cp), name(cp))) + ans.append(f'{cp:x} # {chr(cp)} {name(cp)}') return '\n'.join(ans) @@ -381,7 +380,7 @@ class UnicodeInput(Handler): def draw_title_bar(self) -> None: entries = [] for name, key, mode in all_modes: - entry = ' {} ({}) '.format(name, key) + entry = f' {name} ({key}) ' if mode is self.mode: entry = styled(entry, reverse=False, bold=True) entries.append(entry) diff --git a/kitty/actions.py b/kitty/actions.py index f4cc58b84..780ca35c6 100644 --- a/kitty/actions.py +++ b/kitty/actions.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2021, Kovid Goyal import inspect diff --git a/kitty/borders.py b/kitty/borders.py index c379a1ae8..bc6b6487c 100644 --- a/kitty/borders.py +++ b/kitty/borders.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2016, Kovid Goyal from enum import IntFlag diff --git a/kitty/boss.py b/kitty/boss.py index b600e63cd..6e56288ee 100755 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2016, Kovid Goyal import atexit @@ -899,8 +898,8 @@ class Boss: if w is None: return overlay_window = self._run_kitten('resize_window', args=[ - '--horizontal-increment={}'.format(get_options().window_resize_step_cells), - '--vertical-increment={}'.format(get_options().window_resize_step_lines) + f'--horizontal-increment={get_options().window_resize_step_cells}', + f'--vertical-increment={get_options().window_resize_step_lines}' ]) if overlay_window is not None: overlay_window.allow_remote_control = True @@ -1178,7 +1177,7 @@ class Boss: q = type_of_input.split('-') data = w.last_cmd_output(as_ansi='ansi' in q, add_wrap_markers='screen' in q).encode('utf-8') else: - raise ValueError('Unknown type_of_input: {}'.format(type_of_input)) + raise ValueError(f'Unknown type_of_input: {type_of_input}') else: data = input_data if isinstance(input_data, bytes) else input_data.encode('utf-8') copts = common_opts_as_dict(get_options()) @@ -1766,12 +1765,12 @@ class Boss: assert update_check_process.stdout is not None raw = update_check_process.stdout.read().decode('utf-8') except Exception as e: - log_error('Failed to read data from update check process, with error: {}'.format(e)) + log_error(f'Failed to read data from update check process, with error: {e}') else: try: process_current_release(raw) except Exception as e: - log_error('Failed to process update check data {!r}, with error: {}'.format(raw, e)) + log_error(f'Failed to process update check data {raw!r}, with error: {e}') def dbus_notification_callback(self, activated: bool, a: int, b: Union[int, str]) -> None: from .notify import ( @@ -1787,7 +1786,7 @@ class Boss: def show_bad_config_lines(self, bad_lines: Iterable[BadLine]) -> None: def format_bad_line(bad_line: BadLine) -> str: - return '{}:{} in line: {}\n'.format(bad_line.number, bad_line.exception, bad_line.line) + return f'{bad_line.number}:{bad_line.exception} in line: {bad_line.line}\n' msg = '\n'.join(map(format_bad_line, bad_lines)).rstrip() self.show_error(_('Errors in kitty.conf'), msg) diff --git a/kitty/child.py b/kitty/child.py index cb6b7fad7..17afc79f3 100644 --- a/kitty/child.py +++ b/kitty/child.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2016, Kovid Goyal import fcntl @@ -41,15 +40,15 @@ if is_macos: else: def cmdline_of_process(pid: int) -> List[str]: - with open('/proc/{}/cmdline'.format(pid), 'rb') as f: + with open(f'/proc/{pid}/cmdline', 'rb') as f: return list(filter(None, f.read().decode('utf-8').split('\0'))) def cwd_of_process(pid: int) -> str: - ans = '/proc/{}/cwd'.format(pid) + ans = f'/proc/{pid}/cwd' return os.path.realpath(ans) def _environ_of_process(pid: int) -> str: - with open('/proc/{}/environ'.format(pid), 'rb') as f: + with open(f'/proc/{pid}/environ', 'rb') as f: return f.read().decode('utf-8') def process_group_map() -> DefaultDict[int, List[int]]: diff --git a/kitty/choose_entry.py b/kitty/choose_entry.py index 2e9d0e6aa..c575461a3 100644 --- a/kitty/choose_entry.py +++ b/kitty/choose_entry.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2019, Kovid Goyal import re diff --git a/kitty/cli.py b/kitty/cli.py index ab5f2d1b5..e8a33de19 100644 --- a/kitty/cli.py +++ b/kitty/cli.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2017, Kovid Goyal import re @@ -53,7 +52,7 @@ defaults for all users. def surround(x: str, start: int, end: int) -> str: if sys.stdout.isatty(): - x = '\033[{}m{}\033[{}m'.format(start, x, end) + x = f'\033[{start}m{x}\033[{end}m' return x @@ -185,7 +184,7 @@ def parse_option_spec(spec: Optional[str] = None) -> Tuple[OptionSpecSeq, Option } state = METADATA continue - raise ValueError('Invalid option spec, unexpected line: {}'.format(line)) + raise ValueError(f'Invalid option spec, unexpected line: {line}') elif state is METADATA: m = mpat.match(line) if m is None: @@ -243,7 +242,7 @@ def version(add_rev: bool = False) -> str: rev = '' from . import fast_data_types if add_rev and hasattr(fast_data_types, 'KITTY_VCS_REV'): - rev = ' ({})'.format(fast_data_types.KITTY_VCS_REV[:10]) + rev = f' ({fast_data_types.KITTY_VCS_REV[:10]})' return '{} {}{} created by {}'.format(italic(appname), green(str_version), rev, title('Kovid Goyal')) @@ -334,7 +333,7 @@ class PrintHelpForSeq: a('{}:'.format(title('Options'))) for opt in seq: if isinstance(opt, str): - a('{}:'.format(title(opt))) + a(f'{title(opt)}:') continue help_text = opt['help'] if help_text == '!': @@ -347,7 +346,7 @@ class PrintHelpForSeq: t = help_text.replace('%default', str(defval)) wa(prettify(t.strip()), indent=4) if defval is not None: - wa('Default: {}'.format(defval), indent=4) + wa(f'Default: {defval}', indent=4) if opt.get('choices'): wa('Choices: {}'.format(', '.join(opt['choices'])), indent=4) a('') @@ -384,7 +383,7 @@ def seq_as_rst( a('.. highlight:: sh') a('.. code-block:: sh') a('') - a(' {} {}{}'.format(appname, optstring, usage)) + a(f' {appname} {optstring}{usage}') a('') message = message or default_msg a(prettify_rst(message)) @@ -412,7 +411,7 @@ def seq_as_rst( a('') a(textwrap.indent(prettify_rst(t), ' ' * 4)) if defval is not None: - a(textwrap.indent('Default: :code:`{}`'.format(defval), ' ' * 4)) + a(textwrap.indent(f'Default: :code:`{defval}`', ' ' * 4)) if opt.get('choices'): a(textwrap.indent('Choices: :code:`{}`'.format(', '.join(sorted(opt['choices']))), ' ' * 4)) a('') @@ -423,7 +422,7 @@ def seq_as_rst( def as_type_stub(seq: OptionSpecSeq, disabled: OptionSpecSeq, class_name: str, extra_fields: Sequence[str] = ()) -> str: from itertools import chain - ans: List[str] = ['class {}:'.format(class_name)] + ans: List[str] = [f'class {class_name}:'] for opt in chain(seq, disabled): if isinstance(opt, str): continue @@ -443,10 +442,10 @@ def as_type_stub(seq: OptionSpecSeq, disabled: OptionSpecSeq, class_name: str, e elif otype.startswith('bool-'): t = 'bool' else: - raise ValueError('Unknown CLI option type: {}'.format(otype)) - ans.append(' {}: {}'.format(name, t)) + raise ValueError(f'Unknown CLI option type: {otype}') + ans.append(f' {name}: {t}') for x in extra_fields: - ans.append(' {}'.format(x)) + ans.append(f' {x}') return '\n'.join(ans) + '\n\n\n' @@ -485,7 +484,7 @@ class Options: def opt_for_alias(self, alias: str) -> OptionDict: opt = self.alias_map.get(alias) if opt is None: - raise SystemExit('Unknown option: {}'.format(emph(alias))) + raise SystemExit(f'Unknown option: {emph(alias)}') return opt def needs_arg(self, alias: str) -> bool: @@ -546,7 +545,7 @@ def parse_cmdline(oc: Options, disabled: OptionSpecSeq, ans: Any, args: Optional needs_arg = oc.needs_arg(parts[0]) if not needs_arg: if len(parts) != 1: - raise SystemExit('The {} option does not accept arguments'.format(emph(parts[0]))) + raise SystemExit(f'The {emph(parts[0])} option does not accept arguments') oc.process_arg(parts[0]) continue if len(parts) == 1: @@ -561,7 +560,7 @@ def parse_cmdline(oc: Options, disabled: OptionSpecSeq, ans: Any, args: Optional oc.process_arg(current_option, arg) current_option, state = None, NORMAL if state is EXPECTING_ARG: - raise SystemExit('An argument is required for the option: {}'.format(emph(arg))) + raise SystemExit(f'An argument is required for the option: {emph(arg)}') for key, val in oc.values_map.items(): setattr(ans, key, val) diff --git a/kitty/cli_stub.py b/kitty/cli_stub.py index a792b5de2..e207ef5c6 100644 --- a/kitty/cli_stub.py +++ b/kitty/cli_stub.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal diff --git a/kitty/client.py b/kitty/client.py index c0c51ffc5..ab727b681 100644 --- a/kitty/client.py +++ b/kitty/client.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2016, Kovid Goyal # Replay the log from --dump-commands. To use first run @@ -43,7 +42,7 @@ def screen_alternate_keypad_mode() -> None: def screen_cursor_position(y: int, x: int) -> None: - write(CSI + '%s;%sH' % (y, x)) + write(CSI + f'{y};{x}H') def screen_cursor_forward(amt: int) -> None: diff --git a/kitty/complete.py b/kitty/complete.py index 07efe32c1..f37025002 100644 --- a/kitty/complete.py +++ b/kitty/complete.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2018, Kovid Goyal import os @@ -294,7 +293,7 @@ def bash_output_serializer(ans: Completions) -> str: for word in matches: if matches.trailing_space: word += ' ' - lines.append('COMPREPLY+=({})'.format(shlex.quote(word))) + lines.append(f'COMPREPLY+=({shlex.quote(word)})') # debug('\n'.join(lines)) return '\n'.join(lines) @@ -685,7 +684,7 @@ def main(args: Sequence[str], entry_points: Iterable[str], namespaced_entry_poin parser = parsers[cstyle] serializer = serializers[cstyle] except KeyError: - raise SystemExit('Unknown completion style: {}'.format(cstyle)) + raise SystemExit(f'Unknown completion style: {cstyle}') words, new_word = parser(data) ans = find_completions(words, new_word, entry_points, namespaced_entry_points) print(serializer(ans), end='') diff --git a/kitty/conf/generate.py b/kitty/conf/generate.py index 1737fae91..7fb602ea9 100644 --- a/kitty/conf/generate.py +++ b/kitty/conf/generate.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2021, Kovid Goyal @@ -105,7 +104,7 @@ def generate_class(defn: Definition, loc: str) -> Tuple[str, str]: t(f' ans[{option.name!r}] = {func.__name__}(val)') tc_imports.add((func.__module__, func.__name__)) cnum = int(option.name[5:]) - color_table[cnum] = '0x{:06x}'.format(func(option.defval_as_string).__int__()) + color_table[cnum] = f'0x{func(option.defval_as_string).__int__():06x}' continue else: func, typ = option_type_data(option) @@ -331,7 +330,7 @@ def generate_class(defn: Definition, loc: str) -> Tuple[str, str]: t(' return True') t(' return False') - preamble = ['# generated by gen-config.py DO NOT edit', '# vim:fileencoding=utf-8', ''] + preamble = ['# generated by gen-config.py DO NOT edit', ''] a = preamble.append def output_imports(imports: Set, add_module_imports: bool = True) -> None: @@ -368,7 +367,7 @@ def generate_class(defn: Definition, loc: str) -> Tuple[str, str]: a(' ' + pprint.pformat(tuple(sorted(option_names, key=natural_keys)))[1:] + ' # }}''}') class_def = '\n'.join(preamble + ['', ''] + class_lines) - preamble = ['# generated by gen-config.py DO NOT edit', '# vim:fileencoding=utf-8', ''] + preamble = ['# generated by gen-config.py DO NOT edit', ''] a = preamble.append output_imports(tc_imports, False) diff --git a/kitty/conf/types.py b/kitty/conf/types.py index 93825e810..1bf697446 100644 --- a/kitty/conf/types.py +++ b/kitty/conf/types.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2021, Kovid Goyal import builtins @@ -35,7 +34,7 @@ def expand_opt_references(conf_name: str, text: str) -> str: ref = m.group(1) if '<' not in ref and '.' not in ref: full_ref = conf_name + ref - return ':opt:`{} <{}>`'.format(ref, full_ref) + return f':opt:`{ref} <{full_ref}>`' return str(m.group()) return re.sub(r':opt:`(.+?)`', expand, text) diff --git a/kitty/conf/utils.py b/kitty/conf/utils.py index a2c59c8a6..7d22c62ac 100644 --- a/kitty/conf/utils.py +++ b/kitty/conf/utils.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2018, Kovid Goyal import os @@ -130,7 +129,7 @@ def parse_line( return m = key_pat.match(line) if m is None: - log_error('Ignoring invalid config line: {}'.format(line)) + log_error(f'Ignoring invalid config line: {line}') return key, val = m.groups() if key == 'include': @@ -152,7 +151,7 @@ def parse_line( ) return if not parse_conf_item(key, val, ans): - log_error('Ignoring unknown config key: {}'.format(key)) + log_error(f'Ignoring unknown config key: {key}') def _parse( @@ -199,8 +198,7 @@ def resolve_config(SYSTEM_CONF: str, defconf: str, config_files_on_cmd_line: Seq if config_files_on_cmd_line: if 'NONE' not in config_files_on_cmd_line: yield SYSTEM_CONF - for cf in config_files_on_cmd_line: - yield cf + yield from config_files_on_cmd_line else: yield SYSTEM_CONF yield defconf @@ -240,7 +238,7 @@ def key_func() -> Tuple[Callable[..., Callable], Dict[str, Callable]]: for name in names: if ans.setdefault(name, f) is not f: raise ValueError( - 'the args_func {} is being redefined'.format(name) + f'the args_func {name} is being redefined' ) return f @@ -277,7 +275,7 @@ def parse_kittens_func_args(action: str, args_funcs: Dict[str, Callable]) -> Key try: func, args = parser(func, rest) except Exception: - raise ValueError('Unknown key action: {}'.format(action)) + raise ValueError(f'Unknown key action: {action}') if not isinstance(args, (list, tuple)): args = (args, ) diff --git a/kitty/config.py b/kitty/config.py index af81904bb..b1978777c 100644 --- a/kitty/config.py +++ b/kitty/config.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2016, Kovid Goyal import json diff --git a/kitty/constants.py b/kitty/constants.py index 06174dcf4..bd3cc1c22 100644 --- a/kitty/constants.py +++ b/kitty/constants.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2016, Kovid Goyal import errno @@ -89,7 +88,7 @@ def _get_config_dir() -> str: try: os.makedirs(ans, exist_ok=True) except FileExistsError: - raise SystemExit('A file {} already exists. It must be a directory, not a file.'.format(ans)) + raise SystemExit(f'A file {ans} already exists. It must be a directory, not a file.') except PermissionError: make_tmp_conf() except OSError as err: diff --git a/kitty/debug_config.py b/kitty/debug_config.py index dee927fdd..68f3a4ad0 100644 --- a/kitty/debug_config.py +++ b/kitty/debug_config.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2021, Kovid Goyal import os @@ -128,7 +127,7 @@ def compare_opts(opts: KittyOpts, print: Callable) -> None: if f not in ignored and getattr(opts, f) != getattr(defaults, f) ] field_len = max(map(len, changed_opts)) if changed_opts else 20 - fmt = '{{:{:d}s}}'.format(field_len) + fmt = f'{{:{field_len:d}s}}' colors = [] for f in changed_opts: val = getattr(opts, f) diff --git a/kitty/file_transmission.py b/kitty/file_transmission.py index dcfd8abd5..ed1ac7345 100644 --- a/kitty/file_transmission.py +++ b/kitty/file_transmission.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2021, Kovid Goyal import errno diff --git a/kitty/fonts/box_drawing.py b/kitty/fonts/box_drawing.py index 9d9a0fffe..5c41f12da 100644 --- a/kitty/fonts/box_drawing.py +++ b/kitty/fonts/box_drawing.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2017, Kovid Goyal # @@ -372,7 +371,7 @@ def get_bezier_limits(bezier_x: ParameterizedFunc, bezier_y: ParameterizedFunc) if q > x: increment /= 2 if increment < 1e-6: - raise ValueError('Failed to find t for x={}'.format(x)) + raise ValueError(f'Failed to find t for x={x}') else: start_t += increment increment = t_limit - start_t @@ -1096,7 +1095,7 @@ def test_drawing(sz: int = 48, family: str = 'monospace', start: int = 0x2500, n rgb_data = b''.join(rows) width *= 32 height *= len(rows) - assert len(rgb_data) == width * height * 4, '{} != {}'.format(len(rgb_data), width * height * 4) + assert len(rgb_data) == width * height * 4, f'{len(rgb_data)} != {width * height * 4}' display_bitmap(rgb_data, width, height) finally: set_send_sprite_to_gpu(None) diff --git a/kitty/fonts/core_text.py b/kitty/fonts/core_text.py index f671bca42..b656ae341 100644 --- a/kitty/fonts/core_text.py +++ b/kitty/fonts/core_text.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2017, Kovid Goyal import re @@ -82,7 +81,7 @@ def find_best_match(family: str, bold: bool = False, italic: bool = False, ignor # Let CoreText choose the font if the family exists, otherwise # fallback to Menlo if q not in font_map['family_map']: - log_error('The font {} was not found, falling back to Menlo'.format(family)) + log_error(f'The font {family} was not found, falling back to Menlo') q = 'menlo' candidates = font_map['family_map'][q] return sorted(candidates, key=score)[-1] diff --git a/kitty/fonts/fontconfig.py b/kitty/fonts/fontconfig.py index de927a42a..763f8d333 100644 --- a/kitty/fonts/fontconfig.py +++ b/kitty/fonts/fontconfig.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2016, Kovid Goyal import re @@ -84,7 +83,7 @@ def find_font_features(postscript_name: str) -> Tuple[FontFeature, ...]: try: parsed = parse_font_feature(feat) except ValueError: - log_error('Ignoring invalid font feature: {}'.format(feat)) + log_error(f'Ignoring invalid font feature: {feat}') else: features.append(FontFeature(feat, parsed)) diff --git a/kitty/fonts/list.py b/kitty/fonts/list.py index 34c336284..7cbc65209 100644 --- a/kitty/fonts/list.py +++ b/kitty/fonts/list.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2017, Kovid Goyal import sys diff --git a/kitty/fonts/render.py b/kitty/fonts/render.py index 4cc6ef88f..a77cc8dde 100644 --- a/kitty/fonts/render.py +++ b/kitty/fonts/render.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2016, Kovid Goyal import ctypes diff --git a/kitty/guess_mime_type.py b/kitty/guess_mime_type.py index 048036d29..cc03e8b6c 100644 --- a/kitty/guess_mime_type.py +++ b/kitty/guess_mime_type.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal import os diff --git a/kitty/key_encoding.py b/kitty/key_encoding.py index e186ac3df..61f0dfbce 100644 --- a/kitty/key_encoding.py +++ b/kitty/key_encoding.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2017, Kovid Goyal from enum import IntEnum diff --git a/kitty/key_names.py b/kitty/key_names.py index ff69bfc10..35e639193 100644 --- a/kitty/key_names.py +++ b/kitty/key_names.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2019, Kovid Goyal import sys diff --git a/kitty/keys.py b/kitty/keys.py index 0493e8946..9cb485a45 100644 --- a/kitty/keys.py +++ b/kitty/keys.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2016, Kovid Goyal from typing import Optional, Union diff --git a/kitty/launch.py b/kitty/launch.py index 8ab1baeef..0fc4f299d 100644 --- a/kitty/launch.py +++ b/kitty/launch.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2019, Kovid Goyal diff --git a/kitty/layout/base.py b/kitty/layout/base.py index 2ca8d1e72..585e975e7 100644 --- a/kitty/layout/base.py +++ b/kitty/layout/base.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal from functools import partial diff --git a/kitty/layout/grid.py b/kitty/layout/grid.py index cadc25c63..1827d017d 100644 --- a/kitty/layout/grid.py +++ b/kitty/layout/grid.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal from functools import lru_cache diff --git a/kitty/layout/interface.py b/kitty/layout/interface.py index a8e33f712..f7a6e670c 100644 --- a/kitty/layout/interface.py +++ b/kitty/layout/interface.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal from typing import Dict, Tuple, Type diff --git a/kitty/layout/splits.py b/kitty/layout/splits.py index 2dbc89f7f..b5e0b327d 100644 --- a/kitty/layout/splits.py +++ b/kitty/layout/splits.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal from typing import ( @@ -324,7 +323,7 @@ class Pair: return 'top', 'bottom' return 'bottom', 'top' - geometries = dict((group.id, group.geometry) for group in all_windows.groups if group.geometry) + geometries = {group.id: group.geometry for group in all_windows.groups if group.geometry} def extend(other: Union[int, 'Pair', None], edge: EdgeLiteral, which: EdgeLiteral) -> None: if not ans[which] and other: diff --git a/kitty/layout/stack.py b/kitty/layout/stack.py index 9578ffe11..adce011fe 100644 --- a/kitty/layout/stack.py +++ b/kitty/layout/stack.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal from kitty.typing import WindowType diff --git a/kitty/layout/tall.py b/kitty/layout/tall.py index db991ac55..b15143d0e 100644 --- a/kitty/layout/tall.py +++ b/kitty/layout/tall.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal from itertools import islice, repeat diff --git a/kitty/layout/vertical.py b/kitty/layout/vertical.py index 70846120b..afd06ced4 100644 --- a/kitty/layout/vertical.py +++ b/kitty/layout/vertical.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal from typing import Any, Dict, Generator, Iterable, List, Tuple diff --git a/kitty/main.py b/kitty/main.py index 5915c1b9b..d7a19c6f7 100644 --- a/kitty/main.py +++ b/kitty/main.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2016, Kovid Goyal import locale @@ -50,7 +49,7 @@ def set_custom_ibeam_cursor() -> None: try: set_custom_cursor(GLFW_IBEAM_CURSOR, images, 4, 8) except Exception as e: - log_error('Failed to set custom beam cursor with error: {}'.format(e)) + log_error(f'Failed to set custom beam cursor with error: {e}') def talk_to_instance(args: CLIOptions) -> None: @@ -61,7 +60,7 @@ def talk_to_instance(args: CLIOptions) -> None: 'cwd': os.getcwd()} notify_socket = None if args.wait_for_single_instance_window_close: - address = '\0{}-os-window-close-notify-{}-{}'.format(appname, os.getpid(), os.geteuid()) + address = f'\0{appname}-os-window-close-notify-{os.getpid()}-{os.geteuid()}' notify_socket = socket.socket(family=socket.AF_UNIX) try: notify_socket.bind(address) diff --git a/kitty/marks.py b/kitty/marks.py index adcc0d1ca..b06d0b2c6 100644 --- a/kitty/marks.py +++ b/kitty/marks.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal import os @@ -45,8 +44,8 @@ def marker_from_multiple_regex(regexes: Iterable[Tuple[int, str]], flags: int = expr = '' color_map = {} for i, (color, spec) in enumerate(regexes): - grp = 'mcg{}'.format(i) - expr += '|(?P<{}>{})'.format(grp, spec) + grp = f'mcg{i}' + expr += f'|(?P<{grp}>{spec})' color_map[grp] = color expr = expr[1:] pat = re.compile(expr, flags=flags) @@ -92,4 +91,4 @@ def marker_from_spec(ftype: str, spec: Union[str, Sequence[Tuple[int, str]]], fl if not os.path.isabs(path): path = os.path.join(config_dir, path) return marker_from_function(runpy.run_path(path, run_name='__marker__')["marker"]) - raise ValueError('Unknown marker type: {}'.format(ftype)) + raise ValueError(f'Unknown marker type: {ftype}') diff --git a/kitty/multiprocessing.py b/kitty/multiprocessing.py index 2f222c7ac..f0717ab9a 100644 --- a/kitty/multiprocessing.py +++ b/kitty/multiprocessing.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal # Monkeypatch the stdlib multiprocessing module to work with the embedded python diff --git a/kitty/notify.py b/kitty/notify.py index 2ff48b6ee..935df40f6 100644 --- a/kitty/notify.py +++ b/kitty/notify.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2019, Kovid Goyal from base64 import standard_b64decode diff --git a/kitty/open_actions.py b/kitty/open_actions.py index eb398b0f0..c79601c1a 100644 --- a/kitty/open_actions.py +++ b/kitty/open_actions.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal diff --git a/kitty/options/definition.py b/kitty/options/definition.py index 25753bd96..cf4a02f2c 100644 --- a/kitty/options/definition.py +++ b/kitty/options/definition.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2021, Kovid Goyal # After editing this file run ./gen-config.py to apply the changes diff --git a/kitty/options/parse.py b/kitty/options/parse.py index 83484fbbd..49d22eeeb 100644 --- a/kitty/options/parse.py +++ b/kitty/options/parse.py @@ -1,5 +1,4 @@ # generated by gen-config.py DO NOT edit -# vim:fileencoding=utf-8 import typing from kitty.conf.utils import ( diff --git a/kitty/options/types.py b/kitty/options/types.py index 0d659dd72..d3999d85f 100644 --- a/kitty/options/types.py +++ b/kitty/options/types.py @@ -1,5 +1,4 @@ # generated by gen-config.py DO NOT edit -# vim:fileencoding=utf-8 import typing from array import array diff --git a/kitty/options/utils.py b/kitty/options/utils.py index 3da32f184..03d9e93fe 100644 --- a/kitty/options/utils.py +++ b/kitty/options/utils.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2021, Kovid Goyal @@ -104,7 +103,7 @@ def goto_tab_parse(func: str, rest: str) -> FuncArgsType: @func_with_args('detach_window') def detach_window_parse(func: str, rest: str) -> FuncArgsType: if rest not in ('new', 'new-tab', 'ask', 'tab-prev', 'tab-left', 'tab-right'): - log_error('Ignoring invalid detach_window argument: {}'.format(rest)) + log_error(f'Ignoring invalid detach_window argument: {rest}') rest = 'new' return func, (rest,) @@ -112,7 +111,7 @@ def detach_window_parse(func: str, rest: str) -> FuncArgsType: @func_with_args('detach_tab') def detach_tab_parse(func: str, rest: str) -> FuncArgsType: if rest not in ('new', 'ask'): - log_error('Ignoring invalid detach_tab argument: {}'.format(rest)) + log_error(f'Ignoring invalid detach_tab argument: {rest}') rest = 'new' return func, (rest,) @@ -145,7 +144,7 @@ def signal_child_parse(func: str, rest: str) -> FuncArgsType: def parse_change_font_size(func: str, rest: str) -> Tuple[str, Tuple[bool, Optional[str], float]]: vals = rest.strip().split(maxsplit=1) if len(vals) != 2: - log_error('Invalid change_font_size specification: {}, treating it as default'.format(rest)) + log_error(f'Invalid change_font_size specification: {rest}, treating it as default') return func, (True, None, 0) c_all = vals[0].lower() == 'all' sign: Optional[str] = None @@ -182,7 +181,7 @@ def neighboring_window(func: str, rest: str) -> FuncArgsType: rest = rest.lower() rest = {'up': 'top', 'down': 'bottom'}.get(rest, rest) if rest not in ('left', 'right', 'top', 'bottom'): - log_error('Invalid neighbor specification: {}'.format(rest)) + log_error(f'Invalid neighbor specification: {rest}') rest = 'right' return func, [rest] @@ -196,14 +195,14 @@ def resize_window(func: str, rest: str) -> FuncArgsType: else: quality = vals[0].lower() if quality not in ('taller', 'shorter', 'wider', 'narrower'): - log_error('Invalid quality specification: {}'.format(quality)) + log_error(f'Invalid quality specification: {quality}') quality = 'wider' increment = 1 if len(vals) == 2: try: increment = int(vals[1]) except Exception: - log_error('Invalid increment specification: {}'.format(vals[1])) + log_error(f'Invalid increment specification: {vals[1]}') args = [quality, increment] return func, args @@ -217,7 +216,7 @@ def move_window(func: str, rest: str) -> FuncArgsType: prest = int(prest) except Exception: if prest not in ('left', 'right', 'top', 'bottom'): - log_error('Invalid move_window specification: {}'.format(rest)) + log_error(f'Invalid move_window specification: {rest}') prest = 0 return func, [prest] @@ -269,9 +268,9 @@ def disable_ligatures_in(func: str, rest: str) -> FuncArgsType: else: where, strategy = parts if where not in ('active', 'all', 'tab'): - raise ValueError('{} is not a valid set of windows to disable ligatures in'.format(where)) + raise ValueError(f'{where} is not a valid set of windows to disable ligatures in') if strategy not in ('never', 'always', 'cursor'): - raise ValueError('{} is not a valid disable ligatures strategy'.format(strategy)) + raise ValueError(f'{strategy} is not a valid disable ligatures strategy') return func, [where, strategy] @@ -295,7 +294,7 @@ def parse_marker_spec(ftype: str, parts: Sequence[str]) -> Tuple[str, Union[str, try: color = max(1, min(int(parts[i]), 3)) except Exception: - raise ValueError('color {} in marker specification is not an integer'.format(parts[i])) + raise ValueError(f'color {parts[i]} in marker specification is not an integer') sspec = parts[i + 1] if 'regex' not in ftype: sspec = re.escape(sspec) @@ -305,7 +304,7 @@ def parse_marker_spec(ftype: str, parts: Sequence[str]) -> Tuple[str, Union[str, elif ftype == 'function': spec = ' '.join(parts) else: - raise ValueError('Unknown marker type: {}'.format(ftype)) + raise ValueError(f'Unknown marker type: {ftype}') return ftype, spec, flags @@ -314,7 +313,7 @@ def toggle_marker(func: str, rest: str) -> FuncArgsType: import shlex parts = rest.split(maxsplit=1) if len(parts) != 2: - raise ValueError('{} is not a valid marker specification'.format(rest)) + raise ValueError(f'{rest} is not a valid marker specification') ftype, spec = parts parts = shlex.split(spec) return func, list(parse_marker_spec(ftype, parts)) @@ -332,7 +331,7 @@ def scroll_to_mark(func: str, rest: str) -> FuncArgsType: try: return func, [True, max(0, min(int(q), 3))] except Exception: - raise ValueError('{} is not a valid scroll_to_mark destination'.format(rest)) + raise ValueError(f'{rest} is not a valid scroll_to_mark destination') return func, [parts[0] != 'next', max(0, min(int(parts[1]), 3))] @@ -371,7 +370,7 @@ def parse_mods(parts: Iterable[str], sc: str) -> Optional[int]: mods |= getattr(defines, 'GLFW_MOD_' + map_mod(m.upper())) except AttributeError: if m.upper() != 'NONE': - log_error('Shortcut: {} has unknown modifier, ignoring'.format(sc)) + log_error(f'Shortcut: {sc} has unknown modifier, ignoring') return None return mods @@ -493,9 +492,9 @@ def url_style(x: str) -> int: return url_style_map.get(x, url_style_map['curly']) -url_style_map = dict( - ((v, i) for i, v in enumerate('none single double curly'.split())) -) +url_style_map = { + v: i for i, v in enumerate('none single double curly'.split()) +} def url_prefixes(x: str) -> Tuple[str, ...]: @@ -528,13 +527,13 @@ def parse_layout_names(parts: Iterable[str]) -> List[str]: continue name = p.partition(':')[0] if name not in all_layouts: - raise ValueError('The window layout {} is unknown'.format(p)) + raise ValueError(f'The window layout {p} is unknown') ans.append(p) return uniq(ans) def to_layout_names(raw: str) -> List[str]: - return parse_layout_names((x.strip() for x in raw.split(','))) + return parse_layout_names(x.strip() for x in raw.split(',')) def window_border_width(x: Union[str, int, float]) -> Tuple[float, str]: @@ -721,7 +720,7 @@ def font_features(val: str) -> Iterable[Tuple[str, Tuple[FontFeature, ...]]]: return parts = val.split() if len(parts) < 2: - log_error("Ignoring invalid font_features {}".format(val)) + log_error(f"Ignoring invalid font_features {val}") return if parts[0]: features = [] @@ -729,7 +728,7 @@ def font_features(val: str) -> Iterable[Tuple[str, Tuple[FontFeature, ...]]]: try: parsed = defines.parse_font_feature(feat) except ValueError: - log_error('Ignoring invalid font feature: {}'.format(feat)) + log_error(f'Ignoring invalid font feature: {feat}') else: features.append(FontFeature(feat, parsed)) yield parts[0], tuple(features) @@ -886,7 +885,7 @@ def parse_map(val: str) -> Iterable[KeyDefinition]: return if key == 0: if mods is not None: - log_error('Shortcut: {} has unknown key, ignoring'.format(sc)) + log_error(f'Shortcut: {sc} has unknown key, ignoring') return if trigger is None: trigger = SingleKey(mods, is_native, key) @@ -900,7 +899,7 @@ def parse_map(val: str) -> Iterable[KeyDefinition]: return if key == 0: if mods is not None: - log_error('Shortcut: {} has unknown key, ignoring'.format(sc)) + log_error(f'Shortcut: {sc} has unknown key, ignoring') return try: paction = parse_key_action(action) @@ -961,7 +960,7 @@ def parse_mouse_map(val: str) -> Iterable[MouseMapping]: def deprecated_hide_window_decorations_aliases(key: str, val: str, ans: Dict[str, Any]) -> None: if not hasattr(deprecated_hide_window_decorations_aliases, key): setattr(deprecated_hide_window_decorations_aliases, key, True) - log_error('The option {} is deprecated. Use hide_window_decorations instead.'.format(key)) + log_error(f'The option {key} is deprecated. Use hide_window_decorations instead.') if to_bool(val): if is_macos and key == 'macos_hide_titlebar' or (not is_macos and key == 'x11_hide_window_decorations'): ans['hide_window_decorations'] = True @@ -970,7 +969,7 @@ def deprecated_hide_window_decorations_aliases(key: str, val: str, ans: Dict[str def deprecated_macos_show_window_title_in_menubar_alias(key: str, val: str, ans: Dict[str, Any]) -> None: if not hasattr(deprecated_macos_show_window_title_in_menubar_alias, key): setattr(deprecated_macos_show_window_title_in_menubar_alias, 'key', True) - log_error('The option {} is deprecated. Use macos_show_window_title_in menubar instead.'.format(key)) + log_error(f'The option {key} is deprecated. Use macos_show_window_title_in menubar instead.') macos_show_window_title_in = ans.get('macos_show_window_title_in', 'all') if to_bool(val): if macos_show_window_title_in == 'none': @@ -996,6 +995,6 @@ def deprecated_send_text(key: str, val: str, ans: Dict[str, Any]) -> None: return abort('Incomplete') mode, sc = parts[:2] text = ' '.join(parts[2:]) - key_str = '{} send_text {} {}'.format(sc, mode, text) + key_str = f'{sc} send_text {mode} {text}' for k in parse_map(key_str): ans['map'].append(k) diff --git a/kitty/os_window_size.py b/kitty/os_window_size.py index cdf7b892b..c7b48d676 100644 --- a/kitty/os_window_size.py +++ b/kitty/os_window_size.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal from typing import Any, Callable, Dict, NamedTuple, Tuple diff --git a/kitty/rc/base.py b/kitty/rc/base.py index dd463e002..1e74ecdeb 100644 --- a/kitty/rc/base.py +++ b/kitty/rc/base.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal from contextlib import suppress @@ -37,7 +36,7 @@ class MatchError(ValueError): hide_traceback = True def __init__(self, expression: str, target: str = 'windows'): - ValueError.__init__(self, 'No matching {} for expression: {}'.format(target, expression)) + ValueError.__init__(self, f'No matching {target} for expression: {expression}') class OpacityError(ValueError): @@ -199,15 +198,15 @@ class RemoteCommand: def cli_params_for(command: RemoteCommand) -> Tuple[Callable[[], str], str, str, str]: - return (command.options_spec or '\n').format, command.argspec, command.desc, '{} @ {}'.format(appname, command.name) + return (command.options_spec or '\n').format, command.argspec, command.desc, f'{appname} @ {command.name}' def parse_subcommand_cli(command: RemoteCommand, args: ArgsType) -> Tuple[Any, ArgsType]: opts, items = parse_args(args[1:], *cli_params_for(command), result_class=command.options_class) if command.args_count is not None and command.args_count != len(items): if command.args_count == 0: - raise SystemExit('Unknown extra argument(s) supplied to {}'.format(command.name)) - raise SystemExit('Must specify exactly {} argument(s) for {}'.format(command.args_count, command.name)) + raise SystemExit(f'Unknown extra argument(s) supplied to {command.name}') + raise SystemExit(f'Must specify exactly {command.args_count} argument(s) for {command.name}') return opts, items diff --git a/kitty/rc/close_tab.py b/kitty/rc/close_tab.py index ebf1fdc31..aaba33333 100644 --- a/kitty/rc/close_tab.py +++ b/kitty/rc/close_tab.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal diff --git a/kitty/rc/close_window.py b/kitty/rc/close_window.py index b34a82eec..eccab8c84 100644 --- a/kitty/rc/close_window.py +++ b/kitty/rc/close_window.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal diff --git a/kitty/rc/create_marker.py b/kitty/rc/create_marker.py index 41ba80ecd..c2e91e894 100644 --- a/kitty/rc/create_marker.py +++ b/kitty/rc/create_marker.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal from typing import TYPE_CHECKING, Optional diff --git a/kitty/rc/detach_tab.py b/kitty/rc/detach_tab.py index c3168c647..06dbb05cf 100644 --- a/kitty/rc/detach_tab.py +++ b/kitty/rc/detach_tab.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal from typing import TYPE_CHECKING, Optional diff --git a/kitty/rc/detach_window.py b/kitty/rc/detach_window.py index 80a0b309f..6e1dc8d39 100644 --- a/kitty/rc/detach_window.py +++ b/kitty/rc/detach_window.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal from typing import TYPE_CHECKING, Optional, Union diff --git a/kitty/rc/disable_ligatures.py b/kitty/rc/disable_ligatures.py index 0d1c86eb2..7e6520c68 100644 --- a/kitty/rc/disable_ligatures.py +++ b/kitty/rc/disable_ligatures.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal diff --git a/kitty/rc/env.py b/kitty/rc/env.py index 336f9d6e1..4e7bb972c 100644 --- a/kitty/rc/env.py +++ b/kitty/rc/env.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal from typing import Any, Optional diff --git a/kitty/rc/focus_tab.py b/kitty/rc/focus_tab.py index 6f8fd7f18..1d6394f5d 100644 --- a/kitty/rc/focus_tab.py +++ b/kitty/rc/focus_tab.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal diff --git a/kitty/rc/focus_window.py b/kitty/rc/focus_window.py index 49e35b9ae..f6374585c 100644 --- a/kitty/rc/focus_window.py +++ b/kitty/rc/focus_window.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal diff --git a/kitty/rc/get_colors.py b/kitty/rc/get_colors.py index cd7c913f3..4e36270f3 100644 --- a/kitty/rc/get_colors.py +++ b/kitty/rc/get_colors.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal from typing import TYPE_CHECKING, Optional diff --git a/kitty/rc/get_text.py b/kitty/rc/get_text.py index e64b10e7c..06182ad51 100644 --- a/kitty/rc/get_text.py +++ b/kitty/rc/get_text.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal diff --git a/kitty/rc/goto_layout.py b/kitty/rc/goto_layout.py index 1d49d9dfa..772325a15 100644 --- a/kitty/rc/goto_layout.py +++ b/kitty/rc/goto_layout.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal from typing import TYPE_CHECKING, Optional, Iterable diff --git a/kitty/rc/kitten.py b/kitty/rc/kitten.py index 468cd98a4..d3ce80e26 100644 --- a/kitty/rc/kitten.py +++ b/kitty/rc/kitten.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal from typing import TYPE_CHECKING, Optional diff --git a/kitty/rc/last_used_layout.py b/kitty/rc/last_used_layout.py index 90598b9b2..ab9697689 100644 --- a/kitty/rc/last_used_layout.py +++ b/kitty/rc/last_used_layout.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal diff --git a/kitty/rc/launch.py b/kitty/rc/launch.py index eb290c8bb..69dca3cac 100644 --- a/kitty/rc/launch.py +++ b/kitty/rc/launch.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal diff --git a/kitty/rc/ls.py b/kitty/rc/ls.py index 75fd19321..8ede5d0c4 100644 --- a/kitty/rc/ls.py +++ b/kitty/rc/ls.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal import json diff --git a/kitty/rc/new_window.py b/kitty/rc/new_window.py index 455e4fc6e..05a92b631 100644 --- a/kitty/rc/new_window.py +++ b/kitty/rc/new_window.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal from typing import TYPE_CHECKING, Optional diff --git a/kitty/rc/remove_marker.py b/kitty/rc/remove_marker.py index 719876408..0d61f4277 100644 --- a/kitty/rc/remove_marker.py +++ b/kitty/rc/remove_marker.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal diff --git a/kitty/rc/resize_os_window.py b/kitty/rc/resize_os_window.py index 30592928d..8a00ffc79 100644 --- a/kitty/rc/resize_os_window.py +++ b/kitty/rc/resize_os_window.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal from typing import TYPE_CHECKING, Optional diff --git a/kitty/rc/resize_window.py b/kitty/rc/resize_window.py index 51ab1d2db..f80fb2820 100644 --- a/kitty/rc/resize_window.py +++ b/kitty/rc/resize_window.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal from typing import TYPE_CHECKING, Optional, Union diff --git a/kitty/rc/scroll_window.py b/kitty/rc/scroll_window.py index 9aefd705c..b9d6582d2 100644 --- a/kitty/rc/scroll_window.py +++ b/kitty/rc/scroll_window.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal @@ -67,7 +66,7 @@ class ScrollWindow(RemoteCommand): else: unit = 'page' if unit == 'p' else 'line' direction = 'up' if amt < 0 else 'down' - func = getattr(window, 'scroll_{}_{}'.format(unit, direction)) + func = getattr(window, f'scroll_{unit}_{direction}') for i in range(abs(amt)): func() diff --git a/kitty/rc/send_text.py b/kitty/rc/send_text.py index ae389a833..5fe1b3b5b 100644 --- a/kitty/rc/send_text.py +++ b/kitty/rc/send_text.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal import base64 diff --git a/kitty/rc/set_background_image.py b/kitty/rc/set_background_image.py index 54fdf4d60..f2c263e5c 100644 --- a/kitty/rc/set_background_image.py +++ b/kitty/rc/set_background_image.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal import imghdr diff --git a/kitty/rc/set_background_opacity.py b/kitty/rc/set_background_opacity.py index 26aac864d..263354fc0 100644 --- a/kitty/rc/set_background_opacity.py +++ b/kitty/rc/set_background_opacity.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal diff --git a/kitty/rc/set_colors.py b/kitty/rc/set_colors.py index d7a93ab3a..b3043850b 100644 --- a/kitty/rc/set_colors.py +++ b/kitty/rc/set_colors.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal diff --git a/kitty/rc/set_enabled_layouts.py b/kitty/rc/set_enabled_layouts.py index a2c2a45e0..498785e31 100644 --- a/kitty/rc/set_enabled_layouts.py +++ b/kitty/rc/set_enabled_layouts.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal from typing import TYPE_CHECKING, Iterable, List, Optional diff --git a/kitty/rc/set_font_size.py b/kitty/rc/set_font_size.py index cc10ae304..80ff26166 100644 --- a/kitty/rc/set_font_size.py +++ b/kitty/rc/set_font_size.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal from typing import TYPE_CHECKING, Optional diff --git a/kitty/rc/set_spacing.py b/kitty/rc/set_spacing.py index 2956b6f2e..f77fe0f68 100644 --- a/kitty/rc/set_spacing.py +++ b/kitty/rc/set_spacing.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal diff --git a/kitty/rc/set_tab_color.py b/kitty/rc/set_tab_color.py index 7ce432688..6a1ff9d41 100644 --- a/kitty/rc/set_tab_color.py +++ b/kitty/rc/set_tab_color.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal diff --git a/kitty/rc/set_tab_title.py b/kitty/rc/set_tab_title.py index 3959770e0..29c8b7b6a 100644 --- a/kitty/rc/set_tab_title.py +++ b/kitty/rc/set_tab_title.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal diff --git a/kitty/rc/set_window_title.py b/kitty/rc/set_window_title.py index 0846b4345..55a5919c8 100644 --- a/kitty/rc/set_window_title.py +++ b/kitty/rc/set_window_title.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal from typing import TYPE_CHECKING, Optional diff --git a/kitty/rc/signal_child.py b/kitty/rc/signal_child.py index b19cf2719..d09eec805 100644 --- a/kitty/rc/signal_child.py +++ b/kitty/rc/signal_child.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal from typing import TYPE_CHECKING, Optional diff --git a/kitty/remote_control.py b/kitty/remote_control.py index f91b4a44d..f15fe0401 100644 --- a/kitty/remote_control.py +++ b/kitty/remote_control.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2018, Kovid Goyal import json @@ -146,12 +145,12 @@ cli_msg = ( def parse_rc_args(args: List[str]) -> Tuple[RCOptions, List[str]]: cmap = {name: command_for_name(name) for name in sorted(all_command_names())} - cmds = (' :green:`{}`\n {}'.format(cmd.name, cmd.short_desc) for c, cmd in cmap.items()) + cmds = (f' :green:`{cmd.name}`\n {cmd.short_desc}' for c, cmd in cmap.items()) msg = cli_msg + ( '\n\n:title:`Commands`:\n{cmds}\n\n' 'You can get help for each individual command by using:\n' '{appname} @ :italic:`command` -h').format(appname=appname, cmds='\n'.join(cmds)) - return parse_args(args[1:], global_options_spec, 'command ...', msg, '{} @'.format(appname), result_class=RCOptions) + return parse_args(args[1:], global_options_spec, 'command ...', msg, f'{appname} @', result_class=RCOptions) def create_basic_command(name: str, payload: Any = None, no_response: bool = False) -> Dict[str, Any]: diff --git a/kitty/rgb.py b/kitty/rgb.py index 778d1a72c..c06ebbbac 100644 --- a/kitty/rgb.py +++ b/kitty/rgb.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2017, Kovid Goyal import re @@ -99,7 +98,7 @@ def to_color(raw: str, validate: bool = False) -> Optional[Color]: elif raw[:4].lower() == 'rgb:': val = parse_rgb(raw[4:]) if val is None and validate: - raise ValueError('Invalid color name: {}'.format(raw)) + raise ValueError(f'Invalid color name: {raw}') return val diff --git a/kitty/session.py b/kitty/session.py index 840910bc4..9e5377b33 100644 --- a/kitty/session.py +++ b/kitty/session.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2016, Kovid Goyal import shlex @@ -56,7 +55,7 @@ class Session: def set_layout(self, val: str) -> None: if val.partition(':')[0] not in all_layouts: - raise ValueError('{} is not a valid layout'.format(val)) + raise ValueError(f'{val} is not a valid layout') self.tabs[-1].layout = val def add_window(self, cmd: Union[None, str, List[str]]) -> None: @@ -131,7 +130,7 @@ def parse_session(raw: str, opts: Options) -> Generator[Session, None, None]: elif cmd == 'os_window_class': ans.os_window_class = rest else: - raise ValueError('Unknown command in session file: {}'.format(cmd)) + raise ValueError(f'Unknown command in session file: {cmd}') yield finalize_session(ans) @@ -168,7 +167,7 @@ def create_sessions( with open(default_session) as f: session_data = f.read() except OSError: - log_error('Failed to read from session file, ignoring: {}'.format(default_session)) + log_error(f'Failed to read from session file, ignoring: {default_session}') else: yield from parse_session(session_data, opts) return diff --git a/kitty/shell.py b/kitty/shell.py index 4e6d6b907..35bf8c58e 100644 --- a/kitty/shell.py +++ b/kitty/shell.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2018, Kovid Goyal import os @@ -134,7 +133,7 @@ def print_help(which: Optional[str] = None) -> None: elif which == 'help': print('Show help') else: - print('Unknown command: {}'.format(emph(which))) + print(f'Unknown command: {emph(which)}') return display_subcommand_help(func) @@ -169,7 +168,7 @@ def real_main(global_opts: RCOptions) -> None: print('Use {} for assistance or {} to quit'.format(green('help'), green('exit'))) awid = os.environ.pop('KITTY_SHELL_ACTIVE_WINDOW_ID', None) if awid is not None: - print('The ID of the previously active window is: {}'.format(awid)) + print(f'The ID of the previously active window is: {awid}') pre_prompt = set_window_title('The kitty shell') + set_cursor_shape('bar') pre_prompt += '\x1b]133;A;does_not_redraw_prompts\x1b\\' @@ -200,7 +199,7 @@ def real_main(global_opts: RCOptions) -> None: if cmd == 'help': print_help(cmdline[1] if len(cmdline) > 1 else None) continue - print_err('"{}" is an unknown command. Use "help" to see a list of commands.'.format(emph(cmd))) + print_err(f'"{emph(cmd)}" is an unknown command. Use "help" to see a list of commands.') continue try: diff --git a/kitty/shell_integration.py b/kitty/shell_integration.py index a241c66f5..0a24ed253 100644 --- a/kitty/shell_integration.py +++ b/kitty/shell_integration.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2021, Kovid Goyal diff --git a/kitty/short_uuid.py b/kitty/short_uuid.py index b1e32044e..6015d4702 100644 --- a/kitty/short_uuid.py +++ b/kitty/short_uuid.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2021, Kovid Goyal import math diff --git a/kitty/tab_bar.py b/kitty/tab_bar.py index 1197bd765..6446d7b06 100644 --- a/kitty/tab_bar.py +++ b/kitty/tab_bar.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2018, Kovid Goyal import os @@ -79,7 +78,7 @@ def as_rgb(x: int) -> int: @lru_cache() def report_template_failure(template: str, e: str) -> None: - log_error('Invalid tab title template: "{}" with error: {}'.format(template, e)) + log_error(f'Invalid tab title template: "{template}" with error: {e}') @lru_cache() diff --git a/kitty/tabs.py b/kitty/tabs.py index 61e54cae2..e18a4a8cc 100644 --- a/kitty/tabs.py +++ b/kitty/tabs.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2016, Kovid Goyal import os @@ -94,7 +93,7 @@ class Tab: # {{{ self.os_window_id: int = tab_manager.os_window_id self.id: int = add_tab(self.os_window_id) if not self.id: - raise Exception('No OS window with id {} found, or tab counter has wrapped'.format(self.os_window_id)) + raise Exception(f'No OS window with id {self.os_window_id} found, or tab counter has wrapped') self.args = tab_manager.args self.name = getattr(session_tab, 'name', '') self.enabled_layouts = [x.lower() for x in getattr(session_tab, 'enabled_layouts', None) or get_options().enabled_layouts] @@ -270,7 +269,7 @@ class Tab: # {{{ if layout_name not in self.enabled_layouts: if raise_exception: raise ValueError(layout_name) - log_error('Unknown or disabled layout: {}'.format(layout_name)) + log_error(f'Unknown or disabled layout: {layout_name}') return self._set_current_layout(layout_name) self.relayout() @@ -639,7 +638,7 @@ class Tab: # {{{ self.windows = WindowList(self) def __repr__(self) -> str: - return 'Tab(title={}, id={})'.format(self.name or self.title, hex(id(self))) + return f'Tab(title={self.name or self.title}, id={hex(id(self))})' def make_active(self) -> None: tm = self.tab_manager_ref() diff --git a/kitty/terminfo.py b/kitty/terminfo.py index 1fdc56951..c487a8524 100644 --- a/kitty/terminfo.py +++ b/kitty/terminfo.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2016, Kovid Goyal import re @@ -19,7 +18,7 @@ def modify_key_bytes(keybytes: bytes, amt: int) -> bytes: return bytes(ans[:-1] + bytearray(b';' + samt + b'~')) if ans[1] == ord('O'): return bytes(ans[:1] + bytearray(b'[1;' + samt) + ans[-1:]) - raise ValueError('Unknown key type in key: {!r}'.format(keybytes)) + raise ValueError(f'Unknown key type in key: {keybytes!r}') def encode_keystring(keybytes: bytes) -> str: @@ -285,7 +284,7 @@ string_capabilities = { } string_capabilities.update({ - 'kf{}'.format(offset + n): + f'kf{offset + n}': encode_keystring(modify_key_bytes(b'\033' + value, mod)) for offset, mod in {0: 0, 12: 2, 24: 5, 36: 6, 48: 3, 60: 4}.items() for n, value in zip(range(1, 13), @@ -427,7 +426,7 @@ termcap_aliases.update({ }) termcap_aliases.update({ - tc: 'kf{}'.format(n) + tc: f'kf{n}' for n, tc in enumerate( 'k1 k2 k3 k4 k5 k6 k7 k8 k9 k; F1 F2 F3 F4 F5 F6 F7 F8 F9 FA ' 'FB FC FD FE FF FG FH FI FJ FK FL FM FN FO FP FQ FR FS FT FU ' @@ -439,11 +438,11 @@ queryable_capabilities.update(string_capabilities) extra = (bool_capabilities | numeric_capabilities.keys() | string_capabilities.keys()) - set(termcap_aliases.values()) no_termcap_for = frozenset( 'Su Smulx Sync Tc setrgbf setrgbb fullkbd kUP kDN kbeg kBEG'.split() + [ - 'k{}{}'.format(key, mod) + f'k{key}{mod}' for key in 'UP DN RIT LFT BEG END HOM IC DC PRV NXT'.split() for mod in range(3, 8)]) if extra - no_termcap_for: - raise Exception('Termcap aliases not complete, missing: {}'.format(extra - no_termcap_for)) + raise Exception(f'Termcap aliases not complete, missing: {extra - no_termcap_for}') del extra @@ -451,8 +450,8 @@ def generate_terminfo() -> str: # Use ./build-terminfo to update definition files ans = ['|'.join(names)] ans.extend(sorted(bool_capabilities)) - ans.extend('{}#{}'.format(k, numeric_capabilities[k]) for k in sorted(numeric_capabilities)) - ans.extend('{}={}'.format(k, string_capabilities[k]) for k in sorted(string_capabilities)) + ans.extend(f'{k}#{numeric_capabilities[k]}' for k in sorted(numeric_capabilities)) + ans.extend(f'{k}={string_capabilities[k]}' for k in sorted(string_capabilities)) return ',\n\t'.join(ans) + ',\n' diff --git a/kitty/types.py b/kitty/types.py index bdd3c636a..d863cec57 100644 --- a/kitty/types.py +++ b/kitty/types.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2021, Kovid Goyal from functools import update_wrapper diff --git a/kitty/typing.py b/kitty/typing.py index 48fb9b3da..68b3b59e4 100644 --- a/kitty/typing.py +++ b/kitty/typing.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal from typing import Tuple diff --git a/kitty/update_check.py b/kitty/update_check.py index ba2e62e5f..0bf6c4626 100644 --- a/kitty/update_check.py +++ b/kitty/update_check.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2019, Kovid Goyal import os @@ -118,7 +117,7 @@ def update_check() -> bool: 'from kitty.update_check import run_worker; run_worker()' ], stdout=subprocess.PIPE) except OSError as e: - log_error('Failed to run kitty for update check, with error: {}'.format(e)) + log_error(f'Failed to run kitty for update check, with error: {e}') return False monitor_pid(p.pid) get_boss().set_update_check_process(p) diff --git a/kitty/utils.py b/kitty/utils.py index caa047ede..bac1ee331 100644 --- a/kitty/utils.py +++ b/kitty/utils.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2016, Kovid Goyal import atexit @@ -381,9 +380,9 @@ class SingleInstance: def __call__(self, group_id: Optional[str] = None) -> bool: import socket - name = '{}-ipc-{}'.format(appname, os.geteuid()) + name = f'{appname}-ipc-{os.geteuid()}' if group_id: - name += '-{}'.format(group_id) + name += f'-{group_id}' s = socket.socket(family=socket.AF_UNIX) # First try with abstract UDS @@ -425,7 +424,7 @@ def parse_address_spec(spec: str) -> Tuple[AddressFamily, Union[Tuple[str, int], host, port = rest.rsplit(':', 1) address = host, int(port) else: - raise ValueError('Unknown protocol in --listen-on value: {}'.format(spec)) + raise ValueError(f'Unknown protocol in --listen-on value: {spec}') return family, address, socket_path diff --git a/kitty/window.py b/kitty/window.py index 75807953d..4e256a67f 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2016, Kovid Goyal import json @@ -233,7 +232,7 @@ class LoadShaderPrograms: 'MARK_SHIFT': MARK, 'MARK_MASK': MARK_MASK, }.items(): - vv = vv.replace('{{{}}}'.format(gln), str(pyn), 1) + vv = vv.replace(f'{{{gln}}}', str(pyn), 1) if semi_transparent: vv = vv.replace('#define NOT_TRANSPARENT', '#define TRANSPARENT') ff = ff.replace('#define NOT_TRANSPARENT', '#define TRANSPARENT') @@ -377,7 +376,7 @@ class Window: self.margin = EdgeWidths() self.padding = EdgeWidths() if not self.id: - raise Exception('No tab with id: {} in OS Window: {} was found, or the window counter wrapped'.format(tab.id, tab.os_window_id)) + raise Exception(f'No tab with id: {tab.id} in OS Window: {tab.os_window_id} was found, or the window counter wrapped') self.tab_id = tab.id self.os_window_id = tab.os_window_id self.tabref: Callable[[], Optional[TabType]] = weakref.ref(tab) @@ -778,7 +777,7 @@ class Window: r |= r << 8 g |= g << 8 b |= b << 8 - self.screen.send_escape_code_to_child(OSC, '{};rgb:{:04x}/{:04x}/{:04x}'.format(code, r, g, b)) + self.screen.send_escape_code_to_child(OSC, f'{code};rgb:{r:04x}/{g:04x}/{b:04x}') def report_notification_activated(self, identifier: str) -> None: self.screen.send_escape_code_to_child(OSC, f'99;i={identifier};') @@ -806,7 +805,7 @@ class Window: changed = False for c, val in parse_color_set(value): if val is None: # color query - self.report_color('4;{}'.format(c), *self.screen.color_profile.as_color((c << 8) | 1)) + self.report_color(f'4;{c}', *self.screen.color_profile.as_color((c << 8) | 1)) else: changed = True cp.set_color(c, val) diff --git a/kitty/window_list.py b/kitty/window_list.py index 523d1f044..fc67c681f 100644 --- a/kitty/window_list.py +++ b/kitty/window_list.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal import weakref diff --git a/kitty_tests/__init__.py b/kitty_tests/__init__.py index ccfcda37b..ddbc96613 100644 --- a/kitty_tests/__init__.py +++ b/kitty_tests/__init__.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2016, Kovid Goyal import os @@ -83,7 +82,7 @@ def filled_line_buf(ynum=5, xnum=5, cursor=Cursor()): ans = LineBuf(ynum, xnum) cursor.x = 0 for i in range(ynum): - t = ('{}'.format(i)) * xnum + t = (f'{i}') * xnum ans.line(i).set_text(t, 0, xnum, cursor) return ans diff --git a/kitty_tests/bench_scrollback.py b/kitty_tests/bench_scrollback.py index d0ded77bf..5130b7eea 100755 --- a/kitty_tests/bench_scrollback.py +++ b/kitty_tests/bench_scrollback.py @@ -28,7 +28,7 @@ def main(): characters += ['\x1b[91m', '\x1b[0m', '\x1b[1;32m', '\x1b[22m', '\x1b[35m'] if args.unicode: - characters += [u'日', u'本', u'💜', u'☃', u'🎩', u'🍀', u'、'] + characters += ['日', '本', '💜', '☃', '🎩', '🍀', '、'] patterns = [] for _ in range(0, args.patterns): diff --git a/kitty_tests/check_build.py b/kitty_tests/check_build.py index 0f7ee54e5..1e338c244 100644 --- a/kitty_tests/check_build.py +++ b/kitty_tests/check_build.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2021, Kovid Goyal diff --git a/kitty_tests/choose.py b/kitty_tests/choose.py index 6aeda01db..cbb0e7de0 100644 --- a/kitty_tests/choose.py +++ b/kitty_tests/choose.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2019, Kovid Goyal import random diff --git a/kitty_tests/datatypes.py b/kitty_tests/datatypes.py index bde84a233..99fd7b984 100644 --- a/kitty_tests/datatypes.py +++ b/kitty_tests/datatypes.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2016, Kovid Goyal import os @@ -423,7 +422,7 @@ class TestDataTypes(BaseTest): c = ColorProfile() c.update_ansi_color_table(build_ansi_color_table()) for i in range(8): - col = getattr(defaults, 'color{}'.format(i)) + col = getattr(defaults, f'color{i}') self.assertEqual(c.as_color(i << 8 | 1), (col[0], col[1], col[2])) self.ae(c.as_color(255 << 8 | 1), (0xee, 0xee, 0xee)) diff --git a/kitty_tests/diff.py b/kitty_tests/diff.py index 84184a4e3..37bee2e00 100644 --- a/kitty_tests/diff.py +++ b/kitty_tests/diff.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2018, Kovid Goyal @@ -37,9 +36,9 @@ class TestDiff(BaseTest): self.ae(expected, tuple(split_with_highlights(line, width, [], seg))) def h(s, e, w): - ans = Segment(s, 'S{}S'.format(w)) + ans = Segment(s, f'S{w}S') ans.end = e - ans.end_code = 'E{}E'.format(w) + ans.end_code = f'E{w}E' return ans highlights = [h(0, 1, 1), h(1, 3, 2)] diff --git a/kitty_tests/file_transmission.py b/kitty_tests/file_transmission.py index f0ceb8aac..25f089d9c 100644 --- a/kitty_tests/file_transmission.py +++ b/kitty_tests/file_transmission.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2021, Kovid Goyal diff --git a/kitty_tests/fonts.py b/kitty_tests/fonts.py index c7afb12a0..d30b7c6b3 100644 --- a/kitty_tests/fonts.py +++ b/kitty_tests/fonts.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2017, Kovid Goyal import os diff --git a/kitty_tests/glfw.py b/kitty_tests/glfw.py index 2c2a87f5c..d0e292071 100644 --- a/kitty_tests/glfw.py +++ b/kitty_tests/glfw.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2020, Kovid Goyal import sys diff --git a/kitty_tests/gr.py b/kitty_tests/gr.py index ceb984abd..77be9d277 100755 --- a/kitty_tests/gr.py +++ b/kitty_tests/gr.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2017, Kovid Goyal import os @@ -16,11 +15,11 @@ def clear_screen(): def move_cursor(x, y): - write('\033[{};{}H'.format(y, x).encode('ascii')) + write(f'\033[{y};{x}H'.encode('ascii')) def write_gr_cmd(cmd, payload): - cmd = ','.join('{}={}'.format(k, v) for k, v in cmd.items()) + cmd = ','.join(f'{k}={v}' for k, v in cmd.items()) w = write w(b'\033_G'), w(cmd.encode('ascii')), w(b';'), w(payload), w(b'\033\\') sys.stdout.flush() diff --git a/kitty_tests/graphics.py b/kitty_tests/graphics.py index 3c4e644db..19cdaa821 100644 --- a/kitty_tests/graphics.py +++ b/kitty_tests/graphics.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2016, Kovid Goyal import os @@ -95,7 +94,7 @@ def load_helpers(self): def pl(payload, **kw): kw.setdefault('i', 1) - cmd = ','.join('%s=%s' % (k, v) for k, v in kw.items()) + cmd = ','.join(f'{k}={v}' for k, v in kw.items()) res = send_command(s, cmd, payload) return parse_response(res) @@ -176,7 +175,7 @@ def make_send_command(screen): if i: kw['i'] = i kw['a'] = a - cmd = ','.join('%s=%s' % (k, v) for k, v in kw.items()) + cmd = ','.join(f'{k}={v}' for k, v in kw.items()) res = send_command(screen, cmd, payload) return parse_full_response(res) return li @@ -435,7 +434,7 @@ class TestGraphics(BaseTest): self.assertEqual(g.disk_cache.total_size, 0) def li(payload, **kw): - cmd = ','.join('%s=%s' % (k, v) for k, v in kw.items()) + cmd = ','.join(f'{k}={v}' for k, v in kw.items()) res = send_command(s, cmd, payload) return parse_response_with_ids(res) @@ -470,7 +469,7 @@ class TestGraphics(BaseTest): # test put with number def put(**kw): - cmd = ','.join('%s=%s' % (k, v) for k, v in kw.items()) + cmd = ','.join(f'{k}={v}' for k, v in kw.items()) cmd = 'a=p,' + cmd return parse_response_with_ids(send_command(s, cmd)) @@ -483,9 +482,9 @@ class TestGraphics(BaseTest): def delete(ac='N', **kw): cmd = 'a=d' if ac: - cmd += ',d={}'.format(ac) + cmd += f',d={ac}' if kw: - cmd += ',' + ','.join('{}={}'.format(k, v) for k, v in kw.items()) + cmd += ',' + ','.join(f'{k}={v}' for k, v in kw.items()) send_command(s, cmd) count = s.grman.image_count @@ -599,9 +598,9 @@ class TestGraphics(BaseTest): def delete(ac=None, **kw): cmd = 'a=d' if ac: - cmd += ',d={}'.format(ac) + cmd += f',d={ac}' if kw: - cmd += ',' + ','.join('{}={}'.format(k, v) for k, v in kw.items()) + cmd += ',' + ','.join(f'{k}={v}' for k, v in kw.items()) send_command(s, cmd) put_image(s, cw, ch) diff --git a/kitty_tests/hints.py b/kitty_tests/hints.py index 64d003a58..d116ce125 100644 --- a/kitty_tests/hints.py +++ b/kitty_tests/hints.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2018, Kovid Goyal @@ -24,12 +23,12 @@ class TestHints(BaseTest): u = 'http://test.me/' t(u, 'http://test.me/') - t('"{}"'.format(u), u) - t('({})'.format(u), u) + t(f'"{u}"', u) + t(f'({u})', u) t(u + '\nxxx', u + 'xxx', len(u)) - t('link:{}[xxx]'.format(u), u) - t('`xyz <{}>`_.'.format(u), u) - t('moo'.format(u), u) + t(f'link:{u}[xxx]', u) + t(f'`xyz <{u}>`_.', u) + t(f'moo', u) def test_ip_hints(self): from kittens.hints.main import parse_hints_args, functions_for, mark, convert_text diff --git a/kitty_tests/keys.py b/kitty_tests/keys.py index 16d310089..a2b48ae7f 100644 --- a/kitty_tests/keys.py +++ b/kitty_tests/keys.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2016, Kovid Goyal from functools import partial diff --git a/kitty_tests/layout.py b/kitty_tests/layout.py index 6de3a1e65..63972c22d 100644 --- a/kitty_tests/layout.py +++ b/kitty_tests/layout.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2018, Kovid Goyal from kitty.config import defaults diff --git a/kitty_tests/main.py b/kitty_tests/main.py index 35d000a6e..a0c71df25 100644 --- a/kitty_tests/main.py +++ b/kitty_tests/main.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2021, Kovid Goyal import importlib diff --git a/kitty_tests/mouse.py b/kitty_tests/mouse.py index d866d5488..36c74bc8e 100644 --- a/kitty_tests/mouse.py +++ b/kitty_tests/mouse.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2016, Kovid Goyal from functools import partial @@ -77,7 +76,7 @@ class TestMouse(BaseTest): ev(x=x, y=y, button=button) if q is not None: s = sel() - self.ae(s, q, '{!r} != {!r} after movement to x={} y={}'.format(s, q, x, y)) + self.ae(s, q, f'{s!r} != {q!r} after movement to x={x} y={y}') def multi_click(x=0, y=0, count=2): clear_click_queue = True diff --git a/kitty_tests/open_actions.py b/kitty_tests/open_actions.py index cb8b5aa17..37c32421d 100644 --- a/kitty_tests/open_actions.py +++ b/kitty_tests/open_actions.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2018, Kovid Goyal diff --git a/kitty_tests/options.py b/kitty_tests/options.py index d7d35f78f..a1db02e58 100644 --- a/kitty_tests/options.py +++ b/kitty_tests/options.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2018, Kovid Goyal diff --git a/kitty_tests/parser.py b/kitty_tests/parser.py index 8f8c3de87..da47bc6fe 100644 --- a/kitty_tests/parser.py +++ b/kitty_tests/parser.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2016, Kovid Goyal import time @@ -126,7 +125,7 @@ class TestParser(BaseTest): s.reset() def sgr(params): - return (('select_graphic_rendition', '{} '.format(x)) for x in params.split()) + return (('select_graphic_rendition', f'{x} ') for x in params.split()) pb('\033[1;2;3;4;7;9;34;44m', *sgr('1 2 3 4 7 9 34 44')) for attr in 'bold italic reverse strikethrough dim'.split(): @@ -313,7 +312,7 @@ class TestParser(BaseTest): c = s.callbacks pb = partial(self.parse_bytes_dump, s) q = hexlify(b'kind').decode('ascii') - pb('a\033P+q{}\x9cbcde'.format(q), 'a', ('screen_request_capabilities', 43, q), 'bcde') + pb(f'a\033P+q{q}\x9cbcde', 'a', ('screen_request_capabilities', 43, q), 'bcde') self.ae(str(s.line(0)), 'abcde') self.ae(c.wtcbuf, '1+r{}={}'.format(q, '1b5b313b3242').encode('ascii')) c.clear() @@ -325,12 +324,12 @@ class TestParser(BaseTest): for sgr in '0;34;102;1;2;3;4 0;38:5:200;58:2:10:11:12'.split(): expected = set(sgr.split(';')) - {'0'} c.clear() - parse_bytes(s, '\033[{}m\033P$qm\033\\'.format(sgr).encode('ascii')) + parse_bytes(s, f'\033[{sgr}m\033P$qm\033\\'.encode('ascii')) r = c.wtcbuf.decode('ascii').partition('r')[2].partition('m')[0] self.ae(expected, set(r.split(';'))) c.clear() pb('\033P$qr\033\\', ('screen_request_capabilities', ord('$'), 'r')) - self.ae(c.wtcbuf, '\033P1$r{};{}r\033\\'.format(s.margin_top + 1, s.margin_bottom + 1).encode('ascii')) + self.ae(c.wtcbuf, f'\033P1$r{s.margin_top + 1};{s.margin_bottom + 1}r\033\\'.encode('ascii')) def test_sc81t(self): s = self.create_screen() @@ -396,10 +395,10 @@ class TestParser(BaseTest): pb = partial(self.parse_bytes_dump, s) for prefix in '\033_', '\u009f': for suffix in '\u009c', '\033\\': - pb('a{}+\\++{}bcde'.format(prefix, suffix), ('draw', 'a'), ('Unrecognized APC code: 0x2b',), ('draw', 'bcde')) + pb(f'a{prefix}+\\++{suffix}bcde', ('draw', 'a'), ('Unrecognized APC code: 0x2b',), ('draw', 'bcde')) for prefix in '\033^', '\u009e': for suffix in '\u009c', '\033\\': - pb('a{}+\\++{}bcde'.format(prefix, suffix), ('draw', 'a'), ('Unrecognized PM code: 0x2b',), ('draw', 'bcde')) + pb(f'a{prefix}+\\++{suffix}bcde', ('draw', 'a'), ('Unrecognized PM code: 0x2b',), ('draw', 'bcde')) def test_graphics_command(self): from base64 import standard_b64encode @@ -424,7 +423,7 @@ class TestParser(BaseTest): pb('\033_G{};{}\033\\'.format(cmd, enc(kw.get('payload', ''))), c(**kw)) def e(cmd, err): - pb('\033_G{}\033\\'.format(cmd), (err,)) + pb(f'\033_G{cmd}\033\\', (err,)) s = self.create_screen() pb = partial(self.parse_bytes_dump, s) diff --git a/kitty_tests/screen.py b/kitty_tests/screen.py index fe84d64f6..ceea33227 100644 --- a/kitty_tests/screen.py +++ b/kitty_tests/screen.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2016, Kovid Goyal from kitty.fast_data_types import ( @@ -837,7 +836,7 @@ class TestScreen(BaseTest): return parse_bytes(s, f'\033[{code}{p}u'.encode('ascii')) def ac(flags): - parse_bytes(s, '\033[?u'.encode('ascii')) + parse_bytes(s, b'\033[?u') self.ae(c.wtcbuf, f'\033[?{flags}u'.encode('ascii')) c.clear() @@ -926,10 +925,10 @@ class TestScreen(BaseTest): s = self.create_screen() def mark_prompt(): - parse_bytes(s, '\033]133;A\007'.encode('ascii')) + parse_bytes(s, b'\033]133;A\007') def mark_output(): - parse_bytes(s, '\033]133;C\007'.encode('ascii')) + parse_bytes(s, b'\033]133;C\007') for i in range(4): mark_prompt() diff --git a/kitty_tests/ssh.py b/kitty_tests/ssh.py index 9c0886b7c..703b3b48f 100644 --- a/kitty_tests/ssh.py +++ b/kitty_tests/ssh.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2021, Kovid Goyal diff --git a/kitty_tests/tui.py b/kitty_tests/tui.py index 2a989deb6..6a73d11aa 100644 --- a/kitty_tests/tui.py +++ b/kitty_tests/tui.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2018, Kovid Goyal diff --git a/kitty_tests/unicode_input.py b/kitty_tests/unicode_input.py index e941ac4f8..ac360ffc2 100644 --- a/kitty_tests/unicode_input.py +++ b/kitty_tests/unicode_input.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2018, Kovid Goyal