Merge: Tests nitg --semi-global
[nit.git] / lib / console.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 # Simple numerical statistical analysis and presentation
16 module console
17
18 # Redef String class to add a function to color the string
19 redef class String
20 private fun add_escape_char(escapechar: String): String do
21 return "{escapechar}{self}{esc}[0m"
22 end
23
24 private fun esc: Char do return 27.ascii
25 fun gray: String do return add_escape_char("{esc}[30m")
26 fun red: String do return add_escape_char("{esc}[31m")
27 fun green: String do return add_escape_char("{esc}[32m")
28 fun yellow: String do return add_escape_char("{esc}[33m")
29 fun blue: String do return add_escape_char("{esc}[34m")
30 fun purple: String do return add_escape_char("{esc}[35m")
31 fun cyan: String do return add_escape_char("{esc}[36m")
32 fun light_gray: String do return add_escape_char("{esc}[37m")
33 fun bold: String do return add_escape_char("{esc}[1m")
34 fun underline: String do return add_escape_char("{esc}[4m")
35 end
36