Opened 17 years ago

Closed 17 years ago

#1340 closed bug (fixed)

Terminal doesn't produce the EOF character on Ctrl-D

Reported by: bonefish Owned by: jackburton
Priority: normal Milestone: R1
Component: Applications/Terminal Version: R1/pre-alpha1
Keywords: Cc:
Blocked By: Blocking:
Platform: All

Description

It seems that the terminal produces a three character escape sequence when Ctrl-D is pressed instead of the correct (single) character. This causes Ctrl-D not to have the desired effect. E.g.

cat > /dev/null

can not be terminated with Ctrl-D. This works fine with Be's Terminal under Haiku.

Revision: hrev21735

Change History (20)

comment:1 by jackburton, 17 years ago

I'll have a look.

comment:2 by jackburton, 17 years ago

I added a printf() in TermView::KeyDown(), and on CTRL-d, I get "4", the correct ASCII value for EOT, which is the default value for EOF. Should I enable debugging in ttys to see that three charachter escape value ?

comment:3 by bonefish, 17 years ago

If you add the following in master_write() (src/add-ons/kernel/drivers/tty/master.cpp):

dprintf("master_write(%p, %p, %lu)\n", cookie, buffer, *_length);
for (size_t i = 0; i < *_length; i++) {
dprintf("  %d", ((const char*)buffer)[i]);
}
dprintf("\n");

you'll see that "27 91 91" is written to the master end of the tty when Ctrl-D is pressed. If the Terminal receives the correct char from the app server, it apparently translates it before writing to the tty.

comment:4 by jackburton, 17 years ago

Ok, I found the problem. CTRL-D is 4, which is exactly the enum for B_END. Since B_END is handled in a special way in TermView::KeyDown(), we get that three character sequence. I wonder how I fix this...

in reply to:  4 ; comment:5 by jackburton, 17 years ago

Replying to jackburton:

Ok, I found the problem. CTRL-D is 4, which is exactly the enum for B_END. Since B_END is handled in a special way in TermView::KeyDown(), we get that three character sequence. I wonder how I fix this...

Oh yeah. Now I see why there was that (supposedly) weird code in TermView::Keydown() (which I removed). Check hrev21557 for example. I'll reintroduce that code. This should fix the problem.

in reply to:  5 ; comment:6 by korli, 17 years ago

Replying to jackburton:

Oh yeah. Now I see why there was that (supposedly) weird code in TermView::Keydown() (which I removed). Check hrev21557 for example. I'll reintroduce that code. This should fix the problem.

bytes shouldn't be checked for B_END and others, keycode should be. The first one is generated from the keycode based on the keymap.

in reply to:  6 ; comment:7 by jackburton, 17 years ago

Replying to korli:

bytes shouldn't be checked for B_END and others, keycode should be. The first one is generated from the keycode based on the keymap.

Do you mean the int32 "key" field in the current message ? Or you mean the other way round ?

I'm confused.

comment:8 by bonefish, 17 years ago

You could get CurrentMessage() from the window and check the "raw_key" field. It should contain a "d", if indeed Ctrl=D has been pressed.

in reply to:  7 ; comment:9 by korli, 17 years ago

bytes shouldn't be checked for B_END and others, keycode should be. The first one is generated from the keycode based on the keymap.

Do you mean the int32 "key" field in the current message ? Or you mean the other way round ?

Sorry I meant "key" is the keycode and should be checked for B_END and co.

in reply to:  9 ; comment:10 by jackburton, 17 years ago

Replying to korli:

Sorry I meant "key" is the keycode and should be checked for B_END and co.

So BTextView::KeyDown() is wrong too ?

in reply to:  10 comment:11 by jackburton, 17 years ago

Replying to jackburton:

Replying to korli:

Sorry I meant "key" is the keycode and should be checked for B_END and co.

So BTextView::KeyDown() is wrong too ?

Replying to myself: http://www.beunited.org/bebook/The%20Interface%20Kit/ViewHooks.html#KeyDown()

"Single-byte characters can be tested against ASCII codes and these constants:"

B_BACKSPACE B_LEFT_ARROW B_INSERT

etc. etc.

I'm still confused...

in reply to:  10 comment:12 by korli, 17 years ago

Replying to jackburton:

Replying to korli:

Sorry I meant "key" is the keycode and should be checked for B_END and co.

So BTextView::KeyDown() is wrong too ?

Checking, and the keymap translates to B_* so it is OK to check bytes ... Sorry for the confusion :)

in reply to:  8 ; comment:13 by jackburton, 17 years ago

Replying to bonefish:

You could get CurrentMessage() from the window and check the "raw_key" field. It should contain a "d", if indeed Ctrl=D has been pressed.

Yeah, but then I should do that in any case, independently of the data I get from the "bytes" argument ?

in reply to:  13 ; comment:14 by bonefish, 17 years ago

Replying to jackburton:

Replying to bonefish:

You could get CurrentMessage() from the window and check the "raw_key" field. It should contain a "d", if indeed Ctrl=D has been pressed.

Yeah, but then I should do that in any case, independently of the data I get from the "bytes" argument ?

There are several B_* constants that hide actual characters. I suppose it would make sense to that special handling for all of those.

in reply to:  14 comment:15 by jackburton, 17 years ago

Replying to bonefish:

There are several B_* constants that hide actual characters. I suppose it would make sense to that special handling for all of those.

Ok. That's pretty much what the code did before. I'll revert it, then I'll try to see if I can clean it up. Never touch something you don't fully understand. :/

comment:16 by jackburton, 17 years ago

Status: newassigned

comment:17 by jackburton, 17 years ago

Should be fixed in hrev21751. Can you confirm ?

comment:18 by axeld, 17 years ago

Ingo just confirms that it is working now.

BTW I"key" is still wrong, and must actually be "raw_key" (from the message).

The "key" (or keycode) is indeed the physical key pressed on the keyboard - but that's not really what you want here. What you actually want is the key that says 'd' - and that's exactly what "raw_key" is about (it gives you the difference between the "End" key and the "d" in this case).

So I'm leaving this bug open for now for your measurement :-)

in reply to:  18 comment:19 by jackburton, 17 years ago

Replying to axeld:

Ingo just confirms that it is working now.

BTW I"key" is still wrong, and must actually be "raw_key" (from the message).

The "key" (or keycode) is indeed the physical key pressed on the keyboard - but that's not really what you want here. What you actually want is the key that says 'd' - and that's exactly what "raw_key" is about (it gives you the difference between the "End" key and the "d" in this case).

So I'm leaving this bug open for now for your measurement :-)

Ok. Thank you all for the help.

comment:20 by jackburton, 17 years ago

Resolution: fixed
Status: assignedclosed

Original bug is fixed, and in hrev22512 I also check against "raw_char" instead of using "key". Seems to work fine. Closing.

Note: See TracTickets for help on using tickets.