66import subprocess
77import sys
88from pathlib import Path
9+ from typing import Any
910
1011import click
11- from mathics .core .attributes import attribute_string_to_number
12- from pygments import highlight
13-
1412from mathics import license_string , settings , version_info
13+ from mathics .core .attributes import attribute_string_to_number
1514from mathics .core .definitions import autoload_files
1615from mathics .core .evaluation import Evaluation , Output
1716from mathics .core .expression import from_python
1817from mathics .core .parser import MathicsFileLineFeeder
1918from mathics .core .symbols import Symbol , SymbolFalse , SymbolTrue
20-
2119from mathics_scanner import replace_wl_with_plain_text
20+ from pygments import highlight
2221
2322from mathicsscript .asymptote import asymptote_version
23+ from mathicsscript .settings import definitions
2424from mathicsscript .termshell import ShellEscapeException , mma_lexer
2525from mathicsscript .termshell_gnu import TerminalShellGNUReadline
2626from mathicsscript .termshell_prompt import TerminalShellPromptToolKit
27+ from mathicsscript .version import __version__
2728
2829try :
2930 __import__ ("readline" )
@@ -66,10 +67,6 @@ def get_srcdir():
6667 return osp .realpath (filename )
6768
6869
69- from mathicsscript .settings import definitions
70- from mathicsscript .version import __version__
71-
72-
7370def ensure_settings ():
7471 home = Path .home ()
7572 base_config_dir = home / ".config"
@@ -169,7 +166,8 @@ def out(self, out):
169166 type = click .Choice (readline_choices , case_sensitive = False ),
170167 default = "Prompt" ,
171168 show_default = True ,
172- help = """Readline method. "Prompt" is usually best. None is generally available and have the fewest features.""" ,
169+ help = """Readline method. "Prompt" is usually best. None is generally available and """
170+ """have the fewest features.""" ,
173171)
174172@click .option (
175173 "--completion/--no-completion" ,
@@ -233,7 +231,7 @@ def out(self, out):
233231@click .option (
234232 "--strict-wl-output/--no-strict-wl-output" ,
235233 default = False ,
236- help = ("Most WL-output compatible (at the expense of useability )." ),
234+ help = ("Most WL-output compatible (at the expense of usability )." ),
237235 required = False ,
238236)
239237@click .argument ("file" , nargs = 1 , type = click .Path (readable = True ), required = False )
@@ -377,6 +375,12 @@ def main(
377375 )
378376 TeXForm = Symbol ("System`TeXForm" )
379377
378+ def identity (x : Any ) -> Any :
379+ return x
380+
381+ def fmt_fun (query : Any ) -> Any :
382+ return highlight (str (query ), mma_lexer , shell .terminal_formatter )
383+
380384 definitions .set_line_no (0 )
381385 while True :
382386 try :
@@ -389,13 +393,11 @@ def main(
389393 "Settings`$ShowFullFormInput"
390394 ).replace .to_python ()
391395 style = definitions .get_ownvalue ("Settings`$PygmentsStyle" )
392- fmt = lambda x : x
396+ fmt = identity
393397 if style :
394398 style = style .replace .get_string_value ()
395399 if shell .terminal_formatter :
396- fmt = lambda x : highlight (
397- str (query ), mma_lexer , shell .terminal_formatter
398- )
400+ fmt = fmt_fun
399401
400402 evaluation = Evaluation (shell .definitions , output = TerminalOutput (shell ))
401403 query , source_code = evaluation .parse_feeder_returning_code (shell )
@@ -444,7 +446,7 @@ def main(
444446 # Should we test exit code for adding to history?
445447 GNU_readline .add_history (source_code .rstrip ())
446448 # FIXME add this... when in Mathics core updated
447- # shell.defintions .increment_line(1)
449+ # shell.definitions .increment_line(1)
448450
449451 except (KeyboardInterrupt ):
450452 print ("\n KeyboardInterrupt" )
0 commit comments