'Plotext and Curses - windows
Needed help with this code:
import plotext as plt
from contextlib import redirect_stdout
import io
import curses
import locale
locale.setlocale(locale.LC_ALL, '')
code = locale.getpreferredencoding()
PlotFile = io.StringIO()
with redirect_stdout(PlotFile):
y = plt.sin() # sinusoidal signal
plt.scatter(y, marker='dot', )
plt.title("Scatter Plot")
plt.plot_size(10, 10)
plt.show()
PlotFile.seek(0)
w = PlotFile.readlines()
allchar = []
vischar = []
dechar = []
bychar = []
def main (stdscr):
curses.start_color()
curses.use_default_colors()
k = 0
for i in w:
for c in i:
if ord(c) not in allchar:
allchar.append(ord(c))
vischar.append(c)
dechar.append(c.encode('utf-8'))
bychar.append(bytes(dechar[-1]))
stdscr.addstr(chr(ord(c)).encode('utf-8'))
print(i)
k += 1
stdscr.refresh()
curses.napms(3000)
curses.wrapper(main)
print(allchar)
print(vischar)
print(dechar)
print(bychar)
Using VScode on Windows python 3.9 and wincurses. While on ordinary terminal plotext working fine, in curses displaying odd characters like [[m , [[107m and others. Tried encoding and uft mess, still can't figure out how to manage this problem. As I already figured out curses use uft-8 by default, while python strings are encoded in utf-16, so conversion must be done. When tried to print each character one by one from allchar list all character displayed. But I noticed, that there is [ character printed in curses, which is not in original plotext output. I think it is unicode problem somewhere in middle, but still can't find. Any help would be appreciated.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
