"Read bytes from pipe to buffer function! s:fillBufferFromPipe(pipeObject) let l:text = a:pipeObject.pipe.read(1024, 0) let l:totalBytesRead = 0 while 0 < len(l:text) let l:totalBytesRead += len(l:text) let a:pipeObject.buffer .= l:text let l:text = a:pipeObject.pipe.read(1024, 0) endwhile return l:totalBytesRead endfunction let s:f_debugger={} "Terminate the debugger function! s:f_debugger.kill() dict if self.shell.is_valid call self.addLineToTerminal('','== DEBUGGER TERMINATED ==') endif if !has('timers') let &updatetime=self.prevUpdateTime endif call self.shell.kill(15) if exists('s:debugger') for l:closeHandler in s:debugger.closeHandlers call l:closeHandler.handle(self) endfor endif endfunction "Write a line to the debugger's interactive shell function! s:f_debugger.writeLine(line) dict call self.shell.stdin.write(a:line."\n") endfunction "Check for new lines from the debugger's interactive shell and handle them function! s:f_debugger.invokeReading() dict let l:newLines = {} for l:k in keys(self.pipes) let l:pipe = self.pipes[l:k] if 0 < s:fillBufferFromPipe(l:pipe) let l:nl = l:pipe.bufferer() if 0 < len(l:nl) let l:newLines[l:k] = l:nl endif endif endfor for l:k in keys(l:newLines) for l:line in l:newLines[l:k] call self.handleLine(l:k, l:line) endfor endfor let l:checkpid=self.shell.checkpid() if 'exit'==l:checkpid[0] \|| 'error'==l:checkpid[0] call self.kill() endif if !has('timers') call feedkeys("f\e", '\n') " Make sure the CursorHold event is refired even if the user does nothing endif endfunction "Handle a single line from the debugger's interactive shell function! s:f_debugger.handleLine(pipeName,line) dict call self.addLineToTerminal(a:pipeName,a:line) let l:readResult=deepcopy(self.readResultTemplate,1) for l:readHandler in self.readHandlers call l:readHandler.handle(a:pipeName,a:line,l:readResult,self) endfor for l:thinkHandler in self.thinkHandlers call l:thinkHandler.handle(l:readResult,self) endfor call self.performWriteActions() endfunction "Perform all write actions function! s:f_debugger.performWriteActions() dict for l:namespace in keys(self.writeActions) let l:handlers=get(self.writeHandlers,l:namespace) if !empty(l:handlers) for l:writeAction in items(self.writeActions[l:namespace]) if !empty(l:writeAction[1]) if has_key(l:handlers,l:writeAction[0]) call l:handlers[l:writeAction[0]].handle(l:writeAction[1],self) endif endif endfor endif endfor call self.generateWriteActionsFromTemplate() endfunction "Show the terminal buffer that gets it's content from the debugger's "interactive shell function! s:f_debugger.showTerminalBuffer() dict if has_key(self,'terminalBuffer') if -1