3

I am trying to build a SSH client for the web browser (similar to ajaxterm). I have built a python backend that uses Paramiko's SSHClient.invoke_shell(term='vt100') and a web server which communicates with a frontend (HTML + AJAX). The system works and displays output when I send commands through SSH channel, but the output includes VT100 escape sequences.

If I understand correctly, anything I get from the SSH channel should be interpreted as commands for 24x80 terminal window? Which means the escape sequences may change color, clear screen, remove lines, change the way lines behave... (I have found a good list here) Which means I can't just clear them out?

I checked out Ajaxterm's source, but couldn't figure out how Terminal class can be used (so I could use it for my purposes).

The question: what would be the easiest way to interpret the output stream and properly display the terminal screen in a browser? In other words, is there a library that parses the output and keeps the screen contents for me?

If I have misunderstood the inner workings of the terminals, please let me know. I haven't had much of experience with them in the past. :)

Cédric Julien
  • 78,516
  • 15
  • 127
  • 132
johndodo
  • 17,247
  • 15
  • 96
  • 113

1 Answers1

4

I've tried to do the same thing a few days ago. I didn't finished it, but I found a few python terminal emulator libs.

I choose pyte, which has a clean API and is easy to use. A list of other libs doing the same job is available at the end of pyte's README.

madjar
  • 12,691
  • 2
  • 44
  • 52
  • Thanks! I tried it and it looks clean and useful. Have you had any luck getting the colors out of it? If I understand correctly, screen.display returns character content only? – johndodo Oct 06 '11 at 14:20
  • 1
    screen.display returns only the characters. The only tricky part is that display is a list of Chars. Char is more or less a namedtuple. The interesting fields of Char are data for the actual char, and bg and fg for the color. There are also a few other. You can look at the code for more info : https://github.com/selectel/pyte/blob/develop/pyte/screens.py#L68 – madjar Oct 06 '11 at 14:55
  • Ok, I will. My python skills are still a bit lacking, but I'll figure it out. :) Otherwise pyte looks exactly what I was looking for, thanks again! – johndodo Oct 06 '11 at 15:50