-
Notifications
You must be signed in to change notification settings - Fork 34
/
globals.go
165 lines (140 loc) · 4.84 KB
/
globals.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
165
package main
import (
"image"
"log"
"os"
"strconv"
"9fans.net/go/plumb"
"github.com/rjkroege/edwood/draw"
"github.com/rjkroege/edwood/frame"
)
// TODO(rjk): Document what each of these are.
type globals struct {
globalincref bool
seq int // undo/redo sequence across all file.OEBs
maxtab uint // size of a tab, in units of the '0' character
tabexpand bool // defines whether to expand tab to spaces
tagfont string
mouse *draw.Mouse
mousectl *draw.Mousectl
keyboardctl *draw.Keyboardctl
modbutton draw.Image
colbutton draw.Image
button draw.Image
but2col draw.Image
but3col draw.Image
// boxcursor Cursor
row Row
seltext *Text
argtext *Text
mousetext *Text // global because Text.Close needs to clear it
typetext *Text // global because Text.Close needs to clear it
barttext *Text // shared between mousethread and keyboardthread
activewin *Window
activecol *Column
snarfbuf []byte
home string
acmeshell string
tagcolors [frame.NumColours]draw.Image
textcolors [frame.NumColours]draw.Image
wdir string
editing int
cplumb chan *plumb.Message
cwait chan ProcessState
ccommand chan *Command
ckill chan string
cxfidalloc chan *Xfid
cxfidfree chan *Xfid
cnewwindow chan *Window
cexit chan struct{}
csignal chan os.Signal
cerr chan error
cedit chan int
cwarn chan uint
editoutlk chan bool
WinID int
}
// Singleton global object.
var global *globals
// Preserve existing global semantics.
// TODO(rjk): Remove this *eventually*.
func init() {
global = makeglobals()
}
func makeglobals() *globals {
g := &globals{
acmeshell: os.Getenv("acmeshell"),
editing: Inactive,
editoutlk: make(chan bool, 1),
cwait: make(chan ProcessState),
ccommand: make(chan *Command),
ckill: make(chan string),
cxfidalloc: make(chan *Xfid),
cxfidfree: make(chan *Xfid),
cnewwindow: make(chan *Window),
csignal: make(chan os.Signal, 1),
cerr: make(chan error),
cedit: make(chan int),
cexit: make(chan struct{}),
cwarn: make(chan uint),
}
if home, err := os.UserHomeDir(); err == nil {
g.home = home
} else {
log.Fatalf("could not get user home directory: %v", err)
}
if pwd, err := os.Getwd(); err == nil {
g.wdir = pwd
} else {
log.Fatalf("could not get working directory: %v", err)
}
p := os.Getenv("tabstop")
if p != "" {
mt, _ := strconv.ParseInt(p, 10, 32)
g.maxtab = uint(mt)
}
if g.maxtab == 0 {
g.maxtab = 4
}
b := os.Getenv("tabexpand")
if b != "" {
te, _ := strconv.ParseBool(b)
g.tabexpand = te
} else {
g.tabexpand = false
}
return g
}
// TODO(rjk): Can separate this out even better.
func (g *globals) iconinit(display draw.Display) {
if g.tagcolors[frame.ColBack] == nil {
g.tagcolors[frame.ColBack] = display.AllocImageMix(draw.Palebluegreen, draw.White)
g.tagcolors[frame.ColHigh], _ = display.AllocImage(image.Rect(0, 0, 1, 1), display.ScreenImage().Pix(), true, draw.Palegreygreen)
g.tagcolors[frame.ColBord], _ = display.AllocImage(image.Rect(0, 0, 1, 1), display.ScreenImage().Pix(), true, draw.Purpleblue)
g.tagcolors[frame.ColText] = display.Black()
g.tagcolors[frame.ColHText] = display.Black()
g.textcolors[frame.ColBack] = display.AllocImageMix(draw.Paleyellow, draw.White)
g.textcolors[frame.ColHigh], _ = display.AllocImage(image.Rect(0, 0, 1, 1), display.ScreenImage().Pix(), true, draw.Darkyellow)
g.textcolors[frame.ColBord], _ = display.AllocImage(image.Rect(0, 0, 1, 1), display.ScreenImage().Pix(), true, draw.Yellowgreen)
g.textcolors[frame.ColText] = display.Black()
g.textcolors[frame.ColHText] = display.Black()
}
// ...
r := image.Rect(0, 0, display.ScaleSize(Scrollwid+ButtonBorder), fontget(g.tagfont, display).Height()+1)
g.button, _ = display.AllocImage(r, display.ScreenImage().Pix(), false, draw.Notacolor)
g.button.Draw(r, g.tagcolors[frame.ColBack], nil, r.Min)
r.Max.X -= display.ScaleSize(ButtonBorder)
g.button.Border(r, display.ScaleSize(ButtonBorder), g.tagcolors[frame.ColBord], image.Point{})
r = g.button.R()
g.modbutton, _ = display.AllocImage(r, display.ScreenImage().Pix(), false, draw.Notacolor)
g.modbutton.Draw(r, g.tagcolors[frame.ColBack], nil, r.Min)
r.Max.X -= display.ScaleSize(ButtonBorder)
g.modbutton.Border(r, display.ScaleSize(ButtonBorder), g.tagcolors[frame.ColBord], image.Point{})
r = r.Inset(display.ScaleSize(ButtonBorder))
tmp, _ := display.AllocImage(image.Rect(0, 0, 1, 1), display.ScreenImage().Pix(), true, draw.Medblue)
g.modbutton.Draw(r, tmp, nil, image.Point{})
r = g.button.R()
g.colbutton, _ = display.AllocImage(r, display.ScreenImage().Pix(), false, draw.Purpleblue)
g.but2col, _ = display.AllocImage(image.Rect(0, 0, 1, 1), display.ScreenImage().Pix(), true, 0xAA0000FF)
g.but3col, _ = display.AllocImage(image.Rect(0, 0, 1, 1), display.ScreenImage().Pix(), true, 0x006600FF)
}