9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* Re: [9fans] isatty
@ 2001-02-14 15:45 rog
  0 siblings, 0 replies; 9+ messages in thread
From: rog @ 2001-02-14 15:45 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 416 bytes --]

i was wondering whether it might not be useful
for the terminal handler (win/rio) to print a prompt
of some kind when it got a read request on /dev/cons.
that way you get a prompt for all other programs too
(e.g. db(1)) without the clutter of isatty() and the like.

only problem is you wouldn't be sure quite which
program was asking for input. hmm, maybe not quite
such a good idea after all.

  rog.


[-- Attachment #2: Type: message/rfc822, Size: 3117 bytes --]

[-- Attachment #2.1.1: Type: text/plain, Size: 184 bytes --]

Yeah. For purity and consistency, I tried to get TD to forget
about prompting in rc, just have it run commands, but he
caved in to pressure from less clean-minded people.

-rob


[-- Attachment #2.1.2: Type: message/rfc822, Size: 1374 bytes --]

From: rog@vitanuova.com
To: 9fans@cse.psu.edu
Subject: [9fans] isatty
Date: Wed, 14 Feb 2001 13:48:40 0000
Message-ID: <20010214124400.7C58819A16@mail.cse.psu.edu>

> since the idea is that what i see from
> 	ls
> should be a good guide to what grep sees in
> 	ls | grep '\.c'
> then yes, that isatty is indeed a bad idea

mind you, plan 9 isn't entirely innocent in this
respect, c.f. /sys/src/cmd/rc/exec.c:/Isatty

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] isatty
@ 2002-01-23 15:26 Russ Cox
  0 siblings, 0 replies; 9+ messages in thread
From: Russ Cox @ 2002-01-23 15:26 UTC (permalink / raw)
  To: 9fans

Now that we have fd2path, I prefer this:

def isatty(fd):
	s = fd2path(fd);
	return len(s)>=9 and s[-9:]=='/dev/cons'

Russ


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] isatty
  2002-01-23 13:13 presotto
@ 2002-01-23 13:43 ` Boyd Roberts
  0 siblings, 0 replies; 9+ messages in thread
From: Boyd Roberts @ 2002-01-23 13:43 UTC (permalink / raw)
  To: 9fans

presotto@closedmind.org wrote:
> The version comparison is an overkill and potentially wrong since
> whatever is implementing /dev/cons may decide to update the
> version each write, as is our practice in other places.

I had this in mind as I wrote it and I asked the question
because I wanted an answer from the source.

> That should work in general as long as the namespace hasn't
> been changed twixt the opening of the fd and the dirstat.
> Otherwise /dev/cons may be under a different mount point
> number and hence a different c.dev.

Sure.

> The question isatty is usually trying to answer is
> "does the fd has an interacting user behind it?".  A
> hard question to answer in a world where the geography
> can shift so easily.

True.  But Python seems to really like you to be able to call
isatty.  Whether it wants to do it or whether it's part of the
'os' module is a question I don't want to know and isatty is
a function I never want to call.

The crawling across broken glass [aka dealing with configure
and configure based code] was vastly outweighed by the buzz
I got from using Plan 9.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] isatty
@ 2002-01-23 13:13 presotto
  2002-01-23 13:43 ` Boyd Roberts
  0 siblings, 1 reply; 9+ messages in thread
From: presotto @ 2002-01-23 13:13 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 588 bytes --]

The version comparison is an overkill and potentially wrong since
whatever is implementing /dev/cons may decide to update the
version each write, as is our practice in other places.

That should work in general as long as the namespace hasn't
been changed twixt the opening of the fd and the dirstat.
Otherwise /dev/cons may be under a different mount point
number and hence a different c.dev.

The question isatty is usually trying to answer is
"does the fd has an interacting user behind it?".  A
hard question to answer in a world where the geography
can shift so easily.

