
    
8d                    l   d Z ddlmZ ddlZddlZddlZddlZddlmZ ddl	Z	ddl
mZ ddlZddlmZ ddlmZmZmZmZ ddlmZ dd	lmZmZmZ dd
lmZ ddlmZ ddlmZmZm Z m!Z! ddl"m#Z# ddl$m%Z% ddl&m'Z' ddl(m)Z) ddl*m+Z+ d Z,d Z- G d d ede eej.                  fi                     Z/dS )z0An abstract base class for console-type widgets.    )partialNdedent)category)QT6)QtCoreQtGuiQtPrintSupport	QtWidgets)HtmlExporter)MetaQObjectHasTraitsget_fontsuperQ)	columnize)LoggingConfigurable)BoolEnumIntegerUnicode   )QtAnsiCodeProcessor)CompletionWidget)CompletionHtml)CompletionPlain)
QtKillRingc                 t    t          |           }|                    d          p|                    d          S )zN Returns whether the specified unicode character is a letter or a number.
    LNr   
startswith)charcats     8lib/python3.11/site-packages/qtconsole/console_widget.pyis_letter_or_numberr$   !   s2     4..C>>#5#.."5"55    c                 F    t          |                               d          S )z1Check whether a given char counts as white space.Zr   )r!   s    r#   is_whitespacer(   '   s    D>>$$S)))r%   c                       e Zd ZdZ eddd          Z eddd          Z eddd          Z e	g ddd	d
          Z
 eddd          Z e	ddgddd          Z e	g dddd          Z eddd          Z edd          Zd Z edd          Z eddd          Z eddd          Z ed          ZdZdZ ej        e          Z ej        e          Z ej        e          Z ej        e          Z ej        e j!                  Z"dZ#dZ$dZ%ej&        j'        ej&        j(        ej&        j)        ej&        j*        ej&        j+        ej&        j,        ej&        j-        ej&        j.        ej&        j/        ej&        j0        ej&        j1        ej&        j2        iZ3e4j5        dk    sej&        j6        e3ej&        j7        <    e8e39                                          ej&        j:        ej&        j;        ej&        j<        ej&        j=        hz  Z>dZ?d fd 	Z@d! ZAd" ZBd# ZC fd$ZDd% ZE eddd&          ZF ed'dd(          ZGd) ZHd* ZId+ ZJdd,ZKd- ZLd. ZMd/ ZNd0 ZOdd2ZPd3 ZQdd4ZRd5 ZSd6 ZTd7 ZUdd8ZVd9 ZW eXeVeW          ZYd: ZZdd;Z[d< Z\ eXeZe\          Z]d= Z^d> Z_e j`        ja        fd?Zbdd@ZcdA ZddB ZedC ZfdD ZgdE ZhdF ZidG ZjdH ZkdI ZldJ Zm eXelem          ZndK ZodL ZpdM ZqdN ZrdO ZsdP ZtdQ ZudR ZvddSZwddTZxddUZyddVZzddWZ{dX Z|dY Z}dZ Z~dd[Zd\ Zdd]Zd^ Zd_ Zd` Zda Zdb Zdc ZddeZdf Zdg Zdh Zdi Zdj Zdk Zdl Zdm Zdn Zdo Zdp ZddqZdr Zds ZeXdt             ZeXdu             Zdv Zdw Zdx Zdy ZddzZdd{Zdd|Zd} Zd~ Zd Zd ZddZd Zd Zd Zd Zd ZddZd Zd Zd ZddZddZd Zd Z	 	 ddZd Zd Z xZS )ConsoleWidgeta   An abstract base class for console-type widgets. This class has
        functionality for:

            * Maintaining a prompt and editing region
            * Providing the traditional Unix-style console keyboard shortcuts
            * Performing tab completion
            * Paging text
            * Handling ANSI escape codes

        ConsoleWidget also provides a number of utility methods that will be
        convenient to implementors of a console-style widget.
    Tz%Whether to process ANSI escape codes.)confighelpi  z
        The maximum number of lines of text before truncation. Specifying a
        non-positive number disables text truncation (not recommended).
        a  Whether to automatically execute on syntactically complete input.

        If False, Shift-Enter is required to submit each execution.
        Disabling this is mainly useful for non-Python kernels,
        where the completion check would be wrong.
        )plaindroplistncursesr/   aP  
                    The type of completer to use. Valid values are:

                    'plain'   : Show the available completion as a text list
                                Below the editing area.
                    'droplist': Show the completion in a drop down list navigable
                                by the arrow keys, and from which you can select
                                completion by pressing Return.
                    'ncurses' : Show the completion as a text list which is navigable by
                                `tab` and arrow keys.
                    )r+   default_valuer,   r   z
        Set Height for completion.

        'droplist'
            Height in pixels.
        'ncurses'
            Maximum number of rows.
        r-   richz
        The type of underlying text widget to use. Valid values are 'plain',
        which specifies a QPlainTextEdit, and 'rich', which specifies a
        QTextEdit.
        )r0   r+   r,   )insidehsplitvsplitcustomnoner2   a\  
        The type of paging to use. Valid values are:

        'inside'
           The widget pages like a traditional terminal.
        'hsplit'
           When paging is requested, the widget is split horizontally. The top
           pane contains the console, and the bottom pane contains the paged text.
        'vsplit'
           Similar to 'hsplit', except that a vertical splitter is used.
        'custom'
           No action is taken by the widget beyond emitting a
           'custom_page_requested(str)' signal.
        'none'
           The text is written directly to the console.
        zVThe visibility of the scrollar. If False then the scrollbar will be
        invisible.zThe font family to use for the console.
        On OSX this defaults to Monaco, on Windows the default is
        Consolas with fallback of Courier, and on other platforms
        the default is Monospace.
        c                 N    t           j        dk    rdS t           j        dk    rdS dS )Nwin32ConsolasdarwinMonaco	Monospace)sysplatformselfs    r#   _font_family_defaultz"ConsoleWidget._font_family_default   s-    <7"":\X%%8 ;r%   z`The font size. If unconfigured, Qt will be entrusted
        with the size of the font.
        Q   zrThe width of the console at start time in number
        of characters (will double with `hsplit` paging)
           zsThe height of the console at start time in number
        of characters (will double with `vsplit` paging)
        FNr:   c                     t                      j        d!i | |r|                     |           d| _        d| _        d| _        t          j        j        g| _	        t          t          j        d          r)| j	                            t          j        j                   t          j        |           }|                    dddd           |                                 | _        | j        dv rt          j                    | _        | j        dk    r*| j                            t          j        j                   n)| j                            t          j        j                   | j                            | j                   |                    | j                   n|                    | j                   | j        dv rs|                                 | _        | j        r9| j                                         | j                            | j                   n|                    | j                   | j                                        | _        t?                      | _         | j!        dk    rtE          | | j#                  | _$        nE| j!        d	k    rtK          | | j#                  | _$        n| j!        d
k    rtM          |           | _$        d| _'        d| _(        d| _)        d| _*        tW          | j                  | _,        d| _-        d| _.        t_          | j                  | _0        d| _1        d| _2        | j                                        | _3        d| _4        d| _5        d| _6        d| _7        g | _8        t          j9        | j                  | _:        | j:        ;                    d           | j:        <                    d           | j:        j=        >                    | j?                   | @                                 t          jA        dd          }|B                    d           t          jD        t          jD        jE                  }|F                    d          rt          jH        dk    rd}|I                    |           |J                    t          j        jK                   |jL        >                    | jM                   | N                    |           || _O        t          jA        dd          }|I                    t          jD        jP                   |J                    t          j        jK                   |jL        >                    | jQ                   | N                    |           || _R        t          jA        dd          }|B                    d           t          jD        t          jD        jS                  }|F                    d          rt          jH        dk    rd}|I                    |           |J                    t          j        jK                   |jL        >                    | jT                   | N                    |           || _U        t          jA        d| t          jD        jV        t          j        jK        d| jW                  | _X        | N                    | jX                   t          jA        d| t          jD        jY        t          j        jK        d| jZ                  | _[        | N                    | j[                   t          jA        d| dt          j        jK        d | j@                  | _\        | N                    | j\                   | ]                    d           dS )"z Create a ConsoleWidget.

        Parameters
        ----------
        parent : QWidget, optional [default None]
            The parent for this widget.
        Ng?NativeGesturer   )r3   r4   r3   )r2   r3   r4   r/   r.   r-   z> F    d   TPrintzCtrl+Pr:   zCtrl+Shift+PzSave as HTML/XMLz
Select AllzCtrl+AzCtrl+Shift+AzBigger Fontz#Increase the font size by one point)shortcutshortcutContext	statusTip	triggeredzSmaller Fontz#Decrease the font size by one pointzNormal FontzCtrl+0zRestore the Normal font size )^super__init__	setParent_is_complete_msg_id_is_complete_timeout_is_complete_max_timer   QEventWheel_pager_scroll_eventshasattrappendrE   r   QStackedLayoutsetContentsMargins_create_control_controlpaging	QSplitter	_splittersetOrientationQt
HorizontalVertical	addWidget_create_page_control_page_controlhide
textCursor_append_before_prompt_cursorr   _ansi_processorgui_completionr   gui_completion_height_completion_widgetr   r   _continuation_prompt_continuation_prompt_html
_executing_filter_resizer   _html_exporter_input_buffer_executing_input_buffer_pendingr   
_kill_ring_prompt_prompt_html_prompt_cursor_prompt_sep_reading_reading_callback
_tab_width_pending_insert_textQTimer_pending_text_flush_intervalsetIntervalsetSingleShottimeoutconnect_on_flush_pending_stream_timer
reset_fontQAction
setEnabledr	   QKeySequencerI   matchesr=   r>   setShortcutsetShortcutContextWidgetWithChildrenShortcutrM   print_	addActionprint_actionSaveexport_htmlexport_action	SelectAllselect_all_smartselect_all_actionZoomIn_increase_font_sizeincrease_font_sizeZoomOut_decrease_font_sizedecrease_font_sizereset_font_sizesetAcceptDrops)r@   parentkwlayoutactionprintkey	selectall	__class__s          r#   rP   zConsoleWidget.__init__   s    	2 	#NN6"""#' $'!%)"
 &,]%8$9!6=/22 	J%,,V]-HIII )$//!!!Q1---,,..;...&022DN{h&&--fi.BCCCC--fi.@AAAN$$T]333T^,,,,T]+++ ;888!%!:!:!<!<D~ 5"'')))(();<<<<  !3444 -1M,D,D,F,F)244)++&4T4;U&V&VD## J..&6tT=W&X&XD## G++&5d&;&;D#$(!)-&#*4=99')$%'"$T]33 "m6688!% %'!
 -3M$-,H,H))55c:::)77===)199,0,O	Q 	Q 	Q 	 "7D11$%e&8&>??H%% 	&#,(*B*B &H8$$$!!&)"FGGG  ---v""#5t<<5-2333!!&)"FGGG  !1222v#"<66$&u'9'CDD	X&& 	'3<8+C+C 'I9%%%!!&)"FGGG  !6777v!'"+"3M+2 &	 D?2#4 #4 #4 	t.///"+"3N+3 &	 D?2#4 #4 #4 	t.///(0! &	 D8/ +  +  + 	t+,,, 	D!!!!!r%   c                    |                                                                 r:|                    t          j        j                   |                                 d S |                                                                 r:|                    t          j        j                   |                                 d S d S N)	mimeDatahasUrlssetDropActionr   rb   
