aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authoreunhhu <[email protected]>2026-09-26 18:04:31 +0100
committereunhhu <[email protected]>2026-09-26 18:04:31 +0100
commit9c2d1eb1d423625672cb469af6bf708a48d3cb71 (patch)
treeaffdf0b1ac702129521264ecf1aae64f20c06afb /examples
parentb466603358f8fa5a74551a9819fdd54ad124ef0c (diff)
downloadvega-9c2d1eb1d423625672cb469af6bf708a48d3cb71.tar.gz
vega-9c2d1eb1d423625672cb469af6bf708a48d3cb71.zip
Add a board used by people and programs alike
examples/board.aup is a kanban board: people add and move cards on Vega's surfaces, programs post JSON to the same module served by pure-serve, with no routes written. The checks write cards with the CLI into a store, serve that store over HTTP where a program moves one and adds another, and read it again with the CLI, the focus still on the card it was on.
Diffstat (limited to 'examples')
-rw-r--r--examples/board.aup58
1 files changed, 58 insertions, 0 deletions
diff --git a/examples/board.aup b/examples/board.aup
new file mode 100644
index 0000000..ed73e75
--- /dev/null
+++ b/examples/board.aup
@@ -0,0 +1,58 @@
+# A board of cards in lanes, for people and programs alike: vega tui, web,
+# cli and say show it, and pure-serve serves the same module and store as a
+# JSON API (GET /views/NAME, POST /inputs/NAME) with no routes written.
+use vega
+
+record Card {
+ title: text
+ lane = 0 # 0 to do, 1 doing, 2 done
+ since = 0 # when it came into its lane: milliseconds since 1970
+}
+
+state cards: list of Card by title
+state at: index of cards
+
+input add = text # a person types a title
+input post = message { # a program posts {"title": ..., "lane": ...}
+ title: text
+ lane: u32
+}
+input forward = key ArrowRight
+input back = key ArrowLeft
+input up = key ArrowUp
+input down = key ArrowDown
+input drop = key Delete
+
+fn lane_name(lane) = if lane == 0 { "to do" } else if lane == 1 { "doing" } else { "done" }
+
+on add {
+ cards.add(Card { title: add, since: now })
+ at = cards[add]
+}
+on post {
+ if !cards.has(post.title) { cards.add(Card { title: post.title }) }
+ cards[post.title].lane = min(post.lane, 2)
+ cards[post.title].since = now
+ reply post.title
+}
+on forward.down {
+ at.lane = min(at.lane + 1, 2)
+ at.since = now
+}
+on back.down {
+ at.lane = max(at.lane - 1, 0)
+ at.since = now
+}
+on up.down { at = at - 1 }
+on down.down { at = at + 1 }
+on drop.down { cards.remove(at) }
+
+view title = "Board"
+view counts = "{count(c in cards where c.lane == 0)} to do, {count(c in cards where c.lane == 1)} doing, {count(c in cards where c.lane == 2)} done"
+
+view cards_list = each c in cards {
+ label = c.title
+ badge = lane_name(c.lane)
+ tone = if c.lane == 2 { vega.muted } else { vega.when(c.lane == 1, vega.accent) }
+}
+view cards_list_focus = at.position