B
    һd                 @   s:   d 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.    )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 )zConstructor 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   \/var/www/html/venv/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: %dN)
ValueError	_capacity_items_pointer)r   capacityr   r   r	   r
   ,   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 )zAdd 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_item>   s    z CursesNavigationHistory.add_itemc             C   s    | j std|| j | j _dS )zUpdate 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_positionN   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	   pointer^   s    zCursesNavigationHistory.pointerc             C   s0   | j std|  r$|  jd8  _| j | j S )zGo 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_backa   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_forwardt   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   Ztensorflow.python.debug.clir   ZRichLiner$   objectr   r   r   r   r   r	   <module>   s   