Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle and document all geometries from YAML #173

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Dead keys are preceded by a `*` sign. They can be used in the `base` layer:

+-----+
shift = " ---> | "*" | <----- altgr+shift+key = dead diaeresis
base = ' ----> | '*' | <----- altgt+key = dead acute accent
base = ' ----> | '*' | <----- altgr+key = dead acute accent
+-----+


Expand Down
23 changes: 18 additions & 5 deletions kalamine/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from .generators import ahk, keylayout, klc, web, xkb
from .help import create_layout, user_guide
from .layout import KeyboardLayout, load_layout
from .layout import GEOMETRY_NAMES, KeyboardLayout, load_layout
from .server import keyboard_server


Expand Down Expand Up @@ -162,12 +162,25 @@ def build(
click.echo(f"... {output_file}")


# TODO: Provide geometry choices
@cli.command()
@click.argument("output_file", nargs=1, type=click.Path(exists=False, path_type=Path))
@click.option("--geometry", default="ISO", help="Specify keyboard geometry.")
@click.option("--altgr/--no-altgr", default=False, help="Set an AltGr layer.")
@click.option("--1dk/--no-1dk", "odk", default=False, help="Set a custom dead key.")
@click.option(
"--geometry",
default="ISO",
type=click.Choice(GEOMETRY_NAMES, case_sensitive=False),
help="Specify keyboard geometry (defaults to ISO).",
)
@click.option(
"--altgr/--no-altgr",
default=False,
help="Set an AltGr layer (defaults to --no-altgr).",
)
@click.option(
"--1dk/--no-1dk",
"odk",
default=False,
help="Set a custom dead key (defaults to --no-1dk).",
)
def new(output_file: Path, geometry: str, altgr: bool, odk: bool) -> None:
"""Create a new TOML layout description."""
create_layout(output_file, geometry, altgr, odk)
Expand Down
2 changes: 1 addition & 1 deletion kalamine/data/user_guide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Dead_Keys:

+-----+
shift = " ---> | "*" | <----- altgr+shift+key = dead diaeresis
base = ' ----> | '*' | <----- altgt+key = dead acute accent
base = ' ----> | '*' | <----- altgr+key = dead acute accent
+-----+

Standard_Dead_Keys: |
Expand Down
11 changes: 7 additions & 4 deletions kalamine/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class MetaDescr:
class SpacebarDescr:
shift: str = " "
altgr: str = " "
altgt_shift: str = " "
altgr_shift: str = " "
odk: str = "'"
odk_shift: str = "'"
# fmt: on
Expand Down Expand Up @@ -121,6 +121,8 @@ def from_dict(cls: Type[T], src: Dict) -> T:
key: GeometryDescr.from_dict(val) for key, val in load_data("geometry").items()
}

GEOMETRY_NAMES = list(map(str, GEOMETRY.keys()))


###
# Main
Expand Down Expand Up @@ -375,14 +377,15 @@ def _get_geometry(self, layers: Optional[List[Layer]] = None) -> List[str]:

@property
def geometry(self) -> str:
"""ANSI, ISO, ERGO."""
"""ANSI, ISO, ABNT, JIS, ALT, ERGO."""
return self.meta["geometry"].upper()

@geometry.setter
def geometry(self, value: str) -> None:
"""ANSI, ISO, ERGO."""
"""ANSI, ISO, ABNT, JIS, ALT, ERGO."""
shape = value.upper()
if shape not in ["ANSI", "ISO", "ERGO"]:
if shape not in GEOMETRY_NAMES:
click.echo(f"Unsupported geometry '{shape}', falling back to 'ISO'")
shape = "ISO"
self.meta["geometry"] = shape

Expand Down