)L i(dZddlmZddlmZmZddlmZmZddl m Z m Z ddl m Z mZmZddlmZdd lmZerdd lmZgd ZGd d eZGddeZGddeZGddeZGddeZy)zQ Margin implementations for a :class:`~prompt_toolkit.layout.containers.Window`. ) annotations)ABCMetaabstractmethod) TYPE_CHECKINGCallable) FilterOrBool to_filter)StyleAndTextTuplesfragment_list_to_textto_formatted_text) get_cwidth) UIContent)WindowRenderInfo)MarginNumberedMarginScrollbarMarginConditionalMargin PromptMargincDeZdZdZeddZe ddZy)rz& Base interface for a margin. cy)a  Return the width that this margin is going to consume. :param get_ui_content: Callable that asks the user control to create a :class:`.UIContent` instance. This can be used for instance to obtain the number of lines. rselfget_ui_contents c/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/prompt_toolkit/layout/margins.py get_widthzMargin.get_width%scgS)a Creates a margin. This should return a list of (style_str, text) tuples. :param window_render_info: :class:`~prompt_toolkit.layout.containers.WindowRenderInfo` instance, generated after rendering and copying the visible part of the :class:`~prompt_toolkit.layout.controls.UIControl` into the :class:`~prompt_toolkit.layout.containers.Window`. :param width: The width that's available for this margin. (As reported by :meth:`.get_width`.) :param height: The height that's available for this margin. (The height of the :class:`~prompt_toolkit.layout.containers.Window`.) rrwindow_render_infowidthheights r create_marginzMargin.create_margin0s $ rNrzCallable[[], UIContent]returnintr!rr"r'r#r'r&r )__name__ __module__ __qualname____doc__rrr$rrrrr sO"2;>HK rr) metaclasscFeZdZdZ d ddZddZ d dZy) ra Margin that displays the line numbers. :param relative: Number relative to the cursor position. Similar to the Vi 'relativenumber' option. :param display_tildes: Display tildes after the end of the document, just like Vi does. cDt||_t||_yN)r relativedisplay_tildes)rr1r2s r__init__zNumberedMargin.__init__Os"(+ '7rcV|j}tdt|dzS)Nr) line_countmaxlen)rrr6s rrzNumberedMargin.get_widthUs)#%00 1cZL*Q.//rcz|j}d}d}|jjj}g}d} t |j D]\} } | | k7r| n| |k(rE|r|j |d| dzzfnd|j |d| dzzj|fn;|rt| |z dz } |j |d| dzzj|f| } |j d|jr5 |jkr&|j d| dz } | |jkr&|S)Nzclass:line-numberzclass:line-number.currentz%irz%i  )z class:tildez~ ) r1 ui_contentcursor_positiony enumeratedisplayed_linesappendrjustabsr2 window_height) rr!r"r#r1style style_currentcurrent_linenoresult last_linenor?linenos rr$zNumberedMargin.create_marginYsT==?#3 ,66FFHH&( "#5#E#EF &IAv$>~- }dfqj6I&JK *Ufqj-A,H,H,OP  !$Vn%J8 8 0-"2-;>-HK- -rrc8eZdZdZddZddZ ddZy) rzJ Wrapper around other :class:`.Margin` classes to show/hide them. c2||_t||_yr0)marginr filter)rrPrQs rr3zConditionalMargin.__init__s ' rcZ|jr|jj|Sy)Nr)rQrPrrs rrzConditionalMargin.get_widths# ;;=;;((8 8rcd|r-|jr|jj|||SgSr0)rQrPr$r s rr$zConditionalMargin.create_margins. T[[];;,,-?O OIrN)rPrrQrr&rLr%r(rMrrrrrs6( "2;>HK rrcNeZdZdZ d ddZddZ d dZy) rzc Margin displaying a scrollbar. :param display_arrows: Display scroll up/down arrows. c@t||_||_||_yr0)r display_arrowsup_arrow_symboldown_arrow_symbol)rrVrWrXs rr3zScrollbarMargin.__init__s! (7.!2rcy)Nrrrs rrzScrollbarMargin.get_widthsrc |j}|j}|j}|r|dz} t|jt |z }|j t |z }tt|td||zt||zd fd } g} |r| jd|jfdgd} d} d} d }t|D]}| |r3| |dzs| j|d fnF| j| d fn2| |dzr| j| d fn| j| d f| jd |r| jd|jf| S#t$rgcYSwxYw) Nrc*|cxkxrzkScS)z/True if we should display a button on this row.r)rowscrollbar_height scrollbar_tops ris_scroll_buttonz7ScrollbarMargin.create_margin..is_scroll_buttons$O}?O/OOOOOrzclass:scrollbar.arrow)zclass:scrollbarr<zclass:scrollbar.backgroundz*class:scrollbar.background,scrollbar.startzclass:scrollbar.buttonz$class:scrollbar.button,scrollbar.end r:)r]r'r&bool)content_heightrErVr8rAfloatvertical_scrollr'minr7extendrWrangerBrXZeroDivisionError)rr!r"r#rcrErVfraction_visiblefraction_abover`rIscrollbar_backgroundscrollbar_background_startscrollbar_buttonscrollbar_button_endir^r_s @@rr$zScrollbarMargin.create_margins,::*88 ,,.  Q M5 "#5#E#EFJ  0??%BWWN"M3q-:J*J#KL    >?M  P *,F 0$2F2FG1$@ )U &7 #I =) *#A&+AE2 ';S&AB '7&=>'A. 'A3&GH ';S&AB j) *  68N8NOPMW! I sA)E== F  F N)F^v)rVrrWstrrXrsr&rLr%r(rMrrrrrsg(-"!$ 3$33 3  3?"2?;>?HK? ?rrcFeZdZdZ d ddZddZ d dZy) ra [Deprecated] Create margin that displays a prompt. This can display one prompt at the first line, and a continuation prompt (e.g, just dots) on all the following lines. This `PromptMargin` implementation has been largely superseded in favor of the `get_line_prefix` attribute of `Window`. The reason is that a margin is always a fixed width, while `get_line_prefix` can return a variable width prefix in front of every line, making it more powerful, especially for line continuations. :param get_prompt: Callable returns formatted text or a list of `(style_str, type)` tuples to be shown as the prompt at the first line. :param get_continuation: Callable that takes three inputs. The width (int), line_number (int), and is_soft_wrap (bool). It should return formatted text or a list of `(style_str, type)` tuples for the next lines of the input. Nc ||_||_yr0) get_promptget_continuation)rrvrws rr3zPromptMargin.__init__ s % 0rcJt|j}t|S)z Width to report to the `Window`.)r rvr )rrtexts rrzPromptMargin.get_widths %T__%67$rc |j}g}|jt|j|rNd}|jddD]:}|j d|jt|||||k(|}<|S)Nrr:)rwrgr rvrArB)rr!r"r#rwrIlast_yr?s rr$zPromptMargin.create_margins 00%'  '(9:; F'77;  j) %&6uaf&MN   rr0)rvz Callable[[], StyleAndTextTuples]rwz5None | Callable[[int, int, bool], StyleAndTextTuples]r&rLr%r(rMrrrrrsX2>B 141;1  1 "2;>HK rrN)r, __future__rabcrrtypingrrprompt_toolkit.filtersrr prompt_toolkit.formatted_textr r r prompt_toolkit.utilsr controlsr containersr__all__rrrrrrrrrsz#'*: ,, "w"JAVAH0SfSl969r