Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QPlainTextEdit VT100 espace sequence support
Hi, I am making a terminal widget with PyQt5 and I've come across several problems, one of them being that VT100 espace sequences show up like this
[0m[1;31m ./+o+- [0m[1;31m bot[0m[1m@[0m[0m[1;31mbotnet[0m [0m[1;37m yyyyy- [0m[1;31m-yyyyyy+ [0m[1;31m OS:[0m Ubuntu 18.10 cosmic[0m [0m[1;37m [0m[1;37m://+//////[0m[1;31m-yyyyyyo [0m[1;31m Kernel:[0m x86_64 Linux 4.18.0-10-generic[0m [0m[1;33m .++ [0m[1;37m.:/++++++/-[0m[1;31m.+sss/` [0m[1;31m Uptime:[0m 1d 15h 29m[0m [0m[1;33m .:++o: [0m[1;37m/++++++++/:--:/- [0m[1;31m Packages:[0m 2438[0m [0m[1;33m o:+o+:++.[0m[1;37m`..```.-/oo+++++/ [0m[1;31m Shell:[0m python3[0m [0m[1;33m .:+o:+o/.[0m[1;37m `+sssoo+/ [0m[1;31m Resolution:[0m 1920x1080[0m [0m[1;37m .++/+:[0m[1;33m+oo+o:`[0m[1;37m /sssooo. [0m[1;31m DE:[0m KDE 5.50.0 / Plasma 5.13.5[0m [0m[1;37m /+++//+:[0m[1;33m`oo+o[0m[1;37m /::--:. [0m[1;31m WM:[0m KWin[0m [0m[1;37m \+/+o+++[0m[1;33m`o++o[0m[1;31m ++////. [0m[1;31m GTK Theme:[0m Breeze [GTK2/3][0m [0m[1;37m .++.o+[0m[1;33m++oo+:`[0m[1;31m /dddhhh. [0m[1;31m Icon Theme:[0m breeze[0m [0m[1;33m .+.o+oo:.[0m[1;31m `oddhhhh+ [0m[1;31m Font:[0m Noto Sans Regular[0m [0m[1;33m \+.++o+o`[0m[1;31m`-````.:ohdhhhhh+ [0m[1;31m CPU:[0m Intel Core i7-4800MQ @ 8x 3.7GHz [51.0°C][0m [0m[1;33m `:o+++ [0m[1;31m`ohhhhhhhhyo++os: [0m[1;31m GPU:[0m intel[0m [0m[1;33m .o:[0m[1;31m`.syhhhhhhh/[0m[1;33m.oo++o` [0m[1;31m RAM:[0m 2116MiB / 7667MiB[0m [0m[1;31m /osyyyyyyo[0m[1;33m++ooo+++/ [0m [0m[1;31m ````` [0m[1;33m+oo+++o\: [0m [0m[1;33m `oo++. [0m
I want my qplaintextedit to show the sequences like the linux terminal shows them in the terminal. How do I do that?
You could have a look at a class that we use in QtCreator: http://code.qt.io/cgit/qt-creator/qt-creator.git/tree/src/libs/utils/ansiescapecodehandler.cpp
This class takes escape sequences and transforms them into a list of text with corresponding format.
Later, in http://code.qt.io/cgit/qt-creator/qt-creator.git/tree/src/libs/utils/outputformatter.cpp#n77 this list is appended to the plain text edit with means of
This is of course no readymade solution, but should give you an idea how to do it.
I am making a terminal widget with PyQt5
I am creating an IDE in python (https://github.com/Fuchsiaff/pypad) and I need a good terminal widget to provide interactive mode support but I need a terminal for that and there weren't any terminal widgets for PyQt5 so I decided to write my own.
I still need to figure out how to interact with a process that's running but after I figure that out, my terminal should work just like a real terminal.
QProcessto spawn sub-processes, and you can access their stdin/out/err. But if you mean an "attach to process" like a debugger, I think you'd have to look at platform-specific calls.
Yeah, I am using QProcess but by interact with a running process I mean when you start a program using QProcess.start("python") then How do you write commands into that running process like in the cmd you write python and then you can write commands to the python shell
@jsulm Nope, haven't really dug deeper into the problem since I'm trying to figure out how to unescape the ansii color codes.
Just checking: you are sending the
ESCcharacter (ASCII 27) before the
[each time, aren't you?
I'm afraid there's no point asking me how/whether
QPlainTextEdithandles these and whether it passes them through or not, I wouldn't know.
Roman Bober last edited by
@aha_1980 thank you!