X-Git-Url: https://gitweb.factorcode.org/gitweb.cgi?p=factor.git;a=blobdiff_plain;f=extra%2Fio%2Fstreams%2F256color%2F256color.factor;h=6bce05a25d1ee31fc23d3984ab8a6924b496008b;hp=2401cfa7121120bb6e5626ffe004c1b5bf2c95d5;hb=7abd0073c82a86389e869146876bdffec7bc3214;hpb=b0badd157101d4b6b184f06726b456a00171b801 diff --git a/extra/io/streams/256color/256color.factor b/extra/io/streams/256color/256color.factor index 2401cfa712..6bce05a25d 100644 --- a/extra/io/streams/256color/256color.factor +++ b/extra/io/streams/256color/256color.factor @@ -60,23 +60,23 @@ intensities [| r i | color>rgb '[ _ distance ] 256colors [ keys swap infimum-by ] [ at ] bi ; -: color>foreground ( color -- string ) +MEMO: color>foreground ( color -- string ) color>256color "\e[38;5;%sm" sprintf ; -: color>background ( color -- string ) +MEMO: color>background ( color -- string ) color>256color "\e[48;5;%sm" sprintf ; TUPLE: 256color < filter-writer ; C: <256color> 256color -M: 256color stream-format - [ - [ foreground of [ color>foreground ] [ "" ] if* ] - [ background of [ color>background ] [ "" ] if* ] - [ font-style of [ font-styles ] [ "" ] if* ] - tri 3append [ "\e[0m" surround ] unless-empty - ] dip stream>> stream-write ; +M:: 256color stream-format ( str style stream -- ) + stream stream>> :> out + style foreground of [ color>foreground out stream-write t ] [ f ] if* + style background of [ color>background out stream-write t ] [ f ] if* + style font-style of [ font-styles out stream-write t ] [ f ] if* + or or [ "\e[0m" out stream-write ] unless + str out stream-write ; M: 256color make-span-stream swap ;