
    @OOfl)                     V   d dl Z d dl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 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 dlmZ d dlmZ d dlmZ  G d dej"                        Z G d d      Z G d dej"                        Z G d dej*                  j,                        Zy)    N)flow)commands)common)eventlog)flowlist)flowview)
grideditor)help)keybindings)options)overlay)signals)	statusbarc                   2     e Zd Z fdZ fdZ fdZ xZS )StackWidgetc                     || _         || _        |r.t        j                  t        j                  |      |rdnd      }nd }t
        |   ||       y )Nheadingheading_inactive)header)
is_focusedwindowurwidAttrWrapTextsuper__init__)selfr   widgettitlefocusr   	__class__s         _/var/www/premiumrankchecker/venv/lib/python3.12/site-packages/mitmproxy/tools/console/window.pyr   zStackWidget.__init__   sN    ^^

5!9;MF F/    c                     |dk(  r+|dk(  r&| j                   s| j                  j                          t        |   ||||||      S )Nmouse press   )r   r   switchr   mouse_event)r   sizeeventbuttoncolrowr    r!   s          r"   r(   zStackWidget.mouse_event!   sA    M!fk$//KK w"4S%HHr#   c                 n    t         |   ||      }| j                  |   }|r|j                  d      ry |S )Ncursor)r   keypress_command_map
startswith)r   r)   keyretcommandr!   s        r"   r0   zStackWidget.keypress&   sC     gtS)##
 w))(3
r#   )__name__
__module____qualname__r   r(   r0   __classcell__r!   s   @r"   r   r      s    
0I

 
r#   r   c                   6    e Zd Zd Zd Zd Zd Zd Zd Zd Z	y)	WindowStackc                    || _         t        di dt        j                  |      dt	        j
                  |      dt        j                  |      dt        j                  |      dt        j                  |      dt        j                  |      dt        j                  |      dt!        j"                  |      d	t!        j$                  |      d
t!        j&                  |      dt!        j(                  |      dt!        j*                  |      dt!        j,                  |      dt!        j.                  |      dt!        j0                  |      dt!        j2                  |      | _        |g| _        d | _        y )Nr   r   r   r   r   r
   r   edit_focus_queryedit_focus_cookiesedit_focus_setcookiesedit_focus_setcookie_attrsedit_focus_multipart_formedit_focus_urlencoded_formedit_focus_pathedit_focus_request_headersedit_focus_response_headers )masterdictr   FlowListBoxr   FlowViewr   Commandsr   KeyBindingsr   Optionsr
   HelpViewr   EventLogr	   QueryEditorCookieEditorSetCookieEditorCookieAttributeEditorRequestMultipartEditorRequestUrlEncodedEditor
PathEditorRequestHeaderEditorResponseHeaderEditorwindowsstackr   )r   rH   bases      r"   r   zWindowStack.__init__4   so    
))&1
&&v.
 &&v.
 $//7	

 OOF+
 v&
 &&v.
 (33F;
  *66v>
 #-"<"<V"D
 (2'G'G'O
 '1&G&G&O
 (2'I'I&'Q
 '11&9
 (2'E'Ef'M
  )3(G(G(O!
$ V
r#   c                 p    t        j                  | || j                         |j                  fi || _         y N)r   SimpleOverlay
top_widgetwidthr   okwargss      r"   set_overlayzWindowStack.set_overlayK   s5    ,,OOGG	

 
r#   c                 :    | j                   | j                  d      S )z<
        The current top window, ignoring overlays.
        )rZ   r[   r   s    r"   
top_windowzWindowStack.top_windowT   s     ||DJJrN++r#   c                 R    | j                   r| j                   S | j                         S )zQ
        The current top widget - either a window or the active overlay.
        )r   ri   rh   s    r"   r`   zWindowStack.top_widgetZ   s"     <<<<  r#   c                     | j                   d   |k(  ry | j                         }| j                   j                  |       | j                  d|       y )Nrg   layout_pushed)r[   ri   appendcall)r   wnameprevs      r"   pushzWindowStack.pushb   sA    ::b>U" 

% 		/4(r#   c                     | j                   st        | j                        dk(  ry| j                  d       | j                   rd| _         y| j                  j	                          y)zM
        Pop off the stack, return True if we're already at the top.
        r&   Tlayout_poppingN)r   lenr[   rn   pop)r   argsrd   s      r"   ru   zWindowStack.popi   sF     ||DJJ1 4		"#<<DLJJNNr#   c                      t        | j                         |      |i | | j                  r t        | j                  |      |i | yy)z
        Call a function on both the top window, and the overlay if there is
        one. If the widget has a key_responder, we call the function on the
        responder instead.
        N)getattrri   r   )r   namerv   rd   s       r"   rn   zWindowStack.callu   sG     	)!4($9&9<<'GDLL$'88 r#   N)
r6   r7   r8   r   re   ri   r`   rq   ru   rn   rG   r#   r"   r<   r<   3   s%    .
,!)
9r#   r<   c                        e Zd Z fdZd Zd Zd Zdej                  ddfdZ	d	 Z
d
 Zd Zd ZddZd Zd Zd Zd Zd Z fdZ fdZ xZS )Windowc                    t        j                  |      | _         t        |   d d t	        j
                  | j                   d             || _        | j                  j                  j                  j                  | j                         | j                  j                  j                  j                  | j                         | j                  j                  j                  j                  | j                         | j                  j                  j                  j                  | j                         | j                  j                  j                  j                  j                  | j                         | j                  j                  j                  j                  j                  | j                          t"        j                  j                  | j$                         t"        j&                  j                  | j(                         t"        j*                  j                  | j,                         | j                  j.                  j1                  | j2                  ddg       d| _        t7        |d      t7        |d      g| _        y )N
background)r   footerconsole_layoutconsole_layout_headersr   r   r   )r   	StatusBarr   r   r   r   rH   viewsig_view_refreshconnectview_changedsig_view_addsig_view_removesig_view_updater    
sig_changefocus_changedr   	sig_focusflow_changeflow_changedpop_view_stateru   r   	subscribe	configurepaner<   stacks)r   rH   r!   s     r"   r   zWindow.__init__   s   ",,V4ennT^^\&R 	 	
 ))11$2C2CD%%--d.?.?@((001B1BC((001B1BC))11$2C2CD))11$2D2DEdnn-##D$5$56&&txx0%%NN-/GH	
 	"6:6FJ8WXr#   c                 4    | j                   | j                     S r^   )r   r   rh   s    r"   focus_stackzWindow.focus_stack   s    {{499%%r#   c                 $    | j                          y r^   )refresh)r   r   updateds      r"   r   zWindow.configure   s    r#   c           	      T     j                   j                  j                  }|dk(  rd _         fd}d}|dk(  r	 |d      }n|dk(  rNt	        j
                  t         j                        D cg c]  \  }} ||       c}} j                        }nNt	        j                  t         j                        D cg c]  \  }} ||       c}}d j                        }t	        j                  |d	       _
        t        j                  j                          yc c}}w c c}}w )
z$
        Redraw the layout.
        singler   c                    j                   |    j                         }j                  j                  j                  r(j                   |    j                         j                  }nd }t        ||j                  | k(        S r^   )	r   r`   rH   r   r   ri   r   r   r   )idxr   r   r   s      r"   wrappedzWindow.refresh.<locals>.wrapped   si    [[%002F{{""99C(335;;tVUDII4DEEr#   Nvertical)
focus_itemr&   )dividecharsfocus_columnr}   )rH   r   r   r   r   Pile	enumerater   Columnsr   bodyr   window_refreshsend)r   cr   wiss   `     r"   r   zWindow.refresh   s     KK..=DI	F =
A*_

(1$++(>?1?DIIA (1$++(>?1?!YYA NN1l3	##% @ @s   /D
=D$
r   returnNc                     | j                   j                  j                  j                  rS|j                  | j                   j                  j                  j                  j                  k(  r| j                          y y y r^   )rH   r   r    r   idr   )r   r   s     r"   r   zWindow.flow_changed   sY    ;;!!&&ww$++**0055888""$ 9 'r#   c                 H    | j                   D ]  }|j                  d        y)z
        Triggered when the focus changes - either when it's modified, or
        when it changes to a different flow altogether.
        r   Nr   rn   r   rv   rd   r   s       r"   r   zWindow.focus_changed   s#    
  	$AFF?#	$r#   c                 H    | j                   D ]  }|j                  d        y)z;
        Triggered when the view list has changed.
        r   Nr   r   s       r"   r   zWindow.view_changed   s#      	#AFF>"	#r#   c                 f     | j                         j                  |fi | | j                          y)z@
        Set an overlay on the currently focused stack.
        N)r   re   r   rb   s      r"   re   zWindow.set_overlay   s+     	'&&q3F3r#   c                     | j                         j                  |       | j                          | j                          | j	                          y)zA
        Push a window onto the currently focused stack.
        N)r   rq   r   r   r   )r   ro   s     r"   rq   zWindow.push   s<     	&r#   c                     | j                         j                         r| j                  j                          y| j	                          | j                          | j                          y)z
        Pop a window from the currently focused stack. If there is only one
        window on the stack, this prompts for exit.
        N)r   ru   rH   prompt_for_exitr   r   r   rh   s    r"   ru   z
Window.pop   sJ    
 !!#KK'')LLN r#   c                     | j                   j                         }|j                  d|j                  | j                               |S )zQ
        Returns:
            self.stacks, with the focused stack first.
        r   )r   copyinsertru   r   )r   r   s     r"   stacks_sorted_by_focuszWindow.stacks_sorted_by_focus   s6    
 !!#aDII./r#   c                 t    | j                         D ]%  }|j                         }|j                  |k(  s#|c S  y)z
        Returns the active widget with a matching key context, including overlays.
        If multiple stacks have an active widget with a matching key context,
        the currently focused stack is preferred.
        N)r   r`   keyctxr   r   r   ts       r"   currentzWindow.current   8     ,,. 	AAxx6!	r#   c                 t    | j                         D ]%  }|j                         }|j                  |k(  s#|c S  y)z
        Returns the active window with a matching key context, ignoring overlays.
        If multiple stacks have an active widget with a matching key context,
        the currently focused stack is preferred.
        N)r   ri   r   r   s       r"   current_windowzWindow.current_window  r   r#   c                     || _         y r^   )focus_position)r   sections     r"   r   zWindow.sig_focus  s
    %r#   c                     | j                   j                  j                  dk(  rd| _        n*| j                  dz   t	        | j
                        z  | _        | j                          y)z/
        Switch between the two panes.
        r   r   r&   N)rH   r   r   r   rt   r   r   rh   s    r"   r'   zWindow.switch  sI     ;;--9DIQ#dkk*::DIr#   c                    t        |   |i |}|sw|d   dk(  r"t        j                  j	                  dd       y|d   dk(  r|d   dk(  r| j                  |d   d	       y|d   dk(  r|d   d
k(  r| j                  |d   d       yyy )Nr&   z
mouse dragz_Hold down fn, shift, alt or ctrl to select text or use the --set console_mouse=false parameter.)messageexpirer%         r   up   downFT)r   r(   r   status_messager   r0   )r   rv   rd   kr!   s       r"   r(   zWindow.mouse_event  s    G00Aw,&&&++} ,   aM)d1gld1gt,
 	 aM)d1gld1gv.   r#   c                     t         |   ||      }|rL| j                  j                  j	                  | j                         j                         j                  |      S y r^   )r   r0   rH   keymaphandler   r`   r   )r   r)   r   r!   s      r"   r0   zWindow.keypress,  sR    GT1%;;%%,,T-=-=-?-J-J-L-S-SUVWW r#   )r   N)r6   r7   r8   r   r   r   r   r   Flowr   r   r   re   rq   ru   r   r   r   r   r'   r(   r0   r9   r:   s   @r"   r{   r{      ss    Y.&&B% %t %
$#
!		&"X Xr#   r{   c                        e Zd Z fdZ xZS )Screenc                 r    t         j                  rt        j                  dd|      }t        |   |       y )Nz[] )r   IS_WINDOWS_OR_WSLresubr   write)r   datar!   s     r"   r   zScreen.write3  s,    ## 66,D1Ddr#   )r6   r7   r8   r   r9   r:   s   @r"   r   r   2  s     r#   r   )r   r   	mitmproxyr   mitmproxy.tools.consoler   r   r   r   r   r	   r
   r   r   r   r   r   Framer   r<   r{   raw_displayr   rG   r#   r"   <module>r      s|    	   , * , , , . ( / + + + -%++ >J9 J9ZoXU[[ oXdU%% r#   