# Path: esc/consts.py
# STACKDEPTH = 12
# 
# STACKWIDTH = 21  # needs room for sci notation and labels on top of precision
# 
# Path: esc/oops.py
# class RollbackTransaction(Exception):
#     """
#     Raised during a StackState .transaction() to indicate that the transaction
#     should be rolled back due to an error. If status_message is provided, the
#     status bar will be set to display the message.
#     """
#     def __init__(self, status_message=None):
#         super().__init__()
#         self.status_message = status_message
# 
#     def __str__(self):
#         return f"<RollbackTransaction: message {self.status_message}>"
# 
# Path: esc/status.py
# class StatusState:
#     class Modality(Enum):
#     class SuccessCode(Enum):
#         READY = (' ', "Ready (<F1> for help)")
#         ENTERING_NUMBER = ('i', "Insert")
#         IN_MENU = ('m', "Expecting menu selection")
#         EXPECTING_REGISTER = ('r', "Expecting register identifier (any letter)")
#         EXPECTING_HELP = ('h', "Browsing help (select a command or menu)")
#         OK = auto()  # pylint: disable=invalid-name
#         ADVISORY = auto()
#         ERROR = auto()
#         def __init__(self, status_char, status_message):
#     def __init__(self):
#     def __repr__(self):
#     def status_char(self):
#     def status_message(self):
#     def _clear_errors(self):
#     def ready(self):
#     def entering_number(self):
#     def in_menu(self):
#     def expecting_register(self):
#     def expecting_help(self):
#     def advisory(self, msg):
#     def error(self, msg):
#     def mark_seen(self):
#     def push_state(self):
#     def pop_state(self):
#     def save_state(self):


from contextlib import contextmanager
from decimal import Decimal
from .consts import STACKDEPTH, STACKWIDTH
from . import history
from .oops import RollbackTransaction
from .status import status
import copy
import decimal
            True if a number was finished.
            False if bos was already finished.

        Raises:
            ValueError if the value was invalid and the number couldn't be
            finished. The exception message can be displayed on the status bar.

        Set running_op to an operation name if you're entering prior to running
        an operation (go figure) for a more helpful error message in that case.
        """
        # Even if we were *not* editing the stack, checkpoint the stack state.
        # This ensures that we will get a checkpoint anytime we call an
        # operation as well as when we enter a number onto the stack.
        # Multiple checkpoints in a row do nothing, so this is safe.
        history.hs.checkpoint_stack(self)

        if self.editing_last_item:
            if self.s[self.stack_posn].finish_entry():
                self.editing_last_item = False
                return True
            else:
                if running_op:
                    msg = 'Cannot run "%s": invalid value on bos.' % running_op
                else:
                    msg = 'Bottom of stack is not a valid number.'
                raise ValueError(msg)
        else:
            return False

    def has_push_space(self, spaces):

# Path: esc/consts.py
# STACKDEPTH = 12
# 
# STACKWIDTH = 21  # needs room for sci notation and labels on top of precision
# 
# Path: esc/oops.py
# class RollbackTransaction(Exception):
#     """
#     Raised during a StackState .transaction() to indicate that the transaction
#     should be rolled back due to an error. If status_message is provided, the
#     status bar will be set to display the message.
#     """
#     def __init__(self, status_message=None):
#         super().__init__()
#         self.status_message = status_message
# 
#     def __str__(self):
#         return f"<RollbackTransaction: message {self.status_message}>"
# 
# Path: esc/status.py
# class StatusState:
#     class Modality(Enum):
#     class SuccessCode(Enum):
#         READY = (' ', "Ready (<F1> for help)")
#         ENTERING_NUMBER = ('i', "Insert")
#         IN_MENU = ('m', "Expecting menu selection")
#         EXPECTING_REGISTER = ('r', "Expecting register identifier (any letter)")
#         EXPECTING_HELP = ('h', "Browsing help (select a command or menu)")
#         OK = auto()  # pylint: disable=invalid-name
#         ADVISORY = auto()
#         ERROR = auto()
#         def __init__(self, status_char, status_message):
#     def __init__(self):
#     def __repr__(self):
#     def status_char(self):
#     def status_message(self):
#     def _clear_errors(self):
#     def ready(self):
#     def entering_number(self):
#     def in_menu(self):
#     def expecting_register(self):
#     def expecting_help(self):
#     def advisory(self, msg):
#     def error(self, msg):
#     def mark_seen(self):
#     def push_state(self):
#     def pop_state(self):
#     def save_state(self):


# Path: esc/stack.py
from contextlib import contextmanager
from decimal import Decimal
from .consts import STACKDEPTH, STACKWIDTH
from . import history
from .oops import RollbackTransaction
from .status import status
import copy
import decimal

            True if a number was finished.
            False if bos was already finished.

        Raises:
            ValueError if the value was invalid and the number couldn't be
            finished. The exception message can be displayed on the status bar.

        Set running_op to an operation name if you're entering prior to running
        an operation (go figure) for a more helpful error message in that case.
        """
        # Even if we were *not* editing the stack, checkpoint the stack state.
        # This ensures that we will get a checkpoint anytime we call an
        # operation as well as when we enter a number onto the stack.
        # Multiple checkpoints in a row do nothing, so this is safe.
        history.hs.checkpoint_stack(self)

        if self.editing_last_item:
            if self.s[self.stack_posn].finish_entry():
                self.editing_last_item = False
                return True
            else:
                if running_op:
                    msg = 'Cannot run "%s": invalid value on bos.' % running_op
                else:
                    msg = 'Bottom of stack is not a valid number.'
                raise ValueError(msg)
        else:
            return False

    def has_push_space(self, spaces):

        return STACKDEPTH >= len(self.s) + spaces