From aba64222f1ec884d97f67fb6ae43f421d525ca65 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Fri, 3 Nov 2017 21:22:38 +0100 Subject: fix writing of utf8 chars in the last column Using insch is nice, because it does not update the cursor position, but it does not work with utf8 chars and outputs garbage instead. The problem can be avoided by using addch, but it creates a new problem: addch moves the cursor. For all but the very last character on the screen that's fine, but adding the last character on the screen means scrolling. Thus we follow the advice from http://stackoverflow.com/a/41923640/1626632 and disable scrolling and catching the exception. --- tcvt.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'tcvt.py') diff --git a/tcvt.py b/tcvt.py index 64c2ff5..e97da3c 100755 --- a/tcvt.py +++ b/tcvt.py @@ -168,11 +168,20 @@ class Columns: def addch(self, char): if self.xpos == self.columnwidth - 1: - self.curwin.insch(self.curypos, self.curxpos, char, self.attrs) if self.ypos + 1 == self.numcolumns * self.height: + self.curwin.scrollok(0) # disable scrolling for the addch call + try: + self.curwin.addch(self.curypos, self.curxpos, char, + self.attrs) + except curses.error: + # It errors out, but still draws the character. + # http://stackoverflow.com/a/41923640/1626632 + pass + self.curwin.scrollok(1) self.scroll() self.move(self.ypos, 0) else: + self.curwin.addch(self.curypos, self.curxpos, char, self.attrs) self.move(self.ypos + 1, 0) else: self.curwin.addch(self.curypos, self.curxpos, char, self.attrs) -- cgit v1.2.3