î Òê[Ôã@sbdZddlmZGdd„dƒZedkr^ddlmZeddd d d ƒnd S) z9Implement Idle Shell history mechanism with History classé)ÚidleConfc@sReZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd S) ÚHistorya@ Implement Idle Shell history mechanism. store - Store source statement (called from PyShell.resetoutput). fetch - Fetch stored statement matching prefix already entered. history_next - Bound to <> event (default Alt-N). history_prev - Bound to <> event (default Alt-P). cCsl||_g|_d|_d|_tjdddddƒ|_|jd|jƒ|jd|j ƒdS) adInitialize data attributes and bind event methods. .text - Idle wrapper of tk Text widget, with .bell(). .history - source statements, possibly with multiple lines. .prefix - source already entered at prompt; filters history list. .pointer - index into history. .cyclic - wrap around history list (or not). NÚmainrÚcyclicéÚboolz<>z<>) ÚtextÚhistoryÚprefixÚpointerrZ GetOptionrZbindÚ history_prevÚ history_next)Úselfr©rú)/usr/lib/python3.4/idlelib/IdleHistory.pyÚ__init__ s    zHistory.__init__cCs|jddƒdS)z4Fetch later statement; start with ealiest if cyclic.ÚreverseFÚbreak)Úfetch)rÚeventrrrr szHistory.history_nextcCs|jddƒdS)z0Fetch earlier statement; start with most recent.rTr)r)rrrrrr #szHistory.history_prevcCsMt|jƒ}|j}|j}|dk r–|dk r–|jjdddƒss|jjddƒ|j|kr–d}}|jjddƒq–n|dks®|dkrø|jjddƒ}|rÒ|}qø|jräd }qø|jj ƒdSnt|ƒ}x ||rd nd7}|dks5||kr®|jj ƒ|j r\|dkr\dS|jjddƒ|kr |jj ddƒ|jj d|ƒnd}}Pn|j|}|d|…|krt|ƒ|kr|jj ddƒ|jj d|ƒPqqW|jj dƒ|jj dd d ƒ||_||_dS) a+Fetch statememt and replace current line in text widget. Set prefix and pointer as needed for successive fetches. Reset them to None, None when returning to the start line. Sound bell when return to start line or cannot leave a line because cyclic is False. NÚinsertz!=zend-1cZiomarkrrZselz1.0Úendéÿÿÿÿr)Úlenr r r rZcompareÚgetZmark_setrZbellZdeleterZseeZ tag_remove)rrZnhistr r ZnprefixÚitemrrrr(sJ  "         ( z History.fetchc Csp|jƒ}t|ƒdkrZy|jj|ƒWntk rFYnX|jj|ƒnd|_d|_dS)z.Store Shell input statement into history list.éN)Ústriprr ÚremoveÚ ValueErrorÚappendr r )rÚsourcerrrÚstoreYs   z History.storeN) Ú__name__Ú __module__Ú __qualname__Ú__doc__rr r rr"rrrrrs     1rÚ__main__)rz"idlelib.idle_test.test_idlehistoryÚ verbosityrÚexitFN)r&Zidlelib.configHandlerrrr#ZunittestrrrrrÚs a