]> gitweb.factorcode.org Git - factor.git/commitdiff
io.styles: only allow character styles to inherit.
authorJohn Benediktsson <mrjbq7@gmail.com>
Sat, 15 Feb 2020 16:42:06 +0000 (08:42 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sat, 15 Feb 2020 16:42:06 +0000 (08:42 -0800)
basis/io/styles/styles.factor

index e82c4d71a0f45ebeaad6985a099464b2632da55a..71fb78cd4051d3c855676f87c50d4472c73b54ac 100644 (file)
@@ -1,10 +1,9 @@
 ! Copyright (C) 2005, 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors assocs colors colors.constants delegate
-delegate.protocols destructors fry hashtables io
-io.streams.plain io.streams.string kernel make math.order
-namespaces present sequences splitting strings strings.tables
-summary ;
+USING: accessors assocs colors delegate delegate.protocols
+destructors hashtables io io.streams.plain io.streams.string
+kernel make namespaces present sequences sets splitting strings
+strings.tables summary ;
 IN: io.styles
 
 GENERIC: stream-format ( str style stream -- )
@@ -62,8 +61,10 @@ C: <ignore-close-stream> ignore-close-stream
 TUPLE: style-stream < filter-writer style ;
 INSTANCE: style-stream output-stream
 
+DEFER: inherit-style
+
 : do-nested-style ( style style-stream -- style stream )
-    [ style>> swap assoc-union ] [ stream>> ] bi ; inline
+    [ style>> inherit-style ] [ stream>> ] bi ; inline
 
 C: <style-stream> style-stream
 
@@ -144,6 +145,18 @@ CONSTANT: standard-table-style
         { table-border T{ rgba f 0.8 0.8 0.8 1.0 } }
     }
 
+<PRIVATE
+
+: inherit? ( format -- ? )
+    HS{
+        foreground background font-name font-size font-style
+    } in? ;
+
+PRIVATE>
+
+: inherit-style ( child parent -- child' )
+    [ drop inherit? ] assoc-filter swap assoc-union! ;
+
 ! Input history
 TUPLE: input string ;