Debian Codegraph @

demos/presentation/code.go

raw symbols SCIP
1 package main
2
3 import (
4 "fmt"
5
6 "github.com/rivo/tview"
7 )
8
9 // The width of the code window.
10 const codeWidth = 56
11
12 // Code returns a primitive which displays the given primitive (with the given
13 // size) on the left side and its source code on the right side.
14 func Code(p tview.Primitive, width, height int, code string) tview.Primitive {
15 // Set up code view.
16 codeView := tview.NewTextView().
17 SetWrap(false).
18 SetDynamicColors(true)
19 codeView.SetBorderPadding(1, 1, 2, 0)
20 fmt.Fprint(codeView, code)
21
22 return tview.NewFlex().
23 AddItem(Center(width, height, p), 0, 1, true).
24 AddItem(codeView, codeWidth, 1, false)
25 }