# Path: esc/commands.py
# BINOP = 'binop'
# UNOP = 'unop'
# MAIN_DOC = """
#     The main menu. All other esc functions and menus are eventually accessible
#     from this menu.
# """
# class EscCommand:
# class EscMenu(EscCommand):
# class EscOperation(EscCommand):
# class EscBuiltin(EscCommand):
#     def __init__(self, key, description):
#     def help_title(self):
#     def signature_info(self):
#     def execute(self, access_key, ss, registry):
#     def register_child(self, child):
#     def simulated_result(self, ss, registry):  # pylint: disable=no-self-use, unused-argument
#     def test(self):
#     def __init__(self, key, description, doc, mode_display=None):
#     def __repr__(self):
#     def signature_info(self):
#     def is_main_menu(self):
#     def anonymous_children(self):
#     def named_children(self):
#     def child(self, access_key):
#     def execute(self, access_key, ss, registry):
#     def test(self):
#     def __init__(self, key, func, pop, push, description, menu, retain=False,
#                  log_as=None, simulate=True):
#     def __repr__(self):
#     def __doc__(self):
#     def signature_info(self):
#     def _describe_operation(self, args, retvals, registry):
#     def _insufficient_items_on_stack(self, pops_requested=None):
#     def _retrieve_arguments(self, ss):
#     def _simulated_description(self, args, log, results):
#     def _store_results(self, ss, args, return_values, registry):
#     def execute(self, access_key, ss, registry):  # pylint: disable=useless-return
#     def simulated_result(self, ss, registry):
#     def test(self):
#     def __init__(self):
#     def execute(self, access_key, ss, registry):  # pylint: disable=useless-return
#     def simulated_result(self, ss, registry):
#     def test(self):
#     def signature_info(self):
# def Menu(key, description, parent, doc, mode_display=None):  # pylint: disable=invalid-name
# def Constant(value, key, description, menu):  # pylint: disable=invalid-name
#     def func():
# def Operation(key, menu, push, description=None, retain=False, log_as=None, simulate=True):  # pylint: disable=invalid-name
#     def function_decorator(func):
#         def _bind_stack_parm(stack_item, parm):
#         def wrapper(stack, registry):
#         def ensure(before, after=None, raises=None, close=False):
# def Mode(name, default_value, allowable_values=None):  # pylint: disable=invalid-name
# def ModeChange(key, description, menu, mode_name, to_value):  # pylint: disable=invalid-name
# 
# Path: esc/oops.py
# class FunctionExecutionError(EscError):
#     r"""
#     A broad exception type that occurs when the code within an operation
#     function couldn't be executed successfully for some reason. Examples
#     include:
# 
#     - a number is in the middle of being entered and isn't a valid number
#     - a function performed an undefined operation like dividing by zero
#     - there are too many or too few items on the stack
#     - a function directly raises this error due to invalid input
#       or inability to complete its task for some other reason
# 
#     :class:`FunctionExecutionError`\ s normally result in the ``__str__`` of
#     the exception being printed to the status bar, so exception messages
#     should be concise.
# 
#     A :class:`FunctionExecutionError` may be raised directly, or one of its
#     subclasses may be used.
#     """
# 
# class InsufficientItemsError(FunctionExecutionError):
#     """
#     Raised directly by operations functions that request the entire stack to
#     indicate not enough items are on the stack to finish their work, or by
#     the menu logic when an operation requests more parameters than items on
#     the stack.
# 
#     Functions may use the simplified form of the exception, providing an int
#     describing the number of items that should have been on the stack for the
#     ``number_required`` constructor parameter. esc will then reraise the
#     exception with a more useful message; a fallback message is provided in
#     case this doesn't happen for some reason.
#     """
#     def __init__(self, number_required, msg=None):
#         super().__init__()
#         self.number_required = number_required
#         self.msg = msg
# 
#     def __str__(self):
#         if self.msg:
#             return self.msg
#         else:
#             return f"Insufficient items: needs at least {self.number_required}"


from decimal import Decimal
from functools import reduce
from operator import add as add_operator
from esc.commands import Operation, Menu, main_menu, UNOP
from esc.oops import FunctionExecutionError, InsufficientItemsError
def increment(bos):
    "Add 1 to bos."
    return bos + 1

increment.ensure(before=[5, 6], after=[5, 7])


@Operation('D', menu=main_menu, push=1,
           description='decrement bos',
           log_as=UNOP)
def decrement(bos):
    "Subtract 1 from bos."
    return bos - 1

decrement.ensure(before=[5, 6], after=[5, 5])


@Operation('R', menu=main_menu, push=1,
           description='Sum all registers',
           log_as=lambda retval: f"sum all registers = {retval[0]}")
def sum_reg(registry):
    "Sum the values of all registers. Example function."
    values = registry.values()
    if not values:
        raise FunctionExecutionError("There are no registers defined.")
    return sum(i.decimal for i in values)


submenu = Menu(key='m', description='submenu test', parent=main_menu,
               doc="A menu with a submenu on it.")