LinkActionaccepthasText
CopyAction)r@   es     r#   dragEnterEventzConsoleWidget.dragEnterEvent  s    ::<<!! 		 OOFI0111HHJJJJJZZ\\!!## 	 OOFI0111HHJJJJJ		 	r%   c                 :   |                                                                 rd S |                                                                 r| j                            |                                          }|                     |                                          r?|                    t          j
        j                   | j                            |           n$|                    t          j
        j                   |                                 d S d S r   )r   r   r   r]   cursorForPositionpos
_in_bufferpositionr   r   rb   r   setTextCursorIgnoreActionr   )r@   r   cursors      r#   dragMoveEventzConsoleWidget.dragMoveEvent  s    ::<<!! 		DZZ\\!!## 	]44QUUWW==Fv0011 8	 4555++F3333	 6777HHJJJJJ	 	r%   c                    |                                                                 r|                                  | j                                        }d |                                                                 D             }d                    d |D                       }|                     ||           d S |                                                                 r| j        	                    |
                                          }|                     |                                          r@|                                                                 }|                     ||           d S d S d S )Nc                 6    g | ]}|                                 S rN   )toLocalFile).0urls     r#   
<listcomp>z+ConsoleWidget.dropEvent.<locals>.<listcomp>  s"    JJJs**JJJr%   z, c              3   N   K   | ] }d |                     d d          z   d z   V  !dS )'z'"'"'N)replace)r   fs     r#   	<genexpr>z*ConsoleWidget.dropEvent.<locals>.<genexpr>  sN       1 1!" !199S)#<#<<sB 1 1 1 1 1 1r%   )r   r   _keep_cursor_in_bufferr]   ri   urlsjoin_insert_plain_text_into_bufferr   r   r   r   r   text)r@   r   r   	filenamesr   s        r#   	dropEventzConsoleWidget.dropEvent  s\   ::<<!! 	B'')))]--//FJJajjll6G6G6I6IJJJI99 1 1&/1 1 1 1 1D//=====ZZ\\!!## 	B]44QUUWW==Fv0011 Bzz||((**33FDAAAAA		B 	BB Br%   c                    |                                 }|t          j        j        k    r|                                }|                     |                                          r||| j        v rst          j	        t          j        j        | j        |         t          j
        j                  }t          j                                                            ||           dS || j        k    r|                     |          S || j        k    r|                     |          S nt)          |dd          r|t          j        j        k    r|                                t          j
        j        k    r|| j                                        k    rl| j                            |                                          }| j                            |           |                     t          j        j                   dS |t          j        j        k    r]| j         sVd| _         t          j                                                            ||           | !                                 d| _         dS |t          j        j"        k    r^| j#        rW|                     |                                          r0|                                | j$        v r|%                                 n|| j&        v r&|| j        k    r| j        '                                 dS |t          j        j(        k    r| j        )                    |                                          }tT          r'|+                                ,                                }n|-                                }t          j.        /                    ||           ta                      1                    ||          S )ze Reimplemented to ensure a console-like behavior in the underlying
            text widgets.
        TbuttonF)2typer   rU   KeyPresskey_control_key_down	modifiers_ctrl_down_remapr	   	QKeyEventrb   
NoModifierr   QApplicationinstance	sendEventr]   _event_filter_console_keypressrg   _event_filter_page_keypressgetattrMouseButtonReleaser   MiddleButtonviewportr   r   r   paste
QClipboard	SelectionResizerr   _adjust_scrollbarsShortcutOverrideoverride_shortcuts
_shortcutsr   rW   repaint	MouseMoveanchorAtr   globalPositiontoPoint	globalPosQToolTipshowTextrO   eventFilter)
r@   objeventetyper   	new_eventr   anchorr   r   s
            r#   r   zConsoleWidget.eventFilter  s>    

FM*** ))++C%%eoo&7&788 ?4000!OFM,B,0,A#,F,2I,@B B	 &//11;;CKKKt%%::5AAA***77>>> + UHe,, '	5999&)"888t}--////]44UYY[[AAFM''///JJu'12224 fm***43F*"&D"++--77UCCC##%%%"'D4 fm444' 5&&u'8'899 5 		t..LLNNNN d///t)))&&(((4fm---]++EIIKK88F (**,,4466oo''''V444ww""3...r%   c                    t          j        | j                  }| j                                        | j                                                                        z   dz  }|                                 }|                    t          j
        j                  }|                                 | j        z  |z   }||                    t          j
        j                  z  }| j        dk    r|dz  |z   }|                                | j        z  |z   }| j        dk    r|dz  |z   }t%          j        t)          |          t)          |                    S )zc Reimplemented to suggest a size that is 80 characters wide and
            25 lines high.
           r3   r4   )r	   QFontMetricsfontr]   
frameWidthdocumentdocumentMarginstylepixelMetricr   QStylePM_SplitterWidth_get_font_widthconsole_widthPM_ScrollBarExtentr^   heightconsole_heightr   QSizeint)r@   font_metricsmarginr   
splitwidthwidthr  s          r#   sizeHintzConsoleWidget.sizeHint  s*    )$)44-**,,-((**99;;<?@A

&&y'7'HII
 $$&&);;fD""9#3#FGGG;(""AI
*E$$&&)<<vE;(""aZ*,F|CJJF444r%   zWhether to include output from clients
        other than this one sharing the same kernel.

        Outputs are not displayed until enter is pressed.
        z	[remote] zPrefix to add to outputs coming from clients other than this one.

        Only relevant if include_other_output is True.
        c                 X    | j                                                                         S )z> Returns whether text can be copied to the clipboard.
        )r]   ri   hasSelectionr?   s    r#   can_copyzConsoleWidget.can_copy  s$     }''))66888r%   c                     | j                                         }|                                oM|                     |                                          o&|                     |                                          S )z; Returns whether text can be cut to the clipboard.
        )r]   ri   r  r   r   r   r@   r   s     r#   can_cutzConsoleWidget.can_cut   se     ))++##%% 3003 1 122	4r%   c                     | j                                         t          j        j        z  r=t          t          j                                        	                                          S dS )z@ Returns whether text can be pasted from the clipboard.
        F)
r]   textInteractionFlagsr   rb   TextEditableboolr   r   	clipboardr   r?   s    r#   	can_pastezConsoleWidget.can_paste(  sS     =--//&)2HH 	C	.88::??AABBBur%   c                     | j         r| j                                         dS |r| j        }| j                                         |                                  |r	|| _        dS dS )z Clear the console.

        Parameters
        ----------
        keep_input : bool, optional (default True)
            If set, restores the old input buffer if a new prompt is written.
        N)rq   r]   clearinput_buffer_show_prompt)r@   
keep_inputr  s      r#   r  zConsoleWidget.clear/  s~     ? 	1M!!!!! 1#0M!!! 1$0!!!1 1r%   c                 v    |                                                                                                   dS )z< Copy the currently selected text to the clipboard.
        N)r   currentWidgetcopyr?   s    r#   r  zConsoleWidget.copyA  s0     	##%%**,,,,,r%   c                 h    t           j                                                            |           dS )z+ Copy anchor text to the clipboard
        N)r   r   r  setTextr@   r   s     r#   copy_anchorzConsoleWidget.copy_anchorF  s-     	((**226:::::r%   c                     |                                   |                                 r-| j                                                                         dS dS )zv Copy the currently selected text to the clipboard and delete it
            if it's inside the input buffer.
        N)r  r  r]   ri   removeSelectedTextr?   s    r#   cutzConsoleWidget.cutK  sQ     			<<>> 	<M$$&&99;;;;;	< 	<r%   c                     |d                              dd          | j        k    rd S |d                              dd          }|d                              dd          }|                     |d	k    |           d S )
Nparent_headermsg_idr   contentstatuscompleteindentrF   
incomplete)getrR   _trigger_is_complete_callback)r@   msgr+  r-  s       r#   _handle_is_complete_replyz'ConsoleWidget._handle_is_complete_replyS  s}    ##Ha00D4LLLFY##Hj99Y##Hb11**6\+A6JJJJJr%   rF   c                 R    | j         d | _         |                     ||           d S d S r   )rR   _is_complete_callback)r@   r,  r-  s      r#   r0  z+ConsoleWidget._trigger_is_complete_callbackZ  s7    #/'+D$&&x88888 0/r%   c                    | j         2| j        t          j                    k     rd S |                                  t          j                    | j        z   | _        || _        | j                            |          | _         d S r   )rR   rT   timer0  rS   r4  kernel_clientis_complete)r@   sourcecallbacks      r#   _register_is_complete_callbackz,ConsoleWidget._register_is_complete_callback_  su    #/)DIKK77 22444%)Y[[43L%L"%-"#'#5#A#A&#I#I   r%   c                     || j         }n	|s|| _         |r|                     ||           dS |r2| j        r+|                     |t	          | j        |                     dS |                     |dd           dS )a|   Executes source or the input buffer, possibly prompting for more
        input.

        Parameters
        ----------
        source : str, optional

            The source to execute. If not specified, the input buffer will be
            used. If specified and 'hidden' is False, the input buffer will be
            replaced with the source before execution.

        hidden : bool, optional (default False)

            If set, no output will be shown and the prompt will not be modified.
            In other words, it will be completely invisible to the user that
            an execution has occurred.

        interactive : bool, optional (default False)

            Whether the console is to treat the source as having been manually
            entered by the user. The effect of this parameter depends on the
            subclass implementation.

        Raises
        ------
        RuntimeError
            If incomplete input is given and 'hidden' is True. In this case,
            it is not possible to prompt for more input.

        Returns
        -------
        A boolean indicating whether the source was executed.
        NTrF   )r  _executeexecute_on_complete_inputr;  r   
do_execute)r@   r9  hiddeninteractives       r#   executezConsoleWidget.executek  s    N >&FF 	' &D 	.MM&&))))) 	.T; 	.//88: : : : : OOFD"-----r%   c                    |rT|                      d           | j        | _        d| _        |                                  |                     |d           d S |                                 }|                                 	 |                    d           | 	                    ||           |
                                 n# |
                                 w xY w| j                            t          j        j                   d S )N
