Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ^O series to handle OSC-8 id= search and URIs #251

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd.h
Expand Up @@ -77,6 +77,11 @@
#define A_X116MOUSE_IN 68
#define A_PSHELL 69
#define A_CLR_SEARCH 70
#define A_OSC8_ID_SEARCH 84
#define A_OSC8_ID_SEARCH_LOAD 85
#define A_OSC8_GOTO_P 86
#define A_OSC8_GOTO_N 87
#define A_OSC8_OPEN 88

/* These values must not conflict with any A_* or EC_* value. */
#define A_INVALID 100
Expand Down
32 changes: 32 additions & 0 deletions command.c
Expand Up @@ -332,6 +332,12 @@ static void exec_mca(void)
if (done_msg != NULL)
error(done_msg, NULL_PARG);
break; }
#endif
#if OSC8_SEARCH
case A_OSC8_ID_SEARCH:
case A_OSC8_ID_SEARCH_LOAD:
osc8_id_search(cbuf, mca == A_OSC8_ID_SEARCH);
break;
#endif
}
}
Expand Down Expand Up @@ -2156,6 +2162,32 @@ public void commands(void)
case A_NOACTION:
break;

#if !OSC8_SEARCH
case A_OSC8_ID_SEARCH:
case A_OSC8_ID_SEARCH_LOAD:
case A_OSC8_GOTO_P:
case A_OSC8_GOTO_N:
case A_OSC8_OPEN:
error("Command not available", NULL_PARG);
break;
#else
case A_OSC8_ID_SEARCH:
case A_OSC8_ID_SEARCH_LOAD:
start_mca(action, "[OSC 8 id]:",
(void *)NULL, CF_QUIT_ON_ERASE);
c = getcc();
goto again;
case A_OSC8_GOTO_P:
osc8_goto(SRCH_BACK);
break;
case A_OSC8_GOTO_N:
osc8_goto(SRCH_FORW);
break;
case A_OSC8_OPEN:
osc8_open();
break;
#endif /* OSC8_SEARCH */

