LinuxQuestions.org
Help answer threads with 0 replies.
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 02-09-2011, 11:11 AM   #1
MALDATA
Member
 
Registered: Mar 2005
Posts: 157

Rep: Reputation: 19
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
 
Old 02-09-2011, 12:35 PM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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.
 
Old 02-09-2011, 12:56 PM   #3
xeleema
Member
 
Registered: Aug 2005
Location: D.i.t.h.o, Texas
Distribution: Slackware 13.x, rhel3/5, Solaris 8-10(sparc), HP-UX 11.x (pa-risc)
Posts: 988
Blog Entries: 4

Rep: Reputation: 254Reputation: 254Reputation: 254
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
 
Old 02-09-2011, 02:06 PM   #4
MALDATA
Member
 
Registered: Mar 2005
Posts: 157

Original Poster
Rep: Reputation: 19
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!
Attached Thumbnails
Click image for larger version

Name:	sequence.png
Views:	175
Size:	10.9 KB
ID:	6100  
 
Old 02-09-2011, 02:17 PM   #5
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Quote:
Originally Posted by MALDATA View Post
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.
 
Old 02-09-2011, 02:39 PM   #6
MALDATA
Member
 
Registered: Mar 2005
Posts: 157

Original Poster
Rep: Reputation: 19
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!
 
Old 02-09-2011, 03:10 PM   #7
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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.
 
1 members found this post helpful.
  


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
CUPS 1.3.9-11 with HPLIP 2.8.12-1 prints meaningless garbage (Debian Sid/Exp.) Coviti Linux - Desktop 3 07-21-2010 05:12 PM
problem with 'less' command - prints garbage when piped. spoovy Slackware 11 03-09-2010 04:07 AM
Samba shared printer prints garbage gankoji Linux - Server 4 08-02-2009 02:32 PM
Ncurses: printw(); prints to screen even if refresh(); is not called - why? violagirl23 Programming 3 03-10-2008 08:12 AM
IE doesn't load PDF sometimes and prints garbage siucorn Linux - Software 0 08-29-2003 10:04 PM

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

All times are GMT -5. The time now is 03:51 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