aboutsummaryrefslogtreecommitdiff
path: root/home-manager/modules/programs/urxvt.nix
blob: e4c72bfe2726a048945d74fa8b87acd5a7c60568 (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
{ config, lib, pkgs, ... }:

with lib;

let

  cfg = config.programs.urxvt;

in {
  options.programs.urxvt = {
    enable = mkEnableOption "rxvt-unicode terminal emulator";

    package = mkOption {
      type = types.package;
      default = pkgs.rxvt_unicode;
      defaultText = literalExample "pkgs.rxvt_unicode";
      description = "rxvt-unicode package to install.";
    };

    fonts = mkOption {
      type = types.listOf types.str;
      default = [ ];
      description = "List of fonts to be used.";
      example = [ "xft:Droid Sans Mono Nerd Font:size=9" ];
    };

    keybindings = mkOption {
      type = types.attrsOf types.str;
      default = { };
      description = "Mapping of keybindings to actions";
      example = literalExample ''
        {
          "Shift-Control-C" = "eval:selection_to_clipboard";
          "Shift-Control-V" = "eval:paste_clipboard";
        }
      '';
    };

    iso14755 = mkOption {
      type = types.bool;
      default = true;
      description =
        "ISO14755 support for viewing and entering unicode characters.";
    };

    scroll = {
      bar = mkOption {
        type = types.submodule {
          options = {
            enable = mkOption {
              type = types.bool;
              default = true;
              description = "Whether to enable the scrollbar";
            };

            style = mkOption {
              type = types.enum [ "rxvt" "plain" "next" "xterm" ];
              default = "plain";
              description = "Scrollbar style.";
            };

            align = mkOption {
              type = types.enum [ "top" "bottom" "center" ];
              default = "center";
              description = "Scrollbar alignment.";
            };

            position = mkOption {
              type = types.enum [ "left" "right" ];
              default = "right";
              description = "Scrollbar position.";
            };

            floating = mkOption {
              type = types.bool;
              default = true;
              description =
                "Whether to display an rxvt scrollbar without a trough.";
            };
          };
        };
        default = { };
        description = "Scrollbar settings.";
      };

      lines = mkOption {
        type = types.ints.unsigned;
        default = 10000;
        description = "Number of lines to save in the scrollback buffer.";
      };

      keepPosition = mkOption {
        type = types.bool;
        default = true;
        description =
          "Whether to keep a scroll position when TTY receives new lines.";
      };

      scrollOnKeystroke = mkOption {
        type = types.bool;
        default = true;
        description = "Whether to scroll to bottom on keyboard input.";
      };

      scrollOnOutput = mkOption {
        type = types.bool;
        default = false;
        description = "Whether to scroll to bottom on TTY output.";
      };
    };

    transparent = mkOption {
      type = types.bool;
      default = false;
      description = "Whether to enable pseudo-transparency.";
    };

    shading = mkOption {
      type = types.ints.between 0 200;
      default = 100;
      description =
        "Darken (0 .. 99) or lighten (101 .. 200) the transparent background.";
    };

    extraConfig = mkOption {
      default = { };
      type = types.attrs;
      description = "Additional configuration to add.";
      example = { "shading" = 15; };
    };

  };

  config = mkIf cfg.enable {
    home.packages = [ cfg.package ];

    xresources.properties = {
      "URxvt.scrollBar" = cfg.scroll.bar.enable;
      "URxvt.scrollstyle" = cfg.scroll.bar.style;
      "URxvt.scrollBar_align" = cfg.scroll.bar.align;
      "URxvt.scrollBar_right" = cfg.scroll.bar.position == "right";
      "URxvt.scrollBar_floating" = cfg.scroll.bar.floating;
      "URxvt.saveLines" = cfg.scroll.lines;
      "URxvt.scrollWithBuffer" = cfg.scroll.keepPosition;
      "URxvt.scrollTtyKeypress" = cfg.scroll.scrollOnKeystroke;
      "URxvt.scrollTtyOutput" = cfg.scroll.scrollOnOutput;
      "URxvt.transparent" = cfg.transparent;
      "URxvt.shading" = cfg.shading;
      "URxvt.iso14755" = cfg.iso14755;
    } // flip mapAttrs' cfg.keybindings
      (kb: action: nameValuePair "URxvt.keysym.${kb}" action)
      // optionalAttrs (cfg.fonts != [ ]) {
        "URxvt.font" = concatStringsSep "," cfg.fonts;
      } // flip mapAttrs' cfg.extraConfig (k: v: nameValuePair "URxvt.${k}" v);
  };
}