ó |fc@stdZddlZddlZd„Zdd d„ƒYZedkrpd„ZejeƒZdGe eƒGHndS( s:Simple textbox editing widget with Emacs-like keybindings.iÿÿÿÿNcCsð|j|d|tj||dƒ|j||dtj||dƒ|j||dtj||dƒ|j|d|tj||dƒ|j||tjƒ|j||tjƒ|j||tjƒ|j||tj ƒdS(s^Draw a rectangle with corners at the provided upper-left and lower-right coordinates. iN( tvlinetcursest ACS_VLINEthlinet ACS_HLINEtaddcht ACS_ULCORNERt ACS_URCORNERt ACS_LRCORNERt ACS_LLCORNER(twintulytulxtlrytlrx((s&/usr/lib64/python2.7/curses/textpad.pyt rectangles%%%%tTextboxcBsSeZdZed„Zd„Zd„Zd„Zd„Zd„Z dd„Z RS( sdEditing widget using the interior of a window object. Supports the following Emacs-like key bindings: Ctrl-A Go to left edge of window. Ctrl-B Cursor left, wrapping to previous line if appropriate. Ctrl-D Delete character under cursor. Ctrl-E Go to right edge (stripspaces off) or end of line (stripspaces on). Ctrl-F Cursor right, wrapping to next line when appropriate. Ctrl-G Terminate, returning the window contents. Ctrl-H Delete character backward. Ctrl-J Terminate if the window is 1 line, otherwise insert newline. Ctrl-K If line is blank, delete it, otherwise clear to end of line. Ctrl-L Refresh screen. Ctrl-N Cursor down; move down one line. Ctrl-O Insert a blank line at cursor location. Ctrl-P Cursor up; move up one line. Move operations do nothing if the cursor is at an edge where the movement is not possible. The following synonyms are supported where possible: KEY_LEFT = Ctrl-B, KEY_RIGHT = Ctrl-F, KEY_UP = Ctrl-P, KEY_DOWN = Ctrl-N KEY_BACKSPACE = Ctrl-h cCs?||_||_|jƒd|_d|_|jdƒdS(Ni(R t insert_modet_update_max_yxt stripspacestNonetlastcmdtkeypad(tselfR R((s&/usr/lib64/python2.7/curses/textpad.pyt__init__+s      cCs3|jjƒ\}}|d|_|d|_dS(Ni(R tgetmaxyxtmaxytmaxx(RRR((s&/usr/lib64/python2.7/curses/textpad.pyR3s cCs…|jƒ|j}xktr€tjj|jj||ƒƒtjjkrct|j|dƒ}Pn|dkrsPn|d}qW|S(suGo to the location of the first blank on the given line, returning the index of the last non-blank character.ii( RRtTrueRtasciiR tinchtSPtmin(Rtytlast((s&/usr/lib64/python2.7/curses/textpad.pyt _end_of_line8s   - cCs |jƒ|jjƒ\}}d}x¿||jksF||jkræ|jra|jjƒ}ny|jj|ƒWnt j k r‹nX|j s©t j j |ƒ r­Pn|}|jjƒ\}}|dkr(||f}q(q(W|dk r|jj |ŒndS(N(RR tgetyxRRRRRRRterrorRtisprinttmove(RtchR!txtbackyxtoldch((s&/usr/lib64/python2.7/curses/textpad.pyt_insert_printable_charFs$ !   cCso|jƒ|jjƒ\}}||_tjj|ƒrk||jksX||jkrk|j |ƒqkn|tjj kr“|jj |dƒnØ|tjj tj tjjtjfkrj|dkrã|jj ||dƒnY|dkrònJ|jr"|jj |d|j|dƒƒn|jj |d|jƒ|tjjtjfkrk|jjƒqkn|tjjkrŒ|jjƒnß|tjjkrß|jrÆ|jj ||j|ƒƒqk|jj ||jƒnŒ|tjjtjfkrO||jkr#|jj ||dƒqk||jkr5qk|jj |ddƒn|tjjkredS|tjjkr¶|jdkrŠdS||jkrk|jj |ddƒqknµ|tjjkr|dkrù|j|ƒdkrù|jjƒqk|jj ||ƒ|jjƒnO|tjjkr>|jjƒn-|tjjtjfkrÅ||jkrk|jj |d|ƒ||j|dƒkrÂ|jj |d|j|dƒƒqÂqkn¦|tjj krç|jj!ƒn„|tjj"tj#fkrk|dkrk|jj |d|ƒ||j|dƒkrh|jj |d|j|dƒƒqhqkndS(s!Process a single editing command.ii($RR R$RRRR&RRR,tSOHR'tSTXtKEY_LEFTtBSt KEY_BACKSPACERR#tdelchtEOTtENQtACKt KEY_RIGHTtBELtNLtVTtdeletelntclrtoeoltFFtrefreshtSOtKEY_DOWNtSItinsertlntDLEtKEY_UP(RR(R!R)((s&/usr/lib64/python2.7/curses/textpad.pyt do_command_sr  *   ' !- -cCsíd}|jƒxÖt|jdƒD]Á}|jj|dƒ|j|ƒ}|dkrg|jrgq$nx_t|jdƒD]J}|jrš||kršPn|tt j j |jj ||ƒƒƒ}q{W|jdkr$|d}q$q$W|S(s.Collect and return the contents of the window.tiis ( RtrangeRR R'R#RRtchrRRR(RtresultR!tstopR)((s&/usr/lib64/python2.7/curses/textpad.pytgather s /cCsaxT|jjƒ}|r'||ƒ}n|s3qn|j|ƒsFPn|jjƒqW|jƒS(s2Edit in the widget window and collect the results.(R tgetchRDR=RJ(RtvalidateR(((s&/usr/lib64/python2.7/curses/textpad.pytedit±sN( t__name__t __module__t__doc__tFalseRRR#R,RDRJRRM(((s&/usr/lib64/python2.7/curses/textpad.pyRs     A t__main__cCs‡d\}}d \}}|j|d|dƒtj||||ƒ}t||d|d||||ƒ|jƒt|ƒjƒS( Ni iiiisUse Ctrl-G to end editing.i(i i(ii(taddstrRtnewwinRR=RRM(tstdscrtncolstnlinesR R R ((s&/usr/lib64/python2.7/curses/textpad.pyt test_editbox¿s  & sContents of text box:(( RPRt curses.asciiRRRNRXtwrappertstrtrepr(((s&/usr/lib64/python2.7/curses/textpad.pyts   «