diff options
| author | eunhhu <[email protected]> | 2026-09-26 16:39:30 +0100 |
|---|---|---|
| committer | eunhhu <[email protected]> | 2026-09-26 16:39:30 +0100 |
| commit | 15c4616e19d997c64a983e39501289c7d9f50d0a (patch) | |
| tree | 24fcca80ef6dcdf4f08458aa147a4dc7b82ef693 /examples | |
| parent | 8e2b3ffadcf83dba74d58dbf9ee2c57cef5f1ad5 (diff) | |
| download | vega-15c4616e19d997c64a983e39501289c7d9f50d0a.tar.gz vega-15c4616e19d997c64a983e39501289c7d9f50d0a.zip | |
Add a tally example: a keyed list on every surface
examples/tally.aup counts typed words in a list keyed by the word: the
screen stays sorted with each word once, typing a word again counts it
and moves the focus to it. It runs on the three surfaces with the other
examples, and vega check finds nothing in it.
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/tally.aup | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/examples/tally.aup b/examples/tally.aup new file mode 100644 index 0000000..5c3d9e9 --- /dev/null +++ b/examples/tally.aup @@ -0,0 +1,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 |
