/
TextColor.class.st
114 lines (94 loc) · 2.09 KB
/
TextColor.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
"
A TextColor encodes a text color change applicable over a given range of text.
"
Class {
#name : #TextColor,
#superclass : #TextAttribute,
#instVars : [
'color'
],
#category : #'Text-Core-Attributes'
}
{ #category : #constants }
TextColor class >> black [
^ self new color: Color black
]
{ #category : #constants }
TextColor class >> blue [
^ self new color: Color blue
]
{ #category : #'instance creation' }
TextColor class >> color: aColor [
^ self new color: aColor
]
{ #category : #constants }
TextColor class >> cyan [
^ self new color: Color cyan
]
{ #category : #constants }
TextColor class >> gray [
^ self new color: Color gray
]
{ #category : #constants }
TextColor class >> green [
^ self new color: Color green
]
{ #category : #constants }
TextColor class >> magenta [
^ self new color: Color magenta
]
{ #category : #constants }
TextColor class >> red [
^ self new color: Color red
]
{ #category : #'instance creation' }
TextColor class >> scanFrom: strm [
"read a color in the funny format used by Text styles on files. c125000255 or cblue;"
| r g b |
strm peek isDigit
ifTrue:
[r := (strm next: 3) asNumber.
g := (strm next: 3) asNumber.
b := (strm next: 3) asNumber.
^ self color: (Color r: r g: g b: b range: 255)].
"A name of a color"
^ self color: (Color perform: (strm upTo: $;) asSymbol)
]
{ #category : #constants }
TextColor class >> white [
^ self new color: Color white
]
{ #category : #constants }
TextColor class >> yellow [
^ self new color: Color yellow
]
{ #category : #comparing }
TextColor >> = other [
^ (other class == self class)
and: [other color = color]
]
{ #category : #converting }
TextColor >> asColor [
^ color
]
{ #category : #accessing }
TextColor >> color [
^ color
]
{ #category : #accessing }
TextColor >> color: aColor [
color := aColor
]
{ #category : #scanning }
TextColor >> dominates: other [
^ other class == self class
]
{ #category : #comparing }
TextColor >> hash [
^ color hash
]
{ #category : #printing }
TextColor >> printOn: aStream [
super printOn: aStream.
aStream nextPutAll: ' code: '; print: color
]