Debian Codegraph @

mauview-test/main.go

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 // mauview - A Go TUI library based on tcell.
2 // Copyright © 2019 Tulir Asokan
3 //
4 // This Source Code Form is subject to the terms of the Mozilla Public
5 // License, v. 2.0. If a copy of the MPL was not distributed with this
6 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
8 package main
9
10 import (
•11 "github.com/gdamore/tcell/v2"
12
13 "go.mau.fi/mauview"
14 )
15
16 type Text struct {
17 mauview.SimpleEventHandler
18 Text string
19 }
20
21 func (text *Text) Draw(screen mauview.Screen) {
22 for i, char := range text.Text {
23 screen.SetCell(i, 0, tcell.StyleDefault, char)
24 }
25 }
26
27 func main() {
28 app := mauview.NewApplication()
29 grid := mauview.NewGrid()
30 textComp := &Text{mauview.SimpleEventHandler{}, "Hello, World!"}
31 textComp.OnKey = func(event mauview.KeyEvent) bool {
32 if event.Key() == tcell.KeyCtrlC {
33 app.Stop()
34 }
35 return false
36 }
37 grid.SetColumn(0, 25)
38 grid.SetRow(1, 15)
39 grid.SetRow(3, 5)
40 grid.SetRow(4, 3)
41 grid.AddComponent(mauview.NewBox(textComp), 1, 0, 2, 2)
42 grid.AddComponent(mauview.NewBox(mauview.NewFlex().SetDirection(mauview.FlexRow).
43 AddFixedComponent(mauview.NewBox(nil), 10).
44 AddProportionalComponent(mauview.NewBox(nil), 3).
45 AddProportionalComponent(mauview.NewBox(nil), 1).
46 AddFixedComponent(mauview.NewBox(nil), 10)), 0, 0, 1, 3)
47 grid.AddComponent(mauview.NewBox(
48 mauview.NewGrid().
49 AddComponent(&Text{mauview.SimpleEventHandler{}, "Hello, World! (again)"}, 0, 1, 1, 1).
50 AddComponent(mauview.NewBox(mauview.NewInputArea().SetPlaceholder("I'm holding a place!")), 0, 0, 2, 1).
51 AddComponent(mauview.NewBox(nil), 1, 1, 1, 1)),
52 1, 2, 1, 1)
53 grid.AddComponent(mauview.NewBox(mauview.Center(mauview.NewBox(nil), 10, 5).SetAlwaysFocusChild(true)), 2, 2, 1, 1)
54 grid.AddComponent(mauview.NewBox(nil), 0, 4, 2, 1)
55 grid.AddComponent(mauview.NewBox(mauview.NewInputField()), 0, 3, 3, 1)
56 app.SetRoot(mauview.NewBox(grid))
57 err := app.Start()
58 if err != nil {
59 panic(err)
60 }
61 }