Skip to content

Commit 4266a93

Browse files
authored
Merge pull request #35 from Mathics3/reinstate-gnu-readline
Reinstate GNU Readline as an option...
2 parents bdc89bf + 8fde3ea commit 4266a93

File tree

7 files changed

+402
-457
lines changed

7 files changed

+402
-457
lines changed

mathicsscript/__main__.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
import subprocess
99
from pathlib import Path
1010

11-
from mathicsscript.termshell import ShellEscapeException, TerminalShell, mma_lexer
11+
from mathicsscript.termshell import (
12+
ShellEscapeException,
13+
TerminalShellPromptToolKit,
14+
mma_lexer,
15+
)
16+
from mathicsscript.termshell_gnu import TerminalShellGNUReadline
1217

1318
from mathicsscript.format import format_output
1419

@@ -134,10 +139,11 @@ def out(self, out):
134139
help="don't print message at startup",
135140
)
136141
@click.option(
137-
"--readline/--no-readline",
138-
default=have_readline,
142+
"--readline",
143+
type=click.Choice(["GNU", "Prompt", "None"], case_sensitive=False),
144+
default="Prompt",
139145
show_default=True,
140-
help="GNU Readline line editing. If this is off completion and command history are also turned off",
146+
help="""Readline method. "Prompt" is usually best. GNU Readline is better than "None" most of the time.""",
141147
)
142148
@click.option(
143149
"--completion/--no-completion",
@@ -246,7 +252,17 @@ def main(
246252
"Settings`$PygmentsShowTokens", from_python(True if pygments_tokens else False)
247253
)
248254

249-
shell = TerminalShell(definitions, style, readline, completion, unicode, prompt)
255+
readline = "none" if (execute or file and not persist) else readline.lower()
256+
if readline == "prompt":
257+
shell = TerminalShellPromptToolKit(
258+
definitions, style, completion, unicode, prompt
259+
)
260+
else:
261+
want_readline = readline == "gnu"
262+
shell = TerminalShellGNUReadline(
263+
definitions, style, want_readline, completion, unicode, prompt
264+
)
265+
250266
load_settings(shell)
251267
if run:
252268
with open(run, "r") as ifile:

mathicsscript/bindkeys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def _(event):
6666
line = line.strip()
6767
if not line or line.startswith("#"):
6868
continue
69-
fields = re.split("\s*: ", line)
69+
fields = re.split(r"\s*: ", line)
7070
if len(fields) != 2:
7171
print(f"{line_no+1}: expecting 2 fields, got {len(fields)} in:\n{line}")
7272
continue

0 commit comments

Comments
 (0)