fix layout raw strings

This commit is contained in:
pegasko 2024-05-09 03:21:16 +03:00
parent 6f262652ff
commit 187e8e679a
2 changed files with 19 additions and 6 deletions

View file

@ -21,13 +21,14 @@ import typing
LANGSETS = {
'qwerty-en-ru': (
"""`1234567890-=qwertyuiop[]\asdfghjkl;'zxcvbnm,./~!@#$%^&*()_+QWERTYUIOP{}|ASDFGHJKL:"ZXCVBNM<>?""",
"""ё1234567890-=йцукенгшщзхъ\фывапролджэячсмитьбю.Ё!"№;%:?*()_+ЙЦУКЕНГШЩЗХЪ/ФЫВАПРОЛДЖЭЯЧСМИТЬБЮ,""",
r"""`1234567890-=qwertyuiop[]\asdfghjkl;'zxcvbnm,.~!@#$%^&*()_+QWERTYUIOP{}|ASDFGHJKL:"ZXCVBNM<>""",
r"""ё1234567890-=йцукенгшщзхъ\фывапролджэячсмитьбюЁ!"№;%:?*()_+ЙЦУКЕНГШЩЗХЪ/ФЫВАПРОЛДЖЭЯЧСМИТЬБЮ""",
),
}
def make_langset_dict(ls: typing.Tuple[str, str]) -> typing.Dict[str, str]:
def make_langset_dict(langset: str) -> typing.Dict[str, str]:
ls = LANGSETS[langset]
flipper = {}
for (a, b) in zip(*ls):
flipper[a] = b
@ -45,16 +46,24 @@ def do_x11(args: argparse.Namespace):
result.check_returncode()
clip = result.stdout
if clip.strip() == '':
if args.verbose:
print(f'clipboard is empty')
return
if args.verbose:
print(f'clipboard: "{ clip }"')
# Clear selection
result = subprocess.run([ 'xclip', '-i', '-selection', 'primary' ], text=True, input='')
result.check_returncode()
# Do convert
conv = make_langset_dict(LANGSETS[args.langset])
conv = make_langset_dict(args.langset)
converted = flip_langset(clip, conv)
if args.verbose:
print(f'converted: "{ converted }"')
# Write selection
result = subprocess.run([ 'xclip', '-i', '-selection', 'clipboard' ], text=True, input=converted)
result.check_returncode()
@ -75,6 +84,10 @@ def main():
],
required=True,
)
parser.add_argument(
'-v', '--verbose',
action='store_true',
)
parser.add_argument(
'-l', '--langset',
type=str,

View file

@ -11,12 +11,12 @@ except:
setup(
name='fleepit',
version='3',
version='4',
py_modules=['fleepit'],
description='Text seleciton keyboard layout switcher based on xclip / etc for X11 & wayland',
url='https://git.pegasko.art/bitrate16/fleepit',
author_email='pegasko@pegasko.art',
license='AGPL 3.0',
license='Apache 2.0',
keywords='keyboard layout shortcut layout-switcher',
entry_points='''
[console_scripts]