autocode.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:AutoCode 作者: HashCode55 项目源码 文件源码
def start(self):   
        """
        start iterates the file and paints the text on the screen.
        exits when q is pressed. 
        """
        try:      
            fileptr = 0
            key = ''
            lines = 1        
            while True:
                # get the cursor position for further manipulation 
                y, x = self.stdscr.getyx()
                key = self.stdscr.getch()
                if key == curses.KEY_BACKSPACE or key == curses.KEY_DC or \
                    key == curses.KEY_DL or key == 127 :  
                    # handle backspace                             
                    if x == 0 and y == 0: 
                        continue                     
                    # take the file pointer back one step 
                    fileptr -= 1
                    # update the screen     
                    if x == 0:   
                        lines -= 1
                        self.stdscr.addstr(y-1, len(self.virtualfile[lines-1]), ' ')
                        self.stdscr.move(y-1, len(self.virtualfile[lines-1]))                                   
                    else:
                        self.stdscr.addstr(y, x-1, ' ')
                        self.stdscr.move(y, x-1)                
                elif key == curses.KEY_UP or key == curses.KEY_DOWN or \
                    key == curses.KEY_RESIZE or key == -1:
                    # ignore 
                    continue                           
                else:   
                    text = self.get_text(fileptr)                    
                    # increase the lines if there are "\n" s 
                    lines += sum([1 if c == '\n' else 0 for c in text])
                    fileptr += self.n        
                    self.stdscr.addstr(text)

                self.stdscr.refresh()                
            # graceful exit                 
            curses.endwin()
        except KeyboardInterrupt:            
            curses.endwin()
            exit()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号