2022-01-26 23:38:46 -08:00
|
|
|
|
package engine
|
2021-04-04 11:28:41 -07:00
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"io/ioutil"
|
2022-01-26 04:09:21 -08:00
|
|
|
|
"oh-my-posh/color"
|
2022-03-21 23:41:36 -07:00
|
|
|
|
"oh-my-posh/shell"
|
2021-04-04 11:28:41 -07:00
|
|
|
|
"os"
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func runImageTest(content string) error {
|
2022-01-26 23:38:46 -08:00
|
|
|
|
poshImagePath := "jandedobbeleer.png"
|
2021-04-04 11:28:41 -07:00
|
|
|
|
file, err := ioutil.TempFile("", poshImagePath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
defer os.Remove(file.Name())
|
2022-01-26 04:09:21 -08:00
|
|
|
|
ansi := &color.Ansi{}
|
2022-04-03 04:04:56 -07:00
|
|
|
|
ansi.InitPlain(shell.PLAIN)
|
2021-04-04 11:28:41 -07:00
|
|
|
|
image := &ImageRenderer{
|
2022-01-26 23:38:46 -08:00
|
|
|
|
AnsiString: content,
|
|
|
|
|
Ansi: ansi,
|
2021-04-04 11:28:41 -07:00
|
|
|
|
}
|
2022-01-26 23:38:46 -08:00
|
|
|
|
image.Init("~/jandedobbeleer.omp.json")
|
|
|
|
|
err = image.SavePNG()
|
2021-04-04 11:28:41 -07:00
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestStringImageFileWithText(t *testing.T) {
|
|
|
|
|
err := runImageTest("foobar")
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestStringImageFileWithANSI(t *testing.T) {
|
2022-02-03 08:36:37 -08:00
|
|
|
|
prompt := `[38;2;40;105;131m[0m[48;2;40;105;131m[38;2;224;222;244m jan [0m[38;2;40;105;131m[0m[38;2;224;222;244m [0m`
|
2021-04-04 11:28:41 -07:00
|
|
|
|
err := runImageTest(prompt)
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
}
|