From 06234ed2220e9e5a8113fb08f3e064b2d5f77e5b Mon Sep 17 00:00:00 2001 From: Denis Lehmann Date: Wed, 28 Apr 2021 17:30:00 +0200 Subject: [PATCH] allow hex colors without leading # --- README.org | 8 ++++---- bin/rzr | 7 ++++++- profiles/template.toml | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/README.org b/README.org index 5654f96..472332a 100644 --- a/README.org +++ b/README.org @@ -20,10 +20,10 @@ Lets assume you have created a profile with the name =fps=, containing the following color declarations: #+begin_src toml - w = "aqua" + w = "red" a = "#ff0000" s = "#f0f" - d = "white" + d = "ff2080" #+end_src All you have to do to apply the profile is to execute the following command: @@ -156,8 +156,8 @@ A color string can be one of the following: - - Hexadecimal value with leading hash (e.g. =#ff0000=) - - Short hexadecimal value with leading hash (e.g. =#f0f=, then interpreted as =#ff00ff=) + - Hexadecimal value with or without leading hash (e.g. =#ff0000=) + - Short hexadecimal value with or without leading hash (e.g. =f0f=, then interpreted as =#ff00ff=) - HTML color name (e.g. =green=) (a full list can be found [[https://www.w3schools.com/colors/colors_names.asp][here]]) Not set lights are turned off. diff --git a/bin/rzr b/bin/rzr index 8db4bef..48dc207 100644 --- a/bin/rzr +++ b/bin/rzr @@ -39,7 +39,12 @@ def get_color_tuple(color_string): try: color = Color(color_string).rgb except: - raise Exception("'{}' is not a valid color".format(color_string)) + + # Try again with leading # + try: + color = Color("#{}".format(color_string)).rgb + except: + raise Exception("'{}' is not a valid color".format(color_string)) # Scale RGB tuple from [0, 1] to [0, 255] color_tuple = tuple(map(lambda x: int(x * 255), color)) diff --git a/profiles/template.toml b/profiles/template.toml index 256bbe2..7a04bf9 100644 --- a/profiles/template.toml +++ b/profiles/template.toml @@ -19,7 +19,7 @@ name = "Razer BlackWidow Chroma" lightmap = "blackwidow_chroma_de" [keyboard.lights] -logo = "#dc143c" +logo = "dc143c" w = "coral" a = "bisque" s = "lightgreen"