Skip to content
Merged
Show file tree
Hide file tree
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
47 changes: 29 additions & 18 deletions mathicsscript/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,29 +469,40 @@ def main(

load_settings_file(shell)
style_from_settings_file = definitions.get_ownvalue("Settings`$PygmentsStyle")
if style_from_settings_file is SymbolNull and style is None:
if style_from_settings_file is not SymbolNull and style is None:
style = style_from_settings_file
shell.setup_pygments_style(style)

if file:
with open(file, "r") as ifile:
feeder = MathicsFileLineFeeder(ifile)
if not os.path.exists(file):
print(f"\nFile {file} does not exist; skipping reading.")
file = None
elif os.path.isdir(file):
print(f"\nFile {file} does is a directory; skipping reading.")
file = None
else:
try:
while not feeder.empty():
evaluation = Evaluation(
shell.definitions,
output=TerminalOutput(shell),
catch_interrupt=False,
format="text",
)
query = evaluation.parse_feeder(feeder)
if query is None:
continue
evaluation.evaluate(query, timeout=settings.TIMEOUT)
except KeyboardInterrupt:
print("\nKeyboardInterrupt")

definitions.set_line_no(0)
with open(file, "r") as ifile:
feeder = MathicsFileLineFeeder(ifile)
try:
while not feeder.empty():
evaluation = Evaluation(
shell.definitions,
output=TerminalOutput(shell),
catch_interrupt=False,
format="text",
)
query = evaluation.parse_feeder(feeder)
if query is None:
continue
evaluation.evaluate(query, timeout=settings.TIMEOUT)
except KeyboardInterrupt:
print("\nKeyboardInterrupt")
except Exception as e:
print(f"\nError reading {file}: {e}; skipping reading.")
file = None
else:
definitions.set_line_no(0)

if code:
for expr in code:
Expand Down
9 changes: 6 additions & 3 deletions mathicsscript/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,18 @@ def eval_boxes(result, fn: Callable, obj, **options):
obj.last_eval = SymbolAborted
return "$Aborted"
if format == "text":
if expr_head is SymbolStringForm:
return expr.elements[0].value
elif isinstance(expr, String):
if isinstance(expr, String):
return expr.value
result = expr.format(obj, SymbolOutputForm)
elif format == "xml":
result = Expression(SymbolStandardForm, expr).format(obj, SymbolMathMLForm)
elif format == "tex":
result = Expression(SymbolStandardForm, expr).format(obj, SymbolTeXForm)
elif format == "error":
# We may do fancier things in the future.
if isinstance(expr, String):
return expr.value
result = expr.format(obj, SymbolOutputForm)
elif format == "unformatted":
if expr_head is PyMathicsGraph and hasattr(expr, "G"):
return format_graph(expr.G)
Expand Down
6 changes: 4 additions & 2 deletions mathicsscript/termshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import mathics_scanner.location

from columnize import columnize
from mathics.core.atoms import Symbol
from mathics.core.atoms import String, Symbol
from mathics.core.attributes import attribute_string_to_number
from mathics.core.expression import Expression, from_python # strip_context,
from mathics.core.rules import Rule
Expand Down Expand Up @@ -238,7 +238,8 @@ def print_result(
out_str = str(result.result)
use_highlight = True
if eval_type == "System`String":
if strict_wl_output: # exact-wl-compatibility
# Use exact-wl-compatibility?
if strict_wl_output:
out_str = (
format(
[(MToken.STRING, out_str.rstrip())], self.terminal_formatter
Expand All @@ -263,6 +264,7 @@ def print_result(

if eval_type == "System`Graph":
out_str = "-Graph-"

elif self.terminal_formatter: # pygmentize
show_pygments_tokens = get_settings_value(
self.definitions, "Settings`$PygmentsShowTokens"
Expand Down
5 changes: 3 additions & 2 deletions mathicsscript/termshell_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ def print_result(
out_str = str(result.result)
use_highlight = True
if eval_type == "System`String":
if strict_wl_output: # exact-wl-compatibility
# Use exact-wl-compatibility?
if strict_wl_output:
out_str = (
format(
[(MToken.STRING, out_str.rstrip())], self.terminal_formatter
Expand All @@ -189,8 +190,8 @@ def print_result(

if eval_type == "System`Graph":
out_str = "-Graph-"
elif self.terminal_formatter: # pygmentize

elif self.terminal_formatter: # pygmentize
if show_pygments_tokens:
print(list(lex(out_str, mma_lexer)))
if use_highlight:
Expand Down
Loading