TF)_append_plain_textr  rt   rq   _finalize_input_requestr=  _get_end_cursorbeginEditBlock
insertText_insert_continuation_promptendEditBlockr]   
moveCursorr	   QTextCursorEnd)r@   r9  r,  r-  r   s        r#   r?  zConsoleWidget.do_execute  s    	<##D)))+/+<D("DO((*** MM&%(((((
 ))++F!!###&!!$'''00@@@##%%%%##%%%%
 M$$U%6%:;;;;;s    +C   Cc                 8    | j                                          dS )z? Shows a dialog to export HTML/XML in various formats.
        N)rs   exportr?   s    r#   r   zConsoleWidget.export_html  s     	""$$$$$r%   c                 N   d| _         |                                  | j                            |                                                                            | j                                                            | j	                   | j        
                    d           dS )z8
        Set the widget to a non-reading state.
        FN)r{   _prompt_finishedrj   setPositionrG  r   r]   r   setMaximumBlockCountbuffer_sizesetUndoRedoEnabledr?   s    r#   rF  z%ConsoleWidget._finalize_input_request  s    
  	)55  ""++--	/ 	/ 	/ 	  55d6FGGG 	((/////r%   c                 &   | j         r	|s| j        S |                                 }|                    | j        t
          j        j                   |                                	                                }|
                    d| j        z   d          S )z The text that the user has entered entered at the current prompt.

        If the console is currently executing, the text that is executing will
        always be returned.
        rD  )rq   rt   rG  rS  _prompt_posr	   rM  
KeepAnchor	selectiontoPlainTextr   ro   )r@   forcer   r  s       r#   _get_input_bufferzConsoleWidget._get_input_buffer  s     ? 	05 	0//%%''4+U->-IJJJ''))5577 ##D4+D$DdKKKr%   c                    | j         r	|| _        dS |                                 }|                                 |                    | j        t          j        j                   |	                                 | 
                    |                                 |           |                                 | j                            t          j        j                   dS )z Sets the text in the input buffer.

        If the console is currently executing, this call has no *immediate*
        effect. When the execution is finished, the input buffer will be updated
        appropriately.
        N)rq   ru   rG  rH  rS  rX  r	   rM  rY  r%  r   _get_prompt_cursorrK  r]   rL  rN  )r@   stringr   s      r#   _set_input_bufferzConsoleWidget._set_input_buffer  s     ? 	)/D&F %%''4+U->-IJJJ!!### 	++D,C,C,E,EvNNN  !2!677777r%   c                 X    | j                                                                         S )z8 The base font being used by the ConsoleWidget.
        )r]   r   defaultFontr?   s    r#   	_get_fontzConsoleWidget._get_font  s$     }%%''33555r%   c                     || j         }t          j        |          }t          |d          r|                    d          S |                    d          S )NhorizontalAdvance )r   r	   r   rX   rf  r
  )r@   r   r  s      r#   r   zConsoleWidget._get_font_width  sY    <9D)$//<!455 	+11#666%%c***r%   c                    | j                             | j        |                     |          z             | j                            |           | j                                                             |           | j        r,| j                                                            |           | j	        
                    |           dS )zJ Sets the base font for the ConsoleWidget to the specified QFont.
        N)r]   setTabStopWidth	tab_widthr   rn   setFontr   setDefaultFontrg   font_changedemit)r@   r   s     r#   	_set_fontzConsoleWidget._set_font  s     	%%NT11$777	
 	
 	
 	''---  //555 	?''))88>>>t$$$$$r%   c                     |dk    rt          |           | _        n5|dk    rt          |           | _        n|dk    rt          |           | _        || _        dS )z$ Set gui completion widget.
        r/   r.   r-   N)r   rn   r   r   rl   )r@   rl   s     r#   _set_completion_widgetz$ConsoleWidget._set_completion_widget  si     Y&&&4T&:&:D##z))&6t&<&<D##w&&&5d&;&;D#,r%   c                 .    t          j        |           dS )z8 Open selected anchor in the default webbrowser
        N)
webbrowseropenr"  s     r#   open_anchorzConsoleWidget.open_anchor)  s     	!!!!!r%   c                    | j                                         t          j        j        z  r|                                  | j                                         }t          j        	                                
                    |                                          }|                                |                                 z
  }|                    d|z            r
||d         }|                     |t!          |                     dS dS )a   Paste the contents of the clipboard into the input region.

        Parameters
        ----------
        mode : QClipboard::Mode, optional [default QClipboard::Clipboard]

            Controls which part of the system clipboard is used. This can be
            used to access the selection clipboard in X11 and the Find buffer
            in Mac OS. By default, the regular clipboard is used.
        rg  N)r]   r  r   rb   r  r   ri   r   r   r  r   rstripr   _get_line_start_posr    r   r   )r@   moder   r   cursor_offsets        r#   r   zConsoleWidget.paste.  s     =--//&)2HH 	F'')))]--//F )3355::4@@GGIID #OO--0H0H0J0JJMs]233 ,MNN+//tEEEEE#	F 	Fr%   c                     |sNt          j                    }t          j        |                                          t           j        j        k    rdS | j                            |           dS )zL Print the contents of the ConsoleWidget to the specified QPrinter.
        N)r
   QPrinterQPrintDialogexec_Acceptedr]   r   )r@   printers     r#   r   zConsoleWidget.print_L  sc      	$-//G*73399;;~?Z?cccW%%%%%r%   c                    | j         s||                                 }|                                                                 |                                k     r|                     |           |                     |           dS dS )z6 Moves the prompt to the top of the viewport.
        N)rq   r_  _get_cursorblockNumber_set_cursor_set_top_cursor)r@   prompt_cursors     r#   prompt_to_topzConsoleWidget.prompt_to_topU  s      	0 3355M!!--//-2K2K2M2MMM  ///  /////		0 	0r%   c                 8    | j                                          dS )za Redo the last operation. If there is no operation to redo, nothing
            happens.
        N)r]   redor?   s    r#   r  zConsoleWidget.redo^       	r%   c                    t           j        dk    rd}nt           j        dk    rd}nd}t          | j        |          }| j        r|                    | j                   nU|                    t          j                                        	                                
                                           |                    t          j        j                   |                     |           dS )zJ Sets the font to the default fixed-width font for this platform.
        r8   Courierr:   r;   r<   N)r=   r>   r   font_family	font_sizesetPointSizer   r   r   r   	pointSizesetStyleHintr	   QFont
TypeWriterro  )r@   fallbackr   s      r#   r   zConsoleWidget.reset_fontd  s     <7"" HH\X%%HH #H((33> 	Tdn----i4==??DDFFPPRRSSS%+0111tr%   c                     | j         }t          |                                |z   d          }|                    |           |                     |           dS )zBChange the font size by the specified amount (in points).
        r   N)r   maxr  r  ro  )r@   deltar   sizes       r#   change_font_sizezConsoleWidget.change_font_sizex  sU     y4>>##e+Q//$tr%   c                 0    |                      d           d S )Nr   r  r?   s    r#   r   z!ConsoleWidget._increase_font_size  s    a     r%   c                 0    |                      d           d S )Nr  r?   s    r#   r   z!ConsoleWidget._decrease_font_size  s    b!!!!!r%   c                 D   |                                  }|                                |                                f}|                                 |                    |                                                                            |                    |                                 t          j	        j
                   |                                |                                f}||k    r|                                  dS | j                            |           dS )zK Select current cell, or, if already selected, the whole document.
        ry  N)r  selectionStartselectionEndclearSelectionrS  r_  r   _get_end_posr	   rM  rY  select_documentr]   r   )r@   c	sel_rangenew_sel_ranges       r#   r   zConsoleWidget.select_all_smart  s    $$&&(8(88			d--//88::;;;	d'')) ,7 	 	9 	9 	9((**ANN,<,<<%%  """"" M''*****r%   c                 8    | j                                          dS )z- Selects all the text in the buffer.
        N)r]   	selectAllr?   s    r#   r  zConsoleWidget.select_document  s     	!!!!!r%   c                     | j         S )zF The width (in terms of space characters) for tab characters.
        )r}   r?   s    r#   _get_tab_widthzConsoleWidget._get_tab_width  s     r%   c                 r    | j                             ||                                 z             || _        dS )zK Sets the width (in terms of space characters) for tab characters.
        N)r]   ri  r   r}   )r@   rj  s     r#   _set_tab_widthzConsoleWidget._set_tab_width  s6     	%%i$2F2F2H2H&HIII#r%   c                 8    | j                                          dS )za Undo the last operation. If there is no operation to undo, nothing
            happens.
        N)r]   undor?   s    r#   r  zConsoleWidget.undo  r  r%   c                     t           )z Returns whether 'source' can be executed. When triggered by an
            Enter/Return key press, 'interactive' is True; otherwise, it is
            False.
        NotImplementedError)r@   r9  rA  s      r#   _is_completezConsoleWidget._is_complete  s
    
 "!r%   c                     t           )z@ Execute 'source'. If 'hidden', do not show any output.
        r  )r@   r9  r@  s      r#   r=  zConsoleWidget._execute  s
     "!r%   c                     dS )= Called immediately after a new prompt is displayed.
        NrN   r?   s    r#   _prompt_started_hookz"ConsoleWidget._prompt_started_hook  s	     	r%   c                     dS ) Called immediately after a prompt is finished, i.e. when some input
            will be processed and a new prompt displayed.
        NrN   r?   s    r#   _prompt_finished_hookz#ConsoleWidget._prompt_finished_hook  s	     	r%   c                     dS )zj Called when the up key is pressed. Returns whether to continue
            processing the event.
        TrN   r@   shift_modifiers     r#   _up_pressedzConsoleWidget._up_pressed  	     tr%   c                     dS )zl Called when the down key is pressed. Returns whether to continue
            processing the event.
        TrN   r  s     r#   _down_pressedzConsoleWidget._down_pressed  r  r%   c                     dS )zk Called when the tab key is pressed. Returns whether to continue
            processing the event.
        TrN   r?   s    r#   _tab_pressedzConsoleWidget._tab_pressed  r  r%   c                 d   | j                                         }|rD| j        s| j        s6|                                  d|_        |                    | j                   nC|| j        k    r|                                  |	                    t          j        j                    |||g|R i |}|S )z A low-level method for appending content to the end of the buffer.

        If 'before_prompt' is enabled, the content will be inserted before the
        current prompt, if there is one.
        T)r]   ri   r{   rq   _flush_pending_stream_insert_moderS  _append_before_prompt_pos_insert_plain_textmovePositionr	   rM  rN  )r@   insertinputbefore_promptargskwargsr   results           r#   _append_customzConsoleWidget._append_custom  s     ))++ 	7dm 	74? 	7&&((( $Ft=>>>>000**,,, 1 5666 777777r%   c                 >    |                      | j        ||           dS )zE Appends an new QTextBlock to the end of the console buffer.
        N)r  _insert_block)r@   block_formatr  s      r#   _append_blockzConsoleWidget._append_block  s%     	D.mLLLLLr%   c                 >    |                      | j        ||           dS )z8 Appends HTML at the end of the console buffer.
        N)r  _insert_htmlr@   htmlr  s      r#   _append_htmlzConsoleWidget._append_html  s%     	D-t]CCCCCr%   c                 :    |                      | j        ||          S )zB Appends HTML, then returns the plain text version of it.
        )r   _insert_html_fetching_plain_textr  s      r#    _append_html_fetching_plain_textz.ConsoleWidget._append_html_fetching_plain_text  s&     ""4#H#'8 8 	8r%   c                 >    |                      | j        ||           dS )z? Appends plain text, processing ANSI codes if enabled.
        N)r  r  )r@   r   r  s      r#   rE  z ConsoleWidget._append_plain_text  s%     	D3T=IIIIIr%   c                 8    | j                                          dS )z4 If text completion is progress, cancel it.
        N)rn   cancel_completionr?   s    r#   _cancel_completionz ConsoleWidget._cancel_completion  s     	1133333r%   c                    |                                  }| j                                        }| j        rd| _        |                    t
          j        j                  rt          j        |          }|                    t
          j        j	                   |
                                                                                                }|                    |          sn$|                    t
          j        j                  ndS |                    t
          j        j                   |                    t
          j        j        t
          j        j                   |                                 | j                                        r6| j                            d           | j                            d           dS dS )zh Clears the "temporary text" buffer, i.e. all the text following
            the prompt region.
        FNT)r_  ro   lstrip_temp_buffer_filledr  r	   rM  	NextBlockselectBlockUnderCursorrZ  r[  r    LeftrN  rY  r%  r]   isUndoRedoEnabledrV  )r@   r   prompttemp_cursorr   s        r#   _clear_temporary_bufferz%ConsoleWidget._clear_temporary_buffer  s   
 ((***1133# 
	',D$%%e&7&ABB #/77""5#4#EFFF",,..::<<CCEEv..  %%e&7&ABB  FE-2333E-1!-8	: 	: 	:!!### =**,, 	3M,,U333M,,T22222	3 	3r%   c                    |                                   t          |          dk    rk|                    | j                                                                        t          j        j                   |	                    |d                    dS t          |          dk    r| j                                                                        }t          j                            |          }|rN|                    |t          j        j                   |	                    |           |                                }| j                            ||t          |                     dS dS )zL Performs completion with 'items' at the specified cursor location.
        r   r   )prefix_lengthN)r  lenrS  r]   ri   r   r	   rM  rY  rI  ospathcommonprefixrn   
