2017-12-30 21:10:13 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2020-01-22 23:28:19 +00:00
|
|
|
"gitlab.com/tslocum/cview"
|
2017-12-30 21:10:13 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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.
|
2019-12-30 23:12:17 +00:00
|
|
|
func Code(p cview.Primitive, width, height int, code string) cview.Primitive {
|
2017-12-30 21:10:13 +00:00
|
|
|
// Set up code view.
|
2020-10-07 23:34:21 +00:00
|
|
|
codeView := cview.NewTextView()
|
|
|
|
codeView.SetWrap(false)
|
|
|
|
codeView.SetDynamicColors(true)
|
2020-10-26 17:41:47 +00:00
|
|
|
codeView.SetPadding(1, 1, 2, 0)
|
2017-12-30 21:10:13 +00:00
|
|
|
fmt.Fprint(codeView, code)
|
|
|
|
|
2020-10-07 23:34:21 +00:00
|
|
|
f := cview.NewFlex()
|
|
|
|
f.AddItem(Center(width, height, p), 0, 1, true)
|
|
|
|
f.AddItem(codeView, codeWidth, 1, false)
|
|
|
|
return f
|
2017-12-30 21:10:13 +00:00
|
|
|
}
|