]> gitweb.factorcode.org Git - factor.git/commitdiff
colors.hex: better prettyprinting of HEXCOLOR: colors.
authorJohn Benediktsson <mrjbq7@gmail.com>
Sat, 1 Jan 2022 20:34:11 +0000 (12:34 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sat, 1 Jan 2022 20:34:11 +0000 (12:34 -0800)
basis/colors/hex/hex.factor
basis/colors/hex/prettyprint/prettyprint.factor [new file with mode: 0644]

index 334a067afcd1f38f5bc9529d04c1dafc60707294..af80ebb955104c19531e28a34bb0fa98c0e5104e 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license
 
 USING: accessors colors combinators formatting grouping kernel
-lexer math math.parser sequences ;
+lexer math math.parser sequences vocabs.loader ;
 
 IN: colors.hex
 
@@ -21,4 +21,10 @@ ERROR: invalid-hex-color hex ;
     [ red>> ] [ green>> ] [ blue>> ] tri
     [ 255 * >integer ] tri@ "%02X%02X%02X" sprintf ;
 
-SYNTAX: HEXCOLOR: scan-token hex>rgba suffix! ;
+TUPLE: hex-color < color hex value ;
+
+M: hex-color >rgba value>> >rgba ;
+
+SYNTAX: HEXCOLOR: scan-token dup hex>rgba hex-color boa suffix! ;
+
+{ "colors.hex" "prettyprint" } "colors.hex.prettyprint" require-when
diff --git a/basis/colors/hex/prettyprint/prettyprint.factor b/basis/colors/hex/prettyprint/prettyprint.factor
new file mode 100644 (file)
index 0000000..f100ae2
--- /dev/null
@@ -0,0 +1,6 @@
+USING: accessors colors.hex prettyprint.custom
+prettyprint.backend prettyprint.sections ;
+
+IN: colors.hex.prettyprint
+
+M: hex-color pprint* \ HEXCOLOR: [ hex>> text ] pprint-prefix ;