LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-15-2009, 12:45 PM   #1
default5
LQ Newbie
 
Registered: Feb 2008
Distribution: Fedora
Posts: 18

Rep: Reputation: 0
Pseudo-Terminals and Ncurses


I am trying to write a program that can run other text programs through an ncurses interface. Essentially, I want to map a pseudo-terminal to an ncurses window. I have successfully run programs under my program using a pseudo-terminal (with a lot of help from the book "advanced programming in the unix environment"). However, when I try to start ncurses and use its functions to display what I read from the pseudo terminal, I get tons of text full of terminal escape sequences. Is it possible to use ncurses with programs that generate their own escape sequences for the terminal?

Example: ./myprog bash
^[]0;Dan@localhost:~/prog/c/unix^G^[[?1034h[Dan@localhost unix]$ exit

Backspaces appear as ^G (the bell) when there is nothing to erase, and a backspace and ^[[K otherwise.

Sorry if this wasn't clear, please post back if I need to clarify.
 
Old 04-15-2009, 11:02 PM   #2
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
If I understand you correctly, you want to use ncurses in your master program to keep track of what's going on, but your slave programs probably also use ncurses in an attempt to format their "screens".

There is no magic bullet for this. Either redesign the slave programs so they just output straight ASCII stuff without all that <Esc> stuff, or grit your teeth and figure out what's going on with those escape sequences.
 
Old 04-16-2009, 08:55 AM   #3
default5
LQ Newbie
 
Registered: Feb 2008
Distribution: Fedora
Posts: 18

Original Poster
Rep: Reputation: 0
That's exactly correct. Unfortunately, its not just running ncurses programs under my master program, its also normal programs like bash and echo that don't display correctly, along with the backspace character. Are you saying that I would have to determine what the escape characters mean, and try to emulate that in an ncurses window? That crossed my mind before, but I don't think it would be easy. Could I leverage terminfo to get the meanings of the escape sequences?
 
Old 04-16-2009, 10:13 AM   #4
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
Quote:
Originally Posted by default5 View Post
Are you saying that I would have to determine what the escape characters mean, and try to emulate that in an ncurses window?
That would probably be your best bet.
Quote:
Originally Posted by default5 View Post
Could I leverage terminfo to get the meanings of the escape sequences?
Yes. Do this:
Code:
man terminfo
That will tell you the meaning of all entries in a terminfo data file. But there are many such files, depending on your terminal type. To find out which one you'd be using, do this:
Code:
echo $TERM
This environment variable shows which terminal type is used in the terminfo entries.

In a simpler world, if the terminal type is vt100, for example, you'd want to look at the file at
Code:
/usr/share/terminfo/v/vt100
But this world is not that simple; that file is already in its compiled form.

I'm running Slackware 12.1, so for me to find all the data in its source form (before tic compiles it), I go here to pick up the source. Within that tarball, the file of interest is misc/terminfo.src.

But the data should be the same regardless of your distribution. I wanted to just slap it all in here for your convenience, but this site doesn't allow source that large. Even if you don't use Slackware, the file in that tarball will be what you want. So download it, find your terminal type (from the TERM environment variable), review the terminfo man page, and knock yourself out.

Hope this helps.
 
Old 04-17-2009, 12:50 PM   #5
default5
LQ Newbie
 
Registered: Feb 2008
Distribution: Fedora
Posts: 18

Original Poster
Rep: Reputation: 0
Thanks a lot. This looks fun...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
pseudo terminals - C and reading davo666 Programming 14 01-22-2009 07:14 AM
Little confused on virtual and pseudo terminals, how to open and use, etc. lumix Linux - Newbie 2 04-30-2008 05:53 PM
find the total number of pseudo terminals of all logins RajRed Linux - General 5 04-18-2006 04:30 AM
Regarding Pseudo tty, Pseudo terminals ? mqureshi Programming 0 07-30-2005 10:51 AM
managing pseudo terminals in an ssh session kirkhamster1 Linux - Newbie 1 10-08-2003 12:26 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration