Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix function typo #4269

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions src/engine/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,26 @@ const (

// Config holds all the theme for rendering the prompt
type Config struct {
Version int `json:"version"`
FinalSpace bool `json:"final_space,omitempty"`
ConsoleTitleTemplate string `json:"console_title_template,omitempty"`
TerminalBackground string `json:"terminal_background,omitempty"`
AccentColor string `json:"accent_color,omitempty"`
Blocks []*Block `json:"blocks,omitempty"`
Tooltips []*Segment `json:"tooltips,omitempty"`
TransientPrompt *Segment `json:"transient_prompt,omitempty"`
ValidLine *Segment `json:"valid_line,omitempty"`
ErrorLine *Segment `json:"error_line,omitempty"`
SecondaryPrompt *Segment `json:"secondary_prompt,omitempty"`
DebugPrompt *Segment `json:"debug_prompt,omitempty"`
Palette ansi.Palette `json:"palette,omitempty"`
Palettes *ansi.Palettes `json:"palettes,omitempty"`
Cycle ansi.Cycle `json:"cycle,omitempty"`
ShellIntegration bool `json:"shell_integration,omitempty"`
PWD string `json:"pwd,omitempty"`
Var map[string]interface{} `json:"var,omitempty"`
DisableCursorPositioning bool `json:"disable_cursor_positioning,omitempty"`
PatchPwshBleed bool `json:"patch_pwsh_bleed,omitempty"`
Version int `json:"version"`
FinalSpace bool `json:"final_space,omitempty"`
ConsoleTitleTemplate string `json:"console_title_template,omitempty"`
TerminalBackground string `json:"terminal_background,omitempty"`
AccentColor string `json:"accent_color,omitempty"`
Blocks []*Block `json:"blocks,omitempty"`
Tooltips []*Segment `json:"tooltips,omitempty"`
TransientPrompt *Segment `json:"transient_prompt,omitempty"`
ValidLine *Segment `json:"valid_line,omitempty"`
ErrorLine *Segment `json:"error_line,omitempty"`
SecondaryPrompt *Segment `json:"secondary_prompt,omitempty"`
DebugPrompt *Segment `json:"debug_prompt,omitempty"`
Palette ansi.Palette `json:"palette,omitempty"`
Palettes *ansi.Palettes `json:"palettes,omitempty"`
Cycle ansi.Cycle `json:"cycle,omitempty"`
ShellIntegration bool `json:"shell_integration,omitempty"`
PWD string `json:"pwd,omitempty"`
Var map[string]any `json:"var,omitempty"`
DisableCursorPositioning bool `json:"disable_cursor_positioning,omitempty"`
PatchPwshBleed bool `json:"patch_pwsh_bleed,omitempty"`

// Deprecated
OSC99 bool `json:"osc99,omitempty"`
Expand Down Expand Up @@ -174,7 +174,7 @@ func (cfg *Config) sync() {
if !cfg.updated {
return
}
var structMap map[string]interface{}
var structMap map[string]any
inrec, err := json2.Marshal(cfg)
if err != nil {
return
Expand All @@ -185,7 +185,7 @@ func (cfg *Config) sync() {
}
// remove empty structs
for k, v := range structMap {
if smap, OK := v.(map[string]interface{}); OK && len(smap) == 0 {
if smap, OK := v.(map[string]any); OK && len(smap) == 0 {
delete(structMap, k)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/engine/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (segment *Segment) hasProperty(property properties.Property) bool {
return false
}

func (segment *Segment) migratePropertyValue(property properties.Property, value interface{}) {
func (segment *Segment) migratePropertyValue(property properties.Property, value any) {
if !segment.hasProperty(property) {
return
}
Expand Down
4 changes: 2 additions & 2 deletions src/engine/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestHasProperty(t *testing.T) {
func TestMigratePropertyValue(t *testing.T) {
cases := []struct {
Case string
Expected interface{}
Expected any
Property properties.Property
Props properties.Map
}{
Expand All @@ -60,7 +60,7 @@ func TestMigratePropertyValue(t *testing.T) {
func TestMigratePropertyKey(t *testing.T) {
cases := []struct {
Case string
Expected interface{}
Expected any
OldProperty properties.Property
NewProperty properties.Property
Props properties.Map
Expand Down
2 changes: 1 addition & 1 deletion src/engine/segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type SegmentWriter interface {
// SegmentStyle the style of segment, for more information, see the constants
type SegmentStyle string

func (s *SegmentStyle) Resolve(env platform.Environment, context interface{}) SegmentStyle {
func (s *SegmentStyle) Resolve(env platform.Environment, context any) SegmentStyle {
txtTemplate := &template.Text{
Context: context,
Env: env,
Expand Down
2 changes: 1 addition & 1 deletion src/http/oauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func TestOauthResult(t *testing.T) {
url := "https://www.strava.com/api/v3/athlete/activities?page=1&per_page=1"
tokenURL := fmt.Sprintf("https://ohmyposh.dev/api/refresh?segment=test&token=%s", tc.RefreshToken)

var props properties.Map = map[properties.Property]interface{}{
var props properties.Map = map[properties.Property]any{
properties.CacheTimeout: tc.CacheTimeout,
properties.AccessToken: tc.AccessToken,
properties.RefreshToken: tc.RefreshToken,
Expand Down
2 changes: 1 addition & 1 deletion src/http/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestRequestResult(t *testing.T) {
}

for _, tc := range cases {
var props properties.Map = map[properties.Property]interface{}{
var props properties.Map = map[properties.Property]any{
properties.CacheTimeout: tc.CacheTimeout,
}

Expand Down
4 changes: 2 additions & 2 deletions src/platform/battery/battery_openbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ func Get() (*Info, error) {
apm_status, err := cmd.Run("apm", "-b")
if err != nil {
return nil, err
}
}

return parseBatteryOutput(apm_percentage, apm_status)
return parseBatteryOutput(apm_percentage, apm_status)

}
20 changes: 10 additions & 10 deletions src/platform/battery/battery_openbsd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,45 @@ import (

func TestParseBatteryOutput(t *testing.T) {
cases := []struct {
Case string
PercentOutput string
StatusOutput string
ExpectedState State
ExpectedPercentage int
Case string
PercentOutput string
StatusOutput string
ExpectedState State
ExpectedPercentage int
ExpectError bool
}{
{
Case: "charging",
PercentOutput: "99",
StatusOutput: "3",
StatusOutput: "3",
ExpectedState: Charging,
ExpectedPercentage: 99,
},
{
Case: "charging 1%",
PercentOutput: "1",
StatusOutput: "3",
StatusOutput: "3",
ExpectedState: Charging,
ExpectedPercentage: 1,
},
{
Case: "removed",
PercentOutput: "0",
StatusOutput: "4",
StatusOutput: "4",
ExpectedState: Unknown,
ExpectedPercentage: 0,
},
{
Case: "charged",
PercentOutput: "100",
StatusOutput: "0",
StatusOutput: "0",
ExpectedState: Full,
ExpectedPercentage: 100,
},
{
Case: "discharging",
PercentOutput: "25",
StatusOutput: "1",
StatusOutput: "1",
ExpectedState: Discharging,
ExpectedPercentage: 25,
},
Expand Down
4 changes: 2 additions & 2 deletions src/platform/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ type TemplateCache struct {
sync.RWMutex
}

func (t *TemplateCache) AddSegmentData(key string, value interface{}) {
func (t *TemplateCache) AddSegmentData(key string, value any) {
t.Segments.Set(key, value)
}

Expand Down Expand Up @@ -802,7 +802,7 @@ func (env *Shell) TemplateCache() *TemplateCache {
tmplCache.Segments = NewConcurrentMap()
tmplCache.PromptCount = env.CmdFlags.PromptCount
tmplCache.Env = make(map[string]string)
tmplCache.Var = make(map[string]interface{})
tmplCache.Var = make(map[string]any)

if env.Var != nil {
tmplCache.Var = env.Var
Expand Down
14 changes: 7 additions & 7 deletions src/properties/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const (
CacheTimeout Property = "cache_timeout"
)

type Map map[Property]interface{}
type Map map[Property]any

func (m Map) GetString(property Property, defaultValue string) string {
val, found := m[property]
Expand Down Expand Up @@ -158,11 +158,11 @@ func (m Map) GetStringArray(property Property, defaultValue []string) []string {
return keyValues
}

func ParseStringArray(param interface{}) []string {
func ParseStringArray(param any) []string {
switch v := param.(type) {
default:
return []string{}
case []interface{}:
case []any:
list := make([]string, len(v))
for i, v := range v {
list[i] = fmt.Sprint(v)
Expand All @@ -173,26 +173,26 @@ func ParseStringArray(param interface{}) []string {
}
}

func parseKeyValueArray(param interface{}) map[string]string {
func parseKeyValueArray(param any) map[string]string {
switch v := param.(type) {
default:
return map[string]string{}
case map[interface{}]interface{}:
case map[any]any:
keyValueArray := make(map[string]string)
for key, value := range v {
val := value.(string)
keyString := fmt.Sprintf("%v", key)
keyValueArray[keyString] = val
}
return keyValueArray
case map[string]interface{}:
case map[string]any:
keyValueArray := make(map[string]string)
for key, value := range v {
val := value.(string)
keyValueArray[key] = val
}
return keyValueArray
case []interface{}:
case []any:
keyValueArray := make(map[string]string)
for _, s := range v {
l := ParseStringArray(s)
Expand Down
2 changes: 1 addition & 1 deletion src/properties/map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestGetFloat64(t *testing.T) {
cases := []struct {
Case string
Expected float64
Input interface{}
Input any
}{
{Case: "int", Expected: 1337, Input: 1337},
{Case: "float64", Expected: 1337, Input: float64(1337)},
Expand Down
18 changes: 9 additions & 9 deletions src/segments/az.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ type AzureConfig struct {
}

type AzureSubscription struct {
ID string `json:"id"`
Name string `json:"name"`
State string `json:"state"`
User *AzureUser `json:"user"`
IsDefault bool `json:"isDefault"`
TenantID string `json:"tenantId"`
EnvironmentName string `json:"environmentName"`
HomeTenantID string `json:"homeTenantId"`
ManagedByTenants []interface{} `json:"managedByTenants"`
ID string `json:"id"`
Name string `json:"name"`
State string `json:"state"`
User *AzureUser `json:"user"`
IsDefault bool `json:"isDefault"`
TenantID string `json:"tenantId"`
EnvironmentName string `json:"environmentName"`
HomeTenantID string `json:"homeTenantId"`
ManagedByTenants []any `json:"managedByTenants"`
}

type AzureUser struct {
Expand Down
4 changes: 2 additions & 2 deletions src/segments/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
mock2 "github.com/stretchr/testify/mock"
)

func renderTemplateNoTrimSpace(env *mock.MockedEnvironment, segmentTemplate string, context interface{}) string {
func renderTemplateNoTrimSpace(env *mock.MockedEnvironment, segmentTemplate string, context any) string {
found := false
for _, call := range env.Mock.ExpectedCalls {
if call.Method == "TemplateCache" {
Expand Down Expand Up @@ -42,7 +42,7 @@ func renderTemplateNoTrimSpace(env *mock.MockedEnvironment, segmentTemplate stri
return text
}

func renderTemplate(env *mock.MockedEnvironment, segmentTemplate string, context interface{}) string {
func renderTemplate(env *mock.MockedEnvironment, segmentTemplate string, context any) string {
return strings.TrimSpace(renderTemplateNoTrimSpace(env, segmentTemplate, context))
}

Expand Down
6 changes: 3 additions & 3 deletions src/segments/scm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func TestTruncateBranch(t *testing.T) {
Expected string
Branch string
FullBranch bool
MaxLength interface{}
MaxLength any
}{
{Case: "No limit", Expected: "are-belong-to-us", Branch: "/all-your-base/are-belong-to-us", FullBranch: false},
{Case: "No limit - larger", Expected: "are-belong", Branch: "/all-your-base/are-belong-to-us", FullBranch: false, MaxLength: 10.0},
Expand Down Expand Up @@ -146,8 +146,8 @@ func TestTruncateBranchWithSymbol(t *testing.T) {
Expected string
Branch string
FullBranch bool
MaxLength interface{}
TruncateSymbol interface{}
MaxLength any
TruncateSymbol any
}{
{Case: "No limit", Expected: "are-belong-to-us", Branch: "/all-your-base/are-belong-to-us", FullBranch: false, TruncateSymbol: "..."},
{Case: "No limit - larger", Expected: "are-belong...", Branch: "/all-your-base/are-belong-to-us", FullBranch: false, MaxLength: 10.0, TruncateSymbol: "..."},
Expand Down
4 changes: 2 additions & 2 deletions src/segments/withings.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ type Body struct {
}

type MeasureGroup struct {
Measures []*Measure `json:"measures"`
Comment interface{} `json:"comment"`
Measures []*Measure `json:"measures"`
Comment any `json:"comment"`
}

type Measure struct {
Expand Down
Loading