From 18f6db017a146a6d47866a3799f4bcd05b2937c2 Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Wed, 9 Nov 2022 20:27:54 +0100 Subject: [PATCH] chore: rename environment to platform --- src/cli/cache.go | 8 +- src/cli/config_export.go | 8 +- src/cli/config_export_image.go | 6 +- src/cli/config_migrate.go | 6 +- src/cli/debug.go | 6 +- src/cli/font.go | 6 +- src/cli/get.go | 6 +- src/cli/init.go | 6 +- src/cli/print.go | 6 +- src/color/colors.go | 4 +- src/color/colors_unix.go | 10 +- src/color/colors_windows.go | 8 +- src/color/text_test.go | 4 +- src/console/title.go | 4 +- src/console/title_test.go | 6 +- src/engine/block.go | 8 +- src/engine/config.go | 10 +- src/engine/config_test.go | 4 +- src/engine/engine.go | 4 +- src/engine/engine_test.go | 6 +- src/engine/migrate.go | 10 +- src/engine/migrate_test.go | 4 +- src/engine/segment.go | 10 +- src/engine/segment_test.go | 6 +- src/http/oauth.go | 6 +- src/http/oauth_test.go | 4 +- src/http/request.go | 18 +-- src/http/request_test.go | 4 +- src/mock/environment.go | 32 ++-- .../battery/battery.go | 0 .../battery/battery_darwin.go | 2 +- .../battery/battery_darwin_test.go | 0 .../battery/battery_linux.go | 0 .../battery/battery_windows.go | 0 .../battery/battery_windows_nix.go | 0 .../battery/battery_windows_nix_test.go | 0 .../battery/errors.go | 0 .../battery/errors_test.go | 0 src/{environment => platform}/cache.go | 2 +- src/{environment => platform}/cmd/run.go | 0 .../concurrent_map.go | 2 +- src/{environment => platform}/httpclient.go | 2 +- src/{environment => platform}/shell.go | 82 +++++----- src/{environment => platform}/shell_darwin.go | 8 +- src/{environment => platform}/shell_test.go | 2 +- src/{environment => platform}/shell_unix.go | 32 ++-- .../shell_windows.go | 32 ++-- .../shell_windows_nix.go | 6 +- .../windows_win32.go | 6 +- src/segments/angular.go | 4 +- src/segments/aws.go | 6 +- src/segments/az.go | 6 +- src/segments/az_functions.go | 4 +- src/segments/az_test.go | 4 +- src/segments/battery.go | 8 +- src/segments/brewfather.go | 6 +- src/segments/cds.go | 4 +- src/segments/cds_test.go | 4 +- src/segments/cf.go | 4 +- src/segments/cf_target.go | 6 +- src/segments/cf_test.go | 4 +- src/segments/cmake.go | 4 +- src/segments/command.go | 6 +- src/segments/connection.go | 10 +- src/segments/connection_test.go | 26 +-- src/segments/crystal.go | 4 +- src/segments/dart.go | 4 +- src/segments/deno.go | 4 +- src/segments/dotnet.go | 4 +- src/segments/dotnet_test.go | 6 +- src/segments/executiontime.go | 6 +- src/segments/exit.go | 6 +- src/segments/exit_test.go | 4 +- src/segments/flutter.go | 4 +- src/segments/gcp.go | 14 +- src/segments/gcp_test.go | 6 +- src/segments/git.go | 10 +- src/segments/git_test.go | 8 +- src/segments/golang.go | 4 +- src/segments/golang_test.go | 6 +- src/segments/haskell.go | 4 +- src/segments/haskell_test.go | 6 +- src/segments/ipify.go | 4 +- src/segments/iterm.go | 6 +- src/segments/java.go | 4 +- src/segments/julia.go | 4 +- src/segments/kotlin.go | 4 +- src/segments/kubectl.go | 6 +- src/segments/kubectl_test.go | 4 +- src/segments/language.go | 6 +- src/segments/language_test.go | 6 +- src/segments/lua.go | 4 +- src/segments/lua_test.go | 4 +- src/segments/nbgv.go | 6 +- src/segments/nightscout.go | 6 +- src/segments/node.go | 4 +- src/segments/npm.go | 4 +- src/segments/nx.go | 6 +- src/segments/nx_test.go | 4 +- src/segments/os.go | 18 +-- src/segments/os_test.go | 4 +- src/segments/owm.go | 6 +- src/segments/path.go | 24 +-- src/segments/path_test.go | 152 +++++++++--------- src/segments/perl.go | 4 +- src/segments/php.go | 4 +- src/segments/plastic.go | 4 +- src/segments/plastic_test.go | 4 +- src/segments/posh_git_test.go | 4 +- src/segments/project.go | 6 +- src/segments/python.go | 6 +- src/segments/python_test.go | 6 +- src/segments/r.go | 4 +- src/segments/r_test.go | 4 +- src/segments/root.go | 6 +- src/segments/ruby.go | 4 +- src/segments/rust.go | 4 +- src/segments/scm.go | 10 +- src/segments/scm_test.go | 4 +- src/segments/session.go | 6 +- src/segments/session_test.go | 4 +- src/segments/shell.go | 6 +- src/segments/shell_test.go | 6 +- src/segments/spotify.go | 6 +- src/segments/spotify_windows_test.go | 6 +- src/segments/strava.go | 4 +- src/segments/svn_test.go | 6 +- src/segments/swift.go | 4 +- src/segments/sysinfo.go | 6 +- src/segments/terraform.go | 6 +- src/segments/text.go | 6 +- src/segments/text_test.go | 4 +- src/segments/time.go | 6 +- src/segments/ui5tooling.go | 4 +- src/segments/ui5tooling_test.go | 4 +- src/segments/wakatime.go | 6 +- src/segments/wakatime_test.go | 6 +- src/segments/winreg.go | 8 +- src/segments/winreg_test.go | 12 +- src/segments/withings.go | 4 +- src/segments/xmake.go | 4 +- src/segments/ytm.go | 6 +- src/shell/init.go | 16 +- src/shell/init_test.go | 4 +- src/template/files_test.go | 4 +- src/template/link_test.go | 6 +- src/template/list.go | 8 +- src/template/round_test.go | 4 +- src/template/text.go | 10 +- src/template/text_test.go | 6 +- website/docs/contributing/segment.mdx | 6 +- 151 files changed, 577 insertions(+), 579 deletions(-) rename src/{environment => platform}/battery/battery.go (100%) rename src/{environment => platform}/battery/battery_darwin.go (97%) rename src/{environment => platform}/battery/battery_darwin_test.go (100%) rename src/{environment => platform}/battery/battery_linux.go (100%) rename src/{environment => platform}/battery/battery_windows.go (100%) rename src/{environment => platform}/battery/battery_windows_nix.go (100%) rename src/{environment => platform}/battery/battery_windows_nix_test.go (100%) rename src/{environment => platform}/battery/errors.go (100%) rename src/{environment => platform}/battery/errors_test.go (100%) rename src/{environment => platform}/cache.go (98%) rename src/{environment => platform}/cmd/run.go (100%) rename src/{environment => platform}/concurrent_map.go (96%) rename src/{environment => platform}/httpclient.go (92%) rename src/{environment => platform}/shell.go (88%) rename src/{environment => platform}/shell_darwin.go (86%) rename src/{environment => platform}/shell_test.go (99%) rename src/{environment => platform}/shell_unix.go (77%) rename src/{environment => platform}/shell_windows.go (87%) rename src/{environment => platform}/shell_windows_nix.go (63%) rename src/{environment => platform}/windows_win32.go (98%) diff --git a/src/cli/cache.go b/src/cli/cache.go index 8c32f0cd..993104d9 100644 --- a/src/cli/cache.go +++ b/src/cli/cache.go @@ -2,7 +2,7 @@ package cli import ( "fmt" - "oh-my-posh/environment" + "oh-my-posh/platform" "os" "os/exec" "path/filepath" @@ -33,7 +33,7 @@ You can do the following: _ = cmd.Help() return } - env := &environment.ShellEnvironment{ + env := &platform.Shell{ Version: cliVersion, } env.Init() @@ -42,7 +42,7 @@ You can do the following: case "path": fmt.Print(env.CachePath()) case "clear": - cacheFilePath := filepath.Join(env.CachePath(), environment.CacheFile) + cacheFilePath := filepath.Join(env.CachePath(), platform.CacheFile) err := os.Remove(cacheFilePath) if err != nil { fmt.Println(err.Error()) @@ -50,7 +50,7 @@ You can do the following: } fmt.Printf("removed cache file at %s\n", cacheFilePath) case "edit": - cacheFilePath := filepath.Join(env.CachePath(), environment.CacheFile) + cacheFilePath := filepath.Join(env.CachePath(), platform.CacheFile) editFileWithEditor(cacheFilePath) } }, diff --git a/src/cli/config_export.go b/src/cli/config_export.go index 4a718548..74acf89e 100644 --- a/src/cli/config_export.go +++ b/src/cli/config_export.go @@ -3,7 +3,7 @@ package cli import ( "fmt" "oh-my-posh/engine" - "oh-my-posh/environment" + "oh-my-posh/platform" "path/filepath" "strings" @@ -38,9 +38,9 @@ Exports the ~/myconfig.omp.json config file to toml and writes the result to you A backup of the current config can be found at ~/myconfig.omp.json.bak.`, Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { - env := &environment.ShellEnvironment{ + env := &platform.Shell{ Version: cliVersion, - CmdFlags: &environment.Flags{ + CmdFlags: &platform.Flags{ Config: config, }, } @@ -60,7 +60,7 @@ A backup of the current config can be found at ~/myconfig.omp.json.bak.`, }, } -func cleanOutputPath(path string, env environment.Environment) string { +func cleanOutputPath(path string, env platform.Environment) string { if strings.HasPrefix(path, "~") { path = strings.TrimPrefix(path, "~") path = filepath.Join(env.Home(), path) diff --git a/src/cli/config_export_image.go b/src/cli/config_export_image.go index 6d30865e..da7902f6 100644 --- a/src/cli/config_export_image.go +++ b/src/cli/config_export_image.go @@ -5,7 +5,7 @@ import ( "oh-my-posh/color" "oh-my-posh/console" "oh-my-posh/engine" - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/shell" "github.com/spf13/cobra" @@ -47,9 +47,9 @@ Exports the config to an image file ~/mytheme.png. Exports the config to an image file using customized output options.`, Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { - env := &environment.ShellEnvironment{ + env := &platform.Shell{ Version: cliVersion, - CmdFlags: &environment.Flags{ + CmdFlags: &platform.Flags{ Config: config, Shell: shell.PLAIN, }, diff --git a/src/cli/config_migrate.go b/src/cli/config_migrate.go index 392402f7..712f8e40 100644 --- a/src/cli/config_migrate.go +++ b/src/cli/config_migrate.go @@ -3,7 +3,7 @@ package cli import ( "fmt" "oh-my-posh/engine" - "oh-my-posh/environment" + "oh-my-posh/platform" "github.com/spf13/cobra" ) @@ -37,9 +37,9 @@ Migrates the ~/myconfig.omp.json config file to toml and writes the result to yo A backup of the current config can be found at ~/myconfig.omp.json.bak.`, Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { - env := &environment.ShellEnvironment{ + env := &platform.Shell{ Version: cliVersion, - CmdFlags: &environment.Flags{ + CmdFlags: &platform.Flags{ Config: config, Migrate: true, }, diff --git a/src/cli/debug.go b/src/cli/debug.go index 9595b490..aabb413d 100644 --- a/src/cli/debug.go +++ b/src/cli/debug.go @@ -5,7 +5,7 @@ import ( "oh-my-posh/color" "oh-my-posh/console" "oh-my-posh/engine" - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/shell" "time" @@ -20,9 +20,9 @@ var debugCmd = &cobra.Command{ Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { startTime := time.Now() - env := &environment.ShellEnvironment{ + env := &platform.Shell{ Version: cliVersion, - CmdFlags: &environment.Flags{ + CmdFlags: &platform.Flags{ Config: config, Debug: true, PWD: pwd, diff --git a/src/cli/font.go b/src/cli/font.go index 29ec7952..3abae595 100644 --- a/src/cli/font.go +++ b/src/cli/font.go @@ -2,8 +2,8 @@ package cli import ( "fmt" - "oh-my-posh/environment" "oh-my-posh/font" + "oh-my-posh/platform" "github.com/spf13/cobra" ) @@ -33,9 +33,9 @@ This command is used to install fonts and configure the font in your terminal. if len(args) > 1 { fontName = args[1] } - env := &environment.ShellEnvironment{} + env := &platform.Shell{} env.Init() - needsAdmin := env.GOOS() == environment.WINDOWS && !env.Root() + needsAdmin := env.GOOS() == platform.WINDOWS && !env.Root() font.Run(fontName, needsAdmin) return case "configure": diff --git a/src/cli/get.go b/src/cli/get.go index c8777372..786f04b9 100644 --- a/src/cli/get.go +++ b/src/cli/get.go @@ -3,7 +3,7 @@ package cli import ( "fmt" "oh-my-posh/color" - "oh-my-posh/environment" + "oh-my-posh/platform" "time" color2 "github.com/gookit/color" @@ -32,9 +32,9 @@ This command is used to get the value of the following variables: _ = cmd.Help() return } - env := &environment.ShellEnvironment{ + env := &platform.Shell{ Version: cliVersion, - CmdFlags: &environment.Flags{ + CmdFlags: &platform.Flags{ Shell: shellName, }, } diff --git a/src/cli/init.go b/src/cli/init.go index 55a1d692..fba5de64 100644 --- a/src/cli/init.go +++ b/src/cli/init.go @@ -3,7 +3,7 @@ package cli import ( "fmt" "oh-my-posh/engine" - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/shell" "github.com/spf13/cobra" @@ -49,9 +49,9 @@ func init() { //nolint:gochecknoinits } func runInit(shellName string) { - env := &environment.ShellEnvironment{ + env := &platform.Shell{ Version: cliVersion, - CmdFlags: &environment.Flags{ + CmdFlags: &platform.Flags{ Shell: shellName, Config: config, Strict: strict, diff --git a/src/cli/print.go b/src/cli/print.go index 24be3d62..10ad3b2e 100644 --- a/src/cli/print.go +++ b/src/cli/print.go @@ -5,7 +5,7 @@ import ( "oh-my-posh/color" "oh-my-posh/console" "oh-my-posh/engine" - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/shell" "github.com/spf13/cobra" @@ -46,9 +46,9 @@ var printCmd = &cobra.Command{ _ = cmd.Help() return } - env := &environment.ShellEnvironment{ + env := &platform.Shell{ Version: cliVersion, - CmdFlags: &environment.Flags{ + CmdFlags: &platform.Flags{ Config: config, PWD: pwd, PSWD: pswd, diff --git a/src/color/colors.go b/src/color/colors.go index cdbdab14..a535d647 100644 --- a/src/color/colors.go +++ b/src/color/colors.go @@ -2,13 +2,13 @@ package color import ( "fmt" - "oh-my-posh/environment" + "oh-my-posh/platform" "strconv" "github.com/gookit/color" ) -func MakeColors(palette Palette, cacheEnabled bool, accentColor string, env environment.Environment) (colors AnsiColors) { +func MakeColors(palette Palette, cacheEnabled bool, accentColor string, env platform.Environment) (colors AnsiColors) { defaultColors := &DefaultColors{} defaultColors.SetAccentColor(env, accentColor) colors = defaultColors diff --git a/src/color/colors_unix.go b/src/color/colors_unix.go index 56d5728a..a55a079f 100644 --- a/src/color/colors_unix.go +++ b/src/color/colors_unix.go @@ -2,15 +2,13 @@ package color -import ( - "oh-my-posh/environment" -) +import "oh-my-posh/platform" -func GetAccentColor(env environment.Environment) (*RGB, error) { - return nil, &environment.NotImplemented{} +func GetAccentColor(env platform.Environment) (*RGB, error) { + return nil, &platform.NotImplemented{} } -func (d *DefaultColors) SetAccentColor(env environment.Environment, defaultColor string) { +func (d *DefaultColors) SetAccentColor(env platform.Environment, defaultColor string) { if len(defaultColor) == 0 { return } diff --git a/src/color/colors_windows.go b/src/color/colors_windows.go index 493e16a9..3fb9d732 100644 --- a/src/color/colors_windows.go +++ b/src/color/colors_windows.go @@ -2,18 +2,18 @@ package color import ( "errors" - "oh-my-posh/environment" + "oh-my-posh/platform" "github.com/gookit/color" ) -func GetAccentColor(env environment.Environment) (*RGB, error) { +func GetAccentColor(env platform.Environment) (*RGB, error) { if env == nil { return nil, errors.New("unable to get color without environment") } // see https://stackoverflow.com/questions/3560890/vista-7-how-to-get-glass-color value, err := env.WindowsRegistryKeyValue(`HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM\ColorizationColor`) - if err != nil || value.ValueType != environment.DWORD { + if err != nil || value.ValueType != platform.DWORD { return nil, err } return &RGB{ @@ -23,7 +23,7 @@ func GetAccentColor(env environment.Environment) (*RGB, error) { }, nil } -func (d *DefaultColors) SetAccentColor(env environment.Environment, defaultColor string) { +func (d *DefaultColors) SetAccentColor(env platform.Environment, defaultColor string) { rgb, err := GetAccentColor(env) if err != nil { d.accent = &Color{ diff --git a/src/color/text_test.go b/src/color/text_test.go index 92123779..1e98dcf9 100644 --- a/src/color/text_test.go +++ b/src/color/text_test.go @@ -2,8 +2,8 @@ package color import ( "fmt" - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "oh-my-posh/shell" "oh-my-posh/template" "testing" @@ -29,7 +29,7 @@ func TestMeasureText(t *testing.T) { }, } env := new(mock.MockedEnvironment) - env.On("TemplateCache").Return(&environment.TemplateCache{ + env.On("TemplateCache").Return(&platform.TemplateCache{ Env: make(map[string]string), }) shells := []string{shell.BASH, shell.ZSH, shell.PLAIN} diff --git a/src/console/title.go b/src/console/title.go index 5c9c9332..7eb4d681 100644 --- a/src/console/title.go +++ b/src/console/title.go @@ -2,12 +2,12 @@ package console import ( "oh-my-posh/color" - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/template" ) type Title struct { - Env environment.Environment + Env platform.Environment Ansi *color.Ansi Template string } diff --git a/src/console/title_test.go b/src/console/title_test.go index 0bdd0a71..12cb80d9 100644 --- a/src/console/title_test.go +++ b/src/console/title_test.go @@ -2,8 +2,8 @@ package console import ( "oh-my-posh/color" - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "testing" "github.com/stretchr/testify/assert" @@ -49,7 +49,7 @@ func TestGetTitle(t *testing.T) { env.On("Pwd").Return(tc.Cwd) env.On("Home").Return("/usr/home") env.On("PathSeparator").Return(tc.PathSeparator) - env.On("TemplateCache").Return(&environment.TemplateCache{ + env.On("TemplateCache").Return(&platform.TemplateCache{ Env: map[string]string{ "USERDOMAIN": "MyCompany", }, @@ -106,7 +106,7 @@ func TestGetConsoleTitleIfGethostnameReturnsError(t *testing.T) { env := new(mock.MockedEnvironment) env.On("Pwd").Return(tc.Cwd) env.On("Home").Return("/usr/home") - env.On("TemplateCache").Return(&environment.TemplateCache{ + env.On("TemplateCache").Return(&platform.TemplateCache{ Env: map[string]string{ "USERDOMAIN": "MyCompany", }, diff --git a/src/engine/block.go b/src/engine/block.go index b13c4bfa..71e96b2c 100644 --- a/src/engine/block.go +++ b/src/engine/block.go @@ -2,7 +2,7 @@ package engine import ( "oh-my-posh/color" - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/shell" "sync" "time" @@ -47,21 +47,21 @@ type Block struct { HorizontalOffset int `json:"horizontal_offset,omitempty"` VerticalOffset int `json:"vertical_offset,omitempty"` - env environment.Environment + env platform.Environment writer color.Writer ansi *color.Ansi activeSegment *Segment previousActiveSegment *Segment } -func (b *Block) Init(env environment.Environment, writer color.Writer, ansi *color.Ansi) { +func (b *Block) Init(env platform.Environment, writer color.Writer, ansi *color.Ansi) { b.env = env b.writer = writer b.ansi = ansi b.executeSegmentLogic() } -func (b *Block) InitPlain(env environment.Environment, config *Config) { +func (b *Block) InitPlain(env platform.Environment, config *Config) { b.ansi = &color.Ansi{} b.ansi.InitPlain() b.writer = &color.AnsiWriter{ diff --git a/src/engine/config.go b/src/engine/config.go index 29e6248a..ebba531a 100644 --- a/src/engine/config.go +++ b/src/engine/config.go @@ -6,7 +6,7 @@ import ( "fmt" "io" "oh-my-posh/color" - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" "oh-my-posh/segments" "oh-my-posh/template" @@ -57,7 +57,7 @@ type Config struct { origin string eval bool updated bool - env environment.Environment + env platform.Environment } // MakeColors creates instance of AnsiColors to use in AnsiWriter according to @@ -105,7 +105,7 @@ func (cfg *Config) exitWithError(err error) { } // LoadConfig returns the default configuration including possible user overrides -func LoadConfig(env environment.Environment) *Config { +func LoadConfig(env platform.Environment) *Config { cfg := loadConfig(env) cfg.env = env // only migrate automatically when the switch isn't set @@ -115,7 +115,7 @@ func LoadConfig(env environment.Environment) *Config { return cfg } -func loadConfig(env environment.Environment) *Config { +func loadConfig(env platform.Environment) *Config { defer env.Trace(time.Now(), "config.loadConfig") var cfg Config configFile := env.Flags().Config @@ -205,7 +205,7 @@ func (cfg *Config) Export(format string) string { } } -func (cfg *Config) BackupAndMigrate(env environment.Environment) { +func (cfg *Config) BackupAndMigrate(env platform.Environment) { origin := cfg.backup() cfg.Migrate(env) cfg.Write(cfg.format) diff --git a/src/engine/config_test.go b/src/engine/config_test.go index 11b69345..006cd4dd 100644 --- a/src/engine/config_test.go +++ b/src/engine/config_test.go @@ -2,8 +2,8 @@ package engine import ( "oh-my-posh/color" - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "oh-my-posh/segments" "testing" @@ -119,7 +119,7 @@ func TestGetPalette(t *testing.T) { } for _, tc := range cases { env := &mock.MockedEnvironment{} - env.On("TemplateCache").Return(&environment.TemplateCache{ + env.On("TemplateCache").Return(&platform.TemplateCache{ Env: map[string]string{}, Shell: "bash", }) diff --git a/src/engine/engine.go b/src/engine/engine.go index 4d0d88d4..06a4bc6a 100644 --- a/src/engine/engine.go +++ b/src/engine/engine.go @@ -4,7 +4,7 @@ import ( "fmt" "oh-my-posh/color" "oh-my-posh/console" - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/shell" "oh-my-posh/template" "strings" @@ -13,7 +13,7 @@ import ( type Engine struct { Config *Config - Env environment.Environment + Env platform.Environment Writer color.Writer Ansi *color.Ansi ConsoleTitle *console.Title diff --git a/src/engine/engine_test.go b/src/engine/engine_test.go index e5dabec0..54c7f5e9 100644 --- a/src/engine/engine_test.go +++ b/src/engine/engine_test.go @@ -4,8 +4,8 @@ import ( "errors" "oh-my-posh/color" "oh-my-posh/console" - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "oh-my-posh/shell" "testing" @@ -64,7 +64,7 @@ func TestPrintPWD(t *testing.T) { env.On("Pwd").Return("pwd") env.On("Shell").Return("shell") env.On("Host").Return("host", nil) - env.On("TemplateCache").Return(&environment.TemplateCache{ + env.On("TemplateCache").Return(&platform.TemplateCache{ Env: make(map[string]string), Shell: "shell", }) @@ -91,7 +91,7 @@ func BenchmarkEngineRender(b *testing.B) { } func engineRender() { - env := &environment.ShellEnvironment{} + env := &platform.Shell{} env.Init() defer env.Close() diff --git a/src/engine/migrate.go b/src/engine/migrate.go index c1a462c7..87f20587 100644 --- a/src/engine/migrate.go +++ b/src/engine/migrate.go @@ -2,7 +2,7 @@ package engine import ( "fmt" - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" "oh-my-posh/segments" "strings" @@ -16,7 +16,7 @@ const ( segmentTemplate = properties.Property("template") ) -func (cfg *Config) Migrate(env environment.Environment) { +func (cfg *Config) Migrate(env platform.Environment) { for _, block := range cfg.Blocks { for _, segment := range block.Segments { segment.migrate(env, cfg.Version) @@ -32,7 +32,7 @@ func (cfg *Config) Migrate(env environment.Environment) { cfg.Version = configVersion } -func (segment *Segment) migrate(env environment.Environment, version int) { +func (segment *Segment) migrate(env platform.Environment, version int) { if version < 1 { segment.migrationOne(env) } @@ -41,7 +41,7 @@ func (segment *Segment) migrate(env environment.Environment, version int) { } } -func (segment *Segment) migrationOne(env environment.Environment) { +func (segment *Segment) migrationOne(env platform.Environment) { if err := segment.mapSegmentWithWriter(env); err != nil { return } @@ -161,7 +161,7 @@ func (segment *Segment) migrationOne(env environment.Environment) { delete(segment.Properties, colorBackground) } -func (segment *Segment) migrationTwo(env environment.Environment) { +func (segment *Segment) migrationTwo(env platform.Environment) { if err := segment.mapSegmentWithWriter(env); err != nil { return } diff --git a/src/engine/migrate_test.go b/src/engine/migrate_test.go index df4dbae3..b8fae4a6 100644 --- a/src/engine/migrate_test.go +++ b/src/engine/migrate_test.go @@ -1,8 +1,8 @@ package engine import ( - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "oh-my-posh/properties" "testing" @@ -88,7 +88,7 @@ func (m *MockedWriter) Template() string { return m.template } -func (m *MockedWriter) Init(props properties.Properties, env environment.Environment) {} +func (m *MockedWriter) Init(props properties.Properties, env platform.Environment) {} func TestIconOverride(t *testing.T) { cases := []struct { diff --git a/src/engine/segment.go b/src/engine/segment.go index a7e933ff..5e72c835 100644 --- a/src/engine/segment.go +++ b/src/engine/segment.go @@ -7,7 +7,7 @@ import ( "strings" "time" - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" "oh-my-posh/segments" "oh-my-posh/shell" @@ -37,7 +37,7 @@ type Segment struct { writer SegmentWriter Enabled bool `json:"-"` text string - env environment.Environment + env platform.Environment backgroundCache string foregroundCache string } @@ -55,7 +55,7 @@ type SegmentTiming struct { type SegmentWriter interface { Enabled() bool Template() string - Init(props properties.Properties, env environment.Environment) + Init(props properties.Properties, env platform.Environment) } // SegmentStyle the style of segment, for more information, see the constants @@ -266,7 +266,7 @@ func (segment *Segment) background() string { return segment.backgroundCache } -func (segment *Segment) mapSegmentWithWriter(env environment.Environment) error { +func (segment *Segment) mapSegmentWithWriter(env platform.Environment) error { segment.env = env functions := map[SegmentType]SegmentWriter{ ANGULAR: &segments.Angular{}, @@ -369,7 +369,7 @@ func (segment *Segment) string() string { return text } -func (segment *Segment) SetEnabled(env environment.Environment) { +func (segment *Segment) SetEnabled(env platform.Environment) { defer func() { err := recover() if err == nil { diff --git a/src/engine/segment_test.go b/src/engine/segment_test.go index 241256cf..39bff5dc 100644 --- a/src/engine/segment_test.go +++ b/src/engine/segment_test.go @@ -2,8 +2,8 @@ package engine import ( "encoding/json" - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "oh-my-posh/properties" "oh-my-posh/segments" "testing" @@ -71,7 +71,7 @@ func TestShouldIncludeFolder(t *testing.T) { } for _, tc := range cases { env := new(mock.MockedEnvironment) - env.On("GOOS").Return(environment.LINUX) + env.On("GOOS").Return(platform.LINUX) env.On("Home").Return("") env.On("Pwd").Return(cwd) env.On("DirMatchesOneOf", cwd, []string{"Projects/oh-my-posh"}).Return(tc.Included) @@ -142,7 +142,7 @@ func TestGetColors(t *testing.T) { } for _, tc := range cases { env := new(mock.MockedEnvironment) - env.On("TemplateCache").Return(&environment.TemplateCache{ + env.On("TemplateCache").Return(&platform.TemplateCache{ Env: make(map[string]string), }) segment := &Segment{ diff --git a/src/http/oauth.go b/src/http/oauth.go index 2f506339..7dcab6dd 100644 --- a/src/http/oauth.go +++ b/src/http/oauth.go @@ -5,7 +5,7 @@ import ( "fmt" "io" "net/http" - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" ) @@ -85,7 +85,7 @@ func (o *OAuthRequest) refreshToken(refreshToken string) (string, error) { return tokens.AccessToken, nil } -func OauthResult[a any](o *OAuthRequest, url string, body io.Reader, requestModifiers ...environment.HTTPRequestModifier) (a, error) { +func OauthResult[a any](o *OAuthRequest, url string, body io.Reader, requestModifiers ...platform.HTTPRequestModifier) (a, error) { if data, err := getCacheValue[a](&o.Request, url); err == nil { return data, nil } @@ -102,7 +102,7 @@ func OauthResult[a any](o *OAuthRequest, url string, body io.Reader, requestModi } if requestModifiers == nil { - requestModifiers = []environment.HTTPRequestModifier{} + requestModifiers = []platform.HTTPRequestModifier{} } requestModifiers = append(requestModifiers, addAuthHeader) diff --git a/src/http/oauth_test.go b/src/http/oauth_test.go index da076b52..49b470cb 100644 --- a/src/http/oauth_test.go +++ b/src/http/oauth_test.go @@ -2,8 +2,8 @@ package http import ( "fmt" - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "oh-my-posh/properties" "testing" @@ -161,7 +161,7 @@ func TestOauthResult(t *testing.T) { env.On("Cache").Return(cache) env.On("HTTPRequest", url).Return([]byte(tc.JSONResponse), tc.Error) env.On("HTTPRequest", tokenURL).Return([]byte(tc.TokenResponse), tc.Error) - env.On("Log", environment.Error, "OAuth", mock2.Anything).Return() + env.On("Log", platform.Error, "OAuth", mock2.Anything).Return() oauth := &OAuthRequest{ AccessTokenKey: accessTokenKey, diff --git a/src/http/request.go b/src/http/request.go index e6675985..9831d738 100644 --- a/src/http/request.go +++ b/src/http/request.go @@ -4,21 +4,21 @@ import ( "encoding/json" "errors" "io" - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" ) type Request struct { props properties.Properties - env environment.Environment + env platform.Environment } -func (r *Request) Init(env environment.Environment, props properties.Properties) { +func (r *Request) Init(env platform.Environment, props properties.Properties) { r.env = env r.props = props } -func Do[a any](r *Request, url string, requestModifiers ...environment.HTTPRequestModifier) (a, error) { +func Do[a any](r *Request, url string, requestModifiers ...platform.HTTPRequestModifier) (a, error) { if data, err := getCacheValue[a](r, url); err == nil { return data, nil } @@ -34,29 +34,29 @@ func getCacheValue[a any](r *Request, key string) (a, error) { if val, found := r.env.Cache().Get(key); found { err := json.Unmarshal([]byte(val), &data) if err != nil { - r.env.Log(environment.Error, "OAuth", err.Error()) + r.env.Log(platform.Error, "OAuth", err.Error()) return data, err } return data, nil } err := errors.New("no data in cache") - r.env.Log(environment.Error, "OAuth", err.Error()) + r.env.Log(platform.Error, "OAuth", err.Error()) return data, err } -func do[a any](r *Request, url string, body io.Reader, requestModifiers ...environment.HTTPRequestModifier) (a, error) { +func do[a any](r *Request, url string, body io.Reader, requestModifiers ...platform.HTTPRequestModifier) (a, error) { var data a httpTimeout := r.props.GetInt(properties.HTTPTimeout, properties.DefaultHTTPTimeout) responseBody, err := r.env.HTTPRequest(url, body, httpTimeout, requestModifiers...) if err != nil { - r.env.Log(environment.Error, "OAuth", err.Error()) + r.env.Log(platform.Error, "OAuth", err.Error()) return data, err } err = json.Unmarshal(responseBody, &data) if err != nil { - r.env.Log(environment.Error, "OAuth", err.Error()) + r.env.Log(platform.Error, "OAuth", err.Error()) return data, err } diff --git a/src/http/request_test.go b/src/http/request_test.go index 717616be..cea677cc 100644 --- a/src/http/request_test.go +++ b/src/http/request_test.go @@ -2,8 +2,8 @@ package http import ( "net" - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "oh-my-posh/properties" "testing" @@ -75,7 +75,7 @@ func TestRequestResult(t *testing.T) { env.On("Cache").Return(cache) env.On("HTTPRequest", url).Return([]byte(tc.JSONResponse), tc.Error) - env.On("Log", environment.Error, "OAuth", mock2.Anything).Return() + env.On("Log", platform.Error, "OAuth", mock2.Anything).Return() request := &Request{} request.Init(env, props) diff --git a/src/mock/environment.go b/src/mock/environment.go index 41f1cfe3..ab987986 100644 --- a/src/mock/environment.go +++ b/src/mock/environment.go @@ -3,8 +3,8 @@ package mock import ( "io" "io/fs" - "oh-my-posh/environment" - "oh-my-posh/environment/battery" + "oh-my-posh/platform" + "oh-my-posh/platform/battery" "time" mock "github.com/stretchr/testify/mock" @@ -119,9 +119,9 @@ func (env *MockedEnvironment) Root() bool { return args.Bool(0) } -func (env *MockedEnvironment) Flags() *environment.Flags { +func (env *MockedEnvironment) Flags() *platform.Flags { arguments := env.Called() - return arguments.Get(0).(*environment.Flags) + return arguments.Get(0).(*platform.Flags) } func (env *MockedEnvironment) BatteryState() (*battery.Info, error) { @@ -139,19 +139,19 @@ func (env *MockedEnvironment) QueryWindowTitles(processName, windowTitleRegex st return args.String(0), args.Error(1) } -func (env *MockedEnvironment) WindowsRegistryKeyValue(path string) (*environment.WindowsRegistryValue, error) { +func (env *MockedEnvironment) WindowsRegistryKeyValue(path string) (*platform.WindowsRegistryValue, error) { args := env.Called(path) - return args.Get(0).(*environment.WindowsRegistryValue), args.Error(1) + return args.Get(0).(*platform.WindowsRegistryValue), args.Error(1) } -func (env *MockedEnvironment) HTTPRequest(url string, body io.Reader, timeout int, requestModifiers ...environment.HTTPRequestModifier) ([]byte, error) { +func (env *MockedEnvironment) HTTPRequest(url string, body io.Reader, timeout int, requestModifiers ...platform.HTTPRequestModifier) ([]byte, error) { args := env.Called(url) return args.Get(0).([]byte), args.Error(1) } -func (env *MockedEnvironment) HasParentFilePath(path string) (*environment.FileInfo, error) { +func (env *MockedEnvironment) HasParentFilePath(path string) (*platform.FileInfo, error) { args := env.Called(path) - return args.Get(0).(*environment.FileInfo), args.Error(1) + return args.Get(0).(*platform.FileInfo), args.Error(1) } func (env *MockedEnvironment) StackCount() int { @@ -179,9 +179,9 @@ func (env *MockedEnvironment) CachePath() string { return args.String(0) } -func (env *MockedEnvironment) Cache() environment.Cache { +func (env *MockedEnvironment) Cache() platform.Cache { args := env.Called() - return args.Get(0).(environment.Cache) + return args.Get(0).(platform.Cache) } func (env *MockedEnvironment) Close() { @@ -208,14 +208,14 @@ func (env *MockedEnvironment) ConvertToLinuxPath(path string) string { return args.String(0) } -func (env *MockedEnvironment) Connection(connectionType environment.ConnectionType) (*environment.Connection, error) { +func (env *MockedEnvironment) Connection(connectionType platform.ConnectionType) (*platform.Connection, error) { args := env.Called(connectionType) - return args.Get(0).(*environment.Connection), args.Error(1) + return args.Get(0).(*platform.Connection), args.Error(1) } -func (env *MockedEnvironment) TemplateCache() *environment.TemplateCache { +func (env *MockedEnvironment) TemplateCache() *platform.TemplateCache { args := env.Called() - return args.Get(0).(*environment.TemplateCache) + return args.Get(0).(*platform.TemplateCache) } func (env *MockedEnvironment) LoadTemplateCache() { @@ -246,7 +246,7 @@ func (env *MockedEnvironment) Trace(start time.Time, function string, args ...st _ = env.Called(start, function, args) } -func (env *MockedEnvironment) Log(logType environment.LogType, funcName, message string) { +func (env *MockedEnvironment) Log(logType platform.LogType, funcName, message string) { _ = env.Called(logType, funcName, message) } diff --git a/src/environment/battery/battery.go b/src/platform/battery/battery.go similarity index 100% rename from src/environment/battery/battery.go rename to src/platform/battery/battery.go diff --git a/src/environment/battery/battery_darwin.go b/src/platform/battery/battery_darwin.go similarity index 97% rename from src/environment/battery/battery_darwin.go rename to src/platform/battery/battery_darwin.go index a7fdbf2c..6b239a1d 100644 --- a/src/environment/battery/battery_darwin.go +++ b/src/platform/battery/battery_darwin.go @@ -2,7 +2,7 @@ package battery import ( "errors" - "oh-my-posh/environment/cmd" + "oh-my-posh/platform/cmd" "oh-my-posh/regex" "strconv" "strings" diff --git a/src/environment/battery/battery_darwin_test.go b/src/platform/battery/battery_darwin_test.go similarity index 100% rename from src/environment/battery/battery_darwin_test.go rename to src/platform/battery/battery_darwin_test.go diff --git a/src/environment/battery/battery_linux.go b/src/platform/battery/battery_linux.go similarity index 100% rename from src/environment/battery/battery_linux.go rename to src/platform/battery/battery_linux.go diff --git a/src/environment/battery/battery_windows.go b/src/platform/battery/battery_windows.go similarity index 100% rename from src/environment/battery/battery_windows.go rename to src/platform/battery/battery_windows.go diff --git a/src/environment/battery/battery_windows_nix.go b/src/platform/battery/battery_windows_nix.go similarity index 100% rename from src/environment/battery/battery_windows_nix.go rename to src/platform/battery/battery_windows_nix.go diff --git a/src/environment/battery/battery_windows_nix_test.go b/src/platform/battery/battery_windows_nix_test.go similarity index 100% rename from src/environment/battery/battery_windows_nix_test.go rename to src/platform/battery/battery_windows_nix_test.go diff --git a/src/environment/battery/errors.go b/src/platform/battery/errors.go similarity index 100% rename from src/environment/battery/errors.go rename to src/platform/battery/errors.go diff --git a/src/environment/battery/errors_test.go b/src/platform/battery/errors_test.go similarity index 100% rename from src/environment/battery/errors_test.go rename to src/platform/battery/errors_test.go diff --git a/src/environment/cache.go b/src/platform/cache.go similarity index 98% rename from src/environment/cache.go rename to src/platform/cache.go index 9f787016..42c66f58 100644 --- a/src/environment/cache.go +++ b/src/platform/cache.go @@ -1,4 +1,4 @@ -package environment +package platform import ( "encoding/json" diff --git a/src/environment/cmd/run.go b/src/platform/cmd/run.go similarity index 100% rename from src/environment/cmd/run.go rename to src/platform/cmd/run.go diff --git a/src/environment/concurrent_map.go b/src/platform/concurrent_map.go similarity index 96% rename from src/environment/concurrent_map.go rename to src/platform/concurrent_map.go index 81c03abc..144def24 100644 --- a/src/environment/concurrent_map.go +++ b/src/platform/concurrent_map.go @@ -1,4 +1,4 @@ -package environment +package platform type concurrentMap struct { values map[string]interface{} diff --git a/src/environment/httpclient.go b/src/platform/httpclient.go similarity index 92% rename from src/environment/httpclient.go rename to src/platform/httpclient.go index 85ceb0f2..267751da 100644 --- a/src/environment/httpclient.go +++ b/src/platform/httpclient.go @@ -1,4 +1,4 @@ -package environment +package platform import ( "net/http" diff --git a/src/environment/shell.go b/src/platform/shell.go similarity index 88% rename from src/environment/shell.go rename to src/platform/shell.go index 8e1726ba..9ec7731f 100644 --- a/src/environment/shell.go +++ b/src/platform/shell.go @@ -1,4 +1,4 @@ -package environment +package platform import ( "bytes" @@ -11,8 +11,8 @@ import ( "log" "net/http" "net/http/httputil" - "oh-my-posh/environment/battery" - "oh-my-posh/environment/cmd" + "oh-my-posh/platform/battery" + "oh-my-posh/platform/cmd" "oh-my-posh/regex" "os" "os/exec" @@ -220,7 +220,7 @@ const ( Debug LogType = "debug" ) -type ShellEnvironment struct { +type Shell struct { CmdFlags *Flags Version string @@ -232,7 +232,7 @@ type ShellEnvironment struct { networks []*Connection } -func (env *ShellEnvironment) Init() { +func (env *Shell) Init() { defer env.Trace(time.Now(), "Init") if env.CmdFlags == nil { env.CmdFlags = &Flags{} @@ -248,7 +248,7 @@ func (env *ShellEnvironment) Init() { } } -func (env *ShellEnvironment) resolveConfigPath() { +func (env *Shell) resolveConfigPath() { defer env.Trace(time.Now(), "resolveConfigPath") if len(env.CmdFlags.Config) == 0 { env.CmdFlags.Config = env.Getenv("POSH_THEME") @@ -279,7 +279,7 @@ func (env *ShellEnvironment) resolveConfigPath() { env.CmdFlags.Config = filepath.Clean(configFile) } -func (env *ShellEnvironment) downloadConfig(location string) error { +func (env *Shell) downloadConfig(location string) error { defer env.Trace(time.Now(), "downloadConfig", location) configPath := filepath.Join(env.CachePath(), "config.omp.json") cfg, err := env.HTTPRequest(location, nil, 5000) @@ -299,7 +299,7 @@ func (env *ShellEnvironment) downloadConfig(location string) error { return nil } -func (env *ShellEnvironment) Trace(start time.Time, function string, args ...string) { +func (env *Shell) Trace(start time.Time, function string, args ...string) { if env.CmdFlags == nil || !env.CmdFlags.Debug { return } @@ -308,7 +308,7 @@ func (env *ShellEnvironment) Trace(start time.Time, function string, args ...str log.Println(trace) } -func (env *ShellEnvironment) Log(logType LogType, funcName, message string) { +func (env *Shell) Log(logType LogType, funcName, message string) { if !env.CmdFlags.Debug { return } @@ -316,7 +316,7 @@ func (env *ShellEnvironment) Log(logType LogType, funcName, message string) { log.Println(trace) } -func (env *ShellEnvironment) debugF(function string, fn func() string) { +func (env *Shell) debugF(function string, fn func() string) { if !env.CmdFlags.Debug { return } @@ -324,14 +324,14 @@ func (env *ShellEnvironment) debugF(function string, fn func() string) { log.Println(trace) } -func (env *ShellEnvironment) Getenv(key string) string { +func (env *Shell) Getenv(key string) string { defer env.Trace(time.Now(), "Getenv", key) val := os.Getenv(key) env.Log(Debug, "Getenv", val) return val } -func (env *ShellEnvironment) Pwd() string { +func (env *Shell) Pwd() string { defer env.Trace(time.Now(), "Pwd") lock.Lock() defer func() { @@ -362,7 +362,7 @@ func (env *ShellEnvironment) Pwd() string { return env.cwd } -func (env *ShellEnvironment) HasFiles(pattern string) bool { +func (env *Shell) HasFiles(pattern string) bool { defer env.Trace(time.Now(), "HasFiles", pattern) cwd := env.Pwd() fileSystem := os.DirFS(cwd) @@ -381,7 +381,7 @@ func (env *ShellEnvironment) HasFiles(pattern string) bool { return false } -func (env *ShellEnvironment) HasFilesInDir(dir, pattern string) bool { +func (env *Shell) HasFilesInDir(dir, pattern string) bool { defer env.Trace(time.Now(), "HasFilesInDir", pattern) fileSystem := os.DirFS(dir) matches, err := fs.Glob(fileSystem, pattern) @@ -394,7 +394,7 @@ func (env *ShellEnvironment) HasFilesInDir(dir, pattern string) bool { return hasFilesInDir } -func (env *ShellEnvironment) HasFileInParentDirs(pattern string, depth uint) bool { +func (env *Shell) HasFileInParentDirs(pattern string, depth uint) bool { defer env.Trace(time.Now(), "HasFileInParent", pattern, fmt.Sprint(depth)) currentFolder := env.Pwd() @@ -415,7 +415,7 @@ func (env *ShellEnvironment) HasFileInParentDirs(pattern string, depth uint) boo return false } -func (env *ShellEnvironment) HasFolder(folder string) bool { +func (env *Shell) HasFolder(folder string) bool { defer env.Trace(time.Now(), "HasFolder", folder) f, err := os.Stat(folder) if err != nil { @@ -426,7 +426,7 @@ func (env *ShellEnvironment) HasFolder(folder string) bool { return f.IsDir() } -func (env *ShellEnvironment) ResolveSymlink(path string) (string, error) { +func (env *Shell) ResolveSymlink(path string) (string, error) { defer env.Trace(time.Now(), "ResolveSymlink", path) link, err := filepath.EvalSymlinks(path) if err != nil { @@ -437,7 +437,7 @@ func (env *ShellEnvironment) ResolveSymlink(path string) (string, error) { return link, nil } -func (env *ShellEnvironment) FileContent(file string) string { +func (env *Shell) FileContent(file string) string { defer env.Trace(time.Now(), "FileContent", file) if !filepath.IsAbs(file) { file = filepath.Join(env.Pwd(), file) @@ -452,7 +452,7 @@ func (env *ShellEnvironment) FileContent(file string) string { return fileContent } -func (env *ShellEnvironment) LsDir(path string) []fs.DirEntry { +func (env *Shell) LsDir(path string) []fs.DirEntry { defer env.Trace(time.Now(), "LsDir", path) entries, err := os.ReadDir(path) if err != nil { @@ -469,12 +469,12 @@ func (env *ShellEnvironment) LsDir(path string) []fs.DirEntry { return entries } -func (env *ShellEnvironment) PathSeparator() string { +func (env *Shell) PathSeparator() string { defer env.Trace(time.Now(), "PathSeparator") return string(os.PathSeparator) } -func (env *ShellEnvironment) User() string { +func (env *Shell) User() string { defer env.Trace(time.Now(), "User") user := os.Getenv("USER") if user == "" { @@ -484,7 +484,7 @@ func (env *ShellEnvironment) User() string { return user } -func (env *ShellEnvironment) Host() (string, error) { +func (env *Shell) Host() (string, error) { defer env.Trace(time.Now(), "Host") hostName, err := os.Hostname() if err != nil { @@ -496,12 +496,12 @@ func (env *ShellEnvironment) Host() (string, error) { return hostName, nil } -func (env *ShellEnvironment) GOOS() string { +func (env *Shell) GOOS() string { defer env.Trace(time.Now(), "GOOS") return runtime.GOOS } -func (env *ShellEnvironment) RunCommand(command string, args ...string) (string, error) { +func (env *Shell) RunCommand(command string, args ...string) (string, error) { defer env.Trace(time.Now(), "RunCommand", append([]string{command}, args...)...) if cacheCommand, ok := env.cmdCache.get(command); ok { command = cacheCommand @@ -514,7 +514,7 @@ func (env *ShellEnvironment) RunCommand(command string, args ...string) (string, return output, err } -func (env *ShellEnvironment) RunShellCommand(shell, command string) string { +func (env *Shell) RunShellCommand(shell, command string) string { defer env.Trace(time.Now(), "RunShellCommand") if out, err := env.RunCommand(shell, "-c", command); err == nil { return out @@ -522,7 +522,7 @@ func (env *ShellEnvironment) RunShellCommand(shell, command string) string { return "" } -func (env *ShellEnvironment) CommandPath(command string) string { +func (env *Shell) CommandPath(command string) string { defer env.Trace(time.Now(), "CommandPath", command) if path, ok := env.cmdCache.get(command); ok { env.Log(Debug, "CommandPath", path) @@ -544,7 +544,7 @@ func (env *ShellEnvironment) CommandPath(command string) string { return "" } -func (env *ShellEnvironment) HasCommand(command string) bool { +func (env *Shell) HasCommand(command string) bool { defer env.Trace(time.Now(), "HasCommand", command) if path := env.CommandPath(command); path != "" { return true @@ -552,12 +552,12 @@ func (env *ShellEnvironment) HasCommand(command string) bool { return false } -func (env *ShellEnvironment) ErrorCode() int { +func (env *Shell) ErrorCode() int { defer env.Trace(time.Now(), "ErrorCode") return env.CmdFlags.ErrorCode } -func (env *ShellEnvironment) ExecutionTime() float64 { +func (env *Shell) ExecutionTime() float64 { defer env.Trace(time.Now(), "ExecutionTime") if env.CmdFlags.ExecutionTime < 0 { return 0 @@ -565,12 +565,12 @@ func (env *ShellEnvironment) ExecutionTime() float64 { return env.CmdFlags.ExecutionTime } -func (env *ShellEnvironment) Flags() *Flags { +func (env *Shell) Flags() *Flags { defer env.Trace(time.Now(), "Flags") return env.CmdFlags } -func (env *ShellEnvironment) Shell() string { +func (env *Shell) Shell() string { defer env.Trace(time.Now(), "Shell") if env.CmdFlags.Shell != "" { return env.CmdFlags.Shell @@ -600,7 +600,7 @@ func (env *ShellEnvironment) Shell() string { return env.CmdFlags.Shell } -func (env *ShellEnvironment) unWrapError(err error) error { +func (env *Shell) unWrapError(err error) error { cause := err for { type nested interface{ Unwrap() error } @@ -613,7 +613,7 @@ func (env *ShellEnvironment) unWrapError(err error) error { return cause } -func (env *ShellEnvironment) HTTPRequest(targetURL string, body io.Reader, timeout int, requestModifiers ...HTTPRequestModifier) ([]byte, error) { +func (env *Shell) HTTPRequest(targetURL string, body io.Reader, timeout int, requestModifiers ...HTTPRequestModifier) ([]byte, error) { defer env.Trace(time.Now(), "HTTPRequest", targetURL) ctx, cncl := context.WithTimeout(context.Background(), time.Millisecond*time.Duration(timeout)) defer cncl() @@ -650,7 +650,7 @@ func (env *ShellEnvironment) HTTPRequest(targetURL string, body io.Reader, timeo return responseBody, nil } -func (env *ShellEnvironment) HasParentFilePath(path string) (*FileInfo, error) { +func (env *Shell) HasParentFilePath(path string) (*FileInfo, error) { defer env.Trace(time.Now(), "HasParentFilePath", path) currentFolder := env.Pwd() for { @@ -675,7 +675,7 @@ func (env *ShellEnvironment) HasParentFilePath(path string) (*FileInfo, error) { } } -func (env *ShellEnvironment) StackCount() int { +func (env *Shell) StackCount() int { defer env.Trace(time.Now(), "StackCount") if env.CmdFlags.StackCount < 0 { return 0 @@ -683,11 +683,11 @@ func (env *ShellEnvironment) StackCount() int { return env.CmdFlags.StackCount } -func (env *ShellEnvironment) Cache() Cache { +func (env *Shell) Cache() Cache { return env.fileCache } -func (env *ShellEnvironment) Close() { +func (env *Shell) Close() { defer env.Trace(time.Now(), "Close") templateCache, err := json.Marshal(env.TemplateCache()) if err == nil { @@ -696,7 +696,7 @@ func (env *ShellEnvironment) Close() { env.fileCache.Close() } -func (env *ShellEnvironment) LoadTemplateCache() { +func (env *Shell) LoadTemplateCache() { defer env.Trace(time.Now(), "LoadTemplateCache") val, OK := env.fileCache.Get(TEMPLATECACHE) if !OK { @@ -711,11 +711,11 @@ func (env *ShellEnvironment) LoadTemplateCache() { env.tmplCache = &templateCache } -func (env *ShellEnvironment) Logs() string { +func (env *Shell) Logs() string { return env.logBuilder.String() } -func (env *ShellEnvironment) TemplateCache() *TemplateCache { +func (env *Shell) TemplateCache() *TemplateCache { defer env.Trace(time.Now(), "TemplateCache") if env.tmplCache != nil { return env.tmplCache @@ -758,7 +758,7 @@ func (env *ShellEnvironment) TemplateCache() *TemplateCache { return tmplCache } -func (env *ShellEnvironment) DirMatchesOneOf(dir string, regexes []string) (match bool) { +func (env *Shell) DirMatchesOneOf(dir string, regexes []string) (match bool) { lock.Lock() defer lock.Unlock() // sometimes the function panics inside golang, we want to silence that error diff --git a/src/environment/shell_darwin.go b/src/platform/shell_darwin.go similarity index 86% rename from src/environment/shell_darwin.go rename to src/platform/shell_darwin.go index 7be230bd..7f14e2a5 100644 --- a/src/environment/shell_darwin.go +++ b/src/platform/shell_darwin.go @@ -1,4 +1,4 @@ -package environment +package platform import ( "errors" @@ -7,7 +7,7 @@ import ( "strings" "time" - "oh-my-posh/environment/battery" + "oh-my-posh/platform/battery" ) func mapMostLogicalState(state string) battery.State { @@ -29,7 +29,7 @@ func mapMostLogicalState(state string) battery.State { } } -func (env *ShellEnvironment) parseBatteryOutput(output string) (*battery.Info, error) { +func (env *Shell) parseBatteryOutput(output string) (*battery.Info, error) { matches := regex.FindNamedRegexMatch(`(?P[0-9]{1,3})%; (?P[a-zA-Z\s]+);`, output) if len(matches) != 2 { msg := "Unable to find battery state based on output" @@ -48,7 +48,7 @@ func (env *ShellEnvironment) parseBatteryOutput(output string) (*battery.Info, e }, nil } -func (env *ShellEnvironment) BatteryState() (*battery.Info, error) { +func (env *Shell) BatteryState() (*battery.Info, error) { defer env.Trace(time.Now(), "BatteryState") output, err := env.RunCommand("pmset", "-g", "batt") if err != nil { diff --git a/src/environment/shell_test.go b/src/platform/shell_test.go similarity index 99% rename from src/environment/shell_test.go rename to src/platform/shell_test.go index 36432296..d23d45b7 100644 --- a/src/environment/shell_test.go +++ b/src/platform/shell_test.go @@ -1,4 +1,4 @@ -package environment +package platform import ( "testing" diff --git a/src/environment/shell_unix.go b/src/platform/shell_unix.go similarity index 77% rename from src/environment/shell_unix.go rename to src/platform/shell_unix.go index d7d169a2..594ca6cc 100644 --- a/src/environment/shell_unix.go +++ b/src/platform/shell_unix.go @@ -1,6 +1,6 @@ //go:build !windows -package environment +package platform import ( "errors" @@ -13,20 +13,20 @@ import ( terminal "github.com/wayneashleyberry/terminal-dimensions" ) -func (env *ShellEnvironment) Root() bool { +func (env *Shell) Root() bool { defer env.Trace(time.Now(), "Root") return os.Geteuid() == 0 } -func (env *ShellEnvironment) Home() string { +func (env *Shell) Home() string { return os.Getenv("HOME") } -func (env *ShellEnvironment) QueryWindowTitles(processName, windowTitleRegex string) (string, error) { +func (env *Shell) QueryWindowTitles(processName, windowTitleRegex string) (string, error) { return "", &NotImplemented{} } -func (env *ShellEnvironment) IsWsl() bool { +func (env *Shell) IsWsl() bool { defer env.Trace(time.Now(), "IsWsl") // one way to check // version := env.FileContent("/proc/version") @@ -35,7 +35,7 @@ func (env *ShellEnvironment) IsWsl() bool { return env.Getenv("WSL_DISTRO_NAME") != "" } -func (env *ShellEnvironment) IsWsl2() bool { +func (env *Shell) IsWsl2() bool { defer env.Trace(time.Now(), "IsWsl2") if !env.IsWsl() { return false @@ -44,7 +44,7 @@ func (env *ShellEnvironment) IsWsl2() bool { return strings.Contains(uname, "WSL2") } -func (env *ShellEnvironment) TerminalWidth() (int, error) { +func (env *Shell) TerminalWidth() (int, error) { defer env.Trace(time.Now(), "TerminalWidth") if env.CmdFlags.TerminalWidth != 0 { return env.CmdFlags.TerminalWidth, nil @@ -56,7 +56,7 @@ func (env *ShellEnvironment) TerminalWidth() (int, error) { return int(width), err } -func (env *ShellEnvironment) Platform() string { +func (env *Shell) Platform() string { const key = "environment_platform" if val, found := env.Cache().Get(key); found { return val @@ -80,7 +80,7 @@ func (env *ShellEnvironment) Platform() string { return platform } -func (env *ShellEnvironment) CachePath() string { +func (env *Shell) CachePath() string { defer env.Trace(time.Now(), "CachePath") // get XDG_CACHE_HOME if present if cachePath := returnOrBuildCachePath(env.Getenv("XDG_CACHE_HOME")); len(cachePath) != 0 { @@ -93,11 +93,11 @@ func (env *ShellEnvironment) CachePath() string { return env.Home() } -func (env *ShellEnvironment) WindowsRegistryKeyValue(path string) (*WindowsRegistryValue, error) { +func (env *Shell) WindowsRegistryKeyValue(path string) (*WindowsRegistryValue, error) { return nil, &NotImplemented{} } -func (env *ShellEnvironment) InWSLSharedDrive() bool { +func (env *Shell) InWSLSharedDrive() bool { if !env.IsWsl2() { return false } @@ -105,7 +105,7 @@ func (env *ShellEnvironment) InWSLSharedDrive() bool { return !strings.HasPrefix(windowsPath, `//wsl.localhost/`) && !strings.HasPrefix(windowsPath, `//wsl$/`) } -func (env *ShellEnvironment) ConvertToWindowsPath(path string) string { +func (env *Shell) ConvertToWindowsPath(path string) string { windowsPath, err := env.RunCommand("wslpath", "-m", path) if err == nil { return windowsPath @@ -113,18 +113,18 @@ func (env *ShellEnvironment) ConvertToWindowsPath(path string) string { return path } -func (env *ShellEnvironment) ConvertToLinuxPath(path string) string { +func (env *Shell) ConvertToLinuxPath(path string) string { if linuxPath, err := env.RunCommand("wslpath", "-u", path); err == nil { return linuxPath } return path } -func (env *ShellEnvironment) LookWinAppPath(file string) (string, error) { +func (env *Shell) LookWinAppPath(file string) (string, error) { return "", errors.New("not relevant") } -func (env *ShellEnvironment) DirIsWritable(path string) bool { +func (env *Shell) DirIsWritable(path string) bool { defer env.Trace(time.Now(), "DirIsWritable", path) info, err := os.Stat(path) if err != nil { @@ -157,7 +157,7 @@ func (env *ShellEnvironment) DirIsWritable(path string) bool { return true } -func (env *ShellEnvironment) Connection(connectionType ConnectionType) (*Connection, error) { +func (env *Shell) Connection(connectionType ConnectionType) (*Connection, error) { // added to disable the linting error, we can implement this later if len(env.networks) == 0 { return nil, &NotImplemented{} diff --git a/src/environment/shell_windows.go b/src/platform/shell_windows.go similarity index 87% rename from src/environment/shell_windows.go rename to src/platform/shell_windows.go index 9afa5ff0..ed45d435 100644 --- a/src/environment/shell_windows.go +++ b/src/platform/shell_windows.go @@ -1,4 +1,4 @@ -package environment +package platform import ( "errors" @@ -14,7 +14,7 @@ import ( "golang.org/x/sys/windows/registry" ) -func (env *ShellEnvironment) Root() bool { +func (env *Shell) Root() bool { defer env.Trace(time.Now(), "Root") var sid *windows.SID @@ -51,7 +51,7 @@ func (env *ShellEnvironment) Root() bool { return member } -func (env *ShellEnvironment) Home() string { +func (env *Shell) Home() string { home := os.Getenv("HOME") defer func() { env.Log(Debug, "Home", home) @@ -67,7 +67,7 @@ func (env *ShellEnvironment) Home() string { return home } -func (env *ShellEnvironment) QueryWindowTitles(processName, windowTitleRegex string) (string, error) { +func (env *Shell) QueryWindowTitles(processName, windowTitleRegex string) (string, error) { defer env.Trace(time.Now(), "WindowTitle", windowTitleRegex) title, err := queryWindowTitles(processName, windowTitleRegex) if err != nil { @@ -76,17 +76,17 @@ func (env *ShellEnvironment) QueryWindowTitles(processName, windowTitleRegex str return title, err } -func (env *ShellEnvironment) IsWsl() bool { +func (env *Shell) IsWsl() bool { defer env.Trace(time.Now(), "IsWsl") return false } -func (env *ShellEnvironment) IsWsl2() bool { +func (env *Shell) IsWsl2() bool { defer env.Trace(time.Now(), "IsWsl2") return false } -func (env *ShellEnvironment) TerminalWidth() (int, error) { +func (env *Shell) TerminalWidth() (int, error) { defer env.Trace(time.Now(), "TerminalWidth") if env.CmdFlags.TerminalWidth != 0 { return env.CmdFlags.TerminalWidth, nil @@ -105,11 +105,11 @@ func (env *ShellEnvironment) TerminalWidth() (int, error) { return int(info.Size.X), nil } -func (env *ShellEnvironment) Platform() string { +func (env *Shell) Platform() string { return WINDOWS } -func (env *ShellEnvironment) CachePath() string { +func (env *Shell) CachePath() string { defer env.Trace(time.Now(), "CachePath") // get LOCALAPPDATA if present if cachePath := returnOrBuildCachePath(env.Getenv("LOCALAPPDATA")); len(cachePath) != 0 { @@ -118,7 +118,7 @@ func (env *ShellEnvironment) CachePath() string { return env.Home() } -func (env *ShellEnvironment) LookWinAppPath(file string) (string, error) { +func (env *Shell) LookWinAppPath(file string) (string, error) { winAppPath := filepath.Join(env.Getenv("LOCALAPPDATA"), `\Microsoft\WindowsApps\`) command := file + ".exe" isWinStoreApp := func() bool { @@ -140,7 +140,7 @@ func (env *ShellEnvironment) LookWinAppPath(file string) (string, error) { // If the path ends in "\", the "(Default)" key in that path is retrieved. // // Returns a variant type if successful; nil and an error if not. -func (env *ShellEnvironment) WindowsRegistryKeyValue(path string) (*WindowsRegistryValue, error) { +func (env *Shell) WindowsRegistryKeyValue(path string) (*WindowsRegistryValue, error) { env.Trace(time.Now(), "WindowsRegistryKeyValue", path) // Format: @@ -221,19 +221,19 @@ func (env *ShellEnvironment) WindowsRegistryKeyValue(path string) (*WindowsRegis return regValue, nil } -func (env *ShellEnvironment) InWSLSharedDrive() bool { +func (env *Shell) InWSLSharedDrive() bool { return false } -func (env *ShellEnvironment) ConvertToWindowsPath(path string) string { +func (env *Shell) ConvertToWindowsPath(path string) string { return strings.ReplaceAll(path, `\`, "/") } -func (env *ShellEnvironment) ConvertToLinuxPath(path string) string { +func (env *Shell) ConvertToLinuxPath(path string) string { return path } -func (env *ShellEnvironment) DirIsWritable(path string) bool { +func (env *Shell) DirIsWritable(path string) bool { defer env.Trace(time.Now(), "DirIsWritable") info, err := os.Stat(path) if err != nil { @@ -255,7 +255,7 @@ func (env *ShellEnvironment) DirIsWritable(path string) bool { return true } -func (env *ShellEnvironment) Connection(connectionType ConnectionType) (*Connection, error) { +func (env *Shell) Connection(connectionType ConnectionType) (*Connection, error) { if env.networks == nil { networks := env.getConnections() if len(networks) == 0 { diff --git a/src/environment/shell_windows_nix.go b/src/platform/shell_windows_nix.go similarity index 63% rename from src/environment/shell_windows_nix.go rename to src/platform/shell_windows_nix.go index e0ba8a95..f4a133e5 100644 --- a/src/environment/shell_windows_nix.go +++ b/src/platform/shell_windows_nix.go @@ -1,13 +1,13 @@ //go:build !darwin -package environment +package platform import ( - "oh-my-posh/environment/battery" + "oh-my-posh/platform/battery" "time" ) -func (env *ShellEnvironment) BatteryState() (*battery.Info, error) { +func (env *Shell) BatteryState() (*battery.Info, error) { defer env.Trace(time.Now(), "BatteryState") info, err := battery.Get() if err != nil { diff --git a/src/environment/windows_win32.go b/src/platform/windows_win32.go similarity index 98% rename from src/environment/windows_win32.go rename to src/platform/windows_win32.go index b90e0ffb..987f5533 100644 --- a/src/environment/windows_win32.go +++ b/src/platform/windows_win32.go @@ -1,6 +1,6 @@ //go:build windows -package environment +package platform import ( "errors" @@ -199,7 +199,7 @@ func readWinAppLink(path string) (string, error) { // networks -func (env *ShellEnvironment) getConnections() []*Connection { +func (env *Shell) getConnections() []*Connection { var pIFTable2 *MIN_IF_TABLE2 _, _, _ = hGetIfTable2.Call(uintptr(unsafe.Pointer(&pIFTable2))) @@ -327,7 +327,7 @@ var ( hWlanQueryInterface = wlanapi.NewProc("WlanQueryInterface") ) -func (env *ShellEnvironment) getWiFiSSID(guid windows.GUID) string { +func (env *Shell) getWiFiSSID(guid windows.GUID) string { // Query wifi connection state var pdwNegotiatedVersion uint32 var phClientHandle uint32 diff --git a/src/segments/angular.go b/src/segments/angular.go index dcefa16f..2dc4d0a6 100644 --- a/src/segments/angular.go +++ b/src/segments/angular.go @@ -1,7 +1,7 @@ package segments import ( - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" "path/filepath" ) @@ -14,7 +14,7 @@ func (a *Angular) Template() string { return languageTemplate } -func (a *Angular) Init(props properties.Properties, env environment.Environment) { +func (a *Angular) Init(props properties.Properties, env platform.Environment) { a.language = language{ env: env, props: props, diff --git a/src/segments/aws.go b/src/segments/aws.go index 497cc81c..c84e1859 100644 --- a/src/segments/aws.go +++ b/src/segments/aws.go @@ -2,14 +2,14 @@ package segments import ( "fmt" - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" "strings" ) type Aws struct { props properties.Properties - env environment.Environment + env platform.Environment Profile string Region string @@ -23,7 +23,7 @@ func (a *Aws) Template() string { return " {{ .Profile }}{{ if .Region }}@{{ .Region }}{{ end }} " } -func (a *Aws) Init(props properties.Properties, env environment.Environment) { +func (a *Aws) Init(props properties.Properties, env platform.Environment) { a.props = props a.env = env } diff --git a/src/segments/az.go b/src/segments/az.go index 49b194fa..43eda6d4 100644 --- a/src/segments/az.go +++ b/src/segments/az.go @@ -3,7 +3,7 @@ package segments import ( "encoding/json" "errors" - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" "path/filepath" "strings" @@ -11,7 +11,7 @@ import ( type Az struct { props properties.Properties - env environment.Environment + env platform.Environment AzureSubscription Origin string @@ -73,7 +73,7 @@ func (a *Az) Template() string { return " {{ .Name }} " } -func (a *Az) Init(props properties.Properties, env environment.Environment) { +func (a *Az) Init(props properties.Properties, env platform.Environment) { a.props = props a.env = env } diff --git a/src/segments/az_functions.go b/src/segments/az_functions.go index ae9dcc8c..f0a8f6be 100644 --- a/src/segments/az_functions.go +++ b/src/segments/az_functions.go @@ -1,7 +1,7 @@ package segments import ( - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" ) @@ -13,7 +13,7 @@ func (az *AzFunc) Template() string { return languageTemplate } -func (az *AzFunc) Init(props properties.Properties, env environment.Environment) { +func (az *AzFunc) Init(props properties.Properties, env platform.Environment) { az.language = language{ env: env, props: props, diff --git a/src/segments/az_test.go b/src/segments/az_test.go index cf73070f..c8ec6972 100644 --- a/src/segments/az_test.go +++ b/src/segments/az_test.go @@ -1,8 +1,8 @@ package segments import ( - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "oh-my-posh/properties" "oh-my-posh/template" "os" @@ -122,7 +122,7 @@ func TestAzSegment(t *testing.T) { azureRmContext = string(content) } - env.On("GOOS").Return(environment.LINUX) + env.On("GOOS").Return(platform.LINUX) env.On("FileContent", filepath.Join(home, ".azure", "azureProfile.json")).Return(azureProfile) env.On("Getenv", "POSH_AZURE_SUBSCRIPTION").Return(azureRmContext) env.On("Getenv", "AZURE_CONFIG_DIR").Return("") diff --git a/src/segments/battery.go b/src/segments/battery.go index 608a4de3..efafe494 100644 --- a/src/segments/battery.go +++ b/src/segments/battery.go @@ -1,14 +1,14 @@ package segments import ( - "oh-my-posh/environment" - "oh-my-posh/environment/battery" + "oh-my-posh/platform" + "oh-my-posh/platform/battery" "oh-my-posh/properties" ) type Battery struct { props properties.Properties - env environment.Environment + env platform.Environment *battery.Info Error string @@ -84,7 +84,7 @@ func (b *Battery) enabledWhileError(err error) bool { return true } -func (b *Battery) Init(props properties.Properties, env environment.Environment) { +func (b *Battery) Init(props properties.Properties, env platform.Environment) { b.props = props b.env = env } diff --git a/src/segments/brewfather.go b/src/segments/brewfather.go index 21b5332f..3e55dd59 100644 --- a/src/segments/brewfather.go +++ b/src/segments/brewfather.go @@ -7,7 +7,7 @@ import ( "fmt" "math" "net/http" - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" "sort" "time" @@ -16,7 +16,7 @@ import ( // segment struct, makes templating easier type Brewfather struct { props properties.Properties - env environment.Environment + env platform.Environment Batch TemperatureTrendIcon string @@ -322,7 +322,7 @@ func (bf *Brewfather) SGToPlato(sg float64) float64 { return math.Round(100*((135.997*sg*sg*sg)-(630.272*sg*sg)+(1111.14*sg)-616.868)) / 100 // 2 decimal places } -func (bf *Brewfather) Init(props properties.Properties, env environment.Environment) { +func (bf *Brewfather) Init(props properties.Properties, env platform.Environment) { bf.props = props bf.env = env } diff --git a/src/segments/cds.go b/src/segments/cds.go index f229364d..196878d4 100644 --- a/src/segments/cds.go +++ b/src/segments/cds.go @@ -2,7 +2,7 @@ package segments import ( "encoding/json" - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" ) @@ -15,7 +15,7 @@ func (c *Cds) Template() string { return languageTemplate } -func (c *Cds) Init(props properties.Properties, env environment.Environment) { +func (c *Cds) Init(props properties.Properties, env platform.Environment) { c.language = language{ env: env, props: props, diff --git a/src/segments/cds_test.go b/src/segments/cds_test.go index c6c93da1..83c673b4 100644 --- a/src/segments/cds_test.go +++ b/src/segments/cds_test.go @@ -2,8 +2,8 @@ package segments import ( "fmt" - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "oh-my-posh/properties" "path/filepath" "testing" @@ -115,7 +115,7 @@ func TestCdsSegment(t *testing.T) { "display_mode": tc.DisplayMode, } - env.On("TemplateCache").Return(&environment.TemplateCache{ + env.On("TemplateCache").Return(&platform.TemplateCache{ Env: make(map[string]string), }) diff --git a/src/segments/cf.go b/src/segments/cf.go index 28ac3912..fce933d5 100644 --- a/src/segments/cf.go +++ b/src/segments/cf.go @@ -1,7 +1,7 @@ package segments import ( - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" ) @@ -13,7 +13,7 @@ func (c *Cf) Template() string { return languageTemplate } -func (c *Cf) Init(props properties.Properties, env environment.Environment) { +func (c *Cf) Init(props properties.Properties, env platform.Environment) { c.language = language{ env: env, props: props, diff --git a/src/segments/cf_target.go b/src/segments/cf_target.go index c93b5462..dffaa862 100644 --- a/src/segments/cf_target.go +++ b/src/segments/cf_target.go @@ -1,14 +1,14 @@ package segments import ( - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" "regexp" ) type CfTarget struct { props properties.Properties - env environment.Environment + env platform.Environment CfTargetDetails } @@ -24,7 +24,7 @@ func (c *CfTarget) Template() string { return "{{if .Org }}{{ .Org }}{{ end }}{{if .Space }}/{{ .Space }}{{ end }}" } -func (c *CfTarget) Init(props properties.Properties, env environment.Environment) { +func (c *CfTarget) Init(props properties.Properties, env platform.Environment) { c.props = props c.env = env } diff --git a/src/segments/cf_test.go b/src/segments/cf_test.go index 1392d885..1a3f8247 100644 --- a/src/segments/cf_test.go +++ b/src/segments/cf_test.go @@ -2,8 +2,8 @@ package segments import ( "fmt" - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "oh-my-posh/properties" "path/filepath" "testing" @@ -63,7 +63,7 @@ func TestCFSegment(t *testing.T) { env.On("Pwd").Return("/usr/home/dev/my-app") env.On("Home").Return("/usr/home") - env.On("TemplateCache").Return(&environment.TemplateCache{ + env.On("TemplateCache").Return(&platform.TemplateCache{ Env: make(map[string]string), }) diff --git a/src/segments/cmake.go b/src/segments/cmake.go index 203af347..420182d6 100644 --- a/src/segments/cmake.go +++ b/src/segments/cmake.go @@ -1,7 +1,7 @@ package segments import ( - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" ) @@ -13,7 +13,7 @@ func (c *Cmake) Template() string { return languageTemplate } -func (c *Cmake) Init(props properties.Properties, env environment.Environment) { +func (c *Cmake) Init(props properties.Properties, env platform.Environment) { c.language = language{ env: env, props: props, diff --git a/src/segments/command.go b/src/segments/command.go index c5ece77d..765c51a5 100644 --- a/src/segments/command.go +++ b/src/segments/command.go @@ -1,14 +1,14 @@ package segments import ( - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" "strings" ) type Cmd struct { props properties.Properties - env environment.Environment + env platform.Environment Output string } @@ -71,7 +71,7 @@ func (c *Cmd) runScript(shell, script string) bool { return len(c.Output) != 0 } -func (c *Cmd) Init(props properties.Properties, env environment.Environment) { +func (c *Cmd) Init(props properties.Properties, env platform.Environment) { c.props = props c.env = env } diff --git a/src/segments/connection.go b/src/segments/connection.go index 4891b1f3..6840feb7 100644 --- a/src/segments/connection.go +++ b/src/segments/connection.go @@ -1,16 +1,16 @@ package segments import ( - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" "strings" ) type Connection struct { props properties.Properties - env environment.Environment + env platform.Environment - environment.Connection + platform.Connection } const ( @@ -25,7 +25,7 @@ func (c *Connection) Enabled() bool { types := c.props.GetString(Type, "wifi|ethernet") connectionTypes := strings.Split(types, "|") for _, connectionType := range connectionTypes { - network, err := c.env.Connection(environment.ConnectionType(connectionType)) + network, err := c.env.Connection(platform.ConnectionType(connectionType)) if err != nil { continue } @@ -35,7 +35,7 @@ func (c *Connection) Enabled() bool { return false } -func (c *Connection) Init(props properties.Properties, env environment.Environment) { +func (c *Connection) Init(props properties.Properties, env platform.Environment) { c.props = props c.env = env } diff --git a/src/segments/connection_test.go b/src/segments/connection_test.go index e365fc5a..280f85e1 100644 --- a/src/segments/connection_test.go +++ b/src/segments/connection_test.go @@ -2,8 +2,8 @@ package segments import ( "fmt" - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "oh-my-posh/properties" "testing" @@ -12,7 +12,7 @@ import ( func TestConnection(t *testing.T) { type connectionResponse struct { - Connection *environment.Connection + Connection *platform.Connection Error error } cases := []struct { @@ -29,7 +29,7 @@ func TestConnection(t *testing.T) { ConnectionType: "wifi", Connections: []*connectionResponse{ { - Connection: &environment.Connection{ + Connection: &platform.Connection{ Name: "WiFi", Type: "wifi", }, @@ -41,8 +41,8 @@ func TestConnection(t *testing.T) { ConnectionType: "wifi", Connections: []*connectionResponse{ { - Connection: &environment.Connection{ - Type: environment.WIFI, + Connection: &platform.Connection{ + Type: platform.WIFI, }, Error: fmt.Errorf("no connection"), }, @@ -55,14 +55,14 @@ func TestConnection(t *testing.T) { ExpectedEnabled: true, Connections: []*connectionResponse{ { - Connection: &environment.Connection{ - Type: environment.WIFI, + Connection: &platform.Connection{ + Type: platform.WIFI, }, Error: fmt.Errorf("no connection"), }, { - Connection: &environment.Connection{ - Type: environment.ETHERNET, + Connection: &platform.Connection{ + Type: platform.ETHERNET, }, }, }, @@ -72,14 +72,14 @@ func TestConnection(t *testing.T) { ConnectionType: "wifi|ethernet", Connections: []*connectionResponse{ { - Connection: &environment.Connection{ - Type: environment.WIFI, + Connection: &platform.Connection{ + Type: platform.WIFI, }, Error: fmt.Errorf("no connection"), }, { - Connection: &environment.Connection{ - Type: environment.ETHERNET, + Connection: &platform.Connection{ + Type: platform.ETHERNET, }, Error: fmt.Errorf("no connection"), }, diff --git a/src/segments/crystal.go b/src/segments/crystal.go index 11525b60..a7c08c02 100644 --- a/src/segments/crystal.go +++ b/src/segments/crystal.go @@ -1,7 +1,7 @@ package segments import ( - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" ) @@ -13,7 +13,7 @@ func (c *Crystal) Template() string { return languageTemplate } -func (c *Crystal) Init(props properties.Properties, env environment.Environment) { +func (c *Crystal) Init(props properties.Properties, env platform.Environment) { c.language = language{ env: env, props: props, diff --git a/src/segments/dart.go b/src/segments/dart.go index 7850445a..0fcdf6be 100644 --- a/src/segments/dart.go +++ b/src/segments/dart.go @@ -1,7 +1,7 @@ package segments import ( - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" ) @@ -18,7 +18,7 @@ func (d *Dart) Template() string { return languageTemplate } -func (d *Dart) Init(props properties.Properties, env environment.Environment) { +func (d *Dart) Init(props properties.Properties, env platform.Environment) { d.language = language{ env: env, props: props, diff --git a/src/segments/deno.go b/src/segments/deno.go index c26c6066..6d0a6db8 100644 --- a/src/segments/deno.go +++ b/src/segments/deno.go @@ -1,7 +1,7 @@ package segments import ( - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" ) @@ -13,7 +13,7 @@ func (d *Deno) Template() string { return languageTemplate } -func (d *Deno) Init(props properties.Properties, env environment.Environment) { +func (d *Deno) Init(props properties.Properties, env platform.Environment) { d.language = language{ env: env, props: props, diff --git a/src/segments/dotnet.go b/src/segments/dotnet.go index 37a4ea0b..77968f05 100644 --- a/src/segments/dotnet.go +++ b/src/segments/dotnet.go @@ -2,7 +2,7 @@ package segments import ( "oh-my-posh/constants" - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" ) @@ -16,7 +16,7 @@ func (d *Dotnet) Template() string { return " {{ if .Unsupported }}\uf071{{ else }}{{ .Full }}{{ end }} " } -func (d *Dotnet) Init(props properties.Properties, env environment.Environment) { +func (d *Dotnet) Init(props properties.Properties, env platform.Environment) { d.language = language{ env: env, props: props, diff --git a/src/segments/dotnet_test.go b/src/segments/dotnet_test.go index 6e7742e9..795fc6e0 100644 --- a/src/segments/dotnet_test.go +++ b/src/segments/dotnet_test.go @@ -2,8 +2,8 @@ package segments import ( "oh-my-posh/constants" - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "oh-my-posh/properties" "testing" @@ -29,7 +29,7 @@ func TestDotnetSegment(t *testing.T) { env := new(mock.MockedEnvironment) env.On("HasCommand", "dotnet").Return(tc.HasCommand) if tc.ExitCode != 0 { - err := &environment.CommandError{ExitCode: tc.ExitCode} + err := &platform.CommandError{ExitCode: tc.ExitCode} env.On("RunCommand", "dotnet", []string{"--version"}).Return("", err) } else { env.On("RunCommand", "dotnet", []string{"--version"}).Return(tc.Version, nil) @@ -39,7 +39,7 @@ func TestDotnetSegment(t *testing.T) { env.On("PathSeparator").Return("") env.On("Pwd").Return("/usr/home/project") env.On("Home").Return("/usr/home") - env.On("TemplateCache").Return(&environment.TemplateCache{ + env.On("TemplateCache").Return(&platform.TemplateCache{ Env: make(map[string]string), }) props := properties.Map{ diff --git a/src/segments/executiontime.go b/src/segments/executiontime.go index 5b63d442..0598ee3d 100644 --- a/src/segments/executiontime.go +++ b/src/segments/executiontime.go @@ -2,7 +2,7 @@ package segments import ( "fmt" - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" "strconv" @@ -12,7 +12,7 @@ import ( type Executiontime struct { props properties.Properties - env environment.Environment + env platform.Environment FormattedMs string Ms int64 @@ -67,7 +67,7 @@ func (t *Executiontime) Template() string { return " {{ .FormattedMs }} " } -func (t *Executiontime) Init(props properties.Properties, env environment.Environment) { +func (t *Executiontime) Init(props properties.Properties, env platform.Environment) { t.props = props t.env = env } diff --git a/src/segments/exit.go b/src/segments/exit.go index ef824c1d..1eb47377 100644 --- a/src/segments/exit.go +++ b/src/segments/exit.go @@ -1,14 +1,14 @@ package segments import ( - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" "strconv" ) type Exit struct { props properties.Properties - env environment.Environment + env platform.Environment Meaning string } @@ -25,7 +25,7 @@ func (e *Exit) Enabled() bool { return e.env.ErrorCode() != 0 } -func (e *Exit) Init(props properties.Properties, env environment.Environment) { +func (e *Exit) Init(props properties.Properties, env platform.Environment) { e.props = props e.env = env } diff --git a/src/segments/exit_test.go b/src/segments/exit_test.go index 8904b525..cc2ec86f 100644 --- a/src/segments/exit_test.go +++ b/src/segments/exit_test.go @@ -1,8 +1,8 @@ package segments import ( - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "oh-my-posh/properties" "testing" @@ -79,7 +79,7 @@ func TestExitWriterTemplateString(t *testing.T) { for _, tc := range cases { env := new(mock.MockedEnvironment) env.On("ErrorCode").Return(tc.ExitCode) - env.On("TemplateCache").Return(&environment.TemplateCache{ + env.On("TemplateCache").Return(&platform.TemplateCache{ Code: tc.ExitCode, }) e := &Exit{ diff --git a/src/segments/flutter.go b/src/segments/flutter.go index 98711fb1..10678b65 100644 --- a/src/segments/flutter.go +++ b/src/segments/flutter.go @@ -1,7 +1,7 @@ package segments import ( - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" ) @@ -13,7 +13,7 @@ func (f *Flutter) Template() string { return languageTemplate } -func (f *Flutter) Init(props properties.Properties, env environment.Environment) { +func (f *Flutter) Init(props properties.Properties, env platform.Environment) { f.language = language{ env: env, props: props, diff --git a/src/segments/gcp.go b/src/segments/gcp.go index 3b88d48b..a153b026 100644 --- a/src/segments/gcp.go +++ b/src/segments/gcp.go @@ -2,7 +2,7 @@ package segments import ( "errors" - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" "path" @@ -15,7 +15,7 @@ const ( type Gcp struct { props properties.Properties - env environment.Environment + env platform.Environment Account string Project string @@ -26,7 +26,7 @@ func (g *Gcp) Template() string { return " {{ .Project }} " } -func (g *Gcp) Init(props properties.Properties, env environment.Environment) { +func (g *Gcp) Init(props properties.Properties, env platform.Environment) { g.props = props g.env = env } @@ -35,7 +35,7 @@ func (g *Gcp) Enabled() bool { cfgDir := g.getConfigDirectory() configFile, err := g.getActiveConfig(cfgDir) if err != nil { - g.env.Log(environment.Error, "Gcp.Enabled()", err.Error()) + g.env.Log(platform.Error, "Gcp.Enabled()", err.Error()) return false } @@ -43,13 +43,13 @@ func (g *Gcp) Enabled() bool { cfg := g.env.FileContent(cfgpath) if len(cfg) == 0 { - g.env.Log(environment.Error, "Gcp.Enabled()", "config file is empty") + g.env.Log(platform.Error, "Gcp.Enabled()", "config file is empty") return false } data, err := ini.Load([]byte(cfg)) if err != nil { - g.env.Log(environment.Error, "Gcp.Enabled()", err.Error()) + g.env.Log(platform.Error, "Gcp.Enabled()", err.Error()) return false } @@ -74,7 +74,7 @@ func (g *Gcp) getConfigDirectory() string { if len(cfgDir) != 0 { return cfgDir } - if g.env.GOOS() == environment.WINDOWS { + if g.env.GOOS() == platform.WINDOWS { return path.Join(g.env.Getenv("APPDATA"), "gcloud") } return path.Join(g.env.Home(), ".config", "gcloud") diff --git a/src/segments/gcp_test.go b/src/segments/gcp_test.go index f3044def..6c869835 100644 --- a/src/segments/gcp_test.go +++ b/src/segments/gcp_test.go @@ -4,8 +4,8 @@ import ( "path" "testing" - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "github.com/stretchr/testify/assert" mock2 "github.com/stretchr/testify/mock" @@ -57,7 +57,7 @@ func TestGcpSegment(t *testing.T) { env.On("FileContent", fcPath).Return(tc.ActiveConfig) cfgpath := path.Join("config", "configurations", "config_production") env.On("FileContent", cfgpath).Return(tc.CfgData) - env.On("Log", environment.Error, "Gcp.Enabled()", mock2.Anything).Return() + env.On("Log", platform.Error, "Gcp.Enabled()", mock2.Anything).Return() g := &Gcp{ env: env, } @@ -84,7 +84,7 @@ func TestGetConfigDirectory(t *testing.T) { }, { Case: "Windows", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, AppData: "/Users/posh/.config", Expected: "/Users/posh/.config/gcloud", }, diff --git a/src/segments/git.go b/src/segments/git.go index eaacb684..614cc6c2 100644 --- a/src/segments/git.go +++ b/src/segments/git.go @@ -3,7 +3,7 @@ package segments import ( "fmt" url2 "net/url" - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" "oh-my-posh/regex" "path/filepath" @@ -127,7 +127,7 @@ func (g *Git) Enabled() bool { return false } - g.RepoName = environment.Base(g.env, g.convertToLinuxPath(g.realDir)) + g.RepoName = platform.Base(g.env, g.convertToLinuxPath(g.realDir)) if g.IsBare { g.getBareRepoInfo() @@ -227,15 +227,15 @@ func (g *Git) getBareRepoInfo() { } func (g *Git) setDir(dir string) { - dir = environment.ReplaceHomeDirPrefixWithTilde(g.env, dir) // align with template PWD - if g.env.GOOS() == environment.WINDOWS { + dir = platform.ReplaceHomeDirPrefixWithTilde(g.env, dir) // align with template PWD + if g.env.GOOS() == platform.WINDOWS { g.Dir = strings.TrimSuffix(dir, `\.git`) return } g.Dir = strings.TrimSuffix(dir, "/.git") } -func (g *Git) hasWorktree(gitdir *environment.FileInfo) bool { +func (g *Git) hasWorktree(gitdir *platform.FileInfo) bool { g.rootDir = gitdir.Path dirPointer := strings.Trim(g.env.FileContent(gitdir.Path), " \r\n") matches := regex.FindNamedRegexMatch(`^gitdir: (?P.*)$`, dirPointer) diff --git a/src/segments/git_test.go b/src/segments/git_test.go index 762cd3bf..9f1a8b48 100644 --- a/src/segments/git_test.go +++ b/src/segments/git_test.go @@ -3,8 +3,8 @@ package segments import ( "errors" "fmt" - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "oh-my-posh/properties" "os" "path/filepath" @@ -34,7 +34,7 @@ func TestEnabledGitNotFound(t *testing.T) { } func TestEnabledInWorkingDirectory(t *testing.T) { - fileInfo := &environment.FileInfo{ + fileInfo := &platform.FileInfo{ Path: "/dir/hello", ParentFolder: "/dir", IsDir: true, @@ -121,7 +121,7 @@ func TestEnabledInWorktree(t *testing.T) { ExpectedRootFolder: TestRootPath + "dev/separate/.git/posh", }, } - fileInfo := &environment.FileInfo{ + fileInfo := &platform.FileInfo{ Path: TestRootPath + "dev/.git", ParentFolder: TestRootPath + "dev", } @@ -186,7 +186,7 @@ func TestEnabledInBareRepo(t *testing.T) { env.On("InWSLSharedDrive").Return(false) env.On("GOOS").Return("") env.On("HasCommand", "git").Return(true) - env.On("HasParentFilePath", ".git").Return(&environment.FileInfo{}, errors.New("nope")) + env.On("HasParentFilePath", ".git").Return(&platform.FileInfo{}, errors.New("nope")) env.MockGitCommand(pwd, tc.IsBare, "rev-parse", "--is-bare-repository") env.On("Pwd").Return(pwd) env.On("FileContent", "/home/user/bare.git/HEAD").Return(tc.HEAD) diff --git a/src/segments/golang.go b/src/segments/golang.go index 0dcd1c19..e8da32cb 100644 --- a/src/segments/golang.go +++ b/src/segments/golang.go @@ -1,7 +1,7 @@ package segments import ( - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" "golang.org/x/mod/modfile" @@ -19,7 +19,7 @@ func (g *Golang) Template() string { return languageTemplate } -func (g *Golang) Init(props properties.Properties, env environment.Environment) { +func (g *Golang) Init(props properties.Properties, env platform.Environment) { g.language = language{ env: env, props: props, diff --git a/src/segments/golang_test.go b/src/segments/golang_test.go index 6d3fdf94..32b8a118 100644 --- a/src/segments/golang_test.go +++ b/src/segments/golang_test.go @@ -3,8 +3,8 @@ package segments import ( "errors" "fmt" - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "oh-my-posh/properties" "os" "testing" @@ -26,7 +26,7 @@ func getMockedLanguageEnv(params *mockedLanguageParams) (*mock.MockedEnvironment env.On("HasFiles", params.extension).Return(true) env.On("Pwd").Return("/usr/home/project") env.On("Home").Return("/usr/home") - env.On("TemplateCache").Return(&environment.TemplateCache{ + env.On("TemplateCache").Return(&platform.TemplateCache{ Env: make(map[string]string), }) props := properties.Map{ @@ -67,7 +67,7 @@ func TestGolang(t *testing.T) { env, props := getMockedLanguageEnv(params) if tc.ParseModFile { props[ParseModFile] = tc.ParseModFile - fileInfo := &environment.FileInfo{ + fileInfo := &platform.FileInfo{ Path: "../go.mod", ParentFolder: "./", IsDir: false, diff --git a/src/segments/haskell.go b/src/segments/haskell.go index 4bba90a1..d69f949c 100644 --- a/src/segments/haskell.go +++ b/src/segments/haskell.go @@ -1,7 +1,7 @@ package segments import ( - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" ) @@ -19,7 +19,7 @@ func (h *Haskell) Template() string { return languageTemplate } -func (h *Haskell) Init(props properties.Properties, env environment.Environment) { +func (h *Haskell) Init(props properties.Properties, env platform.Environment) { ghcRegex := `(?P((?P[0-9]+).(?P[0-9]+).(?P[0-9]+)))` ghcCmd := &cmd{ executable: "ghc", diff --git a/src/segments/haskell_test.go b/src/segments/haskell_test.go index 3752059f..dd59ec21 100644 --- a/src/segments/haskell_test.go +++ b/src/segments/haskell_test.go @@ -3,8 +3,8 @@ package segments import ( "errors" "fmt" - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "oh-my-posh/properties" "testing" @@ -63,7 +63,7 @@ func TestHaskell(t *testing.T) { env.On("HasCommand", "ghc").Return(true) env.On("RunCommand", "ghc", []string{"--numeric-version"}).Return(tc.GhcVersion, nil) } - fileInfo := &environment.FileInfo{ + fileInfo := &platform.FileInfo{ Path: "../stack.yaml", ParentFolder: "./", IsDir: false, @@ -77,7 +77,7 @@ func TestHaskell(t *testing.T) { env.On("HasFiles", "*.hs").Return(true) env.On("Pwd").Return("/usr/home/project") env.On("Home").Return("/usr/home") - env.On("TemplateCache").Return(&environment.TemplateCache{ + env.On("TemplateCache").Return(&platform.TemplateCache{ Env: make(map[string]string), }) diff --git a/src/segments/ipify.go b/src/segments/ipify.go index e4ec116c..454c61d6 100644 --- a/src/segments/ipify.go +++ b/src/segments/ipify.go @@ -2,8 +2,8 @@ package segments import ( "net" - "oh-my-posh/environment" "oh-my-posh/http" + "oh-my-posh/platform" "oh-my-posh/properties" ) @@ -61,7 +61,7 @@ func (i *IPify) getResult() (string, error) { return data.IP, err } -func (i *IPify) Init(props properties.Properties, env environment.Environment) { +func (i *IPify) Init(props properties.Properties, env platform.Environment) { request := &http.Request{} request.Init(env, props) diff --git a/src/segments/iterm.go b/src/segments/iterm.go index df88b192..1ca091d3 100644 --- a/src/segments/iterm.go +++ b/src/segments/iterm.go @@ -2,13 +2,13 @@ package segments import ( "errors" - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" ) type ITerm struct { props properties.Properties - env environment.Environment + env platform.Environment PromptMark string } @@ -54,7 +54,7 @@ func (i *ITerm) getResult() (string, error) { return response, nil } -func (i *ITerm) Init(props properties.Properties, env environment.Environment) { +func (i *ITerm) Init(props properties.Properties, env platform.Environment) { i.props = props i.env = env } diff --git a/src/segments/java.go b/src/segments/java.go index 3e90a558..c16c0010 100644 --- a/src/segments/java.go +++ b/src/segments/java.go @@ -2,7 +2,7 @@ package segments import ( "fmt" - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" ) @@ -14,7 +14,7 @@ func (j *Java) Template() string { return languageTemplate } -func (j *Java) Init(props properties.Properties, env environment.Environment) { +func (j *Java) Init(props properties.Properties, env platform.Environment) { javaRegex := `(?: JRE)(?: \(.*\))? \((?P(?P[0-9]+)(?:\.(?P[0-9]+))?(?:\.(?P[0-9]+))?).*\),` javaCmd := &cmd{ executable: "java", diff --git a/src/segments/julia.go b/src/segments/julia.go index dbe77dba..420160f9 100644 --- a/src/segments/julia.go +++ b/src/segments/julia.go @@ -1,7 +1,7 @@ package segments import ( - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" ) @@ -13,7 +13,7 @@ func (j *Julia) Template() string { return languageTemplate } -func (j *Julia) Init(props properties.Properties, env environment.Environment) { +func (j *Julia) Init(props properties.Properties, env platform.Environment) { j.language = language{ env: env, props: props, diff --git a/src/segments/kotlin.go b/src/segments/kotlin.go index bc203539..3f53e123 100644 --- a/src/segments/kotlin.go +++ b/src/segments/kotlin.go @@ -1,7 +1,7 @@ package segments import ( - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" ) @@ -13,7 +13,7 @@ func (k *Kotlin) Template() string { return languageTemplate } -func (k *Kotlin) Init(props properties.Properties, env environment.Environment) { +func (k *Kotlin) Init(props properties.Properties, env platform.Environment) { k.language = language{ env: env, props: props, diff --git a/src/segments/kubectl.go b/src/segments/kubectl.go index 931580fa..9c6c874f 100644 --- a/src/segments/kubectl.go +++ b/src/segments/kubectl.go @@ -1,7 +1,7 @@ package segments import ( - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" "path/filepath" @@ -13,7 +13,7 @@ const ParseKubeConfig properties.Property = "parse_kubeconfig" type Kubectl struct { props properties.Properties - env environment.Environment + env platform.Environment Context string @@ -38,7 +38,7 @@ func (k *Kubectl) Template() string { return " {{ .Context }}{{ if .Namespace }} :: {{ .Namespace }}{{ end }} " } -func (k *Kubectl) Init(props properties.Properties, env environment.Environment) { +func (k *Kubectl) Init(props properties.Properties, env platform.Environment) { k.props = props k.env = env } diff --git a/src/segments/kubectl_test.go b/src/segments/kubectl_test.go index ef3e8ef1..9cf3d520 100644 --- a/src/segments/kubectl_test.go +++ b/src/segments/kubectl_test.go @@ -2,8 +2,8 @@ package segments import ( "fmt" - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "oh-my-posh/properties" "os" "path/filepath" @@ -117,7 +117,7 @@ func TestKubectlSegment(t *testing.T) { } var kubectlErr error if tc.KubectlErr { - kubectlErr = &environment.CommandError{ + kubectlErr = &platform.CommandError{ Err: "oops", ExitCode: 1, } diff --git a/src/segments/language.go b/src/segments/language.go index 09e45fee..9ff6a0ee 100644 --- a/src/segments/language.go +++ b/src/segments/language.go @@ -3,7 +3,7 @@ package segments import ( "errors" "fmt" - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" "oh-my-posh/regex" "oh-my-posh/template" @@ -59,7 +59,7 @@ func (c *cmd) parse(versionInfo string) (*version, error) { type language struct { props properties.Properties - env environment.Environment + env platform.Environment extensions []string folders []string commands []*cmd @@ -167,7 +167,7 @@ func (l *language) setVersion() error { continue } versionStr, err = l.env.RunCommand(command.executable, command.args...) - if exitErr, ok := err.(*environment.CommandError); ok { + if exitErr, ok := err.(*platform.CommandError); ok { l.exitCode = exitErr.ExitCode lastError = fmt.Errorf("err executing %s with %s", command.executable, command.args) continue diff --git a/src/segments/language_test.go b/src/segments/language_test.go index 3de1eeaf..6c3cc3d9 100644 --- a/src/segments/language_test.go +++ b/src/segments/language_test.go @@ -1,8 +1,8 @@ package segments import ( - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "oh-my-posh/properties" "testing" @@ -53,7 +53,7 @@ func bootStrapLanguageTest(args *languageArgs) *language { } env.On("Pwd").Return(cwd) env.On("Home").Return(home) - env.On("TemplateCache").Return(&environment.TemplateCache{ + env.On("TemplateCache").Return(&platform.TemplateCache{ Env: make(map[string]string), }) if args.properties == nil { @@ -353,7 +353,7 @@ func TestLanguageEnabledCommandExitCode(t *testing.T) { enabledExtensions: []string{uni, corn}, enabledCommands: []string{"uni"}, version: universion, - expectedError: &environment.CommandError{ExitCode: expected}, + expectedError: &platform.CommandError{ExitCode: expected}, } lang := bootStrapLanguageTest(args) assert.True(t, lang.Enabled()) diff --git a/src/segments/lua.go b/src/segments/lua.go index 10a39bb2..0be43481 100644 --- a/src/segments/lua.go +++ b/src/segments/lua.go @@ -1,7 +1,7 @@ package segments import ( - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" ) @@ -17,7 +17,7 @@ func (l *Lua) Template() string { return languageTemplate } -func (l *Lua) Init(props properties.Properties, env environment.Environment) { +func (l *Lua) Init(props properties.Properties, env platform.Environment) { l.language = language{ env: env, props: props, diff --git a/src/segments/lua_test.go b/src/segments/lua_test.go index d7f150d5..125a75f1 100644 --- a/src/segments/lua_test.go +++ b/src/segments/lua_test.go @@ -2,8 +2,8 @@ package segments import ( "fmt" - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "oh-my-posh/properties" "strings" "testing" @@ -65,7 +65,7 @@ func TestLua(t *testing.T) { env.On("HasFiles", "*.lua").Return(true) env.On("Pwd").Return("/usr/home/project") env.On("Home").Return("/usr/home") - env.On("TemplateCache").Return(&environment.TemplateCache{ + env.On("TemplateCache").Return(&platform.TemplateCache{ Env: make(map[string]string), }) props := properties.Map{ diff --git a/src/segments/nbgv.go b/src/segments/nbgv.go index 00d4e9d9..14b570d6 100644 --- a/src/segments/nbgv.go +++ b/src/segments/nbgv.go @@ -2,13 +2,13 @@ package segments import ( "encoding/json" - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" ) type Nbgv struct { props properties.Properties - env environment.Environment + env platform.Environment VersionInfo } @@ -45,7 +45,7 @@ func (n *Nbgv) Enabled() bool { return n.VersionInfo.VersionFileFound } -func (n *Nbgv) Init(props properties.Properties, env environment.Environment) { +func (n *Nbgv) Init(props properties.Properties, env platform.Environment) { n.props = props n.env = env } diff --git a/src/segments/nightscout.go b/src/segments/nightscout.go index 74d1c849..4b2fad3b 100644 --- a/src/segments/nightscout.go +++ b/src/segments/nightscout.go @@ -3,7 +3,7 @@ package segments import ( "encoding/json" "errors" - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" "time" ) @@ -11,7 +11,7 @@ import ( // segment struct, makes templating easier type Nightscout struct { props properties.Properties - env environment.Environment + env platform.Environment NightscoutData TrendIcon string @@ -139,7 +139,7 @@ func (ns *Nightscout) getResult() (*NightscoutData, error) { return data, nil } -func (ns *Nightscout) Init(props properties.Properties, env environment.Environment) { +func (ns *Nightscout) Init(props properties.Properties, env platform.Environment) { ns.props = props ns.env = env } diff --git a/src/segments/node.go b/src/segments/node.go index 9def1cf7..0c2c7ce0 100644 --- a/src/segments/node.go +++ b/src/segments/node.go @@ -2,7 +2,7 @@ package segments import ( "fmt" - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" "oh-my-posh/regex" ) @@ -26,7 +26,7 @@ func (n *Node) Template() string { return " {{ if .PackageManagerIcon }}{{ .PackageManagerIcon }} {{ end }}{{ .Full }} " } -func (n *Node) Init(props properties.Properties, env environment.Environment) { +func (n *Node) Init(props properties.Properties, env platform.Environment) { n.language = language{ env: env, props: props, diff --git a/src/segments/npm.go b/src/segments/npm.go index ced904e8..81580471 100644 --- a/src/segments/npm.go +++ b/src/segments/npm.go @@ -1,7 +1,7 @@ package segments import ( - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" ) @@ -17,7 +17,7 @@ func (n *Npm) Template() string { return " \ue71e {{.Full}} " } -func (n *Npm) Init(props properties.Properties, env environment.Environment) { +func (n *Npm) Init(props properties.Properties, env platform.Environment) { n.language = language{ env: env, props: props, diff --git a/src/segments/nx.go b/src/segments/nx.go index f37bbf94..108c7841 100644 --- a/src/segments/nx.go +++ b/src/segments/nx.go @@ -3,7 +3,7 @@ package segments import ( "encoding/json" "fmt" - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" "path/filepath" ) @@ -16,7 +16,7 @@ func (a *Nx) Template() string { return languageTemplate } -func (a *Nx) Init(props properties.Properties, env environment.Environment) { +func (a *Nx) Init(props properties.Properties, env platform.Environment) { a.language = language{ env: env, props: props, @@ -39,7 +39,7 @@ func (a *Nx) getVersion() (string, error) { return getNodePackageVersion(a.language.env, "nx") } -func getNodePackageVersion(env environment.Environment, nodePackage string) (string, error) { +func getNodePackageVersion(env platform.Environment, nodePackage string) (string, error) { const fileName string = "package.json" folder := filepath.Join(env.Pwd(), "node_modules", nodePackage) if !env.HasFilesInDir(folder, fileName) { diff --git a/src/segments/nx_test.go b/src/segments/nx_test.go index 216e955b..d63341a0 100644 --- a/src/segments/nx_test.go +++ b/src/segments/nx_test.go @@ -1,8 +1,8 @@ package segments import ( - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "path/filepath" "testing" @@ -30,7 +30,7 @@ func TestGetNodePackageVersion(t *testing.T) { path := filepath.Join("posh", "node_modules", "nx") env.On("HasFilesInDir", path, "package.json").Return(!tc.NoFiles) env.On("FileContent", filepath.Join(path, "package.json")).Return(tc.PackageJSON) - env.On("TemplateCache").Return(&environment.TemplateCache{ + env.On("TemplateCache").Return(&platform.TemplateCache{ Env: make(map[string]string), }) got, err := getNodePackageVersion(env, "nx") diff --git a/src/segments/os.go b/src/segments/os.go index 93e36a14..6ac335c3 100644 --- a/src/segments/os.go +++ b/src/segments/os.go @@ -1,13 +1,13 @@ package segments import ( - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" ) type Os struct { props properties.Properties - env environment.Environment + env platform.Environment Icon string } @@ -68,18 +68,18 @@ func (oi *Os) Template() string { func (oi *Os) Enabled() bool { goos := oi.env.GOOS() switch goos { - case environment.WINDOWS: + case platform.WINDOWS: oi.Icon = oi.props.GetString(Windows, "\uE62A") - case environment.DARWIN: + case platform.DARWIN: oi.Icon = oi.props.GetString(MacOS, "\uF179") - case environment.LINUX: - platform := oi.env.Platform() + case platform.LINUX: + pf := oi.env.Platform() displayDistroName := oi.props.GetBool(DisplayDistroName, false) if displayDistroName { - oi.Icon = platform + oi.Icon = pf break } - oi.Icon = oi.getDistroIcon(platform) + oi.Icon = oi.getDistroIcon(pf) default: oi.Icon = goos } @@ -130,7 +130,7 @@ func (oi *Os) getDistroIcon(distro string) string { return oi.props.GetString(Linux, "\uF17C") } -func (oi *Os) Init(props properties.Properties, env environment.Environment) { +func (oi *Os) Init(props properties.Properties, env platform.Environment) { oi.props = props oi.env = env } diff --git a/src/segments/os_test.go b/src/segments/os_test.go index da5bb299..1548bcda 100644 --- a/src/segments/os_test.go +++ b/src/segments/os_test.go @@ -1,8 +1,8 @@ package segments import ( - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "oh-my-posh/properties" "testing" @@ -66,7 +66,7 @@ func TestOSInfo(t *testing.T) { env := new(mock.MockedEnvironment) env.On("GOOS").Return(tc.GOOS) env.On("Platform").Return(tc.Platform) - env.On("TemplateCache").Return(&environment.TemplateCache{ + env.On("TemplateCache").Return(&platform.TemplateCache{ Env: make(map[string]string), WSL: tc.IsWSL, }) diff --git a/src/segments/owm.go b/src/segments/owm.go index 20e96245..d2ee1cc2 100644 --- a/src/segments/owm.go +++ b/src/segments/owm.go @@ -5,13 +5,13 @@ import ( "errors" "fmt" "math" - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" ) type Owm struct { props properties.Properties - env environment.Environment + env platform.Environment Temperature int Weather string @@ -163,7 +163,7 @@ func (d *Owm) setStatus() error { return nil } -func (d *Owm) Init(props properties.Properties, env environment.Environment) { +func (d *Owm) Init(props properties.Properties, env platform.Environment) { d.props = props d.env = env } diff --git a/src/segments/path.go b/src/segments/path.go index f3a708e4..04cbdb11 100644 --- a/src/segments/path.go +++ b/src/segments/path.go @@ -2,7 +2,7 @@ package segments import ( "fmt" - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" "oh-my-posh/regex" "oh-my-posh/shell" @@ -13,7 +13,7 @@ import ( type Path struct { props properties.Properties - env environment.Environment + env platform.Environment root string relative string @@ -115,12 +115,12 @@ func (pt *Path) Parent() string { // a root path has no parent return "" } - base := environment.Base(pt.env, pt.pwd) + base := platform.Base(pt.env, pt.pwd) path := pt.replaceFolderSeparators(pt.pwd[:len(pt.pwd)-len(base)]) return path } -func (pt *Path) Init(props properties.Properties, env environment.Environment) { +func (pt *Path) Init(props properties.Properties, env platform.Environment) { pt.props = props pt.env = env } @@ -177,7 +177,7 @@ func (pt *Path) getFolderSeparator() string { } text, err := tmpl.Render() if err != nil { - pt.env.Log(environment.Error, "getFolderSeparator", err.Error()) + pt.env.Log(platform.Error, "getFolderSeparator", err.Error()) } if len(text) == 0 { return pt.env.PathSeparator() @@ -377,7 +377,7 @@ func (pt *Path) getFullPath() string { } func (pt *Path) getFolderPath() string { - pwd := environment.Base(pt.env, pt.pwd) + pwd := platform.Base(pt.env, pt.pwd) return pt.replaceFolderSeparators(pwd) } @@ -441,7 +441,7 @@ func (pt *Path) replaceMappedLocations() (string, string) { } func (pt *Path) normalizePath(path string) string { - if pt.env.GOOS() != environment.WINDOWS { + if pt.env.GOOS() != platform.WINDOWS { return path } var clean []rune @@ -478,7 +478,7 @@ func (pt *Path) parsePath(inputPath string) (root, path string) { return s.String() } - if pt.env.GOOS() == environment.WINDOWS { + if pt.env.GOOS() == platform.WINDOWS { inputPath = pt.normalizePath(inputPath) // for a UNC path, extract \\hostname\sharename as the root matches := regex.FindNamedRegexMatch(`^\\\\(?P[^\\]+)\\+(?P[^\\]+)\\*(?P[\s\S]*)$`, inputPath) @@ -490,7 +490,7 @@ func (pt *Path) parsePath(inputPath string) (root, path string) { } s := strings.SplitAfterN(inputPath, separator, 2) root = s[0] - if pt.env.GOOS() == environment.WINDOWS { + if pt.env.GOOS() == platform.WINDOWS { root = strings.TrimSuffix(root, separator) } if len(s) == 2 { @@ -501,14 +501,14 @@ func (pt *Path) parsePath(inputPath string) (root, path string) { func (pt *Path) normalize(inputPath string) string { normalized := inputPath - if strings.HasPrefix(normalized, "~") && (len(normalized) == 1 || environment.IsPathSeparator(pt.env, normalized[1])) { + if strings.HasPrefix(normalized, "~") && (len(normalized) == 1 || platform.IsPathSeparator(pt.env, normalized[1])) { normalized = pt.env.Home() + normalized[1:] } switch pt.env.GOOS() { - case environment.WINDOWS: + case platform.WINDOWS: normalized = pt.normalizePath(normalized) fallthrough - case environment.DARWIN: + case platform.DARWIN: normalized = strings.ToLower(normalized) } return normalized diff --git a/src/segments/path_test.go b/src/segments/path_test.go index 70fdebcf..9d70150f 100644 --- a/src/segments/path_test.go +++ b/src/segments/path_test.go @@ -1,8 +1,8 @@ package segments import ( - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "oh-my-posh/properties" "oh-my-posh/shell" "oh-my-posh/template" @@ -22,7 +22,7 @@ func renderTemplate(env *mock.MockedEnvironment, segmentTemplate string, context } } if !found { - env.On("TemplateCache").Return(&environment.TemplateCache{ + env.On("TemplateCache").Return(&platform.TemplateCache{ Env: make(map[string]string), }) } @@ -59,28 +59,28 @@ func TestParent(t *testing.T) { Expected: "~/", HomePath: homeDir, Pwd: homeDir + "/test", - GOOS: environment.DARWIN, + GOOS: platform.DARWIN, PathSeparator: "/", }, { Case: "Home folder", HomePath: homeDir, Pwd: homeDir, - GOOS: environment.DARWIN, + GOOS: platform.DARWIN, PathSeparator: "/", }, { Case: "Home folder with a trailing separator", HomePath: homeDir, Pwd: homeDir + "/", - GOOS: environment.DARWIN, + GOOS: platform.DARWIN, PathSeparator: "/", }, { Case: "Root", HomePath: homeDir, Pwd: "/", - GOOS: environment.DARWIN, + GOOS: platform.DARWIN, PathSeparator: "/", }, { @@ -88,28 +88,28 @@ func TestParent(t *testing.T) { Expected: "/", HomePath: homeDir, Pwd: "/usr", - GOOS: environment.DARWIN, + GOOS: platform.DARWIN, PathSeparator: "/", }, { Case: "Windows Home folder", HomePath: homeDirWindows, Pwd: homeDirWindows, - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", }, { Case: "Windows drive root", HomePath: homeDirWindows, Pwd: "C:", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", }, { Case: "Windows drive root with a trailing separator", HomePath: homeDirWindows, Pwd: "C:\\", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", }, { @@ -117,14 +117,14 @@ func TestParent(t *testing.T) { Expected: "C:\\", HomePath: homeDirWindows, Pwd: "C:\\test", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", }, { Case: "PSDrive root", HomePath: homeDirWindows, Pwd: "HKLM:", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", }, } @@ -132,7 +132,7 @@ func TestParent(t *testing.T) { env := new(mock.MockedEnvironment) env.On("Home").Return(tc.HomePath) env.On("Pwd").Return(tc.Pwd) - env.On("Flags").Return(&environment.Flags{}) + env.On("Flags").Return(&platform.Flags{}) env.On("Shell").Return(shell.PLAIN) env.On("PathSeparator").Return(tc.PathSeparator) env.On("GOOS").Return(tc.GOOS) @@ -191,7 +191,7 @@ func TestAgnosterPathStyles(t *testing.T) { Expected: "C > a > ab > abcd", HomePath: homeDirWindows, Pwd: "C:\\ab\\ab\\abcd", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", FolderSeparatorIcon: " > ", }, @@ -297,7 +297,7 @@ func TestAgnosterPathStyles(t *testing.T) { Expected: "C:\\", HomePath: homeDirWindows, Pwd: "C:\\", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", FolderSeparatorIcon: " > ", }, @@ -306,7 +306,7 @@ func TestAgnosterPathStyles(t *testing.T) { Expected: "C > s > .w > man", HomePath: homeDirWindows, Pwd: "C:\\something\\.whatever\\man", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", FolderSeparatorIcon: " > ", }, @@ -315,7 +315,7 @@ func TestAgnosterPathStyles(t *testing.T) { Expected: "~ > s > man", HomePath: homeDirWindows, Pwd: homeDirWindows + "\\something\\man", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", FolderSeparatorIcon: " > ", }, @@ -357,7 +357,7 @@ func TestAgnosterPathStyles(t *testing.T) { Expected: "C: > .. > foo > .. > man", HomePath: homeDirWindows, Pwd: "C:\\Users\\foo\\foobar\\man", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", FolderSeparatorIcon: " > ", }, @@ -424,7 +424,7 @@ func TestAgnosterPathStyles(t *testing.T) { Expected: "\\\\localhost\\c$ > some", HomePath: homeDirWindows, Pwd: "\\\\localhost\\c$\\some", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", FolderSeparatorIcon: " > ", }, @@ -444,7 +444,7 @@ func TestAgnosterPathStyles(t *testing.T) { Expected: "\\\\localhost\\c$", HomePath: homeDirWindows, Pwd: "\\\\localhost\\c$", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", FolderSeparatorIcon: " > ", }, @@ -478,7 +478,7 @@ func TestAgnosterPathStyles(t *testing.T) { Expected: ".. > bar > man", HomePath: homeDirWindows, Pwd: homeDirWindows + "\\foo\\bar\\man", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", FolderSeparatorIcon: " > ", MaxDepth: 2, @@ -597,7 +597,7 @@ func TestAgnosterPathStyles(t *testing.T) { Expected: "C:\\", HomePath: homeDirWindows, Pwd: "C:", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", FolderSeparatorIcon: " > ", }, @@ -606,7 +606,7 @@ func TestAgnosterPathStyles(t *testing.T) { Expected: "C: > .. > bar > man", HomePath: homeDirWindows, Pwd: "C:\\usr\\foo\\bar\\man", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", FolderSeparatorIcon: " > ", MaxDepth: 2, @@ -616,7 +616,7 @@ func TestAgnosterPathStyles(t *testing.T) { Expected: "C: > .. > foo > bar > man", HomePath: homeDirWindows, Pwd: "C:\\usr\\foo\\bar\\man", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", FolderSeparatorIcon: " > ", MaxDepth: 3, @@ -626,7 +626,7 @@ func TestAgnosterPathStyles(t *testing.T) { Expected: "~ > .. > bar > man", HomePath: homeDirWindows, Pwd: homeDirWindows + "\\foo\\bar\\man", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", FolderSeparatorIcon: " > ", MaxDepth: 2, @@ -636,7 +636,7 @@ func TestAgnosterPathStyles(t *testing.T) { Expected: "~ > foo > bar > man", HomePath: homeDirWindows, Pwd: homeDirWindows + "\\foo\\bar\\man", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", FolderSeparatorIcon: " > ", MaxDepth: 3, @@ -646,7 +646,7 @@ func TestAgnosterPathStyles(t *testing.T) { Expected: "~", HomePath: homeDirWindows, Pwd: homeDirWindows, - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", FolderSeparatorIcon: " > ", MaxDepth: 1, @@ -657,7 +657,7 @@ func TestAgnosterPathStyles(t *testing.T) { Expected: ".. > foo", HomePath: homeDirWindows, Pwd: homeDirWindows + "\\foo", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", FolderSeparatorIcon: " > ", MaxDepth: 1, @@ -668,7 +668,7 @@ func TestAgnosterPathStyles(t *testing.T) { Expected: ".. > foo", HomePath: homeDirWindows, Pwd: homeDirWindows + "\\foo", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", FolderSeparatorIcon: " > ", MaxDepth: 2, @@ -683,7 +683,7 @@ func TestAgnosterPathStyles(t *testing.T) { env.On("GOOS").Return(tc.GOOS) env.On("StackCount").Return(0) env.On("IsWsl").Return(false) - args := &environment.Flags{ + args := &platform.Flags{ PSWD: tc.Pswd, } env.On("Flags").Return(args) @@ -743,11 +743,11 @@ func TestFullAndFolderPath(t *testing.T) { {Style: Folder, FolderSeparatorIcon: "|", Pwd: "/a/b/c/d", Expected: "d"}, // for Windows paths - {Style: Folder, FolderSeparatorIcon: "\\", Pwd: "C:\\", Expected: "C:\\", PathSeparator: "\\", GOOS: environment.WINDOWS}, - {Style: Folder, FolderSeparatorIcon: "\\", Pwd: homeDirWindows, Expected: "~", PathSeparator: "\\", GOOS: environment.WINDOWS}, - {Style: Full, FolderSeparatorIcon: "\\", Pwd: homeDirWindows, Expected: "~", PathSeparator: "\\", GOOS: environment.WINDOWS}, - {Style: Full, FolderSeparatorIcon: "\\", Pwd: homeDirWindows + "\\abc", Expected: "~\\abc", PathSeparator: "\\", GOOS: environment.WINDOWS}, - {Style: Full, FolderSeparatorIcon: "\\", Pwd: "C:\\Users\\posh", Expected: "C:\\Users\\posh", PathSeparator: "\\", GOOS: environment.WINDOWS}, + {Style: Folder, FolderSeparatorIcon: "\\", Pwd: "C:\\", Expected: "C:\\", PathSeparator: "\\", GOOS: platform.WINDOWS}, + {Style: Folder, FolderSeparatorIcon: "\\", Pwd: homeDirWindows, Expected: "~", PathSeparator: "\\", GOOS: platform.WINDOWS}, + {Style: Full, FolderSeparatorIcon: "\\", Pwd: homeDirWindows, Expected: "~", PathSeparator: "\\", GOOS: platform.WINDOWS}, + {Style: Full, FolderSeparatorIcon: "\\", Pwd: homeDirWindows + "\\abc", Expected: "~\\abc", PathSeparator: "\\", GOOS: platform.WINDOWS}, + {Style: Full, FolderSeparatorIcon: "\\", Pwd: "C:\\Users\\posh", Expected: "C:\\Users\\posh", PathSeparator: "\\", GOOS: platform.WINDOWS}, // StackCountEnabled=true and StackCount=2 {Style: Full, FolderSeparatorIcon: "|", Pwd: "/", StackCount: 2, Expected: "2 /"}, @@ -796,7 +796,7 @@ func TestFullAndFolderPath(t *testing.T) { tc.PathSeparator = "/" } env.On("PathSeparator").Return(tc.PathSeparator) - if tc.GOOS == environment.WINDOWS { + if tc.GOOS == platform.WINDOWS { env.On("Home").Return(homeDirWindows) } else { env.On("Home").Return(homeDir) @@ -805,7 +805,7 @@ func TestFullAndFolderPath(t *testing.T) { env.On("GOOS").Return(tc.GOOS) env.On("StackCount").Return(tc.StackCount) env.On("IsWsl").Return(false) - args := &environment.Flags{ + args := &platform.Flags{ PSWD: tc.Pswd, } env.On("Flags").Return(args) @@ -843,7 +843,7 @@ func TestFullPathCustomMappedLocations(t *testing.T) { Expected string }{ {Pwd: "/a/b/c/d", MappedLocations: map[string]string{"/a/b/c/d": "#"}, Expected: "#"}, - {Pwd: "\\a\\b\\c\\d", MappedLocations: map[string]string{"\\a\\b": "#"}, GOOS: environment.WINDOWS, PathSeparator: "\\", Expected: "#\\c\\d"}, + {Pwd: "\\a\\b\\c\\d", MappedLocations: map[string]string{"\\a\\b": "#"}, GOOS: platform.WINDOWS, PathSeparator: "\\", Expected: "#\\c\\d"}, {Pwd: "/a/b/c/d", MappedLocations: map[string]string{"/a/b": "#"}, Expected: "#/c/d"}, {Pwd: "/a/b/c/d", MappedLocations: map[string]string{"/a/b": "/e/f"}, Expected: "/e/f/c/d"}, {Pwd: homeDir + "/a/b/c/d", MappedLocations: map[string]string{"~/a/b": "#"}, Expected: "#/c/d"}, @@ -856,14 +856,14 @@ func TestFullPathCustomMappedLocations(t *testing.T) { env.On("Home").Return(homeDir) env.On("Pwd").Return(tc.Pwd) if tc.GOOS == "" { - tc.GOOS = environment.DARWIN + tc.GOOS = platform.DARWIN } env.On("GOOS").Return(tc.GOOS) if tc.PathSeparator == "" { tc.PathSeparator = "/" } env.On("PathSeparator").Return(tc.PathSeparator) - args := &environment.Flags{ + args := &platform.Flags{ PSWD: tc.Pwd, } env.On("Flags").Return(args) @@ -890,7 +890,7 @@ func TestFolderPathCustomMappedLocations(t *testing.T) { env.On("Home").Return(homeDir) env.On("Pwd").Return(pwd) env.On("GOOS").Return("") - args := &environment.Flags{ + args := &platform.Flags{ PSWD: pwd, } env.On("Flags").Return(args) @@ -924,7 +924,7 @@ func TestAgnosterPath(t *testing.T) { Expected: "\uf013 > f > magnetic:TOAST", Home: homeDirWindows, PWD: "HKLM:\\SOFTWARE\\magnetic:TOAST\\", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", }, { @@ -932,7 +932,7 @@ func TestAgnosterPath(t *testing.T) { Expected: "C: > f > f > location", Home: homeDirWindows, PWD: "C:\\Program Files\\Go\\location", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", }, { @@ -940,7 +940,7 @@ func TestAgnosterPath(t *testing.T) { Expected: "~ > f > f > location", Home: homeDirWindows, PWD: homeDirWindows + "\\Documents\\Bill\\location", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", }, { @@ -948,7 +948,7 @@ func TestAgnosterPath(t *testing.T) { Expected: "C: > location", Home: homeDirWindows, PWD: "C:\\location", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", }, { @@ -956,7 +956,7 @@ func TestAgnosterPath(t *testing.T) { Expected: "C: > f > location", Home: homeDirWindows, PWD: "C:\\Program Files\\location", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", }, { @@ -964,7 +964,7 @@ func TestAgnosterPath(t *testing.T) { Expected: "C: > Windows", Home: homeDirWindows, PWD: "C:\\Windows\\", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", }, { @@ -972,7 +972,7 @@ func TestAgnosterPath(t *testing.T) { Expected: "P: > Other", Home: homeDirWindows, PWD: "P:\\Other\\", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", }, { @@ -980,7 +980,7 @@ func TestAgnosterPath(t *testing.T) { Expected: "some: > some", Home: homeDirWindows, PWD: "some:\\some\\", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", }, { @@ -988,7 +988,7 @@ func TestAgnosterPath(t *testing.T) { Expected: "src: > source", Home: homeDirWindows, PWD: "src:\\source\\", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", }, { @@ -996,7 +996,7 @@ func TestAgnosterPath(t *testing.T) { Expected: "sRc: > source", Home: homeDirWindows, PWD: "sRc:\\source\\", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", }, { @@ -1004,7 +1004,7 @@ func TestAgnosterPath(t *testing.T) { Expected: "\uf013 > f > magnetic:test", Home: homeDirWindows, PWD: "HKLM:\\SOFTWARE\\magnetic:test\\", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", }, { @@ -1043,7 +1043,7 @@ func TestAgnosterPath(t *testing.T) { env.On("PathSeparator").Return(tc.PathSeparator) env.On("Pwd").Return(tc.PWD) env.On("GOOS").Return(tc.GOOS) - args := &environment.Flags{ + args := &platform.Flags{ PSWD: tc.PWD, } env.On("Flags").Return(args) @@ -1078,7 +1078,7 @@ func TestAgnosterLeftPath(t *testing.T) { Expected: "~ > Documents > f > f", Home: homeDirWindows, PWD: homeDirWindows + "\\Documents\\Bill\\location", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", }, { @@ -1086,7 +1086,7 @@ func TestAgnosterLeftPath(t *testing.T) { Expected: "C: > Program Files > f > f", Home: homeDirWindows, PWD: "C:\\Program Files\\Go\\location", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", }, { @@ -1094,7 +1094,7 @@ func TestAgnosterLeftPath(t *testing.T) { Expected: "C: > location", Home: homeDirWindows, PWD: "C:\\location", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", }, { @@ -1102,7 +1102,7 @@ func TestAgnosterLeftPath(t *testing.T) { Expected: "C: > Program Files > f", Home: homeDirWindows, PWD: "C:\\Program Files\\location", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", }, { @@ -1110,7 +1110,7 @@ func TestAgnosterLeftPath(t *testing.T) { Expected: "C: > Windows", Home: homeDirWindows, PWD: "C:\\Windows\\", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", }, { @@ -1118,7 +1118,7 @@ func TestAgnosterLeftPath(t *testing.T) { Expected: "P: > Other", Home: homeDirWindows, PWD: "P:\\Other\\", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", }, { @@ -1126,7 +1126,7 @@ func TestAgnosterLeftPath(t *testing.T) { Expected: "some: > some", Home: homeDirWindows, PWD: "some:\\some\\", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", }, { @@ -1134,7 +1134,7 @@ func TestAgnosterLeftPath(t *testing.T) { Expected: "src: > source", Home: homeDirWindows, PWD: "src:\\source\\", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", }, { @@ -1142,7 +1142,7 @@ func TestAgnosterLeftPath(t *testing.T) { Expected: "sRc: > source", Home: homeDirWindows, PWD: "sRc:\\source\\", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", }, { @@ -1150,7 +1150,7 @@ func TestAgnosterLeftPath(t *testing.T) { Expected: "\uf013 > SOFTWARE > f", Home: homeDirWindows, PWD: "HKLM:\\SOFTWARE\\magnetic:test\\", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", }, { @@ -1158,7 +1158,7 @@ func TestAgnosterLeftPath(t *testing.T) { Expected: "\uf013 > SOFTWARE > f", Home: homeDirWindows, PWD: "HKLM:\\SOFTWARE\\magnetic:TOAST\\", - GOOS: environment.WINDOWS, + GOOS: platform.WINDOWS, PathSeparator: "\\", }, { @@ -1197,7 +1197,7 @@ func TestAgnosterLeftPath(t *testing.T) { env.On("PathSeparator").Return(tc.PathSeparator) env.On("Pwd").Return(tc.PWD) env.On("GOOS").Return(tc.GOOS) - args := &environment.Flags{ + args := &platform.Flags{ PSWD: tc.PWD, } env.On("Flags").Return(args) @@ -1250,7 +1250,7 @@ func TestGetPwd(t *testing.T) { env.On("Home").Return(homeDir) env.On("Pwd").Return(tc.Pwd) env.On("GOOS").Return("") - args := &environment.Flags{ + args := &platform.Flags{ PSWD: tc.Pswd, } env.On("Flags").Return(args) @@ -1297,7 +1297,7 @@ func TestGetFolderSeparator(t *testing.T) { if len(tc.FolderSeparatorIcon) > 0 { props[FolderSeparatorIcon] = tc.FolderSeparatorIcon } - env.On("TemplateCache").Return(&environment.TemplateCache{ + env.On("TemplateCache").Return(&platform.TemplateCache{ Env: make(map[string]string), Shell: "bash", }) @@ -1314,14 +1314,14 @@ func TestNormalizePath(t *testing.T) { GOOS string Expected string }{ - {Input: "/foo/~/bar", HomeDir: homeDirWindows, GOOS: environment.WINDOWS, Expected: "\\foo\\~\\bar"}, - {Input: homeDirWindows + "\\Foo", HomeDir: homeDirWindows, GOOS: environment.WINDOWS, Expected: "c:\\users\\someone\\foo"}, - {Input: "~/Bob\\Foo", HomeDir: homeDir, GOOS: environment.LINUX, Expected: homeDir + "/Bob\\Foo"}, - {Input: "~/Bob\\Foo", HomeDir: homeDir, GOOS: environment.DARWIN, Expected: homeDir + "/bob\\foo"}, - {Input: "~\\Bob\\Foo", HomeDir: homeDirWindows, GOOS: environment.WINDOWS, Expected: "c:\\users\\someone\\bob\\foo"}, - {Input: "/foo/~/bar", HomeDir: homeDir, GOOS: environment.LINUX, Expected: "/foo/~/bar"}, - {Input: "~/baz", HomeDir: homeDir, GOOS: environment.LINUX, Expected: homeDir + "/baz"}, - {Input: "~/baz", HomeDir: homeDirWindows, GOOS: environment.WINDOWS, Expected: "c:\\users\\someone\\baz"}, + {Input: "/foo/~/bar", HomeDir: homeDirWindows, GOOS: platform.WINDOWS, Expected: "\\foo\\~\\bar"}, + {Input: homeDirWindows + "\\Foo", HomeDir: homeDirWindows, GOOS: platform.WINDOWS, Expected: "c:\\users\\someone\\foo"}, + {Input: "~/Bob\\Foo", HomeDir: homeDir, GOOS: platform.LINUX, Expected: homeDir + "/Bob\\Foo"}, + {Input: "~/Bob\\Foo", HomeDir: homeDir, GOOS: platform.DARWIN, Expected: homeDir + "/bob\\foo"}, + {Input: "~\\Bob\\Foo", HomeDir: homeDirWindows, GOOS: platform.WINDOWS, Expected: "c:\\users\\someone\\bob\\foo"}, + {Input: "/foo/~/bar", HomeDir: homeDir, GOOS: platform.LINUX, Expected: "/foo/~/bar"}, + {Input: "~/baz", HomeDir: homeDir, GOOS: platform.LINUX, Expected: homeDir + "/baz"}, + {Input: "~/baz", HomeDir: homeDirWindows, GOOS: platform.WINDOWS, Expected: "c:\\users\\someone\\baz"}, } for _, tc := range cases { @@ -1353,7 +1353,7 @@ func TestReplaceMappedLocations(t *testing.T) { env.On("PathSeparator").Return("/") env.On("Pwd").Return(tc.Pwd) env.On("Shell").Return(shell.FISH) - env.On("GOOS").Return(environment.DARWIN) + env.On("GOOS").Return(platform.DARWIN) path := &Path{ env: env, props: properties.Map{ diff --git a/src/segments/perl.go b/src/segments/perl.go index 1818d3c8..46248f3f 100644 --- a/src/segments/perl.go +++ b/src/segments/perl.go @@ -1,7 +1,7 @@ package segments import ( - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" ) @@ -13,7 +13,7 @@ func (p *Perl) Template() string { return languageTemplate } -func (p *Perl) Init(props properties.Properties, env environment.Environment) { +func (p *Perl) Init(props properties.Properties, env platform.Environment) { perlRegex := `This is perl.*v(?P(?P[0-9]+)(?:\.(?P[0-9]+))(?:\.(?P[0-9]+))?).* built for .+` p.language = language{ env: env, diff --git a/src/segments/php.go b/src/segments/php.go index 536595da..a2ce745a 100644 --- a/src/segments/php.go +++ b/src/segments/php.go @@ -1,7 +1,7 @@ package segments import ( - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" ) @@ -13,7 +13,7 @@ func (p *Php) Template() string { return languageTemplate } -func (p *Php) Init(props properties.Properties, env environment.Environment) { +func (p *Php) Init(props properties.Properties, env platform.Environment) { p.language = language{ env: env, props: props, diff --git a/src/segments/plastic.go b/src/segments/plastic.go index 9be8c8b5..5eccc1a1 100644 --- a/src/segments/plastic.go +++ b/src/segments/plastic.go @@ -2,7 +2,7 @@ package segments import ( "fmt" - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" "oh-my-posh/regex" "strconv" @@ -37,7 +37,7 @@ type Plastic struct { plasticWorkspaceFolder string // root folder of workspace } -func (p *Plastic) Init(props properties.Properties, env environment.Environment) { +func (p *Plastic) Init(props properties.Properties, env platform.Environment) { p.props = props p.env = env } diff --git a/src/segments/plastic_test.go b/src/segments/plastic_test.go index d6758335..fcaa6ea4 100644 --- a/src/segments/plastic_test.go +++ b/src/segments/plastic_test.go @@ -1,8 +1,8 @@ package segments import ( - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "oh-my-posh/properties" "testing" @@ -29,7 +29,7 @@ func TestPlasticEnabledInWorkspaceDirectory(t *testing.T) { env.On("GOOS").Return("") env.On("IsWsl").Return(false) env.On("FileContent", "/dir/.plastic//plastic.selector").Return("") - fileInfo := &environment.FileInfo{ + fileInfo := &platform.FileInfo{ Path: "/dir/hello", ParentFolder: "/dir", IsDir: true, diff --git a/src/segments/posh_git_test.go b/src/segments/posh_git_test.go index 16a5d76e..cc7fbcad 100644 --- a/src/segments/posh_git_test.go +++ b/src/segments/posh_git_test.go @@ -1,8 +1,8 @@ package segments import ( - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "oh-my-posh/properties" "testing" @@ -184,7 +184,7 @@ func TestPoshGitSegment(t *testing.T) { env := new(mock.MockedEnvironment) env.On("Getenv", poshGitEnv).Return(tc.PoshGitJSON) env.On("Home").Return("/Users/bill") - env.On("GOOS").Return(environment.LINUX) + env.On("GOOS").Return(platform.LINUX) env.On("RunCommand", "git", []string{"-C", "", "--no-optional-locks", "-c", "core.quotepath=false", "-c", "color.status=false", "remote", "get-url", "origin"}).Return("github.com/cli", nil) g := &Git{ diff --git a/src/segments/project.go b/src/segments/project.go index 0293318a..19e40efc 100644 --- a/src/segments/project.go +++ b/src/segments/project.go @@ -4,7 +4,7 @@ import ( "encoding/json" "encoding/xml" "errors" - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" "oh-my-posh/regex" "path/filepath" @@ -56,7 +56,7 @@ type NuSpec struct { type Project struct { props properties.Properties - env environment.Environment + env platform.Environment projects []*ProjectItem Error string @@ -82,7 +82,7 @@ func (n *Project) Template() string { return " {{ if .Error }}{{ .Error }}{{ else }}{{ if .Version }}\uf487 {{.Version}} {{ end }}{{ if .Name }}{{ .Name }} {{ end }}{{ if .Target }}\uf9fd {{.Target}} {{ end }}{{ end }}" //nolint:lll } -func (n *Project) Init(props properties.Properties, env environment.Environment) { +func (n *Project) Init(props properties.Properties, env platform.Environment) { n.props = props n.env = env diff --git a/src/segments/python.go b/src/segments/python.go index 04dc1174..dc5e54a0 100644 --- a/src/segments/python.go +++ b/src/segments/python.go @@ -3,7 +3,7 @@ package segments import ( "errors" "fmt" - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" "path/filepath" "strings" @@ -25,7 +25,7 @@ func (p *Python) Template() string { return " {{ if .Error }}{{ .Error }}{{ else }}{{ if .Venv }}{{ .Venv }} {{ end }}{{ .Full }}{{ end }} " } -func (p *Python) Init(props properties.Properties, env environment.Environment) { +func (p *Python) Init(props properties.Properties, env platform.Environment) { p.language = language{ env: env, props: props, @@ -74,7 +74,7 @@ func (p *Python) loadContext() { if len(venv) == 0 { continue } - name := environment.Base(p.language.env, venv) + name := platform.Base(p.language.env, venv) if p.canUseVenvName(name) { p.Venv = name break diff --git a/src/segments/python_test.go b/src/segments/python_test.go index 1094496d..9895f84e 100644 --- a/src/segments/python_test.go +++ b/src/segments/python_test.go @@ -2,8 +2,8 @@ package segments import ( "errors" - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "oh-my-posh/properties" "testing" @@ -98,7 +98,7 @@ func TestPythonTemplate(t *testing.T) { UsePythonVersionFile: true, DisplayMode: DisplayModeAlways, } - env.On("TemplateCache").Return(&environment.TemplateCache{ + env.On("TemplateCache").Return(&platform.TemplateCache{ Env: make(map[string]string), }) python := &Python{} @@ -125,7 +125,7 @@ func TestPythonPythonInContext(t *testing.T) { env.On("Getenv", "CONDA_ENV_PATH").Return("") env.On("Getenv", "CONDA_DEFAULT_ENV").Return("") env.On("Getenv", "PYENV_VERSION").Return("") - env.On("HasParentFilePath", ".python-version").Return(&environment.FileInfo{}, errors.New("no match at root level")) + env.On("HasParentFilePath", ".python-version").Return(&platform.FileInfo{}, errors.New("no match at root level")) python := &Python{} python.Init(properties.Map{}, env) python.loadContext() diff --git a/src/segments/r.go b/src/segments/r.go index 547adaf0..4bb3ba5f 100644 --- a/src/segments/r.go +++ b/src/segments/r.go @@ -1,7 +1,7 @@ package segments import ( - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" ) @@ -13,7 +13,7 @@ func (r *R) Template() string { return languageTemplate } -func (r *R) Init(props properties.Properties, env environment.Environment) { +func (r *R) Init(props properties.Properties, env platform.Environment) { rRegex := `version (?P((?P[0-9]+).(?P[0-9]+).(?P[0-9]+)))` r.language = language{ env: env, diff --git a/src/segments/r_test.go b/src/segments/r_test.go index a1403c80..19720075 100644 --- a/src/segments/r_test.go +++ b/src/segments/r_test.go @@ -2,8 +2,8 @@ package segments import ( "fmt" - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "oh-my-posh/properties" "testing" @@ -44,7 +44,7 @@ func TestR(t *testing.T) { env.On("HasFiles", "*.R").Return(true) env.On("Pwd").Return("/usr/home/project") env.On("Home").Return("/usr/home") - env.On("TemplateCache").Return(&environment.TemplateCache{ + env.On("TemplateCache").Return(&platform.TemplateCache{ Env: make(map[string]string), }) props := properties.Map{ diff --git a/src/segments/root.go b/src/segments/root.go index 543e7f88..2680770a 100644 --- a/src/segments/root.go +++ b/src/segments/root.go @@ -1,13 +1,13 @@ package segments import ( - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" ) type Root struct { props properties.Properties - env environment.Environment + env platform.Environment } func (rt *Root) Template() string { @@ -18,7 +18,7 @@ func (rt *Root) Enabled() bool { return rt.env.Root() } -func (rt *Root) Init(props properties.Properties, env environment.Environment) { +func (rt *Root) Init(props properties.Properties, env platform.Environment) { rt.props = props rt.env = env } diff --git a/src/segments/ruby.go b/src/segments/ruby.go index 7e6c0d99..142b5047 100644 --- a/src/segments/ruby.go +++ b/src/segments/ruby.go @@ -1,7 +1,7 @@ package segments import ( - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" ) @@ -13,7 +13,7 @@ func (r *Ruby) Template() string { return languageTemplate } -func (r *Ruby) Init(props properties.Properties, env environment.Environment) { +func (r *Ruby) Init(props properties.Properties, env platform.Environment) { r.language = language{ env: env, props: props, diff --git a/src/segments/rust.go b/src/segments/rust.go index 0fd89ae1..c332dfea 100644 --- a/src/segments/rust.go +++ b/src/segments/rust.go @@ -1,7 +1,7 @@ package segments import ( - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" ) @@ -13,7 +13,7 @@ func (r *Rust) Template() string { return languageTemplate } -func (r *Rust) Init(props properties.Properties, env environment.Environment) { +func (r *Rust) Init(props properties.Properties, env platform.Environment) { r.language = language{ env: env, props: props, diff --git a/src/segments/scm.go b/src/segments/scm.go index 0853e054..fe14f0ff 100644 --- a/src/segments/scm.go +++ b/src/segments/scm.go @@ -2,7 +2,7 @@ package segments import ( "fmt" - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" "strings" ) @@ -47,7 +47,7 @@ func (s *ScmStatus) String() string { type scm struct { props properties.Properties - env environment.Environment + env platform.Environment IsWslSharedPath bool CommandMissing bool @@ -68,7 +68,7 @@ const ( FullBranchPath properties.Property = "full_branch_path" ) -func (s *scm) Init(props properties.Properties, env environment.Environment) { +func (s *scm) Init(props properties.Properties, env platform.Environment) { s.props = props s.env = env } @@ -100,7 +100,7 @@ func (s *scm) FileContents(folder, file string) string { } func (s *scm) convertToWindowsPath(path string) string { - if s.env.GOOS() == environment.WINDOWS || s.IsWslSharedPath { + if s.env.GOOS() == platform.WINDOWS || s.IsWslSharedPath { return s.env.ConvertToWindowsPath(path) } return path @@ -120,7 +120,7 @@ func (s *scm) hasCommand(command string) bool { // when in a WSL shared folder, we must use command.exe and convert paths accordingly // for worktrees, stashes, and path to work s.IsWslSharedPath = s.env.InWSLSharedDrive() - if s.env.GOOS() == environment.WINDOWS || s.IsWslSharedPath { + if s.env.GOOS() == platform.WINDOWS || s.IsWslSharedPath { command += ".exe" } if s.env.HasCommand(command) { diff --git a/src/segments/scm_test.go b/src/segments/scm_test.go index b0d89868..f8b97200 100644 --- a/src/segments/scm_test.go +++ b/src/segments/scm_test.go @@ -1,8 +1,8 @@ package segments import ( - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "oh-my-posh/properties" "testing" @@ -166,7 +166,7 @@ func TestHasCommand(t *testing.T) { IsWslSharedPath bool NativeFallback bool }{ - {Case: "On Windows", ExpectedCommand: "git.exe", GOOS: environment.WINDOWS}, + {Case: "On Windows", ExpectedCommand: "git.exe", GOOS: platform.WINDOWS}, {Case: "Cache", ExpectedCommand: "git.exe", Command: "git.exe"}, {Case: "Non Windows", ExpectedCommand: "git"}, {Case: "Iside WSL2, non shared", ExpectedCommand: "git"}, diff --git a/src/segments/session.go b/src/segments/session.go index a67ca777..006e7659 100644 --- a/src/segments/session.go +++ b/src/segments/session.go @@ -1,13 +1,13 @@ package segments import ( - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" ) type Session struct { props properties.Properties - env environment.Environment + env platform.Environment // text string SSHSession bool @@ -25,7 +25,7 @@ func (s *Session) Template() string { return " {{ if .SSHSession }}\uf817 {{ end }}{{ .UserName }}@{{ .HostName }} " } -func (s *Session) Init(props properties.Properties, env environment.Environment) { +func (s *Session) Init(props properties.Properties, env platform.Environment) { s.props = props s.env = env } diff --git a/src/segments/session_test.go b/src/segments/session_test.go index 1fd406cb..ab9d0eac 100644 --- a/src/segments/session_test.go +++ b/src/segments/session_test.go @@ -1,8 +1,8 @@ package segments import ( - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "oh-my-posh/properties" "testing" @@ -99,7 +99,7 @@ func TestSessionSegmentTemplate(t *testing.T) { } env.On("Getenv", "SSH_CONNECTION").Return(SSHSession) env.On("Getenv", "SSH_CLIENT").Return(SSHSession) - env.On("TemplateCache").Return(&environment.TemplateCache{ + env.On("TemplateCache").Return(&platform.TemplateCache{ UserName: tc.UserName, HostName: tc.ComputerName, Env: map[string]string{ diff --git a/src/segments/shell.go b/src/segments/shell.go index cc6558ae..83e1fa83 100644 --- a/src/segments/shell.go +++ b/src/segments/shell.go @@ -1,14 +1,14 @@ package segments import ( - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" "strings" ) type Shell struct { props properties.Properties - env environment.Environment + env platform.Environment Name string Version string @@ -36,7 +36,7 @@ func (s *Shell) Enabled() bool { return true } -func (s *Shell) Init(props properties.Properties, env environment.Environment) { +func (s *Shell) Init(props properties.Properties, env platform.Environment) { s.props = props s.env = env } diff --git a/src/segments/shell_test.go b/src/segments/shell_test.go index 7bd816a3..2e268b97 100644 --- a/src/segments/shell_test.go +++ b/src/segments/shell_test.go @@ -1,8 +1,8 @@ package segments import ( - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "oh-my-posh/properties" "testing" @@ -13,7 +13,7 @@ func TestWriteCurrentShell(t *testing.T) { expected := "zsh" env := new(mock.MockedEnvironment) env.On("Shell").Return(expected, nil) - env.On("Flags").Return(&environment.Flags{ShellVersion: "1.2.3"}) + env.On("Flags").Return(&platform.Flags{ShellVersion: "1.2.3"}) s := &Shell{ env: env, props: properties.Map{}, @@ -34,7 +34,7 @@ func TestUseMappedShellNames(t *testing.T) { for _, tc := range cases { env := new(mock.MockedEnvironment) env.On("Shell").Return(tc.Expected, nil) - env.On("Flags").Return(&environment.Flags{ShellVersion: "1.2.3"}) + env.On("Flags").Return(&platform.Flags{ShellVersion: "1.2.3"}) s := &Shell{ env: env, props: properties.Map{ diff --git a/src/segments/spotify.go b/src/segments/spotify.go index a5032232..413326f6 100644 --- a/src/segments/spotify.go +++ b/src/segments/spotify.go @@ -1,13 +1,13 @@ package segments import ( - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" ) type Spotify struct { props properties.Properties - env environment.Environment + env platform.Environment MusicPlayer } @@ -48,7 +48,7 @@ func (s *Spotify) resolveIcon() { } } -func (s *Spotify) Init(props properties.Properties, env environment.Environment) { +func (s *Spotify) Init(props properties.Properties, env platform.Environment) { s.props = props s.env = env } diff --git a/src/segments/spotify_windows_test.go b/src/segments/spotify_windows_test.go index a100d766..3f999cb4 100644 --- a/src/segments/spotify_windows_test.go +++ b/src/segments/spotify_windows_test.go @@ -3,8 +3,8 @@ package segments import ( - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "oh-my-posh/properties" "testing" @@ -40,7 +40,7 @@ func TestSpotifyWindowsNative(t *testing.T) { for _, tc := range cases { env := new(mock.MockedEnvironment) env.On("QueryWindowTitles", "spotify.exe", `^(Spotify.*)|(.*\s-\s.*)$`).Return(tc.Title, tc.Error) - env.On("QueryWindowTitles", "msedge.exe", `^(Spotify.*)`).Return("", &environment.NotImplemented{}) + env.On("QueryWindowTitles", "msedge.exe", `^(Spotify.*)`).Return("", &platform.NotImplemented{}) s := &Spotify{ env: env, props: properties.Map{}, @@ -74,7 +74,7 @@ func TestSpotifyWindowsPWA(t *testing.T) { } for _, tc := range cases { env := new(mock.MockedEnvironment) - env.On("QueryWindowTitles", "spotify.exe", "^(Spotify.*)|(.*\\s-\\s.*)$").Return("", &environment.NotImplemented{}) + env.On("QueryWindowTitles", "spotify.exe", "^(Spotify.*)|(.*\\s-\\s.*)$").Return("", &platform.NotImplemented{}) env.On("QueryWindowTitles", "msedge.exe", "^(Spotify.*)").Return(tc.Title, tc.Error) s := &Spotify{ env: env, diff --git a/src/segments/strava.go b/src/segments/strava.go index 7f839208..e578f529 100644 --- a/src/segments/strava.go +++ b/src/segments/strava.go @@ -3,8 +3,8 @@ package segments import ( "fmt" "math" - "oh-my-posh/environment" "oh-my-posh/http" + "oh-my-posh/platform" "oh-my-posh/properties" "time" ) @@ -125,7 +125,7 @@ func (s *Strava) getActivityIcon() string { return s.props.GetString(UnknownActivityIcon, "\ue213") } -func (s *Strava) Init(props properties.Properties, env environment.Environment) { +func (s *Strava) Init(props properties.Properties, env platform.Environment) { s.props = props oauth := &http.OAuthRequest{ diff --git a/src/segments/svn_test.go b/src/segments/svn_test.go index ccbea01f..fdc5e7e7 100644 --- a/src/segments/svn_test.go +++ b/src/segments/svn_test.go @@ -1,8 +1,8 @@ package segments import ( - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "oh-my-posh/properties" "testing" @@ -25,7 +25,7 @@ func TestSvnEnabledToolNotFound(t *testing.T) { } func TestSvnEnabledInWorkingDirectory(t *testing.T) { - fileInfo := &environment.FileInfo{ + fileInfo := &platform.FileInfo{ Path: "/dir/hello", ParentFolder: "/dir", IsDir: true, @@ -215,7 +215,7 @@ R Moved.File`, }, } for _, tc := range cases { - fileInfo := &environment.FileInfo{ + fileInfo := &platform.FileInfo{ Path: "/dir/hello", ParentFolder: "/dir", IsDir: true, diff --git a/src/segments/swift.go b/src/segments/swift.go index ebb99f01..5cb535eb 100644 --- a/src/segments/swift.go +++ b/src/segments/swift.go @@ -1,7 +1,7 @@ package segments import ( - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" ) @@ -13,7 +13,7 @@ func (s *Swift) Template() string { return languageTemplate } -func (s *Swift) Init(props properties.Properties, env environment.Environment) { +func (s *Swift) Init(props properties.Properties, env platform.Environment) { s.language = language{ env: env, props: props, diff --git a/src/segments/sysinfo.go b/src/segments/sysinfo.go index 931b3e6e..9e21d811 100644 --- a/src/segments/sysinfo.go +++ b/src/segments/sysinfo.go @@ -1,7 +1,7 @@ package segments import ( - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" cpu "github.com/shirou/gopsutil/v3/cpu" @@ -12,7 +12,7 @@ import ( type SystemInfo struct { props properties.Properties - env environment.Environment + env platform.Environment Precision int // mem @@ -50,7 +50,7 @@ func (s *SystemInfo) Enabled() bool { return true } -func (s *SystemInfo) Init(props properties.Properties, env environment.Environment) { +func (s *SystemInfo) Init(props properties.Properties, env platform.Environment) { s.props = props s.env = env s.Precision = s.props.GetInt(Precision, 2) diff --git a/src/segments/terraform.go b/src/segments/terraform.go index 366a94ca..1d0dee01 100644 --- a/src/segments/terraform.go +++ b/src/segments/terraform.go @@ -3,7 +3,7 @@ package segments import ( "encoding/json" "errors" - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" "path/filepath" @@ -13,7 +13,7 @@ import ( type Terraform struct { props properties.Properties - env environment.Environment + env platform.Environment WorkspaceName string TerraformBlock @@ -23,7 +23,7 @@ func (tf *Terraform) Template() string { return " {{ .WorkspaceName }}{{ if .Version }} {{ .Version }}{{ end }} " } -func (tf *Terraform) Init(props properties.Properties, env environment.Environment) { +func (tf *Terraform) Init(props properties.Properties, env platform.Environment) { tf.props = props tf.env = env } diff --git a/src/segments/text.go b/src/segments/text.go index 6de1ca6e..fb72f330 100644 --- a/src/segments/text.go +++ b/src/segments/text.go @@ -1,13 +1,13 @@ package segments import ( - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" ) type Text struct { props properties.Properties - env environment.Environment + env platform.Environment } func (t *Text) Template() string { @@ -18,7 +18,7 @@ func (t *Text) Enabled() bool { return true } -func (t *Text) Init(props properties.Properties, env environment.Environment) { +func (t *Text) Init(props properties.Properties, env platform.Environment) { t.props = props t.env = env } diff --git a/src/segments/text_test.go b/src/segments/text_test.go index 659d1a22..8a5f352d 100644 --- a/src/segments/text_test.go +++ b/src/segments/text_test.go @@ -1,8 +1,8 @@ package segments import ( - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "testing" "github.com/stretchr/testify/assert" @@ -27,7 +27,7 @@ func TestTextSegment(t *testing.T) { for _, tc := range cases { env := new(mock.MockedEnvironment) env.On("PathSeparator").Return("/") - env.On("TemplateCache").Return(&environment.TemplateCache{ + env.On("TemplateCache").Return(&platform.TemplateCache{ UserName: "Posh", Env: map[string]string{ "HELLO": "hello", diff --git a/src/segments/time.go b/src/segments/time.go index 19f22e5f..689dc449 100644 --- a/src/segments/time.go +++ b/src/segments/time.go @@ -1,14 +1,14 @@ package segments import ( - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" "time" ) type Time struct { props properties.Properties - env environment.Environment + env platform.Environment CurrentDate time.Time Format string @@ -32,7 +32,7 @@ func (t *Time) Enabled() bool { return true } -func (t *Time) Init(props properties.Properties, env environment.Environment) { +func (t *Time) Init(props properties.Properties, env platform.Environment) { t.props = props t.env = env } diff --git a/src/segments/ui5tooling.go b/src/segments/ui5tooling.go index ccd920ac..47541d12 100644 --- a/src/segments/ui5tooling.go +++ b/src/segments/ui5tooling.go @@ -1,7 +1,7 @@ package segments import ( - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" ) @@ -16,7 +16,7 @@ func (u *UI5Tooling) Template() string { return languageTemplate } -func (u *UI5Tooling) Init(props properties.Properties, env environment.Environment) { +func (u *UI5Tooling) Init(props properties.Properties, env platform.Environment) { u.language = language{ env: env, props: props, diff --git a/src/segments/ui5tooling_test.go b/src/segments/ui5tooling_test.go index 6af56631..60c45f5a 100644 --- a/src/segments/ui5tooling_test.go +++ b/src/segments/ui5tooling_test.go @@ -2,8 +2,8 @@ package segments import ( "fmt" - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "oh-my-posh/properties" "path/filepath" "testing" @@ -131,7 +131,7 @@ func prepareMockedEnvironment(tc *testCase) *mock.MockedEnvironment { env.On("Home").Return("/home/user") env.On("Pwd").Return(WorkingDirRoot) - env.On("TemplateCache").Return(&environment.TemplateCache{ + env.On("TemplateCache").Return(&platform.TemplateCache{ Env: make(map[string]string), }) diff --git a/src/segments/wakatime.go b/src/segments/wakatime.go index ac4420cb..21b4d095 100644 --- a/src/segments/wakatime.go +++ b/src/segments/wakatime.go @@ -2,14 +2,14 @@ package segments import ( "encoding/json" - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" "oh-my-posh/template" ) type Wakatime struct { props properties.Properties - env environment.Environment + env platform.Environment wtData } @@ -78,7 +78,7 @@ func (w *Wakatime) getURL() (string, error) { return tmpl.Render() } -func (w *Wakatime) Init(props properties.Properties, env environment.Environment) { +func (w *Wakatime) Init(props properties.Properties, env platform.Environment) { w.props = props w.env = env } diff --git a/src/segments/wakatime_test.go b/src/segments/wakatime_test.go index cd8071d7..7c212e2a 100644 --- a/src/segments/wakatime_test.go +++ b/src/segments/wakatime_test.go @@ -3,8 +3,8 @@ package segments import ( "errors" "fmt" - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "oh-my-posh/properties" "testing" @@ -82,7 +82,7 @@ func TestWTTrackedTime(t *testing.T) { cache.On("Set", FAKEAPIURL, response, tc.CacheTimeout).Return() env.On("Cache").Return(cache) - env.On("TemplateCache").Return(&environment.TemplateCache{ + env.On("TemplateCache").Return(&platform.TemplateCache{ Env: map[string]string{"HELLO": "hello"}, }) @@ -127,7 +127,7 @@ func TestWTGetUrl(t *testing.T) { env := &mock.MockedEnvironment{} env.On("Log", mock2.Anything, mock2.Anything, mock2.Anything) - env.On("TemplateCache").Return(&environment.TemplateCache{ + env.On("TemplateCache").Return(&platform.TemplateCache{ Env: map[string]string{"HELLO": "hello"}, }) diff --git a/src/segments/winreg.go b/src/segments/winreg.go index 20ebf6e1..9adec2db 100644 --- a/src/segments/winreg.go +++ b/src/segments/winreg.go @@ -1,13 +1,13 @@ package segments import ( - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" ) type WindowsRegistry struct { props properties.Properties - env environment.Environment + env platform.Environment Value string } @@ -23,13 +23,13 @@ func (wr *WindowsRegistry) Template() string { return " {{ .Value }} " } -func (wr *WindowsRegistry) Init(props properties.Properties, env environment.Environment) { +func (wr *WindowsRegistry) Init(props properties.Properties, env platform.Environment) { wr.props = props wr.env = env } func (wr *WindowsRegistry) Enabled() bool { - if wr.env.GOOS() != environment.WINDOWS { + if wr.env.GOOS() != platform.WINDOWS { return false } diff --git a/src/segments/winreg_test.go b/src/segments/winreg_test.go index 2e1ffbfa..2388bb8f 100644 --- a/src/segments/winreg_test.go +++ b/src/segments/winreg_test.go @@ -2,8 +2,8 @@ package segments import ( "errors" - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "oh-my-posh/properties" "testing" @@ -17,7 +17,7 @@ func TestWinReg(t *testing.T) { Fallback string ExpectedSuccess bool ExpectedValue string - getWRKVOutput *environment.WindowsRegistryValue + getWRKVOutput *platform.WindowsRegistryValue Err error }{ { @@ -29,7 +29,7 @@ func TestWinReg(t *testing.T) { { CaseDescription: "Value", Path: "HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\InstallTime", - getWRKVOutput: &environment.WindowsRegistryValue{ValueType: environment.STRING, String: "xbox"}, + getWRKVOutput: &platform.WindowsRegistryValue{ValueType: platform.STRING, String: "xbox"}, ExpectedSuccess: true, ExpectedValue: "xbox", }, @@ -44,7 +44,7 @@ func TestWinReg(t *testing.T) { { CaseDescription: "Empty string value (no error) should display empty string even in presence of fallback", Path: "HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\InstallTime", - getWRKVOutput: &environment.WindowsRegistryValue{ValueType: environment.STRING, String: ""}, + getWRKVOutput: &platform.WindowsRegistryValue{ValueType: platform.STRING, String: ""}, Fallback: "anaconda", ExpectedSuccess: true, ExpectedValue: "", @@ -52,7 +52,7 @@ func TestWinReg(t *testing.T) { { CaseDescription: "Empty string value (no error) should display empty string", Path: "HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\InstallTime", - getWRKVOutput: &environment.WindowsRegistryValue{ValueType: environment.STRING, String: ""}, + getWRKVOutput: &platform.WindowsRegistryValue{ValueType: platform.STRING, String: ""}, ExpectedSuccess: true, ExpectedValue: "", }, @@ -60,7 +60,7 @@ func TestWinReg(t *testing.T) { for _, tc := range cases { env := new(mock.MockedEnvironment) - env.On("GOOS").Return(environment.WINDOWS) + env.On("GOOS").Return(platform.WINDOWS) env.On("WindowsRegistryKeyValue", tc.Path).Return(tc.getWRKVOutput, tc.Err) r := &WindowsRegistry{ env: env, diff --git a/src/segments/withings.go b/src/segments/withings.go index 97a1df91..655e3906 100644 --- a/src/segments/withings.go +++ b/src/segments/withings.go @@ -4,8 +4,8 @@ import ( "errors" "fmt" "math" - "oh-my-posh/environment" "oh-my-posh/http" + "oh-my-posh/platform" "oh-my-posh/properties" "strconv" "strings" @@ -216,7 +216,7 @@ func (w *Withings) getSleep() bool { return true } -func (w *Withings) Init(props properties.Properties, env environment.Environment) { +func (w *Withings) Init(props properties.Properties, env platform.Environment) { w.props = props oauth := &http.OAuthRequest{ diff --git a/src/segments/xmake.go b/src/segments/xmake.go index 87773336..6e6a02e6 100644 --- a/src/segments/xmake.go +++ b/src/segments/xmake.go @@ -1,7 +1,7 @@ package segments import ( - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" ) @@ -13,7 +13,7 @@ func (x *XMake) Template() string { return languageTemplate } -func (x *XMake) Init(props properties.Properties, env environment.Environment) { +func (x *XMake) Init(props properties.Properties, env platform.Environment) { x.language = language{ env: env, props: props, diff --git a/src/segments/ytm.go b/src/segments/ytm.go index 9370dfe5..0b2ee3d6 100644 --- a/src/segments/ytm.go +++ b/src/segments/ytm.go @@ -2,13 +2,13 @@ package segments import ( "encoding/json" - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" ) type Ytm struct { props properties.Properties - env environment.Environment + env platform.Environment MusicPlayer } @@ -29,7 +29,7 @@ func (y *Ytm) Enabled() bool { return err == nil } -func (y *Ytm) Init(props properties.Properties, env environment.Environment) { +func (y *Ytm) Init(props properties.Properties, env platform.Environment) { y.props = props y.env = env } diff --git a/src/shell/init.go b/src/shell/init.go index ebc4306b..1be06192 100644 --- a/src/shell/init.go +++ b/src/shell/init.go @@ -6,7 +6,7 @@ import ( "strconv" "fmt" - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/template" "os" "strings" @@ -40,18 +40,18 @@ var ( Tooltips bool ) -func getExecutablePath(env environment.Environment) (string, error) { +func getExecutablePath(env platform.Environment) (string, error) { executable, err := os.Executable() if err != nil { return "", err } if env.Flags().Strict { - return environment.Base(env, executable), nil + return platform.Base(env, executable), nil } // On Windows, it fails when the excutable is called in MSYS2 for example // which uses unix style paths to resolve the executable's location. // PowerShell knows how to resolve both, so we can swap this without any issue. - if env.GOOS() == environment.WINDOWS { + if env.GOOS() == platform.WINDOWS { executable = strings.ReplaceAll(executable, "\\", "/") } return executable, nil @@ -147,7 +147,7 @@ func quoteNuStr(str string) string { return fmt.Sprintf(`"%s"`, strings.NewReplacer(`\`, `\\`, `"`, `\"`).Replace(str)) } -func Init(env environment.Environment) string { +func Init(env platform.Environment) string { shell := env.Flags().Shell switch shell { case PWSH, PWSH5: @@ -174,7 +174,7 @@ func Init(env environment.Environment) string { } } -func PrintInit(env environment.Environment) string { +func PrintInit(env platform.Environment) string { executable, err := getExecutablePath(env) if err != nil { return noExe @@ -228,7 +228,7 @@ func PrintInit(env environment.Environment) string { ).Replace(script) } -func createNuInit(env environment.Environment) { +func createNuInit(env platform.Environment) { initPath := filepath.Join(env.Home(), ".oh-my-posh.nu") f, err := os.OpenFile(initPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755) if err != nil { @@ -241,7 +241,7 @@ func createNuInit(env environment.Environment) { _ = f.Close() } -func ConsoleBackgroundColor(env environment.Environment, backgroundColorTemplate string) string { +func ConsoleBackgroundColor(env platform.Environment, backgroundColorTemplate string) string { if len(backgroundColorTemplate) == 0 { return backgroundColorTemplate } diff --git a/src/shell/init_test.go b/src/shell/init_test.go index 5679878b..286d50e7 100644 --- a/src/shell/init_test.go +++ b/src/shell/init_test.go @@ -2,8 +2,8 @@ package shell import ( "fmt" - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "testing" "github.com/stretchr/testify/assert" @@ -21,7 +21,7 @@ func TestConsoleBackgroundColorTemplate(t *testing.T) { for _, tc := range cases { env := new(mock.MockedEnvironment) - env.On("TemplateCache").Return(&environment.TemplateCache{ + env.On("TemplateCache").Return(&platform.TemplateCache{ Env: map[string]string{ "TERM_PROGRAM": tc.Term, }, diff --git a/src/template/files_test.go b/src/template/files_test.go index 1af6370a..ccab5767 100644 --- a/src/template/files_test.go +++ b/src/template/files_test.go @@ -1,8 +1,8 @@ package template import ( - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "testing" "github.com/stretchr/testify/assert" @@ -21,7 +21,7 @@ func TestGlob(t *testing.T) { } env := &mock.MockedEnvironment{} - env.On("TemplateCache").Return(&environment.TemplateCache{ + env.On("TemplateCache").Return(&platform.TemplateCache{ Env: make(map[string]string), }) for _, tc := range cases { diff --git a/src/template/link_test.go b/src/template/link_test.go index c5bcbb68..e0c067cb 100644 --- a/src/template/link_test.go +++ b/src/template/link_test.go @@ -1,8 +1,8 @@ package template import ( - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "testing" "github.com/stretchr/testify/assert" @@ -21,7 +21,7 @@ func TestUrl(t *testing.T) { } env := &mock.MockedEnvironment{} - env.On("TemplateCache").Return(&environment.TemplateCache{ + env.On("TemplateCache").Return(&platform.TemplateCache{ Env: make(map[string]string), }) env.On("Log", mock2.Anything, mock2.Anything, mock2.Anything) @@ -50,7 +50,7 @@ func TestPath(t *testing.T) { } env := &mock.MockedEnvironment{} - env.On("TemplateCache").Return(&environment.TemplateCache{ + env.On("TemplateCache").Return(&platform.TemplateCache{ Env: make(map[string]string), }) for _, tc := range cases { diff --git a/src/template/list.go b/src/template/list.go index b6c12649..8d686c5f 100644 --- a/src/template/list.go +++ b/src/template/list.go @@ -1,7 +1,7 @@ package template import ( - "oh-my-posh/environment" + "oh-my-posh/platform" "strings" ) @@ -18,7 +18,7 @@ func (l List) Empty() bool { return len(l) == 0 } -func (l List) Resolve(context interface{}, env environment.Environment, defaultValue string, logic Logic) string { +func (l List) Resolve(context interface{}, env platform.Environment, defaultValue string, logic Logic) string { switch logic { case FirstMatch: return l.FirstMatch(context, env, defaultValue) @@ -29,7 +29,7 @@ func (l List) Resolve(context interface{}, env environment.Environment, defaultV } } -func (l List) Join(context interface{}, env environment.Environment) string { +func (l List) Join(context interface{}, env platform.Environment) string { if len(l) == 0 { return "" } @@ -49,7 +49,7 @@ func (l List) Join(context interface{}, env environment.Environment) string { return buffer.String() } -func (l List) FirstMatch(context interface{}, env environment.Environment, defaultValue string) string { +func (l List) FirstMatch(context interface{}, env platform.Environment, defaultValue string) string { if len(l) == 0 { return defaultValue } diff --git a/src/template/round_test.go b/src/template/round_test.go index 7823cd59..a25c8b67 100644 --- a/src/template/round_test.go +++ b/src/template/round_test.go @@ -1,8 +1,8 @@ package template import ( - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "testing" "github.com/stretchr/testify/assert" @@ -28,7 +28,7 @@ func TestRoundSeconds(t *testing.T) { } env := &mock.MockedEnvironment{} - env.On("TemplateCache").Return(&environment.TemplateCache{ + env.On("TemplateCache").Return(&platform.TemplateCache{ Env: make(map[string]string), }) env.On("Log", mock2.Anything, mock2.Anything, mock2.Anything) diff --git a/src/template/text.go b/src/template/text.go index 7ef82842..749a56e6 100644 --- a/src/template/text.go +++ b/src/template/text.go @@ -3,7 +3,7 @@ package template import ( "bytes" "errors" - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/regex" "strings" "text/template" @@ -18,14 +18,14 @@ const ( type Text struct { Template string Context interface{} - Env environment.Environment + Env platform.Environment TemplatesResult string } type Data interface{} type Context struct { - *environment.TemplateCache + *platform.TemplateCache // Simple container to hold ANY object Data @@ -45,7 +45,7 @@ func (t *Text) Render() (string, error) { t.cleanTemplate() tmpl, err := template.New(t.Template).Funcs(funcMap()).Parse(t.Template) if err != nil { - t.Env.Log(environment.Error, "Render", err.Error()) + t.Env.Log(platform.Error, "Render", err.Error()) return "", errors.New(InvalidTemplate) } context := &Context{} @@ -54,7 +54,7 @@ func (t *Text) Render() (string, error) { defer buffer.Reset() err = tmpl.Execute(buffer, context) if err != nil { - t.Env.Log(environment.Error, "Render", err.Error()) + t.Env.Log(platform.Error, "Render", err.Error()) return "", errors.New(IncorrectTemplate) } text := buffer.String() diff --git a/src/template/text_test.go b/src/template/text_test.go index 0e9f379e..7114c2b0 100644 --- a/src/template/text_test.go +++ b/src/template/text_test.go @@ -1,8 +1,8 @@ package template import ( - "oh-my-posh/environment" "oh-my-posh/mock" + "oh-my-posh/platform" "testing" "github.com/stretchr/testify/assert" @@ -144,7 +144,7 @@ func TestRenderTemplate(t *testing.T) { } env := &mock.MockedEnvironment{} - env.On("TemplateCache").Return(&environment.TemplateCache{ + env.On("TemplateCache").Return(&platform.TemplateCache{ Env: make(map[string]string), }) env.On("Log", mock2.Anything, mock2.Anything, mock2.Anything) @@ -201,7 +201,7 @@ func TestRenderTemplateEnvVar(t *testing.T) { } for _, tc := range cases { env := &mock.MockedEnvironment{} - env.On("TemplateCache").Return(&environment.TemplateCache{ + env.On("TemplateCache").Return(&platform.TemplateCache{ Env: tc.Env, }) env.On("Log", mock2.Anything, mock2.Anything, mock2.Anything) diff --git a/website/docs/contributing/segment.mdx b/website/docs/contributing/segment.mdx index b5d02198..8e925eec 100644 --- a/website/docs/contributing/segment.mdx +++ b/website/docs/contributing/segment.mdx @@ -15,13 +15,13 @@ You can use the following template as a guide. package segments import ( - "oh-my-posh/environment" + "oh-my-posh/platform" "oh-my-posh/properties" ) type New struct { props properties.Properties - env environment.Environment + env platform.Environment Text string } @@ -39,7 +39,7 @@ func (n *new) Template() string { return " {{.Text}} world " } -func (n *new) Init(props properties.Properties, env environment.Environment) { +func (n *new) Init(props properties.Properties, env platform.Environment) { n.props = props n.env = env