summaryrefslogtreecommitdiffstats
path: root/modules/plugins/terminal/toggleterm/toggleterm.nix
blob: 424dd2b8d0aaeb451416533a403947fff221afea (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
{
  config,
  pkgs,
  lib,
  ...
}: let
  inherit (lib.options) mkOption mkEnableOption literalExpression;
  inherit (lib.types) nullOr enum package either int;
  inherit (lib.modules) mkRenamedOptionModule;
  inherit (lib.nvim.types) mkPluginSetupOption luaInline;
  inherit (lib.generators) mkLuaInline;
  inherit (config.vim.lib) mkMappingOption;
in {
  imports = [
    (mkRenamedOptionModule ["vim" "terminal" "toggleterm" "direction"] ["vim" "terminal" "toggleterm" "setupOpts" "direction"])
    (mkRenamedOptionModule ["vim" "terminal" "toggleterm" "enable_winbar"] ["vim" "terminal" "toggleterm" "setupOpts" "enable_winbar"])
  ];

  options.vim.terminal.toggleterm = {
    enable = mkEnableOption "toggleterm as a replacement to built-in terminal command";
    mappings = {
      open = mkMappingOption "Open toggleterm" "<c-t>";
    };

    setupOpts = mkPluginSetupOption "ToggleTerm" {
      direction = mkOption {
        type = enum ["horizontal" "vertical" "tab" "float"];
        default = "horizontal";
        description = "Direction of the terminal";
      };

      enable_winbar = mkEnableOption "winbar";

      size = mkOption {
        type = either luaInline int;
        default = mkLuaInline ''
          function(term)
            if term.direction == "horizontal" then
              return 15
            elseif term.direction == "vertical" then
              return vim.o.columns * 0.4
            end
          end
        '';
        defaultText = literalExpression ''
          mkLuaInline '''
            function(term)
              if term.direction == "horizontal" then
                return 15
              elseif term.direction == "vertical" then
                return vim.o.columns * 0.4
              end
            end
          '''
        '';
        description = "Integer or Lua function which is passed to the current terminal";
      };

      winbar = {
        enabled = mkEnableOption "winbar in terminal" // {default = true;};
        name_formatter = mkOption {
          type = luaInline;
          default = mkLuaInline ''
            function(term)
              return term.name
            end
          '';
          defaultText = literalExpression ''
            mkLuaInline '''
              function(term)
                return term.name
              end
            '''
          '';
          description = "Winbar formatter function.";
        };
      };
    };

    lazygit = {
      enable = mkEnableOption "LazyGit integration";
      direction = mkOption {
        type = enum ["horizontal" "vertical" "tab" "float"];
        default = "float";
        description = "Direction of the lazygit window";
      };

      package = mkOption {
        type = nullOr package;
        default = pkgs.lazygit;
        defaultText = literalExpression "pkgs.lazygit";
        description = ''
          The package that should be used for lazygit.

          Setting this option to `null` will instead attempt to use `lazygit`
          from your {env}`PATH`
        '';
      };

      mappings = {
        open = mkMappingOption "Open lazygit [toggleterm]" "<leader>gg";
      };
    };
  };
}