import curses
import curses.ascii
class text:
def __init__(self, win):
┊ self.win = win
┊ self.lastcmd = ''
┊ self.ch = self.win.getch()
def cursor_curr_position(self):
┊ (c_line, c_row) = self.win.getyx()
┊ return c_line, c_row
def validate(self, ch):
┊ if curses.ascii.isprint(ch):
┊ ┊ self.win.addch(ch)
def editor(self):
┊ curses.cbreak()
┊ curses.raw()
┊ while True:
┊ ┊ self.win.addch(self.ch)
if __name__ == '__main__':
def main(stdscr):
┊ win = curses.newwin(10, 10, 0, 0)
┊
┊ return text(win).editor()
curses.wrapper(main)
I'm try to write a simple terminal text editor. When I run this code a new terminal window show up. when I try to insert some char I get this error:
_curses.error: addch() returned ERR
Someone have an idea on how to fix?
import curses
import curses.ascii
class text:
def __init__(self, win):
┊ self.win = win
┊ self.lastcmd = ''
def cursor_curr_position(self):
┊ (c_line, c_row) = self.win.getyx()
┊ return c_line, c_row
def validate(self, ch):
┊ if curses.ascii.isprint(ch):
┊ ┊ self.win.addch(ch)
def editor(self):
┊ curses.cbreak()
┊ curses.raw()
┊ while True:
ch = self.win.getch()
self.validate(ch)
if __name__ == '__main__':
def main(stdscr):
┊ win = curses.newwin(10, 10, 0, 0)
┊
┊ return text(win).editor()
curses.wrapper(main)
I've put getch() variable after the while loop. Everything work fine!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.