1#!/usr/local/bin/python3.8 2# vim:fileencoding=utf-8 3# License: GPLv3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net> 4 5from typing import TYPE_CHECKING, Optional 6 7from .base import ( 8 ArgsType, Boss, PayloadGetType, PayloadType, RCOptions, RemoteCommand, 9 ResponseType, Window 10) 11 12if TYPE_CHECKING: 13 from kitty.cli_stub import SetFontSizeRCOptions as CLIOptions 14 15 16class SetFontSize(RemoteCommand): 17 ''' 18 size+: The new font size in pts (a positive number) 19 all: Boolean whether to change font size in the current window or all windows 20 increment_op: The string ``+`` or ``-`` to interpret size as an increment 21 ''' 22 23 short_desc = 'Set the font size in the active top-level OS window' 24 desc = ( 25 'Sets the font size to the specified size, in pts. Note' 26 ' that in kitty all sub-windows in the same OS window' 27 ' must have the same font size. A value of zero' 28 ' resets the font size to default. Prefixing the value' 29 ' with a + or - increments the font size by the specified' 30 ' amount.' 31 ) 32 argspec = 'FONT_SIZE' 33 args_count = 1 34 options_spec = '''\ 35--all -a 36type=bool-set 37By default, the font size is only changed in the active OS window, 38this option will cause it to be changed in all OS windows. It also changes 39the font size for any newly created OS Windows in the future. 40''' 41 42 def message_to_kitty(self, global_opts: RCOptions, opts: 'CLIOptions', args: ArgsType) -> PayloadType: 43 if not args: 44 self.fatal('No font size specified') 45 fs = args[0] 46 inc = fs[0] if fs and fs[0] in '+-' else None 47 return {'size': abs(float(fs)), 'all': opts.all, 'increment_op': inc} 48 49 def response_from_kitty(self, boss: Boss, window: Optional[Window], payload_get: PayloadGetType) -> ResponseType: 50 boss.change_font_size( 51 payload_get('all'), 52 payload_get('increment_op'), payload_get('size')) 53 54 55set_font_size = SetFontSize() 56