B
    )²ô`  ã               @   s^   d Z ddlmZ ddlmZ ddlmZ ddlmZ ejZG dd„ de	ƒZ
G dd	„ d	e	ƒZd
S )zWidgets for Curses-based CLI.é    )Úabsolute_import)Údivision)Úprint_function)Údebugger_cli_commonc               @   s   e Zd ZdZdd„ ZdS )ÚNavigationHistoryItemz&Individual item in navigation history.c             C   s   || _ || _|| _dS )zßConstructor of NavigationHistoryItem.

    Args:
      command: (`str`) the command line text.
      screen_output: the screen output of the command.
      scroll_position: (`int`) scroll position in the screen output.
    N)ÚcommandÚscreen_outputÚscroll_position)Úselfr   r   r	   © r   úY/home/dcms/DCMS/lib/python3.7/site-packages/tensorflow/python/debug/cli/curses_widgets.pyÚ__init__   s    zNavigationHistoryItem.__init__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r      s   r   c               @   sj   e Zd ZdZdZdZdd„ Zdd„ Zdd	„ Zd
d„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zddd„ZdS )ÚCursesNavigationHistoryz@Navigation history containing commands, outputs and scroll info.z<--z-->c             C   s*   |dkrt d| ƒ‚|| _g | _d| _dS )a'  Constructor of CursesNavigationHistory.

    Args:
      capacity: (`int`) How many items this object can hold. Each item consists
        of a command stirng, an output RichTextLines object and a scroll
        position.

    Raises:
      ValueError: If capacity is not a positive number.
    r   zIn valid capacity value: %déÿÿÿÿN)Ú
ValueErrorÚ	_capacityÚ_itemsÚ_pointer)r
   Úcapacityr   r   r   r   0   s
    z CursesNavigationHistory.__init__c             C   sv   | j d t| jƒk r*| jd| j d … | _| j t|||ƒ¡ t| jƒ| jkrb| j| j d… | _t| jƒd | _ dS )zÚAdd an item to the navigation histoyr.

    Args:
      command: command line text.
      screen_output: screen output produced for the command.
      scroll_position: (`int`) scroll position in the screen output.
    é   N)r   Úlenr   Úappendr   r   )r
   r   r   r	   r   r   r   Úadd_itemB   s    z CursesNavigationHistory.add_itemc             C   s    | j stdƒ‚|| j | j _dS )zÊUpdate the scroll position of the currently-pointed-to history item.

    Args:
      new_scroll_position: (`int`) new scroll-position value.

    Raises:
      ValueError: If the history is empty.
    zEmpty navigation historyN)r   r   r   r	   )r
   Znew_scroll_positionr   r   r   Úupdate_scroll_positionR   s    	z.CursesNavigationHistory.update_scroll_positionc             C   s
   t | jƒS )N)r   r   )r
   r   r   r   Úsize_   s    zCursesNavigationHistory.sizec             C   s   | j S )N)r   )r
   r   r   r   Úpointerb   s    zCursesNavigationHistory.pointerc             C   s0   | j stdƒ‚|  ¡ r$|  jd8  _| j | j S )zýGo back one place in the history, if possible.

    Decrease the pointer value by 1, if possible. Otherwise, the pointer value
    will be unchanged.

    Returns:
      The updated pointer value.

    Raises:
      ValueError: If history is empty.
    zEmpty navigation historyr   )r   r   Úcan_go_backr   )r
   r   r   r   Úgo_backe   s
    zCursesNavigationHistory.go_backc             C   s0   | j stdƒ‚|  ¡ r$|  jd7  _| j | j S )a   Go forward one place in the history, if possible.

    Increase the pointer value by 1, if possible. Otherwise, the pointer value
    will be unchanged.

    Returns:
      The updated pointer value.

    Raises:
      ValueError: If history is empty.
    zEmpty navigation historyr   )r   r   Úcan_go_forwardr   )r
   r   r   r   Ú
go_forwardx   s
    z"CursesNavigationHistory.go_forwardc             C   s
   | j dkS )zvTest whether client can go back one place.

    Returns:
      (`bool`) Whether going back one place is possible.
    r   )r   )r
   r   r   r   r    ‹   s    z#CursesNavigationHistory.can_go_backc             C   s   | j d t| jƒk S )zyTest whether client can go forward one place.

    Returns:
      (`bool`) Whether going back one place is possible.
    r   )r   r   r   )r
   r   r   r   r"   “   s    z&CursesNavigationHistory.can_go_forwardÚblack_on_whiteÚmagenta_on_whitec       	      C   s  t dƒ}|t | j|  ¡ r$t d|¡ndƒ7 }|t dƒ7 }|t | j|  ¡ rTt d|¡ndƒ7 }| jrø| jt	| jƒd krz|n|}|t dƒ7 }| jt	| jƒd krÀ|t dt	| jƒd | j  |ƒ7 }t	|ƒ|k rø| j| j j
d|t	|ƒ … }|t ||ƒ7 }t |g¡S )at  Render the rich text content of the single-line navigation bar.

    Args:
      max_length: (`int`) Maximum length of the navigation bar, in characters.
      backward_command: (`str`) command for going backward. Used to construct
        the shortcut menu item.
      forward_command: (`str`) command for going forward. Used to construct the
        shortcut menu item.
       latest_command_attribute: font attribute for lastest command.
       old_command_attribute: font attribute for old (non-latest) command.

    Returns:
      (`debugger_cli_common.RichTextLines`) the navigation bar text with
        attributes.

    z| Nú r   z | z(-%d) )ÚRLÚBACK_ARROW_TEXTr    r   ZMenuItemÚFORWARD_ARROW_TEXTr"   r   r   r   r   Z#rich_text_lines_from_rich_line_list)	r
   Ú
max_lengthZbackward_commandZforward_commandZlatest_command_attributeZold_command_attributeÚoutputZcommand_attributeZmaybe_truncated_commandr   r   r   Úrender›   s(    zCursesNavigationHistory.renderN)r$   r%   )r   r   r   r   r(   r)   r   r   r   r   r   r!   r#   r    r"   r,   r   r   r   r   r   *   s    r   N)r   Ú
__future__r   r   r   Ztensorflow.python.debug.clir   ZRichLiner'   Úobjectr   r   r   r   r   r   Ú<module>   s   