about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-05-30 23:28:07 -0700
committerKartik Agaram <vc@akkartik.com>2020-05-30 23:28:07 -0700
commitf817386bb310d801c7795c0d6f56721456bb1cc0 (patch)
tree44e3f2d32c679ed16bcf0a9a8b9ee1afaee3d2af
parent994afb6ebab54973b9a7bf1e1a3fed789703c126 (diff)
downloadmu-f817386bb310d801c7795c0d6f56721456bb1cc0.tar.gz
6450
The current organization doesn't really work for the next feature (section
headings) so let's inline attribute-handling.
-rw-r--r--apps/browse.mu102
1 files changed, 50 insertions, 52 deletions
diff --git a/apps/browse.mu b/apps/browse.mu
index f442d2a4..c71d1dec 100644
--- a/apps/browse.mu
+++ b/apps/browse.mu
@@ -60,22 +60,68 @@ fn render in: (addr buffered-file), nrows: int, ncols: int {
   }
 }
 
-fn render-page in: (addr buffered-file), toprow: int, leftcol: int, botrow: int, rightcol: int, r: (addr render-state) {
+fn render-page in: (addr buffered-file), toprow: int, leftcol: int, botrow: int, rightcol: int, _r: (addr render-state) {
+  var r/edi: (addr render-state) <- copy _r
+  var state/esi: (addr int) <- get r, current-state
   clear toprow, leftcol, botrow, rightcol
   # render screen rows
   var row/ecx: int <- copy toprow
-$line-loop:  {
+$line-loop: {
     compare row, botrow
     break-if->=
     var col/edx: int <- copy leftcol
     move-cursor row, col
-    {
+$char-loop: {
       compare col, rightcol
       break-if->=
       var c/eax: byte <- read-byte-buffered in
       compare c, 0xffffffff  # EOF marker
       break-if-= $line-loop
-      update-attributes c, r
+$update-attributes:check-state: {
+        compare *state, 0  # normal
+        {
+          break-if-!=
+          compare c, 0x2a  # '*'
+          {
+            break-if-!=
+            # r->current-state == 0 && c == '*'
+            start-bold
+            copy-to *state, 1
+            break $update-attributes:check-state
+          }
+          compare c, 0x5f  # '_'
+          {
+            break-if-!=
+            # r->current-state == 0 && c == '_'
+            start-bold
+            copy-to *state, 1
+            break $update-attributes:check-state
+          }
+          break $update-attributes:check-state
+        }
+        {
+          break-if-=
+          compare c, 0x2a  # '*'
+          {
+            break-if-!=
+            # r->current-state == 1 && c == '*'
+            reset-formatting
+            start-color 0xec, 7  # 236 = darkish gray
+            copy-to *state, 0
+            break $update-attributes:check-state
+          }
+          compare c, 0x5f  # '_'
+          {
+            break-if-!=
+            # r->current-state == 1 && c == '_'
+            reset-formatting
+            start-color 0xec, 7  # 236 = darkish gray
+            copy-to *state, 0
+            break $update-attributes:check-state
+          }
+          break $update-attributes:check-state
+        }
+      }
       compare c, 0xa  # newline
       break-if-=  # no need to print newlines
       print-byte c
@@ -87,54 +133,6 @@ $line-loop:  {
   }
 }
 
-fn update-attributes c: byte, _r: (addr render-state) {
-  var r/edi: (addr render-state) <- copy _r
-  var state/esi: (addr int) <- get r, current-state
-$update-attributes:check-state: {
-    compare *state, 0  # normal
-    {
-      break-if-!=
-      compare c, 0x2a  # '*'
-      {
-        break-if-!=
-        # r->current-state == 0 && c == '*'
-        start-bold
-        copy-to *state, 1
-        break $update-attributes:check-state
-      }
-      compare c, 0x5f  # '_'
-      {
-        break-if-!=
-        # r->current-state == 0 && c == '_'
-        start-bold
-        copy-to *state, 1
-        break $update-attributes:check-state
-      }
-      break $update-attributes:check-state
-    }
-    {
-      break-if-=
-      compare c, 0x2a  # '*'
-      {
-        break-if-!=
-        # r->current-state == 1 && c == '*'
-        reset-formatting
-        copy-to *state, 0
-        break $update-attributes:check-state
-      }
-      compare c, 0x5f  # '_'
-      {
-        break-if-!=
-        # r->current-state == 1 && c == '_'
-        reset-formatting
-        copy-to *state, 0
-        break $update-attributes:check-state
-      }
-      break $update-attributes:check-state
-    }
-  }
-}
-
 fn clear toprow: int, leftcol: int, botrow: int, rightcol: int {
   var row/ecx: int <- copy toprow
   {