fix(font): specify CascadiaCode (MS) correctly
Some checks failed
Code QL / code-ql (push) Has been cancelled
Azure Static Web Apps CI/CD / Build and Deploy (push) Has been cancelled
Release / changelog (push) Has been cancelled
Release / artifacts (push) Has been cancelled
Release / msi (arm64) (push) Has been cancelled
Release / msi (x64) (push) Has been cancelled
Release / msi (x86) (push) Has been cancelled
Release / release (push) Has been cancelled

This commit is contained in:
Jan De Dobbeleer 2024-12-18 15:47:56 +01:00 committed by Jan De Dobbeleer
parent cb7a5d0dd8
commit 4d06374007
3 changed files with 27 additions and 11 deletions

View file

@ -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

View file

@ -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) {

View file

@ -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>