show_items)r@   r   itemscurrent_posprefixs        r#   _complete_with_itemsz"ConsoleWidget._complete_with_items0  sM    	!!!u::??t}7799BBDD$0;= = =eAh'''''ZZ!^^-2244==??KW))%00F 0"";0A0LMMM!!&)))$oo//#..vu=@[[ / J J J J J ^r%   c                    | j                                                                         }|                                 |                     d           |                     ||           |                                 |                    |           | j                             t          j
        j                   | j                             |           d| _        dS )z6fill the area below the active editting zone with textrD  )r  TN)r]   ri   r   rH  rE  _pagerK  rS  rL  r	   rM  rN  r   r  )r@   r   r   r  r  s        r#   _fill_temporary_bufferz$ConsoleWidget._fill_temporary_bufferE  s     m..0099;;%%%

4d
###;'''  !2!6777##F+++#'   r%   c                     t          j                   }|                    d j                   _         j                                                                         j                            t          j	        j
                   |                    d j                   _         j                                                                         j                            t          j	        j                   |                    d j                   _         j                                                                         j                            t          j	        j                    j                            |          rR|                                 |                    d fd           _        |                    d fd           _        |                                 |                     j                   |                                 |                     j                   |                     j                   |S )zN Creates a context menu for the given QPoint (in widget coordinates).
        CutCopyPastezCopy Link Addressc                  0                                    S N)r   )r#  r   r@   s   r#   <lambda>z2ConsoleWidget._context_menu_make.<locals>.<lambda>k  s    T-=-=V-=-L-L r%   z	Open Linkc                  0                                    S r  )ru  r   s   r#   r  z2ConsoleWidget._context_menu_make.<locals>.<lambda>m  s    T%5%5V%5%D%D r%   )r   QMenur   r&  
cut_actionr   r  r   r	   r   r  r  copy_actionr  r  r   paste_actionr  r  r]   r   addSeparatorcopy_link_actionopen_link_actionr   r   r   )r@   r   menur   s   `  @r#   _context_menu_makez ConsoleWidget._context_menu_makeV  s    t$$..99""4<<>>222##E$6$:;;;>>&$)<<##DMMOO444$$U%7%<=== NN7DJ??$$T^^%5%5666%%e&8&>???'',, 	F$(NN#%L%L%L%L%L%N %ND!$(NNDDDDD%F %FD! 	t-...t)***t()))r%   c                     t           j        dk    rG|o|t          j        j        z  }t          |          t          |t          j        j        z            z  S t          |t          j        j        z            S )a7   Given a KeyboardModifiers flags object, return whether the Control
        key is down.

        Parameters
        ----------
        include_command : bool, optional (default True)
            Whether to treat the Command key as a (mutually exclusive) synonym
            for Control when in Mac OS.
        r:   )r=   r>   r   rb   ControlModifierr  MetaModifier)r@   r   include_commanddowns       r#   r   zConsoleWidget._control_key_downx  s`     <8##"N	FI4M(MD::Y1G%G H HHH	FI$==>>>r%   c                    | j         r|                                  }ng| j        dk    rt          j                    }nH| j        dk    r=t          j                    }|                    d           |                    d           |                    d           |                    |            |	                                                    |            |j
                            | j                   |j                            | j                   |j                            | j                   |j                            | j                   |                                                                }|j                                         |j                            | j                   | j        rt2          j        j        }nt2          j        j        }|                    t2          j        j        d           |                    t2          j        j                    |!                    d           |"                    d           |#                    |           |S )z: Creates and connects the underlying text widget.
        r-   r1   FT)$custom_controlkindr   QPlainTextEdit	QTextEditsetAcceptRichTextsetMouseTrackingr   installEventFilterr   customContextMenuRequestedr   _custom_context_menu_requestedcopyAvailablecopy_availableredoAvailableredo_availableundoAvailableundo_availabler   documentLayoutdocumentSizeChanged
disconnectr   scrollbar_visibilityr   rb   ScrollBarAlwaysOnScrollBarAlwaysOffsetAttributeWA_InputMethodEnabledsetContextMenuPolicyCustomContextMenusetReadOnlyrV  setVerticalScrollBarPolicy)r@   controlr   scrollbar_policys       r#   r\   zConsoleWidget._create_control  s+     	+))++GGY'!!.00GGY&  )++G%%e,,,$$T*** 	u%%% 	""4(((--d333 	*22/	1 	1 	1%%d&9:::%%d&9:::%%d&9::: !!##2244"--///"**4+BCCC $ 	<%y:%y; 	VY<dCCC$$VY%@AAAD!!!""5)))**+;<<<r%   c                    | j         r|                                  }n=| j        dk    rt          j                    }n| j        dk    rt          j                    }|                    |            |                                }|                    |            |                    d           |                    d           | j	        rt          j        j        }nt          j        j        }|                    |           |S )z< Creates and connects the underlying paging widget.
        r-   r1   TF)custom_page_controlr  r   r  r  r  r   r+  rV  r$  r   rb   r%  r&  r,  )r@   r-  r   r.  s       r#   rf   z"ConsoleWidget._create_page_control  s     # 	,..00GGY'!!.00GGY&  )++G""4(((##%%##D)))D!!!""5))) $ 	<%y:%y;**+;<<<r%   c                 v)    d} j                                                                         |                                }                     |                                          }|                                t          j        j        z  }|                                t          j        j	        z  }t          j        dk    o(                     |                                d          }|r|t          j        j        k    rt          j        j        }nx|t          j        j        k    rt          j        j        }nQ|t          j        j        k    rd}t          j        j        }n(|t          j        j        k    rd}t          j        j        }|t          j        j        t          j        j        fv rd}                                                                 rm j        r9                     d           d _         j        r                                  n5 j        s%                    t6          j        j        t6          j        j                   t?                                           !                                          dk    } "                                #                                 $                                #                                k    }	|s|s|	r|s %                    |            nS &                                }
 fd} '                     (                                d	|
         |           n|r-|t          j        j)        k    r *                                 d}n|t          j        j+        k    r                                r,                                                     t6          j        j-        t6          j        j                   .                                s{                    t6          j        j/        t6          j        j                                       t6          j        j0        t6          j        j        t?           j1                              j2        3                                4                               d}n|t          j        j5        k    r 6                                 d}ns|t          j        j7        k    r= j8        r2 j8        9                                r j8        :                                 d}n!|t          j        j;        k    r-                               r,                                 #                                }| $                                #                                k    rt?           j<                  }nt?           j1                  }                    t6          j        j=        t6          j        j                                       t6          j        j0        t6          j        j        |            j2        3                                4                               d}n|t          j        j>        k    r1 ?                                  j2        @                                 d}n|t          j        jA        t          j        jB        fv r|t          j        jA        k    r C                              n D                              E                    t6          j        j                    j2        3                               d}n|t          j        jF        k    rt?           jG                  dk    r# j        s jH        I                                nt?           (                    d
                    dk    r j                                         J                    t          d                     t7          jL        t          jM        jN        t          j        j        t          j        jO                  }t          jQ        R                                S                     j         |           d}
