You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.0 KiB
Go
51 lines
1.0 KiB
Go
package tui
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"image/color"
|
|
|
|
"github.com/eliukblau/pixterm/pkg/ansimage"
|
|
"github.com/rivo/tview"
|
|
)
|
|
|
|
|
|
type Splashscreen struct {
|
|
Canvas *tview.TextView
|
|
View
|
|
ImageBytes []byte
|
|
}
|
|
|
|
func(t *TUI) NewSplashscreen(logo *[]byte) (*Splashscreen) {
|
|
splashscreen := new(Splashscreen)
|
|
|
|
canvas := tview.NewTextView().
|
|
SetDynamicColors(true).
|
|
SetRegions(true).
|
|
SetWrap(true)
|
|
canvas.SetBorder(false)
|
|
canvas.Clear()
|
|
|
|
splashscreen.ImageBytes = *logo
|
|
|
|
splashscreen.Canvas = canvas
|
|
return splashscreen
|
|
}
|
|
|
|
func (splashscreen *Splashscreen) GetCanvas() (tview.Primitive) {
|
|
return splashscreen.Canvas
|
|
}
|
|
|
|
func(splashscreen *Splashscreen) Draw() {
|
|
canvas := splashscreen.Canvas
|
|
_, _, w, h := canvas.Box.GetRect()
|
|
|
|
logoImage, err := ansimage.NewScaledFromReader(bytes.NewReader(splashscreen.ImageBytes), h, w, color.Black, ansimage.ScaleModeFill, ansimage.NoDithering)
|
|
if err != nil {
|
|
return
|
|
}
|
|
canvas.Clear()
|
|
fmt.Fprint(canvas, tview.TranslateANSI(logoImage.RenderExt(false, false)))
|
|
}
|
|
|