about summary refs log tree commit diff stats
path: root/084console.mu
blob: d566bc275a79941c889e1dbc2c35af27101b3343 (plain) (blame)
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
# Wrappers around interaction primitives that take a potentially fake object
# and are thus easier to test.

exclusive-container event [
  text:char
  keycode:num  # keys on keyboard without a unicode representation
  touch:touch-event  # mouse, track ball, etc.
  resize:resize-event
  # update the assume-console handler if you add more variants
]

container touch-event [
  type:num
  row:num
  column:num
]

container resize-event [
  width:num
  height:num
]

container console [
  current-event-index:num
  events:&:@:event
]

def new-fake-console events:&:@:event -> result:&:console [
  local-scope
  load-ingredients
  result:&:console <- new console:type
  *result <- put *result, events:offset, events
]

def read-event console:&:console -> result:event, found?:bool, quit?:bool, console:&:console [
  local-scope
  load-ingredients
  {
    break-unless console
    current-event-index:num <- get *console, current-event-index:offset
    buf:&:@:event <- get *console, events:offset
    {
      max:num <- length *buf
      done?:bool <- greater-or-equal current-event-index, max
      break-unless done?
      dummy:&:event <- new event:type
      return *dummy, 1/found, 1/quit
    }
    result <- index *buf, current-event-index
    current-event-index <- add current-event-index, 1
    *console <- put *console, current-event-index:offset, current-event-index
    return result, 1/found, 0/quit
  }
  switch  # real event source is infrequent; avoid polling it too much
  result:event, found?:bool <- check-for-interaction
  return result, found?, 0/quit
]

# variant of read-event for just keyboard events. Discards everything that
# isn't unicode, so no arrow keys, page-up/page-down, etc. But you still get
# newlines, tabs, ctrl-d..
def read-key console:&:console -> result:char, found?:bool, quit?:bool, console:&:console [
  local-scope
  load-ingredients
  x:event, found?:bool, quit?:bool, console <- read-event console
  return-if quit?, 0, found?, quit?
  return-unless found?, 0, found?, quit?
  c:char, converted?:bool <- maybe-convert x, text:variant
  return-unless converted?, 0, 0/found, 0/quit
  return c, 1/found, 0/quit
]

def send-keys-to-channel console:&:console, chan:&:sink:char, screen:&:screen -> console:&:console, chan:&:sink:char, screen:&:screen [
  local-scope
  load-ingredients
  {
    c:char, found?:bool, quit?:bool, console <- read-key console
    loop-unless found?
    break-if quit?
    assert c, [invalid event, expected text]
    screen <- print screen, c
    chan <- write chan, c
    loop
  }
  chan <- close chan
]

def wait-for-event console:&:console -> console:&:console [
  local-scope
  load-ingredients
  {
    _, found?:bool <- read-event console
    break-if found?
    switch
    loop
  }
]

# use this helper to skip rendering if there's lots of other events queued up
def has-more-events? console:&:console -> result:bool [
  local-scope
  load-ingredients
  return-if console, 0/false  # fake consoles should be plenty fast; never skip
  result <- interactions-left?
]
'>^
65dc954 ^
c671239 ^

65dc954 ^

30b2e43 ^
f9fd67a ^
30b2e43 ^
65dc954 ^
30b2e43 ^
f9fd67a ^
30b2e43 ^
7648937 ^
30b2e43 ^
30b2e43 ^
f9fd67a ^
2cff2b4 ^
0523d31 ^
2cff2b4 ^
f9fd67a ^
dfd53e4 ^
4612340 ^
dfd53e4 ^
f9fd67a ^
f37aa32 ^
0523d31 ^
65dc954 ^
f37aa32 ^
f9fd67a ^
f9a7d97 ^
f9a7d97 ^

f9fd67a ^
f9a7d97 ^
f2c44b0 ^
f9a7d97 ^



f2c44b0 ^
f9a7d97 ^





65dc954 ^
f2c44b0 ^



65dc954 ^

