Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fabi1cazenave committed Feb 10, 2024
1 parent 5a0a807 commit dc4f069
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
1 change: 0 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ full = '''
'''
```


Layers
--------------------------------------------------------------------------------

Expand Down
12 changes: 3 additions & 9 deletions kalamine/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import click
import tomli

from .help import MARKDOWN_HEADER, TOML_FOOTER, TOML_HEADER, core_guide
from .help import TOML_FOOTER, TOML_HEADER, inline_guide, user_guide
from .layout import KeyboardLayout, load_layout
from .server import keyboard_server

Expand Down Expand Up @@ -204,14 +204,8 @@ def keymap(layout_name, layout_layer, layer_name=""):
content += keymap("ansi", "base")

# append user guide sections
doc = pkgutil.get_data(__package__, "../docs/README.md").decode("utf-8") # type: ignore
sections = doc.split("\n\n\n")
for topic in sections[1:]:
content += "\n\n"
content += "\n# "
content += "\n# ".join(topic.rstrip().split("\n"))
with open(output_file, "w", encoding="utf-8", newline="\n") as file:
file.write(content)
file.write(content + inline_guide())
click.echo(f"... {output_file}")


Expand All @@ -225,7 +219,7 @@ def watch(filepath: Path) -> None:
@cli.command()
def guide() -> None:
"""Show user guide and exit."""
click.echo(MARKDOWN_HEADER + "\n" + core_guide())
click.echo(user_guide())


@cli.command()
Expand Down
47 changes: 31 additions & 16 deletions kalamine/help.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from typing import List

from .utils import load_data

SEPARATOR = "--------------------------------------------------------------------------------"

MARKDOWN_HEADER = """Defining a Keyboard Layout
================================================================================
Expand Down Expand Up @@ -46,32 +50,43 @@


def dead_key_table() -> str:
out = ""
out += "\n id XKB name base -> accented chars"
out += "\n ----------------------------------------------------------------------------"
out = f"\n id XKB name base -> accented chars\n {SEPARATOR[4:]}"
for item in load_data("dead_keys"):
if (item["char"]) != "**":
out += f"\n {item['char']} {item['name']:<17} {item['base']}"
out += f"\n -> {item['alt']}"
return out


def core_guide() -> str:
out = ""
def core_guide() -> List[str]:
sections: List[str] = []

for title, content in load_data("user_guide").items():
out += f"\n{title.replace('_', ' ')}"
out += "\n--------------------------------------------------------------------------------"
out = f"\n{title.replace('_', ' ')}\n{SEPARATOR}"

if not isinstance(content, dict):
if isinstance(content, dict):
for subtitle, subcontent in content.items():
out += f"\n\n### {subtitle.replace('_', ' ')}"
out += f"\n\n{subcontent}"
if subtitle == "Standard_Dead_Keys":
out += dead_key_table()
else:
out += f"\n\n{content}"
continue

for subtitle, subcontent in content.items():
out += f"\n\n### {subtitle.replace('_', ' ')}"
out += f"\n\n{subcontent}"
if subtitle == "Standard_Dead_Keys":
out += dead_key_table()
sections.append(out)

out += "\n"
return sections

return out

def user_guide() -> str:
return MARKDOWN_HEADER + "\n".join(core_guide())


def inline_guide() -> str:
content: str = ""

for topic in core_guide():
content += f"\n\n\n# {SEPARATOR}"
content += "\n# ".join(topic.rstrip().split("\n"))

return content.replace(" \n", "\n")

0 comments on commit dc4f069

Please sign in to comment.