about summary refs log tree commit diff stats
path: root/apps
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-05-29 15:23:36 -0700
committerKartik Agaram <vc@akkartik.com>2020-05-29 15:23:36 -0700
commit2fb656b4f466f85437c268da9e05b270d020b964 (patch)
treeb8d92f8edcff4cbaca9f53bd5fbf4a4650f07df9 /apps
parent0a80e66f6e0976dd9f0ef88fe66e667a53db2456 (diff)
downloadmu-2fb656b4f466f85437c268da9e05b270d020b964.tar.gz
6432 - paginator starting to take shape
Diffstat (limited to 'apps')
-rw-r--r--apps/browse.mu58
1 files changed, 56 insertions, 2 deletions
diff --git a/apps/browse.mu b/apps/browse.mu
index 307ca81c..bb3c1a1c 100644
--- a/apps/browse.mu
+++ b/apps/browse.mu
@@ -3,11 +3,65 @@
 fn main args: (addr array (addr array byte)) -> exit-status/ebx: int {
   var filename/eax: (addr array byte) <- first-arg args
   var file-contents/eax: (addr buffered-file) <- load-file filename
-  dump file-contents
-  flush-stdout
+#?   dump file-contents
+#?   flush-stdout
+  enable-screen-grid-mode
+  enable-keyboard-immediate-mode
+  {
+    render file-contents, 5, 5, 30, 30
+    var key/eax: byte <- read-key
+    compare key, 0x71  # 'q'
+    loop-if-!=
+  }
+  enable-keyboard-type-mode
+  enable-screen-type-mode
   exit-status <- copy 0
 }
 
+fn render in: (addr buffered-file), toprow: int, leftcol: int, botrow: int, rightcol: int {
+  clear toprow, leftcol, botrow, rightcol
+  # render screen rows
+  var row/ecx: int <- copy toprow
+$line-loop:  {
+    compare row, botrow
+    break-if->=
+    var col/edx: int <- copy leftcol
+    move-cursor row, col
+    {
+      compare col, rightcol
+      break-if->=
+      var c/eax: byte <- read-byte-buffered in
+      compare c, 0xffffffff  # EOF marker
+      break-if-= $line-loop
+      print-byte c
+      col <- increment
+      loop
+    }
+    row <- increment
+    loop
+  }
+  flush-stdout
+}
+
+fn clear toprow: int, leftcol: int, botrow: int, rightcol: int {
+  var row/ecx: int <- copy toprow
+  {
+    compare row, botrow
+    break-if->=
+    var col/edx: int <- copy leftcol
+    move-cursor row, col
+    {
+      compare col, rightcol
+      break-if->=
+      print-string " "
+      col <- increment
+      loop
+    }
+    row <- increment
+    loop
+  }
+}
+
 fn first-arg args-on-stack: (addr array (addr array byte)) -> out/eax: (addr array byte) {
   var args/eax: (addr array (addr array byte)) <- copy args-on-stack
   var result/eax: (addr addr array byte) <- index args, 1