Skip to content
Closed
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
20 changes: 15 additions & 5 deletions mathicsscript/termshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
import sys
import re
from columnize import columnize
from mathics_scanner import replace_unicode_with_wl, named_characters
from mathics_scanner import (
replace_wl_with_plain_text,
replace_unicode_with_wl,
named_characters
)
from mathics.core.expression import Expression, String, Symbol
from mathics.core.expression import strip_context, from_python
from mathics.core.rules import Rule
Expand Down Expand Up @@ -106,6 +110,7 @@ def __init__(
self.lineno = 0
self.terminal_formatter = None
self.history_length = definitions.get_config_value("$HistoryLength", HISTSIZE)
self.use_unicode = use_unicode

# Try importing readline to enable arrow keys support etc.
self.using_readline = False
Expand All @@ -130,7 +135,7 @@ def __init__(
parent_dir = pathlib.Path(__file__).parent.absolute()
with parent_dir:
inputrc = (
"inputrc-unicode" if use_unicode else "inputrc-no-unicode"
"inputrc-unicode" if self.use_unicode else "inputrc-no-unicode"
)
try:
read_init_file(str(parent_dir / inputrc))
Expand Down Expand Up @@ -186,7 +191,7 @@ def __init__(
"Settings`$PygmentsShowTokens", from_python(False)
)
self.definitions.set_ownvalue("Settings`$PygmentsStyle", from_python(style))
self.definitions.set_ownvalue("Settings`$UseUnicode", from_python(use_unicode))
self.definitions.set_ownvalue("Settings`$UseUnicode", from_python(self.use_unicode))
self.definitions.set_ownvalue(
"Settings`PygmentsStylesAvailable", from_python(ALL_PYGMENTS_STYLES)
)
Expand Down Expand Up @@ -244,7 +249,11 @@ def to_output(self, text):
return newline.join(text.splitlines())

def out_callback(self, out):
print(self.to_output(str(out)))
print(
self.to_output(
replace_wl_with_plain_text(str(out), self.use_unicode)
)
)

def read_line(self, prompt):
if self.using_readline:
Expand All @@ -269,7 +278,8 @@ def print_result(self, result, output_style=""):
print(sys.exc_info()[1])
return

out_str = str(result.result)
out_str = replace_wl_with_plain_text(str(result.result),
use_unicode=self.use_unicode)
if eval_type == "System`Graph":
out_str = "-Graph-"
elif self.terminal_formatter: # pygmentize
Expand Down