home: tmux: migrate to 'terminalFeatures'

There are other terminal capabilities I want to override in tmux, so
let's make this type more extensible.
This commit is contained in:
Bruno BELANYI 2024-03-07 15:42:58 +00:00
parent 97cc08d199
commit 742b4c39a2
4 changed files with 33 additions and 22 deletions

View file

@ -12,8 +12,10 @@
# I use scripts that use the passthrough sequence often on this host # I use scripts that use the passthrough sequence often on this host
enablePassthrough = true; enablePassthrough = true;
terminalFeatures = {
# HTerm uses `xterm-256color` as its `$TERM`, so use that here # HTerm uses `xterm-256color` as its `$TERM`, so use that here
trueColorTerminals = [ "xterm-256color" ]; xterm-256color = { };
};
}; };
ssh = { ssh = {

View file

@ -15,8 +15,10 @@
# I use scripts that use the passthrough sequence often on this host # I use scripts that use the passthrough sequence often on this host
enablePassthrough = true; enablePassthrough = true;
terminalFeatures = {
# HTerm uses `xterm-256color` as its `$TERM`, so use that here # HTerm uses `xterm-256color` as its `$TERM`, so use that here
trueColorTerminals = [ "xterm-256color" ]; xterm-256color = { };
};
}; };
}; };
} }

View file

@ -8,11 +8,11 @@
}; };
}; };
# Allow using 24bit color when SSH-ing from various clients # Allow using extended features when SSH-ing from various clients
tmux.trueColorTerminals = [ tmux.terminalFeatures = {
# My usual terminal, e.g: on laptop # My usual terminal, e.g: on laptop
"alacritty" alacritty = { };
]; };
# Always start a tmux session when opening a shell session # Always start a tmux session when opening a shell session
zsh.launchTmux = true; zsh.launchTmux = true;

View file

@ -5,6 +5,14 @@ let
config.my.home.x.enable config.my.home.x.enable
(config.my.home.wm.windowManager != null) (config.my.home.wm.windowManager != null)
]; ];
mkTerminalFlags = opt: flag:
let
mkFlag = term: ''set -as terminal-features ",${term}:${flag}"'';
enabledTerminals = lib.filterAttrs (_: v: v.${opt}) cfg.terminalFeatures;
terminals = lib.attrNames enabledTerminals;
in
lib.concatMapStringsSep "\n" mkFlag terminals;
in in
{ {
options.my.home.tmux = with lib; { options.my.home.tmux = with lib; {
@ -12,16 +20,20 @@ in
enablePassthrough = mkEnableOption "tmux DCS passthrough sequence"; enablePassthrough = mkEnableOption "tmux DCS passthrough sequence";
trueColorTerminals = mkOption { terminalFeatures = mkOption {
type = with types; listOf str; type = with types; attrsOf (submodule {
default = lib.my.nullableToList config.my.home.terminal.program; options = {
defaultText = '' trueColor = my.mkDisableOption "24-bit (RGB) color support";
`[ config.my.home.terminal.program ]` if it is non-null, otherwise an };
empty list. });
default = { ${config.my.home.terminal.program} = { }; };
defaultText = litteralExpression ''
{ ''${config.my.home.terminal.program} = { }; };
''; '';
example = [ "xterm-256color" ]; example = { xterm-256color = { }; };
description = '' description = ''
$TERM values which should be considered to always support 24-bit color. $TERM values which should be considered to have additional features.
''; '';
}; };
}; };
@ -90,12 +102,7 @@ in
} }
# Force 24-bit color for each relevant $TERM # Force 24-bit color for each relevant $TERM
${ ${mkTerminalFlags "trueColor" "RGB"}
let
mkTcFlag = term: ''set -as terminal-features ",${term}:RGB"'';
in
lib.concatMapStringsSep "\n" mkTcFlag cfg.trueColorTerminals
}
''; '';
}; };
} }