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

                              ./+o+-       bot@botnet
                      yyyyy- -yyyyyy+      OS: Ubuntu 18.10 cosmic
                   ://+//////-yyyyyyo      Kernel: x86_64 Linux 4.18.0-10-generic
               .++ .:/++++++/-.+sss/`      Uptime: 1d 15h 29m
             .:++o:  /++++++++/:--:/-      Packages: 2438
            o:+o+:++.`..```.-/oo+++++/     Shell: python3
           .:+o:+o/.          `+sssoo+/    Resolution: 1920x1080
      .++/+:+oo+o:`             /sssooo.   DE: KDE 5.50.0 / Plasma 5.13.5
     /+++//+:`oo+o               /::--:.   WM: KWin
     \+/+o+++`o++o               ++////.   GTK Theme: Breeze [GTK2/3]
      .++.o+++oo+:`             /dddhhh.   Icon Theme: breeze
           .+.o+oo:.          `oddhhhh+    Font: Noto Sans Regular
            \+.++o+o``-````.:ohdhhhhh+     CPU: Intel Core i7-4800MQ @ 8x 3.7GHz [51.0°C]
             `:o+++ `ohhhhhhhhyo++os:      GPU: intel
               .o:`.syhhhhhhh/.oo++o`      RAM: 2116MiB / 7667MiB
                   /osyyyyyyo++ooo+++/    
                       ````` +oo+++o\:    
                              `oo++.      
    

    I want my qplaintextedit to show the sequences like the linux terminal shows them in the terminal. How do I do that?


  • Qt Champions 2017

    @Fuchsiaff

    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 QTextCursor()

    This is of course no readymade solution, but should give you an idea how to do it.

    Regards



  • @Fuchsiaff

    I am making a terminal widget with PyQt5

    Why? :)



  • @JonB
    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.



  • @Fuchsiaff
    Qt offers QProcess to 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


  • Moderators

    @Fuchsiaff Did you read http://doc.qt.io/qt-5/qprocess.html ? Especially "Communicating via Channels" part?



  • @jsulm Nope, haven't really dug deeper into the problem since I'm trying to figure out how to unescape the ansii color codes.



  • @Fuchsiaff
    Just checking: you are sending the ESC character (ASCII 27) before the [ each time, aren't you?

    I'm afraid there's no point asking me how/whether QPlainTextEdit handles these and whether it passes them through or not, I wouldn't know.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.