Skip to content
This repository has been archived by the owner on Apr 19, 2024. It is now read-only.

Commit

Permalink
url: mark everything with tray-url regions
Browse files Browse the repository at this point in the history
  • Loading branch information
FauxFaux committed May 22, 2018
1 parent fce4a8f commit a2b6854
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 82 deletions.
11 changes: 6 additions & 5 deletions putty.h
Expand Up @@ -138,7 +138,7 @@ typedef struct terminal_tag Terminal;
#define ATTR_DEFBG (258 << ATTR_BGSHIFT)
#define ATTR_DEFAULT (ATTR_DEFFG | ATTR_DEFBG)


// region tray-url
#define CHAR_MASK 0x000000FFUL

enum
Expand All @@ -154,7 +154,7 @@ enum
URLHACK_REGEX_CLASSIC = 1,
URLHACK_REGEX_LIBERAL,
};

// endregion

struct sesslist {
int nsessions;
Expand Down Expand Up @@ -769,9 +769,9 @@ void palette_set(void *frontend, int, int, int, int);
void palette_reset(void *frontend);
void write_aclip(void *frontend, char *, int, int);


// region tray-url
void write_clip(Terminal *term, void *frontend, wchar_t *, int *, int, int);

// endregion

void get_clip(void *frontend, wchar_t **, int *);
void optimised_move(void *frontend, int, int, int);
Expand Down Expand Up @@ -1080,13 +1080,14 @@ void cleanup_exit(int);
X(INT, NONE, shadowboldoffset) \
X(INT, NONE, crhaslf) \
X(STR, NONE, winclass) \
/* region tray-url */ \
X(INT, NONE, url_ctrl_click) \
X(INT, NONE, url_underline) \
X(INT, NONE, url_defbrowser) \
X(INT, NONE, url_defregex) \
X(FILENAME, NONE, url_browser) \
X(STR, NONE, url_regex)

// endregion

/* Now define the actual enum of option keywords using that macro. */
#define CONF_ENUM_DEF(valtype, keytype, keyword) CONF_##keyword,
Expand Down
12 changes: 6 additions & 6 deletions settings.c
Expand Up @@ -58,7 +58,7 @@ const char *const ttymodes[] = {
"ECHOKE", "PENDIN", "OPOST", "OLCUC", "ONLCR", "OCRNL", "ONOCR",
"ONLRET", "CS7", "CS8", "PARENB", "PARODD", NULL};


// region tray-url
const char *urlhack_default_regex =
"("
"(((https?|ftp):\\/\\/)|www\\.)"
Expand Down Expand Up @@ -110,7 +110,7 @@ const char *urlhack_liberal_regex =
"([a-zA-Z]+://|[wW][wW][wW]\\.|spotify:|telnet:)"
"[^ '\")>]+"
")";

// endregion

/*
* Convenience functions to access the backends[] array
Expand Down Expand Up @@ -667,7 +667,7 @@ void save_open_settings(void *sesskey, Conf *conf)
write_setting_i(
sesskey, "NetHackKeypad", conf_get_int(conf, CONF_nethack_keypad));


// region tray-url
write_setting_i(
sesskey, "HyperlinkUnderline", conf_get_int(conf, CONF_url_underline));
write_setting_i(sesskey,
Expand All @@ -684,7 +684,7 @@ void save_open_settings(void *sesskey, Conf *conf)
write_setting_s(sesskey,
"HyperlinkRegularExpression",
conf_get_str(conf, CONF_url_regex));

// endregion

write_setting_i(sesskey, "AltF4", conf_get_int(conf, CONF_alt_f4));
write_setting_i(sesskey, "AltSpace", conf_get_int(conf, CONF_alt_space));
Expand Down Expand Up @@ -1161,7 +1161,7 @@ void load_open_settings(void *sesskey, Conf *conf)
gppi(sesskey, "ApplicationKeypad", 0, conf, CONF_app_keypad);
gppi(sesskey, "NetHackKeypad", 0, conf, CONF_nethack_keypad);


// region tray-url
gppi(sesskey, "HyperlinkUnderline", 1, conf, CONF_url_underline);
gppi(sesskey, "HyperlinkUseCtrlClick", 0, conf, CONF_url_ctrl_click);
gppi(sesskey, "HyperlinkBrowserUseDefault", 1, conf, CONF_url_defbrowser);
Expand All @@ -1176,7 +1176,7 @@ void load_open_settings(void *sesskey, Conf *conf)
urlhack_default_regex,
conf,
CONF_url_regex);

// endregion

gppi(sesskey, "AltF4", 1, conf, CONF_alt_f4);
gppi(sesskey, "AltSpace", 0, conf, CONF_alt_space);
Expand Down
62 changes: 37 additions & 25 deletions terminal.c
Expand Up @@ -12,9 +12,9 @@
#include "putty.h"
#include "terminal.h"


// region tray-url
#include "urlhack.h"

// endregion

#define poslt(p1, p2) ((p1).y < (p2).y || ((p1).y == (p2).y && (p1).x < (p2).x))
#define posle(p1, p2) \
Expand Down Expand Up @@ -1679,9 +1679,9 @@ Terminal *term_init(Conf *myconf, struct unicode_data *ucsdata, void *frontend)
term->basic_erase_char.cc_next = 0;
term->erase_char = term->basic_erase_char;

//region tray-url
// region tray-url
term->url_update = TRUE;
//endregion
// endregion

return term;
}
Expand Down Expand Up @@ -4967,20 +4967,20 @@ static void do_paint(Terminal *term, Context ctx, int may_optimise)
#endif /* OPTIMISE_SCROLL */
termchar *newline;


// region tray-url
int urlhack_underline_always =
(conf_get_int(term->conf, CONF_url_underline) ==
URLHACK_UNDERLINE_ALWAYS);

int urlhack_underline =
conf_get_int(term->conf, CONF_url_underline) ==
URLHACK_UNDERLINE_ALWAYS ||
(conf_get_int(term->conf, CONF_url_underline) ==
URLHACK_UNDERLINE_HOVER &&
(!conf_get_int(term->conf, CONF_url_ctrl_click) ||
urlhack_is_ctrl_pressed()))
? 1
: 0;
URLHACK_UNDERLINE_ALWAYS ||
(conf_get_int(term->conf, CONF_url_underline) ==
URLHACK_UNDERLINE_HOVER &&
(!conf_get_int(term->conf, CONF_url_ctrl_click) ||
urlhack_is_ctrl_pressed()))
? 1
: 0;
int urlhack_is_link = 0, urlhack_hover_current = 0;
int urlhack_toggle_x = term->cols, urlhack_toggle_y = term->rows;
unsigned int urlhack_region_index = 0;
Expand Down Expand Up @@ -5011,7 +5011,7 @@ static void do_paint(Terminal *term, Context ctx, int may_optimise)
else
urlhack_hover_current = urlhack_is_in_this_link_region(
urlhack_region, urlhack_mouse_old_x, urlhack_mouse_old_y);

// endregion

chlen = 1024;
ch = snewn(chlen, wchar_t);
Expand Down Expand Up @@ -5164,7 +5164,7 @@ static void do_paint(Terminal *term, Context ctx, int may_optimise)
if (j < term->cols - 1 && d[1].chr == UCSWIDE)
tattr |= ATTR_WIDE;


// region tray-url
// Hyperlink stuff: Underline link regions if user has configured us so
if (urlhack_underline) {
if (j == urlhack_toggle_x && i == urlhack_toggle_y) {
Expand Down Expand Up @@ -5202,6 +5202,7 @@ static void do_paint(Terminal *term, Context ctx, int may_optimise)
term->url_update = FALSE;
}

// endregion

/* Video reversing things */
if (term->selstate == DRAGGING || term->selstate == SELECTED) {
Expand Down Expand Up @@ -5511,9 +5512,9 @@ void term_scroll(Terminal *term, int rel, int where)
int shift;
#endif /* OPTIMISE_SCROLL */

//region tray-url
// region tray-url
term->url_update = TRUE;
//endregion
// endregion

term->disptop = (rel < 0 ? 0 : rel > 0 ? sbtop : term->disptop) + where;
if (term->disptop < sbtop)
Expand Down Expand Up @@ -5580,12 +5581,14 @@ static void clip_addchar(clip_workbuf *b, wchar_t chr, int attr)
b->bufpos++;
}

// region tray-url
void clipme(Terminal *term,
pos top,
pos bottom,
int rect,
int desel,
void (*output)(Terminal *, void *, wchar_t *, int *, int, int))
// endregion
{
clip_workbuf buf;
int old_top_x;
Expand Down Expand Up @@ -5741,7 +5744,11 @@ void clipme(Terminal *term,
clip_addchar(&buf, 0, 0);
#endif
/* Finally, transfer all that to the clipboard. */

// region tray-url
output(term, term->frontend, buf.textbuf, buf.attrbuf, buf.bufpos, desel);
// endregion

sfree(buf.textbuf);
sfree(buf.attrbuf);
}
Expand All @@ -5755,7 +5762,10 @@ void term_copyall(Terminal *term)
top.x = 0;
bottom.y = find_last_nonempty_line(term, screen);
bottom.x = term->cols;

// region tray-url
clipme(term, top, bottom, 0, TRUE, write_clip);
// endregion
}

/*
Expand Down Expand Up @@ -6043,7 +6053,7 @@ void term_do_paste(Terminal *term)
queue_toplevel_callback(term_paste_callback, term);
}


// region tray-url
void urlhack_launch_url_helper(Terminal *term,
void *frontend,
wchar_t *data,
Expand All @@ -6052,11 +6062,11 @@ void urlhack_launch_url_helper(Terminal *term,
int must_deselect)
{
urlhack_launch_url(!conf_get_int(term->conf, CONF_url_defbrowser)
? conf_get_filename(term->conf, CONF_url_browser)->path
: NULL,
? conf_get_filename(term->conf, CONF_url_browser)->path
: NULL,
data);
}

// endregion

void term_mouse(Terminal *term,
Mouse_Button braw,
Expand Down Expand Up @@ -6227,9 +6237,9 @@ void term_mouse(Terminal *term,
term->selanchor = selpoint;
term->selmode = SM_CHAR;


// region tray-url
} else if (bcooked == MBT_SELECT && a == MA_RELEASE &&
term->selstate == ABOUT_TO) {
term->selstate == ABOUT_TO) {
deselect(term);
term->selstate = NO_SELECTION;

Expand All @@ -6247,7 +6257,7 @@ void term_mouse(Terminal *term,
clipme(term, top, bottom, 0, 0, urlhack_launch_url_helper);
sfree(linkbuf);
}

// endregion

} else if (bcooked == MBT_SELECT && (a == MA_2CLK || a == MA_3CLK)) {
deselect(term);
Expand Down Expand Up @@ -6342,12 +6352,14 @@ void term_mouse(Terminal *term,
* We've completed a selection. We now transfer the
* data to the clipboard.
*/
// region tray-url
clipme(term,
term->selstart,
term->selend,
(term->seltype == RECTANGULAR),
FALSE,
write_clip);
// endregion
term->selstate = SELECTED;
} else
term->selstate = NO_SELECTION;
Expand Down Expand Up @@ -6459,9 +6471,9 @@ int term_data(Terminal *term, int is_stderr, const char *data, int len)
term_out(term);
term->in_term_out = FALSE;

//region tray-url
// region tray-url
term->url_update = TRUE;
//endregion
// endregion
}

