Advertisement

underlined text

Started by June 03, 2002 08:42 PM
8 comments, last by GarlandIX 22 years, 6 months ago
In a Win32 console program, is it possible to print out underlined text like this: this text is underlined. If so, how do you do it? Thanks in advance for your help. ------------------------------ BASIC programmers don''t die, they just GOSUB and don''t return.
------------------------------BASIC programmers don't die, they just GOSUB and don't return.
Do a search for "ANSI escape sequences".

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Advertisement
I did the search and after spending a while figuring out ASNI escape codes i tried this:
const char ESC = 27;
std::cout << ESC << "[04mThis text should be underlined." << std::endl;
ESC[04m should make the text underlined. Instead, it turnes blue . What could I possibly be doing wrong?

------------------------------
BASIC programmers don''t die, they just GOSUB and don''t return.
------------------------------BASIC programmers don't die, they just GOSUB and don't return.
\e is a (non-standard) code for ESC. gcc supports it, maybe VS too.

According to http://enterprise.aacc.cc.md.us/~rhs/ansi.html

About "\e[04m"
Underscore (on monochrome display adapter only)
Parameters 30 through 47 meet the ISO 6429 standard.

"\e[=0h"
Set Mode 40 x 148 x 25 monochrome (text)

Hope you can get it to work... usually it works in terminals, not that well in windows consoles (at least on W2k).

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
On standard PC display adapters, the only way to get underlined text in text mode is if your video adapter supports it. The last adapater I had that supported it was a Hercules/MDA monochrome display adapter (720x348, if I''m not mistaken), and it could be done by using forground color 01h (which I think is blue on color adapters).

Graphical consoles and terminal emulators can support it using ANSI codes, but i''ve never been able to do it in a NT/DOS console.

You could use two lines to do it. One line with the text and one line with character C4h.

Other than that, you should use graphics mode. Actually, I prefer to do my text-based apps using web servers and HTML, and underlining in HTML is EEEEEASY! :-)

--TheMuuj
--TheMuuj
Fruny: doesn't work. Thanks for reminding me about '\e' though.

What i am trying to do is have an equation(to be solved) on two lines, with the first one underlined, since it is a fraction (in case anyone cares, it is the quadratic formula). This is opposed to three lines(to save screen space). here's what i am talking about:
3 lines: -b±sqrt(b²-4ac)         ---------------               2a2 lines: -b±sqrt(b²-4ac)               2a

EDIT: Stupid spacing...
------------------------------
BASIC programmers don't die, they just GOSUB and don't return.

[edited by - GarlandIX on June 3, 2002 12:59:21 AM]
------------------------------BASIC programmers don't die, they just GOSUB and don't return.
Advertisement
Apparently, ANSI escapes aren''t supported anymore in windows...

I loved these things

Thankfully *NIX has no problems with them

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
quote:
Apparently, ANSI escapes aren''t supported anymore in windows...

They work alright on win98se(i have) but not the underlining .
I guess ill just have to do what theMuuj said (three lines with char C4h as the underline.

------------------------------
BASIC programmers don''t die, they just GOSUB and don''t return.
------------------------------BASIC programmers don't die, they just GOSUB and don't return.
quote: Original post by GarlandIX

They work alright on win98se(i have) but not the underlining .
...


Actually the underlining is only available in Hercules/MDA or Monochrome (those IBM XT,8086,8088)... on CGA/EGA/VGA/SVGA it is blue text (color 1 in BASIC).... TheMuuj already mentioned it. So it is not 98SE not supporting it... it is your grpahics/display card....

...maybe u could change the display mode to black&white.....
"after many years of singularity, i'm still searching on the event horizon"
If you have an expression like "a = b / c" (but with a horizontal division line) wouldn''t you want to have it on 3 lines so the "a =" is centred vertically?

Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions

This topic is closed to new replies.

Advertisement