diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2021-04-10 20:09:18 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2021-04-10 20:09:18 -0700 |
commit | 6fa86619b286cae8a1a990ce5ac845d2b80428ca (patch) | |
tree | 1dd3d23b69154715341d9ff3d367f9b1cb4d24a1 /shell | |
parent | 17f77da27d807ca4489a92a23506c88fb60bd89e (diff) | |
download | mu-6fa86619b286cae8a1a990ce5ac845d2b80428ca.tar.gz |
shell: tweaks for fake screens
- make them more discoverable - clear them between commands
Diffstat (limited to 'shell')
-rw-r--r-- | shell/global.mu | 28 | ||||
-rw-r--r-- | shell/sandbox.mu | 142 |
2 files changed, 165 insertions, 5 deletions
diff --git a/shell/global.mu b/shell/global.mu index 0e7038e9..a3ec33a0 100644 --- a/shell/global.mu +++ b/shell/global.mu @@ -668,3 +668,31 @@ fn apply-print _args-ah: (addr handle cell), out: (addr handle cell), env-h: (ha # return what was printed copy-object second-ah, out } + +fn clear-screen-var _globals: (addr global-table) { + var globals/esi: (addr global-table) <- copy _globals + var screen-literal-storage: (stream byte 8) + var screen-literal/eax: (addr stream byte) <- address screen-literal-storage + write screen-literal, "screen" + var screen-index/ecx: int <- find-symbol-in-globals globals, screen-literal + compare screen-index, -1/not-found + { + break-if-!= + return + } + var global-data-ah/eax: (addr handle array global) <- get globals, data + var global-data/eax: (addr array global) <- lookup *global-data-ah + var screen-offset/ecx: (offset global) <- compute-offset global-data, screen-index + var screen-global/eax: (addr global) <- index global-data, screen-offset + var screen-cell-ah/eax: (addr handle cell) <- get screen-global, value + var screen-cell/eax: (addr cell) <- lookup *screen-cell-ah + var screen-cell-type/ecx: (addr int) <- get screen-cell, type + compare *screen-cell-type, 5/screen + { + break-if-= + return + } + var screen-ah/eax: (addr handle screen) <- get screen-cell, screen-data + var screen/eax: (addr screen) <- lookup *screen-ah + clear-screen screen +} diff --git a/shell/sandbox.mu b/shell/sandbox.mu index 4b5d5b14..2b68de5d 100644 --- a/shell/sandbox.mu +++ b/shell/sandbox.mu @@ -47,6 +47,7 @@ fn render-sandbox screen: (addr screen), _self: (addr sandbox), xmin: int, ymin: var data/edx: (addr gap-buffer) <- copy _data var x/eax: int <- copy xmin var y/ecx: int <- copy ymin + y <- maybe-render-empty-screen screen, globals, xmin, y var cursor-in-sandbox?/ebx: boolean <- copy 0/false { var cursor-in-trace?/eax: (addr boolean) <- get self, cursor-in-trace? @@ -76,6 +77,7 @@ fn render-sandbox screen: (addr screen), _self: (addr sandbox), xmin: int, ymin: var x2/edx: int <- copy x var dummy/eax: int <- draw-stream-rightward screen, value, x2, xmax, y, 7/fg=grey, 0/bg } + y <- add 2 # padding y <- maybe-render-screen screen, globals, xmin, y # render menu var cursor-in-trace?/eax: (addr boolean) <- get self, cursor-in-trace? @@ -88,6 +90,39 @@ fn render-sandbox screen: (addr screen), _self: (addr sandbox), xmin: int, ymin: render-sandbox-menu screen } +fn maybe-render-empty-screen screen: (addr screen), _globals: (addr global-table), xmin: int, ymin: int -> _/ecx: int { + var globals/esi: (addr global-table) <- copy _globals + var screen-literal-storage: (stream byte 8) + var screen-literal/eax: (addr stream byte) <- address screen-literal-storage + write screen-literal, "screen" + var screen-obj-index/ecx: int <- find-symbol-in-globals globals, screen-literal + compare screen-obj-index, -1/not-found + { + break-if-!= + return ymin + } + var global-data-ah/eax: (addr handle array global) <- get globals, data + var global-data/eax: (addr array global) <- lookup *global-data-ah + var screen-obj-offset/ecx: (offset global) <- compute-offset global-data, screen-obj-index + var screen-global/eax: (addr global) <- index global-data, screen-obj-offset + var screen-obj-cell-ah/eax: (addr handle cell) <- get screen-global, value + var screen-obj-cell/eax: (addr cell) <- lookup *screen-obj-cell-ah + var screen-obj-cell-type/ecx: (addr int) <- get screen-obj-cell, type + compare *screen-obj-cell-type, 5/screen + { + break-if-= + return ymin # silently give up on rendering the screen + } + var y/ecx: int <- copy ymin + var screen-obj-ah/eax: (addr handle screen) <- get screen-obj-cell, screen-data + var _screen-obj/eax: (addr screen) <- lookup *screen-obj-ah + var screen-obj/edx: (addr screen) <- copy _screen-obj + var x/eax: int <- draw-text-rightward screen, "screen: ", xmin, 0x99/xmax, y, 7/fg, 0/bg + y <- render-empty-screen screen, screen-obj, x, y + y <- increment # padding + return y +} + fn maybe-render-screen screen: (addr screen), _globals: (addr global-table), xmin: int, ymin: int -> _/ecx: int { var globals/esi: (addr global-table) <- copy _globals var screen-literal-storage: (stream byte 8) @@ -112,24 +147,104 @@ fn maybe-render-screen screen: (addr screen), _globals: (addr global-table), xmi return ymin # silently give up on rendering the screen } var screen-obj-ah/eax: (addr handle screen) <- get screen-obj-cell, screen-data - var screen-obj/eax: (addr screen) <- lookup *screen-obj-ah + var _screen-obj/eax: (addr screen) <- lookup *screen-obj-ah + var screen-obj/edx: (addr screen) <- copy _screen-obj { var screen-empty?/eax: boolean <- fake-screen-empty? screen-obj compare screen-empty?, 0/false break-if-= return ymin } + var x/eax: int <- draw-text-rightward screen, "screen: ", xmin, 0x99/xmax, ymin, 7/fg, 0/bg var y/ecx: int <- copy ymin - y <- add 2 - y <- render-screen screen, screen-obj, xmin, y + y <- render-screen screen, screen-obj, x, y return y } -fn render-screen screen: (addr screen), _target-screen: (addr screen), xmin: int, ymin: int -> _/ecx: int { +fn render-empty-screen screen: (addr screen), _target-screen: (addr screen), xmin: int, ymin: int -> _/ecx: int { var target-screen/esi: (addr screen) <- copy _target-screen + var screen-y/edi: int <- copy ymin + # top border + { + set-cursor-position screen, xmin, screen-y + move-cursor-right screen + var width/edx: (addr int) <- get target-screen, width + var x/ebx: int <- copy 0 + { + compare x, *width + break-if->= + draw-code-point-at-cursor screen, 0x2d/horizontal-bar, 0x18/fg, 0/bg + move-cursor-right screen + x <- increment + loop + } + screen-y <- increment + } + # screen var height/edx: (addr int) <- get target-screen, height var y/ecx: int <- copy 0 + { + compare y, *height + break-if->= + set-cursor-position screen, xmin, screen-y + draw-code-point-at-cursor screen, 0x7c/vertical-bar, 0x18/fg, 0/bg + move-cursor-right screen + var width/edx: (addr int) <- get target-screen, width + var x/ebx: int <- copy 0 + { + compare x, *width + break-if->= + draw-code-point-at-cursor screen, 0x20/space, 0x18/fg, 0/bg + move-cursor-right screen + x <- increment + loop + } + draw-code-point-at-cursor screen, 0x7c/vertical-bar, 0x18/fg, 0/bg + y <- increment + screen-y <- increment + loop + } + # bottom border + { + set-cursor-position screen, xmin, screen-y + move-cursor-right screen + var width/edx: (addr int) <- get target-screen, width + var x/ebx: int <- copy 0 + { + compare x, *width + break-if->= + draw-code-point-at-cursor screen, 0x2d/horizontal-bar, 0x18/fg, 0/bg + move-cursor-right screen + x <- increment + loop + } + screen-y <- increment + } + return screen-y +} + +fn render-screen screen: (addr screen), _target-screen: (addr screen), xmin: int, ymin: int -> _/ecx: int { + var target-screen/esi: (addr screen) <- copy _target-screen var screen-y/edi: int <- copy ymin + # top border + { + set-cursor-position screen, xmin, screen-y + move-cursor-right screen + var width/edx: (addr int) <- get target-screen, width + var x/ebx: int <- copy 0 + { + compare x, *width + break-if->= + draw-code-point-at-cursor screen, 0x2d/horizontal-bar, 0x18/fg, 0/bg + move-cursor-right screen + x <- increment + loop + } + screen-y <- increment + } + # screen + var height/edx: (addr int) <- get target-screen, height + var y/ecx: int <- copy 0 { compare y, *height break-if->= @@ -151,7 +266,23 @@ fn render-screen screen: (addr screen), _target-screen: (addr screen), xmin: int screen-y <- increment loop } - return y + # bottom border + { + set-cursor-position screen, xmin, screen-y + move-cursor-right screen + var width/edx: (addr int) <- get target-screen, width + var x/ebx: int <- copy 0 + { + compare x, *width + break-if->= + draw-code-point-at-cursor screen, 0x2d/horizontal-bar, 0x18/fg, 0/bg + move-cursor-right screen + x <- increment + loop + } + screen-y <- increment + } + return screen-y } fn print-screen-cell-of-fake-screen screen: (addr screen), _target: (addr screen), x: int, y: int { @@ -218,6 +349,7 @@ fn edit-sandbox _self: (addr sandbox), key: byte, globals: (addr global-table), var trace-ah/eax: (addr handle trace) <- get self, trace var trace/eax: (addr trace) <- lookup *trace-ah clear-trace trace + clear-screen-var globals run data, value, globals, trace return } |