nt7          jL        t          jM        jN        t          j        jB        t          j        jO                  }t          jQ        R                                S                     j         |           d}
nD|t          j        j        k    r T                                 
n|t          j        j        k    r, j         U                                V                    d           	n|r.|t          j        jW        k    r, 4                     C                                         d}	n|t          j        jX        k    r, 4                     D                                         d}	nQ|t          j        j>        k    r j2        Y                                 d}	n|t          j        jA        k    rX C                              E                    t6          j        j                    j2        3                               d}n|t          j        jF        k    rX D                              E                    t6          j        j                    j2        3                               d}nE|t          j        jB        k    rd}n,|t          j        jZ        k    r- j         [                    t6          j        j                   d}n|t          j        j\        k    r. j         ]                     $                                           d}n ^                                 |rt6          j        j        }nt6          j        j_        }|t          j        j`        k    r *                                 d}n?|t          j        j        k    rb|s` j        s a                    |          sd}n $                                #                                }#                                |k    }n|t          j        j        k    rb|s` j        s b                    |          sd}n "                                #                                }#                                |k    }nQ|t          j        jc        k    r5 j        s, d                                r e                    d           d}n|t          j        jf        k    r e                    d           d}n|t          j        j        k    r|s߉#                                g                                }}| $                                #                                k    rr|t?           j1                  k    rZ j         [                    t6          j        jh        |            j         [                    t6          j        ji        |           d}n                     dz
             }n|t          j        j        k    r|s j                                k    rz                    t6          j        j/        |                               t6          j        j0        |t?           j1                              j         ]                               n+ j         [                    t6          j        j0        |           d}n
|t          j        j        k    r^ k                                } l                                } m                                }|                                ||z   k    s*|g                                t?           j1                  k    r||z  }|r                               r|                                 rYt          |o                                |p                                          }E                    |t6          j        j_                   E                    |t6          j        j                   nE                    |            4                               d}n|t          j        jA        k    rT#                                g                                }} j        s|t?           j1                  k    r| $                                #                                k    rq                                                     t6          j        j=        t6          j        j                   r                                 s                                 t                                 d}nu                                }|k    r                     dz
             }nR                     t          |                     }n,|t          j        jB        k    r j        sω                               rw                                r.                                s                    t6          j        j/        t6          j        j                                       t6          j        j0        t6          j        j        t?           j1                             r                                 d}n@u                                }                     |           p                                }|s|x                    t6          jy        jz                  r {                                 d}nu|x                    t6          jy        j|                  r }                                 d}n:|x                    t6          jy        j~                  r                                  d}                     |                                d          s|t          j        j        t          j        j        fv s` j        r j        rR|                                dk    r&|s8|t          j        j        t          j        j        fv r ?                                 |S )zj Filter key events for the underlying text widget to create a
            console-like interface.
        Fr:   T)r  rD  r   )rA  c                    	                                                                                      d                                          |r                    |                                            n#                                  w xY wj                            t          j        j	                   j        
                               d S )NrD  )rH  rS  rI  rJ  rK  r]   rL  r	   rM  rN  r   )r,  r-  r   r   r@   s     r#   r:  z>ConsoleWidget._event_filter_console_keypress.<locals>.callback  s    6 & 5 5 7 7 7 & 2 28 < < < & 1 1$ 7 7 7 $ @ @ H H H#) !>$*$5$5f$=$=$= & 3 3 5 5 5 5 3 3 5 5 5 5
 !M44U5F5JKKK M77?????s   A*B BNr\  rG   r   r  r   )ry  nrF   )r]   ri   r   r   r   r   r   rb   AltModifierShiftModifierr=   r>   Key_LeftKey_Home	Key_RightKey_EndKey_UpKey_Down
Key_Return	Key_Enterr  r   r{   rE  r|   rq   r  r	   rM  rN  rY  r  selectedTextstriprG  r  r_  rB  _get_input_buffer_cursor_posr;  r]  Key_G_keyboard_quitKey_Kr  	EndOfLiner  r  Rightro   rv   kill_cursorr  Key_Lr  Key_Org   	isVisiblesetFocusKey_Urw   StartOfBlockKey_Yr   yankKey_Backspace
Key_Delete_get_word_start_cursor_get_word_end_cursorrS  Key_Dr  exit_requestedrn  rI  chrr   rU   r   r   r   r   r   r   _scroll_to_endverticalScrollBarsetValueKey_BKey_FrotateKey_GreaterrL  Key_Lessr   r0  
MoveAnchor
Key_Escaper  r  Key_Tabr  _indentKey_BacktabcolumnNumberPreviousBlock
EndOfBlock_get_line_end_posrx  r  _get_leading_spacesr  r  r  rH  r%  deletePreviousCharrK  r   min
atBlockEndr   r   r  r  r  r&  r  r   
Key_PageUpKey_PageDownr   )r@   r   interceptedr   	ctrl_downalt_down
shift_downcmd_downat_endsingle_liner   r:  
start_lineoffsetr   
anchormodeprompt_lineend_linelinecol	start_posr  spacessel_maxr   r   r   s   `                        @@r#   r   z,ConsoleWidget._event_filter_console_keypress  s    ))++??$$iikk**5??+<+<==	??$$vy'<<__&&)@@
 LH$ L""5??#4#4d"KK 	  
	(fi(((i(	+++i'	((( 	i(	*** 	i' 69')<===K ##%%%x(( 'F= %F++D111$)DM- 1..000
  F''(9(=(-(9(DF F F !4!4!6!6!<!<!>!>??1DF#'#7#7#9#9#E#E#G#G#'#:#:#<#<#H#H#J#J$KK F* F FY Fz>BBBB #??AA@ @ @ @ @ @ @  ;; 2244TcT:HF F F
  x	Bfio%%##%%%"	''??8,, -))+++''(9(C(-(9(DF F F!..00 L++E,=,G,1,=,HJ J J++E,=,C,1,=,H,/0I,J,JL L L O//777$$V,,,"	''""$$$"	''% 2$*<*F*F*H*H 2&//111"	''??8,, -))+++!'!3!3!5!5J!T%<%<%>%>%J%J%L%LLL!$T\!2!2!$T%>!?!?''(9(F(-(9(DF F F''(9(?(-(9(DfN N NO//777$$V,,,"	''++---$$&&&"0&)2FGGG&)111!88BBFF!66x@@F""8U->-IJJJ++F333"	''t())Q..t.',,T2222//d/;;<<AAM,,..99#a&&AAA %0F06	0D06	0D!F !FI *3355??yYYY"&KK %0F06	0D06	0D!F !FI *3355??yYYY"&KK	***##%%%%	(((//11::1===  b	Bfio%%  !<!<X!F!FGGG"	''  !:!:8!D!DEEE"	''&&((("	///44X>>""8U->-IJJJ++F333"	''228<<""8U->-IJJJ++F333"	,,,"	---(():)>???"	***++D,C,C,E,EFFF"
 ..000 :".9

".9
fi***##%%%"	((((= F(8(8(D(D F"&KK"&"9"9";";"G"G"I"IK"("4"4"6"6+"EKK	***:*= C(:(::(F(F C"&KK#3355AACCH"("4"4"6"6("BKK	)))} '((** 3E222"&K	---D)))"	***:* #..00&2E2E2G2Gc$1133??AAAAs4#<====M,,U->-L2< - > > >M,,U->-I2< - > > >"&KK '+oohl&C&C"CKK	+++J+t557777''(9(C*'UUU''(9(?-7*-d.G*H*H ( J J J M//7777M,,U->-D2< - > > >"	*** 4466	$$&&1133JJLL9v#555((C0I,J,JJJ'I 2$//(";"; 2~~'' I"%a&6&6&8&8!..:J:J"K"K**7+0+<+GI I I&&y%2C2NOOOO&&y111  ((("	/// #..00&2E2E2G2Gc} Qs4#<====t6688DDFFFF))+++''(9(F(-(9(DF F F--///--///'')))"&KK $]]__F))*.//(Q,*G*G&G*.//#fh:O:O*P*P&P	,,, } B)B)B B))++B4:4G4G4I4IB''(9(C(-(9(DF F F''(9(?(-(9(D(+D,E(F(FH H H --///"&KK $]]__F'+v'>'>#> $A'+x'@'@#@  
  	#}}U/455 
#		"u1566 #


"u1788 #

" &&u'8'8$&OO 	*69/1GHHHO I,0M IJJLLB&&# '(+	0@&)BT/U(U(U'')))r%   c                 x   |                                 }|                     |                                          }|                                t          j        j        z  }|r2|t          j        j        k    r| j                                         dS n|r|t          j        j	        k    r+| j
                            t          j        j                   dS |t          j        j        k    r+| j
                            t          j        j                   dS n |t          j        j        t          j        j        fv r| j        r3| j
                                         | j                                         n]|                                                     | j                   | j                                                            | j                   dS |t          j        j        t          j        j        t          j        j        fv r|t          j        t          j        j        t          j        j         t          j        j!                  }tD          j#        $                                %                    | j
        |           dS |t          j        j&        k    r|t          j        t          j        j        t          j        j'        t          j        j!                  }tD          j#        $                                %                    | j
        |           dS |t          j        j(        k    r|t          j        t          j        j        t          j        j)        t          j        j!                  }tD          j#        $                                %                    | j
        |           dS |t          j        j*        k    r|t          j        t          j        j        t          j        j+        t          j        j!                  }tD          j#        $                                %                    | j
        |           dS dS )z_ Filter key events for the paging widget to create console-like
            interface.
        TF),r   r   r   r   rb   r5  rI  r]   rK  r]  rg   rL  r	   rM  rN  r^  StartKey_Qr`  r`   rh   r   setCurrentWidgetr   rT  rU  r>  r=  ra  r   rU   r   rm  r   r   r   r   r   rP  rl  Key_Jr<  rD  r;  )r@   r   r   ro  rp  r   s         r#   r   z)ConsoleWidget._event_filter_page_keypress:  sD    iikk**5??+<+<==	??$$vy'<< 5	fio%%&&(((t &  0	fi+++"--e.?.CDDDt	***"--e.?.EFFFt + VY_fi&:;;;~ P"'')))&&((((..t}===&&((==d>NOOO4VY(&)*>Y&( ( ((>(.	(>(.	(<> >I "++--778JIVVV4FI+++(>(.	(<(.	(<> >I "++--778JIVVV4 FIO##(>(.	(:(.	(<> >I "++--778JIVVV4 FIO##(>(.	(8(.	(<> >I "++--778JIVVV4ur%   c                     | j                                         }|                    t          j        j                   |                                  |                    t          j        j                   dS )z_ Flush the pending stream output and change the
        prompt position appropriately.
        N)r]   ri   r  r	   rM  rN  r  r  s     r#   r   z,ConsoleWidget._on_flush_pending_stream_timer{  sc     ))++E-1222""$$$E-122222r%   c           	         | j         }g | _         | j                                                                        }|dk    r|                     ||          }d                    |          }t          j                    }|                     |                                 |d           | j	        
                    t          t          dt          j                    |z
  dz                                 dS )z) Flush out pending text into the widget. r   rF   T)flushrH   i  N)r~   r]   r   maximumBlockCount_get_last_lines_from_listr   r6  r  rG  r   r   r  r  )r@   r   rU  ts       r#   r  z#ConsoleWidget._flush_pending_stream  s    ($&!m,,..@@BB??11$DDDwwt}}IKK 4 4 6 6DIII)55C$)++/T12233	
 	
 	
 	
 	
