# 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

    def restore(self, memento):
        """
        Restore the current object to a prior state checkpointed by calling
        memento().
        """
        self.__dict__.clear()
        self.__dict__.update(memento)
        self.editing_last_item = self._editing_last_item  # force property logic to run

    @contextmanager
    def transaction(self):
        """
        Context manager to start a stack transaction. If an exception occurs
        during the run, any changes made to the StackState will be rolled back
        before re-raising the exception. Otherwise, changes will persist.

        Raising the special exception RollbackTransaction causes the
        transaction to be rolled back but no exception to be raised. In
        addition, the message provided on RollbackTransaction will be set as
        a status-bar error. It's difficult for the caller to do this
        themselves because the act of rolling back will set the status to
        "ready" or "insert".
        """
        checkpoint = self.memento()
        try:
            yield
        except RollbackTransaction as e:
            self.restore(checkpoint)
            if e.status_message:

# 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


    def restore(self, memento):
        """
        Restore the current object to a prior state checkpointed by calling
        memento().
        """
        self.__dict__.clear()
        self.__dict__.update(memento)
        self.editing_last_item = self._editing_last_item  # force property logic to run

    @contextmanager
    def transaction(self):
        """
        Context manager to start a stack transaction. If an exception occurs
        during the run, any changes made to the StackState will be rolled back
        before re-raising the exception. Otherwise, changes will persist.

        Raising the special exception RollbackTransaction causes the
        transaction to be rolled back but no exception to be raised. In
        addition, the message provided on RollbackTransaction will be set as
        a status-bar error. It's difficult for the caller to do this
        themselves because the act of rolling back will set the status to
        "ready" or "insert".
        """
        checkpoint = self.memento()
        try:
            yield
        except RollbackTransaction as e:
            self.restore(checkpoint)
            if e.status_message:

                status.error(e.status_message)