Skip to content

Commit

Permalink
fix(font): specify CascadiaCode (MS) correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
JanDeDobbeleer committed Dec 18, 2024
1 parent cb7a5d0 commit 4d06374
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
13 changes: 9 additions & 4 deletions src/font/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down
23 changes: 17 additions & 6 deletions src/font/fonts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand All @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/installation/fonts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
```

</TabItem>
Expand Down

0 comments on commit 4d06374

Please sign in to comment.