about summary refs log tree commit diff stats
path: root/apps
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-05-31 01:05:23 -0700
committerKartik Agaram <vc@akkartik.com>2020-05-31 01:05:23 -0700
commit972ca2c9345e51dde2ed5c2caac12b8a03191b6f (patch)
tree3c3150d027b7d75b4b2e89ea1c1b41500bfb7aba /apps
parent7e3ad3aeef2429d01a03e9876ecbeb3fb32b295f (diff)
downloadmu-972ca2c9345e51dde2ed5c2caac12b8a03191b6f.tar.gz
6454: abortive first attempt at parsing headings
The state machine is already out of control, and I already have bugs like
turning '*abc_' into bold text.
Diffstat (limited to 'apps')
-rw-r--r--apps/browse.mu44
1 files changed, 41 insertions, 3 deletions
diff --git a/apps/browse.mu b/apps/browse.mu
index 61de6a99..3cffdc4c 100644
--- a/apps/browse.mu
+++ b/apps/browse.mu
@@ -27,6 +27,8 @@ fn main args: (addr array (addr array byte)) -> exit-status/ebx: int {
 
 type render-state {
   current-state: int  # enum 0: normal, 1: bold, 2: heading
+  start-of-line?: boolean
+  num-hashes-seen?: int
 }
 
 # decide how to lay out pages on screen
@@ -42,6 +44,9 @@ fn render in: (addr buffered-file), nrows: int, ncols: int {
   #   text-width
   var _r: render-state
   var r/edi: (addr render-state) <- address _r
+  # r->start-of-line? = true
+  var s/eax: (addr boolean) <- get r, start-of-line?
+  copy-to *s, 1  # true
   var toprow/eax: int <- copy 2  # top-margin
   var botrow/ecx: int <- copy nrows
   var leftcol/edx: int <- copy 5  # page-margin
@@ -97,6 +102,20 @@ $change-state: {
             copy-to *state, 1
             break $change-state
           }
+          compare c, 0x23  # '#'
+          {
+            break-if-!=
+            var s/eax: (addr boolean) <- get r, start-of-line?
+            compare *s, 1
+            {
+              break-if-!=
+              # r->current-state == 0 && c == '#' && at start of line => count '#'s
+              var h/eax: (addr int) <- get r, num-hashes-seen?
+              increment *h
+              break $change-state
+            }
+            break $change-state
+          }
           break $change-state
         }
         compare *state, 1  # bold
@@ -116,9 +135,9 @@ $change-state: {
           compare c, 0x5f  # '_'
           {
             break-if-!=
+            # r->current-state == 1 && c == '_' => print c, then normal text
             print-byte c
             col <- increment
-            # r->current-state == 1 && c == '_' => print c, then normal text
             reset-formatting
             start-color 0xec, 7  # 236 = darkish gray
             copy-to *state, 0
@@ -126,9 +145,28 @@ $change-state: {
           }
           break $change-state
         }
-      }
+      }  # $change-state
+      # update a few attributes of the state based on c without changing the state itself
       compare c, 0xa  # newline
-      break-if-=  # no need to print newlines
+      {
+        break-if-!=
+        # c is newline
+        var s/eax: (addr boolean) <- get r, start-of-line?
+        copy-to *s, 1  # true
+        # switch to normal text
+        reset-formatting
+        start-color 0xec, 7  # 236 = darkish gray
+        # no need to print newlines
+        break $char-loop
+      }
+      compare c, 0x20  # space
+      {
+        break-if-=
+        # c is not newline or space
+        var s/eax: (addr boolean) <- get r, start-of-line?
+        copy-to *s, 0  # false
+      }
+      # print c
       print-byte c
       col <- increment
       loop