3 \@sVdZddlZddlZddZGdddZedkrRdd ZejeZe d e edS) z:Simple textbox editing widget with Emacs-like keybindings.NcCs|j|d|tj||d|j||dtj||d|j||dtj||d|j|d|tj||d|j||tj|j||tj|j||tj|j||tj dS)z^Draw a rectangle with corners at the provided upper-left and lower-right coordinates. N) ZvlinecursesZ ACS_VLINEZhlineZ ACS_HLINEaddchZ ACS_ULCORNERZ ACS_URCORNERZ ACS_LRCORNERZ ACS_LLCORNER)winulyulxZlryZlrxr/usr/lib64/python3.6/textpad.py rectanglesr c@sLeZdZdZdddZddZddZd d Zd d Zd dZ dddZ dS)TextboxadEditing 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 FcCs.||_||_|jd|_d|_|jddS)Nr)r insert_mode_update_max_yx stripspaceslastcmdZkeypad)selfrr rrr __init__+s zTextbox.__init__cCs&|jj\}}|d|_|d|_dS)Nr)rZgetmaxyxmaxymaxx)rrrrrr r 3s zTextbox._update_max_yxcCs\|j|j}xHtjj|jj||tjjkrBt|j|d}Pn |dkrLP|d}qW|S)zuGo to the location of the first blank on the given line, returning the index of the last non-blank character.rr)r rrasciirinchZSPmin)ryZlastrrr _end_of_line8s zTextbox._end_of_linec Cs|j|jj\}}d}x||jks0||jkr|jr@|jj}y|jj|Wntj k rfYnX|j s~tj j | rP|}|jj\}}|dkr||f}qW|dk r|jj |dS)N) r rgetyxrrr rrrerrorrisprintmove)rchrxZbackyxZoldchrrr _insert_printable_charFs$  zTextbox._insert_printable_charcCsV|j|jj\}}||_tjj|rJ||jks<||jkrF|j |n|tjj krh|jj |dn|tjj tj tjjtjfkr|dkr|jj ||dnB|dkrn8|jr|jj |d|j|dn|jj |d|j|tjjtjfkrR|jjnL|tjjkr"|jjn0|tjjkrb|jrN|jj ||j|n|jj ||jn|tjjtjfkr||jkr|jj ||dn ||jkrn|jj |ddn|tjjkrdS|tjjkr |jdkrdS||jkrR|jj |ddnF|tjjkrZ|dkr@|j|dkr@|jjn|jj |||jjn|tjjkrt|jjn|tjjtjfkr||jkrR|jj |d|||j|dkrR|jj |d|j|dnz|tjj kr|jj!n`|tjj"tj#fkrR|dkrR|jj |d|||j|dkrR|jj |d|j|ddS)z!Process a single editing command.rr)$r rrrrrrrrrZSOHrZSTXZKEY_LEFTZBSZ KEY_BACKSPACErrZdelchZEOTZENQZACKZ KEY_RIGHTZBELNLZVTZdeletelnZclrtoeolZFFrefreshSOZKEY_DOWNZSIZinsertlnZDLEZKEY_UP)rrrrrrr do_command_sr            zTextbox.do_commandcCsd}|jxt|jdD]}|jj|d|j|}|dkrH|jrHqxDt|jdD]2}|jrl||krlP|tt j j |jj ||}qXW|jdkr|d}qW|S)z.Collect and return the contents of the window.rr ) r rangerrrrrrchrrrr)rresultrstoprrrr gathers "  zTextbox.gatherNcCs@x6|jj}|r||}|sq|j|s*P|jjqW|jS)z2Edit in the widget window and collect the results.)rZgetchr#r!r*)rZvalidaterrrr edits  z Textbox.edit)F)N) __name__ __module__ __qualname____doc__rr rrr#r*r+rrrr r s Ar __main__cCsfd\}}d \}}|j|d|dtj||||}t||d|d|||||jt|jS) N zUse Ctrl-G to end editing.r)r1r2)r3r4)ZaddstrrZnewwinr r!r r+)ZstdscrZncolsZnlinesrrrrrr test_editboxs r6zContents of text box:) r/rZ curses.asciir r r,r6wrapperstrprintreprrrrr s ,