r%     c                     | j                                                                         }|                                 }t	          d||z  dz
            }t          |||          S )a`   Transform a list of strings into a single string with columns.

        Parameters
        ----------
        items : sequence of strings
            The strings to process.

        separator : str, optional [default is two spaces]
            The string that separates columns.

        Returns
        -------
        The formatted string.
        
   r   )r]   r   	textWidthr   r  r   )r@   r  	separatorr
  
char_widthdisplaywidths         r#   _format_as_columnsz ConsoleWidget._format_as_columns  s_      &&((2244))++
2
 2a788	<888r%   c                 4    | j                                         S )z6 Get a cursor at the current insert position.
        )r]   ri   r?   s    r#   r  zConsoleWidget._get_cursor  s     }'')))r%   c                     | j                                         }|                    t          j        j                   |S )zA Get a cursor at the last character of the current cell.
        )r]   ri   r  r	   rM  rN  r  s     r#   rG  zConsoleWidget._get_end_cursor  s6     ))++E-1222r%   c                 N    |                                                                  S )zE Get the position of the last character of the current cell.
        )rG  r   r?   s    r#   r  zConsoleWidget._get_end_pos  s"     ##%%..000r%   c                    | j                                         }|                                }||                                                                 k    r|                    | j                   n`|                    t          j        j	                   |                    |
                                t          | j                  z              |S )zB Get a cursor at the first character of the current line.
        )r]   ri   r  r_  rS  rX  r  r	   rM  StartOfLiner   r  ro   )r@   r   ru  s      r#   _get_line_start_cursorz$ConsoleWidget._get_line_start_cursor  s     ))++''))
0022>>@@@@t/0000 1 =>>>v00"4#<== > ? ? ?r%   c                 N    |                                                                  S )zF Get the position of the first character of the current line.
        )r  r   r?   s    r#   rx  z!ConsoleWidget._get_line_start_pos  s"     **,,55777r%   c                     | j                                         }|                    t          j        j                   |S )zA Get a cursor at the last character of the current line.
        )r]   ri   r  r	   rM  rE  r  s     r#   _get_line_end_cursorz"ConsoleWidget._get_line_end_cursor  s6     ))++E-7888r%   c                 N    |                                                                  S )zE Get the position of the last character of the current line.
        )r  r   r?   s    r#   rg  zConsoleWidget._get_line_end_pos  s"     ((**33555r%   c                     |                                  }|dS | j                                        }|                                t	          |          z
  S )z Get the column of the cursor in the input buffer, excluding the
            contribution by the prompt, or -1 if there is no such column.
        Nr  )_get_input_buffer_cursor_promptr]   ri   rd  r  )r@   r  r   s      r#   _get_input_buffer_cursor_columnz-ConsoleWidget._get_input_buffer_cursor_column  sO     5577>2]--//F&&((3v;;66r%   c                     |                                  }|dS | j                                        }|                                                                }|t          |          d         S )z~ Get the text of the line of the input buffer that contains the
            cursor, or None if there is no such line.
        N)r  r]   ri   blockr   r  )r@   r  r   r   s       r#   _get_input_buffer_cursor_linez+ConsoleWidget._get_input_buffer_cursor_line  s`     5577>4]--//F<<>>&&((DF%%r%   c                 *   | j                                         }|                    | j        t          j        j                   |                                                                }t          |
                    d| j        z   d                    S )z0Get the cursor position within the input buffer.rD  )r]   ri   rS  rX  r	   rM  rY  rZ  r[  r  r   ro   )r@   r   r  s      r#   rA  z*ConsoleWidget._get_input_buffer_cursor_pos  sy    ))++4+U->-IJJJ''))5577 <''t/H(H$OOPPPr%   c                    | j         rdS | j                                        }|                                | j        k    rJ|                                |                                                                 k    r| j        S | j        S dS )z Returns the (plain text) prompt for line of the input buffer that
            contains the cursor, or None if there is no such line.
        N)	rq   r]   ri   r   rX  r  r_  rw   ro   r  s     r#   r  z-ConsoleWidget._get_input_buffer_cursor_prompt  s     ? 	4))++?? 000!!##t'>'>'@'@'L'L'N'NNN|#004r%   c                     t          |          }||k     r|r||r|                    d          n|fS |S d}||k     r+|                    dd|          }|dk    rd}n|dz  }||k     +|r||d         |fS ||d         S )z Get the last specified number of lines of text (like `tail -n`).
        If return_count is True, returns a tuple of clipped text and the
        number of lines in the clipped text.
        rD  r   Nr  r   )r  countrfind)r@   r   	num_linesreturn_countr   is         r#   _get_last_lineszConsoleWidget._get_last_lines  s    
 $ii?? GTZZ---4GG)mm**T4--CbyyFA )mm  	:q= :r%   c                     g }|}t          |          D ]?}|                     ||d          \  }}|                    |           ||z  }|dk    r n@|ddd         S )z? Get the list of text clipped to last specified lines.
        T)r  r   Nr  )reversedr  rY   )r@   	text_listr  retlines_pendingr   lines_addeds          r#   r  z'ConsoleWidget._get_last_lines_from_list  s     !Y'' 	 	D $ 4 4T=BF !5 !H !HD+JJt[(M!! "44R4yr%   c                    |                                  }|                                }||                                                                 k    rt          | j                  }nt          | j                  }|                    t          j        j	                   |
                                |d         }t          |          t          |                                          z
  S )z? Get the number of leading spaces of the current line.
        N)r  r  r_  r  rw   ro   r  r	   rM  LineUnderCursorr?  r  )r@   r   ru  rv  r   s        r#   rh  z!ConsoleWidget._get_leading_spaces,  s     !!##''))
