Safe Haskell | None |
---|
Handles colors and special effects for text. Internally this module uses the Haskell terminfo library, which links against the UNIX library of the same name, so it should work with a wide variety of UNIX terminals.
The building block of Rainbow is the Chunk
. Each Chunk comes with
a TextSpec
, which specifies how the text should look on 8-color
and on 256-color terminals. The Chunk is a full specification; that
is, although Chunks are typically printed one after the other, the
appearance of one Chunk does not affect the appearance of the next
Chunk.
You have full freedom to specify different attributes and colors for 8 and 256 color terminals; for instance, you can have text appear red on an 8-color terminal but blue on a 256-color terminal.
Some useful combinators are provided to assist with the building of
Chunks. plain
builds a Chunk with a provided Text
that is
rendered using the terminal's default settings and colors. You then
use +.+
to combine different modifiers to change how the Chunk is
rendered. Here's an example:
{-# LANGUAGE OverloadedStrings #-} -- This chunk is blue and underlined, both on 8-color and 256-color -- terminals. blueHello :: Chunk blueHello = plain "Hello world!" +.+ f_blue +.+ underline -- This chunk is red on 8-color terminals but uses color 88 on -- 256-color terminals. Because +.+ is left-associative, the -- color256_f_88 supersedes the f_red, which sets the foreground -- on both 8 and 256 color terminals to red. redHello :: Chunk redHello = plain "Hello world!" +.+ f_red +.+ color256_f_88 -- This chunk is underlined on 8-color terminals but is not -- underlined on 256-color terminals. underlinedOn8 :: Chunk underlinedOn8 = plain "Hello world!" +.+ underline8 newline :: Chunk newline = plain "\n" -- How to print all these chunks main :: IO () main = do t <- termFromEnv printChunks t [blueHello, nl, redHello, nl, underlinedOn8, nl]
- data Term
- termFromEnv :: IO Term
- smartTermFromEnv :: Bool -> Handle -> IO Term
- data Chunk
- plain :: Text -> Chunk
- printChunks :: Term -> [Chunk] -> IO ()
- hPrintChunks :: Handle -> Term -> [Chunk] -> IO ()
- class Mod a where
- changeChunk :: Chunk -> a -> Chunk
- newtype ChangeText = ChangeText {
- unChangeText :: Text -> Text
- (.+.) :: Mod a => (Chunk -> Chunk) -> a -> Chunk -> Chunk
- (+.+) :: Mod a => Chunk -> a -> Chunk
- bold :: BoldAll
- boldOff :: BoldAll
- underline :: UnderlineAll
- underlineOff :: UnderlineAll
- flash :: FlashAll
- flashOff :: FlashAll
- inverse :: InverseAll
- inverseOff :: InverseAll
- bold8 :: Bold8
- bold8off :: Bold8
- underline8 :: Underline8
- underline8off :: Underline8
- flash8 :: Flash8
- flash8off :: Flash8
- inverse8 :: Inverse8
- inverse8off :: Inverse8
- bold256 :: Bold256
- bold256off :: Bold256
- underline256 :: Underline256
- underline256off :: Underline256
- flash256 :: Flash256
- flash256off :: Flash256
- inverse256 :: Inverse256
- inverse256off :: Inverse256
- f_default :: ForegroundAll
- f_black :: ForegroundAll
- f_red :: ForegroundAll
- f_green :: ForegroundAll
- f_yellow :: ForegroundAll
- f_blue :: ForegroundAll
- f_magenta :: ForegroundAll
- f_cyan :: ForegroundAll
- f_white :: ForegroundAll
- b_default :: BackgroundAll
- b_black :: BackgroundAll
- b_red :: BackgroundAll
- b_green :: BackgroundAll
- b_yellow :: BackgroundAll
- b_blue :: BackgroundAll
- b_magenta :: BackgroundAll
- b_cyan :: BackgroundAll
- b_white :: BackgroundAll
- color8_f_default :: Foreground8
- color8_f_black :: Foreground8
- color8_f_red :: Foreground8
- color8_f_green :: Foreground8
- color8_f_yellow :: Foreground8
- color8_f_blue :: Foreground8
- color8_f_magenta :: Foreground8
- color8_f_cyan :: Foreground8
- color8_f_white :: Foreground8
- color8_b_default :: Background8
- color8_b_black :: Background8
- color8_b_red :: Background8
- color8_b_green :: Background8
- color8_b_yellow :: Background8
- color8_b_blue :: Background8
- color8_b_magenta :: Background8
- color8_b_cyan :: Background8
- color8_b_white :: Background8
- color256_f_default :: Foreground256
- color256_f_0 :: Foreground256
- color256_f_black :: Foreground256
- color256_f_1 :: Foreground256
- color256_f_red :: Foreground256
- color256_f_2 :: Foreground256
- color256_f_green :: Foreground256
- color256_f_3 :: Foreground256
- color256_f_yellow :: Foreground256
- color256_f_4 :: Foreground256
- color256_f_blue :: Foreground256
- color256_f_5 :: Foreground256
- color256_f_magenta :: Foreground256
- color256_f_6 :: Foreground256
- color256_f_cyan :: Foreground256
- color256_f_7 :: Foreground256
- color256_f_white :: Foreground256
- color256_f_8 :: Foreground256
- color256_f_grey :: Foreground256
- color256_f_9 :: Foreground256
- color256_f_red_bright :: Foreground256
- color256_f_10 :: Foreground256
- color256_f_green_bright :: Foreground256
- color256_f_11 :: Foreground256
- color256_f_yellow_bright :: Foreground256
- color256_f_12 :: Foreground256
- color256_f_blue_bright :: Foreground256
- color256_f_13 :: Foreground256
- color256_f_magenta_bright :: Foreground256
- color256_f_14 :: Foreground256
- color256_f_cyan_bright :: Foreground256
- color256_f_15 :: Foreground256
- color256_f_white_bright :: Foreground256
- color256_f_16 :: Foreground256
- color256_f_17 :: Foreground256
- color256_f_18 :: Foreground256
- color256_f_19 :: Foreground256
- color256_f_20 :: Foreground256
- color256_f_21 :: Foreground256
- color256_f_22 :: Foreground256
- color256_f_23 :: Foreground256
- color256_f_24 :: Foreground256
- color256_f_25 :: Foreground256
- color256_f_26 :: Foreground256
- color256_f_27 :: Foreground256
- color256_f_28 :: Foreground256
- color256_f_29 :: Foreground256
- color256_f_30 :: Foreground256
- color256_f_31 :: Foreground256
- color256_f_32 :: Foreground256
- color256_f_33 :: Foreground256
- color256_f_34 :: Foreground256
- color256_f_35 :: Foreground256
- color256_f_36 :: Foreground256
- color256_f_37 :: Foreground256
- color256_f_38 :: Foreground256
- color256_f_39 :: Foreground256
- color256_f_40 :: Foreground256
- color256_f_41 :: Foreground256
- color256_f_42 :: Foreground256
- color256_f_43 :: Foreground256
- color256_f_44 :: Foreground256
- color256_f_45 :: Foreground256
- color256_f_46 :: Foreground256
- color256_f_47 :: Foreground256
- color256_f_48 :: Foreground256
- color256_f_49 :: Foreground256
- color256_f_50 :: Foreground256
- color256_f_51 :: Foreground256
- color256_f_52 :: Foreground256
- color256_f_53 :: Foreground256
- color256_f_54 :: Foreground256
- color256_f_55 :: Foreground256
- color256_f_56 :: Foreground256
- color256_f_57 :: Foreground256
- color256_f_58 :: Foreground256
- color256_f_59 :: Foreground256
- color256_f_60 :: Foreground256
- color256_f_61 :: Foreground256
- color256_f_62 :: Foreground256
- color256_f_63 :: Foreground256
- color256_f_64 :: Foreground256
- color256_f_65 :: Foreground256
- color256_f_66 :: Foreground256
- color256_f_67 :: Foreground256
- color256_f_68 :: Foreground256
- color256_f_69 :: Foreground256
- color256_f_70 :: Foreground256
- color256_f_71 :: Foreground256
- color256_f_72 :: Foreground256
- color256_f_73 :: Foreground256
- color256_f_74 :: Foreground256
- color256_f_75 :: Foreground256
- color256_f_76 :: Foreground256
- color256_f_77 :: Foreground256
- color256_f_78 :: Foreground256
- color256_f_79 :: Foreground256
- color256_f_80 :: Foreground256
- color256_f_81 :: Foreground256
- color256_f_82 :: Foreground256
- color256_f_83 :: Foreground256
- color256_f_84 :: Foreground256
- color256_f_85 :: Foreground256
- color256_f_86 :: Foreground256
- color256_f_87 :: Foreground256
- color256_f_88 :: Foreground256
- color256_f_89 :: Foreground256
- color256_f_90 :: Foreground256
- color256_f_91 :: Foreground256
- color256_f_92 :: Foreground256
- color256_f_93 :: Foreground256
- color256_f_94 :: Foreground256
- color256_f_95 :: Foreground256
- color256_f_96 :: Foreground256
- color256_f_97 :: Foreground256
- color256_f_98 :: Foreground256
- color256_f_99 :: Foreground256
- color256_f_100 :: Foreground256
- color256_f_101 :: Foreground256
- color256_f_102 :: Foreground256
- color256_f_103 :: Foreground256
- color256_f_104 :: Foreground256
- color256_f_105 :: Foreground256
- color256_f_106 :: Foreground256
- color256_f_107 :: Foreground256
- color256_f_108 :: Foreground256
- color256_f_109 :: Foreground256
- color256_f_110 :: Foreground256
- color256_f_111 :: Foreground256
- color256_f_112 :: Foreground256
- color256_f_113 :: Foreground256
- color256_f_114 :: Foreground256
- color256_f_115 :: Foreground256
- color256_f_116 :: Foreground256
- color256_f_117 :: Foreground256
- color256_f_118 :: Foreground256
- color256_f_119 :: Foreground256
- color256_f_120 :: Foreground256
- color256_f_121 :: Foreground256
- color256_f_122 :: Foreground256
- color256_f_123 :: Foreground256
- color256_f_124 :: Foreground256
- color256_f_125 :: Foreground256
- color256_f_126 :: Foreground256
- color256_f_127 :: Foreground256
- color256_f_128 :: Foreground256
- color256_f_129 :: Foreground256
- color256_f_130 :: Foreground256
- color256_f_131 :: Foreground256
- color256_f_132 :: Foreground256
- color256_f_133 :: Foreground256
- color256_f_134 :: Foreground256
- color256_f_135 :: Foreground256
- color256_f_136 :: Foreground256
- color256_f_137 :: Foreground256
- color256_f_138 :: Foreground256
- color256_f_139 :: Foreground256
- color256_f_140 :: Foreground256
- color256_f_141 :: Foreground256
- color256_f_142 :: Foreground256
- color256_f_143 :: Foreground256
- color256_f_144 :: Foreground256
- color256_f_145 :: Foreground256
- color256_f_146 :: Foreground256
- color256_f_147 :: Foreground256
- color256_f_148 :: Foreground256
- color256_f_149 :: Foreground256
- color256_f_150 :: Foreground256
- color256_f_151 :: Foreground256
- color256_f_152 :: Foreground256
- color256_f_153 :: Foreground256
- color256_f_154 :: Foreground256
- color256_f_155 :: Foreground256
- color256_f_156 :: Foreground256
- color256_f_157 :: Foreground256
- color256_f_158 :: Foreground256
- color256_f_159 :: Foreground256
- color256_f_160 :: Foreground256
- color256_f_161 :: Foreground256
- color256_f_162 :: Foreground256
- color256_f_163 :: Foreground256
- color256_f_164 :: Foreground256
- color256_f_165 :: Foreground256
- color256_f_166 :: Foreground256
- color256_f_167 :: Foreground256
- color256_f_168 :: Foreground256
- color256_f_169 :: Foreground256
- color256_f_170 :: Foreground256
- color256_f_171 :: Foreground256
- color256_f_172 :: Foreground256
- color256_f_173 :: Foreground256
- color256_f_174 :: Foreground256
- color256_f_175 :: Foreground256
- color256_f_176 :: Foreground256
- color256_f_177 :: Foreground256
- color256_f_178 :: Foreground256
- color256_f_179 :: Foreground256
- color256_f_180 :: Foreground256
- color256_f_181 :: Foreground256
- color256_f_182 :: Foreground256
- color256_f_183 :: Foreground256
- color256_f_184 :: Foreground256
- color256_f_185 :: Foreground256
- color256_f_186 :: Foreground256
- color256_f_187 :: Foreground256
- color256_f_188 :: Foreground256
- color256_f_189 :: Foreground256
- color256_f_190 :: Foreground256
- color256_f_191 :: Foreground256
- color256_f_192 :: Foreground256
- color256_f_193 :: Foreground256
- color256_f_194 :: Foreground256
- color256_f_195 :: Foreground256
- color256_f_196 :: Foreground256
- color256_f_197 :: Foreground256
- color256_f_198 :: Foreground256
- color256_f_199 :: Foreground256
- color256_f_200 :: Foreground256
- color256_f_201 :: Foreground256
- color256_f_202 :: Foreground256
- color256_f_203 :: Foreground256
- color256_f_204 :: Foreground256
- color256_f_205 :: Foreground256
- color256_f_206 :: Foreground256
- color256_f_207 :: Foreground256
- color256_f_208 :: Foreground256
- color256_f_209 :: Foreground256
- color256_f_210 :: Foreground256
- color256_f_211 :: Foreground256
- color256_f_212 :: Foreground256
- color256_f_213 :: Foreground256
- color256_f_214 :: Foreground256
- color256_f_215 :: Foreground256
- color256_f_216 :: Foreground256
- color256_f_217 :: Foreground256
- color256_f_218 :: Foreground256
- color256_f_219 :: Foreground256
- color256_f_220 :: Foreground256
- color256_f_221 :: Foreground256
- color256_f_222 :: Foreground256
- color256_f_223 :: Foreground256
- color256_f_224 :: Foreground256
- color256_f_225 :: Foreground256
- color256_f_226 :: Foreground256
- color256_f_227 :: Foreground256
- color256_f_228 :: Foreground256
- color256_f_229 :: Foreground256
- color256_f_230 :: Foreground256
- color256_f_231 :: Foreground256
- color256_f_232 :: Foreground256
- color256_f_233 :: Foreground256
- color256_f_234 :: Foreground256
- color256_f_235 :: Foreground256
- color256_f_236 :: Foreground256
- color256_f_237 :: Foreground256
- color256_f_238 :: Foreground256
- color256_f_239 :: Foreground256
- color256_f_240 :: Foreground256
- color256_f_241 :: Foreground256
- color256_f_242 :: Foreground256
- color256_f_243 :: Foreground256
- color256_f_244 :: Foreground256
- color256_f_245 :: Foreground256
- color256_f_246 :: Foreground256
- color256_f_247 :: Foreground256
- color256_f_248 :: Foreground256
- color256_f_249 :: Foreground256
- color256_f_250 :: Foreground256
- color256_f_251 :: Foreground256
- color256_f_252 :: Foreground256
- color256_f_253 :: Foreground256
- color256_f_254 :: Foreground256
- color256_f_255 :: Foreground256
- color256_b_default :: Background256
- color256_b_0 :: Background256
- color256_b_black :: Background256
- color256_b_1 :: Background256
- color256_b_red :: Background256
- color256_b_2 :: Background256
- color256_b_green :: Background256
- color256_b_3 :: Background256
- color256_b_yellow :: Background256
- color256_b_4 :: Background256
- color256_b_blue :: Background256
- color256_b_5 :: Background256
- color256_b_magenta :: Background256
- color256_b_6 :: Background256
- color256_b_cyan :: Background256
- color256_b_7 :: Background256
- color256_b_white :: Background256
- color256_b_8 :: Background256
- color256_b_grey :: Background256
- color256_b_9 :: Background256
- color256_b_red_bright :: Background256
- color256_b_10 :: Background256
- color256_b_green_bright :: Background256
- color256_b_11 :: Background256
- color256_b_yellow_bright :: Background256
- color256_b_12 :: Background256
- color256_b_blue_bright :: Background256
- color256_b_13 :: Background256
- color256_b_magenta_bright :: Background256
- color256_b_14 :: Background256
- color256_b_cyan_bright :: Background256
- color256_b_15 :: Background256
- color256_b_white_bright :: Background256
- color256_b_16 :: Background256
- color256_b_17 :: Background256
- color256_b_18 :: Background256
- color256_b_19 :: Background256
- color256_b_20 :: Background256
- color256_b_21 :: Background256
- color256_b_22 :: Background256
- color256_b_23 :: Background256
- color256_b_24 :: Background256
- color256_b_25 :: Background256
- color256_b_26 :: Background256
- color256_b_27 :: Background256
- color256_b_28 :: Background256
- color256_b_29 :: Background256
- color256_b_30 :: Background256
- color256_b_31 :: Background256
- color256_b_32 :: Background256
- color256_b_33 :: Background256
- color256_b_34 :: Background256
- color256_b_35 :: Background256
- color256_b_36 :: Background256
- color256_b_37 :: Background256
- color256_b_38 :: Background256
- color256_b_39 :: Background256
- color256_b_40 :: Background256
- color256_b_41 :: Background256
- color256_b_42 :: Background256
- color256_b_43 :: Background256
- color256_b_44 :: Background256
- color256_b_45 :: Background256
- color256_b_46 :: Background256
- color256_b_47 :: Background256
- color256_b_48 :: Background256
- color256_b_49 :: Background256
- color256_b_50 :: Background256
- color256_b_51 :: Background256
- color256_b_52 :: Background256
- color256_b_53 :: Background256
- color256_b_54 :: Background256
- color256_b_55 :: Background256
- color256_b_56 :: Background256
- color256_b_57 :: Background256
- color256_b_58 :: Background256
- color256_b_59 :: Background256
- color256_b_60 :: Background256
- color256_b_61 :: Background256
- color256_b_62 :: Background256
- color256_b_63 :: Background256
- color256_b_64 :: Background256
- color256_b_65 :: Background256
- color256_b_66 :: Background256
- color256_b_67 :: Background256
- color256_b_68 :: Background256
- color256_b_69 :: Background256
- color256_b_70 :: Background256
- color256_b_71 :: Background256
- color256_b_72 :: Background256
- color256_b_73 :: Background256
- color256_b_74 :: Background256
- color256_b_75 :: Background256
- color256_b_76 :: Background256
- color256_b_77 :: Background256
- color256_b_78 :: Background256
- color256_b_79 :: Background256
- color256_b_80 :: Background256
- color256_b_81 :: Background256
- color256_b_82 :: Background256
- color256_b_83 :: Background256
- color256_b_84 :: Background256
- color256_b_85 :: Background256
- color256_b_86 :: Background256
- color256_b_87 :: Background256
- color256_b_88 :: Background256
- color256_b_89 :: Background256
- color256_b_90 :: Background256
- color256_b_91 :: Background256
- color256_b_92 :: Background256
- color256_b_93 :: Background256
- color256_b_94 :: Background256
- color256_b_95 :: Background256
- color256_b_96 :: Background256
- color256_b_97 :: Background256
- color256_b_98 :: Background256
- color256_b_99 :: Background256
- color256_b_100 :: Background256
- color256_b_101 :: Background256
- color256_b_102 :: Background256
- color256_b_103 :: Background256
- color256_b_104 :: Background256
- color256_b_105 :: Background256
- color256_b_106 :: Background256
- color256_b_107 :: Background256
- color256_b_108 :: Background256
- color256_b_109 :: Background256
- color256_b_110 :: Background256
- color256_b_111 :: Background256
- color256_b_112 :: Background256
- color256_b_113 :: Background256
- color256_b_114 :: Background256
- color256_b_115 :: Background256
- color256_b_116 :: Background256
- color256_b_117 :: Background256
- color256_b_118 :: Background256
- color256_b_119 :: Background256
- color256_b_120 :: Background256
- color256_b_121 :: Background256
- color256_b_122 :: Background256
- color256_b_123 :: Background256
- color256_b_124 :: Background256
- color256_b_125 :: Background256
- color256_b_126 :: Background256
- color256_b_127 :: Background256
- color256_b_128 :: Background256
- color256_b_129 :: Background256
- color256_b_130 :: Background256
- color256_b_131 :: Background256
- color256_b_132 :: Background256
- color256_b_133 :: Background256
- color256_b_134 :: Background256
- color256_b_135 :: Background256
- color256_b_136 :: Background256
- color256_b_137 :: Background256
- color256_b_138 :: Background256
- color256_b_139 :: Background256
- color256_b_140 :: Background256
- color256_b_141 :: Background256
- color256_b_142 :: Background256
- color256_b_143 :: Background256
- color256_b_144 :: Background256
- color256_b_145 :: Background256
- color256_b_146 :: Background256
- color256_b_147 :: Background256
- color256_b_148 :: Background256
- color256_b_149 :: Background256
- color256_b_150 :: Background256
- color256_b_151 :: Background256
- color256_b_152 :: Background256
- color256_b_153 :: Background256
- color256_b_154 :: Background256
- color256_b_155 :: Background256
- color256_b_156 :: Background256
- color256_b_157 :: Background256
- color256_b_158 :: Background256
- color256_b_159 :: Background256
- color256_b_160 :: Background256
- color256_b_161 :: Background256
- color256_b_162 :: Background256
- color256_b_163 :: Background256
- color256_b_164 :: Background256
- color256_b_165 :: Background256
- color256_b_166 :: Background256
- color256_b_167 :: Background256
- color256_b_168 :: Background256
- color256_b_169 :: Background256
- color256_b_170 :: Background256
- color256_b_171 :: Background256
- color256_b_172 :: Background256
- color256_b_173 :: Background256
- color256_b_174 :: Background256
- color256_b_175 :: Background256
- color256_b_176 :: Background256
- color256_b_177 :: Background256
- color256_b_178 :: Background256
- color256_b_179 :: Background256
- color256_b_180 :: Background256
- color256_b_181 :: Background256
- color256_b_182 :: Background256
- color256_b_183 :: Background256
- color256_b_184 :: Background256
- color256_b_185 :: Background256
- color256_b_186 :: Background256
- color256_b_187 :: Background256
- color256_b_188 :: Background256
- color256_b_189 :: Background256
- color256_b_190 :: Background256
- color256_b_191 :: Background256
- color256_b_192 :: Background256
- color256_b_193 :: Background256
- color256_b_194 :: Background256
- color256_b_195 :: Background256
- color256_b_196 :: Background256
- color256_b_197 :: Background256
- color256_b_198 :: Background256
- color256_b_199 :: Background256
- color256_b_200 :: Background256
- color256_b_201 :: Background256
- color256_b_202 :: Background256
- color256_b_203 :: Background256
- color256_b_204 :: Background256
- color256_b_205 :: Background256
- color256_b_206 :: Background256
- color256_b_207 :: Background256
- color256_b_208 :: Background256
- color256_b_209 :: Background256
- color256_b_210 :: Background256
- color256_b_211 :: Background256
- color256_b_212 :: Background256
- color256_b_213 :: Background256
- color256_b_214 :: Background256
- color256_b_215 :: Background256
- color256_b_216 :: Background256
- color256_b_217 :: Background256
- color256_b_218 :: Background256
- color256_b_219 :: Background256
- color256_b_220 :: Background256
- color256_b_221 :: Background256
- color256_b_222 :: Background256
- color256_b_223 :: Background256
- color256_b_224 :: Background256
- color256_b_225 :: Background256
- color256_b_226 :: Background256
- color256_b_227 :: Background256
- color256_b_228 :: Background256
- color256_b_229 :: Background256
- color256_b_230 :: Background256
- color256_b_231 :: Background256
- color256_b_232 :: Background256
- color256_b_233 :: Background256
- color256_b_234 :: Background256
- color256_b_235 :: Background256
- color256_b_236 :: Background256
- color256_b_237 :: Background256
- color256_b_238 :: Background256
- color256_b_239 :: Background256
- color256_b_240 :: Background256
- color256_b_241 :: Background256
- color256_b_242 :: Background256
- color256_b_243 :: Background256
- color256_b_244 :: Background256
- color256_b_245 :: Background256
- color256_b_246 :: Background256
- color256_b_247 :: Background256
- color256_b_248 :: Background256
- color256_b_249 :: Background256
- color256_b_250 :: Background256
- color256_b_251 :: Background256
- color256_b_252 :: Background256
- color256_b_253 :: Background256
- color256_b_254 :: Background256
- color256_b_255 :: Background256
- data StyleCommon = StyleCommon {}
- data Style8 = Style8 {}
- data Style256 = Style256 {}
- defaultStyleCommon :: StyleCommon
- defaultStyle8 :: Style8
- defaultStyle256 :: Style256
- data TextSpec = TextSpec {}
- defaultTextSpec :: TextSpec
- chunkTextSpec :: Chunk -> TextSpec
- chunkText :: Chunk -> Text
- newtype Bold8 = Bold8 {}
- newtype Underline8 = Underline8 {}
- newtype Flash8 = Flash8 {}
- newtype Inverse8 = Inverse8 {}
- newtype Bold256 = Bold256 {}
- newtype Underline256 = Underline256 {}
- newtype Flash256 = Flash256 {
- unFlash256 :: Flash
- newtype Inverse256 = Inverse256 {}
- newtype BoldAll = BoldAll {}
- newtype UnderlineAll = UnderlineAll {}
- newtype FlashAll = FlashAll {
- unFlashAll :: Bool
- newtype InverseAll = InverseAll {
- unInverseAll :: Bool
- data ForegroundAll = ForegroundAll {
- fa8 :: Foreground8
- fa256 :: Foreground256
- data BackgroundAll = BackgroundAll {
- ba8 :: Background8
- ba256 :: Background256
- newtype Bold = Bold {}
- newtype Underline = Underline {
- unUnderline :: Bool
- newtype Flash = Flash {}
- newtype Inverse = Inverse {}
- newtype Background8 = Background8 {}
- newtype Background256 = Background256 {}
- newtype Foreground8 = Foreground8 {}
- newtype Foreground256 = Foreground256 {}
Terminal definitions
Which terminal definition to use.
Dumb | Using this terminal should always succeed. This suppresses all colors. Uesful if output is not going to a TTY, or if you just do not like colors. |
TermName String | Use the terminal with this given name. You might get this from the TERM environment variable, or set it explicitly. A runtime error will result if the terminfo database does not have a definition for this terminal. If this terminal supports 256 colors, then 256 colors are used. If this terminal supports less than 256 colors, but at least 8 colors, then 8 colors are used. Otherwise, no colors are used. |
Gets the terminal definition from the environment. If the
environment does not have a TERM veriable, use Dumb
.
:: Bool | Use True if the user always wants to see colors, even if standard output is not a terminal. Otherwise, use False. |
-> Handle | Check this handle to see if it is a terminal (typically you will use stdout). |
-> IO Term |
Gets the terminal definition from the environment. If the first argument is True, the terminal is always obtained from the environment. If it is False, the terminal is only obtained from the environment if the given handle is not a terminal; otherwise, Dumb is returned.
Chunks
A chunk is some textual data coupled with a description of what color the text is, attributes like whether it is bold or underlined, etc. The chunk knows what foreground and background colors and what attributes to use for both an 8 color terminal and a 256 color terminal. To change these attributes and colors, you must make a new chunk.
There is no way to combine chunks. To print large numbers of
chunks, lazily build a list of them and then print them using
printChunks
.
Makes a plain Chunk; that is, one that has no effects and is printed in the default foreground and background color for the terminal. Modify this chunk so that it has the colors and effects that you want.
Printing chunks
printChunks :: Term -> [Chunk] -> IO ()Source
Sends a list of chunks to standard output for printing. Sets up the terminal (this only needs to be done once.) Lazily processes the list of Chunk.
Which colors are used depends upon the Term
. If it is Dumb
,
then no colors are used on output. If the Term
is specified with
TermName
, the UNIX terminfo library is used to determine how many
colors the terminal supports. If it supports at least 256 colors,
then 256 colors are used. If it supports at least 8 colors but less
than 256 colors, then 256 colors are used. Otherwise, no colors are
used. A runtime error will occur if the TermName
is not found in
the system terminal database.
hPrintChunks :: Handle -> Term -> [Chunk] -> IO ()Source
Sends a list of chunks to the given handle for printing. Sets up
the terminal (this only needs to be done once.) Lazily processes
the list of Chunk. See printChunks
for notes on how many colors
are used.
Mod
A Mod is anything capable of modifying a Chunk. Usually these
will modify the TextSpec, though a few Mod instead modify the Text
itself. Typically you will create a Chunk with plain
and then use
+.+
repeatedly to modify the Chunk to suit your needs.
changeChunk :: Chunk -> a -> ChunkSource
Mod Text | When used as a modifier, a Text will replace the text within a Chunk with new text. {-# LANGUAGE OverloadedStrings #-} goodbyeWorld :: Chunk goodbyeWorld = plain "Hello world!" +.+ "Goodbye world!" |
Mod BackgroundAll | |
Mod ForegroundAll | |
Mod InverseAll | |
Mod FlashAll | |
Mod UnderlineAll | |
Mod BoldAll | |
Mod Inverse256 | |
Mod Flash256 | |
Mod Underline256 | |
Mod Bold256 | |
Mod Inverse8 | |
Mod Flash8 | |
Mod Underline8 | |
Mod Bold8 | |
Mod Foreground256 | |
Mod Foreground8 | |
Mod Background256 | |
Mod Background8 | |
Mod ChangeText |
newtype ChangeText Source
Useful if you want to inspect the text in a Chunk and then build a new Chunk with different text.
{-# LANGUAGE OverloadedStrings #-} import Data.Text (append) helloDolly :: Chunk helloDolly = plain "Hello" +.+ ChangeText (`append` " Dolly")
ChangeText | |
|
(.+.) :: Mod a => (Chunk -> Chunk) -> a -> Chunk -> ChunkSource
Composes modifiers. Useful to build up a single function that
modifies a Chunk. You might use this to build up several modifiers
and use them repeatedly, or you might write an API that expects
functions of type Chunk -> Chunk
and then you could use .+.
to
build those functions. Left associative.
redBoldUnderline :: Chunk -> Chunk redBoldUnderline = id .+. f_red .+. bold .+. underline
Effects for both 8 and 256 color terminals
These modifiers affect both 8 and 256 color terminals:
{-# LANGUAGE OverloadedStrings #-} underlinedOn8and256 :: Chunk underlinedOn8and256 = plain "Underlined!" +.+ underline
There are also modifiers to turn an effect off, such as
boldOff
. Ordinarily you will not need these because each chunk
starts with no effects, so you only need to turn on the effects
you want. However the off
modifiers are here if you need them.
Effects for 8-color terminals only
These modifiers affect 8-color terminals only. For instance this appears bold only on an 8-color terminal:
{-# LANGUAGE OverloadedStrings #-} boldOn8 :: Chunk boldOn8 = plain "Bold on 8 color terminal only" +.+ bold8
Effects for 256-color terminals only
These modifiers affect 256-color terminals only. For instance, this text is underlined on 256 color terminals but is bold on 8-color terminals:
{-# LANGUAGE OverloadedStrings #-} underlinedOn256 :: Chunk underlinedOn256 = plain "Underlined on 256 color terminal" +.+ underlined256 +.+ bold8
Colors for both 8 and 256 color terminals
These color modifiers affect both 8 and 256 color terminals. For example, to print something in red on blue on both an 8 and a 256 color terminal:
{-# LANGUAGE OverloadedStrings #-} redHello :: Chunk redHello = plain "Hello world!" +.+ f_red +.+ b_blue
Foreground colors
Background colors
Specific colors
8 color foreground colors
8 color background colors
256 color foreground colors
The color names assume a palette similar to the default one that xterm uses.
256 color background colors
The color names assume a palette similar to the default one that xterm uses.
Create your own colors
Style, TextSpec, and Chunk innards
A style is a bundle of attributes that describes text attributes, such as its color and whether it is bold.
Ordinarily you shouldn't need to use these types but they are here in case they are useful; in particular, you can use them to examine a Chunk's TextSpec to see what its characteristics are.
data StyleCommon Source
Style elements that apply in both 8 and 256 color terminals. However, the elements are described separately for 8 and 256 color terminals, so that the text appearance can change depending on how many colors a terminal has.
Describes text appearance (foreground and background colors, as well as other attributes such as bold) for an 8 color terminal.
Describes text appearance (foreground and background colors, as well as other attributes such as bold) for a 256 color terminal.
defaultStyleCommon :: StyleCommonSource
Has all bold, flash, underline, and inverse turned off.
Uses the default terminal colors (which will vary depending on the terminal).
defaultStyle256 :: Style256Source
Uses the default terminal colors (which will vary depending on the terminal).
The TextSpec bundles together the styles for the 8 and 256 color terminals, so that the text can be portrayed on any terminal.
defaultTextSpec :: TextSpecSource
A TextSpec with the default colors on 8 and 256 color terminals, with all attributes turned off.
chunkTextSpec :: Chunk -> TextSpecSource
Basement
Ordinarily you will not need the things down here. Instead, the definitions above will give you an instance of Mod that will create the effect or color you need.
Modifier newtype wrappers
newtype Underline8 Source
newtype Underline256 Source
newtype Inverse256 Source
newtype UnderlineAll Source
newtype InverseAll Source
Wrappers for effects
Wrappers for colors
Definitions are provided above that give you every possible
color; however, these constructors are exported in case you want
to make your own colors instead. Use at your own risk, as you can
create non-sensical colors with this (such as 256-color colors in
a Background8
.)
newtype Background8 Source
Background color in an 8 color setting.
newtype Background256 Source
Background color in a 256 color setting.
newtype Foreground8 Source
Foreground color in an 8 color setting.
newtype Foreground256 Source
Foreground color in a 256 color setting.