summaryrefslogtreecommitdiff
path: root/cmds/console-hello-world/newJ.go
blob: 47c7439a7b2725e1378219033586abcefe6dc2f4 (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
// Copyright 2014 The gocui Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

import (
	"errors"
	"fmt"
	"log"
	"strings"

	"github.com/awesome-gocui/gocui"
)

var topX int = 2
var bottomX int = 20
var topY int = 2
var bottomY int = 7

func newJ(g *gocui.Gui) error {
	// maxX, maxY := g.Size()
	name := fmt.Sprintf("jcarr %v test ", idxView)
	v, err := g.SetView(name, topX, topY, bottomX, bottomY, 0)
	if err == nil {
		return err
	}
	if !errors.Is(err, gocui.ErrUnknownView) {
		return err
	}

	v.Wrap = true
	fmt.Fprintln(v, name)
	fmt.Fprintln(v, strings.Repeat("foo\n", 2))
	// fmt.Fprintln(v, strings.Repeat(name+" ", 30))
	log.Println("newJ added a new view", v.Name())

	if _, err := g.SetCurrentView(name); err != nil {
		return err
	}

	views = append(views, name)
	curView = len(views) - 1
	idxView += 1
	return nil
}