Commit graph

42 commits

Author SHA1 Message Date
Daniel Eklöf
8365fde980
url-mode: redirect stdin/stdout/stderr to /dev/null when opening an URL
This fixex an issue where TUI programs started in the parent
terminal (when running nested terminals).
2021-02-24 21:30:58 +01:00
Daniel Eklöf
7ee5247525
url-mode: disable debug logging 2021-02-23 14:59:54 +01:00
Daniel Eklöf
11464a65de
url-mode: use the same key combo for all occurrences of an URL 2021-02-21 20:15:33 +01:00
Daniel Eklöf
2074f8b656
urls: OSC-8 URLs can now optionally be underlined outside of url-mode
This patch adds a new configuration option,
‘osc8-underline=url-mode|always’.

When set to ‘url-mode’, OSC-8 URLs are only
highlighted (i.e. underlined) in url-mode, just like auto-detected
URLs.

When set to ‘always’, they are always underlined, regardless of mode,
and regardless of their other attributes.

This is implemented by tagging collected URLs with a boolean,
instructing urls_render() and urls_reset() whether they should update
the cells’ ‘url’ attribute or not.

The OSC-8 collecter sets this based on the value of ‘osc8-underline’.

Finally, when closing an OSC-8 URL, the cells are immediately tagged
with the ‘url’ attribute if ‘osc8-underline’ is set to ‘always’.
2021-02-21 20:15:32 +01:00
Daniel Eklöf
06a9ffa763
urls: add key binding that toggles whether URLs are displayed on jump-label
By default, the URL isn’t shown on the jump-label. For auto-detect
URLs, doing so is virtually always useless, as the URL is already
visible in the grid.

For OSC-8 URLs however, the URL is often _not_ visible in the
grid. Many times, seeing the URL is still not needed (if you’re doing
‘ls --hyperlink’, you already know what the URIs are).

But it is still useful to have a way to show the URLs.

This patch adds a new key binding action that can be used in url-mode
to toggle the URL on and off in the jump label.

It is bound to ctrl+t by default.
2021-02-21 20:15:31 +01:00
Daniel Eklöf
cc43c1b704
urls: remove free-form ‘text’ member from URL struct 2021-02-21 20:15:31 +01:00
Daniel Eklöf
cf651d361f
url-mode: remove duplicate URLs
Remove URLs with the same start and end coordinates. Such duplicate
URLs can be created by emitting an OSC-8 URL with matching grid
content:

  \E]8;;http://foo\E\\http://foo\E]8;;\E\\
2021-02-21 20:15:31 +01:00
Daniel Eklöf
a99f9c9341
url-mode: activate_url(): ensure ‘scheme’, ‘host’ and ‘path’ are free:d
uri_parse() may succeed. But if the scheme isn’t “file”, or if the
hostname isn’t localhost, then we failed to free ‘scheme’, ‘host’ and
‘path’.
2021-02-21 20:15:31 +01:00
Daniel Eklöf
fb9e9513a5
url-mode: multiple URL (parts) with the same ID is assigned a single key sequence
In case an URL is split up into multiple parts, those parts are now
treated as a single URL when it comes to key assignment.

Only the *first* URL part is actually assigned a key combo. The other
parts are ignored.

We still highlight them, but for all other purposes they are ignored.
2021-02-21 20:15:29 +01:00
Daniel Eklöf
39c5057d49
url-mode: initial support for OSC-8 URLs
Things left to do: since OSC-8 URLs are stored as ranges in the
per-row ‘extra’ data member, we currently do not handle line-wrapping
URLs very well; they will be considered two separate URLs, and
assigned two different key sequences.
2021-02-21 20:14:51 +01:00
Daniel Eklöf
3339915d20
url-mode: store URL in UTF-8, not UTF-32
The only time the URL is actually in UTF-32 is when we’re collecting
it (auto-detecting it) from the grid, since cells store their
character(s) in UTF-32.

Everything *after* that prefers the URL in UTF-8. So, do the
conversion while collecting the URL.

