mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-03-05 20:49:04 -08:00
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
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:
parent
cb7a5d0dd8
commit
4d06374007
|
@ -150,9 +150,14 @@ func (m *main) Init() tea.Cmd {
|
||||||
m.state = downloadFont
|
m.state = downloadFont
|
||||||
|
|
||||||
if !strings.HasPrefix(m.font, "https") {
|
if !strings.HasPrefix(m.font, "https") {
|
||||||
if strings.HasPrefix(m.font, "CascadiaCode-") {
|
if m.font == CascadiaCodeMS {
|
||||||
version := strings.TrimPrefix(m.font, "CascadiaCode-")
|
cascadia, err := CascadiaCode()
|
||||||
m.font = fmt.Sprintf("https://github.com/microsoft/cascadia-code/releases/download/v%s/%s.zip", version, m.font)
|
if err != nil {
|
||||||
|
m.err = err
|
||||||
|
return tea.Quit
|
||||||
|
}
|
||||||
|
|
||||||
|
m.font = cascadia.URL
|
||||||
} else {
|
} else {
|
||||||
m.font = fmt.Sprintf("https://github.com/ryanoasis/nerd-fonts/releases/latest/download/%s.zip", m.font)
|
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()))
|
return textStyle.Render(fmt.Sprintf("No need to install a new font? That's cool.%s", terminal.StopProgress()))
|
||||||
case done:
|
case done:
|
||||||
if len(m.families) == 0 {
|
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
|
var builder strings.Builder
|
||||||
|
|
|
@ -14,6 +14,10 @@ import (
|
||||||
"github.com/jandedobbeleer/oh-my-posh/src/runtime/http"
|
"github.com/jandedobbeleer/oh-my-posh/src/runtime/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
CascadiaCodeMS = "CascadiaCode (MS)"
|
||||||
|
)
|
||||||
|
|
||||||
type release struct {
|
type release struct {
|
||||||
Assets []*Asset `json:"assets"`
|
Assets []*Asset `json:"assets"`
|
||||||
}
|
}
|
||||||
|
@ -36,12 +40,11 @@ func Fonts() ([]*Asset, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
cascadiaCode, err := fetchFontAssets("microsoft/cascadia-code")
|
cascadiaCode, err := CascadiaCode()
|
||||||
if err != nil {
|
if err == nil {
|
||||||
return assets, nil
|
assets = append(assets, cascadiaCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
assets = append(assets, cascadiaCode...)
|
|
||||||
sort.Slice(assets, func(i, j int) bool { return assets[i].Name < assets[j].Name })
|
sort.Slice(assets, func(i, j int) bool { return assets[i].Name < assets[j].Name })
|
||||||
|
|
||||||
setCachedFontData(assets)
|
setCachedFontData(assets)
|
||||||
|
@ -81,8 +84,16 @@ func setCachedFontData(assets []*Asset) {
|
||||||
cache.Set(cache_.FONTLISTCACHE, string(data), cache_.ONEDAY)
|
cache.Set(cache_.FONTLISTCACHE, string(data), cache_.ONEDAY)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CascadiaCode() ([]*Asset, error) {
|
func CascadiaCode() (*Asset, error) {
|
||||||
return fetchFontAssets("microsoft/cascadia-code")
|
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) {
|
func fetchFontAssets(repo string) ([]*Asset, error) {
|
||||||
|
|
|
@ -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:
|
If you have a font that has specific flavors of a font inside sub folders, you can specify the sub folder name:
|
||||||
|
|
||||||
```bash
|
```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>
|
</TabItem>
|
||||||
|
|
Loading…
Reference in a new issue