[-- Attachment #2: Type: message/rfc822, Size: 2165 bytes --]

From: Boyd Roberts <boyd@strakt.com>
To: "9fans@cse.psu.edu" <9fans@cse.psu.edu>
Subject: [9fans] isatty
Date: Wed, 23 Jan 2002 12:56:44 +0100
Message-ID: <3C4EA4FC.A777CA4D@strakt.com>

Given I had to implement this 'thing' on Plan 9 I decided on:

#include <u.h>
#include <libc.h>

static char *cons = "/dev/cons";

/*
 * Compare fd to cons should get it right.
 */
int
isatty(int fd)
{
	Dir c;
	Dir f;

	if (dirstat(cons, &c) != 0)
		return 0;

	if (dirfstat(fd, &f) != 0)
		return 0;

	return f.type == c.type &&
		f.dev == c.dev &&
		f.qid.path == c.qid.path &&
		f.qid.vers == c.qid.vers;
}

Seemed obvious to me, but is this a good plan?

The overkill on the multiple dirstat's on /dev/cons and
qid comparison I thought would ensure that I wouldn't
get fooled [again].

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [9fans] isatty
@ 2002-01-23 11:56 Boyd Roberts
  0 siblings, 0 replies; 9+ messages in thread
From: Boyd Roberts @ 2002-01-23 11:56 UTC (permalink / raw)
  To: 9fans

Given I had to implement this 'thing' on Plan 9 I decided on:

#include <u.h>
#include <libc.h>

static char *cons = "/dev/cons";

/*
 * Compare fd to cons should get it right.
 */
int
isatty(int fd)
{
	Dir c;
	Dir f;

	if (dirstat(cons, &c) != 0)
		return 0;

	if (dirfstat(fd, &f) != 0)
		return 0;

	return f.type == c.type &&
		f.dev == c.dev &&
		f.qid.path == c.qid.path &&
		f.qid.vers == c.qid.vers;
}

Seemed obvious to me, but is this a good plan?

The overkill on the multiple dirstat's on /dev/cons and
qid comparison I thought would ensure that I wouldn't
get fooled [again].


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] isatty
  2001-02-14 13:51 ` rob pike
@ 2001-02-14 16:42   ` Scott Schwartz
  0 siblings, 0 replies; 9+ messages in thread
From: Scott Schwartz @ 2001-02-14 16:42 UTC (permalink / raw)
  To: 9fans

| Yeah. For purity and consistency, I tried to get TD to forget
| about prompting in rc, just have it run commands, but he
| caved in to pressure from less clean-minded people.

Maybe the window system could do the prompting.  It could check if there
are any outstanding read requests for a window, and if so, change the
border color, or something like that.




^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: [9fans] isatty
@ 2001-02-14 15:09 Yehuda Tiram
  0 siblings, 0 replies; 9+ messages in thread
From: Yehuda Tiram @ 2001-02-14 15:09 UTC (permalink / raw)
  To: '9fans@cse.psu.edu'

Dear mail sender,
The addressee of your mail message is not receiving mail from the address
you have (addressee@seerun.com).
Please check with him and correct your records.
Thank you
Tiram
SeeRun LTD.
Office : 972 3 5756154



-----Original Message-----
From: 9fans-admin@cse.psu.edu [mailto:9fans-admin@cse.psu.edu]On Behalf Of
rog@vitanuova.com
Sent: Wednesday, February 14, 2001 3:46 PM
To: 9fans@cse.psu.edu
Subject: Re: [9fans] isatty


i was wondering whether it might not be useful
for the terminal handler (win/rio) to print a prompt
of some kind when it got a read request on /dev/cons.
that way you get a prompt for all other programs too
(e.g. db(1)) without the clutter of isatty() and the like.

only problem is you wouldn't be sure quite which
program was asking for input. hmm, maybe not quite
such a good idea after all.

  rog.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] isatty
@ 2001-02-14 13:51 ` rob pike
  2001-02-14 16:42   ` Scott Schwartz
  0 siblings, 1 reply; 9+ messages in thread
From: rob pike @ 2001-02-14 13:51 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 184 bytes --]

Yeah. For purity and consistency, I tried to get TD to forget
about prompting in rc, just have it run commands, but he
caved in to pressure from less clean-minded people.

-rob


[-- Attachment #2: Type: message/rfc822, Size: 1374 bytes --]

From: rog@vitanuova.com
To: 9fans@cse.psu.edu
Subject: [9fans] isatty
Date: Wed, 14 Feb 2001 13:48:40 0000
Message-ID: <20010214124400.7C58819A16@mail.cse.psu.edu>

> since the idea is that what i see from
> 	ls
> should be a good guide to what grep sees in
> 	ls | grep '\.c'
> then yes, that isatty is indeed a bad idea

mind you, plan 9 isn't entirely innocent in this
respect, c.f. /sys/src/cmd/rc/exec.c:/Isatty

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [9fans] isatty
@ 2001-02-14 13:48 rog
  0 siblings, 0 replies; 9+ messages in thread
From: rog @ 2001-02-14 13:48 UTC (permalink / raw)
  To: 9fans

> since the idea is that what i see from
> 	ls
> should be a good guide to what grep sees in
> 	ls | grep '\.c'
> then yes, that isatty is indeed a bad idea

mind you, plan 9 isn't entirely innocent in this
respect, c.f. /sys/src/cmd/rc/exec.c:/Isatty



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2002-01-23 15:26 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-02-14 15:45 [9fans] isatty rog
  -- strict thread matches above, loose matches on Subject: below --
2002-01-23 15:26 Russ Cox
2002-01-23 13:13 presotto
2002-01-23 13:43 ` Boyd Roberts
2002-01-23 11:56 Boyd Roberts
2001-02-14 15:09 Yehuda Tiram
     [not found] <rob@plan9.bell-labs.com>
2001-02-14 13:51 ` rob pike
2001-02-14 16:42   ` Scott Schwartz
2001-02-14 13:48 rog

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).