65dc954 ^












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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
      
                              
                            


                   
                     
 
 






                          
       
                      
 
 
       
                       
                           
                   
 
 
             
                   
                       
 
 



                   
 


                           
                  
                              
 
 


                              
 



                          
                      
 
 



                          
 

                   
 
 








                            
 








                             
       

                           
                   
                   
 
 
       

                           
                   
                   
 
 


               
 


                      
                       


                      
 


                      
 


                       

                           
 
        

                               


           

                               


         

                               


   
                      
 
 
      
                      

                           

                          
 
 
    
                      
 
 
    
                      
                       
 
 
    
                     
 
 
    
                     
 
 
    
                     
                       
 
 
           

                       
 
              
                                    



                                      
                          





                            
 



                           

                           












                               
body {
    background-color: #0B173B;
    font-family: sans-serif;
    color: #ffffff;
    margin: 0 auto;
    max-width: 75%;
    font-size: 1.0em;
}

pre {
    display: block;
    white-space: pre;
    word-break: break-all;
    overflow-x: auto;
}

.date {
    font-weight: bold;
}

#logo {
    text-align: center;
    font-family: monospace;
    font-size: 1em;
}

#navigation {
    margin: 0 auto;
    text-align: center;
}

#navigation table {
    border: 0px;
    width: 100%;
}

#navigation td {
    text-align: center;
    vertical-align: center;
    height: 1.5em;
    background-color: #0B3861;
}

#navigation td:hover {
    background-color: #045fb4;
}

#navigation td a {
    display: block;
    width: 100%;
    text-decoration: none;
    min-width: 3.5rem;
}

#navigation td a:hover {
    text-decoration: none;
    color: #ffffff;
}

#content {
    margin: 0 auto;
}

@media (min-width: 1024px) {
    #news {
        float: right;
        max-width: 29%;
    }
    #front-content {
        max-width: 69%;
        float: left;
    }
}

#sshfp {
	float: left;
	margin: 0 auto;
	min-width: 100%;
	text-align: center;
	padding-bottom: 3rem;
}

#code {
    font-family: monospace;
    font-size: 1.0em;
    max-width: 75%;
    margin: 0 auto;
}

.code {
    font-family: monospace;
    font-size: 1.0em;
    max-width: 50%;
    margin: 0 auto;
}

.faq {
    width: 75%;
}

.faq .q {
    margin-top: 3rem;
    font-weight: bold;
    font-style: italic;
    text-indent: 0rem;
    font-size: 1.2em;
}

.faq p {
    text-indent: 2rem;
}

.faq h1 {
    font-size: 1.75em;
    text-align: center;
    margin-bottom: -1.5rem;
}

a:link {
    text-decoration: underline;
    color:#ffffff;
}

a:visited {
    color:#ffffff;
    text-decoration: underline;
}

a:hover {
    color:#a4a4a4;
    text-decoration: underline;
}

p {
    text-indent: 15px;
}

code {
    text-indent: 2rem;
    font-family: monospace;
    font-size: 1.0em;
    padding-left: 0.3rem;
    padding-right: 0.3rem;
}

em {
    font-weight: bold;
}

h1 {
    font-size: 1.75em;
    text-align: center;
}

h2 {
    font-size: 1.4em;
}

h3 {
    font-size: 1.2em;
}

h4 {
    font-size: 1.1em;
    margin-top: 0.2rem;
}

.userlist {
	margin: 0 auto;
}

.userlist ul {
	list-style-position: inside;
	display: flex;
	flex-flow: row wrap;
	justify-content: space-evenly;
	list-style-type: "\00BB\0020";
	padding-left: 3em;
}

.userlist li {
	white-space: nowrap;
	flex: 10em;
}

.userlist p {
	text-align: center;
}

.signup {
	text-align: center;
}

.signup input {
	margin-bottom: 1.6rem;
}

.signup h3 {
	margin: 0.5rem;
}

.signup p {
	padding-bottom: 0.3rem;
}