Interpreting terminal codes in Perl

M

Martijn Lievaart

Hi,

I googled, but came up with nothing.

What I want to do is translate terminal codes to readable text. So for an
xterm, "\e[2A" should translate to something like "<UP 2 LINES>".
Obviously there are a lot of terminals out there, any reasonable subset
will do.

Is there any perl module that will help me with this? Or would there be a
way to "reverse" the termcap information? Or do I have to program this
myself for any and all terminals out there? (I started on xterm, it's
doable, but a lot of work, I don't want to repeat that for all and every
terminal out there.)

TIA,
M4
 
M

Martijn Lievaart

I don't know of anything that will do this. However, it shouldn't be too
hard to extract a list of valid capability names from your termcap(5) or
terminfo(5) and then call Term::Cap->Tgets on each to build up a hash
from control string to name for the current terminal. OTOH, you may find
it easier to work directly from the terminfo master file at
http://www.catb.org/terminfo/termtypes.master.gz. It doesn't look too
hard to write a parser for.

Thanks!

M4
 
M

Martijn Lievaart


I am currently encoding the full xterm set, I need to cover all the
cases, not just those described by terminfo/termcap (although that covers
99.99% of the cases). In the end I hope to fully cover xterm*/ansi*/vt*,
and will do the rest through reversing the termcap.

M4
 
R

RedGrittyBrick

Martijn said:
On Tue, 31 Mar 2009 08:07:39 +0200, Martijn Lievaart wrote:
[translating terminal control codes to human readable descriptions]
I am currently encoding the full xterm set, I need to cover all the
cases, not just those described by terminfo/termcap (although that covers
99.99% of the cases). In the end I hope to fully cover xterm*/ansi*/vt*,
and will do the rest through reversing the termcap.

Yikes. ansi, sco-ansi, old sco-ansi, ansic, dosansi, hpansi ... vt52,
vt102, vt105, vt125, ... vt220 ... what about all the emulators? That's
hundreds, perhaps thousands of variants.

May I ask why you want to take on this enormous task? There must be a
good reason, but I'm having trouble imagining what it might be.
 
M

Martijn Lievaart

Martijn said:
On Tue, 31 Mar 2009 08:07:39 +0200, Martijn Lievaart wrote:
[translating terminal control codes to human readable descriptions]
I am currently encoding the full xterm set, I need to cover all the
cases, not just those described by terminfo/termcap (although that
covers 99.99% of the cases). In the end I hope to fully cover
xterm*/ansi*/vt*, and will do the rest through reversing the termcap.
Yikes. ansi, sco-ansi, old sco-ansi, ansic, dosansi, hpansi ... vt52,
vt102, vt105, vt125, ... vt220 ... what about all the emulators? That's
hundreds, perhaps thousands of variants.

May I ask why you want to take on this enormous task? There must be a
good reason, but I'm having trouble imagining what it might be.

Interpreting logged streams of terminal data. The emulation need not be
perfect and many terminals can be grouped together. I guess that all
ansi*/vt*/*xterm* can use one emulation or a few at most. Commands not
implemented on a certain terminal are unlikely to occur in a stream using
that terminal.

And yes, I know, it'll never be perfect. And I probably need to implement
those few encountered in practice only which are for me probably 10 at
most and all probably are some vt variant.

M4
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top