This patch also changes the URL activation code to strip the
‘file://user@host/’ prefix from file URIs that refer to files
on the *local* computer.
2021-02-21 20:14:51 +01:00
Daniel Eklöf
9d362158e3
url-mode: convert struct wl_url to use wayl_win_subsurface_new() 2021-02-17 21:48:07 +01:00
Daniel Eklöf
c7006661f5
url-mode: use ‘jump-label-letters’ as the alphabet for key sequences
Instead of hard coding the alphabet to “sadfjklewcmpgh”, use the
letters from ‘jump-label-letters’.

Closes #355
2021-02-13 11:43:28 +01:00
Daniel Eklöf
b09606e343
url-mode: do case insensitive comparison when matching key sequence 2021-02-13 11:41:04 +01:00
Daniel Eklöf
79e054faff
Merge branch 'refactor-key-bindings' 2021-02-08 18:57:17 +01:00
Daniel Eklöf
1710c1452a
url-mode: ‘%’ is a valid URI character (but don’t allow it at the end)
Closes #338
2021-02-08 16:02:07 +01:00
Daniel Eklöf
4bad85b593
misc: when free:ing tll lists, prefer tll_remove() over tll_free()
In many places we have the following pattern:

  tll_foreach(list, it)
     free(it->item.thing);
  tll_free(list);

Since all tll functions are macros, and thus inlined, and since
tll_free in itself expands to a tll_foreach(), the above pattern
expands to more native code than necessary.

This is somewhat smaller:

  tll_foreach(list, it) {
      free(it->item.thing);
      tll_remove(list, it);
  }
2021-02-08 10:09:59 +01:00
Daniel Eklöf
03bac9dada
key-bindings: refactor: use a single type for all key bindings
Up until now, the various key binding modes (“normal”, “search” and
“url”) have used their own struct definitions for their key bindings.

The only reason for this was to have a properly typed “action” (using
the appropriate “action” enum).

This caused lots of duplicated code. This patch refactors this to use
a single struct definition for the “unparsed” key bindings handled by
the configuration, and another single definition for “parsed” bindings
used while handling input.

This allows us to implement configuration parsing, keymap translation
and so on using one set of functions, regardless of key binding mode.
2021-02-08 10:09:14 +01:00
Daniel Eklöf
24263412dc
url-mode: urls_render(): early exit when URL list is empty 2021-02-07 16:33:35 +01:00
Daniel Eklöf
9ee392dc8c
url-mode: generate-key-combos: minor efficiency tweaks
* Use a do..while loop; this lets us drop the second half of the loop
  condition.

* Call wcslen(prefix) once, *before* iterating the alphabet
  characters.

* Step through the alphabet characters using a  pointer, as this
  avoids an indexed load (with possibly an imul instruction in
  e.g. -Os builds).
2021-02-07 16:33:35 +01:00
Daniel Eklöf
c84e379767
url-mode: be consistent; use xmalloc() + xrealloc() 2021-02-07 16:33:35 +01:00
Daniel Eklöf
9066ba87df
url-mode: early exit when assigning key combos to empty list 2021-02-07 16:33:35 +01:00
Daniel Eklöf
1aec534b37
url-mode: input: backspace reverts the last key 2021-02-07 16:33:35 +01:00
Daniel Eklöf
ddd6f1d944
url-mode: fix key sequence generation
* We were using the ‘back’ element of the list as prefix for the next
  iteration of sequences, instead of the element at index ‘offset’

* ALEN() on a wchar_t[] includes the NULL terminator. We don’t want
  that.
