o ´ ed»ã@s`dZddlZddlZddlZddlZddlZGdd„deƒZGdd„deƒZ Gdd„deƒZ dS) z Terminal / input handling éNc@sVeZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zddd„Z ddd„Z ddd„Z d S)ÚTerminalz@ Do minimal terminal mangling to prompt users for input cCs||_d|_d|_| ¡dS©N)ÚfdÚ orig_flagsÚ orig_termÚsave)Úselfr©r ú&/usr/share/netplan/netplan/terminal.pyÚ__init__"s zTerminal.__init__cCsTtj ¡r(t |j¡}|dtjB|d<|dtjB|d<t |jtj |¡dSdS©Né© ÚsysÚstdinÚisattyÚtermiosÚ tcgetattrrÚICANONÚECHOÚ tcsetattrÚTCSANOW©rÚattrsr r r Ú enable_echo(s  üzTerminal.enable_echocCsXtj ¡r*t |j¡}|dtj@|d<|dtj@|d<t |jtj |¡dSdSr rrr r r Ú disable_echo/s  üzTerminal.disable_echocCs,t |jtj¡}t |jtj|tjB¡dSr©ÚfcntlrÚF_GETFLÚF_SETFLÚosÚ O_NONBLOCK©rÚflagsr r r Úenable_nonblocking_io6szTerminal.enable_nonblocking_iocCs.t |jtj¡}t |jtj|tj@¡dSrrr"r r r Údisable_nonblocking_io:szTerminal.disable_nonblocking_ioéxNcCsÔtdƒtƒ}| |¡| ¡| ¡|sd}td |¡ƒ|}|dkrbtd |tt|ƒƒ¡ddt t j gggd¡zt j   ¡}|d krO|  |¡t ƒ‚Wn tyYYnw|d8}|dks%|  |¡tƒ‚) a Get a "confirmation" input from the user, for at most (timeout) seconds. Optionally, customize the message to be displayed. timeout -- timeout to wait for input (default 120) message -- optional customized message ("Press ENTER to (message)") raises: InputAccepted -- the user confirmed the changes InputRejected -- the user rejected the changes z%Do you want to keep these settings? zaccept the new configurationz&Press ENTER before the timeout to {} rz%Changes will revert in {:>{}} secondsú )ÚendéÚ )ÚprintÚdictrrr$ÚformatÚlenÚstrÚselectrrÚreadÚresetÚ InputAcceptedÚ TypeErrorÚ InputRejected)rÚtimeoutÚmessageÚsettingsÚ timeout_nowÚcr r r Úget_confirmation_input>s2    ý üî zTerminal.get_confirmation_inputcCsVt |jtj¡}d}tj ¡rt |j¡}|dur#| ||dœ¡dS||_ ||_ dS)z• Save the terminal's current attributes and flags Optional argument: - dest: if set, save settings to this dict N)r#Úterm) rrrrrrrrÚupdaterr)rÚdestrrr r r rps   ÿ z Terminal.savecCsdd}d}|dur| d¡}| d¡}n|j}|j}tj ¡r't |jtj |¡t   |jt j |¡dS)z¢ Reset the terminal to its original attributes and flags Optional argument: - orig: if set, reset to settings from this dict Nr<r#) ÚgetrrrrrrrrÚ TCSAFLUSHrr)rÚorigrrr r r r2‚s   zTerminal.reset)r&Nr) Ú__name__Ú __module__Ú __qualname__Ú__doc__r rrr$r%r;rr2r r r r rs  2rc@óeZdZdZdS)r3z Denotes has accepted inputN©rBrCrDrEr r r r r3–ór3c@rF)r5z) Denotes that the user has rejected inputNrGr r r r r5›rHr5) rErr rr0rÚobjectrÚ Exceptionr3r5r r r r Úsy