From 74fabbb8c0033e5152839c6c8d64de32583b93f4 Mon Sep 17 00:00:00 2001 From: Luis Guilherme Coelho Date: Tue, 22 Oct 2024 19:36:57 -0300 Subject: [PATCH] home: services: shells: Add home-tty-colorscheme-service --- radix/home/services/shells.scm | 119 ++++++++++++++++++++++++++++++++- 1 file changed, 118 insertions(+), 1 deletion(-) diff --git a/radix/home/services/shells.scm b/radix/home/services/shells.scm index e4a248a..3da4d68 100644 --- a/radix/home/services/shells.scm +++ b/radix/home/services/shells.scm @@ -1,6 +1,7 @@ (define-module (radix home services shells) #:use-module (gnu services configuration) #:use-module (gnu home services utils) + #:use-module (gnu home services shells) #:use-module (gnu home services) #:use-module (gnu packages shells) #:use-module (guix gexp) @@ -22,7 +23,10 @@ abbreviation - fish-function)) + fish-function + + home-tty-colorscheme-service-type + home-tty-colorscheme-configuration)) ;;; ;;; Fish. @@ -258,3 +262,116 @@ Install and configure Fish, the friendly interactive shell."))) ,home-fish-extension-fields)) 'home-fish-extension))) +(define (color? x) + (and (equal? (string-length x) 6) + (char-set-every (lambda (c) + (char-set-contains? char-set:hex-digit c)) + (string->char-set x)))) + +(define serialize-color empty-serializer) +(define-maybe color) + +(define-configuration home-tty-colorscheme-configuration + (regular-black + maybe-color + "The color to be used as regular black.") + (regular-red + maybe-color + "The color to be used as regular red.") + (regular-green + maybe-color + "The color to be used as regular green.") + (regular-yellow + maybe-color + "The color to be used as regular yellow.") + (regular-blue + maybe-color + "The color to be used as regular blue.") + (regular-magenta + maybe-color + "The color to be used as regular magenta.") + (regular-cyan + maybe-color + "The color to be used as regular cyan.") + (regular-white + maybe-color + "The color to be used as regular white.") + (bright-black + maybe-color + "The color to be used as bright black.") + (bright-red + maybe-color + "The color to be used as bright red.") + (bright-green + maybe-color + "The color to be used as bright green.") + (bright-yellow + maybe-color + "The color to be used as bright yellow.") + (bright-blue + maybe-color + "The color to be used as bright blue.") + (bright-magenta + maybe-color + "The color to be used as bright magenta.") + (bright-cyan + maybe-color + "The color to be used as bright cyan.") + (bright-white + maybe-color + "The color to be used as bright white.")) + +(define (tty-colorscheme-text config) + (define (unset-value? val) + (equal? val %unset-value)) + (match-record config + (regular-black regular-red regular-green regular-yellow regular-blue + regular-magenta regular-cyan regular-white bright-black bright-red + bright-green bright-yellow bright-blue bright-magenta bright-cyan + bright-white) + (list (plain-file "tty-colorscheme" + (string-join + (list "[ \"$TERM\" = \"linux\" ] && {\\" + (if (unset-value? regular-black) "" + (string-append " echo -en \"\\e]P0\"'" regular-black "'")) + (if (unset-value? regular-red) "" + (string-append " echo -en \"\\e]P1\"'" regular-red "'")) + (if (unset-value? regular-green) "" + (string-append " echo -en \"\\e]P2\"'" regular-green "'")) + (if (unset-value? regular-yellow) "" + (string-append " echo -en \"\\e]P3\"'" regular-yellow "'")) + (if (unset-value? regular-blue) "" + (string-append " echo -en \"\\e]P4\"'" regular-blue "'")) + (if (unset-value? regular-magenta) "" + (string-append " echo -en \"\\e]P5\"'" regular-magenta "'")) + (if (unset-value? regular-cyan) "" + (string-append " echo -en \"\\e]P6\"'" regular-cyan "'")) + (if (unset-value? regular-white) "" + (string-append " echo -en \"\\e]P7\"'" regular-white "'")) + (if (unset-value? bright-black) "" + (string-append " echo -en \"\\e]P8\"'" bright-black "'")) + (if (unset-value? bright-red) "" + (string-append " echo -en \"\\e]P9\"'" bright-red "'")) + (if (unset-value? bright-green) "" + (string-append " echo -en \"\\e]PA\"'" bright-green "'")) + (if (unset-value? bright-yellow) "" + (string-append " echo -en \"\\e]PB\"'" bright-yellow "'")) + (if (unset-value? bright-blue) "" + (string-append " echo -en \"\\e]PC\"'" bright-blue "'")) + (if (unset-value? bright-magenta) "" + (string-append " echo -en \"\\e]PD\"'" bright-magenta "'")) + (if (unset-value? bright-cyan) "" + (string-append " echo -en \"\\e]PE\"'" bright-cyan "'")) + (if (unset-value? bright-white) "" + (string-append " echo -en \"\\e]PF\"'" bright-white "'")) + "}") + "\n"))))) + +(define home-tty-colorscheme-service-type + (service-type (name 'home-tty-colorscheme) + (extensions + (list (service-extension home-shell-profile-service-type + tty-colorscheme-text))) + (compose identity) + (default-value (home-tty-colorscheme-configuration)) + (description "Set tty colorscheme.")))