summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2017-11-03 21:22:38 +0100
committerHelmut Grohne <helmut@subdivi.de>2017-11-03 21:22:38 +0100
commitaba64222f1ec884d97f67fb6ae43f421d525ca65 (patch)
treea4467e63c92b0b747f01e6caffb0870dbbc11218
parentc8392bb99d86ca799d057c9fcc91fa53d880af23 (diff)
downloadtcvt-aba64222f1ec884d97f67fb6ae43f421d525ca65.tar.gz
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.
-rwxr-xr-xtcvt.py11
1 files changed, 10 insertions, 1 deletions
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)