Operating System - HP-UX
1834178 Members
2718 Online
110064 Solutions
New Discussion

How to draw a box on the screen?

 
SOLVED
Go to solution
Robert Fisher_1
Frequent Advisor

How to draw a box on the screen?

Hi experts,

I have to update some old shell scripts and make them look nice. Is there a method to draw a box around some text in the shell? I suppose that I could live with +'s for the corners, abd dashes and pipe symbols but I would really like to able to draw nice lines like SAM does. Any hints or ideas?


TIA,
Bob Fisher


8 REPLIES 8
Umapathy S
Honored Contributor

Re: How to draw a box on the screen?

Robert,
As far as I know, they are done with curses/ncurses. You have to do a bit of C programming to achieve what you want.
see man curses for further info.
HTH,
Umapathy
Arise Awake and Stop NOT till the goal is Reached!
Caesar_3
Esteemed Contributor

Re: How to draw a box on the screen?

Hello!

You can write in difrent modes,
about a screens you can draw special characters
(ASCII draw) depend on the font that you use.
I think that exist tools that creates screens
like SAM screens.

Caesar
A. Clay Stephenson
Acclaimed Contributor

Re: How to draw a box on the screen?

Hi Bob:

The key to what you want is the tput smacs command. (Start alternate character set). That sequence is not defined for all terminals so you need a fallback plan using "+","-", & "|" in case the smacs sequence is null. At a minimum the cursor position string and the clear string would also be needed. At best this will be a kludge.

There are some Perl modules that do curses rather well and also Perl/Tcl if you really wanted to modernize but still script.

I do remember doing something like this about 20 years ago. I'll look in my toolbox for the old script.




If it ain't broke, I can fix that.
Bill Hassell
Honored Contributor

Re: How to draw a box on the screen?

The results very much depend on the terminals that you use. SAM recognizes many different terminal types so as long as the terminal has line drawing characters in the available fonts. Note that glass terminals have often been replaced with PCs and cheap emulator programs that don't do a good job of emulating a specific terminal, so your results may vary. You can create some functions that use tput and repeated characters to draw the boxes. The man page for terminfo gives you a lot of details. Note that for tput to work correctly, the terminal must match the setting of $TERM. Essentially, $TERM is an index into the terminfo database of terminal capabilities and tput will return the correct sequence for a given capability.


Bill Hassell, sysadmin
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: How to draw a box on the screen?

Well, it wasn't 20 years old - only 12. The code looked so bad that I had to spiff it up to POSIX/Korn first but it does work. A more rigorous approach would , after determining that smacs is not null, determine if acsc (alternate character set) is also defined and read it in to get the characters for corners, bars, etc.). The values used are the VTxxx and work for the vast majority of terminals (including dtterm). This should at least get you started.

Man 4 terminfo and look for "Line Graphics" for details.

If it ain't broke, I can fix that.
Robert Fisher_1
Frequent Advisor

Re: How to draw a box on the screen?

Thank you guys!. A. Clay and Bill pointed me in the right direction and Clay's attached script worked great. Our PC's are set to vt220.

Clay, I'm amazed that you keep scripts that are 12 years old around.

Thanks again,
Bob Fisher
A. Clay Stephenson
Acclaimed Contributor

Re: How to draw a box on the screen?

Actually, I have some around that are much older. You see, like Foghorn Leghorn, "Fortunately, I always keep my feathers numbered for just such an emergency".

Regards, Clay

If it ain't broke, I can fix that.
Robert Fisher_1
Frequent Advisor

Re: How to draw a box on the screen?

Hi Clay,

I laughed so hard at your last response that I had to give you 10 points!! I remember that cartoon too.

Thanks,
Bob Fisher