Refactor: More f-string for kitty fonts and rc send_text
This commit is contained in:
parent
1ca1c2edad
commit
c21f00c476
@ -29,7 +29,7 @@ def create_font_map(all_fonts: Iterable[CoreTextFont]) -> FontMap:
|
|||||||
ps = (x['postscript_name'] or '').lower()
|
ps = (x['postscript_name'] or '').lower()
|
||||||
ans['family_map'].setdefault(f, []).append(x)
|
ans['family_map'].setdefault(f, []).append(x)
|
||||||
ans['ps_map'].setdefault(ps, []).append(x)
|
ans['ps_map'].setdefault(ps, []).append(x)
|
||||||
ans['full_map'].setdefault(f + ' ' + s, []).append(x)
|
ans['full_map'].setdefault(f'{f} {s}', []).append(x)
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ def list_fonts() -> Generator[ListedFont, None, None]:
|
|||||||
for fd in coretext_all_fonts():
|
for fd in coretext_all_fonts():
|
||||||
f = fd['family']
|
f = fd['family']
|
||||||
if f:
|
if f:
|
||||||
fn = (f + ' ' + (fd['style'] or '')).strip()
|
fn = f'{f} {fd.get("style", "")}'.strip()
|
||||||
is_mono = bool(fd['monospace'])
|
is_mono = bool(fd['monospace'])
|
||||||
yield {'family': f, 'full_name': fn, 'postscript_name': fd['postscript_name'] or '', 'is_monospace': is_mono}
|
yield {'family': f, 'full_name': fn, 'postscript_name': fd['postscript_name'] or '', 'is_monospace': is_mono}
|
||||||
|
|
||||||
|
|||||||
@ -58,7 +58,7 @@ def list_fonts() -> Generator[ListedFont, None, None]:
|
|||||||
if fn_:
|
if fn_:
|
||||||
fn = str(fn_)
|
fn = str(fn_)
|
||||||
else:
|
else:
|
||||||
fn = (f + ' ' + str(fd.get('style', ''))).strip()
|
fn = f'{f} {fd.get("style", "")}'.strip()
|
||||||
is_mono = fd.get('spacing') in ('MONO', 'DUAL')
|
is_mono = fd.get('spacing') in ('MONO', 'DUAL')
|
||||||
yield {'family': f, 'full_name': fn, 'postscript_name': str(fd.get('postscript_name', '')), 'is_monospace': is_mono}
|
yield {'family': f, 'full_name': fn, 'postscript_name': str(fd.get('postscript_name', '')), 'is_monospace': is_mono}
|
||||||
|
|
||||||
|
|||||||
@ -28,13 +28,13 @@ def main(argv: Sequence[str]) -> None:
|
|||||||
groups = create_family_groups()
|
groups = create_family_groups()
|
||||||
for k in sorted(groups, key=lambda x: x.lower()):
|
for k in sorted(groups, key=lambda x: x.lower()):
|
||||||
if isatty:
|
if isatty:
|
||||||
print('\033[1;32m' + k + '\033[m')
|
print(f'\033[1;32m{k}\033[m')
|
||||||
else:
|
else:
|
||||||
print(k)
|
print(k)
|
||||||
for f in sorted(groups[k], key=lambda x: x['full_name'].lower()):
|
for f in sorted(groups[k], key=lambda x: x['full_name'].lower()):
|
||||||
p = f['full_name']
|
p = f['full_name']
|
||||||
if isatty:
|
if isatty:
|
||||||
p = '\033[3m' + p + '\033[m'
|
p = f'\033[3m{p}\033[m'
|
||||||
if psnames:
|
if psnames:
|
||||||
p += ' ({})'.format(f['postscript_name'])
|
p += ' ({})'.format(f['postscript_name'])
|
||||||
print(' ', p)
|
print(' ', p)
|
||||||
|
|||||||
@ -515,7 +515,7 @@ def test_fallback_font(qtext: Optional[str] = None, bold: bool = False, italic:
|
|||||||
try:
|
try:
|
||||||
print(text, f)
|
print(text, f)
|
||||||
except UnicodeEncodeError:
|
except UnicodeEncodeError:
|
||||||
sys.stdout.buffer.write((text + ' %s\n' % f).encode('utf-8'))
|
sys.stdout.buffer.write(f'{text} {f}\n'.encode('utf-8'))
|
||||||
|
|
||||||
|
|
||||||
def showcase() -> None:
|
def showcase() -> None:
|
||||||
|
|||||||
@ -107,20 +107,20 @@ Do not send text to the active window, even if it is one of the matched windows.
|
|||||||
if '\x04' in decoded_data:
|
if '\x04' in decoded_data:
|
||||||
decoded_data = decoded_data[:decoded_data.index('\x04')]
|
decoded_data = decoded_data[:decoded_data.index('\x04')]
|
||||||
keep_going = False
|
keep_going = False
|
||||||
ret['data'] = 'text:' + decoded_data
|
ret['data'] = f'text:{decoded_data}'
|
||||||
yield ret
|
yield ret
|
||||||
else:
|
else:
|
||||||
while True:
|
while True:
|
||||||
data = sys.stdin.buffer.read(limit)
|
data = sys.stdin.buffer.read(limit)
|
||||||
if not data:
|
if not data:
|
||||||
break
|
break
|
||||||
ret['data'] = 'base64:' + base64.standard_b64encode(data).decode('ascii')
|
ret['data'] = f'base64:{base64.standard_b64encode(data).decode("ascii")}'
|
||||||
yield ret
|
yield ret
|
||||||
|
|
||||||
def chunks(text: str) -> CmdGenerator:
|
def chunks(text: str) -> CmdGenerator:
|
||||||
data = parse_send_text_bytes(text).decode('utf-8')
|
data = parse_send_text_bytes(text).decode('utf-8')
|
||||||
while data:
|
while data:
|
||||||
ret['data'] = 'text:' + data[:limit]
|
ret['data'] = f'text:{data[:limit]}'
|
||||||
yield ret
|
yield ret
|
||||||
data = data[limit:]
|
data = data[limit:]
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ Do not send text to the active window, even if it is one of the matched windows.
|
|||||||
data = f.read(limit)
|
data = f.read(limit)
|
||||||
if not data:
|
if not data:
|
||||||
break
|
break
|
||||||
ret['data'] = 'base64:' + base64.standard_b64encode(data).decode('ascii')
|
ret['data'] = f'base64:{base64.standard_b64encode(data).decode("ascii")}'
|
||||||
yield ret
|
yield ret
|
||||||
|
|
||||||
sources = []
|
sources = []
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user