refactor(platform): rename to runtime

This commit is contained in:
Jan De Dobbeleer 2024-07-02 12:02:57 +02:00 committed by Jan De Dobbeleer
parent bab346fcc5
commit 05251e1ac3
207 changed files with 1186 additions and 1185 deletions

View file

@ -7,7 +7,7 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/runtime"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -34,8 +34,8 @@ You can do the following:
_ = cmd.Help() _ = cmd.Help()
return return
} }
env := &platform.Shell{ env := &runtime.Terminal{
CmdFlags: &platform.Flags{}, CmdFlags: &runtime.Flags{},
} }
env.Init() env.Init()
defer env.Close() defer env.Close()
@ -43,7 +43,7 @@ You can do the following:
case "path": case "path":
fmt.Print(env.CachePath()) fmt.Print(env.CachePath())
case "clear": case "clear":
cacheFilePath := filepath.Join(env.CachePath(), platform.CacheFile) cacheFilePath := filepath.Join(env.CachePath(), runtime.CacheFile)
err := os.Remove(cacheFilePath) err := os.Remove(cacheFilePath)
if err != nil { if err != nil {
fmt.Println(err.Error()) fmt.Println(err.Error())
@ -51,7 +51,7 @@ You can do the following:
} }
fmt.Printf("removed cache file at %s\n", cacheFilePath) fmt.Printf("removed cache file at %s\n", cacheFilePath)
case "edit": case "edit":
cacheFilePath := filepath.Join(env.CachePath(), platform.CacheFile) cacheFilePath := filepath.Join(env.CachePath(), runtime.CacheFile)
editFileWithEditor(cacheFilePath) editFileWithEditor(cacheFilePath)
} }
}, },

View file

