From d51280467c654b526eb4fc8268177779acd480e7 Mon Sep 17 00:00:00 2001 From: granitosaurus Date: Mon, 26 Sep 2022 18:48:27 +0700 Subject: [PATCH] add gen-compose-export command --- README.md | 44 +++++++++++++++++++++++++++++++++++++++++--- pyproject.toml | 7 +++++-- toXcompose.py | 10 +++++++--- 3 files changed, 53 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index deddd21..0c4b114 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ _note: Some programs need a hard reboot to take in the map, like `kill -9` sort Linux's xcompose mappings are supported via experimental conversion: ``` -$ gen-compose-conver xcompose --help +$ gen-compose-convert xcompose --help Usage: gen-compose-convert xcompose [OPTIONS] [FILES]... Convert xcompose file, that follows format like: @@ -107,13 +107,51 @@ Options: For example: ``` -$ cat mappings/example.compose +$ head mappings/example.compose : "₿" U20BF # BITCOIN SIGN -$ gen-compose-convert xcompose mappings/example.compose --keep-comments > example.yaml +... +$ gen-compose-convert xcompose mappings/xcompose.compose --keep-comments > example.yaml $ cat example.yaml "B|": "₿" # BITCOIN SIGN +... ``` +## Exporting to XCompose + +`gen-compose-export` command can be used export yaml configuration back to XCompose file: + +```shell +$ gen-compose-export --help +Usage: gen-compose-export [OPTIONS] YAMLFILE + + Export .yaml config file back to XCompose file i.e. this is reverse of + gen-compose-convert + +Options: + --help Show this message and exit. +``` + +For example: + +```python +$ head mappings/xcompose.yaml +"..": "…" # HORIZONTAL ELLIPSIS +"v..": "⋮" # VERTICAL ELLIPSIS +... +$ gen-compose-export mappings/xcompose.yaml > xcompose.compose +$ head xcompose.compose + :"…" + :"⋮" + :"⋯" + :"⋰" + :"⋱" + <2>:"‥" + <1>:"·" + :"⁒" + :"⅋" + <7>:"⁊" +... +``` ## Notes and Issues diff --git a/pyproject.toml b/pyproject.toml index 1946436..6136caf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,12 +1,13 @@ [tool.poetry] name = "gen-compose" -version = "1.1.0" +version = "1.2.0" description = "Key generator for macos keybinding system" authors = ["Granitosaurus "] license = "GPL-3.0-or-later" packages = [ {"include" = "gencompose.py"}, - {"include" = "convcompose.py"} + {"include" = "convcompose.py"}, + {"include" = "toXcompose.py"}, ] readme = "README.md" homepage = "https://github.com/Granitosaurus/macos-compose" @@ -30,6 +31,8 @@ pytest = "^6.1.0" [tool.poetry.scripts] gen-compose = "gencompose:main" gen-compose-convert = "convcompose:main" +gen-compose-export = "toXcompose:main" + [build-system] requires = ["poetry>=0.12"] diff --git a/toXcompose.py b/toXcompose.py index ce16fce..b1198ff 100644 --- a/toXcompose.py +++ b/toXcompose.py @@ -11,20 +11,24 @@ def get_xcompose_key(key): kval = i if i in mapping_dict: kval = mapping_dict[i] - xval += "<" + kval +"> " + xval += f"<{kval}>" return xval def get_xcompose_val(val): - return '"' + val + '"' + return f'"{val}"' @click.command() @click.argument('yamlfile', type=click.File()) def main(yamlfile): + """ + Export .yaml config file back to XCompose file + i.e. this is reverse of gen-compose-convert + """ yamldata = yaml.load(yamlfile.read(), Loader=yaml.Loader) for k, v in yamldata.items(): xkey = get_xcompose_key(k) xval = get_xcompose_val(v) - echo(xkey + ":" + xval) + echo(f"{xkey}:{xval}") if __name__ == '__main__': main()