Skip to content

Commit 3cbcf8d

Browse files
committed
squash! Revert "Make requested console reports work"
This is the proper fix for git-for-windows/git#711 It is actually a real bug fix that will be submitted to Cygwin momentarily. Revert "Revert "Make requested console reports work"" This reverts commit a08308b.
1 parent a08308b commit 3cbcf8d

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

winsup/cygwin/fhandler.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,8 @@ class dev_console
13521352
bool ext_mouse_mode15;
13531353
bool use_focus;
13541354
bool raw_win32_keyboard_mode;
1355+
char cons_rabuf[40]; // cannot get longer than char buf[40] in char_command
1356+
char *cons_rapoi;
13551357

13561358
inline UINT get_console_cp ();
13571359
DWORD con_to_str (char *d, int dlen, WCHAR w);
@@ -1449,6 +1451,11 @@ class fhandler_console: public fhandler_termios
14491451
int init (HANDLE, DWORD, mode_t);
14501452
bool mouse_aware (MOUSE_EVENT_RECORD& mouse_event);
14511453
bool focus_aware () {return shared_console_info->con.use_focus;}
1454+
bool get_cons_readahead_valid ()
1455+
{
1456+
return shared_console_info->con.cons_rapoi != NULL &&
1457+
*shared_console_info->con.cons_rapoi;
1458+
}
14521459

14531460
select_record *select_read (select_stuff *);
14541461
select_record *select_write (select_stuff *);

winsup/cygwin/fhandler_console.cc

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ fhandler_console::setup ()
194194
con.meta_mask |= RIGHT_ALT_PRESSED;
195195
con.set_default_attr ();
196196
con.backspace_keycode = CERASE;
197+
con.cons_rapoi = NULL;
197198
shared_console_info->tty_min_state.is_console = true;
198199
}
199200
}
@@ -308,6 +309,14 @@ fhandler_console::read (void *pv, size_t& buflen)
308309
int ch;
309310
set_input_state ();
310311

312+
/* Check console read-ahead buffer filled from terminal requests */
313+
if (con.cons_rapoi && *con.cons_rapoi)
314+
{
315+
*buf = *con.cons_rapoi++;
316+
buflen = 1;
317+
return;
318+
}
319+
311320
int copied_chars = get_readahead_into_buffer (buf, buflen);
312321

313322
if (copied_chars)
@@ -1895,8 +1904,11 @@ fhandler_console::char_command (char c)
18951904
strcpy (buf, "\033[?6c");
18961905
/* The generated report needs to be injected for read-ahead into the
18971906
fhandler_console object associated with standard input.
1898-
The current call does not work. */
1899-
puts_readahead (buf);
1907+
So puts_readahead does not work.
1908+
Use a common console read-ahead buffer instead. */
1909+
con.cons_rapoi = NULL;
1910+
strcpy (con.cons_rabuf, buf);
1911+
con.cons_rapoi = con.cons_rabuf;
19001912
break;
19011913
case 'n':
19021914
switch (con.args[0])
@@ -1906,9 +1918,11 @@ fhandler_console::char_command (char c)
19061918
y -= con.b.srWindow.Top;
19071919
/* x -= con.b.srWindow.Left; // not available yet */
19081920
__small_sprintf (buf, "\033[%d;%dR", y + 1, x + 1);
1909-
puts_readahead (buf);
1921+
con.cons_rapoi = NULL;
1922+
strcpy (con.cons_rabuf, buf);
1923+
con.cons_rapoi = con.cons_rabuf;
19101924
break;
1911-
default:
1925+
default:
19121926
goto bad_escape;
19131927
}
19141928
break;

winsup/cygwin/select.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,12 @@ peek_console (select_record *me, bool)
844844
if (!me->read_selected)
845845
return me->write_ready;
846846

847+
if (fh->get_cons_readahead_valid ())
848+
{
849+
select_printf ("cons_readahead");
850+
return me->read_ready = true;
851+
}
852+
847853
if (fh->get_readahead_valid ())
848854
{
849855
select_printf ("readahead");

0 commit comments

Comments
 (0)