mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-03-05 20:49:04 -08:00
parent
c34e39c4ed
commit
c62a272e72
|
@ -270,8 +270,12 @@ func escapeGlyphs(s string, migrate bool) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
var cp codePoints
|
var cp codePoints
|
||||||
|
var err error
|
||||||
if migrate {
|
if migrate {
|
||||||
cp = getGlyphCodePoints()
|
cp, err = getGlyphCodePoints()
|
||||||
|
if err != nil {
|
||||||
|
migrate = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var builder strings.Builder
|
var builder strings.Builder
|
||||||
|
|
|
@ -45,6 +45,14 @@ import (
|
||||||
"golang.org/x/image/font"
|
"golang.org/x/image/font"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type ConnectionError struct {
|
||||||
|
reason string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *ConnectionError) Error() string {
|
||||||
|
return f.reason
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
red = "#ED655A"
|
red = "#ED655A"
|
||||||
yellow = "#E1C04C"
|
yellow = "#E1C04C"
|
||||||
|
@ -150,7 +158,7 @@ func (ir *ImageRenderer) Init(env platform.Environment) error {
|
||||||
ir.cleanContent()
|
ir.cleanContent()
|
||||||
|
|
||||||
if err := ir.loadFonts(); err != nil {
|
if err := ir.loadFonts(); err != nil {
|
||||||
return err
|
return &ConnectionError{reason: err.Error()}
|
||||||
}
|
}
|
||||||
|
|
||||||
ir.defaultForegroundColor = &RGB{255, 255, 255}
|
ir.defaultForegroundColor = &RGB{255, 255, 255}
|
||||||
|
|
|
@ -48,17 +48,26 @@ func runImageTest(config, content string) (string, error) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = image.Init(env)
|
err = image.Init(env)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
err = image.SavePNG()
|
err = image.SavePNG()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
os.Remove(image.Path)
|
os.Remove(image.Path)
|
||||||
}
|
}
|
||||||
|
|
||||||
return filepath.Base(image.Path), err
|
return filepath.Base(image.Path), err
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStringImageFileWithText(t *testing.T) {
|
func TestStringImageFileWithText(t *testing.T) {
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
filename, err := runImageTest(tc.Config, "foobar")
|
filename, err := runImageTest(tc.Config, "foobar")
|
||||||
|
if connectionError, ok := err.(*ConnectionError); ok {
|
||||||
|
t.Log(connectionError.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
assert.Equal(t, "jandedobbeleer.png", filename, tc.Case)
|
assert.Equal(t, "jandedobbeleer.png", filename, tc.Case)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
@ -68,6 +77,10 @@ func TestStringImageFileWithANSI(t *testing.T) {
|
||||||
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`
|
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`
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
filename, err := runImageTest(tc.Config, prompt)
|
filename, err := runImageTest(tc.Config, prompt)
|
||||||
|
if connectionError, ok := err.(*ConnectionError); ok {
|
||||||
|
t.Log(connectionError.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
assert.Equal(t, "jandedobbeleer.png", filename, tc.Case)
|
assert.Equal(t, "jandedobbeleer.png", filename, tc.Case)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
|
|
||||||
type codePoints map[int]int
|
type codePoints map[int]int
|
||||||
|
|
||||||
func getGlyphCodePoints() codePoints {
|
func getGlyphCodePoints() (codePoints, error) {
|
||||||
var codePoints = make(codePoints)
|
var codePoints = make(codePoints)
|
||||||
|
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
|
@ -19,19 +19,19 @@ func getGlyphCodePoints() codePoints {
|
||||||
|
|
||||||
request, err := http.NewRequestWithContext(ctx, http.MethodGet, "https://ohmyposh.dev/codepoints.csv", nil)
|
request, err := http.NewRequestWithContext(ctx, http.MethodGet, "https://ohmyposh.dev/codepoints.csv", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return codePoints
|
return codePoints, &ConnectionError{reason: err.Error()}
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := client.Do(request)
|
response, err := client.Do(request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return codePoints
|
return codePoints, err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer response.Body.Close()
|
defer response.Body.Close()
|
||||||
|
|
||||||
lines, err := csv.NewReader(response.Body).ReadAll()
|
lines, err := csv.NewReader(response.Body).ReadAll()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return codePoints
|
return codePoints, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, line := range lines {
|
for _, line := range lines {
|
||||||
|
@ -48,5 +48,5 @@ func getGlyphCodePoints() codePoints {
|
||||||
}
|
}
|
||||||
codePoints[int(oldGlyph)] = int(newGlyph)
|
codePoints[int(oldGlyph)] = int(newGlyph)
|
||||||
}
|
}
|
||||||
return codePoints
|
return codePoints, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetCodePoints(t *testing.T) {
|
func TestGetCodePoints(t *testing.T) {
|
||||||
codepoints := getGlyphCodePoints()
|
codepoints, err := getGlyphCodePoints()
|
||||||
|
if connectionError, ok := err.(*ConnectionError); ok {
|
||||||
|
t.Log(connectionError.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
assert.Equal(t, 1939, len(codepoints))
|
assert.Equal(t, 1939, len(codepoints))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue