From 05251e1ac3c8378aa67dcf63d11749a0699f67b1 Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Tue, 2 Jul 2024 12:02:57 +0200 Subject: [PATCH] refactor(platform): rename to runtime --- src/cli/cache.go | 10 +- src/cli/config_export.go | 8 +- src/cli/config_export_image.go | 6 +- src/cli/config_migrate.go | 6 +- src/cli/config_migrate_glyphs.go | 6 +- src/cli/debug.go | 6 +- src/cli/enable.go | 6 +- src/cli/font.go | 4 +- src/cli/get.go | 8 +- src/cli/init.go | 6 +- src/cli/notice.go | 6 +- src/cli/print.go | 4 +- src/cli/toggle.go | 9 +- src/cli/upgrade.go | 16 +- src/color/colors.go | 4 +- src/color/colors_test.go | 4 +- src/color/colors_unix.go | 8 +- src/color/colors_windows.go | 9 +- src/config/block.go | 8 +- src/config/config.go | 4 +- src/config/config_test.go | 4 +- src/config/default.go | 4 +- src/config/load.go | 10 +- src/config/migrate.go | 8 +- src/config/migrate_glyphs.go | 2 +- src/config/migrate_test.go | 4 +- src/config/responsive.go | 4 +- src/config/segment.go | 10 +- src/config/segment_test.go | 6 +- src/config/segment_types.go | 6 +- src/font/download.go | 2 +- src/font/fonts.go | 2 +- src/font/install.go | 8 +- src/http/oauth.go | 6 +- src/http/request.go | 10 +- src/image/image.go | 14 +- src/image/image_test.go | 17 +- src/mock/environment.go | 34 +- src/platform/shell_unix.go | 195 -------- src/platform/shell_windows_nix.go | 19 - src/prompt/engine.go | 4 +- src/prompt/engine_test.go | 10 +- src/prompt/new.go | 8 +- src/properties/properties.go | 4 +- src/{platform => runtime}/battery/battery.go | 0 .../battery/battery_darwin.go | 2 +- .../battery/battery_darwin_test.go | 0 .../battery/battery_linux.go | 0 .../battery/battery_netbsd.go | 2 +- .../battery/battery_openandfreebsd.go | 2 +- .../battery/battery_openandfreebsd_test.go | 0 .../battery/battery_windows.go | 0 .../battery/battery_windows_nix.go | 0 .../battery/battery_windows_nix_test.go | 0 src/{platform => runtime}/battery/errors.go | 0 .../battery/errors_test.go | 0 src/{platform => runtime}/cache.go | 2 +- src/{platform => runtime}/cmd/run.go | 0 src/{platform => runtime}/config/download.go | 2 +- src/{platform => runtime}/map.go | 2 +- src/{platform => runtime}/net/http.go | 0 src/{platform => runtime}/networks_windows.go | 8 +- src/{platform/shell.go => runtime/os.go} | 452 +++++++++--------- .../shell_darwin.go => runtime/os_darwin.go} | 20 +- .../shell_test.go => runtime/os_test.go} | 2 +- src/runtime/os_unix.go | 195 ++++++++ .../os_windows.go} | 102 ++-- src/runtime/os_windows_nix.go | 19 + src/{platform => runtime}/win32_windows.go | 6 +- src/segments/angular.go | 4 +- src/segments/argocd.go | 6 +- src/segments/aws.go | 6 +- src/segments/az.go | 6 +- src/segments/az_functions.go | 4 +- src/segments/az_test.go | 4 +- src/segments/azd.go | 6 +- src/segments/azd_test.go | 6 +- src/segments/battery.go | 8 +- src/segments/bazel.go | 4 +- src/segments/brewfather.go | 6 +- src/segments/buf.go | 4 +- src/segments/bun.go | 4 +- src/segments/carbon_intensity.go | 6 +- src/segments/cds.go | 4 +- src/segments/cf.go | 4 +- src/segments/cf_target.go | 6 +- src/segments/cf_target_test.go | 8 +- 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/docker.go | 6 +- src/segments/dotnet.go | 4 +- src/segments/dotnet_test.go | 4 +- src/segments/elixir.go | 4 +- src/segments/elixir_test.go | 4 +- src/segments/executiontime.go | 6 +- src/segments/firebase.go | 6 +- src/segments/flutter.go | 4 +- src/segments/gcp.go | 10 +- src/segments/gcp_test.go | 4 +- src/segments/git.go | 12 +- src/segments/git_test.go | 10 +- src/segments/gitversion.go | 6 +- src/segments/golang.go | 4 +- src/segments/golang_test.go | 5 +- src/segments/haskell.go | 4 +- src/segments/haskell_test.go | 5 +- src/segments/helm.go | 6 +- src/segments/helm_test.go | 6 +- src/segments/ipify.go | 4 +- 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 | 8 +- src/segments/language_test.go | 8 +- src/segments/lastfm.go | 6 +- src/segments/lua.go | 4 +- src/segments/mercurial.go | 6 +- src/segments/mercurial_test.go | 6 +- src/segments/nba.go | 6 +- 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/ocaml.go | 4 +- src/segments/os.go | 12 +- src/segments/os_test.go | 4 +- src/segments/owm.go | 6 +- src/segments/path.go | 22 +- src/segments/path_test.go | 178 +++---- src/segments/perl.go | 4 +- src/segments/php.go | 4 +- src/segments/plastic.go | 4 +- src/segments/plastic_test.go | 4 +- src/segments/pnpm.go | 4 +- src/segments/posh_git_test.go | 4 +- src/segments/project.go | 6 +- src/segments/pulumi.go | 6 +- src/segments/python.go | 8 +- src/segments/python_test.go | 6 +- src/segments/quasar.go | 4 +- src/segments/quasar_test.go | 4 +- src/segments/r.go | 4 +- src/segments/react.go | 4 +- src/segments/root.go | 6 +- src/segments/ruby.go | 4 +- src/segments/rust.go | 4 +- src/segments/sapling.go | 8 +- src/segments/sapling_test.go | 18 +- src/segments/scm.go | 10 +- src/segments/scm_test.go | 4 +- src/segments/session.go | 8 +- src/segments/session_test.go | 6 +- src/segments/shell.go | 6 +- src/segments/shell_test.go | 6 +- src/segments/sitecore.go | 6 +- src/segments/spotify.go | 6 +- src/segments/spotify_windows_test.go | 6 +- src/segments/status.go | 6 +- src/segments/status_test.go | 6 +- src/segments/strava.go | 4 +- src/segments/svn_test.go | 6 +- src/segments/swift.go | 4 +- src/segments/sysinfo.go | 8 +- src/segments/sysinfo_test.go | 22 +- src/segments/talosctl.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/umbraco.go | 6 +- src/segments/umbraco_test.go | 8 +- src/segments/unity.go | 6 +- src/segments/unity_test.go | 10 +- src/segments/upgrade.go | 6 +- src/segments/vala.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/yarn.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/numbers_test.go | 4 +- src/template/round_test.go | 4 +- src/template/strings_test.go | 4 +- src/template/text.go | 6 +- src/template/text_test.go | 10 +- src/upgrade/cli.go | 4 +- src/upgrade/install.go | 10 +- src/upgrade/notice.go | 6 +- src/upgrade/notice_test.go | 8 +- 207 files changed, 1186 insertions(+), 1185 deletions(-) delete mode 100644 src/platform/shell_unix.go delete mode 100644 src/platform/shell_windows_nix.go rename src/{platform => runtime}/battery/battery.go (100%) rename src/{platform => runtime}/battery/battery_darwin.go (96%) rename src/{platform => runtime}/battery/battery_darwin_test.go (100%) rename src/{platform => runtime}/battery/battery_linux.go (100%) rename src/{platform => runtime}/battery/battery_netbsd.go (87%) rename src/{platform => runtime}/battery/battery_openandfreebsd.go (94%) rename src/{platform => runtime}/battery/battery_openandfreebsd_test.go (100%) rename src/{platform => runtime}/battery/battery_windows.go (100%) rename src/{platform => runtime}/battery/battery_windows_nix.go (100%) rename src/{platform => runtime}/battery/battery_windows_nix_test.go (100%) rename src/{platform => runtime}/battery/errors.go (100%) rename src/{platform => runtime}/battery/errors_test.go (100%) rename src/{platform => runtime}/cache.go (99%) rename src/{platform => runtime}/cmd/run.go (100%) rename src/{platform => runtime}/config/download.go (97%) rename src/{platform => runtime}/map.go (98%) rename src/{platform => runtime}/net/http.go (100%) rename src/{platform => runtime}/networks_windows.go (96%) rename src/{platform/shell.go => runtime/os.go} (61%) rename src/{platform/shell_darwin.go => runtime/os_darwin.go} (73%) rename src/{platform/shell_test.go => runtime/os_test.go} (99%) create mode 100644 src/runtime/os_unix.go rename src/{platform/shell_windows.go => runtime/os_windows.go} (68%) create mode 100644 src/runtime/os_windows_nix.go rename src/{platform => runtime}/win32_windows.go (98%) diff --git a/src/cli/cache.go b/src/cli/cache.go index e29850f4..fbf86a16 100644 --- a/src/cli/cache.go +++ b/src/cli/cache.go @@ -7,7 +7,7 @@ import ( "path/filepath" "strings" - "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/spf13/cobra" ) @@ -34,8 +34,8 @@ You can do the following: _ = cmd.Help() return } - env := &platform.Shell{ - CmdFlags: &platform.Flags{}, + env := &runtime.Terminal{ + CmdFlags: &runtime.Flags{}, } env.Init() defer env.Close() @@ -43,7 +43,7 @@ You can do the following: case "path": fmt.Print(env.CachePath()) case "clear": - cacheFilePath := filepath.Join(env.CachePath(), platform.CacheFile) + cacheFilePath := filepath.Join(env.CachePath(), runtime.CacheFile) err := os.Remove(cacheFilePath) if err != nil { fmt.Println(err.Error()) @@ -51,7 +51,7 @@ You can do the following: } fmt.Printf("removed cache file at %s\n", cacheFilePath) case "edit": - cacheFilePath := filepath.Join(env.CachePath(), platform.CacheFile) + cacheFilePath := filepath.Join(env.CachePath(), runtime.CacheFile) editFileWithEditor(cacheFilePath) } }, diff --git a/src/cli/config_export.go b/src/cli/config_export.go index 95624b8b..b636e2a9 100644 --- a/src/cli/config_export.go +++ b/src/cli/config_export.go @@ -8,7 +8,7 @@ import ( "strings" "github.com/jandedobbeleer/oh-my-posh/src/config" - "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/spf13/cobra" ) @@ -36,8 +36,8 @@ Exports the ~/myconfig.omp.json config file and prints the result to stdout. Exports the ~/myconfig.omp.json config file to toml and prints the result to stdout.`, Args: cobra.NoArgs, Run: func(_ *cobra.Command, _ []string) { - env := &platform.Shell{ - CmdFlags: &platform.Flags{ + env := &runtime.Terminal{ + CmdFlags: &runtime.Flags{ Config: configFlag, }, } @@ -83,7 +83,7 @@ Exports the ~/myconfig.omp.json config file to toml and prints the result to std }, } -func cleanOutputPath(path string, env platform.Environment) string { +func cleanOutputPath(path string, env runtime.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 a6a94c68..9391b2f0 100644 --- a/src/cli/config_export_image.go +++ b/src/cli/config_export_image.go @@ -5,8 +5,8 @@ import ( "github.com/jandedobbeleer/oh-my-posh/src/config" "github.com/jandedobbeleer/oh-my-posh/src/image" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/prompt" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/jandedobbeleer/oh-my-posh/src/shell" "github.com/jandedobbeleer/oh-my-posh/src/terminal" @@ -49,8 +49,8 @@ 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(_ *cobra.Command, _ []string) { - env := &platform.Shell{ - CmdFlags: &platform.Flags{ + env := &runtime.Terminal{ + CmdFlags: &runtime.Flags{ Config: configFlag, Shell: shell.GENERIC, TerminalWidth: 150, diff --git a/src/cli/config_migrate.go b/src/cli/config_migrate.go index b7560002..83fec6e6 100644 --- a/src/cli/config_migrate.go +++ b/src/cli/config_migrate.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/jandedobbeleer/oh-my-posh/src/config" - "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/spf13/cobra" ) @@ -39,8 +39,8 @@ 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(_ *cobra.Command, _ []string) { - env := &platform.Shell{ - CmdFlags: &platform.Flags{ + env := &runtime.Terminal{ + CmdFlags: &runtime.Flags{ Config: configFlag, Migrate: true, }, diff --git a/src/cli/config_migrate_glyphs.go b/src/cli/config_migrate_glyphs.go index 41134d9d..e9340ecd 100644 --- a/src/cli/config_migrate_glyphs.go +++ b/src/cli/config_migrate_glyphs.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/jandedobbeleer/oh-my-posh/src/config" - "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/spf13/cobra" ) @@ -34,8 +34,8 @@ Migrates the ~/myconfig.omp.json config file's glyphs and writes the result to y A backup of the current config can be found at ~/myconfig.omp.json.bak.`, Args: cobra.NoArgs, Run: func(_ *cobra.Command, _ []string) { - env := &platform.Shell{ - CmdFlags: &platform.Flags{ + env := &runtime.Terminal{ + CmdFlags: &runtime.Flags{ Config: configFlag, }, } diff --git a/src/cli/debug.go b/src/cli/debug.go index 5b22272a..a775f0b0 100644 --- a/src/cli/debug.go +++ b/src/cli/debug.go @@ -6,8 +6,8 @@ import ( "github.com/jandedobbeleer/oh-my-posh/src/build" "github.com/jandedobbeleer/oh-my-posh/src/config" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/prompt" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/jandedobbeleer/oh-my-posh/src/shell" "github.com/jandedobbeleer/oh-my-posh/src/terminal" @@ -23,8 +23,8 @@ var debugCmd = &cobra.Command{ Run: func(_ *cobra.Command, _ []string) { startTime := time.Now() - env := &platform.Shell{ - CmdFlags: &platform.Flags{ + env := &runtime.Terminal{ + CmdFlags: &runtime.Flags{ Config: configFlag, Debug: true, PWD: pwd, diff --git a/src/cli/enable.go b/src/cli/enable.go index aa83be59..2b9cb30e 100644 --- a/src/cli/enable.go +++ b/src/cli/enable.go @@ -3,7 +3,7 @@ package cli import ( "fmt" - "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/jandedobbeleer/oh-my-posh/src/upgrade" "github.com/spf13/cobra" @@ -42,8 +42,8 @@ func init() { } func toggleFeature(cmd *cobra.Command, feature string, enable bool) { - env := &platform.Shell{ - CmdFlags: &platform.Flags{ + env := &runtime.Terminal{ + CmdFlags: &runtime.Flags{ Shell: shellName, }, } diff --git a/src/cli/font.go b/src/cli/font.go index f94798ae..e253a9cb 100644 --- a/src/cli/font.go +++ b/src/cli/font.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/jandedobbeleer/oh-my-posh/src/font" - "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/jandedobbeleer/oh-my-posh/src/terminal" "github.com/spf13/cobra" @@ -35,7 +35,7 @@ This command is used to install fonts and configure the font in your terminal. if len(args) > 1 { fontName = args[1] } - env := &platform.Shell{} + env := &runtime.Terminal{} env.Init() defer env.Close() diff --git a/src/cli/get.go b/src/cli/get.go index 0a7a136a..c545d464 100644 --- a/src/cli/get.go +++ b/src/cli/get.go @@ -6,7 +6,7 @@ import ( "time" "github.com/jandedobbeleer/oh-my-posh/src/color" - "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" color2 "github.com/gookit/color" "github.com/spf13/cobra" @@ -44,8 +44,8 @@ This command is used to get the value of the following variables: return } - env := &platform.Shell{ - CmdFlags: &platform.Flags{ + env := &runtime.Terminal{ + CmdFlags: &runtime.Flags{ Shell: shellName, }, } @@ -65,7 +65,7 @@ This command is used to get the value of the following variables: fmt.Println("#" + accent.Hex()) case "toggles": cache := env.Cache() - togglesCache, _ := cache.Get(platform.TOGGLECACHE) + togglesCache, _ := cache.Get(runtime.TOGGLECACHE) var toggles []string if len(togglesCache) != 0 { toggles = strings.Split(togglesCache, ",") diff --git a/src/cli/init.go b/src/cli/init.go index 17d40080..98220f12 100644 --- a/src/cli/init.go +++ b/src/cli/init.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/jandedobbeleer/oh-my-posh/src/config" - "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/jandedobbeleer/oh-my-posh/src/shell" "github.com/jandedobbeleer/oh-my-posh/src/terminal" "github.com/jandedobbeleer/oh-my-posh/src/upgrade" @@ -55,8 +55,8 @@ func init() { } func runInit(shellName string) { - env := &platform.Shell{ - CmdFlags: &platform.Flags{ + env := &runtime.Terminal{ + CmdFlags: &runtime.Flags{ Shell: shellName, Config: configFlag, Strict: strict, diff --git a/src/cli/notice.go b/src/cli/notice.go index 4f663e38..ba0571eb 100644 --- a/src/cli/notice.go +++ b/src/cli/notice.go @@ -3,7 +3,7 @@ package cli import ( "fmt" - "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/jandedobbeleer/oh-my-posh/src/upgrade" "github.com/spf13/cobra" ) @@ -15,8 +15,8 @@ var noticeCmd = &cobra.Command{ Long: "Print the upgrade notice when a new version is available.", Args: cobra.NoArgs, Run: func(_ *cobra.Command, _ []string) { - env := &platform.Shell{ - CmdFlags: &platform.Flags{}, + env := &runtime.Terminal{ + CmdFlags: &runtime.Flags{}, } env.Init() defer env.Close() diff --git a/src/cli/print.go b/src/cli/print.go index 44ac08b0..fba29a0f 100644 --- a/src/cli/print.go +++ b/src/cli/print.go @@ -3,8 +3,8 @@ package cli import ( "fmt" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/prompt" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/spf13/cobra" ) @@ -49,7 +49,7 @@ var printCmd = &cobra.Command{ return } - flags := &platform.Flags{ + flags := &runtime.Flags{ Config: configFlag, PWD: pwd, PSWD: pswd, diff --git a/src/cli/toggle.go b/src/cli/toggle.go index ba39b59b..23d58d04 100644 --- a/src/cli/toggle.go +++ b/src/cli/toggle.go @@ -3,8 +3,7 @@ package cli import ( "strings" - "github.com/jandedobbeleer/oh-my-posh/src/platform" - + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/spf13/cobra" ) @@ -19,12 +18,12 @@ var toggleCmd = &cobra.Command{ _ = cmd.Help() return } - env := &platform.Shell{} + env := &runtime.Terminal{} env.Init() defer env.Close() cache := env.Cache() - togglesCache, _ := cache.Get(platform.TOGGLECACHE) + togglesCache, _ := cache.Get(runtime.TOGGLECACHE) var toggles []string if len(togglesCache) != 0 { toggles = strings.Split(togglesCache, ",") @@ -45,7 +44,7 @@ var toggleCmd = &cobra.Command{ newToggles = append(newToggles, segment) } - cache.Set(platform.TOGGLECACHE, strings.Join(newToggles, ","), 1440) + cache.Set(runtime.TOGGLECACHE, strings.Join(newToggles, ","), 1440) }, } diff --git a/src/cli/upgrade.go b/src/cli/upgrade.go index a3f65108..44db7e41 100644 --- a/src/cli/upgrade.go +++ b/src/cli/upgrade.go @@ -2,11 +2,11 @@ package cli import ( "fmt" - "runtime" + stdruntime "runtime" "slices" "github.com/jandedobbeleer/oh-my-posh/src/config" - "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/jandedobbeleer/oh-my-posh/src/terminal" "github.com/jandedobbeleer/oh-my-posh/src/upgrade" "github.com/spf13/cobra" @@ -22,18 +22,18 @@ var upgradeCmd = &cobra.Command{ Args: cobra.NoArgs, Run: func(_ *cobra.Command, _ []string) { supportedPlatforms := []string{ - platform.WINDOWS, - platform.DARWIN, - platform.LINUX, + runtime.WINDOWS, + runtime.DARWIN, + runtime.LINUX, } - if !slices.Contains(supportedPlatforms, runtime.GOOS) { + if !slices.Contains(supportedPlatforms, stdruntime.GOOS) { fmt.Print("\n⚠️ upgrade is not supported on this platform\n\n") return } - env := &platform.Shell{ - CmdFlags: &platform.Flags{}, + env := &runtime.Terminal{ + CmdFlags: &runtime.Flags{}, } env.Init() defer env.Close() diff --git a/src/color/colors.go b/src/color/colors.go index 416eb070..60654fe1 100644 --- a/src/color/colors.go +++ b/src/color/colors.go @@ -6,7 +6,7 @@ import ( "strings" "github.com/gookit/color" - "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) var TrueColor = true @@ -107,7 +107,7 @@ func (c Ansi) String() string { return string(c) } -func MakeColors(palette Palette, cacheEnabled bool, accentColor Ansi, env platform.Environment) (colors String) { +func MakeColors(palette Palette, cacheEnabled bool, accentColor Ansi, env runtime.Environment) (colors String) { defaultColors := &Defaults{} defaultColors.SetAccentColor(env, accentColor) colors = defaultColors diff --git a/src/color/colors_test.go b/src/color/colors_test.go index 0bf7aff7..e4121d7b 100644 --- a/src/color/colors_test.go +++ b/src/color/colors_test.go @@ -6,7 +6,7 @@ import ( "github.com/alecthomas/assert" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) func TestGetAnsiFromColorString(t *testing.T) { @@ -40,7 +40,7 @@ func TestGetAnsiFromColorString(t *testing.T) { func TestMakeColors(t *testing.T) { env := &mock.MockedEnvironment{} - env.On("WindowsRegistryKeyValue", `HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM\ColorizationColor`).Return(&platform.WindowsRegistryValue{}, errors.New("err")) + env.On("WindowsRegistryKeyValue", `HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM\ColorizationColor`).Return(&runtime.WindowsRegistryValue{}, errors.New("err")) colors := MakeColors(nil, false, "", env) assert.IsType(t, &Defaults{}, colors) diff --git a/src/color/colors_unix.go b/src/color/colors_unix.go index 2a8bd693..f589b056 100644 --- a/src/color/colors_unix.go +++ b/src/color/colors_unix.go @@ -2,13 +2,13 @@ package color -import "github.com/jandedobbeleer/oh-my-posh/src/platform" +import "github.com/jandedobbeleer/oh-my-posh/src/runtime" -func GetAccentColor(_ platform.Environment) (*RGB, error) { - return nil, &platform.NotImplemented{} +func GetAccentColor(_ runtime.Environment) (*RGB, error) { + return nil, &runtime.NotImplemented{} } -func (d *Defaults) SetAccentColor(_ platform.Environment, defaultColor Ansi) { +func (d *Defaults) SetAccentColor(_ runtime.Environment, defaultColor Ansi) { if len(defaultColor) == 0 { return } diff --git a/src/color/colors_windows.go b/src/color/colors_windows.go index 22a8d8df..47bbfa55 100644 --- a/src/color/colors_windows.go +++ b/src/color/colors_windows.go @@ -3,19 +3,18 @@ package color import ( "errors" - "github.com/jandedobbeleer/oh-my-posh/src/platform" - "github.com/gookit/color" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) -func GetAccentColor(env platform.Environment) (*RGB, error) { +func GetAccentColor(env runtime.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 != platform.DWORD { + if err != nil || value.ValueType != runtime.DWORD { return nil, err } @@ -26,7 +25,7 @@ func GetAccentColor(env platform.Environment) (*RGB, error) { }, nil } -func (d *Defaults) SetAccentColor(env platform.Environment, defaultColor Ansi) { +func (d *Defaults) SetAccentColor(env runtime.Environment, defaultColor Ansi) { rgb, err := GetAccentColor(env) if err != nil { d.accent = &Set{ diff --git a/src/config/block.go b/src/config/block.go index 7ab4e397..848165f9 100644 --- a/src/config/block.go +++ b/src/config/block.go @@ -3,7 +3,7 @@ package config import ( "sync" - "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/jandedobbeleer/oh-my-posh/src/shell" "github.com/jandedobbeleer/oh-my-posh/src/terminal" ) @@ -53,15 +53,15 @@ type Block struct { MaxWidth int `json:"max_width,omitempty" toml:"max_width,omitempty"` MinWidth int `json:"min_width,omitempty" toml:"min_width,omitempty"` - env platform.Environment + env runtime.Environment } -func (b *Block) Init(env platform.Environment) { +func (b *Block) Init(env runtime.Environment) { b.env = env b.executeSegmentLogic() } -func (b *Block) InitPlain(env platform.Environment, config *Config) { +func (b *Block) InitPlain(env runtime.Environment, config *Config) { terminal.Init(shell.GENERIC) terminal.BackgroundColor = shell.ConsoleBackgroundColor(env, config.TerminalBackground) terminal.Colors = config.MakeColors() diff --git a/src/config/config.go b/src/config/config.go index a6c8b2cc..99d503a0 100644 --- a/src/config/config.go +++ b/src/config/config.go @@ -2,7 +2,7 @@ package config import ( "github.com/jandedobbeleer/oh-my-posh/src/color" - "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/jandedobbeleer/oh-my-posh/src/template" "github.com/jandedobbeleer/oh-my-posh/src/terminal" ) @@ -51,7 +51,7 @@ type Config struct { origin string // eval bool updated bool - env platform.Environment + env runtime.Environment } func (cfg *Config) MakeColors() color.String { diff --git a/src/config/config_test.go b/src/config/config_test.go index ad2442ca..dafeecd3 100644 --- a/src/config/config_test.go +++ b/src/config/config_test.go @@ -5,7 +5,7 @@ import ( "github.com/jandedobbeleer/oh-my-posh/src/color" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/stretchr/testify/assert" mock2 "github.com/stretchr/testify/mock" @@ -71,7 +71,7 @@ func TestGetPalette(t *testing.T) { } for _, tc := range cases { env := &mock.MockedEnvironment{} - env.On("TemplateCache").Return(&platform.TemplateCache{ + env.On("TemplateCache").Return(&runtime.TemplateCache{ Env: map[string]string{}, Shell: "bash", }) diff --git a/src/config/default.go b/src/config/default.go index 045ca949..3e151a1b 100644 --- a/src/config/default.go +++ b/src/config/default.go @@ -2,12 +2,12 @@ package config import ( "github.com/jandedobbeleer/oh-my-posh/src/color" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/jandedobbeleer/oh-my-posh/src/segments" ) -func Default(env platform.Environment, warning bool) *Config { +func Default(env runtime.Environment, warning bool) *Config { exitBackgroundTemplate := "{{ if gt .Code 0 }}p:red{{ end }}" exitTemplate := " {{ if gt .Code 0 }}\uf00d{{ else }}\uf00c{{ end }} " if warning { diff --git a/src/config/load.go b/src/config/load.go index 79a434ca..09ec9e88 100644 --- a/src/config/load.go +++ b/src/config/load.go @@ -3,13 +3,13 @@ package config import ( "bytes" "fmt" - "os" + stdOS "os" "path/filepath" "strings" "time" "github.com/gookit/goutil/jsonutil" - "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/jandedobbeleer/oh-my-posh/src/shell" json "github.com/goccy/go-json" @@ -18,7 +18,7 @@ import ( ) // LoadConfig returns the default configuration including possible user overrides -func Load(env platform.Environment) *Config { +func Load(env runtime.Environment) *Config { cfg := loadConfig(env) // only migrate automatically when the switch isn't set @@ -47,7 +47,7 @@ func Load(env platform.Environment) *Config { return cfg } -func loadConfig(env platform.Environment) *Config { +func loadConfig(env runtime.Environment) *Config { defer env.Trace(time.Now()) configFile := env.Flags().Config @@ -61,7 +61,7 @@ func loadConfig(env platform.Environment) *Config { cfg.Format = strings.TrimPrefix(filepath.Ext(configFile), ".") cfg.env = env - data, err := os.ReadFile(configFile) + data, err := stdOS.ReadFile(configFile) if err != nil { env.DebugF("error reading config file: %s", err) return Default(env, true) diff --git a/src/config/migrate.go b/src/config/migrate.go index 56a88ded..b07441f2 100644 --- a/src/config/migrate.go +++ b/src/config/migrate.go @@ -4,8 +4,8 @@ import ( "fmt" "strings" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/jandedobbeleer/oh-my-posh/src/segments" ) @@ -33,7 +33,7 @@ func (cfg *Config) Migrate() { cfg.Version = Version } -func (segment *Segment) migrate(env platform.Environment, version int) { +func (segment *Segment) migrate(env runtime.Environment, version int) { if version < 1 { segment.migrationOne(env) } @@ -42,7 +42,7 @@ func (segment *Segment) migrate(env platform.Environment, version int) { } } -func (segment *Segment) migrationOne(env platform.Environment) { +func (segment *Segment) migrationOne(env runtime.Environment) { if err := segment.MapSegmentWithWriter(env); err != nil { return } @@ -162,7 +162,7 @@ func (segment *Segment) migrationOne(env platform.Environment) { delete(segment.Properties, colorBackground) } -func (segment *Segment) migrationTwo(env platform.Environment) { +func (segment *Segment) migrationTwo(env runtime.Environment) { if err := segment.MapSegmentWithWriter(env); err != nil { return } diff --git a/src/config/migrate_glyphs.go b/src/config/migrate_glyphs.go index 8ca01e4d..fecec871 100644 --- a/src/config/migrate_glyphs.go +++ b/src/config/migrate_glyphs.go @@ -9,7 +9,7 @@ import ( "strings" "time" - "github.com/jandedobbeleer/oh-my-posh/src/platform/net" + "github.com/jandedobbeleer/oh-my-posh/src/runtime/net" ) type ConnectionError struct { diff --git a/src/config/migrate_test.go b/src/config/migrate_test.go index a2721aa0..4e1ce27d 100644 --- a/src/config/migrate_test.go +++ b/src/config/migrate_test.go @@ -4,8 +4,8 @@ import ( "testing" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/jandedobbeleer/oh-my-posh/src/segments" "github.com/stretchr/testify/assert" @@ -91,7 +91,7 @@ func (m *MockedWriter) Template() string { return m.template } -func (m *MockedWriter) Init(_ properties.Properties, _ platform.Environment) {} +func (m *MockedWriter) Init(_ properties.Properties, _ runtime.Environment) {} func TestIconOverride(t *testing.T) { cases := []struct { diff --git a/src/config/responsive.go b/src/config/responsive.go index a4bc06f2..64c85734 100644 --- a/src/config/responsive.go +++ b/src/config/responsive.go @@ -1,8 +1,8 @@ package config -import "github.com/jandedobbeleer/oh-my-posh/src/platform" +import "github.com/jandedobbeleer/oh-my-posh/src/runtime" -func shouldHideForWidth(env platform.Environment, minWidth, maxWidth int) bool { +func shouldHideForWidth(env runtime.Environment, minWidth, maxWidth int) bool { if maxWidth == 0 && minWidth == 0 { return false } diff --git a/src/config/segment.go b/src/config/segment.go index 1cb6da5a..5b2adb56 100644 --- a/src/config/segment.go +++ b/src/config/segment.go @@ -7,8 +7,8 @@ import ( "time" "github.com/jandedobbeleer/oh-my-posh/src/color" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/jandedobbeleer/oh-my-posh/src/template" c "golang.org/x/text/cases" @@ -18,7 +18,7 @@ import ( // SegmentStyle the style of segment, for more information, see the constants type SegmentStyle string -func (s *SegmentStyle) resolve(env platform.Environment, context any) SegmentStyle { +func (s *SegmentStyle) resolve(env runtime.Environment, context any) SegmentStyle { txtTemplate := &template.Text{ Context: context, Env: env, @@ -58,7 +58,7 @@ type Segment struct { Text string - env platform.Environment + env runtime.Environment writer SegmentWriter styleCache SegmentStyle name string @@ -82,7 +82,7 @@ func (segment *Segment) Name() string { return name } -func (segment *Segment) SetEnabled(env platform.Environment) { +func (segment *Segment) SetEnabled(env runtime.Environment) { defer func() { err := recover() if err == nil { @@ -112,7 +112,7 @@ func (segment *Segment) SetEnabled(env platform.Environment) { segment.env.DebugF("Segment: %s", segment.Name()) // validate toggles - if toggles, OK := segment.env.Cache().Get(platform.TOGGLECACHE); OK && len(toggles) > 0 { + if toggles, OK := segment.env.Cache().Get(runtime.TOGGLECACHE); OK && len(toggles) > 0 { list := strings.Split(toggles, ",") for _, toggle := range list { if SegmentType(toggle) == segment.Type || toggle == segment.Alias { diff --git a/src/config/segment_test.go b/src/config/segment_test.go index 8724dfb8..4e3167de 100644 --- a/src/config/segment_test.go +++ b/src/config/segment_test.go @@ -6,8 +6,8 @@ import ( "github.com/jandedobbeleer/oh-my-posh/src/color" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/jandedobbeleer/oh-my-posh/src/segments" "github.com/stretchr/testify/assert" @@ -73,7 +73,7 @@ func TestShouldIncludeFolder(t *testing.T) { } for _, tc := range cases { env := new(mock.MockedEnvironment) - env.On("GOOS").Return(platform.LINUX) + env.On("GOOS").Return(runtime.LINUX) env.On("Home").Return("") env.On("Pwd").Return(cwd) env.On("DirMatchesOneOf", cwd, []string{"Projects/oh-my-posh"}).Return(tc.Included) @@ -145,7 +145,7 @@ func TestGetColors(t *testing.T) { for _, tc := range cases { env := new(mock.MockedEnvironment) env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil) - env.On("TemplateCache").Return(&platform.TemplateCache{ + env.On("TemplateCache").Return(&runtime.TemplateCache{ Env: make(map[string]string), }) diff --git a/src/config/segment_types.go b/src/config/segment_types.go index 3cae8e07..c3a05e7b 100644 --- a/src/config/segment_types.go +++ b/src/config/segment_types.go @@ -3,8 +3,8 @@ package config import ( "errors" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/jandedobbeleer/oh-my-posh/src/segments" ) @@ -15,7 +15,7 @@ type SegmentType string type SegmentWriter interface { Enabled() bool Template() string - Init(props properties.Properties, env platform.Environment) + Init(props properties.Properties, env runtime.Environment) } const ( @@ -308,7 +308,7 @@ var Segments = map[SegmentType]func() SegmentWriter{ YTM: func() SegmentWriter { return &segments.Ytm{} }, } -func (segment *Segment) MapSegmentWithWriter(env platform.Environment) error { +func (segment *Segment) MapSegmentWithWriter(env runtime.Environment) error { segment.env = env if segment.Properties == nil { diff --git a/src/font/download.go b/src/font/download.go index 991bf23a..53ea9e23 100644 --- a/src/font/download.go +++ b/src/font/download.go @@ -11,7 +11,7 @@ import ( "net/http" "net/url" - "github.com/jandedobbeleer/oh-my-posh/src/platform/net" + "github.com/jandedobbeleer/oh-my-posh/src/runtime/net" ) func Download(fontPath string) ([]byte, error) { diff --git a/src/font/fonts.go b/src/font/fonts.go index 68794c70..58786155 100644 --- a/src/font/fonts.go +++ b/src/font/fonts.go @@ -10,7 +10,7 @@ import ( "strings" "time" - "github.com/jandedobbeleer/oh-my-posh/src/platform/net" + "github.com/jandedobbeleer/oh-my-posh/src/runtime/net" ) type release struct { diff --git a/src/font/install.go b/src/font/install.go index 450286df..5398a2eb 100644 --- a/src/font/install.go +++ b/src/font/install.go @@ -7,11 +7,11 @@ import ( "bytes" "io" "path" - "runtime" + stdruntime "runtime" "strings" - "github.com/jandedobbeleer/oh-my-posh/src/platform" - "github.com/jandedobbeleer/oh-my-posh/src/platform/cmd" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" + "github.com/jandedobbeleer/oh-my-posh/src/runtime/cmd" ) func contains[S ~[]E, E comparable](s S, e E) bool { @@ -74,7 +74,7 @@ func InstallZIP(data []byte, user bool) ([]string, error) { } // Update the font cache when installing fonts on Linux - if runtime.GOOS == platform.LINUX || runtime.GOOS == platform.DARWIN { + if stdruntime.GOOS == runtime.LINUX || stdruntime.GOOS == runtime.DARWIN { _, _ = cmd.Run("fc-cache", "-f") } diff --git a/src/http/oauth.go b/src/http/oauth.go index 902d3277..5ba5197d 100644 --- a/src/http/oauth.go +++ b/src/http/oauth.go @@ -6,8 +6,8 @@ import ( "io" "net/http" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) const ( @@ -86,7 +86,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 ...platform.HTTPRequestModifier) (a, error) { +func OauthResult[a any](o *OAuthRequest, url string, body io.Reader, requestModifiers ...runtime.HTTPRequestModifier) (a, error) { if data, err := getCacheValue[a](&o.Request, url); err == nil { return data, nil } @@ -103,7 +103,7 @@ func OauthResult[a any](o *OAuthRequest, url string, body io.Reader, requestModi } if requestModifiers == nil { - requestModifiers = []platform.HTTPRequestModifier{} + requestModifiers = []runtime.HTTPRequestModifier{} } requestModifiers = append(requestModifiers, addAuthHeader) diff --git a/src/http/request.go b/src/http/request.go index 01f08df9..7be768c9 100644 --- a/src/http/request.go +++ b/src/http/request.go @@ -5,21 +5,21 @@ import ( "errors" "io" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Request struct { props properties.Properties - env platform.Environment + env runtime.Environment } -func (r *Request) Init(env platform.Environment, props properties.Properties) { +func (r *Request) Init(env runtime.Environment, props properties.Properties) { r.env = env r.props = props } -func Do[a any](r *Request, url string, requestModifiers ...platform.HTTPRequestModifier) (a, error) { +func Do[a any](r *Request, url string, requestModifiers ...runtime.HTTPRequestModifier) (a, error) { if data, err := getCacheValue[a](r, url); err == nil { return data, nil } @@ -45,7 +45,7 @@ func getCacheValue[a any](r *Request, key string) (a, error) { return data, err } -func do[a any](r *Request, url string, body io.Reader, requestModifiers ...platform.HTTPRequestModifier) (a, error) { +func do[a any](r *Request, url string, body io.Reader, requestModifiers ...runtime.HTTPRequestModifier) (a, error) { var data a httpTimeout := r.props.GetInt(properties.HTTPTimeout, properties.DefaultHTTPTimeout) diff --git a/src/image/image.go b/src/image/image.go index 2193db68..2db4897f 100644 --- a/src/image/image.go +++ b/src/image/image.go @@ -28,7 +28,7 @@ import ( "fmt" "io" "math" - "os" + stdOS "os" "path/filepath" "slices" "strconv" @@ -36,8 +36,8 @@ import ( "unicode/utf8" fontCLI "github.com/jandedobbeleer/oh-my-posh/src/font" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/regex" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/jandedobbeleer/oh-my-posh/src/terminal" "github.com/esimov/stackblur-go" @@ -115,7 +115,7 @@ type Renderer struct { RPromptOffset int BgColor string - env platform.Environment + env runtime.Environment Path string @@ -147,7 +147,7 @@ type Renderer struct { ansiSequenceRegexMap map[string]string } -func (ir *Renderer) Init(env platform.Environment) error { +func (ir *Renderer) Init(env runtime.Environment) error { ir.env = env if ir.Path == "" { @@ -210,8 +210,8 @@ func (ir *Renderer) loadFonts() error { var data []byte fontCachePath := filepath.Join(ir.env.CachePath(), "Hack.zip") - if _, err := os.Stat(fontCachePath); err == nil { - data, _ = os.ReadFile(fontCachePath) + if _, err := stdOS.Stat(fontCachePath); err == nil { + data, _ = stdOS.ReadFile(fontCachePath) } // Download font if not cached @@ -224,7 +224,7 @@ func (ir *Renderer) loadFonts() error { return err } - err = os.WriteFile(fontCachePath, data, 0644) + err = stdOS.WriteFile(fontCachePath, data, 0644) if err != nil { return err } diff --git a/src/image/image_test.go b/src/image/image_test.go index 751cb016..b35fcc62 100644 --- a/src/image/image_test.go +++ b/src/image/image_test.go @@ -1,11 +1,11 @@ package image import ( - "os" + stdOS "os" "path/filepath" "testing" - "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/jandedobbeleer/oh-my-posh/src/shell" "github.com/jandedobbeleer/oh-my-posh/src/terminal" @@ -28,11 +28,14 @@ var cases = []struct { func runImageTest(config, content string) (string, error) { poshImagePath := "jandedobbeleer.png" - file, err := os.CreateTemp("", poshImagePath) + file, err := stdOS.CreateTemp("", poshImagePath) if err != nil { return "", err } - defer os.Remove(file.Name()) + + defer func() { + _ = stdOS.Remove(file.Name()) + }() terminal.Init(shell.GENERIC) @@ -40,8 +43,8 @@ func runImageTest(config, content string) (string, error) { AnsiString: content, } - env := &platform.Shell{ - CmdFlags: &platform.Flags{ + env := &runtime.Terminal{ + CmdFlags: &runtime.Flags{ Config: config, }, } @@ -53,7 +56,7 @@ func runImageTest(config, content string) (string, error) { err = image.SavePNG() if err == nil { - os.Remove(image.Path) + _ = stdOS.Remove(image.Path) } return filepath.Base(image.Path), err diff --git a/src/mock/environment.go b/src/mock/environment.go index a7bbef86..e329f037 100644 --- a/src/mock/environment.go +++ b/src/mock/environment.go @@ -5,8 +5,8 @@ import ( "io/fs" "time" - "github.com/jandedobbeleer/oh-my-posh/src/platform" - "github.com/jandedobbeleer/oh-my-posh/src/platform/battery" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" + "github.com/jandedobbeleer/oh-my-posh/src/runtime/battery" mock "github.com/stretchr/testify/mock" ) @@ -120,9 +120,9 @@ func (env *MockedEnvironment) Root() bool { return args.Bool(0) } -func (env *MockedEnvironment) Flags() *platform.Flags { +func (env *MockedEnvironment) Flags() *runtime.Flags { arguments := env.Called() - return arguments.Get(0).(*platform.Flags) + return arguments.Get(0).(*runtime.Flags) } func (env *MockedEnvironment) BatteryState() (*battery.Info, error) { @@ -140,19 +140,19 @@ func (env *MockedEnvironment) QueryWindowTitles(processName, windowTitleRegex st return args.String(0), args.Error(1) } -func (env *MockedEnvironment) WindowsRegistryKeyValue(path string) (*platform.WindowsRegistryValue, error) { +func (env *MockedEnvironment) WindowsRegistryKeyValue(path string) (*runtime.WindowsRegistryValue, error) { args := env.Called(path) - return args.Get(0).(*platform.WindowsRegistryValue), args.Error(1) + return args.Get(0).(*runtime.WindowsRegistryValue), args.Error(1) } -func (env *MockedEnvironment) HTTPRequest(url string, _ io.Reader, _ int, _ ...platform.HTTPRequestModifier) ([]byte, error) { +func (env *MockedEnvironment) HTTPRequest(url string, _ io.Reader, _ int, _ ...runtime.HTTPRequestModifier) ([]byte, error) { args := env.Called(url) return args.Get(0).([]byte), args.Error(1) } -func (env *MockedEnvironment) HasParentFilePath(path string) (*platform.FileInfo, error) { +func (env *MockedEnvironment) HasParentFilePath(path string) (*runtime.FileInfo, error) { args := env.Called(path) - return args.Get(0).(*platform.FileInfo), args.Error(1) + return args.Get(0).(*runtime.FileInfo), args.Error(1) } func (env *MockedEnvironment) StackCount() int { @@ -180,9 +180,9 @@ func (env *MockedEnvironment) CachePath() string { return args.String(0) } -func (env *MockedEnvironment) Cache() platform.Cache { +func (env *MockedEnvironment) Cache() runtime.Cache { args := env.Called() - return args.Get(0).(platform.Cache) + return args.Get(0).(runtime.Cache) } func (env *MockedEnvironment) Close() { @@ -209,14 +209,14 @@ func (env *MockedEnvironment) ConvertToLinuxPath(_ string) string { return args.String(0) } -func (env *MockedEnvironment) Connection(connectionType platform.ConnectionType) (*platform.Connection, error) { +func (env *MockedEnvironment) Connection(connectionType runtime.ConnectionType) (*runtime.Connection, error) { args := env.Called(connectionType) - return args.Get(0).(*platform.Connection), args.Error(1) + return args.Get(0).(*runtime.Connection), args.Error(1) } -func (env *MockedEnvironment) TemplateCache() *platform.TemplateCache { +func (env *MockedEnvironment) TemplateCache() *runtime.TemplateCache { args := env.Called() - return args.Get(0).(*platform.TemplateCache) + return args.Get(0).(*runtime.TemplateCache) } func (env *MockedEnvironment) LoadTemplateCache() { @@ -278,9 +278,9 @@ func (env *MockedEnvironment) CursorPosition() (int, int) { return args.Int(0), args.Int(1) } -func (env *MockedEnvironment) SystemInfo() (*platform.SystemInfo, error) { +func (env *MockedEnvironment) SystemInfo() (*runtime.SystemInfo, error) { args := env.Called() - return args.Get(0).(*platform.SystemInfo), args.Error(1) + return args.Get(0).(*runtime.SystemInfo), args.Error(1) } func (env *MockedEnvironment) Unset(name string) { diff --git a/src/platform/shell_unix.go b/src/platform/shell_unix.go deleted file mode 100644 index 36105aa5..00000000 --- a/src/platform/shell_unix.go +++ /dev/null @@ -1,195 +0,0 @@ -//go:build !windows - -package platform - -import ( - "os" - "os/exec" - "strconv" - "strings" - "time" - - "github.com/shirou/gopsutil/v3/host" - mem "github.com/shirou/gopsutil/v3/mem" - terminal "github.com/wayneashleyberry/terminal-dimensions" - "golang.org/x/sys/unix" -) - -func (env *Shell) Root() bool { - defer env.Trace(time.Now()) - return os.Geteuid() == 0 -} - -func (env *Shell) Home() string { - return os.Getenv("HOME") -} - -func (env *Shell) QueryWindowTitles(_, _ string) (string, error) { - return "", &NotImplemented{} -} - -func (env *Shell) IsWsl() bool { - defer env.Trace(time.Now()) - const key = "is_wsl" - if val, found := env.Cache().Get(key); found { - env.Debug(val) - return val == "true" - } - var val bool - defer func() { - env.Cache().Set(key, strconv.FormatBool(val), -1) - }() - val = env.HasCommand("wslpath") - env.Debug(strconv.FormatBool(val)) - return val -} - -func (env *Shell) IsWsl2() bool { - defer env.Trace(time.Now()) - if !env.IsWsl() { - return false - } - uname := env.FileContent("/proc/sys/kernel/osrelease") - return strings.Contains(uname, "WSL2") -} - -func (env *Shell) TerminalWidth() (int, error) { - defer env.Trace(time.Now()) - - if env.CmdFlags.TerminalWidth > 0 { - env.DebugF("terminal width: %d", env.CmdFlags.TerminalWidth) - return env.CmdFlags.TerminalWidth, nil - } - - width, err := terminal.Width() - if err != nil { - env.Error(err) - } - - // fetch width from the environment variable - // in case the terminal width is not available - if width == 0 { - i, err := strconv.Atoi(env.Getenv("COLUMNS")) - if err != nil { - env.Error(err) - } - width = uint(i) - } - - env.CmdFlags.TerminalWidth = int(width) - env.DebugF("terminal width: %d", env.CmdFlags.TerminalWidth) - return env.CmdFlags.TerminalWidth, err -} - -func (env *Shell) Platform() string { - const key = "environment_platform" - if val, found := env.Cache().Get(key); found { - env.Debug(val) - return val - } - var platform string - defer func() { - env.Cache().Set(key, platform, -1) - }() - if wsl := env.Getenv("WSL_DISTRO_NAME"); len(wsl) != 0 { - platform = strings.Split(strings.ToLower(wsl), "-")[0] - env.Debug(platform) - return platform - } - platform, _, _, _ = host.PlatformInformation() - if platform == "arch" { - // validate for Manjaro - lsbInfo := env.FileContent("/etc/lsb-release") - if strings.Contains(strings.ToLower(lsbInfo), "manjaro") { - platform = "manjaro" - } - } - env.Debug(platform) - return platform -} - -func (env *Shell) CachePath() string { - defer env.Trace(time.Now()) - - // allow the user to set the cache path using OMP_CACHE_DIR - if cachePath := returnOrBuildCachePath(env.Getenv("OMP_CACHE_DIR")); len(cachePath) != 0 { - return cachePath - } - - // get XDG_CACHE_HOME if present - if cachePath := returnOrBuildCachePath(env.Getenv("XDG_CACHE_HOME")); len(cachePath) != 0 { - return cachePath - } - - // HOME cache folder - if cachePath := returnOrBuildCachePath(env.Home() + "/.cache"); len(cachePath) != 0 { - return cachePath - } - - return env.Home() -} - -func (env *Shell) WindowsRegistryKeyValue(_ string) (*WindowsRegistryValue, error) { - return nil, &NotImplemented{} -} - -func (env *Shell) InWSLSharedDrive() bool { - if !env.IsWsl2() { - return false - } - windowsPath := env.ConvertToWindowsPath(env.Pwd()) - return !strings.HasPrefix(windowsPath, `//wsl.localhost/`) && !strings.HasPrefix(windowsPath, `//wsl$/`) -} - -func (env *Shell) ConvertToWindowsPath(path string) string { - windowsPath, err := env.RunCommand("wslpath", "-m", path) - if err == nil { - return windowsPath - } - return path -} - -func (env *Shell) ConvertToLinuxPath(path string) string { - if linuxPath, err := env.RunCommand("wslpath", "-u", path); err == nil { - return linuxPath - } - return path -} - -func (env *Shell) LookPath(command string) (string, error) { - return exec.LookPath(command) -} - -func (env *Shell) DirIsWritable(path string) bool { - defer env.Trace(time.Now(), path) - return unix.Access(path, unix.W_OK) == nil -} - -func (env *Shell) Connection(_ ConnectionType) (*Connection, error) { - // added to disable the linting error, we can implement this later - if len(env.networks) == 0 { - return nil, &NotImplemented{} - } - return nil, &NotImplemented{} -} - -func (env *Shell) Memory() (*Memory, error) { - m := &Memory{} - memStat, err := mem.VirtualMemory() - if err != nil { - env.Error(err) - return nil, err - } - m.PhysicalTotalMemory = memStat.Total - m.PhysicalAvailableMemory = memStat.Available - m.PhysicalFreeMemory = memStat.Free - m.PhysicalPercentUsed = memStat.UsedPercent - swapStat, err := mem.SwapMemory() - if err != nil { - env.Error(err) - } - m.SwapTotalMemory = swapStat.Total - m.SwapFreeMemory = swapStat.Free - m.SwapPercentUsed = swapStat.UsedPercent - return m, nil -} diff --git a/src/platform/shell_windows_nix.go b/src/platform/shell_windows_nix.go deleted file mode 100644 index f3b01132..00000000 --- a/src/platform/shell_windows_nix.go +++ /dev/null @@ -1,19 +0,0 @@ -//go:build !darwin - -package platform - -import ( - "time" - - "github.com/jandedobbeleer/oh-my-posh/src/platform/battery" -) - -func (env *Shell) BatteryState() (*battery.Info, error) { - defer env.Trace(time.Now()) - info, err := battery.Get() - if err != nil { - env.Error(err) - return nil, err - } - return info, nil -} diff --git a/src/prompt/engine.go b/src/prompt/engine.go index 5964c05c..7bc70fc4 100644 --- a/src/prompt/engine.go +++ b/src/prompt/engine.go @@ -5,8 +5,8 @@ import ( "github.com/jandedobbeleer/oh-my-posh/src/color" "github.com/jandedobbeleer/oh-my-posh/src/config" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/regex" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/jandedobbeleer/oh-my-posh/src/shell" "github.com/jandedobbeleer/oh-my-posh/src/template" "github.com/jandedobbeleer/oh-my-posh/src/terminal" @@ -18,7 +18,7 @@ var ( type Engine struct { Config *config.Config - Env platform.Environment + Env runtime.Environment Plain bool console strings.Builder diff --git a/src/prompt/engine_test.go b/src/prompt/engine_test.go index f5a133be..46b843d4 100644 --- a/src/prompt/engine_test.go +++ b/src/prompt/engine_test.go @@ -6,7 +6,7 @@ import ( "github.com/jandedobbeleer/oh-my-posh/src/config" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/jandedobbeleer/oh-my-posh/src/shell" "github.com/jandedobbeleer/oh-my-posh/src/terminal" @@ -81,7 +81,7 @@ func TestPrintPWD(t *testing.T) { env.On("User").Return("user") env.On("Host").Return("host", nil) env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil) - env.On("TemplateCache").Return(&platform.TemplateCache{ + env.On("TemplateCache").Return(&runtime.TemplateCache{ Env: make(map[string]string), Shell: "shell", }) @@ -110,7 +110,7 @@ func BenchmarkEngineRender(b *testing.B) { } func engineRender() { - env := &platform.Shell{} + env := &runtime.Terminal{} env.Init() defer env.Close() @@ -175,7 +175,7 @@ func TestGetTitle(t *testing.T) { env.On("Home").Return("/usr/home") env.On("PathSeparator").Return(tc.PathSeparator) env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil) - env.On("TemplateCache").Return(&platform.TemplateCache{ + env.On("TemplateCache").Return(&runtime.TemplateCache{ Env: map[string]string{ "USERDOMAIN": "MyCompany", }, @@ -238,7 +238,7 @@ func TestGetConsoleTitleIfGethostnameReturnsError(t *testing.T) { env.On("Pwd").Return(tc.Cwd) env.On("Home").Return("/usr/home") env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil) - env.On("TemplateCache").Return(&platform.TemplateCache{ + env.On("TemplateCache").Return(&runtime.TemplateCache{ Env: map[string]string{ "USERDOMAIN": "MyCompany", }, diff --git a/src/prompt/new.go b/src/prompt/new.go index 70ae9b96..df8c4e96 100644 --- a/src/prompt/new.go +++ b/src/prompt/new.go @@ -2,7 +2,7 @@ package prompt import ( "github.com/jandedobbeleer/oh-my-posh/src/config" - "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/jandedobbeleer/oh-my-posh/src/shell" "github.com/jandedobbeleer/oh-my-posh/src/terminal" ) @@ -10,8 +10,8 @@ import ( // New returns a prompt engine initialized with the // given configuration options, and is ready to print any // of the prompt components. -func New(flags *platform.Flags) *Engine { - env := &platform.Shell{ +func New(flags *runtime.Flags) *Engine { + env := &runtime.Terminal{ CmdFlags: flags, } @@ -39,7 +39,7 @@ func New(flags *platform.Flags) *Engine { return eng } -func patchPowerShellBleed(sh string, flags *platform.Flags) { +func patchPowerShellBleed(sh string, flags *runtime.Flags) { // when in PowerShell, and force patching the bleed bug // we need to reduce the terminal width by 1 so the last // character isn't cut off by the ANSI escape sequences diff --git a/src/properties/properties.go b/src/properties/properties.go index ccdca7f2..5acccb9d 100644 --- a/src/properties/properties.go +++ b/src/properties/properties.go @@ -4,12 +4,12 @@ import ( "fmt" "github.com/jandedobbeleer/oh-my-posh/src/color" - "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Wrapper struct { Properties Map - Env platform.Environment + Env runtime.Environment } func (w *Wrapper) GetColor(property Property, defaultColor color.Ansi) color.Ansi { diff --git a/src/platform/battery/battery.go b/src/runtime/battery/battery.go similarity index 100% rename from src/platform/battery/battery.go rename to src/runtime/battery/battery.go diff --git a/src/platform/battery/battery_darwin.go b/src/runtime/battery/battery_darwin.go similarity index 96% rename from src/platform/battery/battery_darwin.go rename to src/runtime/battery/battery_darwin.go index 9c19e6b0..63bba524 100644 --- a/src/platform/battery/battery_darwin.go +++ b/src/runtime/battery/battery_darwin.go @@ -5,8 +5,8 @@ import ( "strconv" "strings" - "github.com/jandedobbeleer/oh-my-posh/src/platform/cmd" "github.com/jandedobbeleer/oh-my-posh/src/regex" + "github.com/jandedobbeleer/oh-my-posh/src/runtime/cmd" ) func mapMostLogicalState(state string) State { diff --git a/src/platform/battery/battery_darwin_test.go b/src/runtime/battery/battery_darwin_test.go similarity index 100% rename from src/platform/battery/battery_darwin_test.go rename to src/runtime/battery/battery_darwin_test.go diff --git a/src/platform/battery/battery_linux.go b/src/runtime/battery/battery_linux.go similarity index 100% rename from src/platform/battery/battery_linux.go rename to src/runtime/battery/battery_linux.go diff --git a/src/platform/battery/battery_netbsd.go b/src/runtime/battery/battery_netbsd.go similarity index 87% rename from src/platform/battery/battery_netbsd.go rename to src/runtime/battery/battery_netbsd.go index bb81e15a..d083c6fa 100644 --- a/src/platform/battery/battery_netbsd.go +++ b/src/runtime/battery/battery_netbsd.go @@ -5,7 +5,7 @@ import ( "strconv" "strings" - "github.com/jandedobbeleer/oh-my-posh/src/platform/cmd" + "github.com/jandedobbeleer/oh-my-posh/src/runtime/cmd" ) func Get() (*Info, error) { diff --git a/src/platform/battery/battery_openandfreebsd.go b/src/runtime/battery/battery_openandfreebsd.go similarity index 94% rename from src/platform/battery/battery_openandfreebsd.go rename to src/runtime/battery/battery_openandfreebsd.go index 4508e7e9..fe192cd2 100644 --- a/src/platform/battery/battery_openandfreebsd.go +++ b/src/runtime/battery/battery_openandfreebsd.go @@ -7,7 +7,7 @@ import ( "strconv" "strings" - "github.com/jandedobbeleer/oh-my-posh/src/platform/cmd" + "github.com/jandedobbeleer/oh-my-posh/src/runtime/cmd" ) // See https://man.openbsd.org/man8/apm.8 diff --git a/src/platform/battery/battery_openandfreebsd_test.go b/src/runtime/battery/battery_openandfreebsd_test.go similarity index 100% rename from src/platform/battery/battery_openandfreebsd_test.go rename to src/runtime/battery/battery_openandfreebsd_test.go diff --git a/src/platform/battery/battery_windows.go b/src/runtime/battery/battery_windows.go similarity index 100% rename from src/platform/battery/battery_windows.go rename to src/runtime/battery/battery_windows.go diff --git a/src/platform/battery/battery_windows_nix.go b/src/runtime/battery/battery_windows_nix.go similarity index 100% rename from src/platform/battery/battery_windows_nix.go rename to src/runtime/battery/battery_windows_nix.go diff --git a/src/platform/battery/battery_windows_nix_test.go b/src/runtime/battery/battery_windows_nix_test.go similarity index 100% rename from src/platform/battery/battery_windows_nix_test.go rename to src/runtime/battery/battery_windows_nix_test.go diff --git a/src/platform/battery/errors.go b/src/runtime/battery/errors.go similarity index 100% rename from src/platform/battery/errors.go rename to src/runtime/battery/errors.go diff --git a/src/platform/battery/errors_test.go b/src/runtime/battery/errors_test.go similarity index 100% rename from src/platform/battery/errors_test.go rename to src/runtime/battery/errors_test.go diff --git a/src/platform/cache.go b/src/runtime/cache.go similarity index 99% rename from src/platform/cache.go rename to src/runtime/cache.go index ad8655bb..f8f217c3 100644 --- a/src/platform/cache.go +++ b/src/runtime/cache.go @@ -1,4 +1,4 @@ -package platform +package runtime import ( "encoding/json" diff --git a/src/platform/cmd/run.go b/src/runtime/cmd/run.go similarity index 100% rename from src/platform/cmd/run.go rename to src/runtime/cmd/run.go diff --git a/src/platform/config/download.go b/src/runtime/config/download.go similarity index 97% rename from src/platform/config/download.go rename to src/runtime/config/download.go index ce624cec..8ba6b15c 100644 --- a/src/platform/config/download.go +++ b/src/runtime/config/download.go @@ -11,7 +11,7 @@ import ( "time" "github.com/jandedobbeleer/oh-my-posh/src/log" - "github.com/jandedobbeleer/oh-my-posh/src/platform/net" + "github.com/jandedobbeleer/oh-my-posh/src/runtime/net" ) func Download(cachePath, url string) (string, error) { diff --git a/src/platform/map.go b/src/runtime/map.go similarity index 98% rename from src/platform/map.go rename to src/runtime/map.go index fe929d34..10558324 100644 --- a/src/platform/map.go +++ b/src/runtime/map.go @@ -1,4 +1,4 @@ -package platform +package runtime import "sync" diff --git a/src/platform/net/http.go b/src/runtime/net/http.go similarity index 100% rename from src/platform/net/http.go rename to src/runtime/net/http.go diff --git a/src/platform/networks_windows.go b/src/runtime/networks_windows.go similarity index 96% rename from src/platform/networks_windows.go rename to src/runtime/networks_windows.go index 781bc219..76d13a4d 100644 --- a/src/platform/networks_windows.go +++ b/src/runtime/networks_windows.go @@ -1,4 +1,4 @@ -package platform +package runtime import ( "errors" @@ -144,7 +144,7 @@ type DOT11_SSID struct { ucSSID [DOT11_SSID_MAX_LENGTH]uint8 } -func (env *Shell) getConnections() []*Connection { +func (env *Terminal) getConnections() []*Connection { var pIFTable2 *MIN_IF_TABLE2 _, _, _ = hGetIfTable2.Call(uintptr(unsafe.Pointer(&pIFTable2))) @@ -199,7 +199,7 @@ func (env *Shell) getConnections() []*Connection { return networks } -func (env *Shell) wifiNetwork() (*Connection, error) { +func (env *Terminal) wifiNetwork() (*Connection, error) { env.Trace(time.Now()) // Open handle var pdwNegotiatedVersion uint32 @@ -234,7 +234,7 @@ func (env *Shell) wifiNetwork() (*Connection, error) { return nil, errors.New("Not connected") } -func (env *Shell) parseNetworkInterface(network *WLAN_INTERFACE_INFO, clientHandle uint32) (*Connection, error) { +func (env *Terminal) parseNetworkInterface(network *WLAN_INTERFACE_INFO, clientHandle uint32) (*Connection, error) { info := Connection{ Type: WIFI, } diff --git a/src/platform/shell.go b/src/runtime/os.go similarity index 61% rename from src/platform/shell.go rename to src/runtime/os.go index 83f9b939..c22eb0f1 100644 --- a/src/platform/shell.go +++ b/src/runtime/os.go @@ -1,4 +1,4 @@ -package platform +package runtime import ( "context" @@ -18,11 +18,11 @@ import ( "time" "github.com/jandedobbeleer/oh-my-posh/src/log" - "github.com/jandedobbeleer/oh-my-posh/src/platform/battery" - "github.com/jandedobbeleer/oh-my-posh/src/platform/cmd" - "github.com/jandedobbeleer/oh-my-posh/src/platform/config" - "github.com/jandedobbeleer/oh-my-posh/src/platform/net" "github.com/jandedobbeleer/oh-my-posh/src/regex" + "github.com/jandedobbeleer/oh-my-posh/src/runtime/battery" + "github.com/jandedobbeleer/oh-my-posh/src/runtime/cmd" + "github.com/jandedobbeleer/oh-my-posh/src/runtime/config" + "github.com/jandedobbeleer/oh-my-posh/src/runtime/net" disk "github.com/shirou/gopsutil/v3/disk" load "github.com/shirou/gopsutil/v3/load" @@ -194,7 +194,7 @@ type Environment interface { Trace(start time.Time, args ...string) } -type Shell struct { +type Terminal struct { CmdFlags *Flags Var SimpleMap @@ -210,144 +210,144 @@ type Shell struct { lsDirMap ConcurrentMap } -func (env *Shell) Init() { - defer env.Trace(time.Now()) - if env.CmdFlags == nil { - env.CmdFlags = &Flags{} +func (term *Terminal) Init() { + defer term.Trace(time.Now()) + if term.CmdFlags == nil { + term.CmdFlags = &Flags{} } - if env.CmdFlags.Debug { + if term.CmdFlags.Debug { log.Enable() } - if env.CmdFlags.Plain { + if term.CmdFlags.Plain { log.Plain() } - env.fileCache = &fileCache{} - env.fileCache.Init(env.CachePath()) - env.resolveConfigPath() - env.cmdCache = &commandCache{ + term.fileCache = &fileCache{} + term.fileCache.Init(term.CachePath()) + term.resolveConfigPath() + term.cmdCache = &commandCache{ commands: NewConcurrentMap(), } - env.tmplCache = &TemplateCache{} + term.tmplCache = &TemplateCache{} - env.SetPromptCount() + term.SetPromptCount() } -func (env *Shell) resolveConfigPath() { - defer env.Trace(time.Now()) +func (term *Terminal) resolveConfigPath() { + defer term.Trace(time.Now()) - if len(env.CmdFlags.Config) == 0 { - env.CmdFlags.Config = env.Getenv("POSH_THEME") + if len(term.CmdFlags.Config) == 0 { + term.CmdFlags.Config = term.Getenv("POSH_THEME") } - if len(env.CmdFlags.Config) == 0 { - env.Debug("No config set, fallback to default config") + if len(term.CmdFlags.Config) == 0 { + term.Debug("No config set, fallback to default config") return } - if strings.HasPrefix(env.CmdFlags.Config, "https://") { - filePath, err := config.Download(env.CachePath(), env.CmdFlags.Config) + if strings.HasPrefix(term.CmdFlags.Config, "https://") { + filePath, err := config.Download(term.CachePath(), term.CmdFlags.Config) if err != nil { - env.Error(err) - env.CmdFlags.Config = "" + term.Error(err) + term.CmdFlags.Config = "" return } - env.CmdFlags.Config = filePath + term.CmdFlags.Config = filePath return } // Cygwin path always needs the full path as we're on Windows but not really. // Doing filepath actions will convert it to a Windows path and break the init script. - if env.Platform() == WINDOWS && env.Shell() == "bash" { - env.Debug("Cygwin detected, using full path for config") + if term.Platform() == WINDOWS && term.Shell() == "bash" { + term.Debug("Cygwin detected, using full path for config") return } - configFile := env.CmdFlags.Config + configFile := term.CmdFlags.Config if strings.HasPrefix(configFile, "~") { configFile = strings.TrimPrefix(configFile, "~") - configFile = filepath.Join(env.Home(), configFile) + configFile = filepath.Join(term.Home(), configFile) } if !filepath.IsAbs(configFile) { - configFile = filepath.Join(env.Pwd(), configFile) + configFile = filepath.Join(term.Pwd(), configFile) } - env.CmdFlags.Config = filepath.Clean(configFile) + term.CmdFlags.Config = filepath.Clean(configFile) } -func (env *Shell) Trace(start time.Time, args ...string) { +func (term *Terminal) Trace(start time.Time, args ...string) { log.Trace(start, args...) } -func (env *Shell) Debug(message string) { +func (term *Terminal) Debug(message string) { log.Debug(message) } -func (env *Shell) DebugF(format string, a ...any) { - if !env.CmdFlags.Debug { +func (term *Terminal) DebugF(format string, a ...any) { + if !term.CmdFlags.Debug { return } message := fmt.Sprintf(format, a...) log.Debug(message) } -func (env *Shell) Error(err error) { +func (term *Terminal) Error(err error) { log.Error(err) } -func (env *Shell) Getenv(key string) string { - defer env.Trace(time.Now(), key) +func (term *Terminal) Getenv(key string) string { + defer term.Trace(time.Now(), key) val := os.Getenv(key) - env.Debug(val) + term.Debug(val) return val } -func (env *Shell) Pwd() string { - env.Lock() - defer env.Trace(time.Now()) - defer env.Unlock() - if env.cwd != "" { - return env.cwd +func (term *Terminal) Pwd() string { + term.Lock() + defer term.Trace(time.Now()) + defer term.Unlock() + if term.cwd != "" { + return term.cwd } correctPath := func(pwd string) string { - if env.GOOS() != WINDOWS { + if term.GOOS() != WINDOWS { return pwd } // on Windows, and being case sensitive and not consistent and all, this gives silly issues driveLetter := regex.GetCompiledRegex(`^[a-z]:`) return driveLetter.ReplaceAllStringFunc(pwd, strings.ToUpper) } - if env.CmdFlags != nil && env.CmdFlags.PWD != "" { - env.cwd = correctPath(env.CmdFlags.PWD) - env.Debug(env.cwd) - return env.cwd + if term.CmdFlags != nil && term.CmdFlags.PWD != "" { + term.cwd = correctPath(term.CmdFlags.PWD) + term.Debug(term.cwd) + return term.cwd } dir, err := os.Getwd() if err != nil { - env.Error(err) + term.Error(err) return "" } - env.cwd = correctPath(dir) - env.Debug(env.cwd) - return env.cwd + term.cwd = correctPath(dir) + term.Debug(term.cwd) + return term.cwd } -func (env *Shell) HasFiles(pattern string) bool { - return env.HasFilesInDir(env.Pwd(), pattern) +func (term *Terminal) HasFiles(pattern string) bool { + return term.HasFilesInDir(term.Pwd(), pattern) } -func (env *Shell) HasFilesInDir(dir, pattern string) bool { - defer env.Trace(time.Now(), pattern) +func (term *Terminal) HasFilesInDir(dir, pattern string) bool { + defer term.Trace(time.Now(), pattern) fileSystem := os.DirFS(dir) var dirEntries []fs.DirEntry - if files, OK := env.lsDirMap.Get(dir); OK { + if files, OK := term.lsDirMap.Get(dir); OK { dirEntries, _ = files.([]fs.DirEntry) } @@ -355,18 +355,18 @@ func (env *Shell) HasFilesInDir(dir, pattern string) bool { var err error dirEntries, err = fs.ReadDir(fileSystem, ".") if err != nil { - env.Error(err) - env.Debug("false") + term.Error(err) + term.Debug("false") return false } - env.lsDirMap.Set(dir, dirEntries) + term.lsDirMap.Set(dir, dirEntries) } pattern = strings.ToLower(pattern) - env.RWMutex.RLock() - defer env.RWMutex.RUnlock() + term.RWMutex.RLock() + defer term.RWMutex.RUnlock() for _, match := range dirEntries { if match.IsDir() { @@ -375,236 +375,236 @@ func (env *Shell) HasFilesInDir(dir, pattern string) bool { matchFileName, err := filepath.Match(pattern, strings.ToLower(match.Name())) if err != nil { - env.Error(err) - env.Debug("false") + term.Error(err) + term.Debug("false") return false } if matchFileName { - env.Debug("true") + term.Debug("true") return true } } - env.Debug("false") + term.Debug("false") return false } -func (env *Shell) HasFileInParentDirs(pattern string, depth uint) bool { - defer env.Trace(time.Now(), pattern, fmt.Sprint(depth)) - currentFolder := env.Pwd() +func (term *Terminal) HasFileInParentDirs(pattern string, depth uint) bool { + defer term.Trace(time.Now(), pattern, fmt.Sprint(depth)) + currentFolder := term.Pwd() for c := 0; c < int(depth); c++ { - if env.HasFilesInDir(currentFolder, pattern) { - env.Debug("true") + if term.HasFilesInDir(currentFolder, pattern) { + term.Debug("true") return true } if dir := filepath.Dir(currentFolder); dir != currentFolder { currentFolder = dir } else { - env.Debug("false") + term.Debug("false") return false } } - env.Debug("false") + term.Debug("false") return false } -func (env *Shell) HasFolder(folder string) bool { - defer env.Trace(time.Now(), folder) +func (term *Terminal) HasFolder(folder string) bool { + defer term.Trace(time.Now(), folder) f, err := os.Stat(folder) if err != nil { - env.Debug("false") + term.Debug("false") return false } isDir := f.IsDir() - env.DebugF("%t", isDir) + term.DebugF("%t", isDir) return isDir } -func (env *Shell) ResolveSymlink(path string) (string, error) { - defer env.Trace(time.Now(), path) +func (term *Terminal) ResolveSymlink(path string) (string, error) { + defer term.Trace(time.Now(), path) link, err := filepath.EvalSymlinks(path) if err != nil { - env.Error(err) + term.Error(err) return "", err } - env.Debug(link) + term.Debug(link) return link, nil } -func (env *Shell) FileContent(file string) string { - defer env.Trace(time.Now(), file) +func (term *Terminal) FileContent(file string) string { + defer term.Trace(time.Now(), file) if !filepath.IsAbs(file) { - file = filepath.Join(env.Pwd(), file) + file = filepath.Join(term.Pwd(), file) } content, err := os.ReadFile(file) if err != nil { - env.Error(err) + term.Error(err) return "" } fileContent := string(content) - env.Debug(fileContent) + term.Debug(fileContent) return fileContent } -func (env *Shell) LsDir(path string) []fs.DirEntry { - defer env.Trace(time.Now(), path) +func (term *Terminal) LsDir(path string) []fs.DirEntry { + defer term.Trace(time.Now(), path) entries, err := os.ReadDir(path) if err != nil { - env.Error(err) + term.Error(err) return nil } - env.DebugF("%v", entries) + term.DebugF("%v", entries) return entries } -func (env *Shell) PathSeparator() string { - defer env.Trace(time.Now()) +func (term *Terminal) PathSeparator() string { + defer term.Trace(time.Now()) return string(os.PathSeparator) } -func (env *Shell) User() string { - defer env.Trace(time.Now()) +func (term *Terminal) User() string { + defer term.Trace(time.Now()) user := os.Getenv("USER") if user == "" { user = os.Getenv("USERNAME") } - env.Debug(user) + term.Debug(user) return user } -func (env *Shell) Host() (string, error) { - defer env.Trace(time.Now()) - if len(env.host) != 0 { - return env.host, nil +func (term *Terminal) Host() (string, error) { + defer term.Trace(time.Now()) + if len(term.host) != 0 { + return term.host, nil } hostName, err := os.Hostname() if err != nil { - env.Error(err) + term.Error(err) return "", err } hostName = cleanHostName(hostName) - env.Debug(hostName) - env.host = hostName + term.Debug(hostName) + term.host = hostName return hostName, nil } -func (env *Shell) GOOS() string { - defer env.Trace(time.Now()) +func (term *Terminal) GOOS() string { + defer term.Trace(time.Now()) return runtime.GOOS } -func (env *Shell) RunCommand(command string, args ...string) (string, error) { - defer env.Trace(time.Now(), append([]string{command}, args...)...) - if cacheCommand, ok := env.cmdCache.get(command); ok { +func (term *Terminal) RunCommand(command string, args ...string) (string, error) { + defer term.Trace(time.Now(), append([]string{command}, args...)...) + if cacheCommand, ok := term.cmdCache.get(command); ok { command = cacheCommand } output, err := cmd.Run(command, args...) if err != nil { - env.Error(err) + term.Error(err) } - env.Debug(output) + term.Debug(output) return output, err } -func (env *Shell) RunShellCommand(shell, command string) string { - defer env.Trace(time.Now()) - if out, err := env.RunCommand(shell, "-c", command); err == nil { +func (term *Terminal) RunShellCommand(shell, command string) string { + defer term.Trace(time.Now()) + if out, err := term.RunCommand(shell, "-c", command); err == nil { return out } return "" } -func (env *Shell) CommandPath(command string) string { - defer env.Trace(time.Now(), command) - if path, ok := env.cmdCache.get(command); ok { - env.Debug(path) +func (term *Terminal) CommandPath(command string) string { + defer term.Trace(time.Now(), command) + if path, ok := term.cmdCache.get(command); ok { + term.Debug(path) return path } - path, err := env.LookPath(command) + path, err := term.LookPath(command) if err == nil { - env.cmdCache.set(command, path) - env.Debug(path) + term.cmdCache.set(command, path) + term.Debug(path) return path } - env.Error(err) + term.Error(err) return "" } -func (env *Shell) HasCommand(command string) bool { - defer env.Trace(time.Now(), command) - if path := env.CommandPath(command); path != "" { +func (term *Terminal) HasCommand(command string) bool { + defer term.Trace(time.Now(), command) + if path := term.CommandPath(command); path != "" { return true } return false } -func (env *Shell) StatusCodes() (int, string) { - defer env.Trace(time.Now()) +func (term *Terminal) StatusCodes() (int, string) { + defer term.Trace(time.Now()) - if env.CmdFlags.Shell != CMD || !env.CmdFlags.NoExitCode { - return env.CmdFlags.ErrorCode, env.CmdFlags.PipeStatus + if term.CmdFlags.Shell != CMD || !term.CmdFlags.NoExitCode { + return term.CmdFlags.ErrorCode, term.CmdFlags.PipeStatus } - errorCode := env.Getenv("=ExitCode") - env.Debug(errorCode) - env.CmdFlags.ErrorCode, _ = strconv.Atoi(errorCode) + errorCode := term.Getenv("=ExitCode") + term.Debug(errorCode) + term.CmdFlags.ErrorCode, _ = strconv.Atoi(errorCode) - return env.CmdFlags.ErrorCode, env.CmdFlags.PipeStatus + return term.CmdFlags.ErrorCode, term.CmdFlags.PipeStatus } -func (env *Shell) ExecutionTime() float64 { - defer env.Trace(time.Now()) - if env.CmdFlags.ExecutionTime < 0 { +func (term *Terminal) ExecutionTime() float64 { + defer term.Trace(time.Now()) + if term.CmdFlags.ExecutionTime < 0 { return 0 } - return env.CmdFlags.ExecutionTime + return term.CmdFlags.ExecutionTime } -func (env *Shell) Flags() *Flags { - defer env.Trace(time.Now()) - return env.CmdFlags +func (term *Terminal) Flags() *Flags { + defer term.Trace(time.Now()) + return term.CmdFlags } -func (env *Shell) Shell() string { - defer env.Trace(time.Now()) - if len(env.CmdFlags.Shell) != 0 { - return env.CmdFlags.Shell +func (term *Terminal) Shell() string { + defer term.Trace(time.Now()) + if len(term.CmdFlags.Shell) != 0 { + return term.CmdFlags.Shell } - env.Debug("no shell name provided in flags, trying to detect it") + term.Debug("no shell name provided in flags, trying to detect it") pid := os.Getppid() p, _ := process.NewProcess(int32(pid)) name, err := p.Name() if err != nil { - env.Error(err) + term.Error(err) return UNKNOWN } - env.Debug("process name: " + name) + term.Debug("process name: " + name) // this is used for when scoop creates a shim, see // https://github.com/jandedobbeleer/oh-my-posh/issues/2806 executable, _ := os.Executable() if name == executable { p, _ = p.Parent() name, err = p.Name() - env.Debug("parent process name: " + name) + term.Debug("parent process name: " + name) } if err != nil { - env.Error(err) + term.Error(err) return UNKNOWN } // Cache the shell value to speed things up. - env.CmdFlags.Shell = strings.Trim(strings.TrimSuffix(name, ".exe"), " ") - return env.CmdFlags.Shell + term.CmdFlags.Shell = strings.Trim(strings.TrimSuffix(name, ".exe"), " ") + return term.CmdFlags.Shell } -func (env *Shell) unWrapError(err error) error { +func (term *Terminal) unWrapError(err error) error { cause := err for { type nested interface{ Unwrap() error } @@ -617,8 +617,8 @@ func (env *Shell) unWrapError(err error) error { return cause } -func (env *Shell) HTTPRequest(targetURL string, body io.Reader, timeout int, requestModifiers ...HTTPRequestModifier) ([]byte, error) { - defer env.Trace(time.Now(), targetURL) +func (term *Terminal) HTTPRequest(targetURL string, body io.Reader, timeout int, requestModifiers ...HTTPRequestModifier) ([]byte, error) { + defer term.Trace(time.Now(), targetURL) ctx, cncl := context.WithTimeout(context.Background(), time.Millisecond*time.Duration(timeout)) defer cncl() @@ -632,22 +632,22 @@ func (env *Shell) HTTPRequest(targetURL string, body io.Reader, timeout int, req modifier(request) } - if env.CmdFlags.Debug { + if term.CmdFlags.Debug { dump, _ := httputil.DumpRequestOut(request, true) - env.Debug(string(dump)) + term.Debug(string(dump)) } response, err := net.HTTPClient.Do(request) if err != nil { - env.Error(err) - return nil, env.unWrapError(err) + term.Error(err) + return nil, term.unWrapError(err) } // anything inside the range [200, 299] is considered a success if response.StatusCode < 200 || response.StatusCode >= 300 { message := "HTTP status code " + strconv.Itoa(response.StatusCode) err := errors.New(message) - env.Error(err) + term.Error(err) return nil, err } @@ -655,18 +655,18 @@ func (env *Shell) HTTPRequest(targetURL string, body io.Reader, timeout int, req responseBody, err := io.ReadAll(response.Body) if err != nil { - env.Error(err) + term.Error(err) return nil, err } - env.Debug(string(responseBody)) + term.Debug(string(responseBody)) return responseBody, nil } -func (env *Shell) HasParentFilePath(path string) (*FileInfo, error) { - defer env.Trace(time.Now(), path) - currentFolder := env.Pwd() +func (term *Terminal) HasParentFilePath(path string) (*FileInfo, error) { + defer term.Trace(time.Now(), path) + currentFolder := term.Pwd() for { fileSystem := os.DirFS(currentFolder) info, err := fs.Stat(fileSystem, path) @@ -684,68 +684,68 @@ func (env *Shell) HasParentFilePath(path string) (*FileInfo, error) { currentFolder = dir continue } - env.Error(err) + term.Error(err) return nil, errors.New("no match at root level") } } -func (env *Shell) StackCount() int { - defer env.Trace(time.Now()) - if env.CmdFlags.StackCount < 0 { +func (term *Terminal) StackCount() int { + defer term.Trace(time.Now()) + if term.CmdFlags.StackCount < 0 { return 0 } - return env.CmdFlags.StackCount + return term.CmdFlags.StackCount } -func (env *Shell) Cache() Cache { - return env.fileCache +func (term *Terminal) Cache() Cache { + return term.fileCache } -func (env *Shell) saveTemplateCache() { +func (term *Terminal) saveTemplateCache() { // only store this when in a primary prompt // and when we have a transient prompt in the config - canSave := env.CmdFlags.Primary && env.CmdFlags.HasTransient + canSave := term.CmdFlags.Primary && term.CmdFlags.HasTransient if !canSave { return } - cache := env.TemplateCache() + cache := term.TemplateCache() cache.SegmentsCache = cache.Segments.SimpleMap() templateCache, err := json.Marshal(cache) if err == nil { - env.fileCache.Set(TEMPLATECACHE, string(templateCache), 1440) + term.fileCache.Set(TEMPLATECACHE, string(templateCache), 1440) } } -func (env *Shell) Close() { - defer env.Trace(time.Now()) - env.saveTemplateCache() - env.fileCache.Close() +func (term *Terminal) Close() { + defer term.Trace(time.Now()) + term.saveTemplateCache() + term.fileCache.Close() } -func (env *Shell) LoadTemplateCache() { - defer env.Trace(time.Now()) - val, OK := env.fileCache.Get(TEMPLATECACHE) +func (term *Terminal) LoadTemplateCache() { + defer term.Trace(time.Now()) + val, OK := term.fileCache.Get(TEMPLATECACHE) if !OK { return } var tmplCache TemplateCache err := json.Unmarshal([]byte(val), &tmplCache) if err != nil { - env.Error(err) + term.Error(err) return } tmplCache.Segments = tmplCache.SegmentsCache.ConcurrentMap() tmplCache.initialized = true - env.tmplCache = &tmplCache + term.tmplCache = &tmplCache } -func (env *Shell) Logs() string { +func (term *Terminal) Logs() string { return log.String() } -func (env *Shell) TemplateCache() *TemplateCache { - defer env.Trace(time.Now()) - tmplCache := env.tmplCache +func (term *Terminal) TemplateCache() *TemplateCache { + defer term.Trace(time.Now()) + tmplCache := term.tmplCache tmplCache.Lock() defer tmplCache.Unlock() @@ -753,23 +753,23 @@ func (env *Shell) TemplateCache() *TemplateCache { return tmplCache } - tmplCache.Root = env.Root() - tmplCache.Shell = env.Shell() - tmplCache.ShellVersion = env.CmdFlags.ShellVersion - tmplCache.Code, _ = env.StatusCodes() - tmplCache.WSL = env.IsWsl() + tmplCache.Root = term.Root() + tmplCache.Shell = term.Shell() + tmplCache.ShellVersion = term.CmdFlags.ShellVersion + tmplCache.Code, _ = term.StatusCodes() + tmplCache.WSL = term.IsWsl() tmplCache.Segments = NewConcurrentMap() - tmplCache.PromptCount = env.CmdFlags.PromptCount + tmplCache.PromptCount = term.CmdFlags.PromptCount tmplCache.Env = make(map[string]string) tmplCache.Var = make(map[string]any) - if env.Var != nil { - tmplCache.Var = env.Var + if term.Var != nil { + tmplCache.Var = term.Var } const separator = "=" values := os.Environ() - env.DebugF("environment: %v", values) + term.DebugF("environment: %v", values) for value := range values { key, val, valid := strings.Cut(values[value], separator) if !valid { @@ -778,31 +778,31 @@ func (env *Shell) TemplateCache() *TemplateCache { tmplCache.Env[key] = val } - pwd := env.Pwd() - tmplCache.PWD = ReplaceHomeDirPrefixWithTilde(env, pwd) + pwd := term.Pwd() + tmplCache.PWD = ReplaceHomeDirPrefixWithTilde(term, pwd) tmplCache.AbsolutePWD = pwd - if env.IsWsl() { - tmplCache.AbsolutePWD, _ = env.RunCommand("wslpath", "-m", pwd) + if term.IsWsl() { + tmplCache.AbsolutePWD, _ = term.RunCommand("wslpath", "-m", pwd) } - tmplCache.Folder = Base(env, pwd) - if env.GOOS() == WINDOWS && strings.HasSuffix(tmplCache.Folder, ":") { + tmplCache.Folder = Base(term, pwd) + if term.GOOS() == WINDOWS && strings.HasSuffix(tmplCache.Folder, ":") { tmplCache.Folder += `\` } - tmplCache.UserName = env.User() - if host, err := env.Host(); err == nil { + tmplCache.UserName = term.User() + if host, err := term.Host(); err == nil { tmplCache.HostName = host } - goos := env.GOOS() + goos := term.GOOS() tmplCache.OS = goos if goos == LINUX { - tmplCache.OS = env.Platform() + tmplCache.OS = term.Platform() } - val := env.Getenv("SHLVL") + val := term.Getenv("SHLVL") if shlvl, err := strconv.Atoi(val); err == nil { tmplCache.SHLVL = shlvl } @@ -811,17 +811,17 @@ func (env *Shell) TemplateCache() *TemplateCache { return tmplCache } -func (env *Shell) DirMatchesOneOf(dir string, regexes []string) (match bool) { +func (term *Terminal) DirMatchesOneOf(dir string, regexes []string) (match bool) { // sometimes the function panics inside golang, we want to silence that error // and assume that there's no match. Not perfect, but better than crashing // for the time being until we figure out what the actual root cause is defer func() { if err := recover(); err != nil { - env.Error(errors.New("panic")) + term.Error(errors.New("panic")) match = false } }() - match = dirMatchesOneOf(dir, env.Home(), env.GOOS(), regexes) + match = dirMatchesOneOf(dir, term.Home(), term.GOOS(), regexes) return } @@ -852,42 +852,42 @@ func dirMatchesOneOf(dir, home, goos string, regexes []string) bool { return false } -func (env *Shell) SetPromptCount() { +func (term *Terminal) SetPromptCount() { countStr := os.Getenv("POSH_PROMPT_COUNT") if len(countStr) > 0 { // this counter is incremented by the shell count, err := strconv.Atoi(countStr) if err == nil { - env.CmdFlags.PromptCount = count + term.CmdFlags.PromptCount = count return } } var count int - if val, found := env.Cache().Get(PROMPTCOUNTCACHE); found { + if val, found := term.Cache().Get(PROMPTCOUNTCACHE); found { count, _ = strconv.Atoi(val) } // only write to cache if we're the primary prompt - if env.CmdFlags.Primary { + if term.CmdFlags.Primary { count++ - env.Cache().Set(PROMPTCOUNTCACHE, strconv.Itoa(count), 1440) + term.Cache().Set(PROMPTCOUNTCACHE, strconv.Itoa(count), 1440) } - env.CmdFlags.PromptCount = count + term.CmdFlags.PromptCount = count } -func (env *Shell) CursorPosition() (row, col int) { - if number, err := strconv.Atoi(env.Getenv("POSH_CURSOR_LINE")); err == nil { +func (term *Terminal) CursorPosition() (row, col int) { + if number, err := strconv.Atoi(term.Getenv("POSH_CURSOR_LINE")); err == nil { row = number } - if number, err := strconv.Atoi(env.Getenv("POSH_CURSOR_COLUMN")); err != nil { + if number, err := strconv.Atoi(term.Getenv("POSH_CURSOR_COLUMN")); err != nil { col = number } return } -func (env *Shell) SystemInfo() (*SystemInfo, error) { +func (term *Terminal) SystemInfo() (*SystemInfo, error) { s := &SystemInfo{} - mem, err := env.Memory() + mem, err := term.Memory() if err != nil { return nil, err } diff --git a/src/platform/shell_darwin.go b/src/runtime/os_darwin.go similarity index 73% rename from src/platform/shell_darwin.go rename to src/runtime/os_darwin.go index 4d9cc0f3..1e730f01 100644 --- a/src/platform/shell_darwin.go +++ b/src/runtime/os_darwin.go @@ -1,4 +1,4 @@ -package platform +package runtime import ( "errors" @@ -8,7 +8,7 @@ import ( "github.com/jandedobbeleer/oh-my-posh/src/regex" - "github.com/jandedobbeleer/oh-my-posh/src/platform/battery" + "github.com/jandedobbeleer/oh-my-posh/src/runtime/battery" ) func mapMostLogicalState(state string) battery.State { @@ -30,17 +30,17 @@ func mapMostLogicalState(state string) battery.State { } } -func (env *Shell) parseBatteryOutput(output string) (*battery.Info, error) { +func (term *Terminal) parseBatteryOutput(output string) (*battery.Info, error) { matches := regex.FindNamedRegexMatch(`(?P[0-9]{1,3})%; (?P[a-zA-Z\s]+);`, output) if len(matches) != 2 { err := errors.New("Unable to find battery state based on output") - env.Error(err) + term.Error(err) return nil, err } var percentage int var err error if percentage, err = strconv.Atoi(matches["PERCENTAGE"]); err != nil { - env.Error(err) + term.Error(err) return nil, errors.New("Unable to parse battery percentage") } return &battery.Info{ @@ -49,15 +49,15 @@ func (env *Shell) parseBatteryOutput(output string) (*battery.Info, error) { }, nil } -func (env *Shell) BatteryState() (*battery.Info, error) { - defer env.Trace(time.Now()) - output, err := env.RunCommand("pmset", "-g", "batt") +func (term *Terminal) BatteryState() (*battery.Info, error) { + defer term.Trace(time.Now()) + output, err := term.RunCommand("pmset", "-g", "batt") if err != nil { - env.Error(err) + term.Error(err) return nil, err } if !strings.Contains(output, "Battery") { return nil, errors.New("No battery found") } - return env.parseBatteryOutput(output) + return term.parseBatteryOutput(output) } diff --git a/src/platform/shell_test.go b/src/runtime/os_test.go similarity index 99% rename from src/platform/shell_test.go rename to src/runtime/os_test.go index d23d45b7..316162fe 100644 --- a/src/platform/shell_test.go +++ b/src/runtime/os_test.go @@ -1,4 +1,4 @@ -package platform +package runtime import ( "testing" diff --git a/src/runtime/os_unix.go b/src/runtime/os_unix.go new file mode 100644 index 00000000..f095b141 --- /dev/null +++ b/src/runtime/os_unix.go @@ -0,0 +1,195 @@ +//go:build !windows + +package runtime + +import ( + "os" + "os/exec" + "strconv" + "strings" + "time" + + "github.com/shirou/gopsutil/v3/host" + mem "github.com/shirou/gopsutil/v3/mem" + terminal "github.com/wayneashleyberry/terminal-dimensions" + "golang.org/x/sys/unix" +) + +func (term *Terminal) Root() bool { + defer term.Trace(time.Now()) + return os.Geteuid() == 0 +} + +func (term *Terminal) Home() string { + return os.Getenv("HOME") +} + +func (term *Terminal) QueryWindowTitles(_, _ string) (string, error) { + return "", &NotImplemented{} +} + +func (term *Terminal) IsWsl() bool { + defer term.Trace(time.Now()) + const key = "is_wsl" + if val, found := term.Cache().Get(key); found { + term.Debug(val) + return val == "true" + } + var val bool + defer func() { + term.Cache().Set(key, strconv.FormatBool(val), -1) + }() + val = term.HasCommand("wslpath") + term.Debug(strconv.FormatBool(val)) + return val +} + +func (term *Terminal) IsWsl2() bool { + defer term.Trace(time.Now()) + if !term.IsWsl() { + return false + } + uname := term.FileContent("/proc/sys/kernel/osrelease") + return strings.Contains(uname, "WSL2") +} + +func (term *Terminal) TerminalWidth() (int, error) { + defer term.Trace(time.Now()) + + if term.CmdFlags.TerminalWidth > 0 { + term.DebugF("terminal width: %d", term.CmdFlags.TerminalWidth) + return term.CmdFlags.TerminalWidth, nil + } + + width, err := terminal.Width() + if err != nil { + term.Error(err) + } + + // fetch width from the environment variable + // in case the terminal width is not available + if width == 0 { + i, err := strconv.Atoi(term.Getenv("COLUMNS")) + if err != nil { + term.Error(err) + } + width = uint(i) + } + + term.CmdFlags.TerminalWidth = int(width) + term.DebugF("terminal width: %d", term.CmdFlags.TerminalWidth) + return term.CmdFlags.TerminalWidth, err +} + +func (term *Terminal) Platform() string { + const key = "environment_platform" + if val, found := term.Cache().Get(key); found { + term.Debug(val) + return val + } + var platform string + defer func() { + term.Cache().Set(key, platform, -1) + }() + if wsl := term.Getenv("WSL_DISTRO_NAME"); len(wsl) != 0 { + platform = strings.Split(strings.ToLower(wsl), "-")[0] + term.Debug(platform) + return platform + } + platform, _, _, _ = host.PlatformInformation() + if platform == "arch" { + // validate for Manjaro + lsbInfo := term.FileContent("/etc/lsb-release") + if strings.Contains(strings.ToLower(lsbInfo), "manjaro") { + platform = "manjaro" + } + } + term.Debug(platform) + return platform +} + +func (term *Terminal) CachePath() string { + defer term.Trace(time.Now()) + + // allow the user to set the cache path using OMP_CACHE_DIR + if cachePath := returnOrBuildCachePath(term.Getenv("OMP_CACHE_DIR")); len(cachePath) != 0 { + return cachePath + } + + // get XDG_CACHE_HOME if present + if cachePath := returnOrBuildCachePath(term.Getenv("XDG_CACHE_HOME")); len(cachePath) != 0 { + return cachePath + } + + // HOME cache folder + if cachePath := returnOrBuildCachePath(term.Home() + "/.cache"); len(cachePath) != 0 { + return cachePath + } + + return term.Home() +} + +func (term *Terminal) WindowsRegistryKeyValue(_ string) (*WindowsRegistryValue, error) { + return nil, &NotImplemented{} +} + +func (term *Terminal) InWSLSharedDrive() bool { + if !term.IsWsl2() { + return false + } + windowsPath := term.ConvertToWindowsPath(term.Pwd()) + return !strings.HasPrefix(windowsPath, `//wsl.localhost/`) && !strings.HasPrefix(windowsPath, `//wsl$/`) +} + +func (term *Terminal) ConvertToWindowsPath(path string) string { + windowsPath, err := term.RunCommand("wslpath", "-m", path) + if err == nil { + return windowsPath + } + return path +} + +func (term *Terminal) ConvertToLinuxPath(path string) string { + if linuxPath, err := term.RunCommand("wslpath", "-u", path); err == nil { + return linuxPath + } + return path +} + +func (term *Terminal) LookPath(command string) (string, error) { + return exec.LookPath(command) +} + +func (term *Terminal) DirIsWritable(path string) bool { + defer term.Trace(time.Now(), path) + return unix.Access(path, unix.W_OK) == nil +} + +func (term *Terminal) Connection(_ ConnectionType) (*Connection, error) { + // added to disable the linting error, we can implement this later + if len(term.networks) == 0 { + return nil, &NotImplemented{} + } + return nil, &NotImplemented{} +} + +func (term *Terminal) Memory() (*Memory, error) { + m := &Memory{} + memStat, err := mem.VirtualMemory() + if err != nil { + term.Error(err) + return nil, err + } + m.PhysicalTotalMemory = memStat.Total + m.PhysicalAvailableMemory = memStat.Available + m.PhysicalFreeMemory = memStat.Free + m.PhysicalPercentUsed = memStat.UsedPercent + swapStat, err := mem.SwapMemory() + if err != nil { + term.Error(err) + } + m.SwapTotalMemory = swapStat.Total + m.SwapFreeMemory = swapStat.Free + m.SwapPercentUsed = swapStat.UsedPercent + return m, nil +} diff --git a/src/platform/shell_windows.go b/src/runtime/os_windows.go similarity index 68% rename from src/platform/shell_windows.go rename to src/runtime/os_windows.go index 9a94608b..7eb4b694 100644 --- a/src/platform/shell_windows.go +++ b/src/runtime/os_windows.go @@ -1,4 +1,4 @@ -package platform +package runtime import ( "errors" @@ -15,8 +15,8 @@ import ( "golang.org/x/sys/windows/registry" ) -func (env *Shell) Root() bool { - defer env.Trace(time.Now()) +func (term *Terminal) Root() bool { + defer term.Trace(time.Now()) var sid *windows.SID // Although this looks scary, it is directly copied from the @@ -31,7 +31,7 @@ func (env *Shell) Root() bool { 0, 0, 0, 0, 0, 0, &sid) if err != nil { - env.Error(err) + term.Error(err) return false } defer func() { @@ -45,17 +45,17 @@ func (env *Shell) Root() bool { member, err := token.IsMember(sid) if err != nil { - env.Error(err) + term.Error(err) return false } return member } -func (env *Shell) Home() string { +func (term *Terminal) Home() string { home := os.Getenv("HOME") defer func() { - env.Debug(home) + term.Debug(home) }() if len(home) > 0 { return home @@ -68,61 +68,61 @@ func (env *Shell) Home() string { return home } -func (env *Shell) QueryWindowTitles(processName, windowTitleRegex string) (string, error) { - defer env.Trace(time.Now(), windowTitleRegex) +func (term *Terminal) QueryWindowTitles(processName, windowTitleRegex string) (string, error) { + defer term.Trace(time.Now(), windowTitleRegex) title, err := queryWindowTitles(processName, windowTitleRegex) if err != nil { - env.Error(err) + term.Error(err) } return title, err } -func (env *Shell) IsWsl() bool { - defer env.Trace(time.Now()) +func (term *Terminal) IsWsl() bool { + defer term.Trace(time.Now()) return false } -func (env *Shell) IsWsl2() bool { - defer env.Trace(time.Now()) +func (term *Terminal) IsWsl2() bool { + defer term.Trace(time.Now()) return false } -func (env *Shell) TerminalWidth() (int, error) { - defer env.Trace(time.Now()) +func (term *Terminal) TerminalWidth() (int, error) { + defer term.Trace(time.Now()) - if env.CmdFlags.TerminalWidth > 0 { - env.DebugF("terminal width: %d", env.CmdFlags.TerminalWidth) - return env.CmdFlags.TerminalWidth, nil + if term.CmdFlags.TerminalWidth > 0 { + term.DebugF("terminal width: %d", term.CmdFlags.TerminalWidth) + return term.CmdFlags.TerminalWidth, nil } handle, err := syscall.Open("CONOUT$", syscall.O_RDWR, 0) if err != nil { - env.Error(err) + term.Error(err) return 0, err } info, err := winterm.GetConsoleScreenBufferInfo(uintptr(handle)) if err != nil { - env.Error(err) + term.Error(err) return 0, err } - env.CmdFlags.TerminalWidth = int(info.Size.X) - env.DebugF("terminal width: %d", env.CmdFlags.TerminalWidth) - return env.CmdFlags.TerminalWidth, nil + term.CmdFlags.TerminalWidth = int(info.Size.X) + term.DebugF("terminal width: %d", term.CmdFlags.TerminalWidth) + return term.CmdFlags.TerminalWidth, nil } -func (env *Shell) Platform() string { +func (term *Terminal) Platform() string { return WINDOWS } -func (env *Shell) CachePath() string { - defer env.Trace(time.Now()) +func (term *Terminal) CachePath() string { + defer term.Trace(time.Now()) // get LOCALAPPDATA if present - if cachePath := returnOrBuildCachePath(env.Getenv("LOCALAPPDATA")); len(cachePath) != 0 { + if cachePath := returnOrBuildCachePath(term.Getenv("LOCALAPPDATA")); len(cachePath) != 0 { return cachePath } - return env.Home() + return term.Home() } // Takes a registry path to a key like @@ -134,8 +134,8 @@ func (env *Shell) CachePath() string { // 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 *Shell) WindowsRegistryKeyValue(path string) (*WindowsRegistryValue, error) { - env.Trace(time.Now(), path) +func (term *Terminal) WindowsRegistryKeyValue(path string) (*WindowsRegistryValue, error) { + term.Trace(time.Now(), path) // Format:sudo -u postgres psql // "HKLM\Software\Microsoft\Windows NT\CurrentVersion\EditionID" @@ -152,13 +152,13 @@ func (env *Shell) WindowsRegistryKeyValue(path string) (*WindowsRegistryValue, e rootKey, regPath, found := strings.Cut(path, `\`) if !found { err := fmt.Errorf("Error, malformed registry path: '%s'", path) - env.Error(err) + term.Error(err) return nil, err } var regKey string if !strings.HasSuffix(regPath, `\`) { - regKey = Base(env, regPath) + regKey = Base(term, regPath) if len(regKey) != 0 { regPath = strings.TrimSuffix(regPath, `\`+regKey) } @@ -178,18 +178,18 @@ func (env *Shell) WindowsRegistryKeyValue(path string) (*WindowsRegistryValue, e key = windows.HKEY_USERS default: err := fmt.Errorf("Error, unknown registry key: '%s", rootKey) - env.Error(err) + term.Error(err) return nil, err } k, err := registry.OpenKey(key, regPath, registry.READ) if err != nil { - env.Error(err) + term.Error(err) return nil, err } _, valType, err := k.GetValue(regKey, nil) if err != nil { - env.Error(err) + term.Error(err) return nil, err } @@ -214,46 +214,46 @@ func (env *Shell) WindowsRegistryKeyValue(path string) (*WindowsRegistryValue, e errorLogMsg := fmt.Sprintf("Error, no formatter for type: %d", valType) return nil, errors.New(errorLogMsg) } - env.Debug(fmt.Sprintf("%s(%s): %s", regKey, regValue.ValueType, regValue.String)) + term.Debug(fmt.Sprintf("%s(%s): %s", regKey, regValue.ValueType, regValue.String)) return regValue, nil } -func (env *Shell) InWSLSharedDrive() bool { +func (term *Terminal) InWSLSharedDrive() bool { return false } -func (env *Shell) ConvertToWindowsPath(path string) string { +func (term *Terminal) ConvertToWindowsPath(path string) string { return strings.ReplaceAll(path, `\`, "/") } -func (env *Shell) ConvertToLinuxPath(path string) string { +func (term *Terminal) ConvertToLinuxPath(path string) string { return path } -func (env *Shell) DirIsWritable(path string) bool { - defer env.Trace(time.Now()) - return env.isWriteable(path) +func (term *Terminal) DirIsWritable(path string) bool { + defer term.Trace(time.Now()) + return term.isWriteable(path) } -func (env *Shell) Connection(connectionType ConnectionType) (*Connection, error) { - if env.networks == nil { - networks := env.getConnections() +func (term *Terminal) Connection(connectionType ConnectionType) (*Connection, error) { + if term.networks == nil { + networks := term.getConnections() if len(networks) == 0 { return nil, errors.New("No connections found") } - env.networks = networks + term.networks = networks } - for _, network := range env.networks { + for _, network := range term.networks { if network.Type == connectionType { return network, nil } } - env.Error(fmt.Errorf("Network type '%s' not found", connectionType)) + term.Error(fmt.Errorf("Network type '%s' not found", connectionType)) return nil, &NotImplemented{} } -func (env *Shell) LookPath(command string) (string, error) { - winAppPath := filepath.Join(env.Getenv("LOCALAPPDATA"), `\Microsoft\WindowsApps\`, command) +func (term *Terminal) LookPath(command string) (string, error) { + winAppPath := filepath.Join(term.Getenv("LOCALAPPDATA"), `\Microsoft\WindowsApps\`, command) if !strings.HasSuffix(winAppPath, ".exe") { winAppPath += ".exe" } diff --git a/src/runtime/os_windows_nix.go b/src/runtime/os_windows_nix.go new file mode 100644 index 00000000..3f8c4de1 --- /dev/null +++ b/src/runtime/os_windows_nix.go @@ -0,0 +1,19 @@ +//go:build !darwin + +package runtime + +import ( + "time" + + "github.com/jandedobbeleer/oh-my-posh/src/runtime/battery" +) + +func (term *Terminal) BatteryState() (*battery.Info, error) { + defer term.Trace(time.Now()) + info, err := battery.Get() + if err != nil { + term.Error(err) + return nil, err + } + return info, nil +} diff --git a/src/platform/win32_windows.go b/src/runtime/win32_windows.go similarity index 98% rename from src/platform/win32_windows.go rename to src/runtime/win32_windows.go index 1986d1be..53e22377 100644 --- a/src/platform/win32_windows.go +++ b/src/runtime/win32_windows.go @@ -1,4 +1,4 @@ -package platform +package runtime import ( "errors" @@ -259,7 +259,7 @@ func (u *tokenUser) isMemberOf(sid *windows.SID) bool { return false } -func (env *Shell) isWriteable(folder string) bool { +func (env *Terminal) isWriteable(folder string) bool { cu, err := getCurrentUser() if err != nil { @@ -335,7 +335,7 @@ type memoryStatusEx struct { AvailExtendedVirtual uint64 } -func (env *Shell) Memory() (*Memory, error) { +func (env *Terminal) Memory() (*Memory, error) { var memStat memoryStatusEx memStat.Length = uint32(unsafe.Sizeof(memStat)) r0, _, err := globalMemoryStatusEx.Call(uintptr(unsafe.Pointer(&memStat))) diff --git a/src/segments/angular.go b/src/segments/angular.go index 5d642f09..d840cc31 100644 --- a/src/segments/angular.go +++ b/src/segments/angular.go @@ -3,8 +3,8 @@ package segments import ( "path/filepath" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Angular struct { @@ -15,7 +15,7 @@ func (a *Angular) Template() string { return languageTemplate } -func (a *Angular) Init(props properties.Properties, env platform.Environment) { +func (a *Angular) Init(props properties.Properties, env runtime.Environment) { a.language = language{ env: env, props: props, diff --git a/src/segments/argocd.go b/src/segments/argocd.go index 4f761248..c26a5b84 100644 --- a/src/segments/argocd.go +++ b/src/segments/argocd.go @@ -6,8 +6,8 @@ import ( "path" "strings" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/spf13/pflag" "gopkg.in/yaml.v3" ) @@ -34,7 +34,7 @@ type ArgocdConfig struct { type Argocd struct { props properties.Properties - env platform.Environment + env runtime.Environment ArgocdContext } @@ -43,7 +43,7 @@ func (a *Argocd) Template() string { return NameTemplate } -func (a *Argocd) Init(props properties.Properties, env platform.Environment) { +func (a *Argocd) Init(props properties.Properties, env runtime.Environment) { a.props = props a.env = env } diff --git a/src/segments/aws.go b/src/segments/aws.go index 3befdd16..8b55d99d 100644 --- a/src/segments/aws.go +++ b/src/segments/aws.go @@ -4,13 +4,13 @@ import ( "fmt" "strings" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Aws struct { props properties.Properties - env platform.Environment + env runtime.Environment Profile string Region string @@ -24,7 +24,7 @@ func (a *Aws) Template() string { return " {{ .Profile }}{{ if .Region }}@{{ .Region }}{{ end }} " } -func (a *Aws) Init(props properties.Properties, env platform.Environment) { +func (a *Aws) Init(props properties.Properties, env runtime.Environment) { a.props = props a.env = env } diff --git a/src/segments/az.go b/src/segments/az.go index 78a630ac..45620ae3 100644 --- a/src/segments/az.go +++ b/src/segments/az.go @@ -6,13 +6,13 @@ import ( "path/filepath" "strings" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Az struct { props properties.Properties - env platform.Environment + env runtime.Environment AzureSubscription Origin string @@ -74,7 +74,7 @@ func (a *Az) Template() string { return NameTemplate } -func (a *Az) Init(props properties.Properties, env platform.Environment) { +func (a *Az) Init(props properties.Properties, env runtime.Environment) { a.props = props a.env = env } diff --git a/src/segments/az_functions.go b/src/segments/az_functions.go index f7cf3795..23e72fbb 100644 --- a/src/segments/az_functions.go +++ b/src/segments/az_functions.go @@ -1,8 +1,8 @@ package segments import ( - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type AzFunc struct { @@ -13,7 +13,7 @@ func (az *AzFunc) Template() string { return languageTemplate } -func (az *AzFunc) Init(props properties.Properties, env platform.Environment) { +func (az *AzFunc) Init(props properties.Properties, env runtime.Environment) { az.language = language{ env: env, props: props, diff --git a/src/segments/az_test.go b/src/segments/az_test.go index 17557a59..4b209d0d 100644 --- a/src/segments/az_test.go +++ b/src/segments/az_test.go @@ -6,8 +6,8 @@ import ( "testing" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/stretchr/testify/assert" ) @@ -121,7 +121,7 @@ func TestAzSegment(t *testing.T) { azureRmContext = string(content) } - env.On("GOOS").Return(platform.LINUX) + env.On("GOOS").Return(runtime.LINUX) env.On("FileContent", filepath.Join(poshHome, ".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/azd.go b/src/segments/azd.go index c7fd8fa1..170862b2 100644 --- a/src/segments/azd.go +++ b/src/segments/azd.go @@ -5,13 +5,13 @@ import ( "path/filepath" "strings" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Azd struct { props properties.Properties - env platform.Environment + env runtime.Environment azdConfig } @@ -25,7 +25,7 @@ func (t *Azd) Template() string { return " \uebd8 {{ .DefaultEnvironment }} " } -func (t *Azd) Init(props properties.Properties, env platform.Environment) { +func (t *Azd) Init(props properties.Properties, env runtime.Environment) { t.props = props t.env = env } diff --git a/src/segments/azd_test.go b/src/segments/azd_test.go index 4de17ae7..28bd4409 100644 --- a/src/segments/azd_test.go +++ b/src/segments/azd_test.go @@ -7,8 +7,8 @@ import ( "testing" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/stretchr/testify/assert" mock2 "github.com/stretchr/testify/mock" ) @@ -39,7 +39,7 @@ func TestAzdSegment(t *testing.T) { env.On("Debug", mock2.Anything) if tc.IsInited { - fileInfo := &platform.FileInfo{ + fileInfo := &runtime.FileInfo{ Path: "test/.azure", ParentFolder: "test", IsDir: true, @@ -58,7 +58,7 @@ func TestAzdSegment(t *testing.T) { env.On("FileContent", filepath.Join("test", ".azure", "config.json")).Return(`{"version": 1, "defaultEnvironment": "TestEnvironment"}`, nil) } else { - env.On("HasParentFilePath", ".azure").Return(&platform.FileInfo{}, errors.New("no such file or directory")) + env.On("HasParentFilePath", ".azure").Return(&runtime.FileInfo{}, errors.New("no such file or directory")) } azd := Azd{ diff --git a/src/segments/battery.go b/src/segments/battery.go index 5539e203..cd010b24 100644 --- a/src/segments/battery.go +++ b/src/segments/battery.go @@ -1,14 +1,14 @@ package segments import ( - "github.com/jandedobbeleer/oh-my-posh/src/platform" - "github.com/jandedobbeleer/oh-my-posh/src/platform/battery" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" + "github.com/jandedobbeleer/oh-my-posh/src/runtime/battery" ) type Battery struct { props properties.Properties - env platform.Environment + env runtime.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 platform.Environment) { +func (b *Battery) Init(props properties.Properties, env runtime.Environment) { b.props = props b.env = env } diff --git a/src/segments/bazel.go b/src/segments/bazel.go index ff97002c..760ad47a 100644 --- a/src/segments/bazel.go +++ b/src/segments/bazel.go @@ -1,8 +1,8 @@ package segments import ( - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Bazel struct { @@ -20,7 +20,7 @@ func (c *Bazel) Template() string { return " {{ if .Error }}{{ .Icon }} {{ .Error }}{{ else }}{{ url .Icon .URL }} {{ .Full }}{{ end }} " } -func (c *Bazel) Init(props properties.Properties, env platform.Environment) { +func (c *Bazel) Init(props properties.Properties, env runtime.Environment) { c.language = language{ env: env, props: props, diff --git a/src/segments/brewfather.go b/src/segments/brewfather.go index 74b16524..cd45c794 100644 --- a/src/segments/brewfather.go +++ b/src/segments/brewfather.go @@ -10,14 +10,14 @@ import ( "sort" "time" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) // segment struct, makes templating easier type Brewfather struct { props properties.Properties - env platform.Environment + env runtime.Environment Batch TemperatureTrendIcon string @@ -320,7 +320,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 platform.Environment) { +func (bf *Brewfather) Init(props properties.Properties, env runtime.Environment) { bf.props = props bf.env = env } diff --git a/src/segments/buf.go b/src/segments/buf.go index 2a6716ac..9066515f 100644 --- a/src/segments/buf.go +++ b/src/segments/buf.go @@ -1,8 +1,8 @@ package segments import ( - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Buf struct { @@ -13,7 +13,7 @@ func (b *Buf) Template() string { return languageTemplate } -func (b *Buf) Init(props properties.Properties, env platform.Environment) { +func (b *Buf) Init(props properties.Properties, env runtime.Environment) { b.language = language{ env: env, props: props, diff --git a/src/segments/bun.go b/src/segments/bun.go index 684cff1a..28808940 100644 --- a/src/segments/bun.go +++ b/src/segments/bun.go @@ -1,8 +1,8 @@ package segments import ( - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Bun struct { @@ -13,7 +13,7 @@ func (b *Bun) Template() string { return languageTemplate } -func (b *Bun) Init(props properties.Properties, env platform.Environment) { +func (b *Bun) Init(props properties.Properties, env runtime.Environment) { b.language = language{ env: env, props: props, diff --git a/src/segments/carbon_intensity.go b/src/segments/carbon_intensity.go index 35abd2e0..f34115b3 100644 --- a/src/segments/carbon_intensity.go +++ b/src/segments/carbon_intensity.go @@ -4,13 +4,13 @@ import ( "encoding/json" "fmt" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type CarbonIntensity struct { props properties.Properties - env platform.Environment + env runtime.Environment TrendIcon string @@ -149,7 +149,7 @@ func (d *CarbonIntensity) setStatus() error { return nil } -func (d *CarbonIntensity) Init(props properties.Properties, env platform.Environment) { +func (d *CarbonIntensity) Init(props properties.Properties, env runtime.Environment) { d.props = props d.env = env } diff --git a/src/segments/cds.go b/src/segments/cds.go index 60347ffb..3aba4faa 100644 --- a/src/segments/cds.go +++ b/src/segments/cds.go @@ -3,8 +3,8 @@ package segments import ( "encoding/json" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Cds struct { @@ -16,7 +16,7 @@ func (c *Cds) Template() string { return languageTemplate } -func (c *Cds) Init(props properties.Properties, env platform.Environment) { +func (c *Cds) Init(props properties.Properties, env runtime.Environment) { c.language = language{ env: env, props: props, diff --git a/src/segments/cf.go b/src/segments/cf.go index 2d3c4b20..837f2d2d 100644 --- a/src/segments/cf.go +++ b/src/segments/cf.go @@ -1,8 +1,8 @@ package segments import ( - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Cf struct { @@ -13,7 +13,7 @@ func (c *Cf) Template() string { return languageTemplate } -func (c *Cf) Init(props properties.Properties, env platform.Environment) { +func (c *Cf) Init(props properties.Properties, env runtime.Environment) { c.language = language{ env: env, props: props, diff --git a/src/segments/cf_target.go b/src/segments/cf_target.go index 1c1d252f..520813eb 100644 --- a/src/segments/cf_target.go +++ b/src/segments/cf_target.go @@ -4,13 +4,13 @@ import ( "errors" "strings" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type CfTarget struct { props properties.Properties - env platform.Environment + env runtime.Environment CfTargetDetails } @@ -26,7 +26,7 @@ func (c *CfTarget) Template() string { return "{{if .Org }}{{ .Org }}{{ end }}{{if .Space }}/{{ .Space }}{{ end }}" } -func (c *CfTarget) Init(props properties.Properties, env platform.Environment) { +func (c *CfTarget) Init(props properties.Properties, env runtime.Environment) { c.props = props c.env = env } diff --git a/src/segments/cf_target_test.go b/src/segments/cf_target_test.go index 81d435ae..2b0285db 100644 --- a/src/segments/cf_target_test.go +++ b/src/segments/cf_target_test.go @@ -7,8 +7,8 @@ import ( "testing" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/stretchr/testify/assert" ) @@ -19,7 +19,7 @@ func TestCFTargetSegment(t *testing.T) { Template string ExpectedString string DisplayMode string - FileInfo *platform.FileInfo + FileInfo *runtime.FileInfo TargetOutput string CommandError error }{ @@ -51,13 +51,13 @@ func TestCFTargetSegment(t *testing.T) { Case: "files and a manifest file", ExpectedString: "12345678trial/dev", DisplayMode: DisplayModeFiles, - FileInfo: &platform.FileInfo{}, + FileInfo: &runtime.FileInfo{}, TargetOutput: "API endpoint: https://api.cf.eu10.hana.ondemand.com\nAPI version: 3.109.0\nuser: user@some.com\norg: 12345678trial\nspace: dev", }, { Case: "files and a manifest directory", DisplayMode: DisplayModeFiles, - FileInfo: &platform.FileInfo{ + FileInfo: &runtime.FileInfo{ IsDir: true, }, }, diff --git a/src/segments/cmake.go b/src/segments/cmake.go index c47f8c39..8adeb710 100644 --- a/src/segments/cmake.go +++ b/src/segments/cmake.go @@ -1,8 +1,8 @@ package segments import ( - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Cmake struct { @@ -13,7 +13,7 @@ func (c *Cmake) Template() string { return languageTemplate } -func (c *Cmake) Init(props properties.Properties, env platform.Environment) { +func (c *Cmake) Init(props properties.Properties, env runtime.Environment) { c.language = language{ env: env, props: props, diff --git a/src/segments/command.go b/src/segments/command.go index bb6f2782..3b78af96 100644 --- a/src/segments/command.go +++ b/src/segments/command.go @@ -3,13 +3,13 @@ package segments import ( "strings" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Cmd struct { props properties.Properties - env platform.Environment + env runtime.Environment Output string } @@ -86,7 +86,7 @@ func (c *Cmd) runScript(shell, script string) bool { return len(c.Output) != 0 } -func (c *Cmd) Init(props properties.Properties, env platform.Environment) { +func (c *Cmd) Init(props properties.Properties, env runtime.Environment) { c.props = props c.env = env } diff --git a/src/segments/connection.go b/src/segments/connection.go index 1c7a6e38..3042c988 100644 --- a/src/segments/connection.go +++ b/src/segments/connection.go @@ -3,15 +3,15 @@ package segments import ( "strings" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Connection struct { props properties.Properties - env platform.Environment + env runtime.Environment - platform.Connection + runtime.Connection } const ( @@ -26,7 +26,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(platform.ConnectionType(connectionType)) + network, err := c.env.Connection(runtime.ConnectionType(connectionType)) if err != nil { continue } @@ -36,7 +36,7 @@ func (c *Connection) Enabled() bool { return false } -func (c *Connection) Init(props properties.Properties, env platform.Environment) { +func (c *Connection) Init(props properties.Properties, env runtime.Environment) { c.props = props c.env = env } diff --git a/src/segments/connection_test.go b/src/segments/connection_test.go index eba2f6d0..d7e0e910 100644 --- a/src/segments/connection_test.go +++ b/src/segments/connection_test.go @@ -5,15 +5,15 @@ import ( "testing" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/stretchr/testify/assert" ) func TestConnection(t *testing.T) { type connectionResponse struct { - Connection *platform.Connection + Connection *runtime.Connection Error error } cases := []struct { @@ -30,7 +30,7 @@ func TestConnection(t *testing.T) { ConnectionType: "wifi", Connections: []*connectionResponse{ { - Connection: &platform.Connection{ + Connection: &runtime.Connection{ Name: "WiFi", Type: "wifi", }, @@ -42,8 +42,8 @@ func TestConnection(t *testing.T) { ConnectionType: "wifi", Connections: []*connectionResponse{ { - Connection: &platform.Connection{ - Type: platform.WIFI, + Connection: &runtime.Connection{ + Type: runtime.WIFI, }, Error: fmt.Errorf("no connection"), }, @@ -56,14 +56,14 @@ func TestConnection(t *testing.T) { ExpectedEnabled: true, Connections: []*connectionResponse{ { - Connection: &platform.Connection{ - Type: platform.WIFI, + Connection: &runtime.Connection{ + Type: runtime.WIFI, }, Error: fmt.Errorf("no connection"), }, { - Connection: &platform.Connection{ - Type: platform.ETHERNET, + Connection: &runtime.Connection{ + Type: runtime.ETHERNET, }, }, }, @@ -73,14 +73,14 @@ func TestConnection(t *testing.T) { ConnectionType: "wifi|ethernet", Connections: []*connectionResponse{ { - Connection: &platform.Connection{ - Type: platform.WIFI, + Connection: &runtime.Connection{ + Type: runtime.WIFI, }, Error: fmt.Errorf("no connection"), }, { - Connection: &platform.Connection{ - Type: platform.ETHERNET, + Connection: &runtime.Connection{ + Type: runtime.ETHERNET, }, Error: fmt.Errorf("no connection"), }, diff --git a/src/segments/crystal.go b/src/segments/crystal.go index d1c41fb9..825369fc 100644 --- a/src/segments/crystal.go +++ b/src/segments/crystal.go @@ -1,8 +1,8 @@ package segments import ( - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Crystal struct { @@ -13,7 +13,7 @@ func (c *Crystal) Template() string { return languageTemplate } -func (c *Crystal) Init(props properties.Properties, env platform.Environment) { +func (c *Crystal) Init(props properties.Properties, env runtime.Environment) { c.language = language{ env: env, props: props, diff --git a/src/segments/dart.go b/src/segments/dart.go index 634c6eac..11fb582a 100644 --- a/src/segments/dart.go +++ b/src/segments/dart.go @@ -1,8 +1,8 @@ package segments import ( - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) var ( @@ -18,7 +18,7 @@ func (d *Dart) Template() string { return languageTemplate } -func (d *Dart) Init(props properties.Properties, env platform.Environment) { +func (d *Dart) Init(props properties.Properties, env runtime.Environment) { d.language = language{ env: env, props: props, diff --git a/src/segments/deno.go b/src/segments/deno.go index a85adc22..bb3fc3ae 100644 --- a/src/segments/deno.go +++ b/src/segments/deno.go @@ -1,8 +1,8 @@ package segments import ( - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Deno struct { @@ -13,7 +13,7 @@ func (d *Deno) Template() string { return languageTemplate } -func (d *Deno) Init(props properties.Properties, env platform.Environment) { +func (d *Deno) Init(props properties.Properties, env runtime.Environment) { d.language = language{ env: env, props: props, diff --git a/src/segments/docker.go b/src/segments/docker.go index 53c8c247..b1a88380 100644 --- a/src/segments/docker.go +++ b/src/segments/docker.go @@ -4,8 +4,8 @@ import ( "encoding/json" "path/filepath" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type DockerConfig struct { @@ -14,7 +14,7 @@ type DockerConfig struct { type Docker struct { props properties.Properties - env platform.Environment + env runtime.Environment Context string } @@ -23,7 +23,7 @@ func (d *Docker) Template() string { return " \uf308 {{ .Context }} " } -func (d *Docker) Init(props properties.Properties, env platform.Environment) { +func (d *Docker) Init(props properties.Properties, env runtime.Environment) { d.props = props d.env = env } diff --git a/src/segments/dotnet.go b/src/segments/dotnet.go index 80807ae6..6e4d0ab3 100644 --- a/src/segments/dotnet.go +++ b/src/segments/dotnet.go @@ -2,8 +2,8 @@ package segments import ( "github.com/jandedobbeleer/oh-my-posh/src/constants" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Dotnet struct { @@ -16,7 +16,7 @@ func (d *Dotnet) Template() string { return " {{ if .Unsupported }}\uf071{{ else }}{{ .Full }}{{ end }} " } -func (d *Dotnet) Init(props properties.Properties, env platform.Environment) { +func (d *Dotnet) Init(props properties.Properties, env runtime.Environment) { d.language = language{ env: env, props: props, diff --git a/src/segments/dotnet_test.go b/src/segments/dotnet_test.go index 01c54aff..11db456c 100644 --- a/src/segments/dotnet_test.go +++ b/src/segments/dotnet_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/jandedobbeleer/oh-my-posh/src/constants" - "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/stretchr/testify/assert" ) @@ -31,7 +31,7 @@ func TestDotnetSegment(t *testing.T) { if tc.ExitCode != 0 { env.Unset("RunCommand") - err := &platform.CommandError{ExitCode: tc.ExitCode} + err := &runtime.CommandError{ExitCode: tc.ExitCode} env.On("RunCommand", "dotnet", []string{"--version"}).Return("", err) } diff --git a/src/segments/elixir.go b/src/segments/elixir.go index 50851b2b..4a06882b 100644 --- a/src/segments/elixir.go +++ b/src/segments/elixir.go @@ -1,8 +1,8 @@ package segments import ( - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Elixir struct { @@ -13,7 +13,7 @@ func (e *Elixir) Template() string { return languageTemplate } -func (e *Elixir) Init(props properties.Properties, env platform.Environment) { +func (e *Elixir) Init(props properties.Properties, env runtime.Environment) { e.language = language{ env: env, props: props, diff --git a/src/segments/elixir_test.go b/src/segments/elixir_test.go index 0b9fc5e8..0679d686 100644 --- a/src/segments/elixir_test.go +++ b/src/segments/elixir_test.go @@ -4,7 +4,7 @@ import ( "fmt" "testing" - "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/stretchr/testify/assert" ) @@ -50,7 +50,7 @@ func TestElixir(t *testing.T) { env.On("HasCommand", "asdf").Return(tc.HasAsdf) var asdfErr error if tc.AsdfExitCode != 0 { - asdfErr = &platform.CommandError{ExitCode: tc.AsdfExitCode} + asdfErr = &runtime.CommandError{ExitCode: tc.AsdfExitCode} } env.On("RunCommand", "asdf", []string{"current", "elixir"}).Return(tc.AsdfVersionOutput, asdfErr) diff --git a/src/segments/executiontime.go b/src/segments/executiontime.go index ac968ada..47e9c2fc 100644 --- a/src/segments/executiontime.go +++ b/src/segments/executiontime.go @@ -4,8 +4,8 @@ import ( "fmt" "strconv" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" lang "golang.org/x/text/language" "golang.org/x/text/message" @@ -13,7 +13,7 @@ import ( type Executiontime struct { props properties.Properties - env platform.Environment + env runtime.Environment FormattedMs string Ms int64 @@ -70,7 +70,7 @@ func (t *Executiontime) Template() string { return " {{ .FormattedMs }} " } -func (t *Executiontime) Init(props properties.Properties, env platform.Environment) { +func (t *Executiontime) Init(props properties.Properties, env runtime.Environment) { t.props = props t.env = env } diff --git a/src/segments/firebase.go b/src/segments/firebase.go index fc0e58e3..23b78acb 100644 --- a/src/segments/firebase.go +++ b/src/segments/firebase.go @@ -6,8 +6,8 @@ import ( "path/filepath" "strings" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) const ( @@ -16,7 +16,7 @@ const ( type Firebase struct { props properties.Properties - env platform.Environment + env runtime.Environment Project string } @@ -29,7 +29,7 @@ func (f *Firebase) Template() string { return " {{ .Project}} " } -func (f *Firebase) Init(props properties.Properties, env platform.Environment) { +func (f *Firebase) Init(props properties.Properties, env runtime.Environment) { f.props = props f.env = env } diff --git a/src/segments/flutter.go b/src/segments/flutter.go index 5ce2959f..d120f133 100644 --- a/src/segments/flutter.go +++ b/src/segments/flutter.go @@ -1,8 +1,8 @@ package segments import ( - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Flutter struct { @@ -13,7 +13,7 @@ func (f *Flutter) Template() string { return languageTemplate } -func (f *Flutter) Init(props properties.Properties, env platform.Environment) { +func (f *Flutter) Init(props properties.Properties, env runtime.Environment) { f.language = language{ env: env, props: props, diff --git a/src/segments/gcp.go b/src/segments/gcp.go index b9617713..db5744c6 100644 --- a/src/segments/gcp.go +++ b/src/segments/gcp.go @@ -4,8 +4,8 @@ import ( "errors" "path" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "gopkg.in/ini.v1" ) @@ -16,7 +16,7 @@ const ( type Gcp struct { props properties.Properties - env platform.Environment + env runtime.Environment Account string Project string @@ -27,7 +27,7 @@ func (g *Gcp) Template() string { return " {{ .Project }} " } -func (g *Gcp) Init(props properties.Properties, env platform.Environment) { +func (g *Gcp) Init(props properties.Properties, env runtime.Environment) { g.props = props g.env = env } @@ -75,8 +75,10 @@ func (g *Gcp) getConfigDirectory() string { if len(cfgDir) != 0 { return cfgDir } - if g.env.GOOS() == platform.WINDOWS { + + if g.env.GOOS() == runtime.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 8f1eb2be..b8b55453 100644 --- a/src/segments/gcp_test.go +++ b/src/segments/gcp_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/stretchr/testify/assert" mock2 "github.com/stretchr/testify/mock" @@ -84,7 +84,7 @@ func TestGetConfigDirectory(t *testing.T) { }, { Case: "Windows", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, AppData: "/Users/posh/.config", Expected: "/Users/posh/.config/gcloud", }, diff --git a/src/segments/git.go b/src/segments/git.go index c7c3232f..c8e1a0a1 100644 --- a/src/segments/git.go +++ b/src/segments/git.go @@ -8,9 +8,9 @@ import ( "strings" "time" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" "github.com/jandedobbeleer/oh-my-posh/src/regex" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "gopkg.in/ini.v1" ) @@ -336,15 +336,15 @@ func (g *Git) getBareRepoInfo() { } func (g *Git) setDir(dir string) { - dir = platform.ReplaceHomeDirPrefixWithTilde(g.env, dir) // align with template PWD - if g.env.GOOS() == platform.WINDOWS { + dir = runtime.ReplaceHomeDirPrefixWithTilde(g.env, dir) // align with template PWD + if g.env.GOOS() == runtime.WINDOWS { g.Dir = strings.TrimSuffix(dir, `\.git`) return } g.Dir = strings.TrimSuffix(dir, "/.git") } -func (g *Git) hasWorktree(gitdir *platform.FileInfo) bool { +func (g *Git) hasWorktree(gitdir *runtime.FileInfo) bool { g.rootDir = gitdir.Path content := g.env.FileContent(gitdir.Path) content = strings.Trim(content, " \r\n") @@ -862,12 +862,12 @@ func (g *Git) getSwitchMode(property properties.Property, gitSwitch, mode string func (g *Git) repoName() string { if !g.IsWorkTree { - return platform.Base(g.env, g.convertToLinuxPath(g.realDir)) + return runtime.Base(g.env, g.convertToLinuxPath(g.realDir)) } ind := strings.LastIndex(g.workingDir, ".git/worktrees") if ind > -1 { - return platform.Base(g.env, g.workingDir[:ind]) + return runtime.Base(g.env, g.workingDir[:ind]) } return "" diff --git a/src/segments/git_test.go b/src/segments/git_test.go index 9fdffaaa..4b95177c 100644 --- a/src/segments/git_test.go +++ b/src/segments/git_test.go @@ -10,8 +10,8 @@ import ( "time" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/stretchr/testify/assert" mock2 "github.com/stretchr/testify/mock" @@ -39,7 +39,7 @@ func TestEnabledGitNotFound(t *testing.T) { } func TestEnabledInWorkingDirectory(t *testing.T) { - fileInfo := &platform.FileInfo{ + fileInfo := &runtime.FileInfo{ Path: "/dir/hello", ParentFolder: "/dir", IsDir: true, @@ -127,7 +127,7 @@ func TestEnabledInWorktree(t *testing.T) { ExpectedRootFolder: TestRootPath + "dev/separate/.git/posh", }, } - fileInfo := &platform.FileInfo{ + fileInfo := &runtime.FileInfo{ Path: TestRootPath + dotGit, ParentFolder: TestRootPath + "dev", } @@ -192,7 +192,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(&platform.FileInfo{}, errors.New("nope")) + env.On("HasParentFilePath", ".git").Return(&runtime.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) @@ -1142,7 +1142,7 @@ func TestGitRepoName(t *testing.T) { for _, tc := range cases { env := new(mock.MockedEnvironment) env.On("PathSeparator").Return("/") - env.On("GOOS").Return(platform.LINUX) + env.On("GOOS").Return(runtime.LINUX) g := &Git{ scm: scm{ diff --git a/src/segments/gitversion.go b/src/segments/gitversion.go index 6e6aa1bb..a8eef1f1 100644 --- a/src/segments/gitversion.go +++ b/src/segments/gitversion.go @@ -4,8 +4,8 @@ import ( "encoding/json" "errors" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type gitVersion struct { @@ -46,7 +46,7 @@ type gitVersion struct { type GitVersion struct { props properties.Properties - env platform.Environment + env runtime.Environment gitVersion } @@ -107,7 +107,7 @@ func (n *GitVersion) getCacheValue(key string) (*gitVersion, error) { return semVer, err } -func (n *GitVersion) Init(props properties.Properties, env platform.Environment) { +func (n *GitVersion) Init(props properties.Properties, env runtime.Environment) { n.props = props n.env = env } diff --git a/src/segments/golang.go b/src/segments/golang.go index f10fac6e..e35dfe4b 100644 --- a/src/segments/golang.go +++ b/src/segments/golang.go @@ -1,8 +1,8 @@ package segments import ( - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "golang.org/x/mod/modfile" ) @@ -19,7 +19,7 @@ func (g *Golang) Template() string { return languageTemplate } -func (g *Golang) Init(props properties.Properties, env platform.Environment) { +func (g *Golang) Init(props properties.Properties, env runtime.Environment) { g.language = language{ env: env, props: props, diff --git a/src/segments/golang_test.go b/src/segments/golang_test.go index 730516eb..1e2dc55c 100644 --- a/src/segments/golang_test.go +++ b/src/segments/golang_test.go @@ -6,8 +6,7 @@ import ( "os" "testing" - "github.com/jandedobbeleer/oh-my-posh/src/platform" - + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/stretchr/testify/assert" ) @@ -43,7 +42,7 @@ func TestGolang(t *testing.T) { env, props := getMockedLanguageEnv(params) if tc.ParseModFile { props[ParseModFile] = tc.ParseModFile - fileInfo := &platform.FileInfo{ + fileInfo := &runtime.FileInfo{ Path: "../go.mod", ParentFolder: "./", IsDir: false, diff --git a/src/segments/haskell.go b/src/segments/haskell.go index 185a0693..2373728a 100644 --- a/src/segments/haskell.go +++ b/src/segments/haskell.go @@ -1,8 +1,8 @@ package segments import ( - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Haskell struct { @@ -19,7 +19,7 @@ func (h *Haskell) Template() string { return languageTemplate } -func (h *Haskell) Init(props properties.Properties, env platform.Environment) { +func (h *Haskell) Init(props properties.Properties, env runtime.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 8e08b1c8..522dc5e1 100644 --- a/src/segments/haskell_test.go +++ b/src/segments/haskell_test.go @@ -5,8 +5,7 @@ import ( "fmt" "testing" - "github.com/jandedobbeleer/oh-my-posh/src/platform" - + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/stretchr/testify/assert" ) @@ -67,7 +66,7 @@ func TestHaskell(t *testing.T) { env.On("RunCommand", "stack", []string{"ghc", "--", "--numeric-version"}).Return(tc.StackGhcVersion, nil) } - fileInfo := &platform.FileInfo{ + fileInfo := &runtime.FileInfo{ Path: "../stack.yaml", ParentFolder: "./", IsDir: false, diff --git a/src/segments/helm.go b/src/segments/helm.go index 9fa4d830..c69c210e 100644 --- a/src/segments/helm.go +++ b/src/segments/helm.go @@ -1,13 +1,13 @@ package segments import ( - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Helm struct { props properties.Properties - env platform.Environment + env runtime.Environment Version string } @@ -34,7 +34,7 @@ func (h *Helm) Template() string { return " Helm {{.Version}}" } -func (h *Helm) Init(props properties.Properties, env platform.Environment) { +func (h *Helm) Init(props properties.Properties, env runtime.Environment) { h.props = props h.env = env } diff --git a/src/segments/helm_test.go b/src/segments/helm_test.go index f7a299e2..319d5ef8 100644 --- a/src/segments/helm_test.go +++ b/src/segments/helm_test.go @@ -8,8 +8,8 @@ import ( testify_mock "github.com/stretchr/testify/mock" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) func TestHelmSegment(t *testing.T) { @@ -86,8 +86,8 @@ func TestHelmSegment(t *testing.T) { env.On("HasCommand", "helm").Return(tc.HelmExists) env.On("RunCommand", "helm", []string{"version", "--short", "--template={{.Version}}"}).Return("v3.12.3", nil) - env.On("HasParentFilePath", tc.ChartFile).Return(&platform.FileInfo{}, nil) - env.On("HasParentFilePath", testify_mock.Anything).Return(&platform.FileInfo{}, errors.New("no such file or directory")) + env.On("HasParentFilePath", tc.ChartFile).Return(&runtime.FileInfo{}, nil) + env.On("HasParentFilePath", testify_mock.Anything).Return(&runtime.FileInfo{}, errors.New("no such file or directory")) props := properties.Map{ DisplayMode: tc.DisplayMode, diff --git a/src/segments/ipify.go b/src/segments/ipify.go index 55546e53..dad0f7a7 100644 --- a/src/segments/ipify.go +++ b/src/segments/ipify.go @@ -4,8 +4,8 @@ import ( "net" "github.com/jandedobbeleer/oh-my-posh/src/http" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type ipData struct { @@ -62,7 +62,7 @@ func (i *IPify) getResult() (string, error) { return data.IP, err } -func (i *IPify) Init(props properties.Properties, env platform.Environment) { +func (i *IPify) Init(props properties.Properties, env runtime.Environment) { request := &http.Request{} request.Init(env, props) diff --git a/src/segments/java.go b/src/segments/java.go index 6a8c9b13..22289019 100644 --- a/src/segments/java.go +++ b/src/segments/java.go @@ -3,8 +3,8 @@ package segments import ( "fmt" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Java struct { @@ -15,7 +15,7 @@ func (j *Java) Template() string { return languageTemplate } -func (j *Java) Init(props properties.Properties, env platform.Environment) { +func (j *Java) Init(props properties.Properties, env runtime.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 37dad893..24e7c103 100644 --- a/src/segments/julia.go +++ b/src/segments/julia.go @@ -1,8 +1,8 @@ package segments import ( - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Julia struct { @@ -13,7 +13,7 @@ func (j *Julia) Template() string { return languageTemplate } -func (j *Julia) Init(props properties.Properties, env platform.Environment) { +func (j *Julia) Init(props properties.Properties, env runtime.Environment) { j.language = language{ env: env, props: props, diff --git a/src/segments/kotlin.go b/src/segments/kotlin.go index 8360ccff..cd6e4012 100644 --- a/src/segments/kotlin.go +++ b/src/segments/kotlin.go @@ -1,8 +1,8 @@ package segments import ( - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Kotlin struct { @@ -13,7 +13,7 @@ func (k *Kotlin) Template() string { return languageTemplate } -func (k *Kotlin) Init(props properties.Properties, env platform.Environment) { +func (k *Kotlin) Init(props properties.Properties, env runtime.Environment) { k.language = language{ env: env, props: props, diff --git a/src/segments/kubectl.go b/src/segments/kubectl.go index ea8f032f..6be01c93 100644 --- a/src/segments/kubectl.go +++ b/src/segments/kubectl.go @@ -3,8 +3,8 @@ package segments import ( "path/filepath" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "gopkg.in/yaml.v3" ) @@ -17,7 +17,7 @@ const ( type Kubectl struct { props properties.Properties - env platform.Environment + env runtime.Environment Context string @@ -42,7 +42,7 @@ func (k *Kubectl) Template() string { return " {{ .Context }}{{ if .Namespace }} :: {{ .Namespace }}{{ end }} " } -func (k *Kubectl) Init(props properties.Properties, env platform.Environment) { +func (k *Kubectl) Init(props properties.Properties, env runtime.Environment) { k.props = props k.env = env } diff --git a/src/segments/kubectl_test.go b/src/segments/kubectl_test.go index 43130de5..146b0018 100644 --- a/src/segments/kubectl_test.go +++ b/src/segments/kubectl_test.go @@ -7,8 +7,8 @@ import ( "testing" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/stretchr/testify/assert" ) @@ -141,7 +141,7 @@ func TestKubectlSegment(t *testing.T) { } var kubectlErr error if tc.KubectlErr { - kubectlErr = &platform.CommandError{ + kubectlErr = &runtime.CommandError{ Err: "oops", ExitCode: 1, } diff --git a/src/segments/language.go b/src/segments/language.go index 84d42732..8fecc1dd 100644 --- a/src/segments/language.go +++ b/src/segments/language.go @@ -4,9 +4,9 @@ import ( "errors" "fmt" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" "github.com/jandedobbeleer/oh-my-posh/src/regex" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/jandedobbeleer/oh-my-posh/src/template" ) @@ -61,7 +61,7 @@ func (c *cmd) parse(versionInfo string) (*version, error) { type language struct { props properties.Properties - env platform.Environment + env runtime.Environment extensions []string folders []string commands []*cmd @@ -74,7 +74,7 @@ type language struct { displayMode string // root is the root folder of the project projectFiles []string - projectRoot *platform.FileInfo + projectRoot *runtime.FileInfo version Error string @@ -218,7 +218,7 @@ func (l *language) setVersion() error { } versionStr, err = l.env.RunCommand(command.executable, command.args...) - if exitErr, ok := err.(*platform.CommandError); ok { + if exitErr, ok := err.(*runtime.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 67ba9ddf..c4ac73b9 100644 --- a/src/segments/language_test.go +++ b/src/segments/language_test.go @@ -4,8 +4,8 @@ import ( "testing" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/stretchr/testify/assert" mock2 "github.com/stretchr/testify/mock" @@ -61,7 +61,7 @@ func bootStrapLanguageTest(args *languageArgs) *language { env.On("Pwd").Return(cwd) env.On("Home").Return(home) env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil) - env.On("TemplateCache").Return(&platform.TemplateCache{ + env.On("TemplateCache").Return(&runtime.TemplateCache{ Env: make(map[string]string), }) @@ -394,7 +394,7 @@ func TestLanguageEnabledCommandExitCode(t *testing.T) { enabledExtensions: []string{uni, corn}, enabledCommands: []string{"uni"}, version: universion, - expectedError: &platform.CommandError{ExitCode: expected}, + expectedError: &runtime.CommandError{ExitCode: expected}, } lang := bootStrapLanguageTest(args) assert.True(t, lang.Enabled()) @@ -577,7 +577,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(&platform.TemplateCache{ + env.On("TemplateCache").Return(&runtime.TemplateCache{ Env: make(map[string]string), }) env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil) diff --git a/src/segments/lastfm.go b/src/segments/lastfm.go index b2f8da22..6f811818 100644 --- a/src/segments/lastfm.go +++ b/src/segments/lastfm.go @@ -5,13 +5,13 @@ import ( "errors" "fmt" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type LastFM struct { props properties.Properties - env platform.Environment + env runtime.Environment Artist string Track string @@ -136,7 +136,7 @@ func (d *LastFM) setStatus() error { return nil } -func (d *LastFM) Init(props properties.Properties, env platform.Environment) { +func (d *LastFM) Init(props properties.Properties, env runtime.Environment) { d.props = props d.env = env } diff --git a/src/segments/lua.go b/src/segments/lua.go index 214ded2c..11732560 100644 --- a/src/segments/lua.go +++ b/src/segments/lua.go @@ -1,8 +1,8 @@ package segments import ( - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Lua struct { @@ -17,7 +17,7 @@ func (l *Lua) Template() string { return languageTemplate } -func (l *Lua) Init(props properties.Properties, env platform.Environment) { +func (l *Lua) Init(props properties.Properties, env runtime.Environment) { l.language = language{ env: env, props: props, diff --git a/src/segments/mercurial.go b/src/segments/mercurial.go index 4d28d01d..7e7f31e0 100644 --- a/src/segments/mercurial.go +++ b/src/segments/mercurial.go @@ -3,7 +3,7 @@ package segments import ( "strings" - "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) const ( @@ -86,8 +86,8 @@ func (hg *Mercurial) shouldDisplay() bool { } func (hg *Mercurial) setDir(dir string) { - dir = platform.ReplaceHomeDirPrefixWithTilde(hg.env, dir) // align with template PWD - if hg.env.GOOS() == platform.WINDOWS { + dir = runtime.ReplaceHomeDirPrefixWithTilde(hg.env, dir) // align with template PWD + if hg.env.GOOS() == runtime.WINDOWS { hg.Dir = strings.TrimSuffix(dir, `\.hg`) return } diff --git a/src/segments/mercurial_test.go b/src/segments/mercurial_test.go index 76061d6f..3325fde2 100644 --- a/src/segments/mercurial_test.go +++ b/src/segments/mercurial_test.go @@ -4,8 +4,8 @@ import ( "testing" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/stretchr/testify/assert" ) @@ -27,7 +27,7 @@ func TestMercurialEnabledToolNotFound(t *testing.T) { } func TestMercurialEnabledInWorkingDirectory(t *testing.T) { - fileInfo := &platform.FileInfo{ + fileInfo := &runtime.FileInfo{ Path: "/dir/hello", ParentFolder: "/dir", IsDir: true, @@ -137,7 +137,7 @@ A Added.File } for _, tc := range cases { - fileInfo := &platform.FileInfo{ + fileInfo := &runtime.FileInfo{ Path: "/dir/hello", ParentFolder: "/dir", IsDir: true, diff --git a/src/segments/nba.go b/src/segments/nba.go index 6d5bcd27..bca6bec9 100644 --- a/src/segments/nba.go +++ b/src/segments/nba.go @@ -6,14 +6,14 @@ import ( "fmt" "time" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) // segment struct, makes templating easier type Nba struct { props properties.Properties - env platform.Environment + env runtime.Environment NBAData } @@ -414,7 +414,7 @@ func (nba *Nba) getResult() (*NBAData, error) { return data, nil } -func (nba *Nba) Init(props properties.Properties, env platform.Environment) { +func (nba *Nba) Init(props properties.Properties, env runtime.Environment) { nba.props = props nba.env = env } diff --git a/src/segments/nbgv.go b/src/segments/nbgv.go index f655d49f..e8735e03 100644 --- a/src/segments/nbgv.go +++ b/src/segments/nbgv.go @@ -3,13 +3,13 @@ package segments import ( "encoding/json" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Nbgv struct { props properties.Properties - env platform.Environment + env runtime.Environment VersionInfo } @@ -46,7 +46,7 @@ func (n *Nbgv) Enabled() bool { return n.VersionInfo.VersionFileFound } -func (n *Nbgv) Init(props properties.Properties, env platform.Environment) { +func (n *Nbgv) Init(props properties.Properties, env runtime.Environment) { n.props = props n.env = env } diff --git a/src/segments/nightscout.go b/src/segments/nightscout.go index fe1faba0..0b33a895 100644 --- a/src/segments/nightscout.go +++ b/src/segments/nightscout.go @@ -6,14 +6,14 @@ import ( http2 "net/http" "time" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) // segment struct, makes templating easier type Nightscout struct { props properties.Properties - env platform.Environment + env runtime.Environment NightscoutData TrendIcon string @@ -147,7 +147,7 @@ func (ns *Nightscout) getResult() (*NightscoutData, error) { return data, nil } -func (ns *Nightscout) Init(props properties.Properties, env platform.Environment) { +func (ns *Nightscout) Init(props properties.Properties, env runtime.Environment) { ns.props = props ns.env = env } diff --git a/src/segments/node.go b/src/segments/node.go index 0b5b6d40..bfef5be3 100644 --- a/src/segments/node.go +++ b/src/segments/node.go @@ -4,9 +4,9 @@ import ( "fmt" "strings" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" "github.com/jandedobbeleer/oh-my-posh/src/regex" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Node struct { @@ -30,7 +30,7 @@ func (n *Node) Template() string { return " {{ if .PackageManagerIcon }}{{ .PackageManagerIcon }} {{ end }}{{ .Full }} " } -func (n *Node) Init(props properties.Properties, env platform.Environment) { +func (n *Node) Init(props properties.Properties, env runtime.Environment) { n.language = language{ env: env, props: props, diff --git a/src/segments/npm.go b/src/segments/npm.go index 4be48969..220929fc 100644 --- a/src/segments/npm.go +++ b/src/segments/npm.go @@ -1,8 +1,8 @@ package segments import ( - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Npm struct { @@ -17,7 +17,7 @@ func (n *Npm) Template() string { return " \ue71e {{.Full}} " } -func (n *Npm) Init(props properties.Properties, env platform.Environment) { +func (n *Npm) Init(props properties.Properties, env runtime.Environment) { n.language = language{ env: env, props: props, diff --git a/src/segments/nx.go b/src/segments/nx.go index 82b79948..dbf50359 100644 --- a/src/segments/nx.go +++ b/src/segments/nx.go @@ -5,8 +5,8 @@ import ( "fmt" "path/filepath" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Nx struct { @@ -17,7 +17,7 @@ func (a *Nx) Template() string { return languageTemplate } -func (a *Nx) Init(props properties.Properties, env platform.Environment) { +func (a *Nx) Init(props properties.Properties, env runtime.Environment) { a.language = language{ env: env, props: props, @@ -40,7 +40,7 @@ func (a *Nx) getVersion() (string, error) { return getNodePackageVersion(a.language.env, "nx") } -func getNodePackageVersion(env platform.Environment, nodePackage string) (string, error) { +func getNodePackageVersion(env runtime.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 54e7e5ce..875d1e72 100644 --- a/src/segments/nx_test.go +++ b/src/segments/nx_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/stretchr/testify/assert" ) @@ -31,7 +31,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(&platform.TemplateCache{ + env.On("TemplateCache").Return(&runtime.TemplateCache{ Env: make(map[string]string), }) got, err := getNodePackageVersion(env, "nx") diff --git a/src/segments/ocaml.go b/src/segments/ocaml.go index c0e293ef..376662ed 100644 --- a/src/segments/ocaml.go +++ b/src/segments/ocaml.go @@ -1,8 +1,8 @@ package segments import ( - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type OCaml struct { @@ -13,7 +13,7 @@ func (o *OCaml) Template() string { return languageTemplate } -func (o *OCaml) Init(props properties.Properties, env platform.Environment) { +func (o *OCaml) Init(props properties.Properties, env runtime.Environment) { o.language = language{ env: env, props: props, diff --git a/src/segments/os.go b/src/segments/os.go index d62c6f6e..7c89939f 100644 --- a/src/segments/os.go +++ b/src/segments/os.go @@ -1,13 +1,13 @@ package segments import ( - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Os struct { props properties.Properties - env platform.Environment + env runtime.Environment Icon string } @@ -30,11 +30,11 @@ func (oi *Os) Template() string { func (oi *Os) Enabled() bool { goos := oi.env.GOOS() switch goos { - case platform.WINDOWS: + case runtime.WINDOWS: oi.Icon = oi.props.GetString(Windows, "\uE62A") - case platform.DARWIN: + case runtime.DARWIN: oi.Icon = oi.props.GetString(MacOS, "\uF179") - case platform.LINUX: + case runtime.LINUX: pf := oi.env.Platform() displayDistroName := oi.props.GetBool(DisplayDistroName, false) if displayDistroName { @@ -92,7 +92,7 @@ func (oi *Os) getDistroIcon(distro string) string { return oi.props.GetString(Linux, "\uF17C") } -func (oi *Os) Init(props properties.Properties, env platform.Environment) { +func (oi *Os) Init(props properties.Properties, env runtime.Environment) { oi.props = props oi.env = env } diff --git a/src/segments/os_test.go b/src/segments/os_test.go index 9495cfb3..9625012b 100644 --- a/src/segments/os_test.go +++ b/src/segments/os_test.go @@ -4,8 +4,8 @@ import ( "testing" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/stretchr/testify/assert" ) @@ -89,7 +89,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(&platform.TemplateCache{ + env.On("TemplateCache").Return(&runtime.TemplateCache{ Env: make(map[string]string), WSL: tc.IsWSL, }) diff --git a/src/segments/owm.go b/src/segments/owm.go index 0d4d51e2..d446cec0 100644 --- a/src/segments/owm.go +++ b/src/segments/owm.go @@ -7,13 +7,13 @@ import ( "math" "net/url" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Owm struct { props properties.Properties - env platform.Environment + env runtime.Environment Temperature int Weather string @@ -188,7 +188,7 @@ func (d *Owm) setStatus() error { return nil } -func (d *Owm) Init(props properties.Properties, env platform.Environment) { +func (d *Owm) Init(props properties.Properties, env runtime.Environment) { d.props = props d.env = env } diff --git a/src/segments/path.go b/src/segments/path.go index f7a4bf3b..df5d4ff6 100644 --- a/src/segments/path.go +++ b/src/segments/path.go @@ -6,16 +6,16 @@ import ( "strconv" "strings" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" "github.com/jandedobbeleer/oh-my-posh/src/regex" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/jandedobbeleer/oh-my-posh/src/shell" "github.com/jandedobbeleer/oh-my-posh/src/template" ) type Path struct { props properties.Properties - env platform.Environment + env runtime.Environment root string relative string @@ -126,12 +126,12 @@ func (pt *Path) setPaths() { return false } - isCygwin := pt.env.GOOS() == platform.WINDOWS && pt.env.Shell() == shell.BASH + isCygwin := pt.env.GOOS() == runtime.WINDOWS && pt.env.Shell() == shell.BASH return isCygwin } pt.cygPath = displayCygpath() - pt.windowsPath = pt.env.GOOS() == platform.WINDOWS && !pt.cygPath + pt.windowsPath = pt.env.GOOS() == runtime.WINDOWS && !pt.cygPath pt.pathSeparator = pt.env.PathSeparator() pt.pwd = pt.env.Pwd() @@ -168,12 +168,12 @@ func (pt *Path) Parent() string { // a root path has no parent return "" } - base := platform.Base(pt.env, pt.pwd) + base := runtime.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 platform.Environment) { +func (pt *Path) Init(props properties.Properties, env runtime.Environment) { pt.props = props pt.env = env } @@ -507,7 +507,7 @@ func (pt *Path) getFullPath() string { } func (pt *Path) getFolderPath() string { - pwd := platform.Base(pt.env, pt.pwd) + pwd := runtime.Base(pt.env, pt.pwd) return pt.replaceFolderSeparators(pwd) } @@ -599,7 +599,7 @@ func (pt *Path) replaceMappedLocations() (string, string) { } func (pt *Path) normalizePath(path string) string { - if pt.env.GOOS() != platform.WINDOWS || pt.cygPath { + if pt.env.GOOS() != runtime.WINDOWS || pt.cygPath { return path } @@ -681,7 +681,7 @@ func (pt *Path) parsePath(inputPath string) (string, string) { func (pt *Path) normalize(inputPath string) string { normalized := inputPath - if strings.HasPrefix(normalized, "~") && (len(normalized) == 1 || platform.IsPathSeparator(pt.env, normalized[1])) { + if strings.HasPrefix(normalized, "~") && (len(normalized) == 1 || runtime.IsPathSeparator(pt.env, normalized[1])) { normalized = pt.env.Home() + normalized[1:] } @@ -690,10 +690,10 @@ func (pt *Path) normalize(inputPath string) string { } switch pt.env.GOOS() { - case platform.WINDOWS: + case runtime.WINDOWS: normalized = pt.normalizePath(normalized) fallthrough - case platform.DARWIN: + case runtime.DARWIN: normalized = strings.ToLower(normalized) } diff --git a/src/segments/path_test.go b/src/segments/path_test.go index 9c70f6ef..3b0bee6e 100644 --- a/src/segments/path_test.go +++ b/src/segments/path_test.go @@ -6,8 +6,8 @@ import ( "testing" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/jandedobbeleer/oh-my-posh/src/shell" "github.com/jandedobbeleer/oh-my-posh/src/template" @@ -33,7 +33,7 @@ func renderTemplateNoTrimSpace(env *mock.MockedEnvironment, segmentTemplate stri } } if !found { - env.On("TemplateCache").Return(&platform.TemplateCache{ + env.On("TemplateCache").Return(&runtime.TemplateCache{ Env: make(map[string]string), }) } @@ -71,28 +71,28 @@ func TestParent(t *testing.T) { Expected: "~/", HomePath: homeDir, Pwd: homeDir + "/test", - GOOS: platform.DARWIN, + GOOS: runtime.DARWIN, PathSeparator: "/", }, { Case: "Home folder", HomePath: homeDir, Pwd: homeDir, - GOOS: platform.DARWIN, + GOOS: runtime.DARWIN, PathSeparator: "/", }, { Case: "Home folder with a trailing separator", HomePath: homeDir, Pwd: homeDir + "/", - GOOS: platform.DARWIN, + GOOS: runtime.DARWIN, PathSeparator: "/", }, { Case: "Root", HomePath: homeDir, Pwd: "/", - GOOS: platform.DARWIN, + GOOS: runtime.DARWIN, PathSeparator: "/", }, { @@ -100,28 +100,28 @@ func TestParent(t *testing.T) { Expected: "/", HomePath: homeDir, Pwd: "/usr", - GOOS: platform.DARWIN, + GOOS: runtime.DARWIN, PathSeparator: "/", }, { Case: "Windows Home folder", HomePath: homeDirWindows, Pwd: homeDirWindows, - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", }, { Case: "Windows drive root", HomePath: homeDirWindows, Pwd: "C:", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", }, { Case: "Windows drive root with a trailing separator", HomePath: homeDirWindows, Pwd: "C:\\", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", }, { @@ -129,14 +129,14 @@ func TestParent(t *testing.T) { Expected: "C:\\", HomePath: homeDirWindows, Pwd: "C:\\test", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", }, { Case: "PSDrive root", HomePath: homeDirWindows, Pwd: "HKLM:", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", }, } @@ -144,7 +144,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(&platform.Flags{}) + env.On("Flags").Return(&runtime.Flags{}) env.On("Shell").Return(shell.GENERIC) env.On("PathSeparator").Return(tc.PathSeparator) env.On("GOOS").Return(tc.GOOS) @@ -207,7 +207,7 @@ func TestAgnosterPathStyles(t *testing.T) { Expected: "C > a > ab > abcd", HomePath: homeDirWindows, Pwd: "C:\\ab\\ab\\abcd", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", FolderSeparatorIcon: " > ", }, @@ -349,7 +349,7 @@ func TestAgnosterPathStyles(t *testing.T) { Expected: "C: > ", HomePath: homeDirWindows, Pwd: "C:\\", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", FolderSeparatorIcon: " > ", }, @@ -358,7 +358,7 @@ func TestAgnosterPathStyles(t *testing.T) { Expected: "C > s > .w > man", HomePath: homeDirWindows, Pwd: "C:\\something\\.whatever\\man", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", FolderSeparatorIcon: " > ", }, @@ -367,7 +367,7 @@ func TestAgnosterPathStyles(t *testing.T) { Expected: "~ > s > man", HomePath: homeDirWindows, Pwd: homeDirWindows + "\\something\\man", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", FolderSeparatorIcon: " > ", }, @@ -417,7 +417,7 @@ func TestAgnosterPathStyles(t *testing.T) { Expected: "C: > .. > foo > .. > man", HomePath: homeDirWindows, Pwd: "C:\\Users\\foo\\foobar\\man", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", FolderSeparatorIcon: " > ", }, @@ -426,7 +426,7 @@ func TestAgnosterPathStyles(t *testing.T) { Expected: "c > .. > foo > .. > man", HomePath: homeDirWindows, Pwd: "C:\\Users\\foo\\foobar\\man", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, Shell: shell.BASH, Cygpath: "/c/Users/foo/foobar/man", PathSeparator: "\\", @@ -437,7 +437,7 @@ func TestAgnosterPathStyles(t *testing.T) { Expected: "C: > .. > foo > .. > man", HomePath: homeDirWindows, Pwd: "C:\\Users\\foo\\foobar\\man", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, Shell: shell.BASH, CygpathError: errors.New("oh no"), PathSeparator: "\\", @@ -506,7 +506,7 @@ func TestAgnosterPathStyles(t *testing.T) { Expected: "\\\\localhost\\c$ > some", HomePath: homeDirWindows, Pwd: "\\\\localhost\\c$\\some", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", FolderSeparatorIcon: " > ", }, @@ -526,7 +526,7 @@ func TestAgnosterPathStyles(t *testing.T) { Expected: "\\\\localhost\\c$", HomePath: homeDirWindows, Pwd: "\\\\localhost\\c$", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", FolderSeparatorIcon: " > ", }, @@ -560,7 +560,7 @@ func TestAgnosterPathStyles(t *testing.T) { Expected: ".. > bar > man", HomePath: homeDirWindows, Pwd: homeDirWindows + fooBarMan, - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", FolderSeparatorIcon: " > ", MaxDepth: 2, @@ -679,7 +679,7 @@ func TestAgnosterPathStyles(t *testing.T) { Expected: "C: > ", HomePath: homeDirWindows, Pwd: "C:", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", FolderSeparatorIcon: " > ", }, @@ -688,7 +688,7 @@ func TestAgnosterPathStyles(t *testing.T) { Expected: "C: > .. > bar > man", HomePath: homeDirWindows, Pwd: "C:\\usr\\foo\\bar\\man", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", FolderSeparatorIcon: " > ", MaxDepth: 2, @@ -698,7 +698,7 @@ func TestAgnosterPathStyles(t *testing.T) { Expected: "C: > .. > foo > bar > man", HomePath: homeDirWindows, Pwd: "C:\\usr\\foo\\bar\\man", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", FolderSeparatorIcon: " > ", MaxDepth: 3, @@ -708,7 +708,7 @@ func TestAgnosterPathStyles(t *testing.T) { Expected: "~ > .. > bar > man", HomePath: homeDirWindows, Pwd: homeDirWindows + fooBarMan, - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", FolderSeparatorIcon: " > ", MaxDepth: 2, @@ -718,7 +718,7 @@ func TestAgnosterPathStyles(t *testing.T) { Expected: "~ > foo > bar > man", HomePath: homeDirWindows, Pwd: homeDirWindows + fooBarMan, - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", FolderSeparatorIcon: " > ", MaxDepth: 3, @@ -728,7 +728,7 @@ func TestAgnosterPathStyles(t *testing.T) { Expected: "~", HomePath: homeDirWindows, Pwd: homeDirWindows, - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", FolderSeparatorIcon: " > ", MaxDepth: 1, @@ -739,7 +739,7 @@ func TestAgnosterPathStyles(t *testing.T) { Expected: ".. > foo", HomePath: homeDirWindows, Pwd: homeDirWindows + "\\foo", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", FolderSeparatorIcon: " > ", MaxDepth: 1, @@ -750,7 +750,7 @@ func TestAgnosterPathStyles(t *testing.T) { Expected: ".. > foo", HomePath: homeDirWindows, Pwd: homeDirWindows + "\\foo", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", FolderSeparatorIcon: " > ", MaxDepth: 2, @@ -765,7 +765,7 @@ func TestAgnosterPathStyles(t *testing.T) { env.On("GOOS").Return(tc.GOOS) env.On("StackCount").Return(0) env.On("IsWsl").Return(false) - args := &platform.Flags{ + args := &runtime.Flags{ PSWD: tc.Pswd, } env.On("Flags").Return(args) @@ -777,7 +777,7 @@ func TestAgnosterPathStyles(t *testing.T) { env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil) - displayCygpath := tc.GOOS == platform.WINDOWS && tc.Shell == shell.BASH + displayCygpath := tc.GOOS == runtime.WINDOWS && tc.Shell == shell.BASH if displayCygpath { env.On("RunCommand", "cygpath", []string{"-u", tc.Pwd}).Return(tc.Cygpath, tc.CygpathError) env.On("RunCommand", "cygpath", mock2.Anything).Return("brrrr", nil) @@ -841,11 +841,11 @@ func TestFullAndFolderPath(t *testing.T) { {Style: FolderType, FolderSeparatorIcon: "|", Pwd: abcd, Expected: "d"}, // for Windows paths - {Style: FolderType, FolderSeparatorIcon: "\\", Pwd: "C:\\", Expected: "C:\\", PathSeparator: "\\", GOOS: platform.WINDOWS}, - {Style: FolderType, 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}, + {Style: FolderType, FolderSeparatorIcon: "\\", Pwd: "C:\\", Expected: "C:\\", PathSeparator: "\\", GOOS: runtime.WINDOWS}, + {Style: FolderType, FolderSeparatorIcon: "\\", Pwd: homeDirWindows, Expected: "~", PathSeparator: "\\", GOOS: runtime.WINDOWS}, + {Style: Full, FolderSeparatorIcon: "\\", Pwd: homeDirWindows, Expected: "~", PathSeparator: "\\", GOOS: runtime.WINDOWS}, + {Style: Full, FolderSeparatorIcon: "\\", Pwd: homeDirWindows + "\\abc", Expected: "~\\abc", PathSeparator: "\\", GOOS: runtime.WINDOWS}, + {Style: Full, FolderSeparatorIcon: "\\", Pwd: "C:\\Users\\posh", Expected: "C:\\Users\\posh", PathSeparator: "\\", GOOS: runtime.WINDOWS}, // StackCountEnabled=true and StackCount=2 {Style: Full, FolderSeparatorIcon: "|", Pwd: "/", StackCount: 2, Expected: "2 /"}, @@ -894,7 +894,7 @@ func TestFullAndFolderPath(t *testing.T) { tc.PathSeparator = "/" } env.On("PathSeparator").Return(tc.PathSeparator) - if tc.GOOS == platform.WINDOWS { + if tc.GOOS == runtime.WINDOWS { env.On("Home").Return(homeDirWindows) } else { env.On("Home").Return(homeDir) @@ -903,7 +903,7 @@ func TestFullAndFolderPath(t *testing.T) { env.On("GOOS").Return(tc.GOOS) env.On("StackCount").Return(tc.StackCount) env.On("IsWsl").Return(false) - args := &platform.Flags{ + args := &runtime.Flags{ PSWD: tc.Pswd, } env.On("Flags").Return(args) @@ -942,7 +942,7 @@ func TestFullPathCustomMappedLocations(t *testing.T) { }{ {Pwd: abcd, MappedLocations: map[string]string{"{{ .Env.HOME }}/d": "#"}, Expected: "#"}, {Pwd: abcd, MappedLocations: map[string]string{abcd: "#"}, Expected: "#"}, - {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": "#"}, GOOS: runtime.WINDOWS, PathSeparator: "\\", Expected: "#\\c\\d"}, {Pwd: abcd, MappedLocations: map[string]string{"/a/b": "#"}, Expected: "#/c/d"}, {Pwd: abcd, MappedLocations: map[string]string{"/a/b": "/e/f"}, Expected: "/e/f/c/d"}, {Pwd: homeDir + abcd, MappedLocations: map[string]string{"~/a/b": "#"}, Expected: "#/c/d"}, @@ -956,7 +956,7 @@ func TestFullPathCustomMappedLocations(t *testing.T) { env.On("Pwd").Return(tc.Pwd) if len(tc.GOOS) == 0 { - tc.GOOS = platform.DARWIN + tc.GOOS = runtime.DARWIN } env.On("GOOS").Return(tc.GOOS) @@ -966,14 +966,14 @@ func TestFullPathCustomMappedLocations(t *testing.T) { } env.On("PathSeparator").Return(tc.PathSeparator) - args := &platform.Flags{ + args := &runtime.Flags{ PSWD: tc.Pwd, } env.On("Flags").Return(args) env.On("Shell").Return(shell.GENERIC) env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil) - env.On("TemplateCache").Return(&platform.TemplateCache{ + env.On("TemplateCache").Return(&runtime.TemplateCache{ Env: map[string]string{ "HOME": "/a/b/c", }, @@ -1008,7 +1008,7 @@ func TestPowerlevelMappedLocations(t *testing.T) { env := new(mock.MockedEnvironment) env.On("Home").Return("/Users/michal") env.On("Pwd").Return(tc.Pwd) - env.On("GOOS").Return(platform.DARWIN) + env.On("GOOS").Return(runtime.DARWIN) env.On("PathSeparator").Return("/") env.On("Shell").Return(shell.GENERIC) env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil) @@ -1033,7 +1033,7 @@ func TestFolderPathCustomMappedLocations(t *testing.T) { env.On("Home").Return(homeDir) env.On("Pwd").Return(pwd) env.On("GOOS").Return("") - args := &platform.Flags{ + args := &runtime.Flags{ PSWD: pwd, } env.On("Flags").Return(args) @@ -1070,7 +1070,7 @@ func TestAgnosterPath(t *testing.T) { Expected: "\uf013 > f > magnetic:TOAST", Home: homeDirWindows, PWD: "HKLM:\\SOFTWARE\\magnetic:TOAST\\", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", }, { @@ -1078,7 +1078,7 @@ func TestAgnosterPath(t *testing.T) { Expected: "C: > f > f > location", Home: homeDirWindows, PWD: "C:\\Program Files\\Go\\location", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", }, { @@ -1086,7 +1086,7 @@ func TestAgnosterPath(t *testing.T) { Expected: "~ > f > f > location", Home: homeDirWindows, PWD: homeDirWindows + "\\Documents\\Bill\\location", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", }, { @@ -1094,7 +1094,7 @@ func TestAgnosterPath(t *testing.T) { Expected: "C: > location", Home: homeDirWindows, PWD: "C:\\location", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", }, { @@ -1102,7 +1102,7 @@ func TestAgnosterPath(t *testing.T) { Expected: "C: > f > location", Home: homeDirWindows, PWD: "C:\\Program Files\\location", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", }, { @@ -1110,7 +1110,7 @@ func TestAgnosterPath(t *testing.T) { Expected: "C: > Windows", Home: homeDirWindows, PWD: "C:\\Windows\\", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", }, { @@ -1118,7 +1118,7 @@ func TestAgnosterPath(t *testing.T) { Expected: "P: > Other", Home: homeDirWindows, PWD: "P:\\Other\\", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", }, { @@ -1126,7 +1126,7 @@ func TestAgnosterPath(t *testing.T) { Expected: "some: > some", Home: homeDirWindows, PWD: "some:\\some\\", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", }, { @@ -1134,7 +1134,7 @@ func TestAgnosterPath(t *testing.T) { Expected: "src: > source", Home: homeDirWindows, PWD: "src:\\source\\", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", }, { @@ -1142,7 +1142,7 @@ func TestAgnosterPath(t *testing.T) { Expected: "sRc: > source", Home: homeDirWindows, PWD: "sRc:\\source\\", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", }, { @@ -1150,7 +1150,7 @@ func TestAgnosterPath(t *testing.T) { Expected: "\uf013 > f > magnetic:test", Home: homeDirWindows, PWD: "HKLM:\\SOFTWARE\\magnetic:test\\", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", }, { @@ -1213,7 +1213,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 := &platform.Flags{ + args := &runtime.Flags{ PSWD: tc.PWD, } env.On("Flags").Return(args) @@ -1250,7 +1250,7 @@ func TestAgnosterLeftPath(t *testing.T) { Expected: "~ > Documents > f > f", Home: homeDirWindows, PWD: homeDirWindows + "\\Documents\\Bill\\location", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", }, { @@ -1258,7 +1258,7 @@ func TestAgnosterLeftPath(t *testing.T) { Expected: "C: > Program Files > f > f", Home: homeDirWindows, PWD: "C:\\Program Files\\Go\\location", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", }, { @@ -1266,7 +1266,7 @@ func TestAgnosterLeftPath(t *testing.T) { Expected: "C: > location", Home: homeDirWindows, PWD: "C:\\location", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", }, { @@ -1274,7 +1274,7 @@ func TestAgnosterLeftPath(t *testing.T) { Expected: "C: > Program Files > f", Home: homeDirWindows, PWD: "C:\\Program Files\\location", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", }, { @@ -1282,7 +1282,7 @@ func TestAgnosterLeftPath(t *testing.T) { Expected: "C: > Windows", Home: homeDirWindows, PWD: "C:\\Windows\\", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", }, { @@ -1290,7 +1290,7 @@ func TestAgnosterLeftPath(t *testing.T) { Expected: "P: > Other", Home: homeDirWindows, PWD: "P:\\Other\\", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", }, { @@ -1298,7 +1298,7 @@ func TestAgnosterLeftPath(t *testing.T) { Expected: "some: > some", Home: homeDirWindows, PWD: "some:\\some\\", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", }, { @@ -1306,7 +1306,7 @@ func TestAgnosterLeftPath(t *testing.T) { Expected: "src: > source", Home: homeDirWindows, PWD: "src:\\source\\", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", }, { @@ -1314,7 +1314,7 @@ func TestAgnosterLeftPath(t *testing.T) { Expected: "sRc: > source", Home: homeDirWindows, PWD: "sRc:\\source\\", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", }, { @@ -1322,7 +1322,7 @@ func TestAgnosterLeftPath(t *testing.T) { Expected: "\uf013 > SOFTWARE > f", Home: homeDirWindows, PWD: "HKLM:\\SOFTWARE\\magnetic:test\\", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", }, { @@ -1330,7 +1330,7 @@ func TestAgnosterLeftPath(t *testing.T) { Expected: "\uf013 > SOFTWARE > f", Home: homeDirWindows, PWD: "HKLM:\\SOFTWARE\\magnetic:TOAST\\", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, PathSeparator: "\\", }, { @@ -1369,7 +1369,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 := &platform.Flags{ + args := &runtime.Flags{ PSWD: tc.PWD, } env.On("Flags").Return(args) @@ -1422,7 +1422,7 @@ func TestGetPwd(t *testing.T) { env.On("Home").Return(homeDir) env.On("Pwd").Return(tc.Pwd) env.On("GOOS").Return("") - args := &platform.Flags{ + args := &runtime.Flags{ PSWD: tc.Pswd, } env.On("Flags").Return(args) @@ -1476,7 +1476,7 @@ func TestGetFolderSeparator(t *testing.T) { props[FolderSeparatorIcon] = tc.FolderSeparatorIcon } - env.On("TemplateCache").Return(&platform.TemplateCache{ + env.On("TemplateCache").Return(&runtime.TemplateCache{ Env: make(map[string]string), Shell: "bash", }) @@ -1494,14 +1494,14 @@ func TestNormalizePath(t *testing.T) { GOOS string Expected string }{ - {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"}, + {Input: "/foo/~/bar", HomeDir: homeDirWindows, GOOS: runtime.WINDOWS, Expected: "\\foo\\~\\bar"}, + {Input: homeDirWindows + "\\Foo", HomeDir: homeDirWindows, GOOS: runtime.WINDOWS, Expected: "c:\\users\\someone\\foo"}, + {Input: "~/Bob\\Foo", HomeDir: homeDir, GOOS: runtime.LINUX, Expected: homeDir + "/Bob\\Foo"}, + {Input: "~/Bob\\Foo", HomeDir: homeDir, GOOS: runtime.DARWIN, Expected: homeDir + "/bob\\foo"}, + {Input: "~\\Bob\\Foo", HomeDir: homeDirWindows, GOOS: runtime.WINDOWS, Expected: "c:\\users\\someone\\bob\\foo"}, + {Input: "/foo/~/bar", HomeDir: homeDir, GOOS: runtime.LINUX, Expected: "/foo/~/bar"}, + {Input: "~/baz", HomeDir: homeDir, GOOS: runtime.LINUX, Expected: homeDir + "/baz"}, + {Input: "~/baz", HomeDir: homeDirWindows, GOOS: runtime.WINDOWS, Expected: "c:\\users\\someone\\baz"}, } for _, tc := range cases { @@ -1536,7 +1536,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(platform.DARWIN) + env.On("GOOS").Return(runtime.DARWIN) env.On("Home").Return("/a/b/k") env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil) path := &Path{ @@ -1562,7 +1562,7 @@ func TestSplitPath(t *testing.T) { GOOS string Relative string Root string - GitDir *platform.FileInfo + GitDir *runtime.FileInfo GitDirFormat string Expected Folders }{ @@ -1571,7 +1571,7 @@ func TestSplitPath(t *testing.T) { Case: "Regular directory", Root: "/", Relative: "c/d", - GOOS: platform.DARWIN, + GOOS: runtime.DARWIN, Expected: Folders{ {Name: "c", Path: "/c"}, {Name: "d", Path: "/c/d"}, @@ -1581,8 +1581,8 @@ func TestSplitPath(t *testing.T) { Case: "Home directory - git folder", Root: "~", Relative: "c/d", - GOOS: platform.DARWIN, - GitDir: &platform.FileInfo{IsDir: true, ParentFolder: "/a/b/c"}, + GOOS: runtime.DARWIN, + GitDir: &runtime.FileInfo{IsDir: true, ParentFolder: "/a/b/c"}, GitDirFormat: "%s", Expected: Folders{ {Name: "c", Path: "/a/b/c", Display: true}, @@ -1593,8 +1593,8 @@ func TestSplitPath(t *testing.T) { Case: "Home directory - git folder on Windows", Root: "C:", Relative: "a/b/c/d", - GOOS: platform.WINDOWS, - GitDir: &platform.FileInfo{IsDir: true, ParentFolder: "C:/a/b/c"}, + GOOS: runtime.WINDOWS, + GitDir: &runtime.FileInfo{IsDir: true, ParentFolder: "C:/a/b/c"}, GitDirFormat: "%s", Expected: Folders{ {Name: "a", Path: "C:/a"}, @@ -1619,7 +1619,7 @@ func TestSplitPath(t *testing.T) { root: tc.Root, relative: tc.Relative, pathSeparator: "/", - windowsPath: tc.GOOS == platform.WINDOWS, + windowsPath: tc.GOOS == runtime.WINDOWS, } got := path.splitPath() @@ -1658,7 +1658,7 @@ func TestGetMaxWidth(t *testing.T) { env := new(mock.MockedEnvironment) env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil) env.On("Error", mock2.Anything).Return(nil) - env.On("TemplateCache").Return(&platform.TemplateCache{ + env.On("TemplateCache").Return(&runtime.TemplateCache{ Env: map[string]string{ "MAX_WIDTH": "120", }, diff --git a/src/segments/perl.go b/src/segments/perl.go index 826010d6..a849977b 100644 --- a/src/segments/perl.go +++ b/src/segments/perl.go @@ -1,8 +1,8 @@ package segments import ( - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Perl struct { @@ -13,7 +13,7 @@ func (p *Perl) Template() string { return languageTemplate } -func (p *Perl) Init(props properties.Properties, env platform.Environment) { +func (p *Perl) Init(props properties.Properties, env runtime.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 86f9bbfc..acf22eb9 100644 --- a/src/segments/php.go +++ b/src/segments/php.go @@ -1,8 +1,8 @@ package segments import ( - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Php struct { @@ -13,7 +13,7 @@ func (p *Php) Template() string { return languageTemplate } -func (p *Php) Init(props properties.Properties, env platform.Environment) { +func (p *Php) Init(props properties.Properties, env runtime.Environment) { p.language = language{ env: env, props: props, diff --git a/src/segments/plastic.go b/src/segments/plastic.go index e0a05b8b..9d9e1f13 100644 --- a/src/segments/plastic.go +++ b/src/segments/plastic.go @@ -5,9 +5,9 @@ import ( "strconv" "strings" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" "github.com/jandedobbeleer/oh-my-posh/src/regex" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type PlasticStatus struct { @@ -38,7 +38,7 @@ type Plastic struct { plasticWorkspaceFolder string // root folder of workspace } -func (p *Plastic) Init(props properties.Properties, env platform.Environment) { +func (p *Plastic) Init(props properties.Properties, env runtime.Environment) { p.props = props p.env = env } diff --git a/src/segments/plastic_test.go b/src/segments/plastic_test.go index ab97a127..016892bb 100644 --- a/src/segments/plastic_test.go +++ b/src/segments/plastic_test.go @@ -4,8 +4,8 @@ import ( "testing" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/stretchr/testify/assert" ) @@ -30,7 +30,7 @@ func TestPlasticEnabledInWorkspaceDirectory(t *testing.T) { env.On("GOOS").Return("") env.On("IsWsl").Return(false) env.On("FileContent", "/dir/.plastic//plastic.selector").Return("") - fileInfo := &platform.FileInfo{ + fileInfo := &runtime.FileInfo{ Path: "/dir/hello", ParentFolder: "/dir", IsDir: true, diff --git a/src/segments/pnpm.go b/src/segments/pnpm.go index 975294c7..5b848aac 100644 --- a/src/segments/pnpm.go +++ b/src/segments/pnpm.go @@ -1,8 +1,8 @@ package segments import ( - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Pnpm struct { @@ -17,7 +17,7 @@ func (n *Pnpm) Template() string { return " \U000F02C1 {{.Full}} " } -func (n *Pnpm) Init(props properties.Properties, env platform.Environment) { +func (n *Pnpm) Init(props properties.Properties, env runtime.Environment) { n.language = language{ env: env, props: props, diff --git a/src/segments/posh_git_test.go b/src/segments/posh_git_test.go index a82ae2c9..b43d9a60 100644 --- a/src/segments/posh_git_test.go +++ b/src/segments/posh_git_test.go @@ -4,8 +4,8 @@ import ( "testing" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/stretchr/testify/assert" ) @@ -185,7 +185,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(platform.LINUX) + env.On("GOOS").Return(runtime.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 2d2656a6..22a8602c 100644 --- a/src/segments/project.go +++ b/src/segments/project.go @@ -7,9 +7,9 @@ import ( "path/filepath" "strings" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" "github.com/jandedobbeleer/oh-my-posh/src/regex" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "golang.org/x/exp/slices" toml "github.com/pelletier/go-toml/v2" @@ -53,7 +53,7 @@ type NuSpec struct { type Project struct { props properties.Properties - env platform.Environment + env runtime.Environment projects []*ProjectItem Error string @@ -80,7 +80,7 @@ func (n *Project) Template() string { return " {{ if .Error }}{{ .Error }}{{ else }}{{ if .Version }}\uf487 {{.Version}} {{ end }}{{ if .Name }}{{ .Name }} {{ end }}{{ if .Target }}\uf4de {{.Target}} {{ end }}{{ end }}" //nolint:lll } -func (n *Project) Init(props properties.Properties, env platform.Environment) { +func (n *Project) Init(props properties.Properties, env runtime.Environment) { n.props = props n.env = env diff --git a/src/segments/pulumi.go b/src/segments/pulumi.go index eeab7c1f..be292d48 100644 --- a/src/segments/pulumi.go +++ b/src/segments/pulumi.go @@ -7,8 +7,8 @@ import ( "fmt" "path/filepath" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "gopkg.in/yaml.v3" ) @@ -25,7 +25,7 @@ const ( type Pulumi struct { props properties.Properties - env platform.Environment + env runtime.Environment Stack string Name string @@ -52,7 +52,7 @@ func (p *Pulumi) Template() string { return "\U000f0d46 {{ .Stack }}{{if .User }} :: {{ .User }}@{{ end }}{{ if .URL }}{{ .URL }}{{ end }}" } -func (p *Pulumi) Init(props properties.Properties, env platform.Environment) { +func (p *Pulumi) Init(props properties.Properties, env runtime.Environment) { p.props = props p.env = env } diff --git a/src/segments/python.go b/src/segments/python.go index ba518b05..1d9c8ffa 100644 --- a/src/segments/python.go +++ b/src/segments/python.go @@ -7,8 +7,8 @@ import ( "slices" "strings" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Python struct { @@ -28,7 +28,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 platform.Environment) { +func (p *Python) Init(props properties.Properties, env runtime.Environment) { p.language = language{ env: env, props: props, @@ -93,10 +93,10 @@ func (p *Python) loadContext() { continue } - name := platform.Base(p.language.env, venv) + name := runtime.Base(p.language.env, venv) if folderNameFallback && slices.Contains(defaultVenvNames, name) { venv = strings.TrimSuffix(venv, name) - name = platform.Base(p.language.env, venv) + name = runtime.Base(p.language.env, venv) } if p.canUseVenvName(name) { diff --git a/src/segments/python_test.go b/src/segments/python_test.go index 63754473..c1698d8e 100644 --- a/src/segments/python_test.go +++ b/src/segments/python_test.go @@ -6,8 +6,8 @@ import ( "testing" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/alecthomas/assert" mock2 "github.com/stretchr/testify/mock" @@ -140,7 +140,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(&platform.FileInfo{}, errors.New("no match at root level")) + env.On("HasParentFilePath", ".python-version").Return(&runtime.FileInfo{}, errors.New("no match at root level")) python := &Python{} python.Init(properties.Map{}, env) python.loadContext() @@ -188,7 +188,7 @@ func TestPythonVirtualEnvIgnoreDefaultVenvNames(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(&platform.FileInfo{}, errors.New("no match at root level")) + env.On("HasParentFilePath", ".python-version").Return(&runtime.FileInfo{}, errors.New("no match at root level")) props[FolderNameFallback] = tc.FolderNameFallback diff --git a/src/segments/quasar.go b/src/segments/quasar.go index fb9c24b8..a36ae935 100644 --- a/src/segments/quasar.go +++ b/src/segments/quasar.go @@ -4,8 +4,8 @@ import ( "encoding/json" "path/filepath" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) const ( @@ -41,7 +41,7 @@ func (q *Quasar) Template() string { return " \uea6a {{.Full}}{{ if .HasVite }} \ueb29 {{ .Vite.Version }}{{ end }} " } -func (q *Quasar) Init(props properties.Properties, env platform.Environment) { +func (q *Quasar) Init(props properties.Properties, env runtime.Environment) { q.language = language{ env: env, props: props, diff --git a/src/segments/quasar_test.go b/src/segments/quasar_test.go index fc4bc815..92116345 100644 --- a/src/segments/quasar_test.go +++ b/src/segments/quasar_test.go @@ -6,7 +6,7 @@ import ( "testing" "github.com/alecthomas/assert" - "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) func TestQuasar(t *testing.T) { @@ -64,7 +64,7 @@ func TestQuasar(t *testing.T) { env, props := getMockedLanguageEnv(params) env.On("HasFilesInDir", "/usr/home/project", "package-lock.json").Return(tc.HasPackageLockFile) - fileInfo := &platform.FileInfo{ParentFolder: "/usr/home/project", IsDir: true} + fileInfo := &runtime.FileInfo{ParentFolder: "/usr/home/project", IsDir: true} env.On("HasParentFilePath", "quasar.config").Return(fileInfo, nil) env.On("FileContent", filepath.Join(fileInfo.ParentFolder, "package-lock.json")).Return(packageLockFile) diff --git a/src/segments/r.go b/src/segments/r.go index 4b6f883e..eae27b48 100644 --- a/src/segments/r.go +++ b/src/segments/r.go @@ -1,8 +1,8 @@ package segments import ( - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type R struct { @@ -13,7 +13,7 @@ func (r *R) Template() string { return languageTemplate } -func (r *R) Init(props properties.Properties, env platform.Environment) { +func (r *R) Init(props properties.Properties, env runtime.Environment) { rRegex := `version (?P((?P[0-9]+).(?P[0-9]+).(?P[0-9]+)))` r.language = language{ env: env, diff --git a/src/segments/react.go b/src/segments/react.go index 65bff2e7..e825838f 100644 --- a/src/segments/react.go +++ b/src/segments/react.go @@ -1,8 +1,8 @@ package segments import ( - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type React struct { @@ -13,7 +13,7 @@ func (r *React) Template() string { return languageTemplate } -func (r *React) Init(props properties.Properties, env platform.Environment) { +func (r *React) Init(props properties.Properties, env runtime.Environment) { r.language = language{ env: env, props: props, diff --git a/src/segments/root.go b/src/segments/root.go index 27be4bf0..616d459f 100644 --- a/src/segments/root.go +++ b/src/segments/root.go @@ -1,13 +1,13 @@ package segments import ( - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Root struct { props properties.Properties - env platform.Environment + env runtime.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 platform.Environment) { +func (rt *Root) Init(props properties.Properties, env runtime.Environment) { rt.props = props rt.env = env } diff --git a/src/segments/ruby.go b/src/segments/ruby.go index f2cbe751..7c09f53d 100644 --- a/src/segments/ruby.go +++ b/src/segments/ruby.go @@ -1,8 +1,8 @@ package segments import ( - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Ruby struct { @@ -13,7 +13,7 @@ func (r *Ruby) Template() string { return languageTemplate } -func (r *Ruby) Init(props properties.Properties, env platform.Environment) { +func (r *Ruby) Init(props properties.Properties, env runtime.Environment) { r.language = language{ env: env, props: props, diff --git a/src/segments/rust.go b/src/segments/rust.go index 9835e2af..16d1aaa5 100644 --- a/src/segments/rust.go +++ b/src/segments/rust.go @@ -1,8 +1,8 @@ package segments import ( - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Rust struct { @@ -13,7 +13,7 @@ func (r *Rust) Template() string { return languageTemplate } -func (r *Rust) Init(props properties.Properties, env platform.Environment) { +func (r *Rust) Init(props properties.Properties, env runtime.Environment) { r.language = language{ env: env, props: props, diff --git a/src/segments/sapling.go b/src/segments/sapling.go index 5ad9c8f6..47a1e48a 100644 --- a/src/segments/sapling.go +++ b/src/segments/sapling.go @@ -3,7 +3,7 @@ package segments import ( "strings" - "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) // SaplingStatus represents part of the status of a Sapling repository @@ -89,14 +89,14 @@ func (sl *Sapling) shouldDisplay() bool { sl.rootDir = slDir.Path // convert the worktree file path to a windows one when in a WSL shared folder sl.realDir = strings.TrimSuffix(sl.convertToWindowsPath(slDir.Path), "/.sl") - sl.RepoName = platform.Base(sl.env, sl.convertToLinuxPath(sl.realDir)) + sl.RepoName = runtime.Base(sl.env, sl.convertToLinuxPath(sl.realDir)) sl.setDir(slDir.Path) return true } func (sl *Sapling) setDir(dir string) { - dir = platform.ReplaceHomeDirPrefixWithTilde(sl.env, dir) // align with template PWD - if sl.env.GOOS() == platform.WINDOWS { + dir = runtime.ReplaceHomeDirPrefixWithTilde(sl.env, dir) // align with template PWD + if sl.env.GOOS() == runtime.WINDOWS { sl.Dir = strings.TrimSuffix(dir, `\.sl`) return } diff --git a/src/segments/sapling_test.go b/src/segments/sapling_test.go index 11dbc46a..2e256d48 100644 --- a/src/segments/sapling_test.go +++ b/src/segments/sapling_test.go @@ -6,8 +6,8 @@ import ( "github.com/alecthomas/assert" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) func TestSetDir(t *testing.T) { @@ -21,32 +21,32 @@ func TestSetDir(t *testing.T) { Case: "In home folder", Expected: "~/sapling", Path: "/usr/home/sapling/.sl", - GOOS: platform.LINUX, + GOOS: runtime.LINUX, }, { Case: "Outside home folder", Expected: "/usr/sapling/repo", Path: "/usr/sapling/repo/.sl", - GOOS: platform.LINUX, + GOOS: runtime.LINUX, }, { Case: "Windows home folder", Expected: "~\\sapling", Path: "\\usr\\home\\sapling\\.sl", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, }, { Case: "Windows outside home folder", Expected: "\\usr\\sapling\\repo", Path: "\\usr\\sapling\\repo\\.sl", - GOOS: platform.WINDOWS, + GOOS: runtime.WINDOWS, }, } for _, tc := range cases { env := new(mock.MockedEnvironment) env.On("GOOS").Return(tc.GOOS) home := "/usr/home" - if tc.GOOS == platform.WINDOWS { + if tc.GOOS == runtime.WINDOWS { home = "\\usr\\home" } env.On("Home").Return(home) @@ -145,7 +145,7 @@ func TestShouldDisplay(t *testing.T) { Expected: true, }, } - fileInfo := &platform.FileInfo{ + fileInfo := &runtime.FileInfo{ Path: "/sapling/repo/.sl", ParentFolder: "/sapling/repo", IsDir: true, @@ -154,13 +154,13 @@ func TestShouldDisplay(t *testing.T) { env := new(mock.MockedEnvironment) env.On("HasCommand", "sl").Return(tc.HasSapling) env.On("InWSLSharedDrive").Return(false) - env.On("GOOS").Return(platform.LINUX) + env.On("GOOS").Return(runtime.LINUX) env.On("Home").Return("/usr/home/sapling") env.On("DirMatchesOneOf", fileInfo.ParentFolder, []string{"/sapling/repo"}).Return(tc.Excluded) if tc.InRepo { env.On("HasParentFilePath", ".sl").Return(fileInfo, nil) } else { - env.On("HasParentFilePath", ".sl").Return(&platform.FileInfo{}, errors.New("error")) + env.On("HasParentFilePath", ".sl").Return(&runtime.FileInfo{}, errors.New("error")) } sl := &Sapling{ scm: scm{ diff --git a/src/segments/scm.go b/src/segments/scm.go index 9b5f72c7..33260c93 100644 --- a/src/segments/scm.go +++ b/src/segments/scm.go @@ -4,8 +4,8 @@ import ( "fmt" "strings" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) const ( @@ -81,7 +81,7 @@ func (s *ScmStatus) String() string { type scm struct { props properties.Properties - env platform.Environment + env runtime.Environment IsWslSharedPath bool CommandMissing bool @@ -104,7 +104,7 @@ const ( FullBranchPath properties.Property = "full_branch_path" ) -func (s *scm) Init(props properties.Properties, env platform.Environment) { +func (s *scm) Init(props properties.Properties, env runtime.Environment) { s.props = props s.env = env } @@ -140,7 +140,7 @@ func (s *scm) FileContents(folder, file string) string { func (s *scm) convertToWindowsPath(path string) string { // only convert when in Windows, or when in a WSL shared folder and not using the native fallback - if s.env.GOOS() == platform.WINDOWS || (s.IsWslSharedPath && !s.nativeFallback) { + if s.env.GOOS() == runtime.WINDOWS || (s.IsWslSharedPath && !s.nativeFallback) { return s.env.ConvertToWindowsPath(path) } @@ -163,7 +163,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, except when native_fallback is set s.IsWslSharedPath = s.env.InWSLSharedDrive() - if s.env.GOOS() == platform.WINDOWS || s.IsWslSharedPath { + if s.env.GOOS() == runtime.WINDOWS || s.IsWslSharedPath { command += ".exe" } diff --git a/src/segments/scm_test.go b/src/segments/scm_test.go index 6ea0deda..db8ab660 100644 --- a/src/segments/scm_test.go +++ b/src/segments/scm_test.go @@ -4,8 +4,8 @@ import ( "testing" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/stretchr/testify/assert" ) @@ -186,7 +186,7 @@ func TestHasCommand(t *testing.T) { IsWslSharedPath bool NativeFallback bool }{ - {Case: "On Windows", ExpectedCommand: "git.exe", GOOS: platform.WINDOWS}, + {Case: "On Windows", ExpectedCommand: "git.exe", GOOS: runtime.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 bfe21a76..b7e45634 100644 --- a/src/segments/session.go +++ b/src/segments/session.go @@ -1,14 +1,14 @@ package segments import ( - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" "github.com/jandedobbeleer/oh-my-posh/src/regex" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Session struct { props properties.Properties - env platform.Environment + env runtime.Environment // text string SSHSession bool @@ -26,7 +26,7 @@ func (s *Session) Template() string { return " {{ if .SSHSession }}\ueba9 {{ end }}{{ .UserName }}@{{ .HostName }} " } -func (s *Session) Init(props properties.Properties, env platform.Environment) { +func (s *Session) Init(props properties.Properties, env runtime.Environment) { s.props = props s.env = env } @@ -44,7 +44,7 @@ func (s *Session) activeSSHSession() bool { } } - if s.env.Platform() == platform.WINDOWS { + if s.env.Platform() == runtime.WINDOWS { return false } diff --git a/src/segments/session_test.go b/src/segments/session_test.go index b43d910c..7fe6b32d 100644 --- a/src/segments/session_test.go +++ b/src/segments/session_test.go @@ -5,8 +5,8 @@ import ( "testing" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/stretchr/testify/assert" ) @@ -105,7 +105,7 @@ func TestSessionSegmentTemplate(t *testing.T) { UserName: "john", SSHSession: false, WhoAmI: "sascha pts/1 2023-11-08 22:56 (89.246.1.1)", - Platform: platform.WINDOWS, + Platform: runtime.WINDOWS, ComputerName: "remote", Template: "{{.UserName}}{{if .SSHSession}} on {{.HostName}}{{end}}", }, @@ -122,7 +122,7 @@ func TestSessionSegmentTemplate(t *testing.T) { } env.On("Getenv", "SSH_CONNECTION").Return(SSHSession) env.On("Getenv", "SSH_CLIENT").Return(SSHSession) - env.On("TemplateCache").Return(&platform.TemplateCache{ + env.On("TemplateCache").Return(&runtime.TemplateCache{ UserName: tc.UserName, HostName: tc.ComputerName, Env: map[string]string{ diff --git a/src/segments/shell.go b/src/segments/shell.go index 4f36f3a3..0488d239 100644 --- a/src/segments/shell.go +++ b/src/segments/shell.go @@ -3,13 +3,13 @@ package segments import ( "strings" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Shell struct { props properties.Properties - env platform.Environment + env runtime.Environment Name string Version string @@ -37,7 +37,7 @@ func (s *Shell) Enabled() bool { return true } -func (s *Shell) Init(props properties.Properties, env platform.Environment) { +func (s *Shell) Init(props properties.Properties, env runtime.Environment) { s.props = props s.env = env } diff --git a/src/segments/shell_test.go b/src/segments/shell_test.go index 2e1e3bbb..1b7399a5 100644 --- a/src/segments/shell_test.go +++ b/src/segments/shell_test.go @@ -4,8 +4,8 @@ import ( "testing" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/stretchr/testify/assert" ) @@ -14,7 +14,7 @@ func TestWriteCurrentShell(t *testing.T) { expected := "zsh" env := new(mock.MockedEnvironment) env.On("Shell").Return(expected, nil) - env.On("Flags").Return(&platform.Flags{ShellVersion: "1.2.3"}) + env.On("Flags").Return(&runtime.Flags{ShellVersion: "1.2.3"}) s := &Shell{ env: env, props: properties.Map{}, @@ -35,7 +35,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(&platform.Flags{ShellVersion: "1.2.3"}) + env.On("Flags").Return(&runtime.Flags{ShellVersion: "1.2.3"}) s := &Shell{ env: env, props: properties.Map{ diff --git a/src/segments/sitecore.go b/src/segments/sitecore.go index 3a9ca63d..198fbb88 100644 --- a/src/segments/sitecore.go +++ b/src/segments/sitecore.go @@ -4,8 +4,8 @@ import ( "encoding/json" "path" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) const ( @@ -17,7 +17,7 @@ const ( type Sitecore struct { props properties.Properties - env platform.Environment + env runtime.Environment EndpointName string CmHost string @@ -62,7 +62,7 @@ func (s *Sitecore) Template() string { return "{{ .EndpointName }} {{ if .CmHost }}({{ .CmHost }}){{ end }}" } -func (s *Sitecore) Init(props properties.Properties, env platform.Environment) { +func (s *Sitecore) Init(props properties.Properties, env runtime.Environment) { s.props = props s.env = env } diff --git a/src/segments/spotify.go b/src/segments/spotify.go index ab9ab1f8..50ffde51 100644 --- a/src/segments/spotify.go +++ b/src/segments/spotify.go @@ -1,13 +1,13 @@ package segments import ( - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Spotify struct { props properties.Properties - env platform.Environment + env runtime.Environment MusicPlayer } @@ -48,7 +48,7 @@ func (s *Spotify) resolveIcon() { } } -func (s *Spotify) Init(props properties.Properties, env platform.Environment) { +func (s *Spotify) Init(props properties.Properties, env runtime.Environment) { s.props = props s.env = env } diff --git a/src/segments/spotify_windows_test.go b/src/segments/spotify_windows_test.go index 51d75c6a..d20840dd 100644 --- a/src/segments/spotify_windows_test.go +++ b/src/segments/spotify_windows_test.go @@ -6,8 +6,8 @@ import ( "testing" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/stretchr/testify/assert" ) @@ -41,7 +41,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("", &platform.NotImplemented{}) + env.On("QueryWindowTitles", "msedge.exe", `^(Spotify.*)`).Return("", &runtime.NotImplemented{}) s := &Spotify{ env: env, props: properties.Map{}, @@ -81,7 +81,7 @@ func TestSpotifyWindowsPWA(t *testing.T) { } for _, tc := range cases { env := new(mock.MockedEnvironment) - env.On("QueryWindowTitles", "spotify.exe", "^(Spotify.*)|(.*\\s-\\s.*)$").Return("", &platform.NotImplemented{}) + env.On("QueryWindowTitles", "spotify.exe", "^(Spotify.*)|(.*\\s-\\s.*)$").Return("", &runtime.NotImplemented{}) env.On("QueryWindowTitles", "msedge.exe", "^(Spotify.*)").Return(tc.Title, tc.Error) s := &Spotify{ env: env, diff --git a/src/segments/status.go b/src/segments/status.go index 14bbf83d..47b2abc8 100644 --- a/src/segments/status.go +++ b/src/segments/status.go @@ -4,8 +4,8 @@ import ( "strconv" "strings" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/jandedobbeleer/oh-my-posh/src/template" ) @@ -16,7 +16,7 @@ const ( type Status struct { props properties.Properties - env platform.Environment + env runtime.Environment String string Error bool @@ -46,7 +46,7 @@ func (s *Status) Enabled() bool { return s.Error } -func (s *Status) Init(props properties.Properties, env platform.Environment) { +func (s *Status) Init(props properties.Properties, env runtime.Environment) { s.props = props s.env = env diff --git a/src/segments/status_test.go b/src/segments/status_test.go index 170df51e..d0da0b84 100644 --- a/src/segments/status_test.go +++ b/src/segments/status_test.go @@ -4,8 +4,8 @@ import ( "testing" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/stretchr/testify/assert" mock2 "github.com/stretchr/testify/mock" @@ -26,7 +26,7 @@ func TestStatusWriterEnabled(t *testing.T) { for _, tc := range cases { env := new(mock.MockedEnvironment) env.On("StatusCodes").Return(tc.Status, "") - env.On("TemplateCache").Return(&platform.TemplateCache{ + env.On("TemplateCache").Return(&runtime.TemplateCache{ Code: 133, }) env.On("Error", mock2.Anything).Return(nil) @@ -92,7 +92,7 @@ func TestFormatStatus(t *testing.T) { for _, tc := range cases { env := new(mock.MockedEnvironment) - env.On("TemplateCache").Return(&platform.TemplateCache{ + env.On("TemplateCache").Return(&runtime.TemplateCache{ Code: 133, }) env.On("Error", mock2.Anything).Return(nil) diff --git a/src/segments/strava.go b/src/segments/strava.go index f561c1f4..564141f1 100644 --- a/src/segments/strava.go +++ b/src/segments/strava.go @@ -6,8 +6,8 @@ import ( "time" "github.com/jandedobbeleer/oh-my-posh/src/http" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) // StravaAPI is a wrapper around http.Oauth @@ -126,7 +126,7 @@ func (s *Strava) getActivityIcon() string { return s.props.GetString(UnknownActivityIcon, "\ue213") } -func (s *Strava) Init(props properties.Properties, env platform.Environment) { +func (s *Strava) Init(props properties.Properties, env runtime.Environment) { s.props = props oauth := &http.OAuthRequest{ diff --git a/src/segments/svn_test.go b/src/segments/svn_test.go index 57031173..5675735c 100644 --- a/src/segments/svn_test.go +++ b/src/segments/svn_test.go @@ -4,8 +4,8 @@ import ( "testing" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/stretchr/testify/assert" ) @@ -26,7 +26,7 @@ func TestSvnEnabledToolNotFound(t *testing.T) { } func TestSvnEnabledInWorkingDirectory(t *testing.T) { - fileInfo := &platform.FileInfo{ + fileInfo := &runtime.FileInfo{ Path: "/dir/hello", ParentFolder: "/dir", IsDir: true, @@ -225,7 +225,7 @@ R Moved.File`, }, } for _, tc := range cases { - fileInfo := &platform.FileInfo{ + fileInfo := &runtime.FileInfo{ Path: "/dir/hello", ParentFolder: "/dir", IsDir: true, diff --git a/src/segments/swift.go b/src/segments/swift.go index 169b54a3..4b24f187 100644 --- a/src/segments/swift.go +++ b/src/segments/swift.go @@ -1,8 +1,8 @@ package segments import ( - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Swift struct { @@ -13,7 +13,7 @@ func (s *Swift) Template() string { return languageTemplate } -func (s *Swift) Init(props properties.Properties, env platform.Environment) { +func (s *Swift) Init(props properties.Properties, env runtime.Environment) { s.language = language{ env: env, props: props, diff --git a/src/segments/sysinfo.go b/src/segments/sysinfo.go index b9c6eec4..de033be7 100644 --- a/src/segments/sysinfo.go +++ b/src/segments/sysinfo.go @@ -1,17 +1,17 @@ package segments import ( - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type SystemInfo struct { props properties.Properties - env platform.Environment + env runtime.Environment Precision int - platform.SystemInfo + runtime.SystemInfo } const ( @@ -30,7 +30,7 @@ func (s *SystemInfo) Enabled() bool { return true } -func (s *SystemInfo) Init(props properties.Properties, env platform.Environment) { +func (s *SystemInfo) Init(props properties.Properties, env runtime.Environment) { s.props = props s.env = env s.Precision = s.props.GetInt(Precision, 2) diff --git a/src/segments/sysinfo_test.go b/src/segments/sysinfo_test.go index 486a48d6..bea75109 100644 --- a/src/segments/sysinfo_test.go +++ b/src/segments/sysinfo_test.go @@ -5,8 +5,8 @@ import ( "testing" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/stretchr/testify/assert" ) @@ -16,7 +16,7 @@ func TestSysInfo(t *testing.T) { Case string ExpectedString string ExpectDisabled bool - SysInfo platform.SystemInfo + SysInfo runtime.SystemInfo Precision int Template string Error error @@ -29,8 +29,8 @@ func TestSysInfo(t *testing.T) { { Case: "physical mem", ExpectedString: "50", - SysInfo: platform.SystemInfo{ - Memory: platform.Memory{ + SysInfo: runtime.SystemInfo{ + Memory: runtime.Memory{ PhysicalPercentUsed: 50, }, }, @@ -39,8 +39,8 @@ func TestSysInfo(t *testing.T) { { Case: "physical mem 2 digits", ExpectedString: "60.51", - SysInfo: platform.SystemInfo{ - Memory: platform.Memory{ + SysInfo: runtime.SystemInfo{ + Memory: runtime.Memory{ PhysicalPercentUsed: 60.51, }, }, @@ -50,8 +50,8 @@ func TestSysInfo(t *testing.T) { { Case: "physical meme rounded", ExpectedString: "61", - SysInfo: platform.SystemInfo{ - Memory: platform.Memory{ + SysInfo: runtime.SystemInfo{ + Memory: runtime.Memory{ PhysicalPercentUsed: 61, }, }, @@ -62,13 +62,13 @@ func TestSysInfo(t *testing.T) { ExpectedString: "0.22 0.12 0", Precision: 2, Template: "{{ round .Load1 .Precision }} {{round .Load5 .Precision }} {{round .Load15 .Precision }}", - SysInfo: platform.SystemInfo{Load1: 0.22, Load5: 0.12, Load15: 0}, + SysInfo: runtime.SystemInfo{Load1: 0.22, Load5: 0.12, Load15: 0}, }, { Case: "not enabled", ExpectDisabled: true, - SysInfo: platform.SystemInfo{ - Memory: platform.Memory{ + SysInfo: runtime.SystemInfo{ + Memory: runtime.Memory{ PhysicalPercentUsed: 0, SwapPercentUsed: 0, }, diff --git a/src/segments/talosctl.go b/src/segments/talosctl.go index fe6d9fc5..65b2ea7b 100644 --- a/src/segments/talosctl.go +++ b/src/segments/talosctl.go @@ -4,14 +4,14 @@ import ( "errors" "path/filepath" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "gopkg.in/yaml.v3" ) type TalosCTL struct { props properties.Properties - env platform.Environment + env runtime.Environment Context string `yaml:"context"` } @@ -20,7 +20,7 @@ func (t *TalosCTL) Template() string { return " {{ .Context}} " } -func (t *TalosCTL) Init(props properties.Properties, env platform.Environment) { +func (t *TalosCTL) Init(props properties.Properties, env runtime.Environment) { t.props = props t.env = env } diff --git a/src/segments/terraform.go b/src/segments/terraform.go index 6c1671a7..ce9f8cfe 100644 --- a/src/segments/terraform.go +++ b/src/segments/terraform.go @@ -5,8 +5,8 @@ import ( "errors" "path/filepath" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/hashicorp/hcl/v2/gohcl" "github.com/hashicorp/hcl/v2/hclparse" @@ -14,7 +14,7 @@ import ( type Terraform struct { props properties.Properties - env platform.Environment + env runtime.Environment WorkspaceName string TerraformBlock @@ -24,7 +24,7 @@ func (tf *Terraform) Template() string { return " {{ .WorkspaceName }}{{ if .Version }} {{ .Version }}{{ end }} " } -func (tf *Terraform) Init(props properties.Properties, env platform.Environment) { +func (tf *Terraform) Init(props properties.Properties, env runtime.Environment) { tf.props = props tf.env = env } diff --git a/src/segments/text.go b/src/segments/text.go index e376edee..ca27268e 100644 --- a/src/segments/text.go +++ b/src/segments/text.go @@ -1,13 +1,13 @@ package segments import ( - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Text struct { props properties.Properties - env platform.Environment + env runtime.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 platform.Environment) { +func (t *Text) Init(props properties.Properties, env runtime.Environment) { t.props = props t.env = env } diff --git a/src/segments/text_test.go b/src/segments/text_test.go index a3989ac4..d926cbd6 100644 --- a/src/segments/text_test.go +++ b/src/segments/text_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/stretchr/testify/assert" ) @@ -28,7 +28,7 @@ func TestTextSegment(t *testing.T) { for _, tc := range cases { env := new(mock.MockedEnvironment) env.On("PathSeparator").Return("/") - env.On("TemplateCache").Return(&platform.TemplateCache{ + env.On("TemplateCache").Return(&runtime.TemplateCache{ UserName: "Posh", Env: map[string]string{ "HELLO": "hello", diff --git a/src/segments/time.go b/src/segments/time.go index 33cb658e..452c1ad0 100644 --- a/src/segments/time.go +++ b/src/segments/time.go @@ -3,13 +3,13 @@ package segments import ( "time" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Time struct { props properties.Properties - env platform.Environment + env runtime.Environment CurrentDate time.Time Format string @@ -33,7 +33,7 @@ func (t *Time) Enabled() bool { return true } -func (t *Time) Init(props properties.Properties, env platform.Environment) { +func (t *Time) Init(props properties.Properties, env runtime.Environment) { t.props = props t.env = env } diff --git a/src/segments/ui5tooling.go b/src/segments/ui5tooling.go index bee17645..c8ab2b49 100644 --- a/src/segments/ui5tooling.go +++ b/src/segments/ui5tooling.go @@ -1,8 +1,8 @@ package segments import ( - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) const UI5ToolingYamlPattern = "*ui5*.y*ml" @@ -16,7 +16,7 @@ func (u *UI5Tooling) Template() string { return languageTemplate } -func (u *UI5Tooling) Init(props properties.Properties, env platform.Environment) { +func (u *UI5Tooling) Init(props properties.Properties, env runtime.Environment) { u.language = language{ env: env, props: props, diff --git a/src/segments/umbraco.go b/src/segments/umbraco.go index 42c592ca..ea9b5869 100644 --- a/src/segments/umbraco.go +++ b/src/segments/umbraco.go @@ -5,13 +5,13 @@ import ( "path/filepath" "strings" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Umbraco struct { props properties.Properties - env platform.Environment + env runtime.Environment Modern bool Version string @@ -86,7 +86,7 @@ func (u *Umbraco) Template() string { return "{{.Version}} " } -func (u *Umbraco) Init(props properties.Properties, env platform.Environment) { +func (u *Umbraco) Init(props properties.Properties, env runtime.Environment) { u.props = props u.env = env } diff --git a/src/segments/umbraco_test.go b/src/segments/umbraco_test.go index edc8b2c2..0030617a 100644 --- a/src/segments/umbraco_test.go +++ b/src/segments/umbraco_test.go @@ -8,7 +8,7 @@ import ( "testing" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/stretchr/testify/assert" mock2 "github.com/stretchr/testify/mock" @@ -139,7 +139,7 @@ func TestUmbracoSegment(t *testing.T) { env.On("Debug", mock2.Anything) if tc.HasUmbracoFolder { - fileInfo := &platform.FileInfo{ + fileInfo := &runtime.FileInfo{ Path: "/workspace/MyProject/Umbraco", ParentFolder: "/workspace/MyProject", IsDir: true, @@ -147,8 +147,8 @@ func TestUmbracoSegment(t *testing.T) { env.On("HasParentFilePath", "umbraco").Return(fileInfo, nil) } else { - env.On("HasParentFilePath", "Umbraco").Return(&platform.FileInfo{}, errors.New("no such file or directory")) - env.On("HasParentFilePath", "umbraco").Return(&platform.FileInfo{}, errors.New("no such file or directory")) + env.On("HasParentFilePath", "Umbraco").Return(&runtime.FileInfo{}, errors.New("no such file or directory")) + env.On("HasParentFilePath", "umbraco").Return(&runtime.FileInfo{}, errors.New("no such file or directory")) } dirEntries := []fs.DirEntry{} diff --git a/src/segments/unity.go b/src/segments/unity.go index 903804f9..4d64d205 100644 --- a/src/segments/unity.go +++ b/src/segments/unity.go @@ -6,14 +6,14 @@ import ( "path/filepath" "strings" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" "github.com/jandedobbeleer/oh-my-posh/src/regex" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Unity struct { props properties.Properties - env platform.Environment + env runtime.Environment UnityVersion string CSharpVersion string @@ -147,7 +147,7 @@ func (u *Unity) Template() string { return " \ue721 {{ .UnityVersion }}{{ if .CSharpVersion }} {{ .CSharpVersion }}{{ end }} " } -func (u *Unity) Init(props properties.Properties, env platform.Environment) { +func (u *Unity) Init(props properties.Properties, env runtime.Environment) { u.props = props u.env = env } diff --git a/src/segments/unity_test.go b/src/segments/unity_test.go index e0ef38ff..a3bd8f33 100644 --- a/src/segments/unity_test.go +++ b/src/segments/unity_test.go @@ -9,8 +9,8 @@ import ( mock2 "github.com/stretchr/testify/mock" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/stretchr/testify/assert" ) @@ -85,10 +85,10 @@ func TestUnitySegment(t *testing.T) { env.On("Debug", mock2.Anything) err := errors.New("no match at root level") - var projectDir *platform.FileInfo + var projectDir *runtime.FileInfo if tc.VersionFileExists { err = nil - projectDir = &platform.FileInfo{ + projectDir = &runtime.FileInfo{ ParentFolder: "UnityProjectRoot", Path: "UnityProjectRoot/ProjectSettings", IsDir: true, @@ -220,10 +220,10 @@ func TestUnitySegmentCSharpWebRequest(t *testing.T) { env.On("Debug", mock2.Anything) err := errors.New("no match at root level") - var projectDir *platform.FileInfo + var projectDir *runtime.FileInfo if tc.VersionFileExists { err = nil - projectDir = &platform.FileInfo{ + projectDir = &runtime.FileInfo{ ParentFolder: "UnityProjectRoot", Path: "UnityProjectRoot/ProjectSettings", IsDir: true, diff --git a/src/segments/upgrade.go b/src/segments/upgrade.go index 58896dbd..28c821c2 100644 --- a/src/segments/upgrade.go +++ b/src/segments/upgrade.go @@ -5,8 +5,8 @@ import ( "errors" "github.com/jandedobbeleer/oh-my-posh/src/build" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/jandedobbeleer/oh-my-posh/src/upgrade" ) @@ -17,7 +17,7 @@ type UpgradeCache struct { type Upgrade struct { props properties.Properties - env platform.Environment + env runtime.Environment // deprecated Version string @@ -31,7 +31,7 @@ func (u *Upgrade) Template() string { return " \uf019 " } -func (u *Upgrade) Init(props properties.Properties, env platform.Environment) { +func (u *Upgrade) Init(props properties.Properties, env runtime.Environment) { u.props = props u.env = env } diff --git a/src/segments/vala.go b/src/segments/vala.go index 40517967..f5c651f0 100644 --- a/src/segments/vala.go +++ b/src/segments/vala.go @@ -1,8 +1,8 @@ package segments import ( - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Vala struct { @@ -13,7 +13,7 @@ func (v *Vala) Template() string { return languageTemplate } -func (v *Vala) Init(props properties.Properties, env platform.Environment) { +func (v *Vala) Init(props properties.Properties, env runtime.Environment) { v.language = language{ env: env, props: props, diff --git a/src/segments/wakatime.go b/src/segments/wakatime.go index ee509ff4..b39ecb4d 100644 --- a/src/segments/wakatime.go +++ b/src/segments/wakatime.go @@ -3,14 +3,14 @@ package segments import ( "encoding/json" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/jandedobbeleer/oh-my-posh/src/template" ) type Wakatime struct { props properties.Properties - env platform.Environment + env runtime.Environment wtData } @@ -79,7 +79,7 @@ func (w *Wakatime) getURL() (string, error) { return tmpl.Render() } -func (w *Wakatime) Init(props properties.Properties, env platform.Environment) { +func (w *Wakatime) Init(props properties.Properties, env runtime.Environment) { w.props = props w.env = env } diff --git a/src/segments/wakatime_test.go b/src/segments/wakatime_test.go index 31e29e3c..b55cb9cf 100644 --- a/src/segments/wakatime_test.go +++ b/src/segments/wakatime_test.go @@ -6,8 +6,8 @@ import ( "testing" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/stretchr/testify/assert" mock2 "github.com/stretchr/testify/mock" @@ -83,7 +83,7 @@ func TestWTTrackedTime(t *testing.T) { env.On("Cache").Return(cache) env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil) - env.On("TemplateCache").Return(&platform.TemplateCache{ + env.On("TemplateCache").Return(&runtime.TemplateCache{ Env: map[string]string{"HELLO": "hello"}, }) @@ -129,7 +129,7 @@ func TestWTGetUrl(t *testing.T) { env.On("Error", mock2.Anything) env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil) - env.On("TemplateCache").Return(&platform.TemplateCache{ + env.On("TemplateCache").Return(&runtime.TemplateCache{ Env: map[string]string{"HELLO": "hello"}, }) diff --git a/src/segments/winreg.go b/src/segments/winreg.go index 92af05f7..7bb5548e 100644 --- a/src/segments/winreg.go +++ b/src/segments/winreg.go @@ -1,13 +1,13 @@ package segments import ( - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type WindowsRegistry struct { props properties.Properties - env platform.Environment + env runtime.Environment Value string } @@ -23,13 +23,13 @@ func (wr *WindowsRegistry) Template() string { return " {{ .Value }} " } -func (wr *WindowsRegistry) Init(props properties.Properties, env platform.Environment) { +func (wr *WindowsRegistry) Init(props properties.Properties, env runtime.Environment) { wr.props = props wr.env = env } func (wr *WindowsRegistry) Enabled() bool { - if wr.env.GOOS() != platform.WINDOWS { + if wr.env.GOOS() != runtime.WINDOWS { return false } diff --git a/src/segments/winreg_test.go b/src/segments/winreg_test.go index 16da0868..67e3c285 100644 --- a/src/segments/winreg_test.go +++ b/src/segments/winreg_test.go @@ -5,8 +5,8 @@ import ( "testing" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/stretchr/testify/assert" ) @@ -18,7 +18,7 @@ func TestWinReg(t *testing.T) { Fallback string ExpectedSuccess bool ExpectedValue string - getWRKVOutput *platform.WindowsRegistryValue + getWRKVOutput *runtime.WindowsRegistryValue Err error }{ { @@ -30,7 +30,7 @@ func TestWinReg(t *testing.T) { { CaseDescription: "Value", Path: "HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\InstallTime", - getWRKVOutput: &platform.WindowsRegistryValue{ValueType: platform.STRING, String: "xbox"}, + getWRKVOutput: &runtime.WindowsRegistryValue{ValueType: runtime.STRING, String: "xbox"}, ExpectedSuccess: true, ExpectedValue: "xbox", }, @@ -45,7 +45,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: &platform.WindowsRegistryValue{ValueType: platform.STRING, String: ""}, + getWRKVOutput: &runtime.WindowsRegistryValue{ValueType: runtime.STRING, String: ""}, Fallback: "anaconda", ExpectedSuccess: true, ExpectedValue: "", @@ -53,7 +53,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: &platform.WindowsRegistryValue{ValueType: platform.STRING, String: ""}, + getWRKVOutput: &runtime.WindowsRegistryValue{ValueType: runtime.STRING, String: ""}, ExpectedSuccess: true, ExpectedValue: "", }, @@ -61,7 +61,7 @@ func TestWinReg(t *testing.T) { for _, tc := range cases { env := new(mock.MockedEnvironment) - env.On("GOOS").Return(platform.WINDOWS) + env.On("GOOS").Return(runtime.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 50265c0b..2e85766d 100644 --- a/src/segments/withings.go +++ b/src/segments/withings.go @@ -9,8 +9,8 @@ import ( "time" "github.com/jandedobbeleer/oh-my-posh/src/http" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" http2 "net/http" "net/url" @@ -217,7 +217,7 @@ func (w *Withings) getSleep() bool { return true } -func (w *Withings) Init(props properties.Properties, env platform.Environment) { +func (w *Withings) Init(props properties.Properties, env runtime.Environment) { w.props = props oauth := &http.OAuthRequest{ diff --git a/src/segments/xmake.go b/src/segments/xmake.go index 12c22e3c..9082f190 100644 --- a/src/segments/xmake.go +++ b/src/segments/xmake.go @@ -1,8 +1,8 @@ package segments import ( - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type XMake struct { @@ -13,7 +13,7 @@ func (x *XMake) Template() string { return languageTemplate } -func (x *XMake) Init(props properties.Properties, env platform.Environment) { +func (x *XMake) Init(props properties.Properties, env runtime.Environment) { x.language = language{ env: env, props: props, diff --git a/src/segments/yarn.go b/src/segments/yarn.go index e78dd273..7cfbdc87 100644 --- a/src/segments/yarn.go +++ b/src/segments/yarn.go @@ -1,8 +1,8 @@ package segments import ( - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Yarn struct { @@ -17,7 +17,7 @@ func (n *Yarn) Template() string { return " \U000F011B {{.Full}} " } -func (n *Yarn) Init(props properties.Properties, env platform.Environment) { +func (n *Yarn) Init(props properties.Properties, env runtime.Environment) { n.language = language{ env: env, props: props, diff --git a/src/segments/ytm.go b/src/segments/ytm.go index 9a7a8200..d96b48d3 100644 --- a/src/segments/ytm.go +++ b/src/segments/ytm.go @@ -3,13 +3,13 @@ package segments import ( "encoding/json" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Ytm struct { props properties.Properties - env platform.Environment + env runtime.Environment MusicPlayer } @@ -30,7 +30,7 @@ func (y *Ytm) Enabled() bool { return err == nil } -func (y *Ytm) Init(props properties.Properties, env platform.Environment) { +func (y *Ytm) Init(props properties.Properties, env runtime.Environment) { y.props = props y.env = env } diff --git a/src/shell/init.go b/src/shell/init.go index 19605215..e3f96154 100644 --- a/src/shell/init.go +++ b/src/shell/init.go @@ -10,7 +10,7 @@ import ( "strings" "github.com/jandedobbeleer/oh-my-posh/src/color" - "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/jandedobbeleer/oh-my-posh/src/template" "github.com/jandedobbeleer/oh-my-posh/src/upgrade" ) @@ -57,18 +57,18 @@ var ( AutoUpgrade bool ) -func getExecutablePath(env platform.Environment) (string, error) { +func getExecutablePath(env runtime.Environment) (string, error) { executable, err := os.Executable() if err != nil { return "", err } if env.Flags().Strict { - return platform.Base(env, executable), nil + return runtime.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() == platform.WINDOWS { + if env.GOOS() == runtime.WINDOWS { executable = strings.ReplaceAll(executable, "\\", "/") } return executable, nil @@ -164,7 +164,7 @@ func quoteNuStr(str string) string { return fmt.Sprintf(`"%s"`, strings.NewReplacer(`\`, `\\`, `"`, `\"`).Replace(str)) } -func Init(env platform.Environment) string { +func Init(env runtime.Environment) string { shell := env.Flags().Shell switch shell { case PWSH, PWSH5, ELVISH: @@ -200,7 +200,7 @@ func Init(env platform.Environment) string { } } -func PrintInit(env platform.Environment) string { +func PrintInit(env runtime.Environment) string { executable, err := getExecutablePath(env) if err != nil { return noExe @@ -290,7 +290,7 @@ func PrintInit(env platform.Environment) string { ).Replace(script) } -func createNuInit(env platform.Environment) { +func createNuInit(env runtime.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 { @@ -303,7 +303,7 @@ func createNuInit(env platform.Environment) { _ = f.Close() } -func ConsoleBackgroundColor(env platform.Environment, backgroundColorTemplate color.Ansi) color.Ansi { +func ConsoleBackgroundColor(env runtime.Environment, backgroundColorTemplate color.Ansi) color.Ansi { if backgroundColorTemplate.IsEmpty() { return backgroundColorTemplate } diff --git a/src/shell/init_test.go b/src/shell/init_test.go index 9e049606..b8a3c235 100644 --- a/src/shell/init_test.go +++ b/src/shell/init_test.go @@ -6,7 +6,7 @@ import ( "github.com/jandedobbeleer/oh-my-posh/src/color" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/stretchr/testify/assert" mock2 "github.com/stretchr/testify/mock" @@ -25,7 +25,7 @@ func TestConsoleBackgroundColorTemplate(t *testing.T) { for _, tc := range cases { env := new(mock.MockedEnvironment) env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil) - env.On("TemplateCache").Return(&platform.TemplateCache{ + env.On("TemplateCache").Return(&runtime.TemplateCache{ Env: map[string]string{ "TERM_PROGRAM": tc.Term, }, diff --git a/src/template/files_test.go b/src/template/files_test.go index ac7f1f55..8d4403c4 100644 --- a/src/template/files_test.go +++ b/src/template/files_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/stretchr/testify/assert" mock2 "github.com/stretchr/testify/mock" @@ -24,7 +24,7 @@ func TestGlob(t *testing.T) { env := &mock.MockedEnvironment{} env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil) - env.On("TemplateCache").Return(&platform.TemplateCache{ + env.On("TemplateCache").Return(&runtime.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 8e7807cc..c9ae095d 100644 --- a/src/template/link_test.go +++ b/src/template/link_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/stretchr/testify/assert" mock2 "github.com/stretchr/testify/mock" @@ -22,7 +22,7 @@ func TestUrl(t *testing.T) { } env := &mock.MockedEnvironment{} - env.On("TemplateCache").Return(&platform.TemplateCache{ + env.On("TemplateCache").Return(&runtime.TemplateCache{ Env: make(map[string]string), }) env.On("Error", mock2.Anything) @@ -54,7 +54,7 @@ func TestPath(t *testing.T) { env := &mock.MockedEnvironment{} env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil) - env.On("TemplateCache").Return(&platform.TemplateCache{ + env.On("TemplateCache").Return(&runtime.TemplateCache{ Env: make(map[string]string), }) for _, tc := range cases { diff --git a/src/template/list.go b/src/template/list.go index 5b5b1eac..031d8a41 100644 --- a/src/template/list.go +++ b/src/template/list.go @@ -3,7 +3,7 @@ package template import ( "strings" - "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type Logic string @@ -19,7 +19,7 @@ func (l List) Empty() bool { return len(l) == 0 } -func (l List) Resolve(context any, env platform.Environment, defaultValue string, logic Logic) string { +func (l List) Resolve(context any, env runtime.Environment, defaultValue string, logic Logic) string { switch logic { case FirstMatch: return l.FirstMatch(context, env, defaultValue) @@ -30,7 +30,7 @@ func (l List) Resolve(context any, env platform.Environment, defaultValue string } } -func (l List) Join(context any, env platform.Environment) string { +func (l List) Join(context any, env runtime.Environment) string { if len(l) == 0 { return "" } @@ -50,7 +50,7 @@ func (l List) Join(context any, env platform.Environment) string { return buffer.String() } -func (l List) FirstMatch(context any, env platform.Environment, defaultValue string) string { +func (l List) FirstMatch(context any, env runtime.Environment, defaultValue string) string { if len(l) == 0 { return defaultValue } diff --git a/src/template/numbers_test.go b/src/template/numbers_test.go index 9d8d9c4e..386c7eb9 100644 --- a/src/template/numbers_test.go +++ b/src/template/numbers_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/stretchr/testify/assert" mock2 "github.com/stretchr/testify/mock" @@ -22,7 +22,7 @@ func TestHResult(t *testing.T) { } env := &mock.MockedEnvironment{} - env.On("TemplateCache").Return(&platform.TemplateCache{ + env.On("TemplateCache").Return(&runtime.TemplateCache{ Env: make(map[string]string), }) env.On("Error", mock2.Anything) diff --git a/src/template/round_test.go b/src/template/round_test.go index d1af9781..efc29e6f 100644 --- a/src/template/round_test.go +++ b/src/template/round_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/stretchr/testify/assert" mock2 "github.com/stretchr/testify/mock" @@ -29,7 +29,7 @@ func TestRoundSeconds(t *testing.T) { } env := &mock.MockedEnvironment{} - env.On("TemplateCache").Return(&platform.TemplateCache{ + env.On("TemplateCache").Return(&runtime.TemplateCache{ Env: make(map[string]string), }) env.On("Error", mock2.Anything) diff --git a/src/template/strings_test.go b/src/template/strings_test.go index 154853f9..0fcd885b 100644 --- a/src/template/strings_test.go +++ b/src/template/strings_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/stretchr/testify/assert" mock2 "github.com/stretchr/testify/mock" @@ -26,7 +26,7 @@ func TestTrunc(t *testing.T) { } env := &mock.MockedEnvironment{} - env.On("TemplateCache").Return(&platform.TemplateCache{ + env.On("TemplateCache").Return(&runtime.TemplateCache{ Env: make(map[string]string), }) env.On("Error", mock2.Anything) diff --git a/src/template/text.go b/src/template/text.go index 51fdaa16..b253b465 100644 --- a/src/template/text.go +++ b/src/template/text.go @@ -7,8 +7,8 @@ import ( "strings" "text/template" - "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/regex" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) const ( @@ -45,14 +45,14 @@ var ( type Text struct { Template string Context any - Env platform.Environment + Env runtime.Environment TemplatesResult string } type Data any type Context struct { - *platform.TemplateCache + *runtime.TemplateCache // Simple container to hold ANY object Data diff --git a/src/template/text_test.go b/src/template/text_test.go index 928aa5a4..00b4ae5d 100644 --- a/src/template/text_test.go +++ b/src/template/text_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/stretchr/testify/assert" mock2 "github.com/stretchr/testify/mock" @@ -156,7 +156,7 @@ func TestRenderTemplate(t *testing.T) { } env := &mock.MockedEnvironment{} - env.On("TemplateCache").Return(&platform.TemplateCache{ + env.On("TemplateCache").Return(&runtime.TemplateCache{ Env: make(map[string]string), }) env.On("Error", mock2.Anything) @@ -241,7 +241,7 @@ func TestRenderTemplateEnvVar(t *testing.T) { } for _, tc := range cases { env := &mock.MockedEnvironment{} - env.On("TemplateCache").Return(&platform.TemplateCache{ + env.On("TemplateCache").Return(&runtime.TemplateCache{ Env: tc.Env, OS: "darwin", }) @@ -354,10 +354,10 @@ func TestSegmentContains(t *testing.T) { } env := &mock.MockedEnvironment{} - segments := platform.NewConcurrentMap() + segments := runtime.NewConcurrentMap() segments.Set("Git", "foo") env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil) - env.On("TemplateCache").Return(&platform.TemplateCache{ + env.On("TemplateCache").Return(&runtime.TemplateCache{ Env: make(map[string]string), Segments: segments, }) diff --git a/src/upgrade/cli.go b/src/upgrade/cli.go index 93cef002..7723fdae 100644 --- a/src/upgrade/cli.go +++ b/src/upgrade/cli.go @@ -8,7 +8,7 @@ import ( tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" "github.com/jandedobbeleer/oh-my-posh/src/build" - "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) var ( @@ -108,7 +108,7 @@ func (m *model) View() string { return title + textStyle.Render(fmt.Sprintf("%s %s", m.spinner.View(), message)) } -func Run(env platform.Environment) { +func Run(env runtime.Environment) { titleStyle := lipgloss.NewStyle().Margin(1, 0, 1, 0) title = "📦 Upgrading Oh My Posh" diff --git a/src/upgrade/install.go b/src/upgrade/install.go index f13bccf6..d0372d7f 100644 --- a/src/upgrade/install.go +++ b/src/upgrade/install.go @@ -8,10 +8,10 @@ import ( "net/http" "os" "path/filepath" - "runtime" + stdruntime "runtime" - "github.com/jandedobbeleer/oh-my-posh/src/platform" - "github.com/jandedobbeleer/oh-my-posh/src/platform/net" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" + "github.com/jandedobbeleer/oh-my-posh/src/runtime/net" ) func install() error { @@ -23,11 +23,11 @@ func install() error { } extension := "" - if runtime.GOOS == platform.WINDOWS { + if stdruntime.GOOS == runtime.WINDOWS { extension = ".exe" } - asset := fmt.Sprintf("posh-%s-%s%s", runtime.GOOS, runtime.GOARCH, extension) + asset := fmt.Sprintf("posh-%s-%s%s", stdruntime.GOOS, stdruntime.GOARCH, extension) setState(downloading) diff --git a/src/upgrade/notice.go b/src/upgrade/notice.go index bd19f1bf..9932e894 100644 --- a/src/upgrade/notice.go +++ b/src/upgrade/notice.go @@ -6,7 +6,7 @@ import ( "time" "github.com/jandedobbeleer/oh-my-posh/src/build" - "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" ) type release struct { @@ -41,7 +41,7 @@ To enable automated upgrades, set 'auto_upgrade' to 'true' in your configuration ` ) -func Latest(env platform.Environment) (string, error) { +func Latest(env runtime.Environment) (string, error) { body, err := env.HTTPRequest(RELEASEURL, nil, 1000) if err != nil { return "", err @@ -56,7 +56,7 @@ func Latest(env platform.Environment) (string, error) { // that should be displayed to the user. // // The upgrade check is only performed every other week. -func Notice(env platform.Environment, force bool) (string, bool) { +func Notice(env runtime.Environment, force bool) (string, bool) { // do not check when last validation was < 1 week ago if _, OK := env.Cache().Get(CACHEKEY); OK && !force { return "", false diff --git a/src/upgrade/notice_test.go b/src/upgrade/notice_test.go index 34bf0035..c97ba11d 100644 --- a/src/upgrade/notice_test.go +++ b/src/upgrade/notice_test.go @@ -6,7 +6,7 @@ import ( "github.com/jandedobbeleer/oh-my-posh/src/build" "github.com/jandedobbeleer/oh-my-posh/src/mock" - "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/stretchr/testify/assert" mock2 "github.com/stretchr/testify/mock" @@ -24,9 +24,9 @@ func TestCanUpgrade(t *testing.T) { Installer string }{ {Case: "Up to date", CurrentVersion: "3.0.0", LatestVersion: "v3.0.0"}, - {Case: "Outdated Windows", Expected: true, CurrentVersion: "3.0.0", LatestVersion: "v3.0.1", GOOS: platform.WINDOWS}, - {Case: "Outdated Linux", Expected: true, CurrentVersion: "3.0.0", LatestVersion: "v3.0.1", GOOS: platform.LINUX}, - {Case: "Outdated Darwin", Expected: true, CurrentVersion: "3.0.0", LatestVersion: "v3.0.1", GOOS: platform.DARWIN}, + {Case: "Outdated Windows", Expected: true, CurrentVersion: "3.0.0", LatestVersion: "v3.0.1", GOOS: runtime.WINDOWS}, + {Case: "Outdated Linux", Expected: true, CurrentVersion: "3.0.0", LatestVersion: "v3.0.1", GOOS: runtime.LINUX}, + {Case: "Outdated Darwin", Expected: true, CurrentVersion: "3.0.0", LatestVersion: "v3.0.1", GOOS: runtime.DARWIN}, {Case: "Cached", Cache: true}, {Case: "Error", Error: fmt.Errorf("error")}, {Case: "Windows Store", Installer: "ws"},