aboutsummaryrefslogtreecommitdiff
path: root/home-manager/modules/programs/termite.nix
blob: 8a05db03558c2c23eaf1c2b8b2cddec1d92fd1af (plain)
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
{ config, lib, pkgs, ... }:

with lib;

let

  cfg = config.programs.termite;

  vteInitStr = ''
    # See https://github.com/thestinger/termite#id1
    if [[ $TERM == xterm-termite ]]; then
      . ${pkgs.termite.vte-ng}/etc/profile.d/vte.sh
    fi
  '';

in {
  options = {
    programs.termite = {
      enable = mkEnableOption "Termite VTE-based terminal";

      allowBold = mkOption {
        default = null;
        type = types.nullOr types.bool;
        description = ''
          Allow the output of bold characters when the bold escape sequence appears.
        '';
      };

      audibleBell = mkOption {
        default = null;
        type = types.nullOr types.bool;
        description = "Have the terminal beep on the terminal bell.";
      };

      clickableUrl = mkOption {
        default = null;
        type = types.nullOr types.bool;
        description = ''
          Auto-detected URLs can be clicked on to open them in  your browser.
          Only enabled if a browser is configured or detected.
        '';
      };

      dynamicTitle = mkOption {
        default = null;
        type = types.nullOr types.bool;
        description = ''
          Settings dynamic title allows the terminal and the shell to
          update the terminal's title.
        '';
      };

      fullscreen = mkOption {
        default = null;
        type = types.nullOr types.bool;
        description = "Enables entering fullscreen mode by pressing F11.";
      };

      mouseAutohide = mkOption {
        default = null;
        type = types.nullOr types.bool;
        description = ''
          Automatically hide the mouse pointer when you start typing.
        '';
      };

      scrollOnOutput = mkOption {
        default = null;
        type = types.nullOr types.bool;
        description = "Scroll to the bottom when the shell generates output.";
      };

      scrollOnKeystroke = mkOption {
        default = null;
        type = types.nullOr types.bool;
        description = ''
          Scroll to the bottom automatically when a key is pressed.
        '';
      };

      searchWrap = mkOption {
        default = null;
        type = types.nullOr types.bool;
        description = "Search from top again when you hit the bottom.";
      };

      urgentOnBell = mkOption {
        default = null;
        type = types.nullOr types.bool;
        description = "Sets the window as urgent on the terminal bell.";
      };

      font = mkOption {
        default = null;
        example = "Monospace 12";
        type = types.nullOr types.str;
        description = "The font description for the terminal's font.";
      };

      geometry = mkOption {
        default = null;
        example = "640x480";
        type = types.nullOr types.str;
        description = "The default window geometry for new terminal windows.";
      };

      iconName = mkOption {
        default = null;
        example = "terminal";
        type = types.nullOr types.str;
        description =
          "The name of the icon to be used for the terminal process.";
      };

      scrollbackLines = mkOption {
        default = null;
        example = 10000;
        type = types.nullOr types.int;
        description =
          "Set the number of lines to limit the terminal's scrollback.";
      };

      browser = mkOption {
        default = null;
        type = types.nullOr types.str;
        example = "${pkgs.xdg_utils}/xdg-open";
        description = ''
          Set the default browser for opening links. If its not set, $BROWSER is read.
          If that's not set, url hints will be disabled.
        '';
      };

      cursorBlink = mkOption {
        default = null;
        example = "system";
        type = types.nullOr (types.enum [ "system" "on" "off" ]);
        description = ''
          Specify the how the terminal's cursor should behave.
          Accepts system to respect the gtk global configuration,
          on and off to explicitly enable or disable them.
        '';
      };

      cursorShape = mkOption {
        default = null;
        example = "block";
        type = types.nullOr (types.enum [ "block" "underline" "ibeam" ]);
        description = ''
          Specify how the cursor should look. Accepts block, ibeam and underline.
        '';
      };

      filterUnmatchedUrls = mkOption {
        default = null;
        type = types.nullOr types.bool;
        description =
          "Whether to hide url hints not matching input in url hints mode.";
      };

      modifyOtherKeys = mkOption {
        default = null;
        type = types.nullOr types.bool;
        description = ''
          Emit escape sequences for extra keys,
          like the modifyOtherKeys resource for
          <citerefentry>
            <refentrytitle>xterm</refentrytitle>
            <manvolnum>1</manvolnum>
          </citerefentry>.
        '';
      };

      sizeHints = mkOption {
        default = null;
        type = types.nullOr types.bool;
        description = ''
          Enable size hints. Locks the terminal resizing
          to increments of the terminal's cell size.
          Requires a window manager that respects scroll hints.
        '';
      };

      scrollbar = mkOption {
        default = null;
        type = types.nullOr (types.enum [ "off" "left" "right" ]);
        description = "Scrollbar position.";
      };

      backgroundColor = mkOption {
        default = null;
        example = "rgba(63, 63, 63, 0.8)";
        type = types.nullOr types.str;
        description = "Background color value.";
      };

      cursorColor = mkOption {
        default = null;
        example = "#dcdccc";
        type = types.nullOr types.str;
        description = "Cursor color value.";
      };

      cursorForegroundColor = mkOption {
        default = null;
        example = "#dcdccc";
        type = types.nullOr types.str;
        description = "Cursor foreground color value.";
      };

      foregroundColor = mkOption {
        default = null;
        example = "#dcdccc";
        type = types.nullOr types.str;
        description = "Foreground color value.";
      };

      foregroundBoldColor = mkOption {
        default = null;
        example = "#ffffff";
        type = types.nullOr types.str;
        description = "Foreground bold color value.";
      };

      highlightColor = mkOption {
        default = null;
        example = "#2f2f2f";
        type = types.nullOr types.str;
        description = "highlight color value.";
      };

      hintsActiveBackgroundColor = mkOption {
        default = null;
        example = "#3f3f3f";
        type = types.nullOr types.str;
        description = "Hints active background color value.";
      };

      hintsActiveForegroundColor = mkOption {
        default = null;
        example = "#e68080";
        type = types.nullOr types.str;
        description = "Hints active foreground color value.";
      };

      hintsBackgroundColor = mkOption {
        default = null;
        example = "#3f3f3f";
        type = types.nullOr types.str;
        description = "Hints background color value.";
      };

      hintsForegroundColor = mkOption {
        default = null;
        example = "#dcdccc";
        type = types.nullOr types.str;
        description = "Hints foreground color value.";
      };

      hintsBorderColor = mkOption {
        default = null;
        example = "#3f3f3f";
        type = types.nullOr types.str;
        description = "Hints border color value.";
      };

      hintsBorderWidth = mkOption {
        default = null;
        example = "0.5";
        type = types.nullOr types.str;
        description = "Hints border width.";
      };

      hintsFont = mkOption {
        default = null;
        example = "Monospace 12";
        type = types.nullOr types.str;
        description = "The font description for the hints font.";
      };

      hintsPadding = mkOption {
        default = null;
        example = 2;
        type = types.nullOr types.int;
        description = "Hints padding.";
      };

      hintsRoundness = mkOption {
        default = null;
        example = "0.2";
        type = types.nullOr types.str;
        description = "Hints roundness.";
      };

      optionsExtra = mkOption {
        default = "";
        example = "fullscreen = true";
        type = types.lines;
        description =
          "Extra options that should be added to [options] section.";
      };

      colorsExtra = mkOption {
        default = "";
        example = ''
          color0 = #3f3f3f
          color1 = #705050
          color2 = #60b48a
        '';
        type = types.lines;
        description =
          "Extra colors options that should be added to [colors] section.";
      };

      hintsExtra = mkOption {
        default = "";
        example = "border = #3f3f3f";
        type = types.lines;
        description =
          "Extra hints options that should be added to [hints] section.";
      };
    };
  };

  config = (let
    boolToString = v: if v then "true" else "false";
    optionalBoolean = name: val:
      lib.optionalString (val != null) "${name} = ${boolToString val}";
    optionalInteger = name: val:
      lib.optionalString (val != null) "${name} = ${toString val}";
    optionalString = name: val:
      lib.optionalString (val != null) "${name} = ${val}";
  in mkIf cfg.enable {
    home.packages = [ pkgs.termite ];
    xdg.configFile."termite/config".text = ''
      [options]
      ${optionalBoolean "allow_bold" cfg.allowBold}
      ${optionalBoolean "audible_bell" cfg.audibleBell}
      ${optionalString "browser" cfg.browser}
      ${optionalBoolean "clickable_url" cfg.clickableUrl}
      ${optionalString "cursor_blink" cfg.cursorBlink}
      ${optionalString "cursor_shape" cfg.cursorShape}
      ${optionalBoolean "dynamic_title" cfg.dynamicTitle}
      ${optionalBoolean "filter_unmatched_urls" cfg.filterUnmatchedUrls}
      ${optionalString "font" cfg.font}
      ${optionalBoolean "fullscreen" cfg.fullscreen}
      ${optionalString "geometry" cfg.geometry}
      ${optionalString "icon_name" cfg.iconName}
      ${optionalBoolean "modify_other_keys" cfg.modifyOtherKeys}
      ${optionalBoolean "mouse_autohide" cfg.mouseAutohide}
      ${optionalBoolean "scroll_on_keystroke" cfg.scrollOnKeystroke}
      ${optionalBoolean "scroll_on_output" cfg.scrollOnOutput}
      ${optionalInteger "scrollback_lines" cfg.scrollbackLines}
      ${optionalString "scrollbar" cfg.scrollbar}
      ${optionalBoolean "search_wrap" cfg.searchWrap}
      ${optionalBoolean "size_hints" cfg.sizeHints}
      ${optionalBoolean "urgent_on_bell" cfg.urgentOnBell}

      ${cfg.optionsExtra}

      [colors]
      ${optionalString "background" cfg.backgroundColor}
      ${optionalString "cursor" cfg.cursorColor}
      ${optionalString "cursor_foreground" cfg.cursorForegroundColor}
      ${optionalString "foreground" cfg.foregroundColor}
      ${optionalString "foregroundBold" cfg.foregroundBoldColor}
      ${optionalString "highlight" cfg.highlightColor}

      ${cfg.colorsExtra}

      [hints]
      ${optionalString "active_background" cfg.hintsActiveBackgroundColor}
      ${optionalString "active_foreground" cfg.hintsActiveForegroundColor}
      ${optionalString "background" cfg.hintsBackgroundColor}
      ${optionalString "border" cfg.hintsBorderColor}
      ${optionalInteger "border_width" cfg.hintsBorderWidth}
      ${optionalString "font" cfg.hintsFont}
      ${optionalString "foreground" cfg.hintsForegroundColor}
      ${optionalInteger "padding" cfg.hintsPadding}
      ${optionalInteger "roundness" cfg.hintsRoundness}

      ${cfg.hintsExtra}
    '';

    programs.bash.initExtra = vteInitStr;
    programs.zsh.initExtra = vteInitStr;
  });
}