diff --git a/mathicsscript/termshell.py b/mathicsscript/termshell.py index 5667edb..bafde51 100644 --- a/mathicsscript/termshell.py +++ b/mathicsscript/termshell.py @@ -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 @@ -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 @@ -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)) @@ -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) ) @@ -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: @@ -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