From 4d063740070708e51449d472d919027f2c192e52 Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Wed, 18 Dec 2024 15:47:56 +0100 Subject: [PATCH] fix(font): specify CascadiaCode (MS) correctly --- src/font/cli.go | 13 +++++++++---- src/font/fonts.go | 23 +++++++++++++++++------ website/docs/installation/fonts.mdx | 2 +- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/font/cli.go b/src/font/cli.go index ec77ec36dab3..64a995b945c4 100644 --- a/src/font/cli.go +++ b/src/font/cli.go @@ -150,9 +150,14 @@ func (m *main) Init() tea.Cmd { m.state = downloadFont if !strings.HasPrefix(m.font, "https") { - if strings.HasPrefix(m.font, "CascadiaCode-") { - version := strings.TrimPrefix(m.font, "CascadiaCode-") - m.font = fmt.Sprintf("https://github.com/microsoft/cascadia-code/releases/download/v%s/%s.zip", version, m.font) + if m.font == CascadiaCodeMS { + cascadia, err := CascadiaCode() + if err != nil { + m.err = err + return tea.Quit + } + + m.font = cascadia.URL } else { m.font = fmt.Sprintf("https://github.com/ryanoasis/nerd-fonts/releases/latest/download/%s.zip", m.font) } @@ -299,7 +304,7 @@ func (m *main) View() string { return textStyle.Render(fmt.Sprintf("No need to install a new font? That's cool.%s", terminal.StopProgress())) case done: if len(m.families) == 0 { - return textStyle.Render(fmt.Sprintf("No matching font families were installed. Try setting --zip-folder to the correct folder when using Cascadia Code or a custom font zip file %s", terminal.StopProgress())) //nolint: lll + return textStyle.Render(fmt.Sprintf("No matching font families were installed. Try setting --zip-folder to the correct folder when using CascadiaCode (MS) or a custom font zip file. %s", terminal.StopProgress())) //nolint: lll } var builder strings.Builder diff --git a/src/font/fonts.go b/src/font/fonts.go index db022f3cb78c..637ce3a8dff5 100644 --- a/src/font/fonts.go +++ b/src/font/fonts.go @@ -14,6 +14,10 @@ import ( "github.com/jandedobbeleer/oh-my-posh/src/runtime/http" ) +const ( + CascadiaCodeMS = "CascadiaCode (MS)" +) + type release struct { Assets []*Asset `json:"assets"` } @@ -36,12 +40,11 @@ func Fonts() ([]*Asset, error) { return nil, err } - cascadiaCode, err := fetchFontAssets("microsoft/cascadia-code") - if err != nil { - return assets, nil + cascadiaCode, err := CascadiaCode() + if err == nil { + assets = append(assets, cascadiaCode) } - assets = append(assets, cascadiaCode...) sort.Slice(assets, func(i, j int) bool { return assets[i].Name < assets[j].Name }) setCachedFontData(assets) @@ -81,8 +84,16 @@ func setCachedFontData(assets []*Asset) { cache.Set(cache_.FONTLISTCACHE, string(data), cache_.ONEDAY) } -func CascadiaCode() ([]*Asset, error) { - return fetchFontAssets("microsoft/cascadia-code") +func CascadiaCode() (*Asset, error) { + assets, err := fetchFontAssets("microsoft/cascadia-code") + if err != nil || len(assets) != 1 { + return nil, errors.New("no assets found") + } + + // patch the name + assets[0].Name = CascadiaCodeMS + + return assets[0], nil } func fetchFontAssets(repo string) ([]*Asset, error) { diff --git a/website/docs/installation/fonts.mdx b/website/docs/installation/fonts.mdx index 8cfd0ad21637..ffe8e9ba95f4 100644 --- a/website/docs/installation/fonts.mdx +++ b/website/docs/installation/fonts.mdx @@ -50,7 +50,7 @@ oh-my-posh font install meslo If you have a font that has specific flavors of a font inside sub folders, you can specify the sub folder name: ```bash -oh-my-posh font install --zip-folder ttf/static CascadiaCode-2407.24 +oh-my-posh font install --zip-folder ttf/static "CascadiaCode (MS)" ```