Safe Haskell | Safe-Infered |
---|
Handles colors and special effects for text. This module was written using the control sequences documented for xterm in ctlseqs.txt, which is included in the xterm source code (on Debian GNU/Linux systems, it is at /usr/share/doc/xterm/ctlseqs.txt.gz). The code in here should also work for any terminal which recognizes ISO 6429 escape sequences (also known as ANSI escape sequences), but only for 8 colors. This module also generates sequences for 256 color xterms; though this works fine with xterm, it might not work on other terminals (I believe it works for other terminals commonly found on Linux systems, such as gnome-terminal and Konsole, but I have not tested these terminals as I do not use them.) Perhaps it also works on Windows or Mac OS X systems and their terminals, though I have not tested them (in particular, Windows could be problematic as not all Windows terminals support ISO 6429.)
In theory there are more portable ways to generate color codes, such as through curses (or is it ncurses?) but support for ISO 6429 is widespread enough that I am prepared to say that if your terminal does not support it, too bad; just use the colorless mode.
- data Colors
- data Background8
- data Background256
- data Foreground8
- data Foreground256
- data Chunk
- chunk :: TextSpec -> Text -> Chunk
- newtype Width = Width {}
- chunkWidth :: Chunk -> Width
- chunksToText :: Colors -> [Chunk] -> Text
- newtype Bold = Bold {}
- newtype Underline = Underline {
- unUnderline :: Bool
- newtype Flash = Flash {}
- newtype Inverse = Inverse {}
- data StyleCommon = StyleCommon {}
- data Style8 = Style8 {}
- data Style256 = Style256 {}
- defaultStyleCommon :: StyleCommon
- defaultStyle8 :: Style8
- defaultStyle256 :: Style256
- data TextSpec = TextSpec {}
- defaultTextSpec :: TextSpec
- 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_1 :: Foreground256
- color256_f_2 :: Foreground256
- color256_f_3 :: Foreground256
- color256_f_4 :: Foreground256
- color256_f_5 :: Foreground256
- color256_f_6 :: Foreground256
- color256_f_7 :: Foreground256
- color256_f_8 :: Foreground256
- color256_f_9 :: Foreground256
- color256_f_10 :: Foreground256
- color256_f_11 :: Foreground256
- color256_f_12 :: Foreground256
- color256_f_13 :: Foreground256
- color256_f_14 :: Foreground256
- color256_f_15 :: 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_1 :: Background256
- color256_b_2 :: Background256
- color256_b_3 :: Background256
- color256_b_4 :: Background256
- color256_b_5 :: Background256
- color256_b_6 :: Background256
- color256_b_7 :: Background256
- color256_b_8 :: Background256
- color256_b_9 :: Background256
- color256_b_10 :: Background256
- color256_b_11 :: Background256
- color256_b_12 :: Background256
- color256_b_13 :: Background256
- color256_b_14 :: Background256
- color256_b_15 :: 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
Colors
data Background8 Source
Background color in an 8 color setting.
data Background256 Source
Background color in a 256 color setting.
data Foreground8 Source
Foreground color in an 8 color setting.
data Foreground256 Source
Foreground color in a 256 color setting.
Chunks
A chunk is some textual data coupled with a description of what color the text is. The chunk knows what colors to use for both foreground color and background color, in both an 8 color terminal and a 256 color terminal. The chunk has only one set of color descriptions. To change colors, you must use 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 chunksToText.
How wide the text of a chunk is.
chunkWidth :: Chunk -> WidthSource
chunksToText :: Colors -> [Chunk] -> TextSource
Transforms chunks to a lazy Text. This function runs lazily and in constant time and space.
Effects
Style and TextSpec
A style is a bundle of attributes that describes text attributes, such as its color and whether it is bold.
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.