U ʗRe$Y@sUdZddlZddlZddlmZdZeed<ejdkrFeej Zne e dddl Z ddlm Z mZmZddlmZmZmZmZdd lmZdd lmZd Zd ZejZGd ddeZGdddeZGddde ZGdddej Z ej!j"Z#ej$ge#_%ej&e#_'efe(ej&dddZ"ej!j)Z*ej&ej+ge*_%ej,e*_'ej&e(dddZ)ej!j-Z.ej&ej/ej$eeeee0ej$ge._%ej,e._'ej&e1e(ee(dddZ2ej!j3Z4ej&ej5ej$eeeee0ej$ge4_%ej,e4_'ej&e(e(ee(ddd Z3ej!j6Z7ej&ej5ge7_%ej,e7_'ej&ej5e8d!d"d#Z6ej!j9Z:ej&e0ege:_%ej,e:_'ej&edd$d%Z9ej!j;Zej&e0e ge>_%ej,e>_'ej&e e8d)d*d+Z=ej!j?Z@ej&e0e ge@_%ej,e@_'ej&e e8d)d,d-Z?ej!jAZBejCgeB_%ej,eB_'e1e8d.d/d0ZDGd1d2d2ZEe d3kre"ZFdd4lGmHZHeHZIeEejJZKeKLd5ed6d7d8ZMeNd9ZOeIPd:eIQd;eIQd<eIQd=eIQd>eIQd?eIQd@eIQdAeIQdBeIQdCeIQdDeIQdEeIQdFeIQdGeIQdHeIQdIeIPdJeIQeKReKReKSdKe TdLeKUeKSdMe TdLeKVeKSdNe TdLeKUeKReKReKSdOe TdLeKVeKReKReKSdPe TdLeKWeIQeIPdQeIQdReKSdSe TdLeKXdTeKYdUeNdVeKRe TdLeKZe TdLeIQdWeKSdSe TdLeKXdTeKYdXeNdVe TdLeK[e TdLeIQdYeKjYdZeNd[d\e TdLeK\eK]eQd]dS)^zLight wrapper around the Win32 Console API - this module should only be imported on Windows The API that this module wraps is documented at https://docs.microsoft.com/en-us/windows/console/console-functions N)Anywindllwin32z can only be imported on Windows) Structurebyrefwintypes)IO NamedTupleTypecast) ColorSystem)Styleic@s eZdZdS)LegacyWindowsErrorN)__name__ __module__ __qualname__rr/builddir/build/BUILDROOT/alt-python38-pip-22.2.1-2.el8.x86_64/opt/alt/python38/lib/python3.8/site-packages/pip/_vendor/rich/_win32_console.pyrsrc@s6eZdZUdZeed<eed<ededddZdS)WindowsCoordinateszCoordinates in the Windows Console API are (y, x), not (x, y). This class is intended to prevent that confusion. Rows and columns are indexed from 0. This class can be used in place of wintypes._COORD in arguments and argtypes. rowcol)valuereturncCst|j|jS)aEConverts a WindowsCoordinates into a wintypes _COORD structure. This classmethod is internally called by ctypes to perform the conversion. Args: value (WindowsCoordinates): The input coordinates to convert. Returns: wintypes._COORD: The converted coordinates struct. )COORDrr)clsrrrr from_param*s zWindowsCoordinates.from_paramN) rrr__doc__int__annotations__ classmethodrrrrrrr s rc@s2eZdZdefdefdejfdejfdefgZdS)CONSOLE_SCREEN_BUFFER_INFOdwSizedwCursorPosition wAttributesZsrWindowZdwMaximumWindowSizeN)rrrrrWORDZ SMALL_RECT_fields_rrrrr!8s r!c@s eZdZdejfdejfgZdS)CONSOLE_CURSOR_INFOr"bVisibleN)rrrrDWORDBOOLr&rrrrr'Bsr')handlercCsttjt|S)zRetrieves a handle to the specified standard device (standard input, standard output, or standard error). Args: handle (int): Integer identifier for the handle. Defaults to -11 (stdout). Returns: wintypes.HANDLE: The handle )r rHANDLE _GetStdHandle)r+rrr GetStdHandleMs r.) std_handlercCs(t}tt||}|s"td|jS)aRetrieves the current input mode of a console's input buffer or the current output mode of a console screen buffer. Args: std_handle (wintypes.HANDLE): A handle to the console input buffer or the console screen buffer. Raises: LegacyWindowsError: If any error occurs while calling the Windows console API. Returns: int: Value representing the current console mode as documented at https://docs.microsoft.com/en-us/windows/console/getconsolemode#parameters z)Unable to get legacy Windows Console Mode)rr)bool_GetConsoleModerr)r/Z console_modesuccessrrrGetConsoleMode^s r3)r/charlengthstartrcCs<t|}t|}td}t||||t||jS)aWrites a character to the console screen buffer a specified number of times, beginning at the specified coordinates. Args: std_handle (wintypes.HANDLE): A handle to the console input buffer or the console screen buffer. char (str): The character to write. Must be a string of length 1. length (int): The number of times to write the character. start (WindowsCoordinates): The coordinates to start writing at. Returns: int: The number of characters written. r)ctypesc_charencoderr)_FillConsoleOutputCharacterWrr)r/r4r5r6 characterZnum_characters num_writtenrrrFillConsoleOutputCharacters  r=)r/ attributesr5r6rcCs8t|}t|}td}t||||t||jS)alSets the character attributes for a specified number of character cells, beginning at the specified coordinates in a screen buffer. Args: std_handle (wintypes.HANDLE): A handle to the console input buffer or the console screen buffer. attributes (int): Integer value representing the foreground and background colours of the cells. length (int): The number of cells to set the output attribute of. start (WindowsCoordinates): The coordinates of the first cell whose attributes are to be set. Returns: int: The number of cells whose attributes were actually set. r)rr)r%_FillConsoleOutputAttributerr)r/r>r5r6Z num_cellsZ style_attrsr<rrrFillConsoleOutputAttributes   r@)r/r>rcCstt||S)a|Set the colour attributes for all text written after this function is called. Args: std_handle (wintypes.HANDLE): A handle to the console input buffer or the console screen buffer. attributes (int): Integer value representing the foreground and background colours. Returns: bool: True if the attribute was set successfully, otherwise False. )r0_SetConsoleTextAttribute)r/r>rrrSetConsoleTextAttributes rBcCst}t|t||S)aqRetrieves information about the specified console screen buffer. Args: std_handle (wintypes.HANDLE): A handle to the console input buffer or the console screen buffer. Returns: CONSOLE_SCREEN_BUFFER_INFO: A CONSOLE_SCREEN_BUFFER_INFO ctype struct contain information about screen size, cursor position, colour attributes, and more.)r!_GetConsoleScreenBufferInfor)r/Zconsole_screen_buffer_inforrrGetConsoleScreenBufferInfos rD)r/coordsrcCstt||S)aESet the position of the cursor in the console screen Args: std_handle (wintypes.HANDLE): A handle to the console input buffer or the console screen buffer. coords (WindowsCoordinates): The coordinates to move the cursor to. Returns: bool: True if the function succeeds, otherwise False. )r0_SetConsoleCursorPosition)r/rErrrSetConsoleCursorPositions rG)r/ cursor_inforcCstt|t|S)aGet the cursor info - used to get cursor visibility and width Args: std_handle (wintypes.HANDLE): A handle to the console input buffer or the console screen buffer. cursor_info (CONSOLE_CURSOR_INFO): CONSOLE_CURSOR_INFO ctype struct that receives information about the console's cursor. Returns: bool: True if the function succeeds, otherwise False. )r0_GetConsoleCursorInforr/rHrrrGetConsoleCursorInfos rKcCstt|t|S)awSet the cursor info - used for adjusting cursor visibility and width Args: std_handle (wintypes.HANDLE): A handle to the console input buffer or the console screen buffer. cursor_info (CONSOLE_CURSOR_INFO): CONSOLE_CURSOR_INFO ctype struct containing the new cursor info. Returns: bool: True if the function succeeds, otherwise False. )r0_SetConsoleCursorInforrJrrrSetConsoleCursorInfo*s rMtitlercCs tt|S)zSets the title of the current console window Args: title (str): The new title of the console window. Returns: bool: True if the function succeeds, otherwise False. )r0_SetConsoleTitle)rOrrrSetConsoleTitle>s rQc@sJeZdZdZdZddddddd d dd d d ddddgZdddddZeedddZ eedddZ e ddddZ e e ddd d!Zedd"d#d$Zddd%d&Zddd'd(Zddd)d*Zddd+d,Zddd-d.Zddd/d0Zedd1d2d3Zddd4d5Zddd6d7Zddd8d9Ze dd:d;d<Zedd=d>ZdS)?LegacyWindowsTermaThis class allows interaction with the legacy Windows Console API. It should only be used in the context of environments where virtual terminal processing is not available. However, if it is used in a Windows environment, the entire API should work. Args: file (IO[str]): The file which the Windows Console API HANDLE is retrieved from, defaults to sys.stdout. rr  zIO[str]N)filercCsbtt}||_t|j}||_|d@|_|d?d@|_|j|jd>B|_||_ |j |_ |j |_ dS)NrYr) r.STDOUT_handlerDr$ _default_text _default_fore _default_back_default_attrs_filewriteflush)selfrar+Z default_textrrr__init__is  zLegacyWindowsTerm.__init__)rcCs(t|jj}ttt|jtt|jdS)zReturns the current position of the cursor (0-based) Returns: WindowsCoordinates: The current cursor position. rr)rDrcr#rr rYX)rkZcoordrrrcursor_positionws z!LegacyWindowsTerm.cursor_positioncCs(t|jj}ttt|jtt|jdS)zReturns the current size of the console screen buffer, in character columns and rows Returns: WindowsCoordinates: The width and height of the screen as WindowsCoordinates. rm)rDrcr"rr rrnro)rk screen_sizerrrrqs   zLegacyWindowsTerm.screen_size)textrcCs|||dS)zWrite text directly to the terminal without any modification of styles Args: text (str): The text to write to the console N)rirj)rkrrrrr write_texts zLegacyWindowsTerm.write_text)rrstylercCs|j}|j}|jr||}}|rl|tjj}|dk r:|nd}|jrN||jB}|j r`||j@}|j |}n|j }|r|tjj}|dk r|nd}|j |}n|j }|dk st |dk st t|jt||d>Bd||t|j|jddS)zWrite styled text to the terminal. Args: text (str): The text to write style (Style): The style of the text NrYrr)r>)colorbgcolorreverse downgrader WINDOWSnumberbold BRIGHT_BITdimANSI_TO_WINDOWSrerfAssertionErrorrBrcr7Zc_ushortrsrd)rkrrrtrurvforebackrrr write_styleds4        zLegacyWindowsTerm.write_styled) new_positionrcCs*|jdks|jdkrdSt|j|ddS)zSet the position of the cursor Args: new_position (WindowsCoordinates): The WindowsCoordinates representing the new position of the cursor. rNrE)rrrGrc)rkrrrrmove_cursor_tosz LegacyWindowsTerm.move_cursor_tocCsJ|j}|j}|j}t|jdd}t|jd||dt|j|j||ddS)z@Erase all content on the line the cursor is currently located atrrm r5r6N) rqrprrrr=rcr@rg)rkrqrpcells_to_eraseZstart_coordinatesrrr erase_lines zLegacyWindowsTerm.erase_linecCs>|j}|jj|j}t|jd||dt|j|j||ddS)zBErase all content from the cursor position to the end of that linerrN)rprqrr=rcr@rg)rkrprrrrerase_end_of_linesz#LegacyWindowsTerm.erase_end_of_linecCs>|j\}}t|d}t|jd||dt|j|j||ddS)zDErase all content from the cursor position to the start of that linerrrN)rprr=rcr@rg)rkrrr6rrrerase_start_of_lines  z%LegacyWindowsTerm.erase_start_of_linecCs(|j}t|jt|jd|jdddS)z Move the cursor up a single cellrVrmrNrprGrcrrrrkrprrrmove_cursor_upsz LegacyWindowsTerm.move_cursor_upcCs(|j}t|jt|jd|jdddS)z"Move the cursor down a single cellrVrmrNrrrrrmove_cursor_downsz"LegacyWindowsTerm.move_cursor_downcCsJ|j\}}||jjdkr(|d7}d}n|d7}t|jt||dddS)zIMove the cursor forward a single cell. Wrap to the next line if required.rVrrmrNrprqrrGrcrrkrrrrrmove_cursor_forwards  z%LegacyWindowsTerm.move_cursor_forward)columnrcCs"|j\}}t|jt||ddS)zMove cursor to the column specified by the zero-based column index, staying on the same row Args: column (int): The zero-based column index to move the cursor to. rN)rprGrcr)rkrr_rrrmove_cursor_to_columns z'LegacyWindowsTerm.move_cursor_to_columncCsJ|j\}}|dkr(|d8}|jjd}n|d8}t|jt||dddS)zNMove the cursor backward a single cell. Wrap to the previous line if required.rrVrmrNrrrrrmove_cursor_backwards  z&LegacyWindowsTerm.move_cursor_backwardcCs&|}t|dd}t|j|ddS)zHide the cursorrr"r(rHN_get_cursor_sizer'rMrc)rkcurrent_cursor_sizeZinvisible_cursorrrr hide_cursor$s zLegacyWindowsTerm.hide_cursorcCs&|}t|dd}t|j|ddS)zShow the cursorrVrrNr)rkrZvisible_cursorrrr show_cursor*s zLegacyWindowsTerm.show_cursorrNcCs t|dkstdt|dS)zySet the title of the terminal window Args: title (str): The new title of the console window z.Console title must be less than 255 charactersN)lenrrQ)rkrOrrr set_title0szLegacyWindowsTerm.set_titlecCst}t|j|dt|jS)zEGet the percentage of the character cell that is filled by the cursorr)r'rKrcrr")rkrHrrrr9sz"LegacyWindowsTerm._get_cursor_size)rrrrr|r~rlpropertyrrprqstrrsr rrrrrrrrrrrrrrrrrrrrRJsN   '        rR__main__)ConsolezWin32 Console Examplesblackred)rurvzblack on greenzChecking colour outputz[on red]on red!z [blue]blue!z[yellow]yellow!z[bold yellow]bold yellow!z[bright_yellow]bright_yellow!z%[dim bright_yellow]dim bright_yellow!z[italic cyan]italic cyan!z'[bold white on blue]bold white on blue!z7[reverse bold white on blue]reverse bold white on blue!z'[bold black on cyan]bold black on cyan!z[black on green]black on green!z[blue on green]blue on green!z[white on black]white on black!z[black on white]black on white!z'[#1BB152 on #DA812D]#1BB152 on #DA812D!zChecking cursor movementz"went back and wrapped to prev linerVzwe go upzand downzwe went up and back 2zwe went down and back 2zChecking line erasingz( ...Deleting to the start of the line...z?The red arrow shows the cursor location, and direction of erasez) ...Now the whole line will be erased...zI'm going to disappear!z black on cyan)rt )^rr7systypingrrrplatformZ LibraryLoaderZWinDLL ImportErrorrtimerrrrr r r pip._vendor.rich.colorr pip._vendor.rich.styler rbZ"ENABLE_VIRTUAL_TERMINAL_PROCESSINGZ_COORDr Exceptionrrr!r'kernel32r.r-r)Zargtypesr,restyperr3r1ZLPDWORDr*ZFillConsoleOutputCharacterWr:r8ZPOINTERrr=r@r?r%rBrAr0rDrCrGrFrKrIrMrLZSetConsoleTitleWrPZLPCWSTRrQrRr+pip._vendor.rich.consolerconsolestdouttermrrtparseheadingruleprintrrssleeprrrrrrrrrrrrrsd                     w