aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/notes.aup35
1 files changed, 35 insertions, 0 deletions
diff --git a/examples/notes.aup b/examples/notes.aup
new file mode 100644
index 0000000..fdc91b8
--- /dev/null
+++ b/examples/notes.aup
@@ -0,0 +1,35 @@
+# A small text editor. The runtime owns the text: typing inserts at the
+# cursor, the cursor and the mark always sit between characters and follow
+# edits, and a failed event would leave everything as it was.
+state title: text = "메모"
+state note: text = ""
+state at: cursor in note
+state mark: cursor in note
+
+input typed = text
+input left = key ArrowLeft
+input right = key ArrowRight
+input up = key ArrowUp
+input down = key ArrowDown
+input back = key Backspace
+input forward = key Delete
+input home = key Home
+input finish = key End
+input set_mark = key KeyM
+
+on typed { note.insert(at, typed) }
+on left.down { at = at - 1 char }
+on right.down { at = at + 1 char }
+on up.down { at = at - 1 line }
+on down.down { at = at + 1 line }
+on back.down { note.remove(at - 1 char .. at) }
+on forward.down { note.remove(at .. at + 1 char) }
+on home.down { at = note.start }
+on finish.down { at = note.end }
+on set_mark.down { mark = at }
+
+view header = "{title} · {note.chars}자"
+view current = note.line(at)
+view position = "line {at.line}, char {at.chars}"
+view size = note.bytes
+view lines = note.lines