Skip to content

Commit

Permalink
Merge remote-tracking branch 'source/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
BoscoDomingo committed Feb 13, 2025
2 parents 34cc5b6 + c25e278 commit e2da557
Show file tree
Hide file tree
Showing 35 changed files with 362 additions and 186 deletions.
23 changes: 22 additions & 1 deletion .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -2896,7 +2896,8 @@
"profile": "https://mpb-dev.fr/",
"contributions": [
"code",
"design"
"design",
"doc"
]
},
{
Expand Down Expand Up @@ -2934,6 +2935,26 @@
"contributions": [
"doc"
]
},
{
"login": "vil02",
"name": "Piotr Idzik",
"avatar_url": "https://avatars.githubusercontent.com/u/65706193?v=4",
"profile": "https://github.com/vil02",
"contributions": [
"code"
]
},
{
"login": "wiyco",
"name": "wiyco",
"avatar_url": "https://avatars.githubusercontent.com/u/72733890?v=4",
"profile": "https://wiyco.dev",
"contributions": [
"code",
"design",
"doc"
]
}
],
"contributorsPerLine": 7,
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build_code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ jobs:
- name: Install Go 🗳
uses: ./.github/workflows/composite/bootstrap-go
- name: Run GoReleaser 🚀
uses: goreleaser/goreleaser-action@9ed2f89a662bf1735a48bc8557fd212fa902bebf
uses: goreleaser/goreleaser-action@90a3faa9d0182683851fbfa97ca1a2cb983bfca3
with:
distribution: goreleaser
version: v2.3.2
args: build --clean --snapshot --skip=post-hooks --skip=before
workdir: src
- name: Archive production artifacts
uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08
with:
name: builds
retention-days: 1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Install Go 🗳
uses: ./.github/workflows/composite/bootstrap-go
- name: Golang CI
uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8
uses: golangci/golangci-lint-action@051d91933864810ecd5e2ea2cfd98f6a5bca5347
with:
working-directory: src
- name: Fieldalignment
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Install Go 🗳
uses: ./.github/workflows/composite/bootstrap-go
- name: Setup Node.js
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a
with:
node-version: 20.9.0
# Create Kind cluster to have a Kubernetes context for cloud-native-azure theme
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
run: |
./pre.ps1 -Version ${{ needs.changelog.outputs.version }}
- name: Run GoReleaser 🚀
uses: goreleaser/goreleaser-action@9ed2f89a662bf1735a48bc8557fd212fa902bebf
uses: goreleaser/goreleaser-action@90a3faa9d0182683851fbfa97ca1a2cb983bfca3
with:
distribution: goreleaser
version: v2.3.2
Expand All @@ -63,7 +63,7 @@ jobs:
- name: Post Build 🤐
run: |
./post.ps1
- uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b
- uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08
with:
name: build-artifacts
path: |
Expand Down Expand Up @@ -100,7 +100,7 @@ jobs:
run: |
$version = '${{ needs.changelog.outputs.version }}'.TrimStart("v")
./build.ps1 -Architecture ${{ matrix.arch }} -Version $version -Copy -Sign
- uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b
- uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08
with:
name: msi-artifact-${{ matrix.arch }}
path: |
Expand All @@ -124,7 +124,7 @@ jobs:
az storage blob upload-batch --destination v${{ needs.changelog.outputs.version }} --source .
az storage blob upload-batch --destination latest --overwrite true --source .
- name: Release 🎓
uses: softprops/action-gh-release@01570a1f39cb168c169c802c3bceb9e93fb10974
uses: softprops/action-gh-release@c95fe1489396fe8a9eb87c0abf8aa5b2ef267fda
with:
tag_name: ${{ needs.changelog.outputs.tag }}
body: ${{ needs.changelog.outputs.body }}
Expand Down
9 changes: 5 additions & 4 deletions src/cli/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@ func runInit(sh string) {
cfg := config.Load(configFile, sh, false)

flags := &runtime.Flags{
Shell: sh,
Config: configFile,
Strict: strict,
Debug: debug,
Shell: sh,
Config: configFile,
Strict: strict,
Debug: debug,
SaveCache: true,
}

env := &runtime.Terminal{}
Expand Down
4 changes: 2 additions & 2 deletions src/color/colors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ func TestGetAnsiFromColorString(t *testing.T) {
{Case: "Invalid background", Expected: emptyColor, Color: "invalid", Background: true},
{Case: "Invalid background", Expected: emptyColor, Color: "invalid", Background: false},
{Case: "Hex foreground", Expected: Ansi("38;2;170;187;204"), Color: "#AABBCC", Background: false},
{Case: "Hex backgrond", Expected: Ansi("48;2;170;187;204"), Color: "#AABBCC", Background: true},
{Case: "Hex background", Expected: Ansi("48;2;170;187;204"), Color: "#AABBCC", Background: true},
{Case: "Base 8 foreground", Expected: Ansi("31"), Color: "red", Background: false},
{Case: "Base 8 background", Expected: Ansi("41"), Color: "red", Background: true},
{Case: "Base 16 foreground", Expected: Ansi("91"), Color: "lightRed", Background: false},
{Case: "Base 16 backround", Expected: Ansi("101"), Color: "lightRed", Background: true},
{Case: "Base 16 background", Expected: Ansi("101"), Color: "lightRed", Background: true},
{Case: "Non true color TERM", Expected: Ansi("38;5;146"), Color: "#AABBCC", Color256: true},
}
for _, tc := range cases {
Expand Down
2 changes: 1 addition & 1 deletion src/color/palette.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Palette map[Ansi]Ansi
const (
paletteKeyPrefix = "p:"
paletteKeyError = "palette: requested color %s does not exist in palette of colors %s"
paletteMaxRecursionDepth = 3 // allows 3 or less recusive resolutions
paletteMaxRecursionDepth = 3 // allows 3 or less recursive resolutions
paletteRecursiveKeyError = "palette: recursive resolution of color %s returned palette reference %s and reached recursion depth %d"
)

Expand Down
49 changes: 32 additions & 17 deletions src/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,23 +100,7 @@ func (cfg *Config) Features(env runtime.Environment) shell.Features {
feats = append(feats, shell.FTCSMarks)
}

autoUpgrade := cfg.Upgrade.Auto
if _, OK := env.Cache().Get(AUTOUPGRADE); OK {
autoUpgrade = true
}

upgradeNotice := cfg.Upgrade.DisplayNotice
if _, OK := env.Cache().Get(UPGRADENOTICE); OK {
upgradeNotice = true
}

if upgradeNotice && !autoUpgrade {
feats = append(feats, shell.Notice)
}

if autoUpgrade {
feats = append(feats, shell.Upgrade)
}
feats = append(feats, cfg.UpgradeFeatures(env)...)

if cfg.ErrorLine != nil || cfg.ValidLine != nil {
feats = append(feats, shell.LineError)
Expand Down Expand Up @@ -158,3 +142,34 @@ func (cfg *Config) Features(env runtime.Environment) shell.Features {

return feats
}

func (cfg *Config) UpgradeFeatures(env runtime.Environment) shell.Features {
feats := shell.Features{}

if _, OK := env.Cache().Get(upgrade.CACHEKEY); OK && !cfg.Upgrade.Force {
return feats
}

// always reset the cache key so we respect the interval no matter what the outcome
env.Cache().Set(upgrade.CACHEKEY, "", cfg.Upgrade.Interval)

autoUpgrade := cfg.Upgrade.Auto
if _, OK := env.Cache().Get(AUTOUPGRADE); OK {
autoUpgrade = true
}

upgradeNotice := cfg.Upgrade.DisplayNotice
if _, OK := env.Cache().Get(UPGRADENOTICE); OK {
upgradeNotice = true
}

if upgradeNotice && !autoUpgrade {
feats = append(feats, shell.Notice)
}

if autoUpgrade {
feats = append(feats, shell.Upgrade)
}

return feats
}
86 changes: 86 additions & 0 deletions src/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ import (
"testing"

"github.com/jandedobbeleer/oh-my-posh/src/cache"
cache_ "github.com/jandedobbeleer/oh-my-posh/src/cache/mock"
"github.com/jandedobbeleer/oh-my-posh/src/color"
"github.com/jandedobbeleer/oh-my-posh/src/runtime/mock"
"github.com/jandedobbeleer/oh-my-posh/src/shell"
"github.com/jandedobbeleer/oh-my-posh/src/template"
"github.com/jandedobbeleer/oh-my-posh/src/upgrade"

"github.com/stretchr/testify/assert"
mock_ "github.com/stretchr/testify/mock"
)

func TestGetPalette(t *testing.T) {
Expand Down Expand Up @@ -107,3 +111,85 @@ func TestGetPalette(t *testing.T) {
assert.Equal(t, tc.ExpectedPalette, got, tc.Case)
}
}
func TestUpgradeFeatures(t *testing.T) {
cases := []struct {
Case string
ExpectedFeats shell.Features
UpgradeCacheKeyExists bool
AutoUpgrade bool
Force bool
DisplayNotice bool
AutoUpgradeKey bool
NoticeKey bool
}{
{
Case: "cache exists, no force",
UpgradeCacheKeyExists: true,
ExpectedFeats: shell.Features{},
},
{
Case: "auto upgrade enabled",
AutoUpgrade: true,
ExpectedFeats: shell.Features{shell.Upgrade},
},
{
Case: "auto upgrade via cache",
AutoUpgradeKey: true,
ExpectedFeats: shell.Features{shell.Upgrade},
},
{
Case: "notice enabled, no auto upgrade",
DisplayNotice: true,
ExpectedFeats: shell.Features{shell.Notice},
},
{
Case: "notice via cache, no auto upgrade",
NoticeKey: true,
ExpectedFeats: shell.Features{shell.Notice},
},
{
Case: "force upgrade ignores cache",
UpgradeCacheKeyExists: true,
Force: true,
AutoUpgrade: true,
ExpectedFeats: shell.Features{shell.Upgrade},
},
}

for _, tc := range cases {
env := &mock.Environment{}
cache := &cache_.Cache{}
env.On("Cache").Return(cache)

if tc.UpgradeCacheKeyExists {
cache.On("Get", upgrade.CACHEKEY).Return("", true)
} else {
cache.On("Get", upgrade.CACHEKEY).Return("", false)
}

cache.On("Set", upgrade.CACHEKEY, "", mock_.Anything).Return()

if tc.AutoUpgradeKey {
cache.On("Get", AUTOUPGRADE).Return("", true)
} else {
cache.On("Get", AUTOUPGRADE).Return("", false)
}

if tc.NoticeKey {
cache.On("Get", UPGRADENOTICE).Return("", true)
} else {
cache.On("Get", UPGRADENOTICE).Return("", false)
}

cfg := &Config{
Upgrade: &upgrade.Config{
Auto: tc.AutoUpgrade,
Force: tc.Force,
DisplayNotice: tc.DisplayNotice,
},
}

got := cfg.UpgradeFeatures(env)
assert.Equal(t, tc.ExpectedFeats, got, tc.Case)
}
}
22 changes: 11 additions & 11 deletions src/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,26 @@ require (
github.com/stretchr/testify v1.10.0
github.com/wayneashleyberry/terminal-dimensions v1.1.0
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/image v0.23.0
golang.org/x/sys v0.28.0
golang.org/x/text v0.21.0
golang.org/x/image v0.24.0
golang.org/x/sys v0.30.0
golang.org/x/text v0.22.0
gopkg.in/ini.v1 v1.67.0
)

require (
github.com/ConradIrwin/font v0.0.0-20240627033111-8567075b2bfe
github.com/ConradIrwin/font v0.2.1
github.com/charmbracelet/bubbles v0.20.0
github.com/charmbracelet/bubbletea v1.2.4
github.com/charmbracelet/bubbletea v1.3.3
github.com/charmbracelet/lipgloss v1.0.0
github.com/goccy/go-json v0.10.4
github.com/goccy/go-json v0.10.5
github.com/goccy/go-yaml v1.15.13
github.com/gookit/goutil v0.6.18
github.com/hashicorp/hcl/v2 v2.23.0
github.com/mattn/go-runewidth v0.0.16
github.com/pelletier/go-toml/v2 v2.2.3
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67
golang.org/x/mod v0.22.0
github.com/spf13/pflag v1.0.6
golang.org/x/mod v0.23.0
gopkg.in/yaml.v3 v3.0.1
)

Expand All @@ -66,7 +65,7 @@ require (
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/charmbracelet/x/ansi v0.6.0 // indirect
github.com/charmbracelet/x/ansi v0.8.0 // indirect
github.com/charmbracelet/x/term v0.2.1 // indirect
github.com/dsnet/compress v0.0.1 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
Expand All @@ -86,7 +85,8 @@ require (
github.com/shopspring/decimal v1.4.0 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
github.com/zclconf/go-cty v1.15.1 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67 // indirect
golang.org/x/sync v0.11.0 // indirect
golang.org/x/tools v0.28.0 // indirect
)

Expand Down
Loading

0 comments on commit e2da557

Please sign in to comment.