
    Ij                         d Z ddlmZ dZe dZe dZdZdedefd	Z	dde
defdZdde
defdZ G d d          Zde
dedede
dedefdZdS )zSupport for terminal control escape sequences.

These are used for things like setting the window title and asynchronous alerts.
   )string_utils[]titlereturnc                 (    t            d|  t           S )zGenerate a string that, when printed, sets a terminal's window title.

    :param title: new title for the window
    :return: the set title string
    z2;)OSCBEL)r   s    k/home/jenkins/jenkins/workspace/simtester-sanitize/venv/lib/python3.11/site-packages/cmd2/terminal_utils.pyset_title_strr      s     !!U!C!!!       
clear_typec                 X    d| cxk    rdk    rn nt            |  dS t          d          )aY  Generate a string that, when printed, clears a terminal screen based on value of clear_type.

    :param clear_type: integer which specifies how to clear the screen (Defaults to 2)
                       Possible values:
                       0 - clear from cursor to end of screen
                       1 - clear from cursor to beginning of the screen
                       2 - clear entire screen
                       3 - clear entire screen and delete all lines saved in the scrollback buffer
    :return: the clear screen string
    :raises ValueError: if clear_type is not a valid value
           Jz)clear_type must in an integer from 0 to 3CSI
ValueErrorr   s    r   clear_screen_strr      sI     	J!$z$$$$
@
A
AAr   c                 X    d| cxk    rdk    rn nt            |  dS t          d          )a  Generate a string that, when printed, clears a line based on value of clear_type.

    :param clear_type: integer which specifies how to clear the line (Defaults to 2)
                       Possible values:
                       0 - clear from cursor to the end of the line
                       1 - clear from cursor to beginning of the line
                       2 - clear entire line
    :return: the clear line string
    :raises ValueError: if clear_type is not a valid value
    r   r   Kz)clear_type must in an integer from 0 to 2r   r   s    r   clear_line_strr   .   sI     	J!$z$$$$
@
A
AAr   c                       e Zd ZdZeddedefd            Zeddedefd            Zeddedefd            Z	eddedefd            Z
ed	ed
edefd            ZdS )Cursorz3Create ANSI sequences to alter the cursor position.r   countr	   c                     t            |  dS )z?Move the cursor up a specified amount of lines (Defaults to 1).Ar   r    s    r   UPz	Cursor.UPD        ur   c                     t            |  dS )zAMove the cursor down a specified amount of lines (Defaults to 1).Br#   r$   s    r   DOWNzCursor.DOWNI   r&   r   c                     t            |  dS )zDMove the cursor forward a specified amount of lines (Defaults to 1).Cr#   r$   s    r   FORWARDzCursor.FORWARDN   r&   r   c                     t            |  dS )zAMove the cursor back a specified amount of lines (Defaults to 1).Dr#   r$   s    r   BACKzCursor.BACKS   r&   r   xyc                      t            | d|  dS )z9Set the cursor position to coordinates which are 1-based.;Hr#   )r0   r1   s     r   SET_POSzCursor.SET_POSX   s      q1r   N)r   )__name__
__module____qualname____doc__staticmethodintstrr%   r)   r,   r/   r5    r   r   r   r   A   s       ==   #  c       \     C         \     s  3       \     C         \   3  3  3       \     r   r   terminal_columnspromptlinecursor_offset	alert_msgc                 ^   |                                 pdg}d}|dd         D ].}t          j        |          }|t          || z            dz   z  }/|d         }	t          j        |	          }
|
t          j        |          z   }t          || z            dz   }|
|z   }t          || z            dz   }d}||k    r |t                              ||z
            z  }||z   }|t                      t                              d          z   |dz
  z  z  }|t                      z  }|d|z   z  }|S )a  Calculate the desired string, including ANSI escape codes, for displaying an asynchronous alert message.

    :param terminal_columns: terminal width (number of columns)
    :param prompt: current onscreen prompt
    :param line: current contents of the Readline line buffer
    :param cursor_offset: the offset of the current cursor position within line
    :param alert_msg: the message to display to the user
    :return: the correct string so that the alert message appears to the user to be printed above the current line.
     r   Nr   )
splitlinessu	str_widthr;   r   r)   r   r%   )r>   r?   r@   rA   rB   prompt_linesnum_prompt_terminal_linesprompt_lineprompt_line_widthlast_prompt_linelast_prompt_line_widthinput_widthnum_input_terminal_linescursor_input_offsetcursor_input_lineterminal_strtotal_liness                    r   async_alert_strrV   ^   su    $$&&.2$L !"#CRC( S SL55!S):=M)M%N%NQR%RR!! $B'\*:;;(2<+=+==K";1A#ABBQF 1=@ /2BBCCaG L 444$<?P$PQQQ ,.FFK^%%		!4qIIL N$$$L D9$$Lr   N)r   )r9   rD   r   rH   ESCr   r   r   r<   r   r;   r   r   r   rV   r=   r   r   <module>rX      s6   
 !          
 	iii	iii
" " " " " "B B BS B B B B"B Bs B3 B B B B&               :2 2c 2 2UX 2eh 2mp 2 2 2 2 2 2r   