/*
Expand Down
7 changes: 7 additions & 0 deletions terminal.h
Expand Up @@ -20,6 +20,7 @@ typedef struct {
int y, x;
} pos;

// region tray-url

void clipme(Terminal *term,
pos top,
Expand All @@ -35,6 +36,7 @@ void urlhack_launch_url_helper(Terminal *term,
int len,
int must_deselect);

// endregion

#ifdef OPTIMISE_SCROLL
struct scrollregion {
Expand Down Expand Up @@ -351,7 +353,12 @@ struct terminal_tag {
int scroll_on_disp;
int scroll_on_key;
int xterm_256_colour;

// region tray-url

int url_update;

// endregion
};

#define in_utf(term) ((term)->utf || (term)->ucsdata->line_codepage == CP_UTF8)
Expand Down
9 changes: 4 additions & 5 deletions unix/gtkmain.c
Expand Up @@ -36,10 +36,9 @@
#include "gtkfont.h"
#include "gtkmisc.h"


// region tray-url
#include "urlhack.h"


// endregion

#ifndef NOT_X_WINDOWS
#include <gdk/gdkx.h>
Expand Down Expand Up @@ -597,9 +596,9 @@ int main(int argc, char **argv)

gtkcomm_setup();


// region tray-url
urlhack_init();

// endregion

/*
* Block SIGPIPE: if we attempt Duplicate Session or similar and
Expand Down
2 changes: 2 additions & 0 deletions unix/gtkwin.c
Expand Up @@ -2655,12 +2655,14 @@ static char *retrieve_cutbuffer(int *nbytes)
#endif
}

// region tray-url
void write_clip(Terminal *term,
void *frontend,
wchar_t *data,
int *attr,
int len,
int must_deselect)
// endregion
{
struct gui_data *inst = (struct gui_data *)frontend;
if (inst->pasteout_data)
Expand Down
6 changes: 4 additions & 2 deletions urlhack.cpp
Expand Up @@ -8,7 +8,8 @@ extern "C" {
#include "terminal.h"

// TODO: linking fails on mingw if putty.h is included in urlhack.h,
// TODO: so forward-declare (inside extern "C") this here, after `Terminal` is defined.
// TODO: so forward-declare (inside extern "C") this here, after `Terminal` is
// defined.
void urlhack_for_every_link(
Terminal *term,
void (*output)(Terminal *, void *, wchar_t *, int *, int, int));
Expand Down Expand Up @@ -234,7 +235,8 @@ void urlhack_go_find_me_some_hyperlinks(int screen_width)
text_pos = window_text;

// Comedy bad attempt at iterators from the C++ committee here?
auto begin = std::cregex_iterator(window_text, window_text + window_text_len, urlhack_rx);
auto begin = std::cregex_iterator(
window_text, window_text + window_text_len, urlhack_rx);
auto end = std::cregex_iterator();

for (std::cregex_iterator it = begin; it != end; ++it) {
Expand Down

0 comments on commit a2b6854

Please sign in to comment.