about summary refs log tree commit diff stats
path: root/edit/005-sandbox.mu
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2017-06-23 14:09:11 -0700
committerKartik K. Agaram <vc@akkartik.com>2017-06-23 15:39:14 -0700
commitb1e558cfe42029df630e1c2d9399d4b52c187801 (patch)
tree35fba14030c48c8e3a5e1792ffef9a84095cfe85 /edit/005-sandbox.mu
parent0bf322d6f04c28d4b38eb07f5ee9bd588187a058 (diff)
downloadmu-b1e558cfe42029df630e1c2d9399d4b52c187801.tar.gz
3941
Even though the bug of commit 3938 is now fixed, I'm still trying to
track down why the failure looked different on the fake screen than on
the real one. Snapshot as I try to track down the difference.

One key lesson is that the approach of commit 3860 -- updating the
cursor before rather than after printing each character -- turns out to
be untenable. A sequence of `print` followed by `cursor-position` needs
to behave the same as the real screen.

But it's still not clear how the real screen. When you get to the end of
a line the cursor position wraps after print to the left margin (column
0) on the next row. When you get to the bottom right the cursor position
wraps to the *bottom left* margin. How the heck does it know to scroll
on the next print, then? Is there some hidden state in the terminal?
Diffstat (limited to 'edit/005-sandbox.mu')
-rw-r--r--edit/005-sandbox.mu29
1 files changed, 16 insertions, 13 deletions
diff --git a/edit/005-sandbox.mu b/edit/005-sandbox.mu
index 827f6632..2b17ecc2 100644
--- a/edit/005-sandbox.mu
+++ b/edit/005-sandbox.mu
@@ -14,6 +14,8 @@ def! main [
   env:&:environment <- new-programming-environment 0/filesystem, 0/screen
   env <- restore-sandboxes env, 0/filesystem
   render-all 0/screen, env, render
+  wait-for-some-interaction
+  $exit
   event-loop 0/screen, 0/console, env, 0/filesystem
 ]
 
@@ -268,20 +270,25 @@ def! render-sandbox-side screen:&:screen, env:&:environment, render-editor:rende
   clear-rest-of-screen screen, row, left, right
   #
   assert-no-scroll screen, old-top-idx
+  stash [render sandbox side done]
 ]
 
 def render-sandboxes screen:&:screen, sandbox:&:sandbox, left:num, right:num, row:num, render-from:num, idx:num -> row:num, screen:&:screen, sandbox:&:sandbox [
   local-scope
   load-ingredients
   return-unless sandbox
+  a:num b:num <- cursor-position screen
+  stash [render-sandboxes] idx [:] row [--] a b
   screen-height:num <- screen-height screen
+  at-bottom?:bool <- greater-or-equal row, screen-height
+  return-if at-bottom?
   hidden?:bool <- lesser-than idx, render-from
   {
     break-if hidden?
     # render sandbox menu
     row <- add row, 1
-    at-bottom?:bool <- greater-or-equal row, screen-height
-    return-if at-bottom?
+#?     at-bottom?:bool <- greater-or-equal row, screen-height
+#?     return-if at-bottom?
     screen <- move-cursor screen, row, left
     screen <- render-sandbox-menu screen, idx, left, right
     # save menu row so we can detect clicks to it later
@@ -345,30 +352,26 @@ def render-sandbox-menu screen:&:screen, sandbox-index:num, left:num, right:num
 
 scenario skip-rendering-sandbox-menu-past-bottom-row [
   trace-until 100/app  # trace too long
-  assume-screen 100/width, 7/height
+  assume-screen 100/width, 6/height
   # recipe editor is empty
   assume-resources [
+    [lesson/0] <- [|add 2, 2|]
+    [lesson/1] <- [|add 1, 1|]
   ]
   # create two sandboxes such that the top one just barely fills the screen
   env:&:environment <- new-programming-environment resources, screen, []
-  render-all screen, env, render
-  assume-console [
-    left-click 1, 75
-    type [add 1, 1]
-    press F4
-    type [add 2, 2]
-    press F4
-  ]
+  env <- restore-sandboxes env, resources
+  $clear-trace
   run [
-    event-loop screen, console, env, resources
+    render-all screen, env, render
   ]
+  $dump-trace [app]
   screen-should-contain [
     .                                                                                 run (F4)           .
     .                                                  ┊                                                 .
     .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊─────────────────────────────────────────────────.
     .                                                  ┊0   edit       copy       to recipe    delete    .
     .                                                  ┊add 2, 2                                         .
-    .                                                  ┊4                                                .
     .                                                  ┊─────────────────────────────────────────────────.
   ]
 ]
748'>84965d6 ^
a073d76 ^


6728a11 ^
a073d76 ^











e591221 ^



80e891a ^
a073d76 ^


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85




               
                                  
 
                                         


                        
                        

                                 


                           

                           





                                        

                                                    




                                        
                                        
                                   






                                                        

                                                                     

                                                             



                                                           

                                            







                                                                                  

                                            


                                                
                    











                                                                                              



                                    
                                                                 


                   
package widgets

import (
	"time"

	"github.com/gdamore/tcell"

	"git.sr.ht/~sircmpwn/aerc/lib/ui"
)

type StatusLine struct {
	ui.Invalidatable
	stack    []*StatusMessage
	fallback StatusMessage
}

type StatusMessage struct {
	bg      tcell.Color
	fg      tcell.Color
	message string
}

func NewStatusLine() *StatusLine {
	return &StatusLine{
		fallback: StatusMessage{
			bg:      tcell.ColorDefault,
			fg:      tcell.ColorDefault,
			message: "Idle",
		},
	}
}

func (status *StatusLine) Invalidate() {
	status.DoInvalidate(status)
}

func (status *StatusLine) Draw(ctx *ui.Context) {
	line := &status.fallback
	if len(status.stack) != 0 {
		line = status.stack[len(status.stack)-1]
	}
	style := tcell.StyleDefault.
		Background(line.bg).Foreground(line.fg).Reverse(true)
	ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', style)
	ctx.Printf(0, 0, style, "%s", line.message)
}

func (status *StatusLine) Set(text string) *StatusMessage {
	status.fallback = StatusMessage{
		bg:      tcell.ColorDefault,
		fg:      tcell.ColorDefault,
		message: text,
	}
	status.Invalidate()
	return &status.fallback
}

func (status *StatusLine) Push(text string, expiry time.Duration) *StatusMessage {
	msg := &StatusMessage{
		bg:      tcell.ColorDefault,
		fg:      tcell.ColorDefault,
		message: text,
	}
	status.stack = append(status.stack, msg)
	go (func() {
		time.Sleep(expiry)
		for i, m := range status.stack {
			if m == msg {
				status.stack = append(status.stack[:i], status.stack[i+1:]...)
				break
			}
		}
		status.Invalidate()
	})()
	return msg
}

func (status *StatusLine) Expire() {
	status.stack = nil
}

func (msg *StatusMessage) Color(bg tcell.Color, fg tcell.Color) {
	msg.bg = bg
	msg.fg = fg
}