about summary refs log tree commit diff stats
path: root/archive/2.vm/sandbox/009-sandbox-test.mu
blob: c22916a7b982b6fd87ef9d1c0b5d52885192877a (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
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
## clicking on sandbox results to 'fix' them and turn sandboxes into tests

scenario sandbox-click-on-result-toggles-color-to-green [
  local-scope
  trace-until 100/app  # trace too long
  assume-screen 50/width, 20/height
  # basic recipe
  assume-resources [
    [lesson/recipes.mu] <- [
      |recipe foo [|
      |  reply 4|
      |]|
    ]
  ]
  env:&:environment <- new-programming-environment resources, screen, [foo]
  render-all screen, env, render
  # run it
  assume-console [
    press F4
  ]
  event-loop screen, console, env, resources
  screen-should-contain [
    .                               run (F4)           .
    .                                                  .
    .──────────────────────────────────────────────────.
    .0   edit           copy           delete          .
    .foo                                               .
    .4                                                 .
    .──────────────────────────────────────────────────.
    .                                                  .
  ]
  # click on the '4' in the result
  $clear-trace
  assume-console [
    left-click 5, 21
  ]
  run [
    event-loop screen, console, env, resources
  ]
  # color toggles to green
  screen-should-contain-in-color 2/green, [
    .                                                  .
    .                                                  .
    .                                                  .
    .                                                  .
    .                                                  .
    .4                                                 .
    .                                                  .
  ]
  # don't render entire sandbox side
  check-trace-count-for-label-lesser-than 250, [print-character]  # say 5 sandbox lines
  # cursor should remain unmoved
  run [
    cursor:char <- copy 9251/    print screen, cursor
  ]
  screen-should-contain [
    .                               run (F4)           .
    .                                                 .
    .──────────────────────────────────────────────────.
    .0   edit           copy           delete          .
    .foo                                               .
    .4                                                 .
    .──────────────────────────────────────────────────.
    .                                                  .
  ]
  # now change the result
  assume-resources [
    [lesson/recipes.mu] <- [
      |recipe foo [|
      |  reply 3|
      |]|
    ]
  ]
  # then rerun
  assume-console [
    press F4
  ]
  run [
    event-loop screen, console, env, resources
  ]
  # result turns red
  screen-should-contain-in-color 1/red, [
    .                                                  .
    .                                                  .
    .                                                  .
    .                                                  .
    .                                                  .
    .3                                                 .
    .                                                  .
  ]
]

# this requires tracking a couple more things
container sandbox [
  response-starting-row-on-screen:num
  expected-response:text
]

# include expected response when saving or restoring a sandbox
before <end-save-sandbox> [
  {
    expected-response:text <- get *sandbox, expected-response:offset
    break-unless expected-response
    filename <- append filename, [.out]
    resources <- dump resources, filename, expected-response
  }
]

before <end-restore-sandbox> [
  {
    filename <- append filename, [.out]
    contents <- slurp resources, filename
    break-unless contents
    *curr <- put *curr, expected-response:offset, contents
  }
]

# clicks on sandbox responses save it as 'expected'
after <global-touch> [
  # check if it's inside the output of any sandbox
  {
    sandbox-left-margin:num <- get *current-sandbox, left:offset
    click-column:num <- get t, column:offset
    on-sandbox-side?:bool <- greater-or-equal click-column, sandbox-left-margin
    break-unless on-sandbox-side?
    first-sandbox:&:sandbox <- get *env, sandbox:offset
    break-unless first-sandbox
    first-sandbox-begins:num <- get *first-sandbox, starting-row-on-screen:offset
    click-row:num <- get t, row:offset
    below-sandbox-editor?:bool <- greater-or-equal click-row, first-sandbox-begins
    break-unless below-sandbox-editor?
    # identify the sandbox whose output is being clicked on
    sandbox:&:sandbox, sandbox-index:num <- find-click-in-sandbox-output env, click-row
    break-unless sandbox
    # update it
    sandbox <- toggle-expected-response sandbox
    # minimal update to disk
    save-sandbox resources, sandbox, sandbox-index
    # minimal update to screen
    sandbox-right-margin:num <- get *current-sandbox, right:offset
    row:num <- render-sandbox-response screen, sandbox, sandbox-left-margin, sandbox-right-margin
    {
      height:num <- screen-height screen
      at-bottom?:bool <- greater-or-equal row, height
      break-if at-bottom?
      draw-horizontal screen, row, sandbox-left-margin, sandbox-right-margin
    }
    screen <- update-cursor screen, current-sandbox, env
    loop +next-event
  }
]

def find-click-in-sandbox-output env:&:environment, click-row:num -> sandbox:&:sandbox, sandbox-index:num [
  local-scope
  load-inputs
  # assert click-row >= sandbox.starting-row-on-screen
  sandbox:&:sandbox <- get *env, sandbox:offset
  start:num <- get *sandbox, starting-row-on-screen:offset
  clicked-on-sandboxes?:bool <- greater-or-equal click-row, start
  assert clicked-on-sandboxes?, [extract-sandbox called on click to sandbox editor]
  # while click-row < sandbox.next-sandbox.starting-row-on-screen
  sandbox-index <- copy 0
  {
    next-sandbox:&:sandbox <- get *sandbox, next-sandbox:offset
    break-unless next-sandbox
    next-start:num <- get *next-sandbox, starting-row-on-screen:offset
    found?:bool <- lesser-than click-row, next-start
    break-if found?
    sandbox <- copy next-sandbox
    sandbox-index <- add sandbox-index, 1
    loop
  }
  # return sandbox if click is in its output region
  response-starting-row:num <- get *sandbox, response-starting-row-on-screen:offset
  return-unless response-starting-row, null/no-click-in-sandbox-output, 0/sandbox-index
  click-in-response?:bool <- greater-or-equal click-row, response-starting-row
  return-unless click-in-response?, null/no-click-in-sandbox-output, 0/sandbox-index
  return sandbox, sandbox-index
]

def toggle-expected-response sandbox:&:sandbox -> sandbox:&:sandbox [
  local-scope
  load-inputs
  expected-response:text <- get *sandbox, expected-response:offset
  {
    # if expected-response is set, reset
    break-unless expected-response
    *sandbox <- put *sandbox, expected-response:offset, null
  }
  {
    # if not, set expected response to the current response
    break-if expected-response
    response:text <- get *sandbox, response:offset
    *sandbox <- put *sandbox, expected-response:offset, response
  }
]

# when rendering a sandbox, color it in red/green if expected response exists
after <render-sandbox-response> [
  {
    break-unless sandbox-response
    *sandbox <- put *sandbox, response-starting-row-on-screen:offset, row
    row <- render-sandbox-response screen, sandbox, left, right
    jump +render-sandbox-end
  }
]

def render-sandbox-response screen:&:screen, sandbox:&:sandbox, left:num, right:num -> row:num, screen:&:screen [
  local-scope
  load-inputs
  sandbox-response:text <- get *sandbox, response:offset
  expected-response:text <- get *sandbox, expected-response:offset
  row:num <- get *sandbox response-starting-row-on-screen:offset
  {
    break-if expected-response
    row <- render-text screen, sandbox-response, left, right, 245/grey, row
    return
  }
  response-is-expected?:bool <- equal expected-response, sandbox-response
  {
    break-if response-is-expected?
    row <- render-text screen, sandbox-response, left, right, 1/red, row
  }
  {
    break-unless response-is-expected?:bool
    row <- render-text screen, sandbox-response, left, right, 2/green, row
  }
]

before <end-render-sandbox-reset-hidden> [
  *sandbox <- put *sandbox, response-starting-row-on-screen:offset, 0
]
pre>
.TH DWM 1 dwm-VERSION
.SH NAME
dwm \- dynamic window manager
.SH SYNOPSIS
.B dwm
.RB [ \-v ]
.SH DESCRIPTION
dwm is a dynamic window manager for X. It manages windows in tiling and
floating modes. Either mode can be applied dynamically, optimizing the
environment for the application in use and the task performed.
.P
In tiling mode windows are managed in a master and stacking area. The master
area contains the windows which currently need most attention, whereas the
stacking area contains all other windows. In floating mode windows can be
resized and moved freely. Dialog windows are always managed floating,
regardless of the mode applied.
.P
Windows are grouped by tags. Each window can be tagged with one or multiple
tags. Selecting certain tags displays all windows with these tags.
.P
dwm contains a small status bar which displays all available tags, the mode,
the title of the focused window, and the text read from standard input. The
selected tags are indicated with a different color. The tags of the focused
window are indicated with a filled square in the top left corner.  The tags
which are applied to one or more windows are indicated with an empty square in
the top left corner.
.P
dwm draws a small border around windows to indicate the focus state.
.SH OPTIONS
.TP
.B \-v
prints version information to standard output, then exits.
.SH USAGE
.SS Status bar
.TP
.B Standard input
is read and displayed in the status text area.
.TP
.B Button1
click on a tag label to display all windows with that tag, click on the mode
label toggles between tiling and floating mode.
.TP
.B Button3
click on a tag label adds/removes all windows with that tag to/from the view.
.TP
.B Button4
click on the mode label increases the number of windows in the master area (tiling mode only).
.TP
.B Button5
click on the mode label decreases the number of windows in the master area (tiling mode only).
.TP
.B Mod1-Button1
click on a tag label applies that tag to the focused window.
.TP
.B Mod1-Button3
click on a tag label adds/removes that tag to/from the focused window.
.SS Keyboard commands
.TP
.B Mod1-Shift-Return
Start
.BR xterm (1).
.TP
.B Mod1-Tab
Focus next window.
.TP
.B Mod1-Shift-Tab
Focus previous window.
.TP
.B Mod1-Return
Zooms/cycles current window to/from master area (tiling mode), toggles maximization of current window (floating mode).
.TP
.B Mod1-g
Grow master area (tiling mode only).
.TP
.B Mod1-s
Shrink master area (tiling mode only).
.TP
.B Mod1-i
Increase the number of windows in the master area (tiling mode only).
.TP
.B Mod1-d
Decrease the number of windows in the master area (tiling mode only).
.TP
.B Mod1-Shift-[1..n]
Apply
.RB nth
tag to current window.
.TP
.B Mod1-Shift-0
Apply all tags to current window.
.TP
.B Mod1-Control-Shift-[1..n]
Add/remove
.B nth
tag to/from current window.
.TP
.B Mod1-Shift-c
Close focused window.
.TP
.B Mod1-space
Toggle between tiling and floating mode (affects all windows).
.TP
.B Mod1-Shift-space
Toggle focused window between floating and non-floating state.
.TP
.B Mod1-[1..n]
View all windows with
.BR nth
tag.
.TP
.B Mod1-0
View all windows with any tag.
.TP
.B Mod1-Control-[1..n]
Add/remove all windows with
.BR nth
tag to/from the view.
.TP
.B Mod1-Shift-q
Quit dwm.
.SS Mouse commands
.TP
.B Mod1-Button1
Move current window while dragging (floating mode only).
.TP
.B Mod1-Button2
Zooms/cycles current window to/from master area (tiling mode), toggles maximization of current window (floating mode).
.TP
.B Mod1-Button3
Resize current window while dragging (floating mode only).
.SH CUSTOMIZATION
dwm is customized by creating a custom config.h and (re)compiling the source
code. This keeps it fast, secure and simple.
.SH SEE ALSO
.BR dmenu (1)
.SH BUGS
The status bar may display
.BR "EOF"
when dwm has been started by an X session manager like
.BR xdm (1),
because those close standard output before executing dwm.
.P
Java applications which use the XToolkit/XAWT backend may draw grey windows
only. The XToolkit/XAWT backend breaks ICCCM-compliance in recent JDK 1.5 and early
JDK 1.6 versions, because it assumes a reparenting window manager. As a workaround
you can use JDK 1.4 (which doesn't contain the XToolkit/XAWT backend) or you
can set the following environment variable (to use the older Motif
backend instead):
.BR AWT_TOOLKIT=MToolkit .