home: services: shells: Add home-tty-colorscheme-service

main
Luis Guilherme Coelho 2024-10-22 19:36:57 -03:00
parent 3b0ffd9505
commit 74fabbb8c0
No known key found for this signature in database
GPG Key ID: 1F2E76ACE3F531C8
1 changed files with 118 additions and 1 deletions

View File

@ -1,6 +1,7 @@
(define-module (radix home services shells) (define-module (radix home services shells)
#:use-module (gnu services configuration) #:use-module (gnu services configuration)
#:use-module (gnu home services utils) #:use-module (gnu home services utils)
#:use-module (gnu home services shells)
#:use-module (gnu home services) #:use-module (gnu home services)
#:use-module (gnu packages shells) #:use-module (gnu packages shells)
#:use-module (guix gexp) #:use-module (guix gexp)
@ -22,7 +23,10 @@
abbreviation abbreviation
fish-function)) fish-function
home-tty-colorscheme-service-type
home-tty-colorscheme-configuration))
;;; ;;;
;;; Fish. ;;; Fish.
@ -258,3 +262,116 @@ Install and configure Fish, the friendly interactive shell.")))
,home-fish-extension-fields)) ,home-fish-extension-fields))
'home-fish-extension))) '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 <home-tty-colorscheme-configuration>
(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.")))