9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] rawon for /dev/cons
@ 2010-05-16  9:20 Rudolf Sykora
  2010-05-16 13:36 ` erik quanstrom
  0 siblings, 1 reply; 4+ messages in thread
From: Rudolf Sykora @ 2010-05-16  9:20 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Hello,

I played with this simple program, which just sets the raw mode for
the console and writes back written characters:
--------------------------
#include <u.h>
#include <libc.h>

void
main (int argc, char *argv[])
{
	int	cfd;
	char	buf[2];
	int	nr;

	cfd = open("/dev/consctl", OWRITE);
	write(cfd, "rawon", 5);

	while((nr = read(0, buf, 1)) > 0) {
		if(buf[0] == 'q') break;
		buf[1] = 0;
		print("%s", buf);
	}
	close(cfd);
	exits(nil);
}
--------------------------

But I was surprised it doesn't do what I want.
The rio(1) man page says, in the 'Raw text windows' section that
'... no typed keyboard characters are special, ... and all are passed
to a program immediately upon reading'.
However, it seems rio still interprets ^u, ^a, ^e, ^w, BS, arrows,
page up/down,... (although not DEL, e.g.)
Can anybody explain to me what is wrong?
(Also I don't quite understand why pressing ^d results in drawing EOT,
pressing F1 does nothing as well as pressing alt-whatever [e.g.
alt-AE]...; Also, what must I do to see the codes (like ^a=0x01)
instead of the characters?)

Thanks a lot!
Ruda



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

* Re: [9fans] rawon for /dev/cons
  2010-05-16  9:20 [9fans] rawon for /dev/cons Rudolf Sykora
@ 2010-05-16 13:36 ` erik quanstrom
  2010-05-16 20:16   ` Rudolf Sykora
  0 siblings, 1 reply; 4+ messages in thread
From: erik quanstrom @ 2010-05-16 13:36 UTC (permalink / raw)
  To: 9fans

> But I was surprised it doesn't do what I want.
> The rio(1) man page says, in the 'Raw text windows' section that
> '... no typed keyboard characters are special, ... and all are passed
> to a program immediately upon reading'.
> However, it seems rio still interprets ^u, ^a, ^e, ^w, BS, arrows,
> page up/down,... (although not DEL, e.g.)
> Can anybody explain to me what is wrong?

if you open the mouse, you will supress rio's terminal from using these
keys for navigation.

> (Also I don't quite understand why pressing ^d results in drawing EOT,

you're reading ctl-d (0x04) and then printing it.  since there
is a character in your font at that position that looks like EOT, that's
what you see.

> pressing F1 does nothing as well as pressing alt-whatever [e.g.
> alt-AE]...; Also, what must I do to see the codes (like ^a=0x01)
> instead of the characters?)

a Rune is >1 byte.  you're only reading one byte.

- erik

---

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

void
main(void)
{
	char buf[UTFmax + 1];
	int cfd, mfd, n, i, l;
	Rune r;

	cfd = open("/dev/consctl", OWRITE);
	if(cfd == -1 || write(cfd, "rawon", 5) != 5)
		sysfatal("consctl: %r");
	mfd = open("/dev/mouse", OREAD);
	if(mfd == -1)
		sysfatal("mouse: %r");
	i = 0;
	for(;;){
		for(;;){
			n = read(0, buf + i, 1);
			if(n <= 0)
				goto done;
			i += n;
			if(fullrune(buf, i))
				break;
		}
		buf[i] = 0;
		l = chartorune(&r, buf);
		if(r == 0xfff7)
			break;
		if(r < 0x20)
			print("ctl-%c\n", '@' + r);
		else if(r == 0x7f)
			print("del\n");
		else
			print("%C\n", r);
		memmove(buf, buf + l, i - l);
		i = i - l;
	}
done:
	close(cfd);
	close(mfd);
	exits(nil);
}



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

* Re: [9fans] rawon for /dev/cons
  2010-05-16 13:36 ` erik quanstrom
@ 2010-05-16 20:16   ` Rudolf Sykora
  2010-05-16 20:46     ` erik quanstrom
  0 siblings, 1 reply; 4+ messages in thread
From: Rudolf Sykora @ 2010-05-16 20:16 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Hello,

thanks Eric for your answer!

So if I understand right the rio(1) man page is slightly wrong. Not
only /dev/consctl has to be open but also /dev/mouse so that really
all characters be passed through. Is there any reason for this? Why
isn't it just the way the man page describes? (And actually not only
the man page but also FJB's Introduction to Operating Systems
Abstractions, page 290 suggests the same.)

Further. Is it so that in both cooked and raw mode /dev/cons always
serves UTF runes?

Is there any means of seeing the scancodes themselves? Or some other
way of seeing when a key is pressed and released (e.g. a simple Alt
key)? (I guess that providing some simple kbmap could perhaps do this
[or not?] but even if, it'd be a global thing while one would desire
it work on per window basis...)

Thanks for any comments!!
Ruda



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

* Re: [9fans] rawon for /dev/cons
  2010-05-16 20:16   ` Rudolf Sykora
@ 2010-05-16 20:46     ` erik quanstrom
  0 siblings, 0 replies; 4+ messages in thread
From: erik quanstrom @ 2010-05-16 20:46 UTC (permalink / raw)
  To: 9fans

> all characters be passed through. Is there any reason for this? Why
> isn't it just the way the man page describes? (And actually not only
> the man page but also FJB's Introduction to Operating Systems
> Abstractions, page 290 suggests the same.)

the manual page is in error.  please submit a patch.

> Further. Is it so that in both cooked and raw mode /dev/cons always
> serves UTF runes?

i'm sorry.  i misspoke.  the console gives you utf-8, not runes.
all programs use utf-8 in plan 9, except in the odd case of dealing
with data from foreign systems, such as email.

- erik



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

end of thread, other threads:[~2010-05-16 20:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-16  9:20 [9fans] rawon for /dev/cons Rudolf Sykora
2010-05-16 13:36 ` erik quanstrom
2010-05-16 20:16   ` Rudolf Sykora
2010-05-16 20:46     ` erik quanstrom

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).