|
Home > Archive > Unix Programming > August 2005 > ncurses and ansi control codes
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
ncurses and ansi control codes
|
|
| FireStaff@gmail.com 2005-08-26, 6:00 pm |
| I just posted this in comp.unix.questions but thought it may be better
suited for this group.
My question is when you print each character from a string to a window,
i.e. waddch, is there some way to make curses properly handle any ansi
control codes that happen to be embedded in that string?
Thanks
| |
| Norm Dresner 2005-08-26, 6:00 pm |
| <FireStaff@gmail.com> wrote in message
news:1125062854.258678.309490@z14g2000cwz.googlegroups.com...
>I just posted this in comp.unix.questions but thought it may be better
> suited for this group.
>
> My question is when you print each character from a string to a window,
> i.e. waddch, is there some way to make curses properly handle any ansi
> control codes that happen to be embedded in that string?
>
> Thanks
I'm sure that Tom will weigh in on this, but why would you want to (a) even
use ANSII control codes? (b) print something to the screen that where
ncurses wouldn't really know how to give it back to you if you wanted to
move it or repaint the screen?
Norm
| |
| FireStaff@gmail.com 2005-08-26, 6:00 pm |
| The problem is that I am receiving data over a socket connection that
has control codes in it, so I really have no control over that. I
suppose if I had to I could just write some sort of handler that would
parse through the incoming text and make corresponding curses calls
based on any ansi control codes that are found but I thought there may
be support for something like this already in curses.
| |
| Pascal Bourguignon 2005-08-26, 6:00 pm |
| FireStaff@gmail.com writes:
> The problem is that I am receiving data over a socket connection that
> has control codes in it, so I really have no control over that. I
> suppose if I had to I could just write some sort of handler that would
> parse through the incoming text and make corresponding curses calls
> based on any ansi control codes that are found but I thought there may
> be support for something like this already in curses.
You're confonding bytes and characters.
You need to convert bytes to characters:
typedef char byte;
void waddbytes(WINDOW* win,byte* bytes,int count){
for(i=0;i<count;i++){
if(isprint(bytes[i])&&(bytes[i]!='<')&&(bytes[i]!='>')){
waddch(win,bytes[i]);}
else{
waddch(win,'<');
waddch(win,"0123456789ABCDEF"[(i>>4)&0xf]);
waddch(win,"0123456789ABCDEF"[i&0xf]);
waddch(win,'>');}}}
--
__Pascal Bourguignon__ http://www.informatimago.com/
The rule for today:
Touch my tail, I shred your hand.
New rule tomorrow.
| |
| Gordon Burditt 2005-08-26, 6:00 pm |
| >I just posted this in comp.unix.questions but thought it may be better
>suited for this group.
>
>My question is when you print each character from a string to a window,
>i.e. waddch, is there some way to make curses properly handle any ansi
>control codes that happen to be embedded in that string?
You are supposed to use ncurses functions for various stuff ansi
control codes might do (cursor movement, character attribute changes,
etc.) rather than raw ansi control codes which may not work on the
terminal you are using. ncurses is also likely to be confused
about things like how much space on the screen such codes take up
and as a result, mess up redrawing other parts of the screen.
I think the way to make this work is for YOU to interpret the ansi
codes and tell ncurses to do what they are supposed to do on an
ansi terminal (enable highlighting, cursor movement, whatever).
Gordon L. Burditt
| |
| Thomas Dickey 2005-08-26, 6:00 pm |
| FireStaff@gmail.com wrote:
> The problem is that I am receiving data over a socket connection that
> has control codes in it, so I really have no control over that. I
> suppose if I had to I could just write some sort of handler that would
> parse through the incoming text and make corresponding curses calls
> based on any ansi control codes that are found but I thought there may
> be support for something like this already in curses.
No, curses doesn't do that. One could in principle refer to a terminfo or
termcap description and use that to infer which terminal control sequences
were used to generate the character stream.
--
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net
|
|
|
|
|