IN: colors.constants
USING: help.markup help.syntax strings colors ;
-HELP: named-color
+HELP: lookup-color
{ $values { "name" string } { "color" color } }
{ $description "Outputs a named color from the color database." }
{ $notes "In most cases, " { $link POSTPONE: COLOR: } " should be used instead." }
ARTICLE: "colors.constants" "Standard color database"
"The " { $vocab-link "colors.constants" } " vocabulary bundles the X11 " { $snippet "rgb.txt" } " database and Factor's " { $snippet "factor-colors.txt" } " theme database to provide words for looking up color values by name."
{ $subsections
- named-color
+ lookup-color
named-colors
POSTPONE: COLOR:
} ;
! See http://factorcode.org/license.txt for BSD license.
USING: colors colors.constants tools.test ;
-{ t } [ COLOR: light-green rgba? ] unit-test
+{ t } [ COLOR: light-green value>> rgba? ] unit-test
! Copyright (C) 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: kernel assocs math math.parser memoize io.encodings.utf8
-io.files lexer parser colors sequences splitting ascii ;
+
+USING: accessors ascii assocs colors io.encodings.utf8 io.files
+kernel lexer math math.parser sequences splitting vocabs.loader
+;
+
IN: colors.constants
<PRIVATE
ERROR: no-such-color name ;
-: named-color ( name -- color )
+: lookup-color ( name -- color )
dup colors at [ ] [ no-such-color ] ?if ;
-SYNTAX: COLOR: scan-token named-color suffix! ;
+TUPLE: named-color < color name value ;
+
+M: named-color >rgba value>> >rgba ;
+
+SYNTAX: COLOR: scan-token dup lookup-color named-color boa suffix! ;
+
+{ "colors.constants" "prettyprint" } "colors.constants.prettyprint" require-when
--- /dev/null
+USING: accessors colors.constants prettyprint.custom
+prettyprint.backend prettyprint.sections ;
+
+IN: colors.constants.prettyprint
+
+M: named-color pprint* \ COLOR: [ name>> text ] pprint-prefix ;
+
] [ drop COLOR: dark-gray ] if ;
M: color-completion row-color
- drop second named-color ;
+ drop second lookup-color ;
: up-to-caret ( caret document -- string )
[ { 0 0 } ] 2dip doc-range ;
M: color-renderer row-columns
drop [
full-block-string swap
- dup named-color {
+ dup lookup-color {
[ red>> "%.5f" sprintf ]
[ green>> "%.5f" sprintf ]
[ blue>> "%.5f" sprintf ]
] output>array ;
M: color-renderer row-color
- drop named-color ;
+ drop lookup-color ;
M: color-renderer row-value
- drop named-color ;
+ drop lookup-color ;
: <color-table> ( -- table )
named-colors { human<=> } sort-by <model>