2021-02-07 16:33:34 +01:00
Daniel Eklöf
29c86612df
url-mode: generate key combinations using vimium’s algorithm 2021-02-07 16:33:34 +01:00
Daniel Eklöf
e9ff8bac1c
url-mode: refresh rendered URLs after accepting a key 2021-02-07 16:33:34 +01:00
Daniel Eklöf
ab1224ba91
url-mode: urls_assign_key_combos(): remove URLs when all key combos have been used up 2021-02-07 16:33:34 +01:00
Daniel Eklöf
e6612927be
url-mode: add ftp://, ftps://, file://, gemini:// and gopher:// 2021-02-07 16:33:34 +01:00
Daniel Eklöf
a988138492
url-mode: urls_collect(): URL list pointer as an argument 2021-02-07 16:33:34 +01:00
Daniel Eklöf
2c10a147ea
url-mode: underline URLs using the color from colors.urls
This is implemented by allocating one of the (few!) remaining bits in
the cells’ attribute struct to indicate the cell should be “URL
highlighted”.

render_cell() looks at this bit and draws an underline using the color
from colors.urls (defaults to regular3 - i.e. yellow).

A new function, url_tag_cells(), iterates the currently detected URLs
and sets the new ‘url’ attribute flag on the affected cells.

Note: this is done in a separate function to keep urls_collect() free
from as many dependencies as possible.

urls_reset() is updated to *clear* the ‘url’ flag (and thus implicitly
also results in a grid refresh, _if_ there were any URLs).

We now exit URL mode on *any* client application input. This needs to
be so since we can’t know if the URLs we previously detected are still
valid.
2021-02-07 16:33:34 +01:00
Daniel Eklöf
6726494f4c
url-mode: store absolute row numbers in start/end coordinates
This allows us to update the jump label positions when the viewport
changes.

This in turn allows us to stay in URL mode while the user is using the
mouse to scroll in the scrollback history.

Scrolling with the keyboard is currently not possible, since input
handling in URL mode does not recognize “regular” key bindings. We
_could_ add scrollback up/down bindings to URL mode too, but lets not,
for the time being.

(Note: an alternative to this patch is to disallow mouse scrolling
too. Then we could have kept the URL start/end as viewport local
coordinates).
2021-02-07 16:33:34 +01:00
Daniel Eklöf
a578faf494
url-mode: make the end coordinate *inclusive* 2021-02-07 16:33:33 +01:00
Daniel Eklöf
ef3ce530ba
url-mode: refactor: break out URL activation to a separate function 2021-02-07 16:33:33 +01:00
Daniel Eklöf
607ee63b77
url-mode: auto-detect: use wcsncasecmp() instead of towlower()
When matching the URI scheme, use wcsncasecmp() when comparing the
strings, instead of calling towlower() on each cell.
2021-02-07 16:33:33 +01:00
Daniel Eklöf
6b7003bcc3
url-mode: auto-detect: don’t store the lower-cased URL; use original casing 2021-02-07 16:33:33 +01:00
Daniel Eklöf
93181649b3
config: add show-urls-copy action
This works just like show-urls-launch, except that instead of opening
the URL (typically using xdg-open), it is placed in the clipboard when
activated.
2021-02-07 16:33:32 +01:00
Daniel Eklöf
65caa33084
url-mode: auto-detect: don’t line-wrap URL is row isn’t line-wrapped 2021-02-07 16:33:32 +01:00
Daniel Eklöf
f61f7c131f
url-mode: auto-detect: heuristics for parenthesis and brackets
While parenthesis and brackets _are_ valid URL characters, there are
many times when we do *not* want them to be part of the URL.

For example, in markdown we write “[text](url)”, or even
“[![alt-text](url-1)](url-2)”.

Here, the URLs are clearly *not* “url)” or “url-1)](url2)”.
2021-02-07 16:33:32 +01:00
Daniel Eklöf
9d8ec857ce
url-mode: use ‘url-launch’ from config to open URLs 2021-02-07 16:33:32 +01:00
Daniel Eklöf
2315aba458
url-mode: urls_reset() do an early return if we don’t have any URLs 2021-02-07 16:33:31 +01:00
Daniel Eklöf
d75688b0bd
url-mode: fix ‘n’ parameter to wcstombs() 2021-02-07 16:33:31 +01:00
Daniel Eklöf
2cc84db979
urls: initial support for detecting URLs and rendering jump-labels
The jump labels work, but is currently hardcoded to use xdg-open
2021-02-07 16:33:31 +01:00