o bJ@sUdZddlZddlmZddlmZddlmZmZddl m Z ddl m Z ddl mZiZeeefed <Gd d d ZeejGd d d ZGdddZGdddejZGdddeZdS)z4 Basic line editing support. @author: Jp Calderone N)Dict) implementer)helperinsults)Logger)reflect) iterbytes _counterscsLeZdZdZddZdeffdd Zdeffdd Zfd d ZZ S) Loggingz Wrapper which logs attribute lookups. This was useful in debugging something, I guess. I forget what. It can probably be deleted or moved somewhere more appropriate. Nothing special going on here, really. cCsF||_t|j}t|d}|dt|<t|dt|d|_dS)Nr-w) originalrqual __class__r getopenstr_logFile)selfrkeycountr8/usr/lib/python3/dist-packages/twisted/conch/recvline.py__init__!s    zLogging.__init__returncttdSNr)rsuper__getattribute__rrrr__str__(zLogging.__str__crr)reprrrr r!rr__repr__+r#zLogging.__repr__cs0td}td}||dt||S)Nrr )rrwritegetattr)rnamerlogFiler!rrr.s   zLogging.__getattribute__) __name__ __module__ __qualname____doc__rrr"r%r __classcell__rrr!rr s r c@seZdZdZdD]ZedZedZeeqdZ dZ ddZ e j D] Zed eefq#d d Zd d ZddZddZddZdiddZdiddZdiddZdiddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Z d/d0Z!d1d2Z"d3d4Z#d5d6Z$d7d8Z%d9d:Z&d;d<Z'd=d>Z(d?d@Z)dAdBZ*dCdDZ+dEdFZ,dGdHZ-djdJdKZ.dLdMZ/dNdOZ0dPdQZ1dRdSZ2dTdUZ3dVdWZ4dXdYZ5dZd[Z6did\d]Z7did^d_Z8did`daZ9dbdcZ:dddeZ;dfdgZrArBrCrDrGrHrIrJrKrLrMrPrRrSrTrUrWrZr[r\r]r^r`rarbrcrerfrgrhrirjrkrlrmrnrorprqrrrurrrrr05sz              r0cs.eZdZdZfddZdefddZZS)LocalTerminalBufferMixina A mixin for RecvLine subclasses which records the state of the terminal. This is accomplished by performing all L{ITerminalTransport} operations on both the transport passed to makeConnection and an instance of helper.TerminalBuffer. @ivar terminalCopy: A L{helper.TerminalBuffer} instance which efforts will be made to keep up to date with the actual terminal associated with this protocol instance. cs(t|_|jtt||jSN)rTerminalBuffer terminalCopyconnectionMadermakeConnectionr0)r transportr!rrrBs  z'LocalTerminalBufferMixin.makeConnectionrcCs t|jSr)rrr rrrr"Gs z LocalTerminalBufferMixin.__str__)r+r,r-r.rrr"r/rrr!rr6s rc@seZdZdZdZdZdZdZdZe j dZ e Zdd Zd d Zd d ZddZddZddZddZddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Z d,d-Z!d.d/Z"d0S)1RecvLinea L{TerminalProtocol} which adds line editing features. Clients will be prompted for lines of input with all the usual features: character echoing, left and right arrow support for moving the cursor to different areas of the line buffer, backspace and delete for removing characters, and insert for toggling between typeover and insert mode. Tabs will be expanded to enough spaces to move the cursor to the next tabstop (every four characters by default). Enter causes the line buffer to be cleared and the line to be passed to the lineReceived() method which, by default, does nothing. Subclasses are responsible for redrawing the input prompt (this will probably change). P)s>>> s... rr1cCspg|_d|_|j}|j|j|j|j|j|jd|j d|j |j |j |j |j |j|j|j|j|j|ji |_|dS)Nr  ) lineBufferlineBufferIndexterminal LEFT_ARROW handle_LEFT RIGHT_ARROW handle_RIGHTr{ handle_TAB handle_RETURNr|handle_BACKSPACEDELETE handle_DELETEINSERT handle_INSERTHOME handle_HOMEEND handle_END keyHandlersinitializeScreenrtrrrrfs zRecvLine.connectionMadecCs*|j|j|j|j|dSr)rrrr'pspn setInsertModer rrrrs  zRecvLine.initializeScreencCs(d|j}|d|j||jdfSN)joinrr)rsrrrcurrentLineBuffers zRecvLine.currentLineBuffercCd|_|jtjjgdS)Ninsert)rQrrPrrOIRMr rrrrzRecvLine.setInsertModecCr)Ntypeover)rQrrRrrOrr rrrsetTypeoverModerzRecvLine.setTypeoverModecCs$|j|j|jd|jdS)z Write a line containing the current input prompt and the current line buffer at the current cursor position. rN)rr'rrrrr rrr drawInputLines$zRecvLine.drawInputLinecCs,|j|j||_||_|dSr)rrmrHwidthheightr)rrrrrr terminalSizes   zRecvLine.terminalSizecCdSrrrsrrrruz!RecvLine.unhandledControlSequencecCsL|j|}|dur|dS||jvr||ddS|jjd|ddS)NFz#Received unhandled keyID: {keyID!r})rv)rr_printableCharscharacterReceived_logwarn)rrvmodifiermrrrkeystrokeReceiveds   zRecvLine.keystrokeReceivedcCsR|jdkr|j|j|n |g|j|j|jd<|jd7_|j|dS)Nrr )rQrrrrr')rchmoreCharactersComingrrrrs zRecvLine.characterReceivedcCsH|jt|j|j}|j||j|7_|jtd|dS)N )TABSTOPlenrrrCrextendrr?rrrrs zRecvLine.handle_TABcCs*|jdkr|jd8_|jdSdSNrr rrrDr rrrrs zRecvLine.handle_LEFTcCs0|jt|jkr|jd7_|jdSdS)Nr )rrrrrCr rrrrszRecvLine.handle_RIGHTcCs"|jr|j|jd|_dSdSNrrr rrrrs zRecvLine.handle_HOMEcCs4t|j|j}|r|j|t|j|_dSdSr)rrrrrC)roffsetrrrrs  zRecvLine.handle_ENDcCs>|jdkr|jd8_|j|j=|j|jdSdSr)rrrrDrnr rrrrs   zRecvLine.handle_BACKSPACEcCs,|jt|jkr|j|j=|jdSdSr)rrrrrnr rrrrs zRecvLine.handle_DELETEcCs0d|j}g|_d|_|j||dS)Nrr)rrrrrK lineReceivedrrFrrrrs  zRecvLine.handle_RETURNcCs0|jdvsJ|jdkr|dS|dS)N)rrr)rQrrr rrrrs   zRecvLine.handle_INSERTcCrrrrrrrrrzRecvLine.lineReceivedN)#r+r,r-r.rrrrrstring printableencoderrrrrrrrrrrurrrrrrrrrrrrrrrrrKs:    rc@s@eZdZdZddZddZddZdd Zd d Zd d Z dS)HistoricRecvLinea; L{TerminalProtocol} which adds both basic line-editing features and input history. Everything supported by L{RecvLine} is also supported by this class. In addition, the up and down arrows traverse the input history. Each received line is automatically added to the end of the input history. cCs<t|g|_d|_|j}|j|j|j|j |j idSr) rr historyLineshistoryPositionrrupdateUP_ARROW handle_UP DOWN_ARROW handle_DOWNrrrrrs zHistoricRecvLine.connectionMadecCs&t|j}|d|j||jdfSr)tuplerr)rbrrrcurrentHistoryBuffers z%HistoricRecvLine.currentHistoryBuffercCsB|rt|ddD]}||dq ||ddddSdS)NTF)rr)rbufrrrr_deliverBuffers zHistoricRecvLine._deliverBuffercCst|jr|jt|jkr|jd|j|jdkr8||j|jd8_g|_| |j|jdSdS)Nrrr ) rrrrappendrrrrhrr rrrrs  zHistoricRecvLine.handle_UPcCs~|jt|jdkr(||j|jd7_g|_||j|jdS||jt|j|_g|_d|_dS)Nr r) rrrrrrhrrrr rrrr$s    zHistoricRecvLine.handle_DOWNcCs0|jr |jd|jt|j|_t|Sr)rrrrrrrrr rrrr5s  zHistoricRecvLine.handle_RETURNN) r+r,r-r.rrrrrrrrrrrs  r)r.rtypingrzope.interfacertwisted.conch.insultsrrtwisted.loggerrtwisted.pythonrtwisted.python.compatrr rint__annotations__r r}r0rTerminalProtocolrrrrrrs$     0