|
|
1.1 root 1: input = cluster is peek, % peek a char
2: getc, % read a char
3: pending, % any input ready ?
4: pending_wait, % wait a while for input
5: copy_wait, % wait for raster_copy done
6: push, % push back on input
7: in_macro, % test if in macro
8: still_macro, % test if still macro chars
9: push_macro, % push macro back on input
10: flush_macro, % flush any macro input
11: bpos, % button position
12: set_highlight, % control highlight
13: chan, % input chan
14: reset
15:
16: rep = null % own data is what is important
17:
18: inputs = KeyPressed + ButtonPressed + ButtonReleased
19: exposures = ExposeRegion + ExposeWindow + ExposeCopy
20:
21: downs = sequence[string]$["\362\361\363\366\360\365\370\370",
22: "\355\351\352\356\350\353\357\357",
23: "\354\342\344\346\341\345\347\347"]
24: ups = sequence[string]$["\322\321\323\326\320\325\330\330",
25: "\315\311\312\316\310\313\317\317",
26: "\314\302\304\306\301\305\307\307"]
27:
28: own peeks: act
29: own rstart: int
30: own copies: int
31: own dones: int
32: own xpos: int
33: own ypos: int
34: own highlight: bool
35: own ev: event
36:
37: peek = proc () returns (char)
38: return(act$top(peeks))
39: except when bounds: end
40: c: char := getchar()
41: act$addh(peeks, c)
42: return(c)
43: end peek
44:
45: getc = proc () returns (char)
46: if act$empty(peeks)
47: then return(getchar())
48: else return(act$remh(peeks))
49: end
50: end getc
51:
52: pending = proc () returns (bool)
53: return(~act$empty(peeks) cor cpending())
54: end pending
55:
56: pending_wait = proc () returns (bool)
57: if ~act$empty(peeks)
58: then return(true)
59: else for i: int in int$from_to_by(1000, 1, -1) do
60: if cpending()
61: then return(true) end
62: end
63: return(false)
64: end
65: end pending_wait
66:
67: copy_wait = proc ()
68: copies := copies + 1
69: while copies > dones do
70: x_input$mdeq(exposures, ev)
71: if ev.kind = ExposeCopy
72: then dones := dones + 1
73: else screen$redisplay(ev.win, ev.x, ev.y, ev.x0, ev.y0)
74: end
75: end
76: end copy_wait
77:
78: cpending = proc () returns (bool)
79: while x_input$pending() do
80: x_input$deq(ev)
81: if ev.kind = KeyPressed
82: then act$addh(peeks, x_keymap$getc(ev.value, ev.mask))
83: except when none: continue
84: when multi (s: string):
85: for i: int in int$from_to_by(string$size(s), 1, -1) do
86: act$addh(peeks, s[i])
87: end
88: end
89: return(true)
90: end
91: if ev.kind = ButtonPressed
92: then act$addh(peeks, downs[ev.value + 1][ev.mask / 2**12 + 1])
93: xpos, ypos := screen$position(ev.x, ev.y)
94: act$addh(peeks, esc)
95: return(true)
96: end
97: if ev.kind = ButtonReleased
98: then act$addh(peeks, ups[ev.value + 1][ev.mask / 2**12 + 1])
99: xpos, ypos := screen$position(ev.x, ev.y)
100: act$addh(peeks, esc)
101: return(true)
102: end
103: if ev.kind = ExposeCopy
104: then dones := dones + 1
105: elseif ev.kind = UnmapWindow
106: then copies := copies - 1
107: copy_wait()
108: screen$unmapped(ev.win)
109: elseif ev.kind ~= MouseMoved
110: then screen$redisplay(ev.win, ev.x, ev.y, ev.x0, ev.y0) end
111: end
112: return(false)
113: end cpending
114:
115: getchar = proc () returns (char)
116: rstart := -1
117: high: bool := false
118: while true do
119: if highlight cand ~high cand ~x_input$pending()
120: then high := true
121: screen$highlight(true)
122: end
123: x_input$deq(ev)
124: if ev.kind = MouseMoved
125: then if highlight
126: then high := true
127: screen$highlight(true)
128: end
129: continue
130: end
131: if high
132: then high := false
133: screen$highlight(false)
134: end
135: if ev.kind = KeyPressed
136: then return(x_keymap$getc(ev.value, ev.mask))
137: except when none: continue
138: when multi (s: string):
139: for i: int in int$from_to_by(string$size(s), 2, -1) do
140: act$addh(peeks, s[i])
141: end
142: return(s[1])
143: end
144: end
145: if ev.kind = ButtonPressed
146: then act$addh(peeks, downs[ev.value + 1][ev.mask / 2**12 + 1])
147: xpos, ypos := screen$position(ev.x, ev.y)
148: return(esc)
149: end
150: if ev.kind = ButtonReleased
151: then act$addh(peeks, ups[ev.value + 1][ev.mask / 2**12 + 1])
152: xpos, ypos := screen$position(ev.x, ev.y)
153: return(esc)
154: end
155: if ev.kind = ExposeCopy
156: then dones := dones + 1
157: elseif ev.kind = UnmapWindow
158: then copies := copies - 1
159: copy_wait()
160: screen$unmapped(ev.win)
161: else screen$redisplay(ev.win, ev.x, ev.y, ev.x0, ev.y0) end
162: end
163: end getchar
164:
165: push = proc (c: char)
166: if rstart > act$size(peeks)
167: then rstart := -1 end
168: act$addh(peeks, c)
169: end push
170:
171: in_macro = proc () returns (bool)
172: return(rstart >= 0 cand rstart <= act$size(peeks))
173: end in_macro
174:
175: still_macro = proc () returns (bool)
176: return(rstart >= 0 cand rstart < act$size(peeks))
177: end still_macro
178:
179: push_macro = proc (s: string)
180: if ~string$empty(s)
181: then z: int := act$size(peeks)
182: if rstart < 0 cor rstart > z then rstart := z end
183: for i: int in int$from_to_by(string$size(s), 1, -1) do
184: act$addh(peeks, s[i])
185: end
186: end
187: end push_macro
188:
189: flush_macro = proc () returns (string)
190: s: string
191: if rstart >= 0 cand rstart < act$size(peeks)
192: then s := _cvt[_bytevec, string](
193: _bytevec$create(act$size(peeks) - rstart))
194: for i: int in int$from_to(1, string$size(s)) do
195: _cvt[string, _bytevec](s)[i] := act$remh(peeks)
196: end
197: else s := ""
198: end
199: rstart := -1
200: return(s)
201: end flush_macro
202:
203: bpos = proc () returns (int, int)
204: return(xpos, ypos)
205: end bpos
206:
207: set_highlight = proc (flag: bool)
208: highlight := flag
209: end set_highlight
210:
211: chan = proc () returns (_chan)
212: return(_chan$nul())
213: end chan
214:
215: reset = proc ()
216: x_keymap$load("")
217: peeks := act$new()
218: rstart := -1
219: copies := -1
220: dones := 0
221: xpos := 0
222: ypos := 0
223: highlight := false
224: ev := x_input$empty_event()
225: end reset
226:
227: end input
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.