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
19 changes: 16 additions & 3 deletions mathicsscript/bindkeys.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import pathlib
import re

from mathicsscript.termshell import ALL_PYGMENTS_STYLES
from mathicsscript.settings import definitions
from mathics.session import get_settings_value

Expand Down Expand Up @@ -136,12 +137,24 @@ def _editor_toggle(event):
def _group_autocomplete_toggle(event):
"""Complete braces."""
app = event.app

if not hasattr(app, "group_autocomplete"):
app.group_autocomplete = False
app.group_autocomplete = not app.group_autocomplete


# Add an additional key binding for toggling this flag.
@bindings.add("f2")
def _next_pygements_style(event):
"""Set Pygments style to the next sytle in ."""
app = event.app

try:
i = ALL_PYGMENTS_STYLES.index(app.pygments_style)
except ValueError:
pass
else:
i = (i + 1) % len(ALL_PYGMENTS_STYLES)
app.pygments_style = ALL_PYGMENTS_STYLES[i]


def read_inputrc(read_init_file_fn: Callable, use_unicode: bool) -> None:
"""
Read GNU Readline style inputrc
Expand Down
6 changes: 1 addition & 5 deletions mathicsscript/termshell_gnu.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from readline import read_init_file
except ImportError:
# Not sure what to do here: nothing is probably safe.
def read_init_file(path: str):
def read_init_file(_: str):
return


Expand All @@ -25,10 +25,6 @@ def read_init_file(path: str):
)
from mathics.core.symbols import strip_context

from pygments.styles import get_all_styles

ALL_PYGMENTS_STYLES = list(get_all_styles())

try:
from readline import (
parse_and_bind,
Expand Down
40 changes: 33 additions & 7 deletions mathicsscript/termshell_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from mathics.core.attributes import attribute_string_to_number
from mathics.core.expression import Expression, from_python
from mathics.core.rules import Rule
from mathics.core.symbols import SymbolNull
from mathics.core.symbols import SymbolNull, SymbolFalse, SymbolTrue
from mathics.core.systemsymbols import SymbolMessageName
from mathics_pygments.lexer import MathematicaLexer, MToken
from mathics_scanner.location import ContainerKind
Expand All @@ -35,6 +35,7 @@
from mathicsscript.bindkeys import bindings, read_init_file, read_inputrc
from mathicsscript.completion import MathicsCompleter
from mathicsscript.termshell import (
ALL_PYGMENTS_STYLES,
CONFIGDIR,
HISTSIZE,
USER_INPUTRC,
Expand All @@ -47,8 +48,6 @@

mma_lexer = MathematicaLexer()

ALL_PYGMENTS_STYLES = list(get_all_styles())

color_scheme = TERMINAL_COLORS.copy()
color_scheme[MToken.SYMBOL] = ("yellow", "ansibrightyellow")
color_scheme[MToken.BUILTIN] = ("ansigreen", "ansibrightgreen")
Expand Down Expand Up @@ -163,16 +162,43 @@ def bottom_toolbar(self):
app = get_app()
edit_mode = "Vi" if app.editing_mode == EditingMode.VI else "Emacs"

app.group_autocomplete = True

if self.definitions.get_ownvalue("Settings`$GroupAutocomplete"):
# The first time around, app.group_autocomplete has not been set,
# so use the value from Settings`GroupAutocomplete.
# However, after that we may have changed this value internally using
# function key f3, so update Settings`GroupAutocomplete from that.
if hasattr(app, "group_autocomplete"):
self.definitions.set_ownvalue(
"Settings`$GroupAutocomplete",
SymbolTrue if app.group_autocomplete else SymbolFalse,
)
elif self.definitions.get_ownvalue("Settings`$GroupAutocomplete"):
app.group_autocomplete = self.definitions.get_ownvalue(
"Settings`$GroupAutocomplete"
).to_python()
else:
# First time around and there is no value set via
# Settings`GroupAutocomplete.
app.group_autocomplete = True
self.definitions.set_ownvalue("Settings`$GroupAutocomplete", SymbolTrue)

if hasattr(app, "pygments_style"):
self.definitions.set_ownvalue(
"Settings`$PygmentsStyle", String(app.pygments_style)
)
elif self.definitions.get_ownvalue("Settings`$PygmentsStyle") is not SymbolNull:
app.pygments_style = self.definitions.get_ownvalue(
"Settings`$PygmentsStyle"
)
else:
# First time around and there is no value set via
app.pygments_style = self.pygments_style
self.definitions.set_ownvalue(
"Settings`$PygmentsStyle", String(app.pygments_style)
)

edit_mode = "Vi" if app.editing_mode == EditingMode.VI else "Emacs"
return HTML(
f" mathicsscript: {__version__}, Style: {self.pygments_style}, Mode: {edit_mode}, Autobrace: {app.group_autocomplete}"
f" mathicsscript: {__version__}, Style: {app.pygments_style}, Mode: {edit_mode}, Autobrace: {app.group_autocomplete}"
)

def get_in_prompt(self):
Expand Down
Loading