Skip to content

Commit 27bbe44

Browse files
committed
--view=+COMMAND to wait for key press after COMMAND terminated, e.g. --view=+file to display file info with the `file` command and wait for a key press; Wikipedia page "ANSI escape code" mentions that ESC ] P n rr gg bb may hang a terminal: TUI is updated to only support OSC code ESC ] 8 to display hyperlinks with option --hyperlink
1 parent 24b5a4f commit 27bbe44

3 files changed

Lines changed: 15 additions & 17 deletions

File tree

src/query.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2370,13 +2370,14 @@ void Query::view()
23702370
}
23712371

23722372
// if no viewer, then give up
2373-
if (flag_view == NULL || *flag_view == '\0')
2373+
if (flag_view == NULL || *flag_view == '\0' || (*flag_view == '+' && flag_view[1] == '\0'))
23742374
{
23752375
Screen::alert();
23762376
return;
23772377
}
23782378

2379-
std::string command(flag_view);
2379+
bool keypress = (*flag_view == '+');
2380+
std::string command(flag_view + keypress);
23802381
int ref = select_ >= 0 ? select_ : row_;
23812382
size_t line_number = 0;
23822383

@@ -2518,8 +2519,6 @@ void Query::view()
25182519
bool changed = false;
25192520

25202521
// track elapsed time: if the command terminates very quickly within 500ms, then let the user press a key
2521-
reflex::timer_type et;
2522-
reflex::timer_start(et);
25232522

25242523
if (flag_stdin && filename == flag_label)
25252524
{
@@ -2637,12 +2636,10 @@ void Query::view()
26372636

26382637
if (ok)
26392638
{
2640-
float ms = reflex::timer_elapsed(et);
2641-
26422639
#ifdef OS_WIN
2643-
if (ms < 500 || strcmp(flag_view, "more") == 0)
2640+
if (keypress || strcmp(flag_view, "more") == 0)
26442641
#else
2645-
if (ms < 500)
2642+
if (keypress)
26462643
#endif
26472644
{
26482645
// command terminated very quickly within 500ms

src/screen.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -567,11 +567,11 @@ int Screen::put(int row, int col, const char *text, size_t size, int skip, int w
567567
break;
568568

569569
default:
570-
if (*text == '\033' && text + 1 < end && (text[1] == '[' || text[1] == ']'))
570+
if (*text == '\033' && text + 2 < end && (text[1] == '[' || (text[1] == ']' && text[2] == '8')))
571571
{
572-
if (text + 1 < end && text[1] == '[')
572+
if (text[1] == '[')
573573
{
574-
// CSI \e[... sequence
574+
// ANSI CSI \e[... sequence
575575
next = text;
576576
next += 2;
577577
while (next < end && (*next < 0x40 || *next > 0x7e))
@@ -586,7 +586,7 @@ int Screen::put(int row, int col, const char *text, size_t size, int skip, int w
586586
}
587587
else
588588
{
589-
// OSC \e]...BEL|ST sequence
589+
// ANSI OSC \e]8...BEL|ST sequence (hyperlink)
590590
next = text;
591591
next += 2;
592592
while (next < end && *next != '\a' && (*next != '\033' || (next + 1 < end && next[1] != '\\')))
@@ -703,11 +703,11 @@ int Screen::put(int row, int col, const char *text, size_t size, int skip, int w
703703
break;
704704

705705
default:
706-
if (*ptr == '\033' && ptr + 1 < end && (ptr[1] == '[' || ptr[1] == ']'))
706+
if (*ptr == '\033' && ptr + 2 < end && (ptr[1] == '[' || (ptr[1] == ']' && ptr[2] == '8')))
707707
{
708708
if (ptr[1] == '[')
709709
{
710-
// CSI \e[... sequence
710+
// ANSI CSI \e[... sequence
711711
if (mono)
712712
put(text, ptr - text);
713713
ptr += 2;
@@ -728,7 +728,7 @@ int Screen::put(int row, int col, const char *text, size_t size, int skip, int w
728728
}
729729
else
730730
{
731-
// OSC \e]...BEL|ST sequence
731+
// ANSI OSC \e]8...BEL|ST sequence (hyperlink)
732732
if (mono)
733733
put(text, ptr - text);
734734
ptr += 2;

src/ugrep.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14689,8 +14689,9 @@ void help(std::ostream& out)
1468914689
-v, --invert-match\n\
1469014690
Selected lines are those not matching any of the specified\n\
1469114691
patterns.\n\
14692-
--view[=COMMAND]\n\
14693-
Use COMMAND to view/edit a file in -Q query TUI by pressing CTRL-Y.\n\
14692+
--view[=[+]COMMAND]\n\
14693+
Use COMMAND to view/edit a file in -Q query TUI by pressing CTRL-Y,\n\
14694+
+COMMAND waits for a key press after COMMAND terminated.\n\
1469414695
-W, --with-hex\n\
1469514696
Output binary matches in hexadecimal, leaving text matches alone.\n\
1469614697
This option is equivalent to the --binary-files=with-hex option.\n\

0 commit comments

Comments
 (0)