summaryrefslogtreecommitdiffstatshomepage
path: root/posts/new-features-in-weltschmerz.md
blob: f189909777051f33b1aaf874890857cb61cad35c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
title: New features in weltschmerz 1.3.0
date: 2020-04-13
author: Wynn Wolf Arbor

Over the past few weeks I have been working on bringing a few new
features to [weltschmerz](weltschmerz.html), my terminal emulator. One
of them is the addition of a major VTE feature that I had overlooked
when I first prototyped it: The support for **OSC 8 hyperlinks**.

The remaining two are smaller in nature, but hopefully just as useful:
The context menu has learned a couple of new tricks, namely **copying a
selection as HTML**, and the ability to **open the current directory**
in the desktop environment's default file manager.

Additionally, I have overhauled and improved the configuration
management code to make future changes and additions easier. These
improvements include a small bug fix, but are otherwise invisible to the
end user.

Head on over to the [project page](weltschmerz.html) to get the newest
version right away, or read on to take a closer look at each new
feature.

## Hyperlink support

The motivation for this feature came when I [read about](https://developers.redhat.com/blog/2020/03/26/static-analysis-in-gcc-10/)
the new `-fanalyzer` static analysis pass that will come with GCC 10.
The post mentions that in sufficiently capable terminals, new CWE
identifiers and the option names for warnings are clickable hyperlinks
pointing people to the right place in the documentation.

Since the post mentioned _gnome-terminal_ as one such capable emulator,
I assumed that VTE had to have been updated with hyperlink support and
went to find out when that happened. It turned out that it had been
added [way back when](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda)
in 2017, I just never paid much attention to it.

Since VTE already had full support, I decided to add this feature to
weltschmerz as well. Now, if enabled, hyperlinks are clickable; they
open up in the application that GLib thinks is best for the given URI.
To make the user aware of what they will open, the terminal now renders
a tooltip with the URI when hovering over a hyperlink:

![hyperlinks in weltschmerz](img/weltschmerz-hyperlinks.png)

Given the relative infancy of this functionality, and a couple of
[security concerns](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda#security),
this feature is disabled by default. If you want to try it out, it can
be enabled in weltschmerz's config file like so:

```ini
[misc]
allow-hyperlinks = true
```

## Copy as HTML

Whilst looking through VTE's [Vala
documentation](https://valadoc.org/vte-2.91/Vte.Terminal.html) to find
out more about hyperlinks, I stumbled across the [definition](https://valadoc.org/vte-2.91/Vte.Format.html)
for the _Format_ enum which controls in what format the selection is
copied to the clipboard. `TEXT` makes the clipboard contain the plain
text copy of the selection, and `HTML` formats the selection as HTML,
with mostly complete style and colour information, like this:

<pre class="indent clear">
<b>diff --git a/NEWS b/NEWS</b>
<b>index a9b1359..4e1c329 100644</b>
<b>--- a/NEWS</b>
<b>+++ b/NEWS</b>
<font color="#5C4BC8">@@ -1,5 +1,11 @@</font>
 This file lists important changes to the weltschmerz terminal emulator.

<font color="#377945">+Changes in version 1.2.1, released on January 17, 2020:</font>
<font color="#377945">+</font>
<font color="#377945">+    --- MINOR BUGFIXES ---</font>
<font color="#377945">+ * weltschmerz.1: The manual page now contains updated contact and author</font>
<font color="#377945">+   information.</font>
<font color="#377945">+</font>
 Changes in version 1.2.0, released on December 30, 2019:

     --- MINOR NEW FEATURES ---
</pre>

Adding support for this was straightforward. **Copy as HTML** is now
available as a context menu entry whenever there is an active selection.
The above is an excerpt of the output of `git-diff(1)` from one of the
release commits. Except for the font (which depends on your browser),
this is exactly how it looked in my terminal.

## Open directory

For the longest time I primarily used [ranger](https://github.com/ranger/ranger),
a terminal file manager, to traverse directories and open files quickly.
A few months back I decided to try out a few GUI-based ones and found that
[Thunar](https://docs.xfce.org/xfce/thunar/start) does the job very
well. So well, in fact, that I rarely use ranger anymore these days. I
find that for regular day-to-day browsing, I am much faster with the
mouse and quick drag-and-drop actions are now essential to me.

I still spend most of my time in a terminal, however, and whilst it is
very easy to open a terminal from within Thunar, it used to be not so
easy to open an instance of Thunar (or whichever file manager you
prefer) from within weltschmerz.

![Open directory context menu entry in weltschmerz](img/weltschmerz-open-directory.png)

Now, with the new **Open directory** context menu entry (or by hitting
`Ctrl+Shift+O`), weltschmerz opens the current directory in the desktop
manager's default file manager. Note that VTE relies on **OSC 7** to
determine which directory an application is in.

The shell I use, [fish](https://fishshell.com/), emits the correct
escape sequence [automatically](https://github.com/fish-shell/fish-shell/blob/8029f15f1fd4f77b0105fcf7421a5cdf551e2fec/share/functions/__fish_config_interactive.fish#L269)
whenever it enters a new directory, but other shells will most likely
**not** do this by default. In that case, the menu entry will be greyed
out. However, for other shells, it should simply be sufficient to put the
proper escape sequence into `PS1` or something comparable to
`PROMPT_COMMAND` in bash. Note that it has to contain a URI (and not
a regular path).

Consider something like the following (though note that `hostname` and `path`
should be URL-encoded):

```sh
printf '\e]7;file://%s%s\a' "$hostname" "$path"
```

## Closing

That's it for this release. I hope these new features will be useful (or
at least interesting) to people. Until next time!