
    hh[%                     ^    d Z ddlmZ ddlmZ ddlmZ ddlZddlZddlmZ  G d de	      Z
y)	zSimple console pager.    )absolute_import)division)unicode_literalsN)console_attrc                   8    e Zd ZdZdZdZd
dZd Zd Zd Z	d	 Z
y)Pagera"  A simple console text pager.

  This pager requires the entire contents to be available. The contents are
  written one page of lines at a time. The prompt is written after each page of
  lines. A one character response is expected. See HELP_TEXT below for more
  info.

  The contents are written as is. For example, ANSI control codes will be in
  effect. This is different from pagers like more(1) which is ANSI control code
  agnostic and miscalculates line lengths, and less(1) which displays control
  character names by default.

  Attributes:
    _attr: The current ConsoleAttr handle.
    _clear: A string that clears the prompt when written to _out.
    _contents: The entire contents of the text lines to page.
    _height: The terminal height in characters.
    _out: The output stream, log.out (effectively) if None.
    _prompt: The page break prompt.
    _search_direction: The search direction command, n:forward, N:reverse.
    _search_pattern: The current forward/reverse search compiled RE.
    _width: The termonal width in characters.
  aI  
  Simple pager commands:

    b, ^B, <PAGE-UP>, <LEFT-ARROW>
      Back one page.
    f, ^F, <SPACE>, <PAGE-DOWN>, <RIGHT-ARROW>
      Forward one page. Does not quit if there are no more lines.
    g, <HOME>
      Back to the first page.
    <number>g
      Go to <number> lines from the top.
    G, <END>
      Forward to the last page.
    <number>G
      Go to <number> lines from the bottom.
    h
      Print pager command help.
    j, +, <DOWN-ARROW>
      Forward one line.
    k, -, <UP-ARROW>
      Back one line.
    /pattern
      Forward search for pattern.
    ?pattern
      Backward search for pattern.
    n
      Repeat current search.
    N
      Repeat current search in the opposite direction.
    q, Q, ^C, ^D, ^Z
      Quit return to the caller.
    any other character
      Prompt again.

  Hit any key to continue:)r	   Nc                    || _         |xs t        j                  | _        d| _        d| _        | j                  \  | _        | _        t        j                         | _        | j                  j                         \  | _        | _        |sEdj                  | j                  j!                  d      | j                  j!                               }dj                  d| j                  j#                  |      dz
  z        | _        || _        g | _        |j+                         D ];  }| xj(                  | j                  j-                  || j                        z  c_        = y)	zConstructor.

    Args:
      contents: The entire contents of the text lines to page.
      out: The output stream, log.out (effectively) if None.
      prompt: The page break prompt, a default prompt is used if None..
    Nz {bold}--({{percent}}%)--{normal}T)bold)r   normalz{0}    )	_contentssysstdout_out_search_pattern_search_directionPREV_POS_NXT_REPRINTprev_posprev_nxtr   GetConsoleAttr_attrGetTermSize_width_heightformatGetFontCodeDisplayWidth_clear_prompt_lines
splitlines	SplitLine)selfcontentsoutpromptlines        X/var/www/html/dev/engine/venv/lib/python3.12/site-packages/fire/console/console_pager.py__init__zPager.__init__[   s#    DN!szzDID!D $(#<#< DM4=,,.DJ $

 6 6 8DK 188zz%%4%0'') 9 +f ""3$***A*A&*IA*M#NODKDL DK##% =
kkTZZ))$<<k=    c                 :    | j                   j                  |       y)z+Mockable helper that writes s to self._out.N)r   write)r%   ss     r*   _WritezPager._Write|   s    IIOOAr,   c                    | j                  |       d}	 | j                  j                         }|dv st        |      dk7  rn| j                  |       ||z  }D| j                  ddt        |      z  z   dz          |r	 t	        j
                  |      | _        |dk(  rd| _        yd	| _        y# t        j                  $ r
 d| _        Y yw xY w)
