1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00

Implement Richard's really clever idea about bell overload mode:

it's automatically deactivated by any keypress, so that command-line
beeps from (e.g.) filename completion don't suddenly stop occurring,
but it still provides a rapid response to an accidental spewing of a
binary to your terminal.

[originally from svn r2107]
This commit is contained in:
Simon Tatham 2002-10-20 13:23:30 +00:00
parent de8789b8f2
commit 07878d8b7c
6 changed files with 62 additions and 17 deletions

View File

@ -1,4 +1,4 @@
\versionid $Id: config.but,v 1.42 2002/09/26 18:37:33 simon Exp $
\versionid $Id: config.but,v 1.43 2002/10/20 13:23:30 simon Exp $
\C{config} Configuring PuTTY
@ -686,6 +686,11 @@ constitute an overload, how short a time period they have to arrive
in to do so, and how much silent time is required before the
overload feature will deactivate itself.
Bell overload mode is always deactivated by any keypress in the
terminal. This means it can respond to large unexpected streams of
data, but does not interfere with ordinary command-line activities
that generate beeps (such as filename completion).
\H{config-features} The Features panel
PuTTY's terminal emulation is very highly featured, and can do a lot

View File

@ -109,7 +109,6 @@ GLOBAL unsigned long vbell_startpoint;
GLOBAL int app_cursor_keys, app_keypad_keys, vt52_mode;
GLOBAL int repeat_off, cr_lf_return;
GLOBAL int seen_key_event;
GLOBAL int seen_disp_event;
GLOBAL int alt_pressed;
@ -499,6 +498,7 @@ void logfopen(void);
void logfclose(void);
void term_copyall(void);
void term_reconfig(void);
void term_seen_key_event(void);
/*
* Exports from logging.c.

View File

@ -328,10 +328,9 @@ void term_update(void)
ctx = get_ctx();
if (ctx) {
int need_sbar_update = seen_disp_event;
if ((seen_key_event && (cfg.scroll_on_key)) ||
(seen_disp_event && (cfg.scroll_on_disp))) {
if (seen_disp_event && cfg.scroll_on_disp) {
disptop = 0; /* return to main screen */
seen_disp_event = seen_key_event = 0;
seen_disp_event = 0;
need_sbar_update = TRUE;
}
if (need_sbar_update)
@ -342,6 +341,37 @@ void term_update(void)
}
}
/*
* Called from front end when a keypress occurs, to trigger
* anything magical that needs to happen in that situation.
*/
void term_seen_key_event(void)
{
/*
* On any keypress, clear the bell overload mechanism
* completely, on the grounds that large numbers of
* beeps coming from deliberate key action are likely
* to be intended (e.g. beeps from filename completion
* blocking repeatedly).
*/
beep_overloaded = FALSE;
while (beephead) {
struct beeptime *tmp = beephead;
beephead = tmp->next;
sfree(tmp);
}
beeptail = NULL;
nbeeps = 0;
/*
* Reset the scrollback on keypress, if we're doing that.
*/
if (cfg.scroll_on_key) {
disptop = 0; /* return to main screen */
seen_disp_event = 1;
}
}
/*
* Same as power_on(), but an external function.
*/
@ -3450,9 +3480,11 @@ void term_do_paste(void)
int len;
get_clip(&data, &len);
if (data) {
if (data && len > 0) {
wchar_t *p, *q;
term_seen_key_event(); /* pasted data counts */
if (paste_buffer)
sfree(paste_buffer);
paste_pos = paste_hold = paste_len = 0;

View File

@ -218,6 +218,11 @@ not drive you crazy.
The bell overload mode is activated by receiving N bells in time T;
after a further time S without any bells, overload mode will turn
itself off again.
Bell overload mode is always deactivated by any keypress in the
terminal. This means it can respond to large unexpected streams of
data, but does not interfere with ordinary command-line activities
that generate beeps (such as filename completion).
.IP "\fBpterm.BellOverloadN\fP"
This option counts the number of bell characters which will activate
bell overload if they are received within a length of time T. The

View File

@ -786,7 +786,7 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
ldisc_send(output+start, end-start, 1);
show_mouseptr(0);
seen_key_event = 1;
term_seen_key_event();
term_out();
}

View File

@ -2439,6 +2439,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
* messages. We _have_ to buffer everything
* we're sent.
*/
term_seen_key_event();
ldisc_send(buf, len, 1);
show_mouseptr(0);
}
@ -2485,8 +2486,10 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
* luni_send() covering the whole of buff. So
* instead we luni_send the characters one by one.
*/
for (i = 0; i < n; i += 2)
term_seen_key_event();
for (i = 0; i < n; i += 2) {
luni_send((unsigned short *)(buff+i), 1, 1);
}
free(buff);
}
ImmReleaseContext(hwnd, hIMC);
@ -2499,9 +2502,11 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
buf[1] = wParam;
buf[0] = wParam >> 8;
term_seen_key_event();
lpage_send(kbd_codepage, buf, 2, 1);
} else {
char c = (unsigned char) wParam;
term_seen_key_event();
lpage_send(kbd_codepage, &c, 1, 1);
}
return (0);
@ -2515,6 +2520,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
*/
{
char c = (unsigned char)wParam;
term_seen_key_event();
lpage_send(CP_ACP, &c, 1, 1);
}
return 0;
@ -3184,15 +3190,6 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam,
} else if (compose_state == 1 && wParam != VK_CONTROL)
compose_state = 0;
/*
* Record that we pressed key so the scroll window can be reset, but
* be careful to avoid Shift-UP/Down
*/
if (wParam != VK_SHIFT && wParam != VK_PRIOR && wParam != VK_NEXT &&
wParam != VK_MENU && wParam != VK_CONTROL) {
seen_key_event = 1;
}
if (compose_state > 1 && left_alt)
compose_state = 0;
@ -3769,6 +3766,7 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam,
return 0;
}
keybuf = nc;
term_seen_key_event();
luni_send(&keybuf, 1, 1);
continue;
}
@ -3779,6 +3777,7 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam,
if (alt_sum) {
if (in_utf || dbcs_screenfont) {
keybuf = alt_sum;
term_seen_key_event();
luni_send(&keybuf, 1, 1);
} else {
ch = (char) alt_sum;
@ -3791,21 +3790,25 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam,
* messages. We _have_ to buffer
* everything we're sent.
*/
term_seen_key_event();
ldisc_send(&ch, 1, 1);
}
alt_sum = 0;
} else
term_seen_key_event();
lpage_send(kbd_codepage, &ch, 1, 1);
} else {
if(capsOn && ch < 0x80) {
WCHAR cbuf[2];
cbuf[0] = 27;
cbuf[1] = xlat_uskbd2cyrllic(ch);
term_seen_key_event();
luni_send(cbuf+!left_alt, 1+!!left_alt, 1);
} else {
char cbuf[2];
cbuf[0] = '\033';
cbuf[1] = ch;
term_seen_key_event();
lpage_send(kbd_codepage, cbuf+!left_alt, 1+!!left_alt, 1);
}
}