about summary refs log tree commit diff stats
path: root/sieve.tlv
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-02-27 08:38:48 -0800
committerKartik K. Agaram <vc@akkartik.com>2022-02-27 08:41:30 -0800
commitae51b06dabbae991914aff281ff42addbcd21146 (patch)
tree7a24f1d7f22409dd1a0110cf82f1a930e64db061 /sieve.tlv
parent891bced5443cde47f51626d962e87df7d084a64c (diff)
downloadteliva-ae51b06dabbae991914aff281ff42addbcd21146.tar.gz
starting to make Teliva apps more testable
Tasteful apps should only perform side-effects through 'window'
arguments rather than the 'curses' module directly. It's ok however to
read constants like curses.A_NORMAL or curses.stdscr().

There are some limitations, unfortunately. Ncurses wasn't designed with
testability in mind. For example, there's no way to curs_set or
assume_default_colors without the 'curses' module. Oh well.
Diffstat (limited to 'sieve.tlv')
-rw-r--r--sieve.tlv12
1 files changed, 6 insertions, 6 deletions
diff --git a/sieve.tlv b/sieve.tlv
index 13d1e8c..ae70bfe 100644
--- a/sieve.tlv
+++ b/sieve.tlv
@@ -80,7 +80,7 @@
   check_eq:
     >function check_eq(x, expected, msg)
     >  if eq(x, expected) then
-    >    curses.addch('.')
+    >    window:addch('.')
     >  else
     >    print('F - '..msg)
     >    print('  expected '..str(expected)..' but got '..str(x))
@@ -221,7 +221,7 @@
     >    window:attrset(curses.color_pair(i))
     >    window:mvaddstr(3+i, 5, "========================")
     >  end
-    >  curses.refresh()
+    >  window:refresh()
     >end
 - __teliva_timestamp: original
   menu:
@@ -231,7 +231,7 @@
 - __teliva_timestamp: original
   update:
     >function update(window)
-    >  local key = curses.getch()
+    >  local key = window:getch()
     >  -- process key here
     >end
 - __teliva_timestamp: original
@@ -271,7 +271,7 @@
     >  task.spawn(main_task)
     >  task.scheduler()
     >  print('out of scheduler')
-    >  curses.getch()
+    >  window:getch()
     >end
 - __teliva_timestamp:
     >Sat Feb 26 21:50:11 2022
@@ -368,7 +368,7 @@
     >  task.scheduler()
     >  print('key pressed; done')
     >  window:nodelay(false)
-    >  curses.getch()
+    >  window:getch()
     >end
 - __teliva_timestamp:
     >Sat Feb 26 22:09:47 2022
@@ -384,7 +384,7 @@
     >  while true do
     >    window:addstr(primes:recv())
     >    window:addstr(' ')
-    >    local c = curses.getch()
+    >    local c = window:getch()
     >    if c then break end  -- key pressed
     >    local y, x = window:getyx()
     >    if y > h-1 then