0022>>@@@@&&FF 233Fe'7888""$$VWW-4yy3t{{}}----r%   c                 z    t          | j                                        dz   |                                           S )z? Find the position in the text right after the prompt.
        r   )rj  ry   r   r  r?   s    r#   rX  zConsoleWidget._prompt_pos<  s4     4&//11A5t7H7H7J7JKKKr%   c                 t    t          | j                                        |                                           S )z@ Find the position in the text right before the prompt.
        )rj  rj   r   r  r?   s    r#   r  z'ConsoleWidget._append_before_prompt_posB  s6     44==??$$&&( ( 	(r%   c                 l    | j                                         }|                    | j                   |S )zB Get a cursor at the prompt position of the current cell.
        )r]   ri   rS  rX  r  s     r#   r_  z ConsoleWidget._get_prompt_cursorI  s3     ))++4+,,,r%   c                     | j                                         }|                    |           |                    |t          j        j                   |S )z^ Get a cursor with text selected between the positions 'start' and
            'end'.
        )r]   ri   rS  r	   rM  rY  )r@   startendr   s       r#   _get_selection_cursorz#ConsoleWidget._get_selection_cursorP  sL     ))++5!!!3 1 <===r%   c                    | j                                         }| j                                         }|                                 }|| j        k    r|S ||k    r| j                                         }|                    |           |                    t          j        j	                   |                    t          j        j
                   |                                }|| j        k    rTt          |                    |                    r2|dz  }|| j        k    r"t          |                    |                    2|                    |dz              n|dz  }|| j        k    r`||k    rZt          |                    |                    s8|dz  }|| j        k    r(||k    r"t          |                    |                    8|| j        k    r`||k    rZt          |                    |                    r8|dz  }|| j        k    r(||k    r"t          |                    |                    8|                    |dz              |S )z Find the start of the word to the left the given position. If a
            sequence of non-word characters precedes the first word, skip over
            them. (This emulates the behavior of bash, emacs, etc.)
        r   )r]   r   ri   rx  rX  rS  r  r	   rM  re  rf  r   r(   characterAtr$   )r@   r   r   r   line_start_poss        r#   rR  z$ConsoleWidget._get_word_start_cursorY  si   
 =))++))++1133t'''M'' ]--//Fx((( 1 ?@@@ 1 <===((HD,,,h228<<== - A D,,,h228<<== - x!|,,,,MH D,,,N**'(<(<X(F(FGG + A	 D,,,N**'(<(<X(F(FGG + D,,,N**#H$8$8$B$BCC + A	 D,,,N**#H$8$8$B$BCC +
 x!|,,,r%   c                 ,   | j                                         }| j                                         }|                                 }|                                 }||k    r|S ||k    r| j                                         }|                    |           |                    t          j        j	                   |
                                t          | j                  z   }||k     rOt          |                    |                    r-|dz  }||k     r"t          |                    |                    -|                    |           nt          |                    |                    rd}|dz
  }|                                 }||k    r0t          |                    |                    sd}n|dz  }||k    0|rx||k     r[||k     rUt          |                    |                    r3|dz  }||k     r(||k     r"t          |                    |                    3|                    |           |S ||k     r[||k     rUt!          |                    |                    s3|dz  }||k     r(||k     r"t!          |                    |                    3||k     r[||k     rUt!          |                    |                    r3|dz  }||k     r(||k     r"t!          |                    |                    3|                    |           |S )z Find the end of the word to the right the given position. If a
            sequence of non-word characters precedes the first word, skip over
            them. (This emulates the behavior of bash, emacs, etc.)
        r   TF)r]   r   ri   r  rg  rS  r  r	   rM  r  r   r  ro   r(   r  rx  r$   )	r@   r   r   r   end_posline_end_posis_indentation_whitespaceback_posr  s	            r#   rS  z"ConsoleWidget._get_word_end_cursor  sn   
 =))++))++##%%--//wM%% ]--//Fx((( 1 ;<<<((3t/H+I+IIH7""h228<<== # A 7""h228<<== # x((((X11(;;<< " -1)#a<!%!9!9!;!;.00()=)=h)G)GHH 491MH	 .00
 - 	" !7** <//%h&:&:8&D&DEE 0 !A	 !7** <//%h&:&:8&D&DEE 0 &&x000!M 7""<'''(<(<X(F(FGG ( A	 7""<'''(<(<X(F(FGG ( 7""<''#H$8$8$B$BCC ( A	 7""<''#H$8$8$B$BCC (
 x(((r%   c           
      @   |                                                                                      d          }|                                  }|                                  }|                    |                                           | j                            |           |                                 }| j        || j        z  z
  }|	                                 t          |dz             D ]}| j                            |           |                    |                                            |rt          ||                                           }|| j        z  }|                    t          j        j        t          j        j        t          ||dk    r|n| j                             |                                 n|                    d|z             |                    t          j        j                   | j                            |           dS )z? Indent/Dedent current line or current text selection.
        u    r   r   rg  N)r  r?  r  rS  r  r]   r   rh  r}   r  rangerx  rj  r  r	   rM  rF  rY  r%  rI  Down)	r@   r   num_newlinessave_curcurr}  step_	safe_steps	            r#   rb  zConsoleWidget._indent  s    ''))6688>>xHH##%%   	**,,---##C((())++&4?":; 	 |A~&& 	5 	5AM'',,,OOD4466777 	)T4#;#;#=#=>>"T_4	  !2!8!&!2!=!$V)q..YY)-": ":; ; ; &&((((s4x(((U.34444 	##H-----r%   c                     | j         |                     || j                   n |                     || j                   | _        |r|                    |           dS dS )zE Inserts new continuation prompt using the specified cursor.
        N)rp   r  ro   r  rI  )r@   r   r-  s      r#   rJ  z)ConsoleWidget._insert_continuation_prompt  su     )1##FD,EFFFF(,(M(M6)8 )8D% 	&f%%%%%	& 	&r%   c                 Z    |t          j                    }|                    |           dS )zA Inserts an empty QTextBlock using the specified cursor.
        N)r	   QTextBlockFormatinsertBlock)r@   r   r  s      r#   r  zConsoleWidget._insert_block  s2      133L<(((((r%   c                    |                                  |                    |           |                    t          j        j        t          j        j                   |                                                                dk    r|	                                 n$|                    t          j        j
                   |                    dt          j                               |                                 dS )zq Inserts HTML using the specified cursor in such a way that future
            formatting is unaffected.
        rg  N)rH  
insertHtmlr  r	   rM  r  rY  rZ  r[  r%  rF  rI  QTextCharFormatrK  )r@   r   r  s      r#   r  zConsoleWidget._insert_html  s     	$ 	E-2!-8	: 	: 	:))++s22%%'''' 1 7888#u466777r%   c                    |                                  |                                 |                                }|                     ||           |                                }|                    |t
          j        j                   |                                	                                }|                    |           |
                                 |S )zc Inserts HTML using the specified cursor, then returns its plain text
            version.
        )rH  r%  r   r  rS  r	   rM  rY  rZ  r[  rK  )r@   r   r  r  r  r   s         r#   r  z.ConsoleWidget._insert_html_fetching_plain_text  s     	!!###!!&$'''oo5%"3">???!!--//3r%   c                 @   | j                                         }| j                             t          j        |                                dz
  |                                dz
                                                      }|                                 }||z
  dk    S )z4Check if the viewport is at the end of the document.r   )	r]   r   r   r   QPointr
  r  r   r  )r@   r   end_scroll_posend_doc_poss       r#   _viewport_at_endzConsoleWidget._viewport_at_end*  s    =))++88M(..**Q.0A0AA0EFF hjj 	 ''))^+q00r%   c                 n   | j                                                                         | j                                                                         z
  }|| j                                                                         k    r.| j                                                             |           dS dS )z"Scroll to the end of the document.N)r]   rX  maximumpageStepvaluerY  )r@   
end_scrolls     r#   rW  zConsoleWidget._scroll_to_end3  s    m5577??AA7799BBDDE
 7799??AAAAM++--66zBBBBB BAr%   c                    |                                  }| j                                                                        }| j        r|s| j                                        rl|                                |                                 k    rB| j	        
                    |           |dk    r |                     | j	        |          | _	        dS | j        r2| j                                        s| j                                         |dk    r|                     ||          }|                                 | j        rQ| j                            |          D ]4}| j        j        D ]1}|j        dk    rZd}d}	|j        dk    r&|                    t,          j        j                   d}|j        dk    r|j        dk    r'|                    t,          j        j                   d}n|j        d	k    r9|                    t,          j        j        t,          j        j                   d}d}	nA|j        d
k    r6|                    t,          j        j        t,          j        j                   d}|r_|	r)|                                |                                 z
  nd}
|!                                 |
dk    r|"                    d|
z             i|j        dk    r|j#        dk    r|"                    d           |$                                 | %                    |           |&                                 |'                                 tP          j)        dk    r8|                    t,          j        j                   |!                                 /|j        dk    r6|                    t,          j        j        t,          j        j*                   p|j        dk    r2tV          j,        -                                .                                 |j        dk    rJ|/                                s4|                    t,          j        j0        t,          j        j*                   |j        dk    r$|                    t,          j        j                   3|| j        1                                }te          |d          r|j3        s|                                }t-          j        |          }|                    t,          j        j                   |                                |z
  }ti          |          }tk          ||          }|6                    ||z   t,          j        j                   |"                    ||           6n|"                    |           |$                                 |r| 7                                 dS dS )zf Inserts plain text using the specified cursor, processing ANSI codes
            if enabled.
        r   NeraseFscreenTrz  allr  r  rg  scrollpagerD  ntzcarriage-returnbeep	backspacenewliner  )8r  r]   r   r  rq   r   isActiver   r  r~   rY   r  r  r  rH  
ansi_codesrk   split_stringactionsr   arear  r	   rM  Documenterase_tor  r  r  rY  rE  r  r  r%  rI  unitrK  r  joinPreviousEditBlockri  r  namer_  r   r   r   r  atBlockStartPreviousCharacter
get_formatrX   r  r  rj  rS  rW  )r@   r   r   r  should_autoscrollrU  	substringactremovefillnspaceformatr   cursor2remainr4  swallows                    r#   r  z ConsoleWidget._insert_plain_text;  s    !1133 m,,..@@BBO 	E 	1::<<	!!T%6%6%8%888%,,T222Q,0,J,J(,(A;-P -P)F? 	64#D#M#M#O#O 	6-33555 ??''k::D? K	$!1>>tDD H8 H8	/7 :I :IC
 zW,,!&$8x//"MM%*;*DEEE%)F8v--"|u44 &e.?.O P P P)-!$!8!8 & 3 3$)$5$A$)$5$@!B !B !B *.'+!$!6!6 & 3 3$)$5$?$)$5$@!B !B !B *.! GTX#_6#6#6#8#89N9N9P9P#P#P^_F"55777%axx):):3v:)F)F)F x//CH4F4F))$///++---,,V44444666113337d??"MM%*;*DEEE"55777'888++!-9!-8: : : : v--!.7799>>@@@@{22%2244 >"// % 1 C % 1 <> > > y00++E,=,GHHH (!1<<>>F#F>:: Uv?R U$oo//"'"3F";";,,U->-HIII!(!1!1!3!3c!9i.."%a..**3w;u7H7STTT%%i777QH8T d### 	"!!!!!	" 	"r%   c                    |                     d          }|r|d                             d          r|                    d           |                                 |                    |d                    |dd         D ]Y}| j        |                    | j                   n |                     || j                  | _        |                    |           Z|                                 dS dS )z Inserts text into the input buffer using the specified cursor (which
            must be in the input buffer), ensuring that continuation prompts are
            inserted as necessary.
        Tr  rD  rF   r   r   N)	
splitlinesendswithrY   rH  rI  rp   ro   r  rK  )r@   r   r   linesrz  s        r#   r   z,ConsoleWidget._insert_plain_text_into_buffer  s   
 %% 	"Ry!!$'' ! R   !!###eAh'''abb	 ( (19%%d&?@@@@ =="D$BD D - !!$''''!!!!!	" 	"r%   c                 4    ||                      |          k    S )zV
        Returns whether the specified position is inside the editing region.
        )_move_position_in_buffer)r@   r   s     r#   r   zConsoleWidget._in_buffer  s     488BBBBr%   c                    | j                                         }|                    |           |                                }|                                                                 }||k    r|| j        k    r|S | j        S ||k    rW|                    t          j        j	                   |
                                t          | j                  z   }||k    r|S |S | j        S )z5
        Return the next position in buffer.
        )r]   ri   rS  r  r_  rX  r  r	   rM  rM  r   r  ro   )r@   r   r   rz  rx  
prompt_poss         r#   r  z&ConsoleWidget._move_position_in_buffer  s     ))++8$$$!!##--//;;==;4+++##+ 1 >???**S1J-K-KKJ:%%r%   c                    | j                                         }|                                }|| j        k     r|                    |           |                                }|                                                                 }||k    r|                    | j                   n$|                    t          j	        j
                   | j                             |           dS |                                }|                     |          }|                     |          }||k    r||k    rdS |                    |           |                    |t          j	        j                   | j                             |           dS )zq Ensures that the cursor is inside the editing region. Returns
            whether the cursor was moved.
        TF)r]   ri   r  rX  rS  r  r_  r  r	   rM  rN  r   r  r  rY  )r@   r   endposrz  rx  startpos
new_endposnew_startposs           r#   r   z$ConsoleWidget._keep_cursor_in_buffer  sp    ))++$$&&D$$$v&&&%%''D1133??AAK{""""4#34444 ##E$5$9:::M''///4((**226::
44X>>LH$<$<5<(((:u'8'CDDD##F+++tr%   c                 v    | j         r*|                                  |                                  dS d| _        dS )z? Cancels the current editing task ala Ctrl-G in Emacs.
        rF   N)r  r  r  r  r?   s    r#   rC  zConsoleWidget._keyboard_quit  sG     # 	###%%%((***** "Dr%   c                 p   t          j        | j                                                  }| j                                                                        |z  }| j        dk    rt          j        d|z  |          r| j        dk    r| j	        
                    |           dS | j                                                            d           | j                                         | j                                        }|r|                     ||           n|                     ||           | j                            t           j        j                   | j                                                            | j                                                   | j        r4| j                                         | j                                         dS |                                                     | j                   dS |r|                     |           dS |                     |           dS )z Displays text using the pager if it exceeds the height of the
        viewport.

        Parameters
        ----------
        html : bool, optional (default False)
            If set, the text will be interpreted as HTML instead of plain text.
        r6   z(?:[^
]*
){%i}r5   r   N)r	   r   r   r  r]   r   r^   rematchcustom_page_requestedrn  r   rT  rg   r  ri   r  r  rL  rM  r  resizer  r`   showrK  r   r  r  rE  )r@   r   r  line_heightminlinesr   s         r#   r  zConsoleWidget._page	  s    (33::<<=))++2244{B;&  +h6== !{h&&*//55555 &&((==a@@@"((***+6688 :%%fd3333++FD999"--e.?.EFFF"++--44T]5G5G5I5IJJJ> G&++---&//11111KKMM2243EFFFFF 	*d#######D)))))r%   c                 N   | j         t          d          |dk    r*| j                             t          j        j                   nW|dk    r*| j                             t          j        j                   n'|dk    rt          d          t          d|z            || _        dS )z
        Change the pager to `paging` style.

        Parameters
        ----------
        paging : string
            Either "hsplit", "vsplit", or "inside"
        NzRcan only switch if --paging=hsplit or
                    --paging=vsplit is used.r3   r4   r2   zCswitching to 'inside' paging not
                    supported yet.zunknown paging method '%s')	r`   r  ra   r   rb   rc   rd   
ValueErrorr^   )r@   r^   s     r#   _set_pagingzConsoleWidget._set_paging&	  s     >!% '0 1 1 1XN))&)*>????xN))&)*<====x% '& ' ' ' 9FBCCCr%   c                 b    | j                             d           |                                  dS )r  TN)r]   r+  r  r?   s    r#   rR  zConsoleWidget._prompt_finished=	  s2     	!!$'''""$$$$$r%   c                    | j                                                             d           | j                             d           | j                             d           | j                             t          j        j        d           | j	        sd| _
        |                                  | j        r| j        | _        d| _        | j                             t          j        j                   dS )r  r   TFrF   N)r]   r   rT  rV  r+  r'  r   rb   r(  r{   rq   r  ru   r  rL  r	   rM  rN  r?   s    r#   _prompt_startedzConsoleWidget._prompt_startedD	  s    
 	  55a888((... 	!!%(((""69#BDIII} 	$#DO!!### % 	, $ :D)+D&  !2!677777r%   c                      j         rt          d          s#                                 st          d          d _         |r                     dd           d|                                vr                     |dd           n                     |d           \d	 _         j         r%t          j                                          j         % 	                    d
          
                    d          S  fd _        d	S )a2   Reads one line of input from the user.

        Parameters
        ----------
        prompt : str, optional
            The prompt to print before reading the line.

        callback : callable, optional
            A callback to execute with the read line. If not specified, input is
            read *synchronously* and this method does not return until it has
            been read.

        Returns
        -------
        If a callback is specified, returns nothing. Otherwise, returns the
        input string with the trailing newline stripped.
        z.Cannot read a line. Widget is already reading.z>Cannot synchronously read a line if the widget is not visible!TzUWarning: QtConsole does not support password mode, the text you type will be visible.)r  ipdbF)r  r  Nr3  rD  c                  h                           d                              d                    S )NTr3  rD  )r]  rw  )r:  r@   s   r#   r  z)ConsoleWidget._readline.<locals>.<lambda>	  s4    //d/;;BB4HHII r%   )r{   RuntimeErrorrJ  r  lowerr|   r   QCoreApplicationprocessEventsr]  rw  )r@   r  r:  passwords   ` ` r#   	_readlinezConsoleWidget._readline\	  s^   $ = 	QOPPP 	2 0 0 	2  1 2 2 2  	R CLP  R R R ''feuEEEEfe444%)D"- 8'55777 - 8)))55<<TBBB&J &J &J &J &JD"""r%   c                 8    |r	|| _         dS || _        d| _         dS )a   Sets the continuation prompt.

        Parameters
        ----------
        prompt : str
            The prompt to show when more input is needed.

        html : bool, optional (default False)
            If set, the prompt will be inserted as formatted HTML. Otherwise,
            the prompt will be treated as plain text, though ANSI color codes
            will be handled.
        N)rp   ro   )r@   r  r  s      r#   _set_continuation_promptz&ConsoleWidget._set_continuation_prompt	  s0      	2-3D***(.D%-1D***r%   c                 :    | j                             |           dS )z7 Convenience method to set the current cursor.
        N)r]   r   r  s     r#   r  zConsoleWidget._set_cursor	  s      	##F+++++r%   c                 R   | j                                         }|                    |                                           | j                                         }| j                             |           | j                                          | j                             |           dS )zJ Scrolls the viewport so that the specified cursor is at the top.
        N)r]   rX  rY  r  ri   r   ensureCursorVisible)r@   r   	scrollbaroriginal_cursors       r#   r  zConsoleWidget._set_top_cursor	  s     M3355	9,,..///-2244##F+++))+++##O44444r%   c                 <   |                                   t          j        dk    r>t          j                            d          st          j                                         nt          j                                         | 	                                }|
                                dk    rd}n1d}| j                            |
                                dz
             |r|
                                dk    rr|                    t          j        j        t          j        j                   |                                                                dk    r|                                  |r|                     | j                   |=| j        |                     | j                   nb|                     | j                   nG|r"|                     |          | _        || _        n#|                     |           || _        d| _        |                                   | j                            |                                 dz
             |r4| j                            | j        
                                dz              |                                  dS )	a   Writes a new prompt at the end of the buffer.

        Parameters
        ----------
        prompt : str, optional
            The prompt to show. If not specified, the previous prompt is used.

        html : bool, optional (default False)
            Only relevant when a prompt is specified. If set, the prompt will
            be inserted as formatted HTML. Otherwise, the prompt will be treated
            as plain text, though ANSI color codes will be handled.

        newline : bool, optional (default True)
            If set, a new line will be written before showing the prompt if
            there is not already a newline at the end of the buffer.

        separator : bool, optional (default True)
            If set, a separator will be written before the prompt.
        r:   QTCONSOLE_TESTINGr   FTr   rD  N)r  r=   r>   r  environr/  r   r  r   rG  r   rj   rS  r  r	   rM  r  rY  rZ  r[  r  rE  rz   rx   rw   r  r  ry   r  r  )r@   r  r  r  r  r   move_forwards          r#   r  zConsoleWidget._show_prompt	  s|   * 	""$$$
 <8## :>>"566 8'55777#11333%%'' ??!! LLL-99&//:K:Ka:OPPP  	%v((1,, 1 6 % 1 <> > >!!--//477""$$$  	6##D$4555> (''5555!!$"34444 )#DDVLL$*!!''///%$(!""$$$''(9(9(;(;a(?@@@ 	B-991::<<q@B B Br%   c                    | j                                         }| j                                         }| j                                                                         }t          | j         t          j                  rTt          d|	                                dz
            }|| j         
                                                                z  }n(|                                                                }|}||                                z
  }|                    dt          |                     |                    t          |                     |dk     rc|                                |                                k    r;|                    t          |                                |z                        dS dS dS )zD Expands the vertical scrollbar beyond the range set by Qt.
        r   r   N)r]   r   rX  r   r  
isinstancer   r  r  	lineCountfontMetricslineSpacingr  r  setRangeroundsetPageStep
blockCountr  rY  r  )r@   r   r(  viewport_heightr  r  diffs          r#   r   z ConsoleWidget._adjust_scrollbars 
  s}   
 =))++M3355	-002299;;dmY%=>> 	#!X//11A566G"T]%>%>%@%@%L%L%N%NNDD
 mmoo,,..G"D**,,,1eGnn---eDkk*** !88++--1K1K1M1MMMuY__%6%6%=>>????? 8MMr%   c                     |                      |          }|                    | j                            |                     dS )zK Shows a context menu at the given QPoint (in widget coordinates).
        N)r  r~  r]   mapToGlobal)r@   r   r
  s      r#   r  z,ConsoleWidget._custom_context_menu_requested
  s?     &&s++

4=,,S1122222r%   r   )T)FrF   )NFF)F)NF)r  )rF   )rF   NF)NFTT)__name__
__module____qualname____doc__r   r  r   rU  r>  r   rl   rm   r  r^   r$  r   r  rA   r  r  r  r   r  r0  r   Signalr  r  r  r   objectr  r	   r  rm  r]   rg   r`   rb   rZ  r7  r[  r9  Key_Ar8  Key_Pr;  Key_Nr<  Key_HrP  r   r=   r>   r:  Key_EsetkeysKey_CrB  rI  Key_Vr   r  rP   r   r   r   r   r  include_other_outputother_output_prefixr  r  r  r  r  r#  r&  r2  r0  r;  rB  r?  r   rF  r]  ra  propertyr  rd  r   ro  r   rq  ru  r   	Clipboardr   r   r  r  r   r  r   r   r   r  r  r  rj  r  r  r=  r  r  r  r  r  r  r  r  r  rE  r  r  r  r  r  r   r\   rf   r   r   r   r  r  r  rG  r  r  rx  r  rg  r  r  rA  r  r  r  rh  rX  r  r_  r  rR  rS  rb  rJ  r  r  r  r  rW  r  r   r   r  r   rC  r  r  rR  r  r"  r$  r  r  r  r   r  __classcell__)r   s   @r#   r*   r*   /   s0         d44  J '#d  K !%T$! ! ! T:::4$-
  N $GAd	 	 	 4&!  D TBBB (  F&  4T  
 '  K	 	 	 t  I
 GBt  M
 WR  N e N
 #V]4((N"V]4((N"V]4((N *FM&11 !6=--L
 HMI  69+=69+>69+=69+;69+=69+BF <8## -3I,=) %**,,--y	y))J  X" X" X" X" X" X"|
 
 

 
 
B B BA/ A/ A/ A/ A/N5 5 5>  4d   "'+d  9 9 9
4 4 4  1 1 1 1$- - -
; ; ;
< < <K K K9 9 9 9

J 
J 
J3. 3. 3. 3.j< < <4% % %
0 0 0*L L L L$8 8 8. 8-/@AAL6 6 6
+ + + +% % % 8Iy))D
- 
- 
-" " "
 )3 F F F F<& & & &0 0 0    (  ! ! !" " "+ + +$" " "
  
$ $ $ 88I  " " "" " "
  
           *M M M M
D D D D
8 8 8 8J J J J
4 4 4
3 3 3>J J J*( ( ( ("     D? ? ? ?$1 1 1f  0c c cJ? ? ?B3 3 3
 
 
9 9 9 9,* * *
  1 1 1
  8 8 8
  6 6 6
	7 	7 	7
& 
& 
&Q Q Q     .  . . .  L L XL
 ( ( X(    . . .`A A AF$. $. $. $.L	& 	& 	& 	&) ) ) )  *  "1 1 1C C Cj" j" j" j"X" " ".C C C     (  @# # ##* #* #* #*J  .% % %8 8 80,J ,J ,J ,J\2 2 2 2&, , ,
5 5 5 =A#P P P Ph@ @ @43 3 3 3 3 3 3r%   r*   NewBase)0r>  	functoolsr   r  os.pathr  r=   textwrapr   r6  unicodedatar   rs  qtpyr   r   r	   r
   r   qtconsole.rich_textr   qtconsole.utilr   r   r   ipython_genutils.textr   traitlets.config.configurabler   	traitletsr   r   r   r   ansi_code_processorr   completion_widgetr   completion_htmlr   completion_plainr   	kill_ringr   r$   r(   QWidgetr*   rN   r%   r#   <module>r`     s   6 6
       				  				 



                              9 9 9 9 9 9 9 9 9 9 9 9 , , , , , , A A A A A A A A A A + + + + + + = = = = = = 2 2 2 2 2 2 2 2 2 2 2 2 4 4 4 4 4 4 / / / / / / + + + + + + - - - - - - ! ! ! ! ! !6 6 6* * *o'3 o'3 o'3 o'3 o'3((5H&&QZQbJcJc4dfhii o'3 o'3 o'3 o'3 o'3r%   