nix-community / nix-on-droid

Nix-enabled environment for your Android device. [maintainers=@t184256,@Gerschtli]
https://nix-on-droid.unboiled.info
MIT License
1.15k stars 65 forks source link

Implement termux colorschemes #311

Closed socksthefennec closed 4 months ago

socksthefennec commented 7 months ago

This implements basic support for termux's colorschemes (~/.termux/colors.properties) through the new option terminal.colors. It takes an attribute set of strings and naively converts that to the key-value format termux expects, e.g.

terminal.colors = rec {
  background = color0;
  foreground = color15;
  cursor = color15;

  color0 = "#000000";
  # color1-14 here :)
  color15 = "#FFFFFF";
};

would become

background=#000000
color0=#000000
color15=#FFFFFF
cursor=#FFFFFF
foreground=#FFFFFF

I wasn't sure whether to use attrsOf or lazyAttrsOf, so I chose the latter as a guess. I've mostly just copied over the implementation from what fonts do, I hope that's correct.

There are a couple issues with this as it stands:

  1. Colors aren't strictly checked, you can input any string.
  2. Attributes aren't checked, you can input any attribute (whereas I believe termux only ever uses background, foreground, cursor and color0-15).
  3. There isn't any option to use a preexisting file.
  4. The changes don't immediately apply and require opening a new session, but as I understand it that's blocked by #221.
  5. Since both font and colors share most of the same code, maybe it could be pulled out into a separate function/functions?
  6. My documentation here could probably be better.

It works enough for my usecase, but there's certainly a lot that could be improved.

t184256 commented 4 months ago

Hello and sorry for not getting to this PR for so long.

I took the liberty of rebasing, bumping copyright year, squashing, limiting allowed attrnames and adding some tests. Please take a look.

t184256 commented 4 months ago

One more thing we'll need is a changelog entry.