default:
bell();
break;
Expand Down
5 changes: 5 additions & 0 deletions configure.ac
Expand Up @@ -560,6 +560,11 @@ AH_TOP([
*/
#define LOGFILE (!SECURE)

/*
* OSC8_SEARCH is 1 if you wish to support searching/following OSC8 references.
*/
#define OSC8_SEARCH (!SECURE)

/*
* GNU_OPTIONS is 1 if you wish to support the GNU-style command
* line options --help and --version.
Expand Down
7 changes: 6 additions & 1 deletion decode.c
Expand Up @@ -179,7 +179,12 @@ static unsigned char cmdtable[] =
'Q',0, A_QUIT,
':','q',0, A_QUIT,
':','Q',0, A_QUIT,
'Z','Z',0, A_QUIT
'Z','Z',0, A_QUIT,
CONTROL('O'),CONTROL('I'),0, A_OSC8_ID_SEARCH,
CONTROL('O'),CONTROL('L'),0, A_OSC8_ID_SEARCH_LOAD,
CONTROL('O'),CONTROL('N'),0, A_OSC8_GOTO_N,
CONTROL('O'),CONTROL('P'),0, A_OSC8_GOTO_P,
CONTROL('O'),CONTROL('O'),0, A_OSC8_OPEN
};

static unsigned char edittable[] =
Expand Down
5 changes: 5 additions & 0 deletions defines.ds
Expand Up @@ -97,6 +97,11 @@
*/
#define LOGFILE (!SECURE)

/*
* OSC8_SEARCH is 1 if you wish to support searching/following OSC8 references.
*/
#define OSC8_SEARCH (!SECURE)

/*
* GNU_OPTIONS is 1 if you wish to support the GNU-style command
* line options --help and --version.
Expand Down
5 changes: 5 additions & 0 deletions defines.o2
Expand Up @@ -90,6 +90,11 @@
*/
#define LOGFILE (!SECURE)

/*
* OSC8_SEARCH is 1 if you wish to support searching/following OSC8 references.
*/
#define OSC8_SEARCH (!SECURE)

/*
* GNU_OPTIONS is 1 if you wish to support the GNU-style command
* line options --help and --version.
Expand Down
5 changes: 5 additions & 0 deletions defines.o9
Expand Up @@ -89,6 +89,11 @@
*/
#define LOGFILE (!SECURE)

/*
* OSC8_SEARCH is 1 if you wish to support searching/following OSC8 references.
*/
#define OSC8_SEARCH (!SECURE)

/*
* GNU_OPTIONS is 1 if you wish to support the GNU-style command
* line options --help and --version.
Expand Down
5 changes: 5 additions & 0 deletions defines.wn
Expand Up @@ -90,6 +90,11 @@
*/
#define LOGFILE (!SECURE)

/*
* OSC8_SEARCH is 1 if you wish to support searching/following OSC8 references.
*/
#define OSC8_SEARCH (!SECURE)

/*
* GNU_OPTIONS is 1 if you wish to support the GNU-style command
* line options --help and --version.
Expand Down
12 changes: 11 additions & 1 deletion less.h
Expand Up @@ -347,6 +347,14 @@ struct wchar_range_table
unsigned int count;
};

/* State while processing an ANSI escape sequence */
struct ansi_state
{
int hindex; /* Index into hyperlink prefix */
int hlink; /* Processing hyperlink address? */
int prev_esc; /* Prev char was ESC (to detect ESC-\ seq) */
};

#if HAVE_POLL
typedef short POLL_EVENTS;
#endif
Expand Down Expand Up @@ -395,6 +403,9 @@ typedef short POLL_EVENTS;
#define SRCH_SUBSEARCH(i) (1 << (16+(i))) /* Search for subpattern */
/* {{ Depends on NUM_SEARCH_COLORS==5 }} */
#define SRCH_SUBSEARCH_ALL (SRCH_SUBSEARCH(1)|SRCH_SUBSEARCH(2)|SRCH_SUBSEARCH(3)|SRCH_SUBSEARCH(4)|SRCH_SUBSEARCH(5))
#if OSC8_SEARCH
# define SRCH_OSC8 (1 << 22) /* OSC 8 id= search */
#endif

#define SRCH_REVERSE(t) (((t) & SRCH_FORW) ? \
(((t) & ~SRCH_FORW) | SRCH_BACK) : \
Expand Down Expand Up @@ -625,7 +636,6 @@ typedef enum {
struct mlist;
struct loption;
struct hilite_tree;
struct ansi_state;
#include "pattern.h"
#include "xbuf.h"
#include "funcs.h"
Expand Down
5 changes: 5 additions & 0 deletions less.hlp
Expand Up @@ -75,6 +75,11 @@

m_<_l_e_t_t_e_r_> Mark the current top line with <letter>.
M_<_l_e_t_t_e_r_> Mark the current bottom line with <letter>.
^O^I_<_i_d_> Search for an OSC 8 <id> in the file.
^O^P Go to previous OSC 8 link.
^O^N Go to next OSC 8 link.
^O^O Open current OSC 8 link with LESSOSC8OPEN.
^O^L_<_i_d_> Combined ^O^I plus ^O^O.
'_<_l_e_t_t_e_r_> Go to a previously marked position.
'' Go to the previous position.
^X^X Same as '.
Expand Down
16 changes: 16 additions & 0 deletions less.nro.VER
Expand Up @@ -105,6 +105,17 @@ and LEFTARROW commands.
Scroll horizontally right to show the end of the longest displayed line.
.IP "ESC-{ or \(haLEFTARROW"
Scroll horizontally left back to the first column.
.IP "^O^I"
Search for an OSC 8 ID in the file.
.IP "^O^P"
Go to the previous OSC 8 link.
.IP "^O^N"
Go to the next OSC 8 link.
.IP "^O^O"
Open the current OSC 8 link with the command specified
in the LESSOSC8OPEN environment variable.
.IP "^O^L"
Combined ^O^I plus ^O^O.
.IP "r or \(haR or \(haL"
Repaint the screen.
.IP R
Expand Down Expand Up @@ -2316,6 +2327,11 @@ Enables individual features which are normally disabled by LESSSECURE.
See discussion under SECURITY.
.IP LESSSEPARATOR
String to be appended to a directory name in filename completion.
.IP LESSOSC8OPEN
Command line to invoke when following OSC 8 links.
Without this being set only
.IR man (1)
references like "man:ls(1)" can be opened.
.IP LESSUTFBINFMT
Format for displaying non-printable Unicode code points.
.IP LESSUTFCHARDEF
Expand Down
5 changes: 5 additions & 0 deletions lesskey.nro.VER
Expand Up @@ -179,6 +179,11 @@ g goto-line
\ekh goto-line
< goto-line
\ee< goto-line
^O^I osc8-id-search
^O^L osc8-id-search-load
^O^N osc8-goto-next
^O^P osc8-goto-prev
^O^O osc8-open
p percent
% percent
\ee[ left-scroll
Expand Down
7 changes: 7 additions & 0 deletions lesskey_parse.c
Expand Up @@ -72,6 +72,13 @@ static constant struct lesskey_cmdname cmdnames[] =
{ "next-tag", A_NEXT_TAG },
{ "noaction", A_NOACTION },
{ "no-scroll", A_LLSHIFT },
#if OSC8_SEARCH
{ "osc8-id-search", A_OSC8_ID_SEARCH },
{ "osc8-id-search-load", A_OSC8_ID_SEARCH_LOAD },
{ "osc8-goto-next", A_OSC8_GOTO_N },
{ "osc8-goto-prev", A_OSC8_GOTO_P },
{ "osc8-open", A_OSC8_OPEN },
#endif
{ "percent", A_PERCENT },
{ "pipe", A_PIPE },
{ "prev-file", A_PREV_FILE },
Expand Down
7 changes: 0 additions & 7 deletions line.c
Expand Up @@ -135,13 +135,6 @@ static struct color_map color_map[] = {
{ AT_COLOR_SUBSEARCH(5), "Wc" },
};

/* State while processing an ANSI escape sequence */
struct ansi_state {
int hindex; /* Index into hyperlink prefix */
int hlink; /* Processing hyperlink address? */
int prev_esc; /* Prev char was ESC (to detect ESC-\ seq) */
};

/*
* Initialize from environment variables.
*/
Expand Down