Mini Shell
3
<�Zc* � @ sP d dl mZ G dd� de�ZG dd� de�ZG dd� de�ZG dd � d e�Zd
S )� )�SimplelineErrorc @ s e Zd ZdZdS )�ScreenStackExceptionzGeneral screen stack exception.N)�__name__�
__module__�__qualname__�__doc__� r r �"/usr/lib/python3.6/screen_stack.pyr s r c @ s e Zd ZdZdS )�ScreenStackEmptyExceptionz+Screen stack exception when stack is empty.N)r r r r r r r r r
s r
c @ sJ e Zd ZdZdd� Zdd� Zdd� Zdd � Zddd�Zd
d� Z dd� Z
dS )�ScreenStackz0Managing screen stack used in `ScreenScheduler`.c C s
g | _ d S )N)�_screens)�selfr r r �__init__% s zScreenStack.__init__c C s | j S )z]Test if screen stack is empty.
:return: True if empty.
:rtype: bool
)r )r
r r r �empty( s zScreenStack.emptyc C s
t | j�S )zDGet size of the stack.
:return: Size of the stack.
)�lenr )r
r r r �size0 s zScreenStack.sizec C s | j j|� dS )z�Add new screen to the top of the stack.
:param screen: Screen for the future rendering.
:type screen: Class based on `simpleline.render.ui_screen.UIScreen`.
N)r �append)r
�screenr r r r 7 s zScreenStack.appendTc C sL y|r| j j� S | j d S W n* tk
rF } zt|��W Y dd}~X nX dS )z�Return top item from the stack.
:param remove: If True (default) also remove this items from the stack.
:return: The top screen on the stack.
� N���)r �pop�
IndexErrorr
)r
�remove�er r r r ? s
zScreenStack.popc C s | j jd|� dS )z�Add `screen` to the bottom of the stack.
:param screen: Add the `screen` to the bottom of the stack.
:type screen: Class based on `simpleline.render.ui_screen.UIScreen`.
r N)r �insert)r
r r r r � add_firstM s zScreenStack.add_firstc C s@ d}|d7 }x&t | j�D ]}|t|�7 }|d7 }qW |d7 }|S )ziDump screen stack structure.
:returns: Screen stack representation.
:rtype: str
z======= Screen stack =======
z----------- TOP ------------
�
z============================
)�reversedr �str)r
�msgr r r r �
dump_stackU s zScreenStack.dump_stackN)T)r r r r r r r r r r r r r r r r "