blob: 0be42da56cef94f2592ecd3fbe1eed4a180deecb [file] [log] [blame]
David K. Bainbridge528b3182017-01-23 08:51:59 -08001// Copyright 2016 Canonical Ltd.
2// Licensed under the LGPLv3, see LICENCE file for details.
3
4package ansiterm
5
6const (
7 _ Style = iota
8 Bold
9 Faint
10 Italic
11 Underline
12 Blink
13 Reverse
14 Strikethrough
15 Conceal
16)
17
18type Style int
19
20func (s Style) String() string {
21 switch s {
22 case Bold:
23 return "bold"
24 case Faint:
25 return "faint"
26 case Italic:
27 return "italic"
28 case Underline:
29 return "underline"
30 case Blink:
31 return "blink"
32 case Reverse:
33 return "reverse"
34 case Strikethrough:
35 return "strikethrough"
36 case Conceal:
37 return "conceal"
38 default:
39 return ""
40 }
41}
42
43func (s Style) enable() attribute {
44 switch s {
45 case Bold:
46 return 1
47 case Faint:
48 return 2
49 case Italic:
50 return 3
51 case Underline:
52 return 4
53 case Blink:
54 return 5
55 case Reverse:
56 return 7
57 case Conceal:
58 return 8
59 case Strikethrough:
60 return 9
61 default:
62 return unknownAttribute
63 }
64}
65
66func (s Style) disable() attribute {
67 value := s.enable()
68 if value != unknownAttribute {
69 return value + 20
70 }
71 return value
72}