@ -8,7 +8,7 @@ import (
"strings" "strings"
"github.com/jandedobbeleer/oh-my-posh/src/config" "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" "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.`, Exports the ~/myconfig.omp.json config file to toml and prints the result to stdout.`,
Args: cobra.NoArgs, Args: cobra.NoArgs,
Run: func(_ *cobra.Command, _ []string) { Run: func(_ *cobra.Command, _ []string) {
env := &platform.Shell{ env := &runtime.Terminal{
CmdFlags: &platform.Flags{ CmdFlags: &runtime.Flags{
Config: configFlag, 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, "~") { if strings.HasPrefix(path, "~") {
path = strings.TrimPrefix(path, "~") path = strings.TrimPrefix(path, "~")
path = filepath.Join(env.Home(), path) path = filepath.Join(env.Home(), path)

View file

@ -5,8 +5,8 @@ import (
"github.com/jandedobbeleer/oh-my-posh/src/config" "github.com/jandedobbeleer/oh-my-posh/src/config"
"github.com/jandedobbeleer/oh-my-posh/src/image" "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/prompt"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
"github.com/jandedobbeleer/oh-my-posh/src/shell" "github.com/jandedobbeleer/oh-my-posh/src/shell"
"github.com/jandedobbeleer/oh-my-posh/src/terminal" "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.`, Exports the config to an image file using customized output options.`,
Args: cobra.NoArgs, Args: cobra.NoArgs,
Run: func(_ *cobra.Command, _ []string) { Run: func(_ *cobra.Command, _ []string) {
env := &platform.Shell{ env := &runtime.Terminal{
CmdFlags: &platform.Flags{ CmdFlags: &runtime.Flags{
Config: configFlag, Config: configFlag,
Shell: shell.GENERIC, Shell: shell.GENERIC,
TerminalWidth: 150, TerminalWidth: 150,

View file

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"github.com/jandedobbeleer/oh-my-posh/src/config" "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" "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.`, A backup of the current config can be found at ~/myconfig.omp.json.bak.`,
Args: cobra.NoArgs, Args: cobra.NoArgs,
Run: func(_ *cobra.Command, _ []string) { Run: func(_ *cobra.Command, _ []string) {
env := &platform.Shell{ env := &runtime.Terminal{
CmdFlags: &platform.Flags{ CmdFlags: &runtime.Flags{
Config: configFlag, Config: configFlag,
Migrate: true, Migrate: true,
}, },

View file

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"github.com/jandedobbeleer/oh-my-posh/src/config" "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" "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.`, A backup of the current config can be found at ~/myconfig.omp.json.bak.`,
Args: cobra.NoArgs, Args: cobra.NoArgs,
Run: func(_ *cobra.Command, _ []string) { Run: func(_ *cobra.Command, _ []string) {
env := &platform.Shell{ env := &runtime.Terminal{
CmdFlags: &platform.Flags{ CmdFlags: &runtime.Flags{
Config: configFlag, Config: configFlag,
}, },
} }

View file

@ -6,8 +6,8 @@ import (
"github.com/jandedobbeleer/oh-my-posh/src/build" "github.com/jandedobbeleer/oh-my-posh/src/build"
"github.com/jandedobbeleer/oh-my-posh/src/config" "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/prompt"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
"github.com/jandedobbeleer/oh-my-posh/src/shell" "github.com/jandedobbeleer/oh-my-posh/src/shell"
"github.com/jandedobbeleer/oh-my-posh/src/terminal" "github.com/jandedobbeleer/oh-my-posh/src/terminal"
@ -23,8 +23,8 @@ var debugCmd = &cobra.Command{
Run: func(_ *cobra.Command, _ []string) { Run: func(_ *cobra.Command, _ []string) {
startTime := time.Now() startTime := time.Now()
env := &platform.Shell{ env := &runtime.Terminal{
CmdFlags: &platform.Flags{ CmdFlags: &runtime.Flags{
Config: configFlag, Config: configFlag,
Debug: true, Debug: true,
PWD: pwd, PWD: pwd,

View file

@ -3,7 +3,7 @@ package cli
import ( import (
"fmt" "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/jandedobbeleer/oh-my-posh/src/upgrade"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -42,8 +42,8 @@ func init() {
} }
func toggleFeature(cmd *cobra.Command, feature string, enable bool) { func toggleFeature(cmd *cobra.Command, feature string, enable bool) {
env := &platform.Shell{ env := &runtime.Terminal{
CmdFlags: &platform.Flags{ CmdFlags: &runtime.Flags{
Shell: shellName, Shell: shellName,
}, },
} }

View file

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"github.com/jandedobbeleer/oh-my-posh/src/font" "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/jandedobbeleer/oh-my-posh/src/terminal"
"github.com/spf13/cobra" "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 { if len(args) > 1 {
fontName = args[1] fontName = args[1]
} }
env := &platform.Shell{} env := &runtime.Terminal{}
env.Init() env.Init()
defer env.Close() defer env.Close()

View file

@ -6,7 +6,7 @@ import (
"time" "time"
"github.com/jandedobbeleer/oh-my-posh/src/color" "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" color2 "github.com/gookit/color"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -44,8 +44,8 @@ This command is used to get the value of the following variables:
return return
} }
env := &platform.Shell{ env := &runtime.Terminal{
CmdFlags: &platform.Flags{ CmdFlags: &runtime.Flags{
Shell: shellName, Shell: shellName,
}, },
} }
@ -65,7 +65,7 @@ This command is used to get the value of the following variables:
fmt.Println("#" + accent.Hex()) fmt.Println("#" + accent.Hex())
case "toggles": case "toggles":
cache := env.Cache() cache := env.Cache()
togglesCache, _ := cache.Get(platform.TOGGLECACHE) togglesCache, _ := cache.Get(runtime.TOGGLECACHE)
var toggles []string var toggles []string
if len(togglesCache) != 0 { if len(togglesCache) != 0 {
toggles = strings.Split(togglesCache, ",") toggles = strings.Split(togglesCache, ",")

View file

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"github.com/jandedobbeleer/oh-my-posh/src/config" "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/shell"
"github.com/jandedobbeleer/oh-my-posh/src/terminal" "github.com/jandedobbeleer/oh-my-posh/src/terminal"
"github.com/jandedobbeleer/oh-my-posh/src/upgrade" "github.com/jandedobbeleer/oh-my-posh/src/upgrade"
@ -55,8 +55,8 @@ func init() {
} }
func runInit(shellName string) { func runInit(shellName string) {
env := &platform.Shell{ env := &runtime.Terminal{
CmdFlags: &platform.Flags{ CmdFlags: &runtime.Flags{
Shell: shellName, Shell: shellName,
Config: configFlag, Config: configFlag,
Strict: strict, Strict: strict,

View file

@ -3,7 +3,7 @@ package cli
import ( import (
"fmt" "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/jandedobbeleer/oh-my-posh/src/upgrade"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -15,8 +15,8 @@ var noticeCmd = &cobra.Command{
Long: "Print the upgrade notice when a new version is available.", Long: "Print the upgrade notice when a new version is available.",
Args: cobra.NoArgs, Args: cobra.NoArgs,
Run: func(_ *cobra.Command, _ []string) { Run: func(_ *cobra.Command, _ []string) {
env := &platform.Shell{ env := &runtime.Terminal{
CmdFlags: &platform.Flags{}, CmdFlags: &runtime.Flags{},
} }
env.Init() env.Init()
defer env.Close() defer env.Close()

View file

@ -3,8 +3,8 @@ package cli
import ( import (
"fmt" "fmt"
"github.com/jandedobbeleer/oh-my-posh/src/platform"
"github.com/jandedobbeleer/oh-my-posh/src/prompt" "github.com/jandedobbeleer/oh-my-posh/src/prompt"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -49,7 +49,7 @@ var printCmd = &cobra.Command{
return return
} }
flags := &platform.Flags{ flags := &runtime.Flags{
Config: configFlag, Config: configFlag,
PWD: pwd, PWD: pwd,
PSWD: pswd, PSWD: pswd,

View file

@ -3,8 +3,7 @@ package cli
import ( import (
"strings" "strings"
"github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/runtime"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -19,12 +18,12 @@ var toggleCmd = &cobra.Command{
_ = cmd.Help() _ = cmd.Help()
return return
} }
env := &platform.Shell{} env := &runtime.Terminal{}
env.Init() env.Init()
defer env.Close() defer env.Close()
cache := env.Cache() cache := env.Cache()
togglesCache, _ := cache.Get(platform.TOGGLECACHE) togglesCache, _ := cache.Get(runtime.TOGGLECACHE)
var toggles []string var toggles []string
if len(togglesCache) != 0 { if len(togglesCache) != 0 {
toggles = strings.Split(togglesCache, ",") toggles = strings.Split(togglesCache, ",")
@ -45,7 +44,7 @@ var toggleCmd = &cobra.Command{
newToggles = append(newToggles, segment) newToggles = append(newToggles, segment)
} }
cache.Set(platform.TOGGLECACHE, strings.Join(newToggles, ","), 1440) cache.Set(runtime.TOGGLECACHE, strings.Join(newToggles, ","), 1440)
}, },
} }

View file

@ -2,11 +2,11 @@ package cli
import ( import (
"fmt" "fmt"
"runtime" stdruntime "runtime"
"slices" "slices"
"github.com/jandedobbeleer/oh-my-posh/src/config" "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/terminal"
"github.com/jandedobbeleer/oh-my-posh/src/upgrade" "github.com/jandedobbeleer/oh-my-posh/src/upgrade"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -22,18 +22,18 @@ var upgradeCmd = &cobra.Command{
Args: cobra.NoArgs, Args: cobra.NoArgs,
Run: func(_ *cobra.Command, _ []string) { Run: func(_ *cobra.Command, _ []string) {
supportedPlatforms := []string{ supportedPlatforms := []string{
platform.WINDOWS, runtime.WINDOWS,
platform.DARWIN, runtime.DARWIN,
platform.LINUX, 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") fmt.Print("\n⚠ upgrade is not supported on this platform\n\n")
return return
} }
env := &platform.Shell{ env := &runtime.Terminal{
CmdFlags: &platform.Flags{}, CmdFlags: &runtime.Flags{},
} }
env.Init() env.Init()
defer env.Close() defer env.Close()

View file

@ -6,7 +6,7 @@ import (
"strings" "strings"
"github.com/gookit/color" "github.com/gookit/color"
"github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/runtime"
) )
var TrueColor = true var TrueColor = true
@ -107,7 +107,7 @@ func (c Ansi) String() string {
return string(c) 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 := &Defaults{}
defaultColors.SetAccentColor(env, accentColor) defaultColors.SetAccentColor(env, accentColor)
colors = defaultColors colors = defaultColors

View file

@ -6,7 +6,7 @@ import (
"github.com/alecthomas/assert" "github.com/alecthomas/assert"
"github.com/jandedobbeleer/oh-my-posh/src/mock" "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) { func TestGetAnsiFromColorString(t *testing.T) {
@ -40,7 +40,7 @@ func TestGetAnsiFromColorString(t *testing.T) {
func TestMakeColors(t *testing.T) { func TestMakeColors(t *testing.T) {
env := &mock.MockedEnvironment{} 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) colors := MakeColors(nil, false, "", env)
assert.IsType(t, &Defaults{}, colors) assert.IsType(t, &Defaults{}, colors)

View file

@ -2,13 +2,13 @@
package color 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) { func GetAccentColor(_ runtime.Environment) (*RGB, error) {
return nil, &platform.NotImplemented{} return nil, &runtime.NotImplemented{}
} }
func (d *Defaults) SetAccentColor(_ platform.Environment, defaultColor Ansi) { func (d *Defaults) SetAccentColor(_ runtime.Environment, defaultColor Ansi) {
if len(defaultColor) == 0 { if len(defaultColor) == 0 {
return return
} }

View file

@ -3,19 +3,18 @@ package color
import ( import (
"errors" "errors"
"github.com/jandedobbeleer/oh-my-posh/src/platform"
"github.com/gookit/color" "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 { if env == nil {
return nil, errors.New("unable to get color without environment") return nil, errors.New("unable to get color without environment")
} }
// see https://stackoverflow.com/questions/3560890/vista-7-how-to-get-glass-color // 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`) 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 return nil, err
} }
@ -26,7 +25,7 @@ func GetAccentColor(env platform.Environment) (*RGB, error) {
}, nil }, nil
} }
func (d *Defaults) SetAccentColor(env platform.Environment, defaultColor Ansi) { func (d *Defaults) SetAccentColor(env runtime.Environment, defaultColor Ansi) {
rgb, err := GetAccentColor(env) rgb, err := GetAccentColor(env)
if err != nil { if err != nil {
d.accent = &Set{ d.accent = &Set{

View file

@ -3,7 +3,7 @@ package config
import ( import (
"sync" "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/shell"
"github.com/jandedobbeleer/oh-my-posh/src/terminal" "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"` MaxWidth int `json:"max_width,omitempty" toml:"max_width,omitempty"`
MinWidth int `json:"min_width,omitempty" toml:"min_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.env = env
b.executeSegmentLogic() 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.Init(shell.GENERIC)
terminal.BackgroundColor = shell.ConsoleBackgroundColor(env, config.TerminalBackground) terminal.BackgroundColor = shell.ConsoleBackgroundColor(env, config.TerminalBackground)
terminal.Colors = config.MakeColors() terminal.Colors = config.MakeColors()

View file

@ -2,7 +2,7 @@ package config
import ( import (
"github.com/jandedobbeleer/oh-my-posh/src/color" "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/template"
"github.com/jandedobbeleer/oh-my-posh/src/terminal" "github.com/jandedobbeleer/oh-my-posh/src/terminal"
) )
@ -51,7 +51,7 @@ type Config struct {
origin string origin string
// eval bool // eval bool
updated bool updated bool
env platform.Environment env runtime.Environment
} }
func (cfg *Config) MakeColors() color.String { func (cfg *Config) MakeColors() color.String {

View file

@ -5,7 +5,7 @@ import (
"github.com/jandedobbeleer/oh-my-posh/src/color" "github.com/jandedobbeleer/oh-my-posh/src/color"
"github.com/jandedobbeleer/oh-my-posh/src/mock" "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" "github.com/stretchr/testify/assert"
mock2 "github.com/stretchr/testify/mock" mock2 "github.com/stretchr/testify/mock"
@ -71,7 +71,7 @@ func TestGetPalette(t *testing.T) {
} }
for _, tc := range cases { for _, tc := range cases {
env := &mock.MockedEnvironment{} env := &mock.MockedEnvironment{}
env.On("TemplateCache").Return(&platform.TemplateCache{ env.On("TemplateCache").Return(&runtime.TemplateCache{
Env: map[string]string{}, Env: map[string]string{},
Shell: "bash", Shell: "bash",
}) })

View file

@ -2,12 +2,12 @@ package config
import ( import (
"github.com/jandedobbeleer/oh-my-posh/src/color" "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/properties"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
"github.com/jandedobbeleer/oh-my-posh/src/segments" "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 }}" exitBackgroundTemplate := "{{ if gt .Code 0 }}p:red{{ end }}"
exitTemplate := " {{ if gt .Code 0 }}\uf00d{{ else }}\uf00c{{ end }} " exitTemplate := " {{ if gt .Code 0 }}\uf00d{{ else }}\uf00c{{ end }} "
if warning { if warning {

View file

@ -3,13 +3,13 @@ package config
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"os" stdOS "os"
"path/filepath" "path/filepath"
"strings" "strings"
"time" "time"
"github.com/gookit/goutil/jsonutil" "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" "github.com/jandedobbeleer/oh-my-posh/src/shell"
json "github.com/goccy/go-json" json "github.com/goccy/go-json"
@ -18,7 +18,7 @@ import (
) )
// LoadConfig returns the default configuration including possible user overrides // LoadConfig returns the default configuration including possible user overrides
func Load(env platform.Environment) *Config { func Load(env runtime.Environment) *Config {
cfg := loadConfig(env) cfg := loadConfig(env)
// only migrate automatically when the switch isn't set // only migrate automatically when the switch isn't set
@ -47,7 +47,7 @@ func Load(env platform.Environment) *Config {
return cfg return cfg
} }
func loadConfig(env platform.Environment) *Config { func loadConfig(env runtime.Environment) *Config {
defer env.Trace(time.Now()) defer env.Trace(time.Now())
configFile := env.Flags().Config configFile := env.Flags().Config
@ -61,7 +61,7 @@ func loadConfig(env platform.Environment) *Config {
cfg.Format = strings.TrimPrefix(filepath.Ext(configFile), ".") cfg.Format = strings.TrimPrefix(filepath.Ext(configFile), ".")
cfg.env = env cfg.env = env
data, err := os.ReadFile(configFile) data, err := stdOS.ReadFile(configFile)
if err != nil { if err != nil {
env.DebugF("error reading config file: %s", err) env.DebugF("error reading config file: %s", err)
return Default(env, true) return Default(env, true)

View file

@ -4,8 +4,8 @@ import (
"fmt" "fmt"
"strings" "strings"
"github.com/jandedobbeleer/oh-my-posh/src/platform"
"github.com/jandedobbeleer/oh-my-posh/src/properties" "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/jandedobbeleer/oh-my-posh/src/segments"
) )
@ -33,7 +33,7 @@ func (cfg *Config) Migrate() {
cfg.Version = Version cfg.Version = Version
} }
func (segment *Segment) migrate(env platform.Environment, version int) { func (segment *Segment) migrate(env runtime.Environment, version int) {
if version < 1 { if version < 1 {
segment.migrationOne(env) 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 { if err := segment.MapSegmentWithWriter(env); err != nil {
return return
} }
@ -162,7 +162,7 @@ func (segment *Segment) migrationOne(env platform.Environment) {
delete(segment.Properties, colorBackground) 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 { if err := segment.MapSegmentWithWriter(env); err != nil {
return return
} }

View file

@ -9,7 +9,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/jandedobbeleer/oh-my-posh/src/platform/net" "github.com/jandedobbeleer/oh-my-posh/src/runtime/net"
) )
type ConnectionError struct { type ConnectionError struct {

View file

@ -4,8 +4,8 @@ import (
"testing" "testing"
"github.com/jandedobbeleer/oh-my-posh/src/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/properties"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
"github.com/jandedobbeleer/oh-my-posh/src/segments" "github.com/jandedobbeleer/oh-my-posh/src/segments"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -91,7 +91,7 @@ func (m *MockedWriter) Template() string {
return m.template return m.template
} }
func (m *MockedWriter) Init(_ properties.Properties, _ platform.Environment) {} func (m *MockedWriter) Init(_ properties.Properties, _ runtime.Environment) {}
func TestIconOverride(t *testing.T) { func TestIconOverride(t *testing.T) {
cases := []struct { cases := []struct {

View file

@ -1,8 +1,8 @@
package config 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 { if maxWidth == 0 && minWidth == 0 {
return false return false
} }

View file

@ -7,8 +7,8 @@ import (
"time" "time"
"github.com/jandedobbeleer/oh-my-posh/src/color" "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/properties"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
"github.com/jandedobbeleer/oh-my-posh/src/template" "github.com/jandedobbeleer/oh-my-posh/src/template"
c "golang.org/x/text/cases" c "golang.org/x/text/cases"
@ -18,7 +18,7 @@ import (
// SegmentStyle the style of segment, for more information, see the constants // SegmentStyle the style of segment, for more information, see the constants
type SegmentStyle string 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{ txtTemplate := &template.Text{
Context: context, Context: context,
Env: env, Env: env,
@ -58,7 +58,7 @@ type Segment struct {
Text string Text string
env platform.Environment env runtime.Environment
writer SegmentWriter writer SegmentWriter
styleCache SegmentStyle styleCache SegmentStyle
name string name string
@ -82,7 +82,7 @@ func (segment *Segment) Name() string {
return name return name
} }
func (segment *Segment) SetEnabled(env platform.Environment) { func (segment *Segment) SetEnabled(env runtime.Environment) {
defer func() { defer func() {
err := recover() err := recover()
if err == nil { if err == nil {
@ -112,7 +112,7 @@ func (segment *Segment) SetEnabled(env platform.Environment) {
segment.env.DebugF("Segment: %s", segment.Name()) segment.env.DebugF("Segment: %s", segment.Name())
// validate toggles // 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, ",") list := strings.Split(toggles, ",")
for _, toggle := range list { for _, toggle := range list {
if SegmentType(toggle) == segment.Type || toggle == segment.Alias { if SegmentType(toggle) == segment.Type || toggle == segment.Alias {

View file

@ -6,8 +6,8 @@ import (
"github.com/jandedobbeleer/oh-my-posh/src/color" "github.com/jandedobbeleer/oh-my-posh/src/color"
"github.com/jandedobbeleer/oh-my-posh/src/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/properties"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
"github.com/jandedobbeleer/oh-my-posh/src/segments" "github.com/jandedobbeleer/oh-my-posh/src/segments"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -73,7 +73,7 @@ func TestShouldIncludeFolder(t *testing.T) {
} }
for _, tc := range cases { for _, tc := range cases {
env := new(mock.MockedEnvironment) env := new(mock.MockedEnvironment)
env.On("GOOS").Return(platform.LINUX) env.On("GOOS").Return(runtime.LINUX)
env.On("Home").Return("") env.On("Home").Return("")
env.On("Pwd").Return(cwd) env.On("Pwd").Return(cwd)
env.On("DirMatchesOneOf", cwd, []string{"Projects/oh-my-posh"}).Return(tc.Included) 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 { for _, tc := range cases {
env := new(mock.MockedEnvironment) env := new(mock.MockedEnvironment)
env.On("DebugF", mock2.Anything, mock2.Anything).Return(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), Env: make(map[string]string),
}) })

View file

@ -3,8 +3,8 @@ package config
import ( import (
"errors" "errors"
"github.com/jandedobbeleer/oh-my-posh/src/platform"
"github.com/jandedobbeleer/oh-my-posh/src/properties" "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/jandedobbeleer/oh-my-posh/src/segments"
) )
@ -15,7 +15,7 @@ type SegmentType string
type SegmentWriter interface { type SegmentWriter interface {
Enabled() bool Enabled() bool
Template() string Template() string
Init(props properties.Properties, env platform.Environment) Init(props properties.Properties, env runtime.Environment)
} }
const ( const (
@ -308,7 +308,7 @@ var Segments = map[SegmentType]func() SegmentWriter{
YTM: func() SegmentWriter { return &segments.Ytm{} }, 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 segment.env = env
if segment.Properties == nil { if segment.Properties == nil {

View file

@ -11,7 +11,7 @@ import (
"net/http" "net/http"
"net/url" "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) { func Download(fontPath string) ([]byte, error) {

View file

@ -10,7 +10,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/jandedobbeleer/oh-my-posh/src/platform/net" "github.com/jandedobbeleer/oh-my-posh/src/runtime/net"
) )
type release struct { type release struct {

View file

@ -7,11 +7,11 @@ import (
"bytes" "bytes"
"io" "io"
"path" "path"
"runtime" stdruntime "runtime"
"strings" "strings"
"github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/runtime"
"github.com/jandedobbeleer/oh-my-posh/src/platform/cmd" "github.com/jandedobbeleer/oh-my-posh/src/runtime/cmd"
) )
func contains[S ~[]E, E comparable](s S, e E) bool { 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 // 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") _, _ = cmd.Run("fc-cache", "-f")
} }

View file

@ -6,8 +6,8 @@ import (
"io" "io"
"net/http" "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/properties"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
) )
const ( const (
@ -86,7 +86,7 @@ func (o *OAuthRequest) refreshToken(refreshToken string) (string, error) {
return tokens.AccessToken, nil 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 { if data, err := getCacheValue[a](&o.Request, url); err == nil {
return data, nil return data, nil
} }
@ -103,7 +103,7 @@ func OauthResult[a any](o *OAuthRequest, url string, body io.Reader, requestModi
} }
if requestModifiers == nil { if requestModifiers == nil {
requestModifiers = []platform.HTTPRequestModifier{} requestModifiers = []runtime.HTTPRequestModifier{}
} }
requestModifiers = append(requestModifiers, addAuthHeader) requestModifiers = append(requestModifiers, addAuthHeader)

View file

@ -5,21 +5,21 @@ import (
"errors" "errors"
"io" "io"
"github.com/jandedobbeleer/oh-my-posh/src/platform"
"github.com/jandedobbeleer/oh-my-posh/src/properties" "github.com/jandedobbeleer/oh-my-posh/src/properties"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
) )
type Request struct { type Request struct {
props properties.Properties 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.env = env
r.props = props 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 { if data, err := getCacheValue[a](r, url); err == nil {
return data, nil return data, nil
} }
@ -45,7 +45,7 @@ func getCacheValue[a any](r *Request, key string) (a, error) {
return data, err 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 var data a
httpTimeout := r.props.GetInt(properties.HTTPTimeout, properties.DefaultHTTPTimeout) httpTimeout := r.props.GetInt(properties.HTTPTimeout, properties.DefaultHTTPTimeout)

View file

@ -28,7 +28,7 @@ import (
"fmt" "fmt"
"io" "io"
"math" "math"
"os" stdOS "os"
"path/filepath" "path/filepath"
"slices" "slices"
"strconv" "strconv"
@ -36,8 +36,8 @@ import (
"unicode/utf8" "unicode/utf8"
fontCLI "github.com/jandedobbeleer/oh-my-posh/src/font" 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/regex"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
"github.com/jandedobbeleer/oh-my-posh/src/terminal" "github.com/jandedobbeleer/oh-my-posh/src/terminal"
"github.com/esimov/stackblur-go" "github.com/esimov/stackblur-go"
@ -115,7 +115,7 @@ type Renderer struct {
RPromptOffset int RPromptOffset int
BgColor string BgColor string
env platform.Environment env runtime.Environment
Path string Path string
@ -147,7 +147,7 @@ type Renderer struct {
ansiSequenceRegexMap map[string]string ansiSequenceRegexMap map[string]string
} }
func (ir *Renderer) Init(env platform.Environment) error { func (ir *Renderer) Init(env runtime.Environment) error {
ir.env = env ir.env = env
if ir.Path == "" { if ir.Path == "" {
@ -210,8 +210,8 @@ func (ir *Renderer) loadFonts() error {
var data []byte var data []byte
fontCachePath := filepath.Join(ir.env.CachePath(), "Hack.zip") fontCachePath := filepath.Join(ir.env.CachePath(), "Hack.zip")
if _, err := os.Stat(fontCachePath); err == nil { if _, err := stdOS.Stat(fontCachePath); err == nil {
data, _ = os.ReadFile(fontCachePath) data, _ = stdOS.ReadFile(fontCachePath)
} }
// Download font if not cached // Download font if not cached
@ -224,7 +224,7 @@ func (ir *Renderer) loadFonts() error {
return err return err
} }
err = os.WriteFile(fontCachePath, data, 0644) err = stdOS.WriteFile(fontCachePath, data, 0644)
if err != nil { if err != nil {
return err return err
} }

View file

@ -1,11 +1,11 @@
package image package image
import ( import (
"os" stdOS "os"
"path/filepath" "path/filepath"
"testing" "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/shell"
"github.com/jandedobbeleer/oh-my-posh/src/terminal" "github.com/jandedobbeleer/oh-my-posh/src/terminal"
@ -28,11 +28,14 @@ var cases = []struct {
func runImageTest(config, content string) (string, error) { func runImageTest(config, content string) (string, error) {
poshImagePath := "jandedobbeleer.png" poshImagePath := "jandedobbeleer.png"
file, err := os.CreateTemp("", poshImagePath) file, err := stdOS.CreateTemp("", poshImagePath)
if err != nil { if err != nil {
return "", err return "", err
} }
defer os.Remove(file.Name())
defer func() {
_ = stdOS.Remove(file.Name())
}()
terminal.Init(shell.GENERIC) terminal.Init(shell.GENERIC)
@ -40,8 +43,8 @@ func runImageTest(config, content string) (string, error) {
AnsiString: content, AnsiString: content,
} }
env := &platform.Shell{ env := &runtime.Terminal{
CmdFlags: &platform.Flags{ CmdFlags: &runtime.Flags{
Config: config, Config: config,
}, },
} }
@ -53,7 +56,7 @@ func runImageTest(config, content string) (string, error) {
err = image.SavePNG() err = image.SavePNG()
if err == nil { if err == nil {
os.Remove(image.Path) _ = stdOS.Remove(image.Path)
} }
return filepath.Base(image.Path), err return filepath.Base(image.Path), err

View file

@ -5,8 +5,8 @@ import (
"io/fs" "io/fs"
"time" "time"
"github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/runtime"
"github.com/jandedobbeleer/oh-my-posh/src/platform/battery" "github.com/jandedobbeleer/oh-my-posh/src/runtime/battery"
mock "github.com/stretchr/testify/mock" mock "github.com/stretchr/testify/mock"
) )
@ -120,9 +120,9 @@ func (env *MockedEnvironment) Root() bool {
return args.Bool(0) return args.Bool(0)
} }
func (env *MockedEnvironment) Flags() *platform.Flags { func (env *MockedEnvironment) Flags() *runtime.Flags {
arguments := env.Called() arguments := env.Called()
return arguments.Get(0).(*platform.Flags) return arguments.Get(0).(*runtime.Flags)
} }
func (env *MockedEnvironment) BatteryState() (*battery.Info, error) { 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) 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) 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) args := env.Called(url)
return args.Get(0).([]byte), args.Error(1) 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) 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 { func (env *MockedEnvironment) StackCount() int {
@ -180,9 +180,9 @@ func (env *MockedEnvironment) CachePath() string {
return args.String(0) return args.String(0)
} }
func (env *MockedEnvironment) Cache() platform.Cache { func (env *MockedEnvironment) Cache() runtime.Cache {
args := env.Called() args := env.Called()
return args.Get(0).(platform.Cache) return args.Get(0).(runtime.Cache)
} }
func (env *MockedEnvironment) Close() { func (env *MockedEnvironment) Close() {
@ -209,14 +209,14 @@ func (env *MockedEnvironment) ConvertToLinuxPath(_ string) string {
return args.String(0) 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) 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() args := env.Called()
return args.Get(0).(*platform.TemplateCache) return args.Get(0).(*runtime.TemplateCache)
} }
func (env *MockedEnvironment) LoadTemplateCache() { func (env *MockedEnvironment) LoadTemplateCache() {
@ -278,9 +278,9 @@ func (env *MockedEnvironment) CursorPosition() (int, int) {
return args.Int(0), args.Int(1) return args.Int(0), args.Int(1)
} }
func (env *MockedEnvironment) SystemInfo() (*platform.SystemInfo, error) { func (env *MockedEnvironment) SystemInfo() (*runtime.SystemInfo, error) {
args := env.Called() 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) { func (env *MockedEnvironment) Unset(name string) {

View file

@ -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
}

View file

@ -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
}

View file

@ -5,8 +5,8 @@ import (
"github.com/jandedobbeleer/oh-my-posh/src/color" "github.com/jandedobbeleer/oh-my-posh/src/color"
"github.com/jandedobbeleer/oh-my-posh/src/config" "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/regex"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
"github.com/jandedobbeleer/oh-my-posh/src/shell" "github.com/jandedobbeleer/oh-my-posh/src/shell"
"github.com/jandedobbeleer/oh-my-posh/src/template" "github.com/jandedobbeleer/oh-my-posh/src/template"
"github.com/jandedobbeleer/oh-my-posh/src/terminal" "github.com/jandedobbeleer/oh-my-posh/src/terminal"
@ -18,7 +18,7 @@ var (
type Engine struct { type Engine struct {
Config *config.Config Config *config.Config
Env platform.Environment Env runtime.Environment
Plain bool Plain bool
console strings.Builder console strings.Builder

View file

@ -6,7 +6,7 @@ import (
"github.com/jandedobbeleer/oh-my-posh/src/config" "github.com/jandedobbeleer/oh-my-posh/src/config"
"github.com/jandedobbeleer/oh-my-posh/src/mock" "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/shell"
"github.com/jandedobbeleer/oh-my-posh/src/terminal" "github.com/jandedobbeleer/oh-my-posh/src/terminal"
@ -81,7 +81,7 @@ func TestPrintPWD(t *testing.T) {
env.On("User").Return("user") env.On("User").Return("user")
env.On("Host").Return("host", nil) env.On("Host").Return("host", nil)
env.On("DebugF", mock2.Anything, mock2.Anything).Return(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), Env: make(map[string]string),
Shell: "shell", Shell: "shell",
}) })
@ -110,7 +110,7 @@ func BenchmarkEngineRender(b *testing.B) {
} }
func engineRender() { func engineRender() {
env := &platform.Shell{} env := &runtime.Terminal{}
env.Init() env.Init()
defer env.Close() defer env.Close()
@ -175,7 +175,7 @@ func TestGetTitle(t *testing.T) {
env.On("Home").Return("/usr/home") env.On("Home").Return("/usr/home")
env.On("PathSeparator").Return(tc.PathSeparator) env.On("PathSeparator").Return(tc.PathSeparator)
env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil) 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{ Env: map[string]string{
"USERDOMAIN": "MyCompany", "USERDOMAIN": "MyCompany",
}, },
@ -238,7 +238,7 @@ func TestGetConsoleTitleIfGethostnameReturnsError(t *testing.T) {
env.On("Pwd").Return(tc.Cwd) env.On("Pwd").Return(tc.Cwd)
env.On("Home").Return("/usr/home") env.On("Home").Return("/usr/home")
env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil) 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{ Env: map[string]string{
"USERDOMAIN": "MyCompany", "USERDOMAIN": "MyCompany",
}, },

View file

@ -2,7 +2,7 @@ package prompt
import ( import (
"github.com/jandedobbeleer/oh-my-posh/src/config" "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/shell"
"github.com/jandedobbeleer/oh-my-posh/src/terminal" "github.com/jandedobbeleer/oh-my-posh/src/terminal"
) )
@ -10,8 +10,8 @@ import (
// New returns a prompt engine initialized with the // New returns a prompt engine initialized with the
// given configuration options, and is ready to print any // given configuration options, and is ready to print any
// of the prompt components. // of the prompt components.
func New(flags *platform.Flags) *Engine { func New(flags *runtime.Flags) *Engine {
env := &platform.Shell{ env := &runtime.Terminal{
CmdFlags: flags, CmdFlags: flags,
} }
@ -39,7 +39,7 @@ func New(flags *platform.Flags) *Engine {
return eng 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 // when in PowerShell, and force patching the bleed bug
// we need to reduce the terminal width by 1 so the last // we need to reduce the terminal width by 1 so the last
// character isn't cut off by the ANSI escape sequences // character isn't cut off by the ANSI escape sequences

View file

@ -4,12 +4,12 @@ import (
"fmt" "fmt"
"github.com/jandedobbeleer/oh-my-posh/src/color" "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 { type Wrapper struct {
Properties Map Properties Map
Env platform.Environment Env runtime.Environment
} }
func (w *Wrapper) GetColor(property Property, defaultColor color.Ansi) color.Ansi { func (w *Wrapper) GetColor(property Property, defaultColor color.Ansi) color.Ansi {

View file

@ -5,8 +5,8 @@ import (
"strconv" "strconv"
"strings" "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/regex"
"github.com/jandedobbeleer/oh-my-posh/src/runtime/cmd"
) )
func mapMostLogicalState(state string) State { func mapMostLogicalState(state string) State {

View file

@ -5,7 +5,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/jandedobbeleer/oh-my-posh/src/platform/cmd" "github.com/jandedobbeleer/oh-my-posh/src/runtime/cmd"
) )
func Get() (*Info, error) { func Get() (*Info, error) {

View file

@ -7,7 +7,7 @@ import (
"strconv" "strconv"
"strings" "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 // See https://man.openbsd.org/man8/apm.8

View file

@ -1,4 +1,4 @@
package platform package runtime
import ( import (
"encoding/json" "encoding/json"

View file

@ -11,7 +11,7 @@ import (
"time" "time"
"github.com/jandedobbeleer/oh-my-posh/src/log" "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) { func Download(cachePath, url string) (string, error) {

View file

@ -1,4 +1,4 @@
package platform package runtime
import "sync" import "sync"

View file

@ -1,4 +1,4 @@
package platform package runtime
import ( import (
"errors" "errors"
@ -144,7 +144,7 @@ type DOT11_SSID struct {
ucSSID [DOT11_SSID_MAX_LENGTH]uint8 ucSSID [DOT11_SSID_MAX_LENGTH]uint8
} }
func (env *Shell) getConnections() []*Connection { func (env *Terminal) getConnections() []*Connection {
var pIFTable2 *MIN_IF_TABLE2 var pIFTable2 *MIN_IF_TABLE2
_, _, _ = hGetIfTable2.Call(uintptr(unsafe.Pointer(&pIFTable2))) _, _, _ = hGetIfTable2.Call(uintptr(unsafe.Pointer(&pIFTable2)))
@ -199,7 +199,7 @@ func (env *Shell) getConnections() []*Connection {
return networks return networks
} }
func (env *Shell) wifiNetwork() (*Connection, error) { func (env *Terminal) wifiNetwork() (*Connection, error) {
env.Trace(time.Now()) env.Trace(time.Now())
// Open handle // Open handle
var pdwNegotiatedVersion uint32 var pdwNegotiatedVersion uint32
@ -234,7 +234,7 @@ func (env *Shell) wifiNetwork() (*Connection, error) {
return nil, errors.New("Not connected") 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{ info := Connection{
Type: WIFI, Type: WIFI,
} }

View file

@ -1,4 +1,4 @@
package platform package runtime
import ( import (
"context" "context"
@ -18,11 +18,11 @@ import (
"time" "time"
"github.com/jandedobbeleer/oh-my-posh/src/log" "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/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" disk "github.com/shirou/gopsutil/v3/disk"
load "github.com/shirou/gopsutil/v3/load" load "github.com/shirou/gopsutil/v3/load"
@ -194,7 +194,7 @@ type Environment interface {
Trace(start time.Time, args ...string) Trace(start time.Time, args ...string)
} }
type Shell struct { type Terminal struct {
CmdFlags *Flags CmdFlags *Flags
Var SimpleMap Var SimpleMap
@ -210,144 +210,144 @@ type Shell struct {
lsDirMap ConcurrentMap lsDirMap ConcurrentMap
} }
func (env *Shell) Init() { func (term *Terminal) Init() {
defer env.Trace(time.Now()) defer term.Trace(time.Now())
if env.CmdFlags == nil { if term.CmdFlags == nil {
env.CmdFlags = &Flags{} term.CmdFlags = &Flags{}
} }
if env.CmdFlags.Debug { if term.CmdFlags.Debug {
log.Enable() log.Enable()
} }
if env.CmdFlags.Plain { if term.CmdFlags.Plain {
log.Plain() log.Plain()
} }
env.fileCache = &fileCache{} term.fileCache = &fileCache{}
env.fileCache.Init(env.CachePath()) term.fileCache.Init(term.CachePath())
env.resolveConfigPath() term.resolveConfigPath()
env.cmdCache = &commandCache{ term.cmdCache = &commandCache{
commands: NewConcurrentMap(), commands: NewConcurrentMap(),
} }
env.tmplCache = &TemplateCache{} term.tmplCache = &TemplateCache{}
env.SetPromptCount() term.SetPromptCount()
} }
func (env *Shell) resolveConfigPath() { func (term *Terminal) resolveConfigPath() {
defer env.Trace(time.Now()) defer term.Trace(time.Now())
if len(env.CmdFlags.Config) == 0 { if len(term.CmdFlags.Config) == 0 {
env.CmdFlags.Config = env.Getenv("POSH_THEME") term.CmdFlags.Config = term.Getenv("POSH_THEME")
} }
if len(env.CmdFlags.Config) == 0 { if len(term.CmdFlags.Config) == 0 {
env.Debug("No config set, fallback to default config") term.Debug("No config set, fallback to default config")
return return
} }
if strings.HasPrefix(env.CmdFlags.Config, "https://") { if strings.HasPrefix(term.CmdFlags.Config, "https://") {
filePath, err := config.Download(env.CachePath(), env.CmdFlags.Config) filePath, err := config.Download(term.CachePath(), term.CmdFlags.Config)
if err != nil { if err != nil {
env.Error(err) term.Error(err)
env.CmdFlags.Config = "" term.CmdFlags.Config = ""
return return
} }
env.CmdFlags.Config = filePath term.CmdFlags.Config = filePath
return return
} }
// Cygwin path always needs the full path as we're on Windows but not really. // 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. // Doing filepath actions will convert it to a Windows path and break the init script.
if env.Platform() == WINDOWS && env.Shell() == "bash" { if term.Platform() == WINDOWS && term.Shell() == "bash" {
env.Debug("Cygwin detected, using full path for config") term.Debug("Cygwin detected, using full path for config")
return return
} }
configFile := env.CmdFlags.Config configFile := term.CmdFlags.Config
if strings.HasPrefix(configFile, "~") { if strings.HasPrefix(configFile, "~") {
configFile = strings.TrimPrefix(configFile, "~") configFile = strings.TrimPrefix(configFile, "~")
configFile = filepath.Join(env.Home(), configFile) configFile = filepath.Join(term.Home(), configFile)
} }
if !filepath.IsAbs(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...) log.Trace(start, args...)
} }
func (env *Shell) Debug(message string) { func (term *Terminal) Debug(message string) {
log.Debug(message) log.Debug(message)
} }
func (env *Shell) DebugF(format string, a ...any) { func (term *Terminal) DebugF(format string, a ...any) {
if !env.CmdFlags.Debug { if !term.CmdFlags.Debug {
return return
} }
message := fmt.Sprintf(format, a...) message := fmt.Sprintf(format, a...)
log.Debug(message) log.Debug(message)
} }
func (env *Shell) Error(err error) { func (term *Terminal) Error(err error) {
log.Error(err) log.Error(err)
} }
func (env *Shell) Getenv(key string) string { func (term *Terminal) Getenv(key string) string {
defer env.Trace(time.Now(), key) defer term.Trace(time.Now(), key)
val := os.Getenv(key) val := os.Getenv(key)
env.Debug(val) term.Debug(val)
return val return val
} }
func (env *Shell) Pwd() string { func (term *Terminal) Pwd() string {
env.Lock() term.Lock()
defer env.Trace(time.Now()) defer term.Trace(time.Now())
defer env.Unlock() defer term.Unlock()
if env.cwd != "" { if term.cwd != "" {
return env.cwd return term.cwd
} }
correctPath := func(pwd string) string { correctPath := func(pwd string) string {
if env.GOOS() != WINDOWS { if term.GOOS() != WINDOWS {
return pwd return pwd
} }
// on Windows, and being case sensitive and not consistent and all, this gives silly issues // on Windows, and being case sensitive and not consistent and all, this gives silly issues
driveLetter := regex.GetCompiledRegex(`^[a-z]:`) driveLetter := regex.GetCompiledRegex(`^[a-z]:`)
return driveLetter.ReplaceAllStringFunc(pwd, strings.ToUpper) return driveLetter.ReplaceAllStringFunc(pwd, strings.ToUpper)
} }
if env.CmdFlags != nil && env.CmdFlags.PWD != "" { if term.CmdFlags != nil && term.CmdFlags.PWD != "" {
env.cwd = correctPath(env.CmdFlags.PWD) term.cwd = correctPath(term.CmdFlags.PWD)
env.Debug(env.cwd) term.Debug(term.cwd)
return env.cwd return term.cwd
} }
dir, err := os.Getwd() dir, err := os.Getwd()
if err != nil { if err != nil {
env.Error(err) term.Error(err)
return "" return ""
} }
env.cwd = correctPath(dir) term.cwd = correctPath(dir)
env.Debug(env.cwd) term.Debug(term.cwd)
return env.cwd return term.cwd
} }
func (env *Shell) HasFiles(pattern string) bool { func (term *Terminal) HasFiles(pattern string) bool {
return env.HasFilesInDir(env.Pwd(), pattern) return term.HasFilesInDir(term.Pwd(), pattern)
} }
func (env *Shell) HasFilesInDir(dir, pattern string) bool { func (term *Terminal) HasFilesInDir(dir, pattern string) bool {
defer env.Trace(time.Now(), pattern) defer term.Trace(time.Now(), pattern)
fileSystem := os.DirFS(dir) fileSystem := os.DirFS(dir)
var dirEntries []fs.DirEntry var dirEntries []fs.DirEntry
if files, OK := env.lsDirMap.Get(dir); OK { if files, OK := term.lsDirMap.Get(dir); OK {
dirEntries, _ = files.([]fs.DirEntry) dirEntries, _ = files.([]fs.DirEntry)
} }
@ -355,18 +355,18 @@ func (env *Shell) HasFilesInDir(dir, pattern string) bool {
var err error var err error
dirEntries, err = fs.ReadDir(fileSystem, ".") dirEntries, err = fs.ReadDir(fileSystem, ".")
if err != nil { if err != nil {
env.Error(err) term.Error(err)
env.Debug("false") term.Debug("false")
return false return false
} }
env.lsDirMap.Set(dir, dirEntries) term.lsDirMap.Set(dir, dirEntries)
} }
pattern = strings.ToLower(pattern) pattern = strings.ToLower(pattern)
env.RWMutex.RLock() term.RWMutex.RLock()
defer env.RWMutex.RUnlock() defer term.RWMutex.RUnlock()
for _, match := range dirEntries { for _, match := range dirEntries {
if match.IsDir() { if match.IsDir() {
@ -375,236 +375,236 @@ func (env *Shell) HasFilesInDir(dir, pattern string) bool {
matchFileName, err := filepath.Match(pattern, strings.ToLower(match.Name())) matchFileName, err := filepath.Match(pattern, strings.ToLower(match.Name()))
if err != nil { if err != nil {
env.Error(err) term.Error(err)
env.Debug("false") term.Debug("false")
return false return false
} }
if matchFileName { if matchFileName {
env.Debug("true") term.Debug("true")
return true return true
} }
} }
env.Debug("false") term.Debug("false")
return false return false
} }
func (env *Shell) HasFileInParentDirs(pattern string, depth uint) bool { func (term *Terminal) HasFileInParentDirs(pattern string, depth uint) bool {
defer env.Trace(time.Now(), pattern, fmt.Sprint(depth)) defer term.Trace(time.Now(), pattern, fmt.Sprint(depth))
currentFolder := env.Pwd() currentFolder := term.Pwd()
for c := 0; c < int(depth); c++ { for c := 0; c < int(depth); c++ {
if env.HasFilesInDir(currentFolder, pattern) { if term.HasFilesInDir(currentFolder, pattern) {
env.Debug("true") term.Debug("true")
return true return true
} }
if dir := filepath.Dir(currentFolder); dir != currentFolder { if dir := filepath.Dir(currentFolder); dir != currentFolder {
currentFolder = dir currentFolder = dir
} else { } else {
env.Debug("false") term.Debug("false")
return false return false
} }
} }
env.Debug("false") term.Debug("false")
return false return false
} }
func (env *Shell) HasFolder(folder string) bool { func (term *Terminal) HasFolder(folder string) bool {
defer env.Trace(time.Now(), folder) defer term.Trace(time.Now(), folder)
f, err := os.Stat(folder) f, err := os.Stat(folder)
if err != nil { if err != nil {
env.Debug("false") term.Debug("false")
return false return false
} }
isDir := f.IsDir() isDir := f.IsDir()
env.DebugF("%t", isDir) term.DebugF("%t", isDir)
return isDir return isDir
} }
func (env *Shell) ResolveSymlink(path string) (string, error) { func (term *Terminal) ResolveSymlink(path string) (string, error) {
defer env.Trace(time.Now(), path) defer term.Trace(time.Now(), path)
link, err := filepath.EvalSymlinks(path) link, err := filepath.EvalSymlinks(path)
if err != nil { if err != nil {
env.Error(err) term.Error(err)
return "", err return "", err
} }
env.Debug(link) term.Debug(link)
return link, nil return link, nil
} }
func (env *Shell) FileContent(file string) string { func (term *Terminal) FileContent(file string) string {
defer env.Trace(time.Now(), file) defer term.Trace(time.Now(), file)
if !filepath.IsAbs(file) { if !filepath.IsAbs(file) {
file = filepath.Join(env.Pwd(), file) file = filepath.Join(term.Pwd(), file)
} }
content, err := os.ReadFile(file) content, err := os.ReadFile(file)
if err != nil { if err != nil {
env.Error(err) term.Error(err)
return "" return ""
} }
fileContent := string(content) fileContent := string(content)
env.Debug(fileContent) term.Debug(fileContent)
return fileContent return fileContent
} }
func (env *Shell) LsDir(path string) []fs.DirEntry { func (term *Terminal) LsDir(path string) []fs.DirEntry {
defer env.Trace(time.Now(), path) defer term.Trace(time.Now(), path)
entries, err := os.ReadDir(path) entries, err := os.ReadDir(path)
if err != nil { if err != nil {
env.Error(err) term.Error(err)
return nil return nil
} }
env.DebugF("%v", entries) term.DebugF("%v", entries)
return entries return entries
} }
func (env *Shell) PathSeparator() string { func (term *Terminal) PathSeparator() string {
defer env.Trace(time.Now()) defer term.Trace(time.Now())
return string(os.PathSeparator) return string(os.PathSeparator)
} }
func (env *Shell) User() string { func (term *Terminal) User() string {
defer env.Trace(time.Now()) defer term.Trace(time.Now())
user := os.Getenv("USER") user := os.Getenv("USER")
if user == "" { if user == "" {
user = os.Getenv("USERNAME") user = os.Getenv("USERNAME")
} }
env.Debug(user) term.Debug(user)
return user return user
} }
func (env *Shell) Host() (string, error) { func (term *Terminal) Host() (string, error) {
defer env.Trace(time.Now()) defer term.Trace(time.Now())
if len(env.host) != 0 { if len(term.host) != 0 {
return env.host, nil return term.host, nil
} }
hostName, err := os.Hostname() hostName, err := os.Hostname()
if err != nil { if err != nil {
env.Error(err) term.Error(err)
return "", err return "", err
} }
hostName = cleanHostName(hostName) hostName = cleanHostName(hostName)
env.Debug(hostName) term.Debug(hostName)
env.host = hostName term.host = hostName
return hostName, nil return hostName, nil
} }
func (env *Shell) GOOS() string { func (term *Terminal) GOOS() string {
defer env.Trace(time.Now()) defer term.Trace(time.Now())
return runtime.GOOS return runtime.GOOS
} }
func (env *Shell) RunCommand(command string, args ...string) (string, error) { func (term *Terminal) RunCommand(command string, args ...string) (string, error) {
defer env.Trace(time.Now(), append([]string{command}, args...)...) defer term.Trace(time.Now(), append([]string{command}, args...)...)
if cacheCommand, ok := env.cmdCache.get(command); ok { if cacheCommand, ok := term.cmdCache.get(command); ok {
command = cacheCommand command = cacheCommand
} }
output, err := cmd.Run(command, args...) output, err := cmd.Run(command, args...)
if err != nil { if err != nil {
env.Error(err) term.Error(err)
} }
env.Debug(output) term.Debug(output)
return output, err return output, err
} }
func (env *Shell) RunShellCommand(shell, command string) string { func (term *Terminal) RunShellCommand(shell, command string) string {
defer env.Trace(time.Now()) defer term.Trace(time.Now())
if out, err := env.RunCommand(shell, "-c", command); err == nil { if out, err := term.RunCommand(shell, "-c", command); err == nil {
return out return out
} }
return "" return ""
} }
func (env *Shell) CommandPath(command string) string { func (term *Terminal) CommandPath(command string) string {
defer env.Trace(time.Now(), command) defer term.Trace(time.Now(), command)
if path, ok := env.cmdCache.get(command); ok { if path, ok := term.cmdCache.get(command); ok {
env.Debug(path) term.Debug(path)
return path return path
} }
path, err := env.LookPath(command) path, err := term.LookPath(command)
if err == nil { if err == nil {
env.cmdCache.set(command, path) term.cmdCache.set(command, path)
env.Debug(path) term.Debug(path)
return path return path
} }
env.Error(err) term.Error(err)
return "" return ""
} }
func (env *Shell) HasCommand(command string) bool { func (term *Terminal) HasCommand(command string) bool {
defer env.Trace(time.Now(), command) defer term.Trace(time.Now(), command)
if path := env.CommandPath(command); path != "" { if path := term.CommandPath(command); path != "" {
return true return true
} }
return false return false
} }
func (env *Shell) StatusCodes() (int, string) { func (term *Terminal) StatusCodes() (int, string) {
defer env.Trace(time.Now()) defer term.Trace(time.Now())
if env.CmdFlags.Shell != CMD || !env.CmdFlags.NoExitCode { if term.CmdFlags.Shell != CMD || !term.CmdFlags.NoExitCode {
return env.CmdFlags.ErrorCode, env.CmdFlags.PipeStatus return term.CmdFlags.ErrorCode, term.CmdFlags.PipeStatus
} }
errorCode := env.Getenv("=ExitCode") errorCode := term.Getenv("=ExitCode")
env.Debug(errorCode) term.Debug(errorCode)
env.CmdFlags.ErrorCode, _ = strconv.Atoi(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 { func (term *Terminal) ExecutionTime() float64 {
defer env.Trace(time.Now()) defer term.Trace(time.Now())
if env.CmdFlags.ExecutionTime < 0 { if term.CmdFlags.ExecutionTime < 0 {
return 0 return 0
} }
return env.CmdFlags.ExecutionTime return term.CmdFlags.ExecutionTime
} }
func (env *Shell) Flags() *Flags { func (term *Terminal) Flags() *Flags {
defer env.Trace(time.Now()) defer term.Trace(time.Now())
return env.CmdFlags return term.CmdFlags
} }
func (env *Shell) Shell() string { func (term *Terminal) Shell() string {
defer env.Trace(time.Now()) defer term.Trace(time.Now())
if len(env.CmdFlags.Shell) != 0 { if len(term.CmdFlags.Shell) != 0 {
return env.CmdFlags.Shell 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() pid := os.Getppid()
p, _ := process.NewProcess(int32(pid)) p, _ := process.NewProcess(int32(pid))
name, err := p.Name() name, err := p.Name()
if err != nil { if err != nil {
env.Error(err) term.Error(err)
return UNKNOWN return UNKNOWN
} }
env.Debug("process name: " + name) term.Debug("process name: " + name)
// this is used for when scoop creates a shim, see // this is used for when scoop creates a shim, see
// https://github.com/jandedobbeleer/oh-my-posh/issues/2806 // https://github.com/jandedobbeleer/oh-my-posh/issues/2806
executable, _ := os.Executable() executable, _ := os.Executable()
if name == executable { if name == executable {
p, _ = p.Parent() p, _ = p.Parent()
name, err = p.Name() name, err = p.Name()
env.Debug("parent process name: " + name) term.Debug("parent process name: " + name)
} }
if err != nil { if err != nil {
env.Error(err) term.Error(err)
return UNKNOWN return UNKNOWN
} }
// Cache the shell value to speed things up. // Cache the shell value to speed things up.
env.CmdFlags.Shell = strings.Trim(strings.TrimSuffix(name, ".exe"), " ") term.CmdFlags.Shell = strings.Trim(strings.TrimSuffix(name, ".exe"), " ")
return env.CmdFlags.Shell return term.CmdFlags.Shell
} }
func (env *Shell) unWrapError(err error) error { func (term *Terminal) unWrapError(err error) error {
cause := err cause := err
for { for {
type nested interface{ Unwrap() error } type nested interface{ Unwrap() error }
@ -617,8 +617,8 @@ func (env *Shell) unWrapError(err error) error {
return cause return cause
} }
func (env *Shell) HTTPRequest(targetURL string, body io.Reader, timeout int, requestModifiers ...HTTPRequestModifier) ([]byte, error) { func (term *Terminal) HTTPRequest(targetURL string, body io.Reader, timeout int, requestModifiers ...HTTPRequestModifier) ([]byte, error) {
defer env.Trace(time.Now(), targetURL) defer term.Trace(time.Now(), targetURL)
ctx, cncl := context.WithTimeout(context.Background(), time.Millisecond*time.Duration(timeout)) ctx, cncl := context.WithTimeout(context.Background(), time.Millisecond*time.Duration(timeout))
defer cncl() defer cncl()
@ -632,22 +632,22 @@ func (env *Shell) HTTPRequest(targetURL string, body io.Reader, timeout int, req
modifier(request) modifier(request)
} }
if env.CmdFlags.Debug { if term.CmdFlags.Debug {
dump, _ := httputil.DumpRequestOut(request, true) dump, _ := httputil.DumpRequestOut(request, true)
env.Debug(string(dump)) term.Debug(string(dump))
} }
response, err := net.HTTPClient.Do(request) response, err := net.HTTPClient.Do(request)
if err != nil { if err != nil {
env.Error(err) term.Error(err)
return nil, env.unWrapError(err) return nil, term.unWrapError(err)
} }
// anything inside the range [200, 299] is considered a success // anything inside the range [200, 299] is considered a success
if response.StatusCode < 200 || response.StatusCode >= 300 { if response.StatusCode < 200 || response.StatusCode >= 300 {
message := "HTTP status code " + strconv.Itoa(response.StatusCode) message := "HTTP status code " + strconv.Itoa(response.StatusCode)
err := errors.New(message) err := errors.New(message)
env.Error(err) term.Error(err)
return nil, 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) responseBody, err := io.ReadAll(response.Body)
if err != nil { if err != nil {
env.Error(err) term.Error(err)
return nil, err return nil, err
} }
env.Debug(string(responseBody)) term.Debug(string(responseBody))
return responseBody, nil return responseBody, nil
} }
func (env *Shell) HasParentFilePath(path string) (*FileInfo, error) { func (term *Terminal) HasParentFilePath(path string) (*FileInfo, error) {
defer env.Trace(time.Now(), path) defer term.Trace(time.Now(), path)
currentFolder := env.Pwd() currentFolder := term.Pwd()
for { for {
fileSystem := os.DirFS(currentFolder) fileSystem := os.DirFS(currentFolder)
info, err := fs.Stat(fileSystem, path) info, err := fs.Stat(fileSystem, path)
@ -684,68 +684,68 @@ func (env *Shell) HasParentFilePath(path string) (*FileInfo, error) {
currentFolder = dir currentFolder = dir
continue continue
} }
env.Error(err) term.Error(err)
return nil, errors.New("no match at root level") return nil, errors.New("no match at root level")
} }
} }
func (env *Shell) StackCount() int { func (term *Terminal) StackCount() int {
defer env.Trace(time.Now()) defer term.Trace(time.Now())
if env.CmdFlags.StackCount < 0 { if term.CmdFlags.StackCount < 0 {
return 0 return 0
} }
return env.CmdFlags.StackCount return term.CmdFlags.StackCount
} }
func (env *Shell) Cache() Cache { func (term *Terminal) Cache() Cache {
return env.fileCache return term.fileCache
} }
func (env *Shell) saveTemplateCache() { func (term *Terminal) saveTemplateCache() {
// only store this when in a primary prompt // only store this when in a primary prompt
// and when we have a transient prompt in the config // 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 { if !canSave {
return return
} }
cache := env.TemplateCache() cache := term.TemplateCache()
cache.SegmentsCache = cache.Segments.SimpleMap() cache.SegmentsCache = cache.Segments.SimpleMap()
templateCache, err := json.Marshal(cache) templateCache, err := json.Marshal(cache)
if err == nil { if err == nil {
env.fileCache.Set(TEMPLATECACHE, string(templateCache), 1440) term.fileCache.Set(TEMPLATECACHE, string(templateCache), 1440)
} }
} }
func (env *Shell) Close() { func (term *Terminal) Close() {
defer env.Trace(time.Now()) defer term.Trace(time.Now())
env.saveTemplateCache() term.saveTemplateCache()
env.fileCache.Close() term.fileCache.Close()
} }
func (env *Shell) LoadTemplateCache() { func (term *Terminal) LoadTemplateCache() {
defer env.Trace(time.Now()) defer term.Trace(time.Now())
val, OK := env.fileCache.Get(TEMPLATECACHE) val, OK := term.fileCache.Get(TEMPLATECACHE)
if !OK { if !OK {
return return
} }
var tmplCache TemplateCache var tmplCache TemplateCache
err := json.Unmarshal([]byte(val), &tmplCache) err := json.Unmarshal([]byte(val), &tmplCache)
if err != nil { if err != nil {
env.Error(err) term.Error(err)
return return
} }
tmplCache.Segments = tmplCache.SegmentsCache.ConcurrentMap() tmplCache.Segments = tmplCache.SegmentsCache.ConcurrentMap()
tmplCache.initialized = true tmplCache.initialized = true
env.tmplCache = &tmplCache term.tmplCache = &tmplCache
} }
func (env *Shell) Logs() string { func (term *Terminal) Logs() string {
return log.String() return log.String()
} }
func (env *Shell) TemplateCache() *TemplateCache { func (term *Terminal) TemplateCache() *TemplateCache {
defer env.Trace(time.Now()) defer term.Trace(time.Now())
tmplCache := env.tmplCache tmplCache := term.tmplCache
tmplCache.Lock() tmplCache.Lock()
defer tmplCache.Unlock() defer tmplCache.Unlock()
@ -753,23 +753,23 @@ func (env *Shell) TemplateCache() *TemplateCache {
return tmplCache return tmplCache
} }
tmplCache.Root = env.Root() tmplCache.Root = term.Root()
tmplCache.Shell = env.Shell() tmplCache.Shell = term.Shell()
tmplCache.ShellVersion = env.CmdFlags.ShellVersion tmplCache.ShellVersion = term.CmdFlags.ShellVersion
tmplCache.Code, _ = env.StatusCodes() tmplCache.Code, _ = term.StatusCodes()
tmplCache.WSL = env.IsWsl() tmplCache.WSL = term.IsWsl()
tmplCache.Segments = NewConcurrentMap() tmplCache.Segments = NewConcurrentMap()
tmplCache.PromptCount = env.CmdFlags.PromptCount tmplCache.PromptCount = term.CmdFlags.PromptCount
tmplCache.Env = make(map[string]string) tmplCache.Env = make(map[string]string)
tmplCache.Var = make(map[string]any) tmplCache.Var = make(map[string]any)
if env.Var != nil { if term.Var != nil {
tmplCache.Var = env.Var tmplCache.Var = term.Var
} }
const separator = "=" const separator = "="
values := os.Environ() values := os.Environ()
env.DebugF("environment: %v", values) term.DebugF("environment: %v", values)
for value := range values { for value := range values {
key, val, valid := strings.Cut(values[value], separator) key, val, valid := strings.Cut(values[value], separator)
if !valid { if !valid {
@ -778,31 +778,31 @@ func (env *Shell) TemplateCache() *TemplateCache {
tmplCache.Env[key] = val tmplCache.Env[key] = val
} }
pwd := env.Pwd() pwd := term.Pwd()
tmplCache.PWD = ReplaceHomeDirPrefixWithTilde(env, pwd) tmplCache.PWD = ReplaceHomeDirPrefixWithTilde(term, pwd)
tmplCache.AbsolutePWD = pwd tmplCache.AbsolutePWD = pwd
if env.IsWsl() { if term.IsWsl() {
tmplCache.AbsolutePWD, _ = env.RunCommand("wslpath", "-m", pwd) tmplCache.AbsolutePWD, _ = term.RunCommand("wslpath", "-m", pwd)
} }
tmplCache.Folder = Base(env, pwd) tmplCache.Folder = Base(term, pwd)
if env.GOOS() == WINDOWS && strings.HasSuffix(tmplCache.Folder, ":") { if term.GOOS() == WINDOWS && strings.HasSuffix(tmplCache.Folder, ":") {
tmplCache.Folder += `\` tmplCache.Folder += `\`
} }
tmplCache.UserName = env.User() tmplCache.UserName = term.User()
if host, err := env.Host(); err == nil { if host, err := term.Host(); err == nil {
tmplCache.HostName = host tmplCache.HostName = host
} }
goos := env.GOOS() goos := term.GOOS()
tmplCache.OS = goos tmplCache.OS = goos
if goos == LINUX { 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 { if shlvl, err := strconv.Atoi(val); err == nil {
tmplCache.SHLVL = shlvl tmplCache.SHLVL = shlvl
} }
@ -811,17 +811,17 @@ func (env *Shell) TemplateCache() *TemplateCache {
return tmplCache 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 // 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 // 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 // for the time being until we figure out what the actual root cause is
defer func() { defer func() {
if err := recover(); err != nil { if err := recover(); err != nil {
env.Error(errors.New("panic")) term.Error(errors.New("panic"))
match = false match = false
} }
}() }()
match = dirMatchesOneOf(dir, env.Home(), env.GOOS(), regexes) match = dirMatchesOneOf(dir, term.Home(), term.GOOS(), regexes)
return return
} }
@ -852,42 +852,42 @@ func dirMatchesOneOf(dir, home, goos string, regexes []string) bool {
return false return false
} }
func (env *Shell) SetPromptCount() { func (term *Terminal) SetPromptCount() {
countStr := os.Getenv("POSH_PROMPT_COUNT") countStr := os.Getenv("POSH_PROMPT_COUNT")
if len(countStr) > 0 { if len(countStr) > 0 {
// this counter is incremented by the shell // this counter is incremented by the shell
count, err := strconv.Atoi(countStr) count, err := strconv.Atoi(countStr)
if err == nil { if err == nil {
env.CmdFlags.PromptCount = count term.CmdFlags.PromptCount = count
return return
} }
} }
var count int var count int
if val, found := env.Cache().Get(PROMPTCOUNTCACHE); found { if val, found := term.Cache().Get(PROMPTCOUNTCACHE); found {
count, _ = strconv.Atoi(val) count, _ = strconv.Atoi(val)
} }
// only write to cache if we're the primary prompt // only write to cache if we're the primary prompt
if env.CmdFlags.Primary { if term.CmdFlags.Primary {
count++ 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) { func (term *Terminal) CursorPosition() (row, col int) {
if number, err := strconv.Atoi(env.Getenv("POSH_CURSOR_LINE")); err == nil { if number, err := strconv.Atoi(term.Getenv("POSH_CURSOR_LINE")); err == nil {
row = number 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 col = number
} }
return return
} }
func (env *Shell) SystemInfo() (*SystemInfo, error) { func (term *Terminal) SystemInfo() (*SystemInfo, error) {
s := &SystemInfo{} s := &SystemInfo{}
mem, err := env.Memory() mem, err := term.Memory()
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -1,4 +1,4 @@
package platform package runtime
import ( import (
"errors" "errors"
@ -8,7 +8,7 @@ import (
"github.com/jandedobbeleer/oh-my-posh/src/regex" "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 { 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<PERCENTAGE>[0-9]{1,3})%; (?P<STATE>[a-zA-Z\s]+);`, output) matches := regex.FindNamedRegexMatch(`(?P<PERCENTAGE>[0-9]{1,3})%; (?P<STATE>[a-zA-Z\s]+);`, output)
if len(matches) != 2 { if len(matches) != 2 {
err := errors.New("Unable to find battery state based on output") err := errors.New("Unable to find battery state based on output")
env.Error(err) term.Error(err)
return nil, err return nil, err
} }
var percentage int var percentage int
var err error var err error
if percentage, err = strconv.Atoi(matches["PERCENTAGE"]); err != nil { 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 nil, errors.New("Unable to parse battery percentage")
} }
return &battery.Info{ return &battery.Info{
@ -49,15 +49,15 @@ func (env *Shell) parseBatteryOutput(output string) (*battery.Info, error) {
}, nil }, nil
} }
func (env *Shell) BatteryState() (*battery.Info, error) { func (term *Terminal) BatteryState() (*battery.Info, error) {
defer env.Trace(time.Now()) defer term.Trace(time.Now())
output, err := env.RunCommand("pmset", "-g", "batt") output, err := term.RunCommand("pmset", "-g", "batt")
if err != nil { if err != nil {
env.Error(err) term.Error(err)
return nil, err return nil, err
} }
if !strings.Contains(output, "Battery") { if !strings.Contains(output, "Battery") {
return nil, errors.New("No battery found") return nil, errors.New("No battery found")
} }
return env.parseBatteryOutput(output) return term.parseBatteryOutput(output)
} }

View file

@ -1,4 +1,4 @@
package platform package runtime
import ( import (
"testing" "testing"

195
src/runtime/os_unix.go Normal file
View file

@ -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
}

View file

@ -1,4 +1,4 @@
package platform package runtime
import ( import (
"errors" "errors"
@ -15,8 +15,8 @@ import (
"golang.org/x/sys/windows/registry" "golang.org/x/sys/windows/registry"
) )
func (env *Shell) Root() bool { func (term *Terminal) Root() bool {
defer env.Trace(time.Now()) defer term.Trace(time.Now())
var sid *windows.SID var sid *windows.SID
// Although this looks scary, it is directly copied from the // 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, 0, 0, 0, 0, 0, 0,
&sid) &sid)
if err != nil { if err != nil {
env.Error(err) term.Error(err)
return false return false
} }
defer func() { defer func() {
@ -45,17 +45,17 @@ func (env *Shell) Root() bool {
member, err := token.IsMember(sid) member, err := token.IsMember(sid)
if err != nil { if err != nil {
env.Error(err) term.Error(err)
return false return false
} }
return member return member
} }
func (env *Shell) Home() string { func (term *Terminal) Home() string {
home := os.Getenv("HOME") home := os.Getenv("HOME")
defer func() { defer func() {
env.Debug(home) term.Debug(home)
}() }()
if len(home) > 0 { if len(home) > 0 {
return home return home
@ -68,61 +68,61 @@ func (env *Shell) Home() string {
return home return home
} }
func (env *Shell) QueryWindowTitles(processName, windowTitleRegex string) (string, error) { func (term *Terminal) QueryWindowTitles(processName, windowTitleRegex string) (string, error) {
defer env.Trace(time.Now(), windowTitleRegex) defer term.Trace(time.Now(), windowTitleRegex)
title, err := queryWindowTitles(processName, windowTitleRegex) title, err := queryWindowTitles(processName, windowTitleRegex)
if err != nil { if err != nil {
env.Error(err) term.Error(err)
} }
return title, err return title, err
} }
func (env *Shell) IsWsl() bool { func (term *Terminal) IsWsl() bool {
defer env.Trace(time.Now()) defer term.Trace(time.Now())
return false return false
} }
func (env *Shell) IsWsl2() bool { func (term *Terminal) IsWsl2() bool {
defer env.Trace(time.Now()) defer term.Trace(time.Now())
return false return false
} }
func (env *Shell) TerminalWidth() (int, error) { func (term *Terminal) TerminalWidth() (int, error) {
defer env.Trace(time.Now()) defer term.Trace(time.Now())
if env.CmdFlags.TerminalWidth > 0 { if term.CmdFlags.TerminalWidth > 0 {
env.DebugF("terminal width: %d", env.CmdFlags.TerminalWidth) term.DebugF("terminal width: %d", term.CmdFlags.TerminalWidth)
return env.CmdFlags.TerminalWidth, nil return term.CmdFlags.TerminalWidth, nil
} }
handle, err := syscall.Open("CONOUT$", syscall.O_RDWR, 0) handle, err := syscall.Open("CONOUT$", syscall.O_RDWR, 0)
if err != nil { if err != nil {
env.Error(err) term.Error(err)
return 0, err return 0, err
} }
info, err := winterm.GetConsoleScreenBufferInfo(uintptr(handle)) info, err := winterm.GetConsoleScreenBufferInfo(uintptr(handle))
if err != nil { if err != nil {
env.Error(err) term.Error(err)
return 0, err return 0, err
} }
env.CmdFlags.TerminalWidth = int(info.Size.X) term.CmdFlags.TerminalWidth = int(info.Size.X)
env.DebugF("terminal width: %d", env.CmdFlags.TerminalWidth) term.DebugF("terminal width: %d", term.CmdFlags.TerminalWidth)
return env.CmdFlags.TerminalWidth, nil return term.CmdFlags.TerminalWidth, nil
} }
func (env *Shell) Platform() string { func (term *Terminal) Platform() string {
return WINDOWS return WINDOWS
} }
func (env *Shell) CachePath() string { func (term *Terminal) CachePath() string {
defer env.Trace(time.Now()) defer term.Trace(time.Now())
// get LOCALAPPDATA if present // 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 cachePath
} }
return env.Home() return term.Home()
} }
// Takes a registry path to a key like // 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. // 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. // Returns a variant type if successful; nil and an error if not.
func (env *Shell) WindowsRegistryKeyValue(path string) (*WindowsRegistryValue, error) { func (term *Terminal) WindowsRegistryKeyValue(path string) (*WindowsRegistryValue, error) {
env.Trace(time.Now(), path) term.Trace(time.Now(), path)
// Format:sudo -u postgres psql // Format:sudo -u postgres psql
// "HKLM\Software\Microsoft\Windows NT\CurrentVersion\EditionID" // "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, `\`) rootKey, regPath, found := strings.Cut(path, `\`)
if !found { if !found {
err := fmt.Errorf("Error, malformed registry path: '%s'", path) err := fmt.Errorf("Error, malformed registry path: '%s'", path)
env.Error(err) term.Error(err)
return nil, err return nil, err
} }
var regKey string var regKey string
if !strings.HasSuffix(regPath, `\`) { if !strings.HasSuffix(regPath, `\`) {
regKey = Base(env, regPath) regKey = Base(term, regPath)
if len(regKey) != 0 { if len(regKey) != 0 {
regPath = strings.TrimSuffix(regPath, `\`+regKey) regPath = strings.TrimSuffix(regPath, `\`+regKey)
} }
@ -178,18 +178,18 @@ func (env *Shell) WindowsRegistryKeyValue(path string) (*WindowsRegistryValue, e
key = windows.HKEY_USERS key = windows.HKEY_USERS
default: default:
err := fmt.Errorf("Error, unknown registry key: '%s", rootKey) err := fmt.Errorf("Error, unknown registry key: '%s", rootKey)
env.Error(err) term.Error(err)
return nil, err return nil, err
} }
k, err := registry.OpenKey(key, regPath, registry.READ) k, err := registry.OpenKey(key, regPath, registry.READ)
if err != nil { if err != nil {
env.Error(err) term.Error(err)
return nil, err return nil, err
} }
_, valType, err := k.GetValue(regKey, nil) _, valType, err := k.GetValue(regKey, nil)
if err != nil { if err != nil {
env.Error(err) term.Error(err)
return nil, 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) errorLogMsg := fmt.Sprintf("Error, no formatter for type: %d", valType)
return nil, errors.New(errorLogMsg) 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 return regValue, nil
} }
func (env *Shell) InWSLSharedDrive() bool { func (term *Terminal) InWSLSharedDrive() bool {
return false return false
} }
func (env *Shell) ConvertToWindowsPath(path string) string { func (term *Terminal) ConvertToWindowsPath(path string) string {
return strings.ReplaceAll(path, `\`, "/") return strings.ReplaceAll(path, `\`, "/")
} }
func (env *Shell) ConvertToLinuxPath(path string) string { func (term *Terminal) ConvertToLinuxPath(path string) string {
return path return path
} }
func (env *Shell) DirIsWritable(path string) bool { func (term *Terminal) DirIsWritable(path string) bool {
defer env.Trace(time.Now()) defer term.Trace(time.Now())
return env.isWriteable(path) return term.isWriteable(path)
} }
func (env *Shell) Connection(connectionType ConnectionType) (*Connection, error) { func (term *Terminal) Connection(connectionType ConnectionType) (*Connection, error) {
if env.networks == nil { if term.networks == nil {
networks := env.getConnections() networks := term.getConnections()
if len(networks) == 0 { if len(networks) == 0 {
return nil, errors.New("No connections found") 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 { if network.Type == connectionType {
return network, nil 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{} return nil, &NotImplemented{}
} }
func (env *Shell) LookPath(command string) (string, error) { func (term *Terminal) LookPath(command string) (string, error) {
winAppPath := filepath.Join(env.Getenv("LOCALAPPDATA"), `\Microsoft\WindowsApps\`, command) winAppPath := filepath.Join(term.Getenv("LOCALAPPDATA"), `\Microsoft\WindowsApps\`, command)
if !strings.HasSuffix(winAppPath, ".exe") { if !strings.HasSuffix(winAppPath, ".exe") {
winAppPath += ".exe" winAppPath += ".exe"
} }

View file

@ -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
}

View file

@ -1,4 +1,4 @@
package platform package runtime
import ( import (
"errors" "errors"
@ -259,7 +259,7 @@ func (u *tokenUser) isMemberOf(sid *windows.SID) bool {
return false return false
} }
func (env *Shell) isWriteable(folder string) bool { func (env *Terminal) isWriteable(folder string) bool {
cu, err := getCurrentUser() cu, err := getCurrentUser()
if err != nil { if err != nil {
@ -335,7 +335,7 @@ type memoryStatusEx struct {
AvailExtendedVirtual uint64 AvailExtendedVirtual uint64
} }
func (env *Shell) Memory() (*Memory, error) { func (env *Terminal) Memory() (*Memory, error) {
var memStat memoryStatusEx var memStat memoryStatusEx
memStat.Length = uint32(unsafe.Sizeof(memStat)) memStat.Length = uint32(unsafe.Sizeof(memStat))
r0, _, err := globalMemoryStatusEx.Call(uintptr(unsafe.Pointer(&memStat))) r0, _, err := globalMemoryStatusEx.Call(uintptr(unsafe.Pointer(&memStat)))

View file

@ -3,8 +3,8 @@ package segments
import ( import (
"path/filepath" "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/properties"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
) )
type Angular struct { type Angular struct {
@ -15,7 +15,7 @@ func (a *Angular) Template() string {
return languageTemplate 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{ a.language = language{
env: env, env: env,
props: props, props: props,

View file

@ -6,8 +6,8 @@ import (
"path" "path"
"strings" "strings"
"github.com/jandedobbeleer/oh-my-posh/src/platform"
"github.com/jandedobbeleer/oh-my-posh/src/properties" "github.com/jandedobbeleer/oh-my-posh/src/properties"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
"github.com/spf13/pflag" "github.com/spf13/pflag"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
) )
@ -34,7 +34,7 @@ type ArgocdConfig struct {
type Argocd struct { type Argocd struct {
props properties.Properties props properties.Properties
env platform.Environment env runtime.Environment
ArgocdContext ArgocdContext
} }
@ -43,7 +43,7 @@ func (a *Argocd) Template() string {
return NameTemplate 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.props = props
a.env = env a.env = env
} }

View file

@ -4,13 +4,13 @@ import (
"fmt" "fmt"
"strings" "strings"
"github.com/jandedobbeleer/oh-my-posh/src/platform"
"github.com/jandedobbeleer/oh-my-posh/src/properties" "github.com/jandedobbeleer/oh-my-posh/src/properties"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
) )
type Aws struct { type Aws struct {
props properties.Properties props properties.Properties
env platform.Environment env runtime.Environment
Profile string Profile string
Region string Region string
@ -24,7 +24,7 @@ func (a *Aws) Template() string {
return " {{ .Profile }}{{ if .Region }}@{{ .Region }}{{ end }} " 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.props = props
a.env = env a.env = env
} }

View file

@ -6,13 +6,13 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/jandedobbeleer/oh-my-posh/src/platform"
"github.com/jandedobbeleer/oh-my-posh/src/properties" "github.com/jandedobbeleer/oh-my-posh/src/properties"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
) )
type Az struct { type Az struct {
props properties.Properties props properties.Properties
env platform.Environment env runtime.Environment
AzureSubscription AzureSubscription
Origin string Origin string
@ -74,7 +74,7 @@ func (a *Az) Template() string {
return NameTemplate 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.props = props
a.env = env a.env = env
} }

View file

@ -1,8 +1,8 @@
package segments package segments
import ( import (
"github.com/jandedobbeleer/oh-my-posh/src/platform"
"github.com/jandedobbeleer/oh-my-posh/src/properties" "github.com/jandedobbeleer/oh-my-posh/src/properties"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
) )
type AzFunc struct { type AzFunc struct {
@ -13,7 +13,7 @@ func (az *AzFunc) Template() string {
return languageTemplate 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{ az.language = language{
env: env, env: env,
props: props, props: props,

View file

@ -6,8 +6,8 @@ import (
"testing" "testing"
"github.com/jandedobbeleer/oh-my-posh/src/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/properties"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@ -121,7 +121,7 @@ func TestAzSegment(t *testing.T) {
azureRmContext = string(content) 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("FileContent", filepath.Join(poshHome, ".azure", "azureProfile.json")).Return(azureProfile)
env.On("Getenv", "POSH_AZURE_SUBSCRIPTION").Return(azureRmContext) env.On("Getenv", "POSH_AZURE_SUBSCRIPTION").Return(azureRmContext)
env.On("Getenv", "AZURE_CONFIG_DIR").Return("") env.On("Getenv", "AZURE_CONFIG_DIR").Return("")

View file

@ -5,13 +5,13 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/jandedobbeleer/oh-my-posh/src/platform"
"github.com/jandedobbeleer/oh-my-posh/src/properties" "github.com/jandedobbeleer/oh-my-posh/src/properties"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
) )
type Azd struct { type Azd struct {
props properties.Properties props properties.Properties
env platform.Environment env runtime.Environment
azdConfig azdConfig
} }
@ -25,7 +25,7 @@ func (t *Azd) Template() string {
return " \uebd8 {{ .DefaultEnvironment }} " 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.props = props
t.env = env t.env = env
} }

View file

@ -7,8 +7,8 @@ import (
"testing" "testing"
"github.com/jandedobbeleer/oh-my-posh/src/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/properties"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
mock2 "github.com/stretchr/testify/mock" mock2 "github.com/stretchr/testify/mock"
) )
@ -39,7 +39,7 @@ func TestAzdSegment(t *testing.T) {
env.On("Debug", mock2.Anything) env.On("Debug", mock2.Anything)
if tc.IsInited { if tc.IsInited {
fileInfo := &platform.FileInfo{ fileInfo := &runtime.FileInfo{
Path: "test/.azure", Path: "test/.azure",
ParentFolder: "test", ParentFolder: "test",
IsDir: true, 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) env.On("FileContent", filepath.Join("test", ".azure", "config.json")).Return(`{"version": 1, "defaultEnvironment": "TestEnvironment"}`, nil)
} else { } 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{ azd := Azd{

View file

@ -1,14 +1,14 @@
package segments package segments
import ( 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/properties"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
"github.com/jandedobbeleer/oh-my-posh/src/runtime/battery"
) )
type Battery struct { type Battery struct {
props properties.Properties props properties.Properties
env platform.Environment env runtime.Environment
*battery.Info *battery.Info
Error string Error string
@ -84,7 +84,7 @@ func (b *Battery) enabledWhileError(err error) bool {
return true 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.props = props
b.env = env b.env = env
} }

View file

@ -1,8 +1,8 @@
package segments package segments
import ( import (
"github.com/jandedobbeleer/oh-my-posh/src/platform"
"github.com/jandedobbeleer/oh-my-posh/src/properties" "github.com/jandedobbeleer/oh-my-posh/src/properties"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
) )
type Bazel struct { type Bazel struct {
@ -20,7 +20,7 @@ func (c *Bazel) Template() string {
return " {{ if .Error }}{{ .Icon }} {{ .Error }}{{ else }}{{ url .Icon .URL }} {{ .Full }}{{ end }} " 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{ c.language = language{
env: env, env: env,
props: props, props: props,

View file

@ -10,14 +10,14 @@ import (
"sort" "sort"
"time" "time"
"github.com/jandedobbeleer/oh-my-posh/src/platform"
"github.com/jandedobbeleer/oh-my-posh/src/properties" "github.com/jandedobbeleer/oh-my-posh/src/properties"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
) )
// segment struct, makes templating easier // segment struct, makes templating easier
type Brewfather struct { type Brewfather struct {
props properties.Properties props properties.Properties
env platform.Environment env runtime.Environment
Batch Batch
TemperatureTrendIcon string 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 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.props = props
bf.env = env bf.env = env
} }

View file

@ -1,8 +1,8 @@
package segments package segments
import ( import (
"github.com/jandedobbeleer/oh-my-posh/src/platform"
"github.com/jandedobbeleer/oh-my-posh/src/properties" "github.com/jandedobbeleer/oh-my-posh/src/properties"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
) )
type Buf struct { type Buf struct {
@ -13,7 +13,7 @@ func (b *Buf) Template() string {
return languageTemplate 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{ b.language = language{
env: env, env: env,
props: props, props: props,

View file

@ -1,8 +1,8 @@
package segments package segments
import ( import (
"github.com/jandedobbeleer/oh-my-posh/src/platform"
"github.com/jandedobbeleer/oh-my-posh/src/properties" "github.com/jandedobbeleer/oh-my-posh/src/properties"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
) )
type Bun struct { type Bun struct {
@ -13,7 +13,7 @@ func (b *Bun) Template() string {
return languageTemplate 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{ b.language = language{
env: env, env: env,
props: props, props: props,

View file

@ -4,13 +4,13 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/jandedobbeleer/oh-my-posh/src/platform"
"github.com/jandedobbeleer/oh-my-posh/src/properties" "github.com/jandedobbeleer/oh-my-posh/src/properties"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
) )
type CarbonIntensity struct { type CarbonIntensity struct {
props properties.Properties props properties.Properties
env platform.Environment env runtime.Environment
TrendIcon string TrendIcon string
@ -149,7 +149,7 @@ func (d *CarbonIntensity) setStatus() error {
return nil 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.props = props
d.env = env d.env = env
} }

View file

@ -3,8 +3,8 @@ package segments
import ( import (
"encoding/json" "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/properties"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
) )
type Cds struct { type Cds struct {
@ -16,7 +16,7 @@ func (c *Cds) Template() string {
return languageTemplate 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{ c.language = language{
env: env, env: env,
props: props, props: props,

View file

@ -1,8 +1,8 @@
package segments package segments
import ( import (
"github.com/jandedobbeleer/oh-my-posh/src/platform"
"github.com/jandedobbeleer/oh-my-posh/src/properties" "github.com/jandedobbeleer/oh-my-posh/src/properties"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
) )
type Cf struct { type Cf struct {
@ -13,7 +13,7 @@ func (c *Cf) Template() string {
return languageTemplate 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{ c.language = language{
env: env, env: env,
props: props, props: props,

View file

@ -4,13 +4,13 @@ import (
"errors" "errors"
"strings" "strings"
"github.com/jandedobbeleer/oh-my-posh/src/platform"
"github.com/jandedobbeleer/oh-my-posh/src/properties" "github.com/jandedobbeleer/oh-my-posh/src/properties"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
) )
type CfTarget struct { type CfTarget struct {
props properties.Properties props properties.Properties
env platform.Environment env runtime.Environment
CfTargetDetails CfTargetDetails
} }
@ -26,7 +26,7 @@ func (c *CfTarget) Template() string {
return "{{if .Org }}{{ .Org }}{{ end }}{{if .Space }}/{{ .Space }}{{ end }}" 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.props = props
c.env = env c.env = env
} }

View file

@ -7,8 +7,8 @@ import (
"testing" "testing"
"github.com/jandedobbeleer/oh-my-posh/src/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/properties"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@ -19,7 +19,7 @@ func TestCFTargetSegment(t *testing.T) {
Template string Template string
ExpectedString string ExpectedString string
DisplayMode string DisplayMode string
FileInfo *platform.FileInfo FileInfo *runtime.FileInfo
TargetOutput string TargetOutput string
CommandError error CommandError error
}{ }{
@ -51,13 +51,13 @@ func TestCFTargetSegment(t *testing.T) {
Case: "files and a manifest file", Case: "files and a manifest file",
ExpectedString: "12345678trial/dev", ExpectedString: "12345678trial/dev",
DisplayMode: DisplayModeFiles, 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", 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", Case: "files and a manifest directory",
DisplayMode: DisplayModeFiles, DisplayMode: DisplayModeFiles,
FileInfo: &platform.FileInfo{ FileInfo: &runtime.FileInfo{
IsDir: true, IsDir: true,
}, },
}, },

View file

@ -1,8 +1,8 @@
package segments package segments
import ( import (
"github.com/jandedobbeleer/oh-my-posh/src/platform"
"github.com/jandedobbeleer/oh-my-posh/src/properties" "github.com/jandedobbeleer/oh-my-posh/src/properties"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
) )
type Cmake struct { type Cmake struct {
@ -13,7 +13,7 @@ func (c *Cmake) Template() string {
return languageTemplate 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{ c.language = language{
env: env, env: env,
props: props, props: props,

View file

@ -3,13 +3,13 @@ package segments
import ( import (
"strings" "strings"
"github.com/jandedobbeleer/oh-my-posh/src/platform"
"github.com/jandedobbeleer/oh-my-posh/src/properties" "github.com/jandedobbeleer/oh-my-posh/src/properties"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
) )
type Cmd struct { type Cmd struct {
props properties.Properties props properties.Properties
env platform.Environment env runtime.Environment
Output string Output string
} }
@ -86,7 +86,7 @@ func (c *Cmd) runScript(shell, script string) bool {
return len(c.Output) != 0 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.props = props
c.env = env c.env = env
} }

View file

@ -3,15 +3,15 @@ package segments
import ( import (
"strings" "strings"
"github.com/jandedobbeleer/oh-my-posh/src/platform"
"github.com/jandedobbeleer/oh-my-posh/src/properties" "github.com/jandedobbeleer/oh-my-posh/src/properties"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
) )
type Connection struct { type Connection struct {
props properties.Properties props properties.Properties
env platform.Environment env runtime.Environment
platform.Connection runtime.Connection
} }
const ( const (
@ -26,7 +26,7 @@ func (c *Connection) Enabled() bool {
types := c.props.GetString(Type, "wifi|ethernet") types := c.props.GetString(Type, "wifi|ethernet")
connectionTypes := strings.Split(types, "|") connectionTypes := strings.Split(types, "|")
for _, connectionType := range connectionTypes { for _, connectionType := range connectionTypes {
network, err := c.env.Connection(platform.ConnectionType(connectionType)) network, err := c.env.Connection(runtime.ConnectionType(connectionType))
if err != nil { if err != nil {
continue continue
} }
@ -36,7 +36,7 @@ func (c *Connection) Enabled() bool {
return false 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.props = props
c.env = env c.env = env
} }

View file

@ -5,15 +5,15 @@ import (
"testing" "testing"
"github.com/jandedobbeleer/oh-my-posh/src/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/properties"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestConnection(t *testing.T) { func TestConnection(t *testing.T) {
type connectionResponse struct { type connectionResponse struct {
Connection *platform.Connection Connection *runtime.Connection
Error error Error error
} }
cases := []struct { cases := []struct {
@ -30,7 +30,7 @@ func TestConnection(t *testing.T) {
ConnectionType: "wifi", ConnectionType: "wifi",
Connections: []*connectionResponse{ Connections: []*connectionResponse{
{ {
Connection: &platform.Connection{ Connection: &runtime.Connection{
Name: "WiFi", Name: "WiFi",
Type: "wifi", Type: "wifi",
}, },
@ -42,8 +42,8 @@ func TestConnection(t *testing.T) {
ConnectionType: "wifi", ConnectionType: "wifi",
Connections: []*connectionResponse{ Connections: []*connectionResponse{
{ {
Connection: &platform.Connection{ Connection: &runtime.Connection{
Type: platform.WIFI, Type: runtime.WIFI,
}, },
Error: fmt.Errorf("no connection"), Error: fmt.Errorf("no connection"),
}, },
@ -56,14 +56,14 @@ func TestConnection(t *testing.T) {
ExpectedEnabled: true, ExpectedEnabled: true,
Connections: []*connectionResponse{ Connections: []*connectionResponse{
{ {
Connection: &platform.Connection{ Connection: &runtime.Connection{
Type: platform.WIFI, Type: runtime.WIFI,
}, },
Error: fmt.Errorf("no connection"), Error: fmt.Errorf("no connection"),
}, },
{ {
Connection: &platform.Connection{ Connection: &runtime.Connection{
Type: platform.ETHERNET, Type: runtime.ETHERNET,
}, },
}, },
}, },
@ -73,14 +73,14 @@ func TestConnection(t *testing.T) {
ConnectionType: "wifi|ethernet", ConnectionType: "wifi|ethernet",
Connections: []*connectionResponse{ Connections: []*connectionResponse{
{ {
Connection: &platform.Connection{ Connection: &runtime.Connection{
Type: platform.WIFI, Type: runtime.WIFI,
}, },
Error: fmt.Errorf("no connection"), Error: fmt.Errorf("no connection"),
}, },
{ {
Connection: &platform.Connection{ Connection: &runtime.Connection{
Type: platform.ETHERNET, Type: runtime.ETHERNET,
}, },
Error: fmt.Errorf("no connection"), Error: fmt.Errorf("no connection"),
}, },

View file

@ -1,8 +1,8 @@
package segments package segments
import ( import (
"github.com/jandedobbeleer/oh-my-posh/src/platform"
"github.com/jandedobbeleer/oh-my-posh/src/properties" "github.com/jandedobbeleer/oh-my-posh/src/properties"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
) )
type Crystal struct { type Crystal struct {
@ -13,7 +13,7 @@ func (c *Crystal) Template() string {
return languageTemplate 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{ c.language = language{
env: env, env: env,
props: props, props: props,

View file

@ -1,8 +1,8 @@
package segments package segments
import ( import (
"github.com/jandedobbeleer/oh-my-posh/src/platform"
"github.com/jandedobbeleer/oh-my-posh/src/properties" "github.com/jandedobbeleer/oh-my-posh/src/properties"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
) )
var ( var (
@ -18,7 +18,7 @@ func (d *Dart) Template() string {
return languageTemplate 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{ d.language = language{
env: env, env: env,
props: props, props: props,

View file

@ -1,8 +1,8 @@
package segments package segments
import ( import (
"github.com/jandedobbeleer/oh-my-posh/src/platform"
"github.com/jandedobbeleer/oh-my-posh/src/properties" "github.com/jandedobbeleer/oh-my-posh/src/properties"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
) )
type Deno struct { type Deno struct {
@ -13,7 +13,7 @@ func (d *Deno) Template() string {
return languageTemplate 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{ d.language = language{
env: env, env: env,
props: props, props: props,

View file

@ -4,8 +4,8 @@ import (
"encoding/json" "encoding/json"
"path/filepath" "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/properties"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
) )
type DockerConfig struct { type DockerConfig struct {
@ -14,7 +14,7 @@ type DockerConfig struct {
type Docker struct { type Docker struct {
props properties.Properties props properties.Properties
env platform.Environment env runtime.Environment
Context string Context string
} }
@ -23,7 +23,7 @@ func (d *Docker) Template() string {
return " \uf308 {{ .Context }} " 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.props = props
d.env = env d.env = env
} }

View file

@ -2,8 +2,8 @@ package segments
import ( import (
"github.com/jandedobbeleer/oh-my-posh/src/constants" "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/properties"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
) )
type Dotnet struct { type Dotnet struct {
@ -16,7 +16,7 @@ func (d *Dotnet) Template() string {
return " {{ if .Unsupported }}\uf071{{ else }}{{ .Full }}{{ end }} " 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{ d.language = language{
env: env, env: env,
props: props, props: props,

View file

@ -4,7 +4,7 @@ import (
"testing" "testing"
"github.com/jandedobbeleer/oh-my-posh/src/constants" "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" "github.com/stretchr/testify/assert"
) )
@ -31,7 +31,7 @@ func TestDotnetSegment(t *testing.T) {
if tc.ExitCode != 0 { if tc.ExitCode != 0 {
env.Unset("RunCommand") env.Unset("RunCommand")
err := &platform.CommandError{ExitCode: tc.ExitCode} err := &runtime.CommandError{ExitCode: tc.ExitCode}
env.On("RunCommand", "dotnet", []string{"--version"}).Return("", err) env.On("RunCommand", "dotnet", []string{"--version"}).Return("", err)
} }

View file

@ -1,8 +1,8 @@
package segments package segments
import ( import (
"github.com/jandedobbeleer/oh-my-posh/src/platform"
"github.com/jandedobbeleer/oh-my-posh/src/properties" "github.com/jandedobbeleer/oh-my-posh/src/properties"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
) )
type Elixir struct { type Elixir struct {
@ -13,7 +13,7 @@ func (e *Elixir) Template() string {
return languageTemplate 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{ e.language = language{
env: env, env: env,
props: props, props: props,

View file

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"testing" "testing"
"github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/runtime"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@ -50,7 +50,7 @@ func TestElixir(t *testing.T) {
env.On("HasCommand", "asdf").Return(tc.HasAsdf) env.On("HasCommand", "asdf").Return(tc.HasAsdf)
var asdfErr error var asdfErr error
if tc.AsdfExitCode != 0 { 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) env.On("RunCommand", "asdf", []string{"current", "elixir"}).Return(tc.AsdfVersionOutput, asdfErr)

View file

@ -4,8 +4,8 @@ import (
"fmt" "fmt"
"strconv" "strconv"
"github.com/jandedobbeleer/oh-my-posh/src/platform"
"github.com/jandedobbeleer/oh-my-posh/src/properties" "github.com/jandedobbeleer/oh-my-posh/src/properties"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
lang "golang.org/x/text/language" lang "golang.org/x/text/language"
"golang.org/x/text/message" "golang.org/x/text/message"
@ -13,7 +13,7 @@ import (
type Executiontime struct { type Executiontime struct {
props properties.Properties props properties.Properties
env platform.Environment env runtime.Environment
FormattedMs string FormattedMs string
Ms int64 Ms int64
@ -70,7 +70,7 @@ func (t *Executiontime) Template() string {
return " {{ .FormattedMs }} " 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.props = props
t.env = env t.env = env
} }

Some files were not shown because too many files have changed in this diff Show more