|
1 | 1 | from cmd import Cmd |
2 | 2 | from dataclasses import dataclass, field |
3 | 3 | from operator import attrgetter |
4 | | -from typing import Callable |
| 4 | +from typing import Callable, Tuple |
5 | 5 |
|
6 | 6 | from prompt_toolkit import PromptSession |
7 | 7 | from prompt_toolkit.history import FileHistory |
|
12 | 12 | from .errors import show_exception |
13 | 13 | from .evolve.types import Evolved |
14 | 14 | from .translate import Translator |
| 15 | +from .types import Form |
| 16 | +from .unicode import center, length |
15 | 17 |
|
16 | 18 | HISTORY_PATH = PYCONLANG_PATH / "repl.history" |
17 | 19 |
|
@@ -115,6 +117,24 @@ def do_s(self, line: str) -> None: |
115 | 117 | """ |
116 | 118 | self.do_simple(line) |
117 | 119 |
|
| 120 | + def do_gloss(self, line: str) -> None: |
| 121 | + """ |
| 122 | + Translates and glosses the translation. |
| 123 | + """ |
| 124 | + |
| 125 | + def pair_width(pair: Tuple[Evolved, Form]) -> int: |
| 126 | + return 2 + max(length(pair[0].modern), length(str(pair[1]))) |
| 127 | + |
| 128 | + gloss = self.translator.gloss_string(line) |
| 129 | + print(" ".join(center(pair[0].modern, pair_width(pair), " ") for pair in gloss)) |
| 130 | + print(" ".join(center(str(pair[1]), pair_width(pair), " ") for pair in gloss)) |
| 131 | + |
| 132 | + def do_g(self, line: str) -> None: |
| 133 | + """ |
| 134 | + See gloss. |
| 135 | + """ |
| 136 | + return self.do_gloss(line) |
| 137 | + |
118 | 138 |
|
119 | 139 | def run(command: str = "") -> None: |
120 | 140 | session = ReplSession() |
|
0 commit comments