a  Consumes a search command and returns the equivalent pager command.

    The search pattern is an RE that is pre-compiled and cached for subsequent
    /<newline>, ?<newline>, n, or N commands.

    Args:
      c: The search command char.

    Returns:
      The pager command char.
     )N
   r4   r   N/nN)	r0   r   	GetRawKeylenrecompiler   errorr   )r%   cbufps       r*   _GetSearchCommandzPager._GetSearchCommand   s     	KKN
C

**


 a	
 	 CFaK
kk!n	Qhc  	KKsSX~%,-
!zz#
 %&HSD 36D XX #s   ?B. .C
Cc                 R   | j                   t        | j                        t        | j                  j                  dd            z
  z
  }|dkD  r| j	                  d|z         | j	                  | j                         | j
                  j                          | j	                  d       y)z:Print command help and wait for any character to continue.r3   r2   r   N)r   r:   	HELP_TEXTreplacer0   r   r9   )r%   clears     r*   _HelpzPager._Help   s~    LLC/ 6 6tR @AB CEqy
kk$,KKJJKKr,   c                 	   t        | j                        | j                  k  r| j                  | j                         yd}| xj                  dz  c_        d}|t        | j                        k  r|| j                  z   }|t        | j                        kD  r$t        | j                        }|| j                  z
  }| j
                  |cxk  r| j                  k  r>n n;| j                  dj                  | j                  | j                  |       dz          nN|| j
                  k7  r?|| j                  k7  r0| j                  dj                  | j                  ||       dz          | j                  j                  d|z  t        | j                        z        }d}	 |r||c| _        | _        d	}| j                  |       | j                  j                         }| j                  | j                         |d
v ry|dv r| j                  |      }n|j                         r||z  }|rt        |      }d}nd}|dv r|| j                  z
  }|dk  rd}n	|dv rE|t        | j                        k\  r|| j                  z   }|t        | j                        k\  r|}n|dv rV|dz
  }|t        | j                        | j                  z
  kD  r"t        | j                        | j                  z
  }|dk  rjd}nf|dv rgt        | j                        |z
  }|t        | j                        | j                  z
  kD  r"t        | j                        | j                  z
  }|dk  rd}n|dk(  r,| j!                          | j"                  \  | _        | _        |}n|dv r:|t        | j                        k\  r|dz   }|t        | j                        k\  r|}n|dv r|dz
  }|dk  r~d}n{|dv ru| j$                  sZ|}|}|| j&                  k(  rdnd}		 ||	z  }|dk  s|t        | j                        k\  rn.| j$                  j)                  | j                  |         r|}nO||k7  rd}n|}|t        | j                        k  ryy)zRun the pager.NTr5   r   r3   d   )percentr2   F)NqQ)r6   ?)z	<PAGE-UP>z<LEFT-ARROW>b)z<PAGE-DOWN>z<RIGHT-ARROW>fr   )z<HOME>g)z<END>Gh)z<DOWN-ARROW>j+r3   r4   )z
<UP-ARROW>k-)r7   r8   r	   )r:   r"   r   r0   r   r   r   joinr!   r   r   r9   r    rA   isdigitintrF   r   r   r   search)
r%   reset_prev_valuesposnxtrI   digitsr>   counti	directions
             r*   Runz	Pager.Run   s.    4;;4<<'
kk$..! LLAL C
DKK 
 $,,c	s4;;	$++DLL  
	,t}}	,DIIdkk$--<=DE$--C4==$8DIIdkk#c23d:; ##C#IT[[9I,I#Jgf),c
&$-#
GJJ  "DKK     *_$$Q'!YY[
A+&
 f+%&% ::dll"#1WCDDC$$dll"#C$$C/!	#3t{{#dll22dkk"T\\1C1WC. DKK 5(#3t{{#dll22dkk"T\\1C1WC#X
**,)-)B)B
&$-#
88C$$a#C$$C**a#1WC*_%%#! 6 66aB)NA1uS--##**4;;q>:c  #: #

E F ci DKK 
 r,   )NN)__name__
__module____qualname____doc__rC   r   r+   r0   rA   rF   re    r,   r*   r   r      s2    0")H  =B>Br,   r   )ri   
__future__r   r   r   r;   r   fire.consoler   objectr   rj   r,   r*   <module>rn      s*      &  ' 	 
 %OF Or,   