aboutsummaryrefslogtreecommitdiffstats
path: root/examples/tally.aup
blob: 5c3d9e92939a4594289a2d63c3136d4fcc47844c (plain)
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
# Words typed, tallied. A list keyed by the word keeps each word once and in
# order: the screen is sorted without a sort anywhere, and typing a word
# again counts it and moves the focus to it.
use vega

record Tally {
  word: text
  times = 0
}

state tallies: list of Tally by word
state at: index of tallies

input add = text
input up = key ArrowUp
input down = key ArrowDown
input drop = key Delete

on add {
  if !tallies.has(add) {
    tallies.add(Tally { word: add })
  }
  tallies[add].times = tallies[add].times + 1
  at = tallies[add]
}
on up.down { at = at - 1 }
on down.down { at = at + 1 }
on drop.down { tallies.remove(at) }

view title = "Tally"
view typed = "{sum(t.times for t in tallies)} typed, {tallies.count} different"

view tallies_list = each t in tallies {
  label = t.word
  badge = "{t.times}"
  tone = vega.when(t.times > 1, vega.accent)
}
view tallies_list_focus = at.position