|
Home > Archive > Unix Programming > September 2007 > Question about terminfo
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 |
Question about terminfo
|
|
| Spiros Bousbouras 2007-09-14, 1:23 pm |
| The terminfo man page has entries for "end italic" or
"end standout" but it doesn't have entries for "end reverse"
or "end bold" although it has entries for "start reverse"
or "start bold". Does anyone know why this is ?
If you have a programme which needs to start reverse,
print some things and then return the terminal to its
previous state without affecting any other attributes
apart from reverse , is there a way to do it ? I'm interested
for an answer both with shell and with C.
| |
| Brian Bebeau 2007-09-14, 1:23 pm |
| Spiros Bousbouras wrote:
> The terminfo man page has entries for "end italic" or
> "end standout" but it doesn't have entries for "end reverse"
> or "end bold" although it has entries for "start reverse"
> or "start bold". Does anyone know why this is ?
>
> If you have a programme which needs to start reverse,
> print some things and then return the terminal to its
> previous state without affecting any other attributes
> apart from reverse , is there a way to do it ? I'm interested
> for an answer both with shell and with C.
Check your terminal description. You may find that "reverse" is
the same as "standout" (though the terminfo man page says standout
is reverse + bold). If that's the case, then using "rmso" may work
for "reverse".
If you don't want to assume standout and reverse are the same, it
looks like you'll have to use "sgr". For instance, if you do:
tput rev
tput bold
you can then do:
tput sgr 0 0 0 0 0 1 0 0
to turn off reverse and leave bold, or:
tput sgr 0 0 1 0 0 0 0 0
to turn off bold and leave reverse. Check the terminfo man page
where it discusses "sgr" for the details.
| |
| Spiros Bousbouras 2007-09-14, 1:23 pm |
| On 14 Sep, 16:36, Brian Bebeau <bbeb...@computer.org> wrote:
> Spiros Bousbouras wrote:
>
>
> Check your terminal description. You may find that "reverse" is
> the same as "standout" (though the terminfo man page says standout
> is reverse + bold). If that's the case, then using "rmso" may work
> for "reverse".
The idea is to make it portable between different terminals (or
emulators).
>
> If you don't want to assume standout and reverse are the same, it
> looks like you'll have to use "sgr". For instance, if you do:
>
> tput rev
> tput bold
>
> you can then do:
>
> tput sgr 0 0 0 0 0 1 0 0
>
> to turn off reverse and leave bold, or:
>
> tput sgr 0 0 1 0 0 0 0 0
>
> to turn off bold and leave reverse. Check the terminfo man page
> where it discusses "sgr" for the details.
The problem is that I don't know whether, before my programme/script
starts, bold was on. The point is that if it was on I want to leave it
on and
if it was off I want to leave it off. Same for the other attributes
apart from
reverse. So is there a way to get that information ?
| |
| Spiros Bousbouras 2007-09-15, 1:19 pm |
| On 14 Sep, 17:25, Miles <my_spam_acco...@shaw.ca> wrote:
> Will the Ansi Terminal Control sequences help you?
>
> These two operations sounded like they may help you:
> Save Cursor & Attrs <ESC>7
>
> * Save current cursor position.
>
> Restore Cursor & Attrs <ESC>8
>
> * Restores cursor position after a Save Cursor.
>
> Copied from:http://www.termsys.demon.co.uk/vtansi.htm
This is the kind of thing I'm looking for but does anyone
know how portable they are ? I would imagine they're less
portable than terminfo.
They are mentioned in the Linux console_codes man page
in the section "ESC- but not CSI- sequences". On xterm
and Linux console they restore cursor position and attributes,
on gnome-terminal just cursor position.
| |
| Stephane CHAZELAS 2007-09-15, 1:19 pm |
| 2007-09-15, 07:44(-07), Spiros Bousbouras:
[...]
>
> This is the kind of thing I'm looking for but does anyone
> know how portable they are ? I would imagine they're less
> portable than terminfo.
[...]
They've got a terminfo capability associated with them: sc and
rc. As you found out, restoring the attributes looks more like a
side effect.
If you want to restore the screen to what it was before, you can
use the alternate screen if available.
What if you explained what you really want to do?
My view is that managing terminal attributes is a portability
nightmare, so I would tend to use existing libraries to do
anything fancy like ncurses, slang, cdk... and go for the
simplest possible.
--
Stéphane
| |
| Thomas Dickey 2007-09-16, 1:24 pm |
| >> * Restores cursor position after a Save Cursor.
hmm (that page intermixes ANSI and VT100 without noting that they're
not synonymous).
better:
http://vt100.net/
e.g.,
http://vt100.net/docs/vt102-ug/chapter5.html#S5.5.2
"Saves cursor position, character attribute (graphic rendition),
character set, and origin mode selection. (See restore cursor)"
[vbcol=seagreen]
> This is the kind of thing I'm looking for but does anyone
> know how portable they are ? I would imagine they're less
> portable than terminfo.
> They are mentioned in the Linux console_codes man page
> in the section "ESC- but not CSI- sequences". On xterm
> and Linux console they restore cursor position and attributes,
> on gnome-terminal just cursor position.
On any terminal that emulates vt100, they should restore the video attributes
as well (but many terminal emulators claim to emulate vt100... ;-)
--
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net
| |
| Maxwell Lol 2007-09-16, 7:19 pm |
| Thomas Dickey <dickey@saltmine.radix.net> writes:
[vbcol=seagreen]
>
> hmm (that page intermixes ANSI and VT100 without noting that they're
> not synonymous).
>
> better:
>
> http://vt100.net/
>
> e.g.,
>
> http://vt100.net/docs/vt102-ug/chapter5.html#S5.5.2
>
> "Saves cursor position, character attribute (graphic rendition),
> character set, and origin mode selection. (See restore cursor)"
>
As someone who remembers ADM and VT52 terminals (and ASR-33, TI Silent
700, etc.), termcap/terminfo was AFAIK designed to support ANY
terminal. It's the entry for the terminal that matters most. And if it
didn't, we used to extract the part that described the terminal, and
put it in a file, and set the environment variable to point to the
file (because we didn't have permission to exit the database directly).
Then we'd edit it until things worked properly.
Many terminal emulators tried to emulate VT100's. There's a program
called vttest that determines how accutrately your terminal did the
emulation.
So it there's a problem, you can either change the terminfo database
to match the terminal you had, or you changed your terminal.
If you wanted to make your applicaiton as portable as possiible, use
the terminfo database. But test it with different types of terminals.
I also remember a program called vtem, which used termcap/terminfo to
emulate the actions of a vt102 terminals.
| |
| Spiros Bousbouras 2007-09-18, 1:27 pm |
| On Sep 15, 4:34 pm, Stephane CHAZELAS <this.addr...@is.invalid> wrote:
> 2007-09-15, 07:44(-07), Spiros Bousbouras:
> [...]>> These two operations sounded like they may help you:
>
>
>
>
>
>
> [...]
>
> They've got a terminfo capability associated with them: sc and
> rc. As you found out, restoring the attributes looks more like a
> side effect.
The terminfo man page says that sc and rc save and restore
respectively
cursor position ; it doesn't say anything about attributes. On the
other hand
the console_codes man page when discussing <ESC> 7 and <ESC> 8 says
that they also deal with attributes. So they don't look analogous to
me.
>
> If you want to restore the screen to what it was before, you can
> use the alternate screen if available.
>
> What if you explained what you really want to do?
I thought that I did that in my first post but here goes again. I have
a
script which is supposed to print some things in normal and some
things in reverse for emphasis. But ideally I would like for my script
to
leave after it finishes the terminal attributes as they were before my
script
started. If for example the user who uses my script likes to have bold
on
all the time and runs my script , then I want bold to remain on after
my
script finishes rather than force the user to turn it back on
manually. So
doing for example ``tput sgr0" at the end of my script won't do.
> My view is that managing terminal attributes is a portability
> nightmare, so I would tend to use existing libraries to do
> anything fancy like ncurses, slang, cdk... and go for the
> simplest possible.
I wouldn't consider what I'm trying to do fancy. (n)curses won't do
because it doesn't tell you what the terminal attributes were before
you call the initialisation function for curses (can't remember what
it's called).
| |
| Stephane CHAZELAS 2007-09-18, 1:27 pm |
| 2007-09-18, 13:13(-00), Spiros Bousbouras:
[...]
> I thought that I did that in my first post but here goes
> again. I have a script which is supposed to print some things
> in normal and some things in reverse for emphasis. But ideally
> I would like for my script to leave after it finishes the
> terminal attributes as they were before my script started. If
> for example the user who uses my script likes to have bold on
> all the time and runs my script , then I want bold to remain
> on after my script finishes rather than force the user to turn
> it back on manually. So doing for example ``tput sgr0" at the
> end of my script won't do.
[...]
I wouldn't bother. No visual application does that as far as I
can see.
So, if such basic applications as vi or less don't do it, users
should expect that any command they run, especially visual ones
may reset the attributes.
shells like zsh or fish even reset the attributes (sgr0) before
each prompt.
--
Stéphane
|
|
|
|
|