Added a new command

master
Mark 2022-10-28 19:47:50 -07:00
parent 6e17963d91
commit fbf2d6f36d
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
4 changed files with 80 additions and 7 deletions

View File

@ -36,7 +36,7 @@ def cmd_save(command, runner) -> None:
if len(command.args) != 1: if len(command.args) != 1:
printf( printf(
HTML( HTML(
"<err>Command <cmd_code>:{command.name}</cmd_code> takes exactly one argument.</err>" f"<err>Command <cmd_code>:{command.name}</cmd_code> takes exactly one argument.</err>"
), ),
style = lamb.utils.style style = lamb.utils.style
) )
@ -81,7 +81,7 @@ def cmd_load(command, runner):
if len(command.args) != 1: if len(command.args) != 1:
printf( printf(
HTML( HTML(
"<err>Command <cmd_code>:{command.name}</cmd_code> takes exactly one argument.</err>" f"<err>Command <cmd_code>:{command.name}</cmd_code> takes exactly one argument.</err>"
), ),
style = lamb.utils.style style = lamb.utils.style
) )
@ -145,7 +145,7 @@ def mdel(command, runner) -> None:
if len(command.args) != 1: if len(command.args) != 1:
printf( printf(
HTML( HTML(
"<err>Command <cmd_code>:{command.name}</cmd_code> takes exactly one argument.</err>" f"<err>Command <cmd_code>:{command.name}</cmd_code> takes exactly one argument.</err>"
), ),
style = lamb.utils.style style = lamb.utils.style
) )
@ -185,6 +185,76 @@ def clear(command, runner) -> None:
clear_screen() clear_screen()
lamb.utils.show_greeting() lamb.utils.show_greeting()
@lamb_command(
help_text = "Get or set reduction limit"
)
def rlimit(command, runner) -> None:
if len(command.args) == 0:
if runner.reduction_limit is None:
printf(
HTML(
"<ok>No reduction limit is set</ok>"
),
style = lamb.utils.style
)
else:
printf(
HTML(
f"<ok>Reduction limit is {runner.reduction_limit:,}</ok>"
),
style = lamb.utils.style
)
return
elif len(command.args) != 1:
printf(
HTML(
f"<err>Command <cmd_code>:{command.name}</cmd_code> takes exactly one argument.</err>"
),
style = lamb.utils.style
)
return
t = command.args[0]
if t.lower() == "none":
runner.reduction_limit = None
printf(
HTML(
f"<ok>Removed reduction limit</ok>"
),
style = lamb.utils.style
)
return
try:
t = int(t)
except ValueError:
printf(
HTML(
"<err>Reduction limit must be a positive integer or \"none\".</err>"
),
style = lamb.utils.style
)
return
if 50 > t:
printf(
HTML(
"<err>Reduction limit must be at least 50.</err>"
),
style = lamb.utils.style
)
return
runner.reduction_limit = t
printf(
HTML(
f"<ok>Set reduction limit to {t:,}</ok>"
),
style = lamb.utils.style
)
@lamb_command( @lamb_command(
help_text = "Print this help" help_text = "Print this help"

View File

@ -54,7 +54,7 @@ class LambdaParser:
(self.lp + self.pp_call + self.rp) (self.lp + self.pp_call + self.rp)
) )
self.pp_command = pp.Suppress(":") + pp.Word(pp.alphas + "_") + pp.Word(pp.alphas + "_")[0, ...] self.pp_command = pp.Suppress(":") + pp.Word(pp.alphas + "_") + pp.Word(pp.alphas + pp.nums + "_")[0, ...]
self.pp_all = ( self.pp_all = (

View File

@ -1,7 +1,6 @@
from prompt_toolkit import PromptSession from prompt_toolkit import PromptSession
from prompt_toolkit.formatted_text import FormattedText from prompt_toolkit.formatted_text import FormattedText
from prompt_toolkit import print_formatted_text as printf from prompt_toolkit import print_formatted_text as printf
from prompt_toolkit.shortcuts import clear as clear_screen
import enum import enum
import math import math
import time import time
@ -86,7 +85,9 @@ class Runner:
self.iter_update = 231 self.iter_update = 231
def prompt(self): def prompt(self):
return self.prompt_session.prompt(message = self.prompt_message) return self.prompt_session.prompt(
message = self.prompt_message
)
def parse(self, line): def parse(self, line):
e = self.parser.parse_line(line) e = self.parser.parse_line(line)
@ -151,7 +152,8 @@ class Runner:
("class:text", str(macro_expansions)), ("class:text", str(macro_expansions)),
("class:result_header", f"\nReductions: "), ("class:result_header", f"\nReductions: "),
("class:text", str(i)) ("class:text", f"{i} "),
("class:muted", f"(Limit: {self.reduction_limit:,})")
] ]
if (stop_reason == StopReason.BETA_NORMAL or stop_reason == StopReason.LOOP_DETECTED): if (stop_reason == StopReason.BETA_NORMAL or stop_reason == StopReason.LOOP_DETECTED):

View File

@ -11,6 +11,7 @@ style = Style.from_dict({ # type: ignore
"err": "#FF0000", "err": "#FF0000",
"prompt": "#00FFFF", "prompt": "#00FFFF",
"ok": "#B4EC85", "ok": "#B4EC85",
"muted": "#AAAAAA",
# Syntax # Syntax
"syn_macro": "#FF00FF", "syn_macro": "#FF00FF",