File: code.go

package info (click to toggle)
golang-github-rivo-tview 0.0~git20230530.8bd761d-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,868 kB
  • sloc: makefile: 3
file content (25 lines) | stat: -rw-r--r-- 621 bytes parent folder | download | duplicates (4)
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
package main

import (
	"fmt"

	"github.com/rivo/tview"
)

// The width of the code window.
const codeWidth = 56

// Code returns a primitive which displays the given primitive (with the given
// size) on the left side and its source code on the right side.
func Code(p tview.Primitive, width, height int, code string) tview.Primitive {
	// Set up code view.
	codeView := tview.NewTextView().
		SetWrap(false).
		SetDynamicColors(true)
	codeView.SetBorderPadding(1, 1, 2, 0)
	fmt.Fprint(codeView, code)

	return tview.NewFlex().
		AddItem(Center(width, height, p), 0, 1, true).
		AddItem(codeView, codeWidth, 1, false)
}