This repository has been archived by the owner on Aug 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtcell.go
164 lines (149 loc) · 3.41 KB
/
tcell.go
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// +build !sdl,!js
package main
import (
"runtime"
"github.com/anaseto/gruid"
"github.com/anaseto/gruid-tcell"
tc "github.com/gdamore/tcell/v2"
)
const Tiles = false
func (md *model) ApplyToggleTiles() {
// do nothing
}
func (md *model) updateZoom() {
// do nothing
}
var driver gruid.Driver
var color8 bool
func initDriver(fullscreen bool) {
st := styler{}
dr := tcell.NewDriver(tcell.Config{StyleManager: st})
//dr.PreventQuit()
driver = dr
Terminal = true
if runtime.GOOS == "windows" {
color8 = true
}
}
// styler implements the tcell.StyleManager interface.
type styler struct{}
func (sty styler) GetStyle(cst gruid.Style) tc.Style {
st := tc.StyleDefault
if Xterm256Color {
cst.Fg = map16ColorTo256(cst.Fg, true)
cst.Bg = map16ColorTo256(cst.Bg, false)
st = st.Background(tc.ColorValid + tc.Color(cst.Bg)).Foreground(tc.ColorValid + tc.Color(cst.Fg))
} else {
if !GameConfig.DarkLOS {
cst.Fg = map16ColorToLight(cst.Fg)
cst.Bg = map16ColorToLight(cst.Bg)
}
if color8 {
cst.Fg = map16ColorTo8Color(cst.Fg)
cst.Bg = map16ColorTo8Color(cst.Bg)
}
fg := tc.Color(cst.Fg)
bg := tc.Color(cst.Bg)
if cst.Bg == gruid.ColorDefault {
st = st.Background(tc.ColorDefault)
} else {
st = st.Background(tc.ColorValid + bg - 1)
}
if cst.Fg == gruid.ColorDefault {
st = st.Foreground(tc.ColorDefault)
} else {
st = st.Foreground(tc.ColorValid + fg - 1)
}
}
if cst.Attrs&AttrReverse != 0 {
st = st.Reverse(true)
}
return st
}
func map16ColorTo8Color(c gruid.Color) gruid.Color {
if c >= 1+8 {
c -= 8
}
return c
}
func map16ColorToLight(c gruid.Color) gruid.Color {
switch c {
case ColorBackgroundSecondary:
return ColorForegroundEmph
case ColorForegroundSecondary:
return ColorBackgroundSecondary
case ColorForegroundEmph:
return 1 + 0
default:
return c
}
}
// xterm solarized colors: http://ethanschoonover.com/solarized
const (
Color256Base03 gruid.Color = 234
Color256Base02 gruid.Color = 235
Color256Base01 gruid.Color = 240
Color256Base00 gruid.Color = 241 // for dark on light background
Color256Base0 gruid.Color = 244
Color256Base1 gruid.Color = 245
Color256Base2 gruid.Color = 254
Color256Base3 gruid.Color = 230
Color256Yellow gruid.Color = 136
Color256Orange gruid.Color = 166
Color256Red gruid.Color = 160
Color256Magenta gruid.Color = 125
Color256Violet gruid.Color = 61
Color256Blue gruid.Color = 33
Color256Cyan gruid.Color = 37
Color256Green gruid.Color = 64
)
func map16ColorTo256(c gruid.Color, fg bool) gruid.Color {
switch c {
case ColorBackground:
if fg {
if GameConfig.DarkLOS {
return Color256Base0
}
return Color256Base00
}
if GameConfig.DarkLOS {
return Color256Base03
}
return Color256Base3
case ColorBackgroundSecondary:
if GameConfig.DarkLOS {
return Color256Base02
}
return Color256Base2
case ColorForegroundEmph:
if GameConfig.DarkLOS {
return Color256Base1
}
return Color256Base01
case ColorForegroundSecondary:
if GameConfig.DarkLOS {
return Color256Base01
}
return Color256Base1
case ColorYellow:
return Color256Yellow
case ColorOrange:
return Color256Orange
case ColorRed:
return Color256Red
case ColorMagenta:
return Color256Magenta
case ColorViolet:
return Color256Violet
case ColorBlue:
return Color256Blue
case ColorCyan:
return Color256Cyan
case ColorGreen:
return Color256Green
default:
return c
}
}
func clearCache() {
}