[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: terminal
Both of these are terrible advice, you should choose the third option
and write OS & terminal specific code foreach platform and tty.
This is as opposed to:
1) Writing easy code that works perfectly on OpenBSD, but not
everywhere else.
2) Writing kludgy code that works pretty much everywhere.
So my advice is best, set up a team of developers for each target OS
and ensure they agree an API with the rest of the product team. Each
team is responsible for implementing the API correctly on all supported
ttys for that OS.
What? You don't own a software company? Ohh.
Well I guess the choice must depend on your exact situation then....
e.g.
#ifdef OPENBSD
/* Pretty code */
#else
/* Kludge! Freeze authors brain when he dies! */
#endif
Dom
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Dom De Vitto Tel. 07855 805 271
http://www.devitto.com mailto:dom@devitto.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-----Original Message-----
From: owner-misc@openbsd.org [mailto:owner-misc@openbsd.org] On Behalf
Of Theo de Raadt
Sent: Sunday, December 01, 2002 10:34 AM
To: dr@kyx.net
Cc: Hugo Villeneuve; Ben Bunker; misc@openbsd.org
Subject: Re: terminal
This is terrible advice.
Use the ioctl.
> On December 1, 2002 07:03 am, Hugo Villeneuve wrote:
> > On Sat, Nov 30, 2002 at 11:45:27AM -0800, Ben Bunker wrote:
> > > Hello,
> > >
> > > Bit of a programming question here. I'm attempting to write a
> > > scaled-down version of the more utility, and I'm at a loss as to
> > > how to find the size of the terminal (i.e., width, number of
> > > lines). Does anyone have any insight into this? Thanks.
> >
> > There's a TIOCGWINSZ ioctl to get the window size (man 4 tty).
>
> Assuming the user has set it right. ;-)
>
> The low level method of this is to send a terminal capabilities
> inquiry
> code to some terminals or terminal software. But inquiry code
> emulation in the more marginal terminal emulations is hit or miss.
> And the parsing logic can get ugly. Or....
>
> The portable way of doing it (given that everything except ancient
> crusty wyse magic cookie terminals accepts ANSI/VT codes) sounds ugly
> but works nicely: The technique is to gradually send incrementing
> screen positions {printf("\x1B[%d;%dH]",x,y);} and use the return
> character pos inquiry code {printf("\x1B[6n");} and parse out the
> returned "\x1B[%d;%dH" sequences until it's obvious you've hit the end
> of the screen because they stop incrementing.
>
> This method works even with very broken terminal emulation sw and
> should
> be as close to universally applicable as I've found.
>
> cheers
> --dr
>
> P.S. Join the campaign to remove terminfo and termcap from POSIX
> today!!! s/term{info,cap}/ansi/ :-)
>
> P.P.S. Less is often more better. :-) :-) :-)
>
> --
> dr@kyx.net pgp: http://dragos.com/kyxpgp
> CanSecWest/core03 speakers on-line at http://cansecwest.com