11# -*- coding: utf-8 -*-
2- # Copyright (C) 2021-2022 Rocky Bernstein <[email protected] > 2+ # Copyright (C) 2021-2022, 2025 Rocky Bernstein <[email protected] > 33
44import locale
55import os
88import sys
99from typing import Optional
1010
11- from mathics_pygments .lexer import MathematicaLexer , MToken
12- from mathicsscript .completion import MathicsCompleter
13- from mathicsscript .termshell import (
14- CONFIGDIR ,
15- HISTSIZE ,
16- USER_INPUTRC ,
17- is_pygments_style ,
18- ShellEscapeException ,
19- SymbolPygmentsStylesAvailable ,
20- TerminalShellCommon ,
21- )
22- from mathicsscript .version import __version__
23-
11+ from colorama import init as colorama_init
2412from mathics .core .atoms import String
2513from mathics .core .attributes import attribute_string_to_number
2614from mathics .core .expression import Expression , from_python
2715from mathics .core .rules import Rule
2816from mathics .core .systemsymbols import SymbolMessageName
29-
30- from mathicsscript .bindkeys import bindings , read_inputrc , read_init_file
31-
32- from prompt_toolkit import PromptSession , HTML , print_formatted_text
17+ from mathics_pygments .lexer import MathematicaLexer , MToken
18+ from prompt_toolkit import HTML , PromptSession , print_formatted_text
3319from prompt_toolkit .application .current import get_app
3420from prompt_toolkit .enums import EditingMode
3521from prompt_toolkit .history import FileHistory
3622from prompt_toolkit .lexers import PygmentsLexer
3723from prompt_toolkit .styles .pygments import style_from_pygments_cls
38-
39-
4024from pygments import format , highlight , lex
41- from pygments .styles import get_style_by_name
42- from pygments .formatters .terminal import TERMINAL_COLORS
4325from pygments .formatters import Terminal256Formatter
44- from pygments .styles import get_all_styles
26+ from pygments .formatters .terminal import TERMINAL_COLORS
27+ from pygments .styles import get_all_styles , get_style_by_name
4528from pygments .util import ClassNotFound
4629
30+ # FIXME: __main__ shouldn't be needed. Fix term_background
31+ from term_background .__main__ import is_dark_background
32+
33+ from mathicsscript .bindkeys import bindings , read_init_file , read_inputrc
34+ from mathicsscript .completion import MathicsCompleter
35+ from mathicsscript .termshell import (
36+ CONFIGDIR ,
37+ HISTSIZE ,
38+ USER_INPUTRC ,
39+ ShellEscapeException ,
40+ SymbolPygmentsStylesAvailable ,
41+ TerminalShellCommon ,
42+ is_pygments_style ,
43+ )
44+ from mathicsscript .version import __version__
45+
4746mma_lexer = MathematicaLexer ()
4847
4948ALL_PYGMENTS_STYLES = list (get_all_styles ())
5453color_scheme [MToken .OPERATOR ] = ("magenta" , "ansibrightmagenta" )
5554color_scheme [MToken .NUMBER ] = ("ansiblue" , "ansibrightblue" )
5655
57- from colorama import init as colorama_init
58-
59- # FIXME: __main__ shouldn't be needed. Fix term_background
60- from term_background .__main__ import is_dark_background
61-
6256HISTFILE = osp .join (CONFIGDIR , "history-ptk" )
6357
6458
@@ -70,6 +64,7 @@ def __init__(
7064 want_completion : bool ,
7165 use_unicode : bool ,
7266 prompt : bool ,
67+ edit_mode : Optional [str ],
7368 ):
7469 super (TerminalShellCommon , self ).__init__ ("<stdin>" )
7570 self .input_encoding = locale .getpreferredencoding ()
@@ -79,6 +74,10 @@ def __init__(
7974 self .prompt = prompt
8075
8176 self .session = PromptSession (history = FileHistory (HISTFILE ))
77+ if edit_mode is not None :
78+ self .session .editing_mode = (
79+ EditingMode .VI if edit_mode == "vi" else EditingMode .EMACS
80+ )
8281
8382 # Try importing readline to enable arrow keys support etc.
8483 self .using_readline = False
0 commit comments