)L i)bUddlmZddlZejdk7sJddlZddlZddlZddlZddlm Z m Z ddl m Z m Z mZmZddlmZdd lmZdd lmZdd lmZgd ZGd deZiZded<ej8 ddZej8ddZGddZGddeZ y)) annotationsNwin32)AbstractEventLoopget_running_loop)CallableContextManager GeneratorTextIO)KeyPress)Input)PosixStdinReader) Vt100Parser) Vt100Inputraw_mode cooked_modeceZdZUdZeZded<ddZddZddZ ddZ ddZ e dd Z dd Zdd Zdd Zdd Zy)rzz Vt100 input for Posix systems. (This uses a posix file descriptor that can be registered in the event loop.) zset[int]_fds_not_a_terminalc |j|j }|j}|ss|t jvrad}tjj||ztjjt jj||_ |j_ g_tj|j _t%fd_y#tj$rC}dtjvrtjd|tjd|d}~wwxYw)Nz idlelib.runzz%Vt100Input.__init__..Jsdll11)<)filenoioUnsupportedOperationsysmodulesisattyrrstderrwriteflushaddstdin_filenorrr stdin_readerr vt100_parser)rr+er&fdmsgs` r__init__zVt100Input.__init__$s Q LLN \\^"J$B$BB?C JJ  S2X & JJ     * * . .r 2 ||~ ') ,T\\ENNS' < ?&& Q +--R--.HIqP  QsDE>EEct||S)zj Return a context manager that makes this input active in the current event loop. )_attached_input)rinput_ready_callbacks rattachzVt100Input.attachMs t%9::r ct|S)z{ Return a context manager that makes sure that this input is not active in the current event loop. )_detached_inputrs rdetachzVt100Input.detachTs t$$r c|jj}|jj||j}g|_|S)zRead list of KeyPress.)r-readr.feedr)rdataresults r read_keyszVt100Input.read_keys[sE  %%' t$  r c`|jj|j}g|_|S)zc Flush pending keys and return them. (Used for flushing the 'escape' key.) )r.r)r)rr?s r flush_keyszVt100Input.flush_keyshs- !  r c.|jjSr)r-closedr9s rrDzVt100Input.closedvs  '''r cHt|jjSr)rr+r!r9s rrzVt100Input.raw_modezs ))+,,r cHt|jjSr)rr+r!r9s rrzVt100Input.cooked_mode}s4::,,.//r c6|jjSr)r+r!r9s rr!zVt100Input.filenoszz  ""r c d|jS)Nzfd-)r,r9s rtypeahead_hashzVt100Input.typeahead_hashsT\\N##r N)r+r returnNone)r5Callable[[], None]rJContextManager[None])rJrM)rJzlist[KeyPress])rJbool)rJint)rJstr)__name__ __module__ __qualname____doc__setr__annotations__r2r6r:r@rBpropertyrDrrr!rIr rrrsX%(E)' R;%  ((-0#$r rz>dict[tuple[AbstractEventLoop, int], Callable[[], None] | None]_current_callbacksc#Ktjtjf}dfd } j |tf< dj|rj ||tf<ytf=y#t $rt wxYw#j|rj ||tf<wtf=wxYww)z Context manager that makes this input active in the current event loop. :param input: :class:`~prompt_toolkit.input.Input` object. :param callback: Called when the input is ready to read. cNjrjy)a:Wrapper around the callback that already removes the reader when the input is closed. Otherwise, we keep continuously calling this callback, until we leave the context manager (which can happen a bit later). This fixes issues when piping /dev/null into a prompt_toolkit application.N)rD remove_reader)callbackr0inputloopsrcallback_wrapperz)_attached_input..callback_wrappers <<   r " r NrJrK)rr!rYget add_readerPermissionErrorEOFErrorr\)r^r]previousr`r0r_s`` @@rr4r4s  D B!%%tRj1H  ,-$,tRx  -  2  OOB )+3 tRx ("48,+  2  OOB )+3 tRx ("48,s5;C1B C1 B2$;C1B//C12Kt}|j}tj||f}|r|j |dt||f< d|r|j |||t||f<yy#|r|j |||t||f<wwxYwwr)rr!rYrbr\rc)r^r_r0rfs rr8r8s  D B!%%tRj1H 2'+48$4  OOB )+3 tRx ( 8 OOB )+3 tRx ( sABA8!B8"BBcLeZdZdZddZd dZed dZed dZd dZ y) rz :: with raw_mode(stdin): ''' the pseudo-terminal stdin is now used in raw mode ''' We ignore errors when executing `tcgetattr` fails. c||_| tj||_y#tj$r d|_YywxYwr)r!termios tcgetattr attrs_beforeerror)rr!s rr2zraw_mode.__init__s?   % ' 1 1& 9D }} % $D  %s&AAc tj|j}|j|tj |tj <|j |tj|tj<d|tjtj<tj|jtj|y#tj$rYywxYw)Nr ) rjrkr! _patch_lflagttyLFLAG _patch_iflagIFLAGCCVMIN tcsetattrTCSANOWrm)rnewattrs r __enter__zraw_mode.__enter__s E'' 4G"&!2!273993E!FGCII !%!2!273993E!FGCII -.GCFFOGLL )   dkk7??G D}}   sCC10C1c|tjtjztjztjzzSrrjECHOICANONIEXTENISIGclsattrss rrozraw_mode._patch_lflags/6G',,VWWWr c|tjtjztjztjztj zzSr)rjIXONIXOFFICRNLINLCRIGNCRrs rrrzraw_mode._patch_iflagsS LLmm  MM   mm   mm     r c|j; tj|jtj|jyy#tj $rYywxYwr)rlrjrvr!rwrm)ras r__exit__zraw_mode.__exit__sP    ( !!$++w@Q@QR )==  s9A AAN)r!rOrJrKrarrOrJrO)robjectrJrK) rQrRrSrTr2ry classmethodrorrrrXr rrrsA.%E&XX    r rc4eZdZdZeddZeddZy)rz The opposite of ``raw_mode``, used when we need cooked mode inside a `raw_mode` block. Used in `Application.run_in_terminal`.:: with cooked_mode(stdin): ''' the pseudo-terminal stdin is now used in cooked mode. ''' c|tjtjztjztjzzSrr{rs rrozcooked_mode._patch_lflag+s, w~~5FUVVr c(|tjzSr)rjrrs rrrzcooked_mode._patch_iflag/s w}}$$r Nr)rQrRrSrTrrorrrXr rrr"s1WW%%r r)r^rr]rLrJGenerator[None, None, None])r^rrJr)! __future__rr$platform contextlibr"rjrpasynciorrtypingrrr r key_bindingr baser posix_utilsrr.r__all__rrYrVcontextmanagerr4r8rrrXr rrs"  ||w  7>>")% j$j$^  .- .-!3.- .-.-b 44"LLd%(%r