LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   ncurses screen prints garbage (https://www.linuxquestions.org/questions/programming-9/ncurses-screen-prints-garbage-861645/)

MALDATA 02-09-2011 11:11 AM

ncurses screen prints garbage
 
I actually have two reasons for posting this. One is to see if there's an actual name for characters like this:



Hopefully that will show up correctly for you. If not, it's a little box with four numbers in it, one in each corner. I don't know their name or their reason for showing up, so it's hard to look for help.

My main problem, though, is that I wrote a program that prints some output to a console using ncurses as it runs. These characters show up on the console, seemingly at random, and disturb the whole thing. Sometimes I'll also get sets of characters like "[13;" I'm not printing anything bizarre on there, just strings and floating-point numbers. For example, here's some output from a console running now:

Code:

-0.063158  -0.002083    6.009213    0.000000
0.194120  -0.000095[16;1

I don't really know where to go with this because the code is very straightforward (unfortunately I can't post it). Has anyone else had a similar problem? Sorry I can't be more specific, but I don't even know what those things are.

Thanks

theNbomr 02-09-2011 12:35 PM

I will speculate that ncurses does not know what type of terminal you are using. The odd-looking character you posted is a printable version of the 'escape', '\x1b', ASCII 27 character. Normally, the terminal will trap sequences of characters that begin with the escape character, and interpret these escape sequences to control the screen and manage cursor and text placement. Evidently, the sequence being sent to the terminal by ncurses is not being trapped by your terminal, and is instead being displayed in the only way it knows how.

What is the value of $TERM, and what kind of terminal/emulator is your application running on?

--- rod.

xeleema 02-09-2011 12:56 PM

Those are probably UTF-8 characters. Try setting the locale of the terminal you're running in.
Code:

luser@lhost$ env|grep -i utf
LANG=en_US
luser@lhost$ ls -la /usr/share/X11/locale | grep en_US | grep -i utf
drwxr-xr-x  2 root root  4096 Oct 27  2009 en_US.UTF-8
luser@lhost$ export LANG=en_US.UTF-8
luser@lhost$ env|grep -i utf
LANG=en_US.UTF-8


MALDATA 02-09-2011 02:06 PM

1 Attachment(s)
Thanks for the responses. Here is the information you requested. Note that the locale is already set to en_US.UTF-8, and that I'm using gnome-terminal.

Code:

$ echo $TERM
xterm
$ env|grep -i utf
LANG=en_US.utf8
GDM_LANG=en_US.utf8
$ ls -la /usr/share/X11/locale | grep en_US | grep -i utf
drwxr-xr-x.  2 root root  4096 Oct 22 13:32 en_US.UTF-8

I'm not sure I know how an escape character would get into the values I'm printing. They're all just floating-point numbers. Also, here's something even weirder. The box is sometimes partially overwritten by a [SOME_NUMBER; such that the [ is on top of half of the box. I can even select it individually with the mouse. See the attached sequence of screenshots.

Other thoughts?
Thanks!

theNbomr 02-09-2011 02:17 PM

Quote:

Originally Posted by MALDATA (Post 4253382)
I'm not sure I know how an escape character would get into the values I'm printing.

If you are using ncurses to print them, then they are getting there because that's how ncurses tells the terminal where and with what attribute(s) to display the text.
What happens if you use a different terminal type, such as an xterm?

--- rod.

MALDATA 02-09-2011 02:39 PM

xterm seems to display everything correctly. I don't get any of these anomalies. Do you happen to know why that might be the case? That is, what is gnome-terminal doing differently from xterm?

Thanks!

theNbomr 02-09-2011 03:10 PM

It isn't correctly emulating an xterm. It's hard to say whether that is a bug, or whether it simply wasn't intended to do so. Perhaps it is the setting of $TERM that is incorrect. I've never really figured out which is the chicken and which is the egg. I don't have gnome terminal; have you checked to see whether it has a configurable emulation? Maybe it can be set to xterm emulation.

--- rod.


All times are GMT -5. The time now is 06:04 PM.