Skip to content

Commit 9e659f7

Browse files
committed
-e --execute is better suited for embedded use
This options adds `--quiet` and shows just evaluation output as text--execute
1 parent f41a7b9 commit 9e659f7

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

NEWS.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
1.1.2
1+
2.0.0
22
-----
33

44
* Fix ``Settings`$ShowFullForm`` now that we use Mathics supports Booleans better
55
* Show mathicsscript version on startup
66
* Add ``Settings`MathicsScriptVersion``
7+
* Add all of the WL escape sequences
8+
* Add conversions from WL Unicode to standard Unicode
9+
* Shell escapes `!` and `!!` added
10+
11+
Incompatible changes:
12+
13+
* `-e` `--execute` is better suited for embedded use. It adds `--quiet` and shows just evaluation output as text
714

815
1.1.1
916
-----

mathicsscript/__main__.py

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

11-
from mathicsscript.termshell import (
12-
ShellEscapeException,
13-
TerminalShell,
14-
)
11+
from mathicsscript.termshell import ShellEscapeException, TerminalShell
1512

1613
from mathicsscript.format import format_output
1714

@@ -151,7 +148,7 @@ def out(self, out):
151148
"-e",
152149
"--execute",
153150
help="evaluate EXPR before processing any input files (may be given "
154-
"multiple times)",
151+
"multiple times). Sets --quiet and --no-completion",
155152
multiple=True,
156153
required=False,
157154
)
@@ -241,12 +238,12 @@ def main(
241238

242239
if execute:
243240
for expr in execute:
244-
print(shell.get_in_prompt() + expr)
245241
evaluation = Evaluation(
246242
shell.definitions, output=TerminalOutput(shell), format="text"
247243
)
244+
shell.terminal_formatter = None
248245
result = evaluation.parse_evaluate(expr, timeout=settings.TIMEOUT)
249-
shell.print_result(result)
246+
shell.print_result(result, "text")
250247

251248
# After the next release, we can remove the hasattr test.
252249
if hasattr(evaluation, "exc_result"):
@@ -288,7 +285,9 @@ def main(
288285
print(f"Quit by pressing {quit_command}\n")
289286

290287
# If defined, full_form and style overwrite the predefined values.
291-
definitions.set_ownvalue("Settings`$ShowFullFormInput", SymbolTrue if full_form else SymbolFalse)
288+
definitions.set_ownvalue(
289+
"Settings`$ShowFullFormInput", SymbolTrue if full_form else SymbolFalse
290+
)
292291

293292
definitions.set_ownvalue(
294293
"Settings`$PygmentsStyle", from_python(shell.pygments_style)

mathicsscript/termshell.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,10 @@ def print_result(self, result, output_style=""):
285285
print(list(lex(out_str, mma_lexer)))
286286
out_str = highlight(out_str, mma_lexer, self.terminal_formatter)
287287
output = self.to_output(out_str)
288-
print(self.get_out_prompt("") + output + "\n")
288+
if output_style == "text":
289+
print(output)
290+
else:
291+
print(self.get_out_prompt("") + output + "\n")
289292

290293
def rl_read_line(self, prompt):
291294
# Wrap ANSI color sequences in \001 and \002, so readline

0 commit comments

Comments
 (0)