# Path: esc/commands.py
# BINOP = 'binop'
# UNOP = 'unop'
# MAIN_DOC = """
#     The main menu. All other esc functions and menus are eventually accessible
#     from this menu.
# """
# class EscCommand:
# class EscMenu(EscCommand):
# class EscOperation(EscCommand):
# class EscBuiltin(EscCommand):
#     def __init__(self, key, description):
#     def help_title(self):
#     def signature_info(self):
#     def execute(self, access_key, ss, registry):
#     def register_child(self, child):
#     def simulated_result(self, ss, registry):  # pylint: disable=no-self-use, unused-argument
#     def test(self):
#     def __init__(self, key, description, doc, mode_display=None):
#     def __repr__(self):
#     def signature_info(self):
#     def is_main_menu(self):
#     def anonymous_children(self):
#     def named_children(self):
#     def child(self, access_key):
#     def execute(self, access_key, ss, registry):
#     def test(self):
#     def __init__(self, key, func, pop, push, description, menu, retain=False,
#                  log_as=None, simulate=True):
#     def __repr__(self):
#     def __doc__(self):
#     def signature_info(self):
#     def _describe_operation(self, args, retvals, registry):
#     def _insufficient_items_on_stack(self, pops_requested=None):
#     def _retrieve_arguments(self, ss):
#     def _simulated_description(self, args, log, results):
#     def _store_results(self, ss, args, return_values, registry):
#     def execute(self, access_key, ss, registry):  # pylint: disable=useless-return
#     def simulated_result(self, ss, registry):
#     def test(self):
#     def __init__(self):
#     def execute(self, access_key, ss, registry):  # pylint: disable=useless-return
#     def simulated_result(self, ss, registry):
#     def test(self):
#     def signature_info(self):
# def Menu(key, description, parent, doc, mode_display=None):  # pylint: disable=invalid-name
# def Constant(value, key, description, menu):  # pylint: disable=invalid-name
#     def func():
# def Operation(key, menu, push, description=None, retain=False, log_as=None, simulate=True):  # pylint: disable=invalid-name
#     def function_decorator(func):
#         def _bind_stack_parm(stack_item, parm):
#         def wrapper(stack, registry):
#         def ensure(before, after=None, raises=None, close=False):
# def Mode(name, default_value, allowable_values=None):  # pylint: disable=invalid-name
# def ModeChange(key, description, menu, mode_name, to_value):  # pylint: disable=invalid-name
# 
# Path: esc/oops.py
# class FunctionExecutionError(EscError):
#     r"""
#     A broad exception type that occurs when the code within an operation
#     function couldn't be executed successfully for some reason. Examples
#     include:
# 
#     - a number is in the middle of being entered and isn't a valid number
#     - a function performed an undefined operation like dividing by zero
#     - there are too many or too few items on the stack
#     - a function directly raises this error due to invalid input
#       or inability to complete its task for some other reason
# 
#     :class:`FunctionExecutionError`\ s normally result in the ``__str__`` of
#     the exception being printed to the status bar, so exception messages
#     should be concise.
# 
#     A :class:`FunctionExecutionError` may be raised directly, or one of its
#     subclasses may be used.
#     """
# 
# class InsufficientItemsError(FunctionExecutionError):
#     """
#     Raised directly by operations functions that request the entire stack to
#     indicate not enough items are on the stack to finish their work, or by
#     the menu logic when an operation requests more parameters than items on
#     the stack.
# 
#     Functions may use the simplified form of the exception, providing an int
#     describing the number of items that should have been on the stack for the
#     ``number_required`` constructor parameter. esc will then reraise the
#     exception with a more useful message; a fallback message is provided in
#     case this doesn't happen for some reason.
#     """
#     def __init__(self, number_required, msg=None):
#         super().__init__()
#         self.number_required = number_required
#         self.msg = msg
# 
#     def __str__(self):
#         if self.msg:
#             return self.msg
#         else:
#             return f"Insufficient items: needs at least {self.number_required}"


# Path: esc-plugins/misc.py
from decimal import Decimal
from functools import reduce
from operator import add as add_operator
from esc.commands import Operation, Menu, main_menu, UNOP
from esc.oops import FunctionExecutionError, InsufficientItemsError

def increment(bos):
    "Add 1 to bos."
    return bos + 1

increment.ensure(before=[5, 6], after=[5, 7])


@Operation('D', menu=main_menu, push=1,
           description='decrement bos',
           log_as=UNOP)
def decrement(bos):
    "Subtract 1 from bos."
    return bos - 1

decrement.ensure(before=[5, 6], after=[5, 5])


@Operation('R', menu=main_menu, push=1,
           description='Sum all registers',
           log_as=lambda retval: f"sum all registers = {retval[0]}")
def sum_reg(registry):
    "Sum the values of all registers. Example function."
    values = registry.values()
    if not values:
        raise FunctionExecutionError("There are no registers defined.")
    return sum(i.decimal for i in values)


submenu = Menu(key='m', description='submenu test', parent=main_menu,
               doc="A menu with a submenu on it.")

subsubmenu = Menu(key='m', description='subsubmenu test', parent=submenu,