summaryrefslogtreecommitdiff
path: root/eventBindingsStdout.go
blob: 8e59b7d95ab1ecd5ba91b6f0a115967223294961 (plain)
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0

package main

import (
	"fmt"

	"github.com/awesome-gocui/gocui"
	"go.wit.com/log"
	"go.wit.com/toolkits/tree"
)

func theStdout(g *gocui.Gui, v *gocui.View) error {
	// me.stdout.pager = 0
	infos := fmt.Sprintf("pager=%d len(%d) ", me.stdout.pager, len(me.stdout.outputS))
	infos += fmt.Sprintf("last(%d,%d)", me.stdout.lastW, me.stdout.lastH)
	me.stdout.changed = true

	if me.stdout.outputOnTop {
		if me.stdout.outputOffscreen {
			me.stdout.outputOffscreen = false
			log.Info("stdout moved off screen", infos)
			me.stdout.lastW = me.stdout.tk.gocuiSize.w0
			me.stdout.lastH = me.stdout.tk.gocuiSize.h0
			relocateStdoutOffscreen()
			new1 := new(tree.ToolkitConfig)
			new1.Plugin = "gocui"
			new1.Name = "stdoutoffscreen"
			new1.Value = "true"
			me.myTree.ConfigSave(new1)
			return nil
		} else {
			me.stdout.outputOffscreen = true
			log.Info("stdout moved on  screen", infos)
			new1 := new(tree.ToolkitConfig)
			new1.Plugin = "gocui"
			new1.Name = "stdoutoffscreen"
			new1.Value = "false"
			me.myTree.ConfigSave(new1)
		}
		// move the stdout window back onscreen
		me.stdout.tk.relocateStdout(me.stdout.lastW, me.stdout.lastH)
		me.stdout.outputOnTop = false
		setThingsOnTop()
		new1 := new(tree.ToolkitConfig)
		new1.Plugin = "gocui"
		new1.Name = "stdoutlevel"
		new1.Value = "bottom"
		me.myTree.ConfigSave(new1)
	} else {
		me.stdout.outputOnTop = true
		setThingsOnTop()
		new1 := new(tree.ToolkitConfig)
		new1.Plugin = "gocui"
		new1.Name = "stdoutlevel"
		new1.Value = "top"
		me.myTree.ConfigSave(new1)
	}
	return nil
}

func stdoutPgup(g *gocui.Gui, v *gocui.View) error {
	me.stdout.pager -= me.stdout.Height() - 2
	if me.stdout.pager < 0 {
		me.stdout.pager = 0
	}
	tk := me.stdout.tk
	tk.refreshStdout()
	return nil
}

func stdoutHome(g *gocui.Gui, v *gocui.View) error {
	me.stdout.pager = 0
	me.stdout.tk.refreshStdout()
	return nil
}

func stdoutArrowUp(g *gocui.Gui, v *gocui.View) error {
	if me.stdout.reverse {
		stdoutWheelsDown()
	} else {
		stdoutWheelsUp()
	}
	return nil
}

func stdoutArrowDown(g *gocui.Gui, v *gocui.View) error {
	if me.stdout.reverse {
		stdoutWheelsUp()
	} else {
		stdoutWheelsDown()
	}
	return nil
}

func stdoutPgdn(g *gocui.Gui, v *gocui.View) error {
	win := findWindowUnderMouse()
	if win != nil {
		if win.full.Height() > 50 {
			log.Info("paging through really large window pager =", win.window.pager)
			win.window.pager += 10
			return nil
		}
	}
	me.stdout.pager += 10

	tk := me.stdout.tk
	tk.refreshStdout()
	return nil
}

// scrolling up with the mouse wheel (or trackpad)
func stdoutWheelsUp() {
	// log.Info("private wheels up")
	me.stdout.pager -= 2
	if me.stdout.pager < 0 {
		me.stdout.pager = 0
	}
	me.stdout.tk.refreshStdout()
}

// scrolling down with the mouse wheel (or trackpad)
func stdoutWheelsDown() {
	// log.Info("you've landed")
	me.stdout.pager += 2
	if me.stdout.pager > len(me.stdout.outputS) {
		me.stdout.pager = len(me.stdout.outputS)
	}
	me.stdout.tk.refreshStdout()
}