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 Chunk
s 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.
A Chunk
is a Monoid
, so you can combine them using the usual
monoid functions, including <>
. You can create a Chunk
with
text using fromString
, but this library is much more usable if
you enable the OverloadedStrings GHC extension:
{-# LANGUAGE OverloadedStrings #-}
and all future examples assume you have enabled OverloadedStrings.
Here are some basic examples:
putChunkLn $ "Some blue text" <> f_blue putChunkLn $ "Blue on red background" <> f_blue <> b_red putChunkLn $ "Blue on red, foreground bold" <> f_blue <> b_red <> bold
But what makes Rainbow a little more interesting is that you can
also specify output for 256-color terminals. To use these examples,
be sure your TERM environment variable is set to something that
supports 256 colors (like xterm-256color
) before you start GHCi:
putChunkLn $ "Blue on 8-color terminal, red on 256-color terminal" <> c8_f_blue <> c256_f_red
If mappend
multiple chunks that change the same property, the
rightmost one "wins":
putChunkLn $ "This will be blue" <> f_red <> f_blue
This property comes in handy if you want to specify a default color for 8- and 256-color terminals, then a more specific shade for a 256-color terminal:
putChunkLn $ "Pink" <> f_red <> c256_f_201
However, if you use mappend
to add additional Chunk
s that have
text, the text will be appended:
putChunkLn $ f_green <> "You will see this text " <> "and this text too, but it will all be blue" <> f_blue
Although one chunk can have different colors on 8- and 256-color terminals, it cannot have different colors on the same terminal. That is, if you want to print some text in one color and some text in another color, make two chunks.
- data Term
- termFromEnv :: IO Term
- smartTermFromEnv :: Bool -> Handle -> IO Term
- data Chunk = Chunk {}
- putChunks :: Term -> [Chunk] -> IO ()
- hPutChunks :: Handle -> Term -> [Chunk] -> IO ()
- putChunk :: Chunk -> IO ()
- putChunkLn :: Chunk -> IO ()
- hPutChunk :: Handle -> Chunk -> IO ()
- hPutChunkLn :: Handle -> Chunk -> IO ()
- bold :: Chunk
- boldOff :: Chunk
- underline :: Chunk
- underlineOff :: Chunk
- flash :: Chunk
- flashOff :: Chunk
- inverse :: Chunk
- inverseOff :: Chunk
- bold8 :: Chunk
- bold8off :: Chunk
- underline8 :: Chunk
- underline8off :: Chunk
- flash8 :: Chunk
- flash8off :: Chunk
- inverse8 :: Chunk
- inverse8off :: Chunk
- bold256 :: Chunk
- bold256off :: Chunk
- underline256 :: Chunk
- underline256off :: Chunk
- flash256 :: Chunk
- flash256off :: Chunk
- inverse256 :: Chunk
- inverse256off :: Chunk
- f_default :: Chunk
- f_black :: Chunk
- f_red :: Chunk
- f_green :: Chunk
- f_yellow :: Chunk
- f_blue :: Chunk
- f_magenta :: Chunk
- f_cyan :: Chunk
- f_white :: Chunk
- b_default :: Chunk
- b_black :: Chunk
- b_red :: Chunk
- b_green :: Chunk
- b_yellow :: Chunk
- b_blue :: Chunk
- b_magenta :: Chunk
- b_cyan :: Chunk
- b_white :: Chunk
- c8_f_default :: Chunk
- c8_f_black :: Chunk
- c8_f_red :: Chunk
- c8_f_green :: Chunk
- c8_f_yellow :: Chunk
- c8_f_blue :: Chunk
- c8_f_magenta :: Chunk
- c8_f_cyan :: Chunk
- c8_f_white :: Chunk
- c8_b_default :: Chunk
- c8_b_black :: Chunk
- c8_b_red :: Chunk
- c8_b_green :: Chunk
- c8_b_yellow :: Chunk
- c8_b_blue :: Chunk
- c8_b_magenta :: Chunk
- c8_b_cyan :: Chunk
- c8_b_white :: Chunk
- c256_f_default :: Chunk
- c256_f_0 :: Chunk
- c256_f_black :: Chunk
- c256_f_1 :: Chunk
- c256_f_red :: Chunk
- c256_f_2 :: Chunk
- c256_f_green :: Chunk
- c256_f_3 :: Chunk
- c256_f_yellow :: Chunk
- c256_f_4 :: Chunk
- c256_f_blue :: Chunk
- c256_f_5 :: Chunk
- c256_f_magenta :: Chunk
- c256_f_6 :: Chunk
- c256_f_cyan :: Chunk
- c256_f_7 :: Chunk
- c256_f_white :: Chunk
- c256_f_8 :: Chunk
- c256_f_grey :: Chunk
- c256_f_9 :: Chunk
- c256_f_red_bright :: Chunk
- c256_f_10 :: Chunk
- c256_f_green_bright :: Chunk
- c256_f_11 :: Chunk
- c256_f_yellow_bright :: Chunk
- c256_f_12 :: Chunk
- c256_f_blue_bright :: Chunk
- c256_f_13 :: Chunk
- c256_f_magenta_bright :: Chunk
- c256_f_14 :: Chunk
- c256_f_cyan_bright :: Chunk
- c256_f_15 :: Chunk
- c256_f_white_bright :: Chunk
- c256_f_16 :: Chunk
- c256_f_17 :: Chunk
- c256_f_18 :: Chunk
- c256_f_19 :: Chunk
- c256_f_20 :: Chunk
- c256_f_21 :: Chunk
- c256_f_22 :: Chunk
- c256_f_23 :: Chunk
- c256_f_24 :: Chunk
- c256_f_25 :: Chunk
- c256_f_26 :: Chunk
- c256_f_27 :: Chunk
- c256_f_28 :: Chunk
- c256_f_29 :: Chunk
- c256_f_30 :: Chunk
- c256_f_31 :: Chunk
- c256_f_32 :: Chunk
- c256_f_33 :: Chunk
- c256_f_34 :: Chunk
- c256_f_35 :: Chunk
- c256_f_36 :: Chunk
- c256_f_37 :: Chunk
- c256_f_38 :: Chunk
- c256_f_39 :: Chunk
- c256_f_40 :: Chunk
- c256_f_41 :: Chunk
- c256_f_42 :: Chunk
- c256_f_43 :: Chunk
- c256_f_44 :: Chunk
- c256_f_45 :: Chunk
- c256_f_46 :: Chunk
- c256_f_47 :: Chunk
- c256_f_48 :: Chunk
- c256_f_49 :: Chunk
- c256_f_50 :: Chunk
- c256_f_51 :: Chunk
- c256_f_52 :: Chunk
- c256_f_53 :: Chunk
- c256_f_54 :: Chunk
- c256_f_55 :: Chunk
- c256_f_56 :: Chunk
- c256_f_57 :: Chunk
- c256_f_58 :: Chunk
- c256_f_59 :: Chunk
- c256_f_60 :: Chunk
- c256_f_61 :: Chunk
- c256_f_62 :: Chunk
- c256_f_63 :: Chunk
- c256_f_64 :: Chunk
- c256_f_65 :: Chunk
- c256_f_66 :: Chunk
- c256_f_67 :: Chunk
- c256_f_68 :: Chunk
- c256_f_69 :: Chunk
- c256_f_70 :: Chunk
- c256_f_71 :: Chunk
- c256_f_72 :: Chunk
- c256_f_73 :: Chunk
- c256_f_74 :: Chunk
- c256_f_75 :: Chunk
- c256_f_76 :: Chunk
- c256_f_77 :: Chunk
- c256_f_78 :: Chunk
- c256_f_79 :: Chunk
- c256_f_80 :: Chunk
- c256_f_81 :: Chunk
- c256_f_82 :: Chunk
- c256_f_83 :: Chunk
- c256_f_84 :: Chunk
- c256_f_85 :: Chunk
- c256_f_86 :: Chunk
- c256_f_87 :: Chunk
- c256_f_88 :: Chunk
- c256_f_89 :: Chunk
- c256_f_90 :: Chunk
- c256_f_91 :: Chunk
- c256_f_92 :: Chunk
- c256_f_93 :: Chunk
- c256_f_94 :: Chunk
- c256_f_95 :: Chunk
- c256_f_96 :: Chunk
- c256_f_97 :: Chunk
- c256_f_98 :: Chunk
- c256_f_99 :: Chunk
- c256_f_100 :: Chunk
- c256_f_101 :: Chunk
- c256_f_102 :: Chunk
- c256_f_103 :: Chunk
- c256_f_104 :: Chunk
- c256_f_105 :: Chunk
- c256_f_106 :: Chunk
- c256_f_107 :: Chunk
- c256_f_108 :: Chunk
- c256_f_109 :: Chunk
- c256_f_110 :: Chunk
- c256_f_111 :: Chunk
- c256_f_112 :: Chunk
- c256_f_113 :: Chunk
- c256_f_114 :: Chunk
- c256_f_115 :: Chunk
- c256_f_116 :: Chunk
- c256_f_117 :: Chunk
- c256_f_118 :: Chunk
- c256_f_119 :: Chunk
- c256_f_120 :: Chunk
- c256_f_121 :: Chunk
- c256_f_122 :: Chunk
- c256_f_123 :: Chunk
- c256_f_124 :: Chunk
- c256_f_125 :: Chunk
- c256_f_126 :: Chunk
- c256_f_127 :: Chunk
- c256_f_128 :: Chunk
- c256_f_129 :: Chunk
- c256_f_130 :: Chunk
- c256_f_131 :: Chunk
- c256_f_132 :: Chunk
- c256_f_133 :: Chunk
- c256_f_134 :: Chunk
- c256_f_135 :: Chunk
- c256_f_136 :: Chunk
- c256_f_137 :: Chunk
- c256_f_138 :: Chunk
- c256_f_139 :: Chunk
- c256_f_140 :: Chunk
- c256_f_141 :: Chunk
- c256_f_142 :: Chunk
- c256_f_143 :: Chunk
- c256_f_144 :: Chunk
- c256_f_145 :: Chunk
- c256_f_146 :: Chunk
- c256_f_147 :: Chunk
- c256_f_148 :: Chunk
- c256_f_149 :: Chunk
- c256_f_150 :: Chunk
- c256_f_151 :: Chunk
- c256_f_152 :: Chunk
- c256_f_153 :: Chunk
- c256_f_154 :: Chunk
- c256_f_155 :: Chunk
- c256_f_156 :: Chunk
- c256_f_157 :: Chunk
- c256_f_158 :: Chunk
- c256_f_159 :: Chunk
- c256_f_160 :: Chunk
- c256_f_161 :: Chunk
- c256_f_162 :: Chunk
- c256_f_163 :: Chunk
- c256_f_164 :: Chunk
- c256_f_165 :: Chunk
- c256_f_166 :: Chunk
- c256_f_167 :: Chunk
- c256_f_168 :: Chunk
- c256_f_169 :: Chunk
- c256_f_170 :: Chunk
- c256_f_171 :: Chunk
- c256_f_172 :: Chunk
- c256_f_173 :: Chunk
- c256_f_174 :: Chunk
- c256_f_175 :: Chunk
- c256_f_176 :: Chunk
- c256_f_177 :: Chunk
- c256_f_178 :: Chunk
- c256_f_179 :: Chunk
- c256_f_180 :: Chunk
- c256_f_181 :: Chunk
- c256_f_182 :: Chunk
- c256_f_183 :: Chunk
- c256_f_184 :: Chunk
- c256_f_185 :: Chunk
- c256_f_186 :: Chunk
- c256_f_187 :: Chunk
- c256_f_188 :: Chunk
- c256_f_189 :: Chunk
- c256_f_190 :: Chunk
- c256_f_191 :: Chunk
- c256_f_192 :: Chunk
- c256_f_193 :: Chunk
- c256_f_194 :: Chunk
- c256_f_195 :: Chunk
- c256_f_196 :: Chunk
- c256_f_197 :: Chunk
- c256_f_198 :: Chunk
- c256_f_199 :: Chunk
- c256_f_200 :: Chunk
- c256_f_201 :: Chunk
- c256_f_202 :: Chunk
- c256_f_203 :: Chunk
- c256_f_204 :: Chunk
- c256_f_205 :: Chunk
- c256_f_206 :: Chunk
- c256_f_207 :: Chunk
- c256_f_208 :: Chunk
- c256_f_209 :: Chunk
- c256_f_210 :: Chunk
- c256_f_211 :: Chunk
- c256_f_212 :: Chunk
- c256_f_213 :: Chunk
- c256_f_214 :: Chunk
- c256_f_215 :: Chunk
- c256_f_216 :: Chunk
- c256_f_217 :: Chunk
- c256_f_218 :: Chunk
- c256_f_219 :: Chunk
- c256_f_220 :: Chunk
- c256_f_221 :: Chunk
- c256_f_222 :: Chunk
- c256_f_223 :: Chunk
- c256_f_224 :: Chunk
- c256_f_225 :: Chunk
- c256_f_226 :: Chunk
- c256_f_227 :: Chunk
- c256_f_228 :: Chunk
- c256_f_229 :: Chunk
- c256_f_230 :: Chunk
- c256_f_231 :: Chunk
- c256_f_232 :: Chunk
- c256_f_233 :: Chunk
- c256_f_234 :: Chunk
- c256_f_235 :: Chunk
- c256_f_236 :: Chunk
- c256_f_237 :: Chunk
- c256_f_238 :: Chunk
- c256_f_239 :: Chunk
- c256_f_240 :: Chunk
- c256_f_241 :: Chunk
- c256_f_242 :: Chunk
- c256_f_243 :: Chunk
- c256_f_244 :: Chunk
- c256_f_245 :: Chunk
- c256_f_246 :: Chunk
- c256_f_247 :: Chunk
- c256_f_248 :: Chunk
- c256_f_249 :: Chunk
- c256_f_250 :: Chunk
- c256_f_251 :: Chunk
- c256_f_252 :: Chunk
- c256_f_253 :: Chunk
- c256_f_254 :: Chunk
- c256_f_255 :: Chunk
- c256_b_default :: Chunk
- c256_b_0 :: Chunk
- c256_b_black :: Chunk
- c256_b_1 :: Chunk
- c256_b_red :: Chunk
- c256_b_2 :: Chunk
- c256_b_green :: Chunk
- c256_b_3 :: Chunk
- c256_b_yellow :: Chunk
- c256_b_4 :: Chunk
- c256_b_blue :: Chunk
- c256_b_5 :: Chunk
- c256_b_magenta :: Chunk
- c256_b_6 :: Chunk
- c256_b_cyan :: Chunk
- c256_b_7 :: Chunk
- c256_b_white :: Chunk
- c256_b_8 :: Chunk
- c256_b_grey :: Chunk
- c256_b_9 :: Chunk
- c256_b_red_bright :: Chunk
- c256_b_10 :: Chunk
- c256_b_green_bright :: Chunk
- c256_b_11 :: Chunk
- c256_b_yellow_bright :: Chunk
- c256_b_12 :: Chunk
- c256_b_blue_bright :: Chunk
- c256_b_13 :: Chunk
- c256_b_magenta_bright :: Chunk
- c256_b_14 :: Chunk
- c256_b_cyan_bright :: Chunk
- c256_b_15 :: Chunk
- c256_b_white_bright :: Chunk
- c256_b_16 :: Chunk
- c256_b_17 :: Chunk
- c256_b_18 :: Chunk
- c256_b_19 :: Chunk
- c256_b_20 :: Chunk
- c256_b_21 :: Chunk
- c256_b_22 :: Chunk
- c256_b_23 :: Chunk
- c256_b_24 :: Chunk
- c256_b_25 :: Chunk
- c256_b_26 :: Chunk
- c256_b_27 :: Chunk
- c256_b_28 :: Chunk
- c256_b_29 :: Chunk
- c256_b_30 :: Chunk
- c256_b_31 :: Chunk
- c256_b_32 :: Chunk
- c256_b_33 :: Chunk
- c256_b_34 :: Chunk
- c256_b_35 :: Chunk
- c256_b_36 :: Chunk
- c256_b_37 :: Chunk
- c256_b_38 :: Chunk
- c256_b_39 :: Chunk
- c256_b_40 :: Chunk
- c256_b_41 :: Chunk
- c256_b_42 :: Chunk
- c256_b_43 :: Chunk
- c256_b_44 :: Chunk
- c256_b_45 :: Chunk
- c256_b_46 :: Chunk
- c256_b_47 :: Chunk
- c256_b_48 :: Chunk
- c256_b_49 :: Chunk
- c256_b_50 :: Chunk
- c256_b_51 :: Chunk
- c256_b_52 :: Chunk
- c256_b_53 :: Chunk
- c256_b_54 :: Chunk
- c256_b_55 :: Chunk
- c256_b_56 :: Chunk
- c256_b_57 :: Chunk
- c256_b_58 :: Chunk
- c256_b_59 :: Chunk
- c256_b_60 :: Chunk
- c256_b_61 :: Chunk
- c256_b_62 :: Chunk
- c256_b_63 :: Chunk
- c256_b_64 :: Chunk
- c256_b_65 :: Chunk
- c256_b_66 :: Chunk
- c256_b_67 :: Chunk
- c256_b_68 :: Chunk
- c256_b_69 :: Chunk
- c256_b_70 :: Chunk
- c256_b_71 :: Chunk
- c256_b_72 :: Chunk
- c256_b_73 :: Chunk
- c256_b_74 :: Chunk
- c256_b_75 :: Chunk
- c256_b_76 :: Chunk
- c256_b_77 :: Chunk
- c256_b_78 :: Chunk
- c256_b_79 :: Chunk
- c256_b_80 :: Chunk
- c256_b_81 :: Chunk
- c256_b_82 :: Chunk
- c256_b_83 :: Chunk
- c256_b_84 :: Chunk
- c256_b_85 :: Chunk
- c256_b_86 :: Chunk
- c256_b_87 :: Chunk
- c256_b_88 :: Chunk
- c256_b_89 :: Chunk
- c256_b_90 :: Chunk
- c256_b_91 :: Chunk
- c256_b_92 :: Chunk
- c256_b_93 :: Chunk
- c256_b_94 :: Chunk
- c256_b_95 :: Chunk
- c256_b_96 :: Chunk
- c256_b_97 :: Chunk
- c256_b_98 :: Chunk
- c256_b_99 :: Chunk
- c256_b_100 :: Chunk
- c256_b_101 :: Chunk
- c256_b_102 :: Chunk
- c256_b_103 :: Chunk
- c256_b_104 :: Chunk
- c256_b_105 :: Chunk
- c256_b_106 :: Chunk
- c256_b_107 :: Chunk
- c256_b_108 :: Chunk
- c256_b_109 :: Chunk
- c256_b_110 :: Chunk
- c256_b_111 :: Chunk
- c256_b_112 :: Chunk
- c256_b_113 :: Chunk
- c256_b_114 :: Chunk
- c256_b_115 :: Chunk
- c256_b_116 :: Chunk
- c256_b_117 :: Chunk
- c256_b_118 :: Chunk
- c256_b_119 :: Chunk
- c256_b_120 :: Chunk
- c256_b_121 :: Chunk
- c256_b_122 :: Chunk
- c256_b_123 :: Chunk
- c256_b_124 :: Chunk
- c256_b_125 :: Chunk
- c256_b_126 :: Chunk
- c256_b_127 :: Chunk
- c256_b_128 :: Chunk
- c256_b_129 :: Chunk
- c256_b_130 :: Chunk
- c256_b_131 :: Chunk
- c256_b_132 :: Chunk
- c256_b_133 :: Chunk
- c256_b_134 :: Chunk
- c256_b_135 :: Chunk
- c256_b_136 :: Chunk
- c256_b_137 :: Chunk
- c256_b_138 :: Chunk
- c256_b_139 :: Chunk
- c256_b_140 :: Chunk
- c256_b_141 :: Chunk
- c256_b_142 :: Chunk
- c256_b_143 :: Chunk
- c256_b_144 :: Chunk
- c256_b_145 :: Chunk
- c256_b_146 :: Chunk
- c256_b_147 :: Chunk
- c256_b_148 :: Chunk
- c256_b_149 :: Chunk
- c256_b_150 :: Chunk
- c256_b_151 :: Chunk
- c256_b_152 :: Chunk
- c256_b_153 :: Chunk
- c256_b_154 :: Chunk
- c256_b_155 :: Chunk
- c256_b_156 :: Chunk
- c256_b_157 :: Chunk
- c256_b_158 :: Chunk
- c256_b_159 :: Chunk
- c256_b_160 :: Chunk
- c256_b_161 :: Chunk
- c256_b_162 :: Chunk
- c256_b_163 :: Chunk
- c256_b_164 :: Chunk
- c256_b_165 :: Chunk
- c256_b_166 :: Chunk
- c256_b_167 :: Chunk
- c256_b_168 :: Chunk
- c256_b_169 :: Chunk
- c256_b_170 :: Chunk
- c256_b_171 :: Chunk
- c256_b_172 :: Chunk
- c256_b_173 :: Chunk
- c256_b_174 :: Chunk
- c256_b_175 :: Chunk
- c256_b_176 :: Chunk
- c256_b_177 :: Chunk
- c256_b_178 :: Chunk
- c256_b_179 :: Chunk
- c256_b_180 :: Chunk
- c256_b_181 :: Chunk
- c256_b_182 :: Chunk
- c256_b_183 :: Chunk
- c256_b_184 :: Chunk
- c256_b_185 :: Chunk
- c256_b_186 :: Chunk
- c256_b_187 :: Chunk
- c256_b_188 :: Chunk
- c256_b_189 :: Chunk
- c256_b_190 :: Chunk
- c256_b_191 :: Chunk
- c256_b_192 :: Chunk
- c256_b_193 :: Chunk
- c256_b_194 :: Chunk
- c256_b_195 :: Chunk
- c256_b_196 :: Chunk
- c256_b_197 :: Chunk
- c256_b_198 :: Chunk
- c256_b_199 :: Chunk
- c256_b_200 :: Chunk
- c256_b_201 :: Chunk
- c256_b_202 :: Chunk
- c256_b_203 :: Chunk
- c256_b_204 :: Chunk
- c256_b_205 :: Chunk
- c256_b_206 :: Chunk
- c256_b_207 :: Chunk
- c256_b_208 :: Chunk
- c256_b_209 :: Chunk
- c256_b_210 :: Chunk
- c256_b_211 :: Chunk
- c256_b_212 :: Chunk
- c256_b_213 :: Chunk
- c256_b_214 :: Chunk
- c256_b_215 :: Chunk
- c256_b_216 :: Chunk
- c256_b_217 :: Chunk
- c256_b_218 :: Chunk
- c256_b_219 :: Chunk
- c256_b_220 :: Chunk
- c256_b_221 :: Chunk
- c256_b_222 :: Chunk
- c256_b_223 :: Chunk
- c256_b_224 :: Chunk
- c256_b_225 :: Chunk
- c256_b_226 :: Chunk
- c256_b_227 :: Chunk
- c256_b_228 :: Chunk
- c256_b_229 :: Chunk
- c256_b_230 :: Chunk
- c256_b_231 :: Chunk
- c256_b_232 :: Chunk
- c256_b_233 :: Chunk
- c256_b_234 :: Chunk
- c256_b_235 :: Chunk
- c256_b_236 :: Chunk
- c256_b_237 :: Chunk
- c256_b_238 :: Chunk
- c256_b_239 :: Chunk
- c256_b_240 :: Chunk
- c256_b_241 :: Chunk
- c256_b_242 :: Chunk
- c256_b_243 :: Chunk
- c256_b_244 :: Chunk
- c256_b_245 :: Chunk
- c256_b_246 :: Chunk
- c256_b_247 :: Chunk
- c256_b_248 :: Chunk
- c256_b_249 :: Chunk
- c256_b_250 :: Chunk
- c256_b_251 :: Chunk
- c256_b_252 :: Chunk
- c256_b_253 :: Chunk
- c256_b_254 :: Chunk
- c256_b_255 :: Chunk
- class Monoid a where
- (<>) :: Monoid m => m -> m -> m
- class IsString a where
- fromString :: String -> a
- data StyleCommon = StyleCommon {}
- data Style8 = Style8 {}
- data Style256 = Style256 {}
- data TextSpec = TextSpec {}
- type Background8 = Last (Maybe Color)
- type Background256 = Last (Maybe Color)
- type Foreground8 = Last (Maybe Color)
- type Foreground256 = Last (Maybe Color)
- scBold :: Lens' StyleCommon (Last Bool)
- scUnderline :: Lens' StyleCommon (Last Bool)
- scFlash :: Lens' StyleCommon (Last Bool)
- scInverse :: Lens' StyleCommon (Last Bool)
- foreground8 :: Lens' Style8 Foreground8
- background8 :: Lens' Style8 Background8
- common8 :: Lens' Style8 StyleCommon
- foreground256 :: Lens' Style256 Foreground256
- background256 :: Lens' Style256 Background256
- common256 :: Lens' Style256 StyleCommon
- textSpec :: Lens' Chunk TextSpec
- text :: Lens' Chunk Text
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.
Printing chunks
putChunks :: 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.
hPutChunks :: 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 putChunks
for notes on how many colors
are used.
Printing one chunk at a time
These functions make it easy to print one chunk at a time. Each function initializes the terminal once for each chunk, unlike the list-oriented functions, which only initialize the terminal once. (Initialization does not clear the screen; rather, it is a process that the terminfo library requires.) Thus there might be a performance penalty for using these functions to print large numbers of chunks. Or, there might not be--I have not benchmarked them.
These functions use the default terminal, obtained using
termFromEnv
.
putChunkLn :: Chunk -> IO ()Source
Print one chunk at a time, to standard output, append a newline
hPutChunkLn :: Handle -> Chunk -> IO ()Source
Print one chunk at a time, to a handle, append a newline
Effects for both 8 and 256 color terminals
These Chunk
s affect both 8 and 256 color terminals:
putChunkLn $ "bold on 8 and 256 color terminals" <> bold
There are also Chunk
s 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
Chunk
s are here if you need them.
Bold. What actually happens when you use Bold is going to depend
on your terminal. For example, xterm allows you actually use a bold
font for bold, if you have one. Otherwise, it might simulate bold
by using overstriking. Another possibility is that your terminal
might use a different color to indicate bold. For more details (at
least for xterm), look at xterm (1) and search for boldColors
.
If your terminal uses a different color for bold, this allows an 8-color terminal to really have 16 colors.
Effects for 8-color terminals only
These Chunk
s affect 8-color terminals only.
putChunkLn $ "Bold on 8 color terminal only" <> bold8
Effects for 256-color terminals only
These Chunk
s affect 256-color terminals only.
putChunkLn $ "Underlined on 256-color terminal, " <> "bold on 8-color terminal" <> underlined256 <> bold8
Colors for both 8 and 256 color terminals
These Chunk
s affect both 8 and 256 color
terminals.
putChunkLn $ "Red on blue" <> 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.
Re-exports
class Monoid a where
The class of monoids (types with an associative binary operation that has an identity). Instances should satisfy the following laws:
mappend mempty x = x
mappend x mempty = x
mappend x (mappend y z) = mappend (mappend x y) z
mconcat =
foldr
mappend mempty
The method names refer to the monoid of lists under concatenation, but there are many other instances.
Minimal complete definition: mempty
and mappend
.
Some types can be viewed as a monoid in more than one way,
e.g. both addition and multiplication on numbers.
In such cases we often define newtype
s and make those instances
of Monoid
, e.g. Sum
and Product
.
mempty :: a
Identity of mappend
mappend :: a -> a -> a
An associative operation
mconcat :: [a] -> a
Fold a list using the monoid.
For most types, the default definition for mconcat
will be
used, but the function is included in the class definition so
that an optimized version can be provided for specific types.
Monoid Ordering | |
Monoid () | |
Monoid All | |
Monoid Any | |
Monoid IntSet | |
Monoid Text | |
Monoid Text | |
Monoid TermOutput | |
Monoid StyleCommon | |
Monoid Style8 | |
Monoid Style256 | |
Monoid TextSpec | |
Monoid Chunk | |
Monoid [a] | |
Monoid a => Monoid (Dual a) | |
Monoid (Endo a) | |
Num a => Monoid (Sum a) | |
Num a => Monoid (Product a) | |
Monoid (First a) | |
Monoid (Last a) | |
Monoid a => Monoid (Maybe a) | Lift a semigroup into |
Monoid (Seq a) | |
Monoid (IntMap a) | |
Ord a => Monoid (Set a) | |
Unbox a => Monoid (Vector a) | |
(Hashable a, Eq a) => Monoid (HashSet a) | |
Monoid b => Monoid (a -> b) | |
(Monoid a, Monoid b) => Monoid (a, b) | |
Ord k => Monoid (Map k v) | |
(Eq k, Hashable k) => Monoid (HashMap k v) | |
(Monoid a, Monoid b, Monoid c) => Monoid (a, b, c) | |
Monoid a => Monoid (Tagged k s a) | |
(Monoid a, Monoid b, Monoid c, Monoid d) => Monoid (a, b, c, d) | |
(Monoid a, Monoid b, Monoid c, Monoid d, Monoid e) => Monoid (a, b, c, d, e) |
class IsString a where
Class for string-like datastructures; used by the overloaded string extension (-foverloaded-strings in GHC).
fromString :: String -> a
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.
The TextSpec bundles together the styles for the 8 and 256 color terminals, so that the text can be portrayed on any terminal.
Basement
Ordinarily you will not need the things down here. Instead, the
definitions above will give you a Chunk
that will
create the effect or color you need.
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
.)
type Background8 = Last (Maybe Color)Source
type Background256 = Last (Maybe Color)Source
type Foreground8 = Last (Maybe Color)Source
type Foreground256 = Last (Maybe Color)Source