|
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 | # Copyright (C) 2020-2022, 2024, 2025 Rocky Bernstein <[email protected]> |
3 | 3 |
|
4 | | -from columnize import columnize |
5 | | - |
6 | 4 | import locale |
7 | 5 | import os |
8 | 6 | import os.path as osp |
9 | 7 | import pathlib |
10 | 8 | import sys |
11 | | - |
12 | 9 | from typing import Optional |
13 | 10 |
|
14 | | -from mathics_pygments.lexer import MathematicaLexer, MToken |
| 11 | +import mathics_scanner.location |
15 | 12 |
|
| 13 | +from colorama import init as colorama_init |
| 14 | +from columnize import columnize |
16 | 15 | from mathics.core.atoms import String, Symbol |
17 | 16 | from mathics.core.attributes import attribute_string_to_number |
18 | | -from mathics.core.expression import ( |
19 | | - Expression, |
20 | | - # strip_context, |
21 | | - from_python, |
22 | | -) |
| 17 | +from mathics.core.expression import Expression, from_python # strip_context, |
23 | 18 | from mathics.core.rules import Rule |
24 | 19 | from mathics.core.symbols import SymbolNull |
25 | 20 | from mathics.core.systemsymbols import SymbolMessageName |
| 21 | +from mathics_scanner.location import ContainerKind |
26 | 22 | from mathics.session import get_settings_value, set_settings_value |
27 | | - |
| 23 | +from mathics_pygments.lexer import MathematicaLexer, MToken |
28 | 24 | from pygments import format, highlight, lex |
29 | | -from pygments.formatters.terminal import TERMINAL_COLORS |
30 | 25 | from pygments.formatters import Terminal256Formatter |
| 26 | +from pygments.formatters.terminal import TERMINAL_COLORS |
31 | 27 | from pygments.styles import get_all_styles |
32 | 28 | from pygments.util import ClassNotFound |
33 | 29 |
|
| 30 | +# FIXME: __main__ shouldn't be needed. Fix term_background |
| 31 | +from term_background.__main__ import is_dark_background |
| 32 | + |
34 | 33 | mma_lexer = MathematicaLexer() |
35 | 34 |
|
36 | 35 | ALL_PYGMENTS_STYLES = list(get_all_styles()) |
|
41 | 40 | color_scheme[MToken.OPERATOR] = ("magenta", "ansibrightmagenta") |
42 | 41 | color_scheme[MToken.NUMBER] = ("ansiblue", "ansibrightblue") |
43 | 42 |
|
44 | | -from colorama import init as colorama_init |
45 | | - |
46 | | -# FIXME: __main__ shouldn't be needed. Fix term_background |
47 | | -from term_background.__main__ import is_dark_background |
48 | | - |
49 | 43 | # Set up mathicsscript configuration directory |
50 | 44 | CONFIGHOME = os.environ.get("XDG_CONFIG_HOME", osp.expanduser("~/.config")) |
51 | 45 | CONFIGDIR = osp.join(CONFIGHOME, "mathicsscript") |
@@ -86,11 +80,11 @@ def __init__( |
86 | 80 | self, |
87 | 81 | definitions, |
88 | 82 | style: Optional[str], |
89 | | - want_completion: bool, |
| 83 | + _: bool, |
90 | 84 | use_unicode: bool, |
91 | 85 | prompt: bool, |
92 | 86 | ): |
93 | | - super().__init__("<stdin>") |
| 87 | + super().__init__([], ContainerKind.STREAM) |
94 | 88 | self.input_encoding = locale.getpreferredencoding() |
95 | 89 | self.lineno = 0 |
96 | 90 | self.terminal_formatter = None |
@@ -284,6 +278,8 @@ def reset_lineno(self): |
284 | 278 | def feed(self): |
285 | 279 | prompt_str = self.get_in_prompt() if self.prompt else "" |
286 | 280 | result = self.read_line(prompt_str) + "\n" |
| 281 | + if mathics_scanner.location.TRACK_LOCATIONS: |
| 282 | + self.container.append(self.source_text) |
287 | 283 | if result == "\n": |
288 | 284 | return "" # end of input |
289 | 285 | self.lineno += 1 |
|
0 commit comments