chore: rename environment to platform

This commit is contained in:
Jan De Dobbeleer 2022-11-09 20:27:54 +01:00 committed by Jan De Dobbeleer
parent 1729952804
commit 18f6db017a
151 changed files with 577 additions and 579 deletions

View file

@ -2,7 +2,7 @@ package cli
import (
"fmt"
"oh-my-posh/environment"
"oh-my-posh/platform"
"os"
"os/exec"
"path/filepath"
@ -33,7 +33,7 @@ You can do the following:
_ = cmd.Help()
return
}
env := &environment.ShellEnvironment{
env := &platform.Shell{
Version: cliVersion,
}
env.Init()
@ -42,7 +42,7 @@ You can do the following:
case "path":
fmt.Print(env.CachePath())
case "clear":
cacheFilePath := filepath.Join(env.CachePath(), environment.CacheFile)
cacheFilePath := filepath.Join(env.CachePath(), platform.CacheFile)
err := os.Remove(cacheFilePath)
if err != nil {
fmt.Println(err.Error())
@ -50,7 +50,7 @@ You can do the following:
}
fmt.Printf("removed cache file at %s\n", cacheFilePath)
case "edit":
cacheFilePath := filepath.Join(env.CachePath(), environment.CacheFile)
cacheFilePath := filepath.Join(env.CachePath(), platform.CacheFile)
editFileWithEditor(cacheFilePath)
}
},

View file

@ -3,7 +3,7 @@ package cli
import (
"fmt"
"oh-my-posh/engine"
"oh-my-posh/environment"
"oh-my-posh/platform"
"path/filepath"
"strings"
@ -38,9 +38,9 @@ Exports the ~/myconfig.omp.json config file to toml and writes the result to you
A backup of the current config can be found at ~/myconfig.omp.json.bak.`,
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
env := &environment.ShellEnvironment{
env := &platform.Shell{
Version: cliVersion,
CmdFlags: &environment.Flags{
CmdFlags: &platform.Flags{
Config: config,
},
}
@ -60,7 +60,7 @@ A backup of the current config can be found at ~/myconfig.omp.json.bak.`,
},
}
func cleanOutputPath(path string, env environment.Environment) string {
func cleanOutputPath(path string, env platform.Environment) string {
if strings.HasPrefix(path, "~") {
path = strings.TrimPrefix(path, "~")
path = filepath.Join(env.Home(), path)

View file

@ -5,7 +5,7 @@ import (
"oh-my-posh/color"
"oh-my-posh/console"
"oh-my-posh/engine"
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/shell"
"github.com/spf13/cobra"
@ -47,9 +47,9 @@ Exports the config to an image file ~/mytheme.png.
Exports the config to an image file using customized output options.`,
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
env := &environment.ShellEnvironment{
env := &platform.Shell{
Version: cliVersion,
CmdFlags: &environment.Flags{
CmdFlags: &platform.Flags{
Config: config,
Shell: shell.PLAIN,
},

View file

@ -3,7 +3,7 @@ package cli
import (
"fmt"
"oh-my-posh/engine"
"oh-my-posh/environment"
"oh-my-posh/platform"
"github.com/spf13/cobra"
)
@ -37,9 +37,9 @@ Migrates the ~/myconfig.omp.json config file to toml and writes the result to yo
A backup of the current config can be found at ~/myconfig.omp.json.bak.`,
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
env := &environment.ShellEnvironment{
env := &platform.Shell{
Version: cliVersion,
CmdFlags: &environment.Flags{
CmdFlags: &platform.Flags{
Config: config,
Migrate: true,
},

View file

@ -5,7 +5,7 @@ import (
"oh-my-posh/color"
"oh-my-posh/console"
"oh-my-posh/engine"
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/shell"
"time"
@ -20,9 +20,9 @@ var debugCmd = &cobra.Command{
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
startTime := time.Now()
env := &environment.ShellEnvironment{
env := &platform.Shell{
Version: cliVersion,
CmdFlags: &environment.Flags{
CmdFlags: &platform.Flags{
Config: config,
Debug: true,
PWD: pwd,

View file

@ -2,8 +2,8 @@ package cli
import (
"fmt"
"oh-my-posh/environment"
"oh-my-posh/font"
"oh-my-posh/platform"
"github.com/spf13/cobra"
)
@ -33,9 +33,9 @@ This command is used to install fonts and configure the font in your terminal.
if len(args) > 1 {
fontName = args[1]
}
env := &environment.ShellEnvironment{}
env := &platform.Shell{}
env.Init()
needsAdmin := env.GOOS() == environment.WINDOWS && !env.Root()
needsAdmin := env.GOOS() == platform.WINDOWS && !env.Root()
font.Run(fontName, needsAdmin)
return
case "configure":

View file

@ -3,7 +3,7 @@ package cli
import (
"fmt"
"oh-my-posh/color"
"oh-my-posh/environment"
"oh-my-posh/platform"
"time"
color2 "github.com/gookit/color"
@ -32,9 +32,9 @@ This command is used to get the value of the following variables:
_ = cmd.Help()
return
}
env := &environment.ShellEnvironment{
env := &platform.Shell{
Version: cliVersion,
CmdFlags: &environment.Flags{
CmdFlags: &platform.Flags{
Shell: shellName,
},
}

View file

@ -3,7 +3,7 @@ package cli
import (
"fmt"
"oh-my-posh/engine"
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/shell"
"github.com/spf13/cobra"
@ -49,9 +49,9 @@ func init() { //nolint:gochecknoinits
}
func runInit(shellName string) {
env := &environment.ShellEnvironment{
env := &platform.Shell{
Version: cliVersion,
CmdFlags: &environment.Flags{
CmdFlags: &platform.Flags{
Shell: shellName,
Config: config,
Strict: strict,

View file

@ -5,7 +5,7 @@ import (
"oh-my-posh/color"
"oh-my-posh/console"
"oh-my-posh/engine"
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/shell"
"github.com/spf13/cobra"
@ -46,9 +46,9 @@ var printCmd = &cobra.Command{
_ = cmd.Help()
return
}
env := &environment.ShellEnvironment{
env := &platform.Shell{
Version: cliVersion,
CmdFlags: &environment.Flags{
CmdFlags: &platform.Flags{
Config: config,
PWD: pwd,
PSWD: pswd,

View file

@ -2,13 +2,13 @@ package color
import (
"fmt"
"oh-my-posh/environment"
"oh-my-posh/platform"
"strconv"
"github.com/gookit/color"
)
func MakeColors(palette Palette, cacheEnabled bool, accentColor string, env environment.Environment) (colors AnsiColors) {
func MakeColors(palette Palette, cacheEnabled bool, accentColor string, env platform.Environment) (colors AnsiColors) {
defaultColors := &DefaultColors{}
defaultColors.SetAccentColor(env, accentColor)
colors = defaultColors

View file

@ -2,15 +2,13 @@
package color
import (
"oh-my-posh/environment"
)
import "oh-my-posh/platform"
func GetAccentColor(env environment.Environment) (*RGB, error) {
return nil, &environment.NotImplemented{}
func GetAccentColor(env platform.Environment) (*RGB, error) {
return nil, &platform.NotImplemented{}
}
func (d *DefaultColors) SetAccentColor(env environment.Environment, defaultColor string) {
func (d *DefaultColors) SetAccentColor(env platform.Environment, defaultColor string) {
if len(defaultColor) == 0 {
return
}

View file

@ -2,18 +2,18 @@ package color
import (
"errors"
"oh-my-posh/environment"
"oh-my-posh/platform"
"github.com/gookit/color"
)
func GetAccentColor(env environment.Environment) (*RGB, error) {
func GetAccentColor(env platform.Environment) (*RGB, error) {
if env == nil {
return nil, errors.New("unable to get color without environment")
}
// see https://stackoverflow.com/questions/3560890/vista-7-how-to-get-glass-color
value, err := env.WindowsRegistryKeyValue(`HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM\ColorizationColor`)
if err != nil || value.ValueType != environment.DWORD {
if err != nil || value.ValueType != platform.DWORD {
return nil, err
}
return &RGB{
@ -23,7 +23,7 @@ func GetAccentColor(env environment.Environment) (*RGB, error) {
}, nil
}
func (d *DefaultColors) SetAccentColor(env environment.Environment, defaultColor string) {
func (d *DefaultColors) SetAccentColor(env platform.Environment, defaultColor string) {
rgb, err := GetAccentColor(env)
if err != nil {
d.accent = &Color{

View file

@ -2,8 +2,8 @@ package color
import (
"fmt"
"oh-my-posh/environment"
"oh-my-posh/mock"
"oh-my-posh/platform"
"oh-my-posh/shell"
"oh-my-posh/template"
"testing"
@ -29,7 +29,7 @@ func TestMeasureText(t *testing.T) {
},
}
env := new(mock.MockedEnvironment)
env.On("TemplateCache").Return(&environment.TemplateCache{
env.On("TemplateCache").Return(&platform.TemplateCache{
Env: make(map[string]string),
})
shells := []string{shell.BASH, shell.ZSH, shell.PLAIN}

View file

@ -2,12 +2,12 @@ package console
import (
"oh-my-posh/color"
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/template"
)
type Title struct {
Env environment.Environment
Env platform.Environment
Ansi *color.Ansi
Template string
}

View file

@ -2,8 +2,8 @@ package console
import (
"oh-my-posh/color"
"oh-my-posh/environment"
"oh-my-posh/mock"
"oh-my-posh/platform"
"testing"
"github.com/stretchr/testify/assert"
@ -49,7 +49,7 @@ func TestGetTitle(t *testing.T) {
env.On("Pwd").Return(tc.Cwd)
env.On("Home").Return("/usr/home")
env.On("PathSeparator").Return(tc.PathSeparator)
env.On("TemplateCache").Return(&environment.TemplateCache{
env.On("TemplateCache").Return(&platform.TemplateCache{
Env: map[string]string{
"USERDOMAIN": "MyCompany",
},
@ -106,7 +106,7 @@ func TestGetConsoleTitleIfGethostnameReturnsError(t *testing.T) {
env := new(mock.MockedEnvironment)
env.On("Pwd").Return(tc.Cwd)
env.On("Home").Return("/usr/home")
env.On("TemplateCache").Return(&environment.TemplateCache{
env.On("TemplateCache").Return(&platform.TemplateCache{
Env: map[string]string{
"USERDOMAIN": "MyCompany",
},

View file

@ -2,7 +2,7 @@ package engine
import (
"oh-my-posh/color"
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/shell"
"sync"
"time"
@ -47,21 +47,21 @@ type Block struct {
HorizontalOffset int `json:"horizontal_offset,omitempty"`
VerticalOffset int `json:"vertical_offset,omitempty"`
env environment.Environment
env platform.Environment
writer color.Writer
ansi *color.Ansi
activeSegment *Segment
previousActiveSegment *Segment
}
func (b *Block) Init(env environment.Environment, writer color.Writer, ansi *color.Ansi) {
func (b *Block) Init(env platform.Environment, writer color.Writer, ansi *color.Ansi) {
b.env = env
b.writer = writer
b.ansi = ansi
b.executeSegmentLogic()
}
func (b *Block) InitPlain(env environment.Environment, config *Config) {
func (b *Block) InitPlain(env platform.Environment, config *Config) {
b.ansi = &color.Ansi{}
b.ansi.InitPlain()
b.writer = &color.AnsiWriter{

View file

@ -6,7 +6,7 @@ import (
"fmt"
"io"
"oh-my-posh/color"
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/properties"
"oh-my-posh/segments"
"oh-my-posh/template"
@ -57,7 +57,7 @@ type Config struct {
origin string
eval bool
updated bool
env environment.Environment
env platform.Environment
}
// MakeColors creates instance of AnsiColors to use in AnsiWriter according to
@ -105,7 +105,7 @@ func (cfg *Config) exitWithError(err error) {
}
// LoadConfig returns the default configuration including possible user overrides
func LoadConfig(env environment.Environment) *Config {
func LoadConfig(env platform.Environment) *Config {
cfg := loadConfig(env)
cfg.env = env
// only migrate automatically when the switch isn't set
@ -115,7 +115,7 @@ func LoadConfig(env environment.Environment) *Config {
return cfg
}
func loadConfig(env environment.Environment) *Config {
func loadConfig(env platform.Environment) *Config {
defer env.Trace(time.Now(), "config.loadConfig")
var cfg Config
configFile := env.Flags().Config
@ -205,7 +205,7 @@ func (cfg *Config) Export(format string) string {
}
}
func (cfg *Config) BackupAndMigrate(env environment.Environment) {
func (cfg *Config) BackupAndMigrate(env platform.Environment) {
origin := cfg.backup()
cfg.Migrate(env)
cfg.Write(cfg.format)

View file

@ -2,8 +2,8 @@ package engine
import (
"oh-my-posh/color"
"oh-my-posh/environment"
"oh-my-posh/mock"
"oh-my-posh/platform"
"oh-my-posh/segments"
"testing"
@ -119,7 +119,7 @@ func TestGetPalette(t *testing.T) {
}
for _, tc := range cases {
env := &mock.MockedEnvironment{}
env.On("TemplateCache").Return(&environment.TemplateCache{
env.On("TemplateCache").Return(&platform.TemplateCache{
Env: map[string]string{},
Shell: "bash",
})

View file

@ -4,7 +4,7 @@ import (
"fmt"
"oh-my-posh/color"
"oh-my-posh/console"
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/shell"
"oh-my-posh/template"
"strings"
@ -13,7 +13,7 @@ import (
type Engine struct {
Config *Config
Env environment.Environment
Env platform.Environment
Writer color.Writer
Ansi *color.Ansi
ConsoleTitle *console.Title

View file

@ -4,8 +4,8 @@ import (
"errors"
"oh-my-posh/color"
"oh-my-posh/console"
"oh-my-posh/environment"
"oh-my-posh/mock"
"oh-my-posh/platform"
"oh-my-posh/shell"
"testing"
@ -64,7 +64,7 @@ func TestPrintPWD(t *testing.T) {
env.On("Pwd").Return("pwd")
env.On("Shell").Return("shell")
env.On("Host").Return("host", nil)
env.On("TemplateCache").Return(&environment.TemplateCache{
env.On("TemplateCache").Return(&platform.TemplateCache{
Env: make(map[string]string),
Shell: "shell",
})
@ -91,7 +91,7 @@ func BenchmarkEngineRender(b *testing.B) {
}
func engineRender() {
env := &environment.ShellEnvironment{}
env := &platform.Shell{}
env.Init()
defer env.Close()

View file

@ -2,7 +2,7 @@ package engine
import (
"fmt"
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/properties"
"oh-my-posh/segments"
"strings"
@ -16,7 +16,7 @@ const (
segmentTemplate = properties.Property("template")
)
func (cfg *Config) Migrate(env environment.Environment) {
func (cfg *Config) Migrate(env platform.Environment) {
for _, block := range cfg.Blocks {
for _, segment := range block.Segments {
segment.migrate(env, cfg.Version)
@ -32,7 +32,7 @@ func (cfg *Config) Migrate(env environment.Environment) {
cfg.Version = configVersion
}
func (segment *Segment) migrate(env environment.Environment, version int) {
func (segment *Segment) migrate(env platform.Environment, version int) {
if version < 1 {
segment.migrationOne(env)
}
@ -41,7 +41,7 @@ func (segment *Segment) migrate(env environment.Environment, version int) {
}
}
func (segment *Segment) migrationOne(env environment.Environment) {
func (segment *Segment) migrationOne(env platform.Environment) {
if err := segment.mapSegmentWithWriter(env); err != nil {
return
}
@ -161,7 +161,7 @@ func (segment *Segment) migrationOne(env environment.Environment) {
delete(segment.Properties, colorBackground)
}
func (segment *Segment) migrationTwo(env environment.Environment) {
func (segment *Segment) migrationTwo(env platform.Environment) {
if err := segment.mapSegmentWithWriter(env); err != nil {
return
}

View file

@ -1,8 +1,8 @@
package engine
import (
"oh-my-posh/environment"
"oh-my-posh/mock"
"oh-my-posh/platform"
"oh-my-posh/properties"
"testing"
@ -88,7 +88,7 @@ func (m *MockedWriter) Template() string {
return m.template
}
func (m *MockedWriter) Init(props properties.Properties, env environment.Environment) {}
func (m *MockedWriter) Init(props properties.Properties, env platform.Environment) {}
func TestIconOverride(t *testing.T) {
cases := []struct {

View file

@ -7,7 +7,7 @@ import (
"strings"
"time"
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/properties"
"oh-my-posh/segments"
"oh-my-posh/shell"
@ -37,7 +37,7 @@ type Segment struct {
writer SegmentWriter
Enabled bool `json:"-"`
text string
env environment.Environment
env platform.Environment
backgroundCache string
foregroundCache string
}
@ -55,7 +55,7 @@ type SegmentTiming struct {
type SegmentWriter interface {
Enabled() bool
Template() string
Init(props properties.Properties, env environment.Environment)
Init(props properties.Properties, env platform.Environment)
}
// SegmentStyle the style of segment, for more information, see the constants
@ -266,7 +266,7 @@ func (segment *Segment) background() string {
return segment.backgroundCache
}
func (segment *Segment) mapSegmentWithWriter(env environment.Environment) error {
func (segment *Segment) mapSegmentWithWriter(env platform.Environment) error {
segment.env = env
functions := map[SegmentType]SegmentWriter{
ANGULAR: &segments.Angular{},
@ -369,7 +369,7 @@ func (segment *Segment) string() string {
return text
}
func (segment *Segment) SetEnabled(env environment.Environment) {
func (segment *Segment) SetEnabled(env platform.Environment) {
defer func() {
err := recover()
if err == nil {

View file

@ -2,8 +2,8 @@ package engine
import (
"encoding/json"
"oh-my-posh/environment"
"oh-my-posh/mock"
"oh-my-posh/platform"
"oh-my-posh/properties"
"oh-my-posh/segments"
"testing"
@ -71,7 +71,7 @@ func TestShouldIncludeFolder(t *testing.T) {
}
for _, tc := range cases {
env := new(mock.MockedEnvironment)
env.On("GOOS").Return(environment.LINUX)
env.On("GOOS").Return(platform.LINUX)
env.On("Home").Return("")
env.On("Pwd").Return(cwd)
env.On("DirMatchesOneOf", cwd, []string{"Projects/oh-my-posh"}).Return(tc.Included)
@ -142,7 +142,7 @@ func TestGetColors(t *testing.T) {
}
for _, tc := range cases {
env := new(mock.MockedEnvironment)
env.On("TemplateCache").Return(&environment.TemplateCache{
env.On("TemplateCache").Return(&platform.TemplateCache{
Env: make(map[string]string),
})
segment := &Segment{

View file

@ -5,7 +5,7 @@ import (
"fmt"
"io"
"net/http"
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/properties"
)
@ -85,7 +85,7 @@ func (o *OAuthRequest) refreshToken(refreshToken string) (string, error) {
return tokens.AccessToken, nil
}
func OauthResult[a any](o *OAuthRequest, url string, body io.Reader, requestModifiers ...environment.HTTPRequestModifier) (a, error) {
func OauthResult[a any](o *OAuthRequest, url string, body io.Reader, requestModifiers ...platform.HTTPRequestModifier) (a, error) {
if data, err := getCacheValue[a](&o.Request, url); err == nil {
return data, nil
}
@ -102,7 +102,7 @@ func OauthResult[a any](o *OAuthRequest, url string, body io.Reader, requestModi
}
if requestModifiers == nil {
requestModifiers = []environment.HTTPRequestModifier{}
requestModifiers = []platform.HTTPRequestModifier{}
}
requestModifiers = append(requestModifiers, addAuthHeader)

View file

@ -2,8 +2,8 @@ package http
import (
"fmt"
"oh-my-posh/environment"
"oh-my-posh/mock"
"oh-my-posh/platform"
"oh-my-posh/properties"
"testing"
@ -161,7 +161,7 @@ func TestOauthResult(t *testing.T) {
env.On("Cache").Return(cache)
env.On("HTTPRequest", url).Return([]byte(tc.JSONResponse), tc.Error)
env.On("HTTPRequest", tokenURL).Return([]byte(tc.TokenResponse), tc.Error)
env.On("Log", environment.Error, "OAuth", mock2.Anything).Return()
env.On("Log", platform.Error, "OAuth", mock2.Anything).Return()
oauth := &OAuthRequest{
AccessTokenKey: accessTokenKey,

View file

@ -4,21 +4,21 @@ import (
"encoding/json"
"errors"
"io"
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/properties"
)
type Request struct {
props properties.Properties
env environment.Environment
env platform.Environment
}
func (r *Request) Init(env environment.Environment, props properties.Properties) {
func (r *Request) Init(env platform.Environment, props properties.Properties) {
r.env = env
r.props = props
}
func Do[a any](r *Request, url string, requestModifiers ...environment.HTTPRequestModifier) (a, error) {
func Do[a any](r *Request, url string, requestModifiers ...platform.HTTPRequestModifier) (a, error) {
if data, err := getCacheValue[a](r, url); err == nil {
return data, nil
}
@ -34,29 +34,29 @@ func getCacheValue[a any](r *Request, key string) (a, error) {
if val, found := r.env.Cache().Get(key); found {
err := json.Unmarshal([]byte(val), &data)
if err != nil {
r.env.Log(environment.Error, "OAuth", err.Error())
r.env.Log(platform.Error, "OAuth", err.Error())
return data, err
}
return data, nil
}
err := errors.New("no data in cache")
r.env.Log(environment.Error, "OAuth", err.Error())
r.env.Log(platform.Error, "OAuth", err.Error())
return data, err
}
func do[a any](r *Request, url string, body io.Reader, requestModifiers ...environment.HTTPRequestModifier) (a, error) {
func do[a any](r *Request, url string, body io.Reader, requestModifiers ...platform.HTTPRequestModifier) (a, error) {
var data a
httpTimeout := r.props.GetInt(properties.HTTPTimeout, properties.DefaultHTTPTimeout)
responseBody, err := r.env.HTTPRequest(url, body, httpTimeout, requestModifiers...)
if err != nil {
r.env.Log(environment.Error, "OAuth", err.Error())
r.env.Log(platform.Error, "OAuth", err.Error())
return data, err
}
err = json.Unmarshal(responseBody, &data)
if err != nil {
r.env.Log(environment.Error, "OAuth", err.Error())
r.env.Log(platform.Error, "OAuth", err.Error())
return data, err
}

View file

@ -2,8 +2,8 @@ package http
import (
"net"
"oh-my-posh/environment"
"oh-my-posh/mock"
"oh-my-posh/platform"
"oh-my-posh/properties"
"testing"
@ -75,7 +75,7 @@ func TestRequestResult(t *testing.T) {
env.On("Cache").Return(cache)
env.On("HTTPRequest", url).Return([]byte(tc.JSONResponse), tc.Error)
env.On("Log", environment.Error, "OAuth", mock2.Anything).Return()
env.On("Log", platform.Error, "OAuth", mock2.Anything).Return()
request := &Request{}
request.Init(env, props)

View file

@ -3,8 +3,8 @@ package mock
import (
"io"
"io/fs"
"oh-my-posh/environment"
"oh-my-posh/environment/battery"
"oh-my-posh/platform"
"oh-my-posh/platform/battery"
"time"
mock "github.com/stretchr/testify/mock"
@ -119,9 +119,9 @@ func (env *MockedEnvironment) Root() bool {
return args.Bool(0)
}
func (env *MockedEnvironment) Flags() *environment.Flags {
func (env *MockedEnvironment) Flags() *platform.Flags {
arguments := env.Called()
return arguments.Get(0).(*environment.Flags)
return arguments.Get(0).(*platform.Flags)
}
func (env *MockedEnvironment) BatteryState() (*battery.Info, error) {
@ -139,19 +139,19 @@ func (env *MockedEnvironment) QueryWindowTitles(processName, windowTitleRegex st
return args.String(0), args.Error(1)
}
func (env *MockedEnvironment) WindowsRegistryKeyValue(path string) (*environment.WindowsRegistryValue, error) {
func (env *MockedEnvironment) WindowsRegistryKeyValue(path string) (*platform.WindowsRegistryValue, error) {
args := env.Called(path)
return args.Get(0).(*environment.WindowsRegistryValue), args.Error(1)
return args.Get(0).(*platform.WindowsRegistryValue), args.Error(1)
}
func (env *MockedEnvironment) HTTPRequest(url string, body io.Reader, timeout int, requestModifiers ...environment.HTTPRequestModifier) ([]byte, error) {
func (env *MockedEnvironment) HTTPRequest(url string, body io.Reader, timeout int, requestModifiers ...platform.HTTPRequestModifier) ([]byte, error) {
args := env.Called(url)
return args.Get(0).([]byte), args.Error(1)
}
func (env *MockedEnvironment) HasParentFilePath(path string) (*environment.FileInfo, error) {
func (env *MockedEnvironment) HasParentFilePath(path string) (*platform.FileInfo, error) {
args := env.Called(path)
return args.Get(0).(*environment.FileInfo), args.Error(1)
return args.Get(0).(*platform.FileInfo), args.Error(1)
}
func (env *MockedEnvironment) StackCount() int {
@ -179,9 +179,9 @@ func (env *MockedEnvironment) CachePath() string {
return args.String(0)
}
func (env *MockedEnvironment) Cache() environment.Cache {
func (env *MockedEnvironment) Cache() platform.Cache {
args := env.Called()
return args.Get(0).(environment.Cache)
return args.Get(0).(platform.Cache)
}
func (env *MockedEnvironment) Close() {
@ -208,14 +208,14 @@ func (env *MockedEnvironment) ConvertToLinuxPath(path string) string {
return args.String(0)
}
func (env *MockedEnvironment) Connection(connectionType environment.ConnectionType) (*environment.Connection, error) {
func (env *MockedEnvironment) Connection(connectionType platform.ConnectionType) (*platform.Connection, error) {
args := env.Called(connectionType)
return args.Get(0).(*environment.Connection), args.Error(1)
return args.Get(0).(*platform.Connection), args.Error(1)
}
func (env *MockedEnvironment) TemplateCache() *environment.TemplateCache {
func (env *MockedEnvironment) TemplateCache() *platform.TemplateCache {
args := env.Called()
return args.Get(0).(*environment.TemplateCache)
return args.Get(0).(*platform.TemplateCache)
}
func (env *MockedEnvironment) LoadTemplateCache() {
@ -246,7 +246,7 @@ func (env *MockedEnvironment) Trace(start time.Time, function string, args ...st
_ = env.Called(start, function, args)
}
func (env *MockedEnvironment) Log(logType environment.LogType, funcName, message string) {
func (env *MockedEnvironment) Log(logType platform.LogType, funcName, message string) {
_ = env.Called(logType, funcName, message)
}

View file

@ -2,7 +2,7 @@ package battery
import (
"errors"
"oh-my-posh/environment/cmd"
"oh-my-posh/platform/cmd"
"oh-my-posh/regex"
"strconv"
"strings"

View file

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

View file

@ -1,4 +1,4 @@
package environment
package platform
type concurrentMap struct {
values map[string]interface{}

View file

@ -1,4 +1,4 @@
package environment
package platform
import (
"net/http"

View file

@ -1,4 +1,4 @@
package environment
package platform
import (
"bytes"
@ -11,8 +11,8 @@ import (
"log"
"net/http"
"net/http/httputil"
"oh-my-posh/environment/battery"
"oh-my-posh/environment/cmd"
"oh-my-posh/platform/battery"
"oh-my-posh/platform/cmd"
"oh-my-posh/regex"
"os"
"os/exec"
@ -220,7 +220,7 @@ const (
Debug LogType = "debug"
)
type ShellEnvironment struct {
type Shell struct {
CmdFlags *Flags
Version string
@ -232,7 +232,7 @@ type ShellEnvironment struct {
networks []*Connection
}
func (env *ShellEnvironment) Init() {
func (env *Shell) Init() {
defer env.Trace(time.Now(), "Init")
if env.CmdFlags == nil {
env.CmdFlags = &Flags{}
@ -248,7 +248,7 @@ func (env *ShellEnvironment) Init() {
}
}
func (env *ShellEnvironment) resolveConfigPath() {
func (env *Shell) resolveConfigPath() {
defer env.Trace(time.Now(), "resolveConfigPath")
if len(env.CmdFlags.Config) == 0 {
env.CmdFlags.Config = env.Getenv("POSH_THEME")
@ -279,7 +279,7 @@ func (env *ShellEnvironment) resolveConfigPath() {
env.CmdFlags.Config = filepath.Clean(configFile)
}
func (env *ShellEnvironment) downloadConfig(location string) error {
func (env *Shell) downloadConfig(location string) error {
defer env.Trace(time.Now(), "downloadConfig", location)
configPath := filepath.Join(env.CachePath(), "config.omp.json")
cfg, err := env.HTTPRequest(location, nil, 5000)
@ -299,7 +299,7 @@ func (env *ShellEnvironment) downloadConfig(location string) error {
return nil
}
func (env *ShellEnvironment) Trace(start time.Time, function string, args ...string) {
func (env *Shell) Trace(start time.Time, function string, args ...string) {
if env.CmdFlags == nil || !env.CmdFlags.Debug {
return
}
@ -308,7 +308,7 @@ func (env *ShellEnvironment) Trace(start time.Time, function string, args ...str
log.Println(trace)
}
func (env *ShellEnvironment) Log(logType LogType, funcName, message string) {
func (env *Shell) Log(logType LogType, funcName, message string) {
if !env.CmdFlags.Debug {
return
}
@ -316,7 +316,7 @@ func (env *ShellEnvironment) Log(logType LogType, funcName, message string) {
log.Println(trace)
}
func (env *ShellEnvironment) debugF(function string, fn func() string) {
func (env *Shell) debugF(function string, fn func() string) {
if !env.CmdFlags.Debug {
return
}
@ -324,14 +324,14 @@ func (env *ShellEnvironment) debugF(function string, fn func() string) {
log.Println(trace)
}
func (env *ShellEnvironment) Getenv(key string) string {
func (env *Shell) Getenv(key string) string {
defer env.Trace(time.Now(), "Getenv", key)
val := os.Getenv(key)
env.Log(Debug, "Getenv", val)
return val
}
func (env *ShellEnvironment) Pwd() string {
func (env *Shell) Pwd() string {
defer env.Trace(time.Now(), "Pwd")
lock.Lock()
defer func() {
@ -362,7 +362,7 @@ func (env *ShellEnvironment) Pwd() string {
return env.cwd
}
func (env *ShellEnvironment) HasFiles(pattern string) bool {
func (env *Shell) HasFiles(pattern string) bool {
defer env.Trace(time.Now(), "HasFiles", pattern)
cwd := env.Pwd()
fileSystem := os.DirFS(cwd)
@ -381,7 +381,7 @@ func (env *ShellEnvironment) HasFiles(pattern string) bool {
return false
}
func (env *ShellEnvironment) HasFilesInDir(dir, pattern string) bool {
func (env *Shell) HasFilesInDir(dir, pattern string) bool {
defer env.Trace(time.Now(), "HasFilesInDir", pattern)
fileSystem := os.DirFS(dir)
matches, err := fs.Glob(fileSystem, pattern)
@ -394,7 +394,7 @@ func (env *ShellEnvironment) HasFilesInDir(dir, pattern string) bool {
return hasFilesInDir
}
func (env *ShellEnvironment) HasFileInParentDirs(pattern string, depth uint) bool {
func (env *Shell) HasFileInParentDirs(pattern string, depth uint) bool {
defer env.Trace(time.Now(), "HasFileInParent", pattern, fmt.Sprint(depth))
currentFolder := env.Pwd()
@ -415,7 +415,7 @@ func (env *ShellEnvironment) HasFileInParentDirs(pattern string, depth uint) boo
return false
}
func (env *ShellEnvironment) HasFolder(folder string) bool {
func (env *Shell) HasFolder(folder string) bool {
defer env.Trace(time.Now(), "HasFolder", folder)
f, err := os.Stat(folder)
if err != nil {
@ -426,7 +426,7 @@ func (env *ShellEnvironment) HasFolder(folder string) bool {
return f.IsDir()
}
func (env *ShellEnvironment) ResolveSymlink(path string) (string, error) {
func (env *Shell) ResolveSymlink(path string) (string, error) {
defer env.Trace(time.Now(), "ResolveSymlink", path)
link, err := filepath.EvalSymlinks(path)
if err != nil {
@ -437,7 +437,7 @@ func (env *ShellEnvironment) ResolveSymlink(path string) (string, error) {
return link, nil
}
func (env *ShellEnvironment) FileContent(file string) string {
func (env *Shell) FileContent(file string) string {
defer env.Trace(time.Now(), "FileContent", file)
if !filepath.IsAbs(file) {
file = filepath.Join(env.Pwd(), file)
@ -452,7 +452,7 @@ func (env *ShellEnvironment) FileContent(file string) string {
return fileContent
}
func (env *ShellEnvironment) LsDir(path string) []fs.DirEntry {
func (env *Shell) LsDir(path string) []fs.DirEntry {
defer env.Trace(time.Now(), "LsDir", path)
entries, err := os.ReadDir(path)
if err != nil {
@ -469,12 +469,12 @@ func (env *ShellEnvironment) LsDir(path string) []fs.DirEntry {
return entries
}
func (env *ShellEnvironment) PathSeparator() string {
func (env *Shell) PathSeparator() string {
defer env.Trace(time.Now(), "PathSeparator")
return string(os.PathSeparator)
}
func (env *ShellEnvironment) User() string {
func (env *Shell) User() string {
defer env.Trace(time.Now(), "User")
user := os.Getenv("USER")
if user == "" {
@ -484,7 +484,7 @@ func (env *ShellEnvironment) User() string {
return user
}
func (env *ShellEnvironment) Host() (string, error) {
func (env *Shell) Host() (string, error) {
defer env.Trace(time.Now(), "Host")
hostName, err := os.Hostname()
if err != nil {
@ -496,12 +496,12 @@ func (env *ShellEnvironment) Host() (string, error) {
return hostName, nil
}
func (env *ShellEnvironment) GOOS() string {
func (env *Shell) GOOS() string {
defer env.Trace(time.Now(), "GOOS")
return runtime.GOOS
}
func (env *ShellEnvironment) RunCommand(command string, args ...string) (string, error) {
func (env *Shell) RunCommand(command string, args ...string) (string, error) {
defer env.Trace(time.Now(), "RunCommand", append([]string{command}, args...)...)
if cacheCommand, ok := env.cmdCache.get(command); ok {
command = cacheCommand
@ -514,7 +514,7 @@ func (env *ShellEnvironment) RunCommand(command string, args ...string) (string,
return output, err
}
func (env *ShellEnvironment) RunShellCommand(shell, command string) string {
func (env *Shell) RunShellCommand(shell, command string) string {
defer env.Trace(time.Now(), "RunShellCommand")
if out, err := env.RunCommand(shell, "-c", command); err == nil {
return out
@ -522,7 +522,7 @@ func (env *ShellEnvironment) RunShellCommand(shell, command string) string {
return ""
}
func (env *ShellEnvironment) CommandPath(command string) string {
func (env *Shell) CommandPath(command string) string {
defer env.Trace(time.Now(), "CommandPath", command)
if path, ok := env.cmdCache.get(command); ok {
env.Log(Debug, "CommandPath", path)
@ -544,7 +544,7 @@ func (env *ShellEnvironment) CommandPath(command string) string {
return ""
}
func (env *ShellEnvironment) HasCommand(command string) bool {
func (env *Shell) HasCommand(command string) bool {
defer env.Trace(time.Now(), "HasCommand", command)
if path := env.CommandPath(command); path != "" {
return true
@ -552,12 +552,12 @@ func (env *ShellEnvironment) HasCommand(command string) bool {
return false
}
func (env *ShellEnvironment) ErrorCode() int {
func (env *Shell) ErrorCode() int {
defer env.Trace(time.Now(), "ErrorCode")
return env.CmdFlags.ErrorCode
}
func (env *ShellEnvironment) ExecutionTime() float64 {
func (env *Shell) ExecutionTime() float64 {
defer env.Trace(time.Now(), "ExecutionTime")
if env.CmdFlags.ExecutionTime < 0 {
return 0
@ -565,12 +565,12 @@ func (env *ShellEnvironment) ExecutionTime() float64 {
return env.CmdFlags.ExecutionTime
}
func (env *ShellEnvironment) Flags() *Flags {
func (env *Shell) Flags() *Flags {
defer env.Trace(time.Now(), "Flags")
return env.CmdFlags
}
func (env *ShellEnvironment) Shell() string {
func (env *Shell) Shell() string {
defer env.Trace(time.Now(), "Shell")
if env.CmdFlags.Shell != "" {
return env.CmdFlags.Shell
@ -600,7 +600,7 @@ func (env *ShellEnvironment) Shell() string {
return env.CmdFlags.Shell
}
func (env *ShellEnvironment) unWrapError(err error) error {
func (env *Shell) unWrapError(err error) error {
cause := err
for {
type nested interface{ Unwrap() error }
@ -613,7 +613,7 @@ func (env *ShellEnvironment) unWrapError(err error) error {
return cause
}
func (env *ShellEnvironment) HTTPRequest(targetURL string, body io.Reader, timeout int, requestModifiers ...HTTPRequestModifier) ([]byte, error) {
func (env *Shell) HTTPRequest(targetURL string, body io.Reader, timeout int, requestModifiers ...HTTPRequestModifier) ([]byte, error) {
defer env.Trace(time.Now(), "HTTPRequest", targetURL)
ctx, cncl := context.WithTimeout(context.Background(), time.Millisecond*time.Duration(timeout))
defer cncl()
@ -650,7 +650,7 @@ func (env *ShellEnvironment) HTTPRequest(targetURL string, body io.Reader, timeo
return responseBody, nil
}
func (env *ShellEnvironment) HasParentFilePath(path string) (*FileInfo, error) {
func (env *Shell) HasParentFilePath(path string) (*FileInfo, error) {
defer env.Trace(time.Now(), "HasParentFilePath", path)
currentFolder := env.Pwd()
for {
@ -675,7 +675,7 @@ func (env *ShellEnvironment) HasParentFilePath(path string) (*FileInfo, error) {
}
}
func (env *ShellEnvironment) StackCount() int {
func (env *Shell) StackCount() int {
defer env.Trace(time.Now(), "StackCount")
if env.CmdFlags.StackCount < 0 {
return 0
@ -683,11 +683,11 @@ func (env *ShellEnvironment) StackCount() int {
return env.CmdFlags.StackCount
}
func (env *ShellEnvironment) Cache() Cache {
func (env *Shell) Cache() Cache {
return env.fileCache
}
func (env *ShellEnvironment) Close() {
func (env *Shell) Close() {
defer env.Trace(time.Now(), "Close")
templateCache, err := json.Marshal(env.TemplateCache())
if err == nil {
@ -696,7 +696,7 @@ func (env *ShellEnvironment) Close() {
env.fileCache.Close()
}
func (env *ShellEnvironment) LoadTemplateCache() {
func (env *Shell) LoadTemplateCache() {
defer env.Trace(time.Now(), "LoadTemplateCache")
val, OK := env.fileCache.Get(TEMPLATECACHE)
if !OK {
@ -711,11 +711,11 @@ func (env *ShellEnvironment) LoadTemplateCache() {
env.tmplCache = &templateCache
}
func (env *ShellEnvironment) Logs() string {
func (env *Shell) Logs() string {
return env.logBuilder.String()
}
func (env *ShellEnvironment) TemplateCache() *TemplateCache {
func (env *Shell) TemplateCache() *TemplateCache {
defer env.Trace(time.Now(), "TemplateCache")
if env.tmplCache != nil {
return env.tmplCache
@ -758,7 +758,7 @@ func (env *ShellEnvironment) TemplateCache() *TemplateCache {
return tmplCache
}
func (env *ShellEnvironment) DirMatchesOneOf(dir string, regexes []string) (match bool) {
func (env *Shell) DirMatchesOneOf(dir string, regexes []string) (match bool) {
lock.Lock()
defer lock.Unlock()
// sometimes the function panics inside golang, we want to silence that error

View file

@ -1,4 +1,4 @@
package environment
package platform
import (
"errors"
@ -7,7 +7,7 @@ import (
"strings"
"time"
"oh-my-posh/environment/battery"
"oh-my-posh/platform/battery"
)
func mapMostLogicalState(state string) battery.State {
@ -29,7 +29,7 @@ func mapMostLogicalState(state string) battery.State {
}
}
func (env *ShellEnvironment) parseBatteryOutput(output string) (*battery.Info, error) {
func (env *Shell) parseBatteryOutput(output string) (*battery.Info, error) {
matches := regex.FindNamedRegexMatch(`(?P<PERCENTAGE>[0-9]{1,3})%; (?P<STATE>[a-zA-Z\s]+);`, output)
if len(matches) != 2 {
msg := "Unable to find battery state based on output"
@ -48,7 +48,7 @@ func (env *ShellEnvironment) parseBatteryOutput(output string) (*battery.Info, e
}, nil
}
func (env *ShellEnvironment) BatteryState() (*battery.Info, error) {
func (env *Shell) BatteryState() (*battery.Info, error) {
defer env.Trace(time.Now(), "BatteryState")
output, err := env.RunCommand("pmset", "-g", "batt")
if err != nil {

View file

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

View file

@ -1,6 +1,6 @@
//go:build !windows
package environment
package platform
import (
"errors"
@ -13,20 +13,20 @@ import (
terminal "github.com/wayneashleyberry/terminal-dimensions"
)
func (env *ShellEnvironment) Root() bool {
func (env *Shell) Root() bool {
defer env.Trace(time.Now(), "Root")
return os.Geteuid() == 0
}
func (env *ShellEnvironment) Home() string {
func (env *Shell) Home() string {
return os.Getenv("HOME")
}
func (env *ShellEnvironment) QueryWindowTitles(processName, windowTitleRegex string) (string, error) {
func (env *Shell) QueryWindowTitles(processName, windowTitleRegex string) (string, error) {
return "", &NotImplemented{}
}
func (env *ShellEnvironment) IsWsl() bool {
func (env *Shell) IsWsl() bool {
defer env.Trace(time.Now(), "IsWsl")
// one way to check
// version := env.FileContent("/proc/version")
@ -35,7 +35,7 @@ func (env *ShellEnvironment) IsWsl() bool {
return env.Getenv("WSL_DISTRO_NAME") != ""
}
func (env *ShellEnvironment) IsWsl2() bool {
func (env *Shell) IsWsl2() bool {
defer env.Trace(time.Now(), "IsWsl2")
if !env.IsWsl() {
return false
@ -44,7 +44,7 @@ func (env *ShellEnvironment) IsWsl2() bool {
return strings.Contains(uname, "WSL2")
}
func (env *ShellEnvironment) TerminalWidth() (int, error) {
func (env *Shell) TerminalWidth() (int, error) {
defer env.Trace(time.Now(), "TerminalWidth")
if env.CmdFlags.TerminalWidth != 0 {
return env.CmdFlags.TerminalWidth, nil
@ -56,7 +56,7 @@ func (env *ShellEnvironment) TerminalWidth() (int, error) {
return int(width), err
}
func (env *ShellEnvironment) Platform() string {
func (env *Shell) Platform() string {
const key = "environment_platform"
if val, found := env.Cache().Get(key); found {
return val
@ -80,7 +80,7 @@ func (env *ShellEnvironment) Platform() string {
return platform
}
func (env *ShellEnvironment) CachePath() string {
func (env *Shell) CachePath() string {
defer env.Trace(time.Now(), "CachePath")
// get XDG_CACHE_HOME if present
if cachePath := returnOrBuildCachePath(env.Getenv("XDG_CACHE_HOME")); len(cachePath) != 0 {
@ -93,11 +93,11 @@ func (env *ShellEnvironment) CachePath() string {
return env.Home()
}
func (env *ShellEnvironment) WindowsRegistryKeyValue(path string) (*WindowsRegistryValue, error) {
func (env *Shell) WindowsRegistryKeyValue(path string) (*WindowsRegistryValue, error) {
return nil, &NotImplemented{}
}
func (env *ShellEnvironment) InWSLSharedDrive() bool {
func (env *Shell) InWSLSharedDrive() bool {
if !env.IsWsl2() {
return false
}
@ -105,7 +105,7 @@ func (env *ShellEnvironment) InWSLSharedDrive() bool {
return !strings.HasPrefix(windowsPath, `//wsl.localhost/`) && !strings.HasPrefix(windowsPath, `//wsl$/`)
}
func (env *ShellEnvironment) ConvertToWindowsPath(path string) string {
func (env *Shell) ConvertToWindowsPath(path string) string {
windowsPath, err := env.RunCommand("wslpath", "-m", path)
if err == nil {
return windowsPath
@ -113,18 +113,18 @@ func (env *ShellEnvironment) ConvertToWindowsPath(path string) string {
return path
}
func (env *ShellEnvironment) ConvertToLinuxPath(path string) string {
func (env *Shell) ConvertToLinuxPath(path string) string {
if linuxPath, err := env.RunCommand("wslpath", "-u", path); err == nil {
return linuxPath
}
return path
}
func (env *ShellEnvironment) LookWinAppPath(file string) (string, error) {
func (env *Shell) LookWinAppPath(file string) (string, error) {
return "", errors.New("not relevant")
}
func (env *ShellEnvironment) DirIsWritable(path string) bool {
func (env *Shell) DirIsWritable(path string) bool {
defer env.Trace(time.Now(), "DirIsWritable", path)
info, err := os.Stat(path)
if err != nil {
@ -157,7 +157,7 @@ func (env *ShellEnvironment) DirIsWritable(path string) bool {
return true
}
func (env *ShellEnvironment) Connection(connectionType ConnectionType) (*Connection, error) {
func (env *Shell) Connection(connectionType ConnectionType) (*Connection, error) {
// added to disable the linting error, we can implement this later
if len(env.networks) == 0 {
return nil, &NotImplemented{}

View file

@ -1,4 +1,4 @@
package environment
package platform
import (
"errors"
@ -14,7 +14,7 @@ import (
"golang.org/x/sys/windows/registry"
)
func (env *ShellEnvironment) Root() bool {
func (env *Shell) Root() bool {
defer env.Trace(time.Now(), "Root")
var sid *windows.SID
@ -51,7 +51,7 @@ func (env *ShellEnvironment) Root() bool {
return member
}
func (env *ShellEnvironment) Home() string {
func (env *Shell) Home() string {
home := os.Getenv("HOME")
defer func() {
env.Log(Debug, "Home", home)
@ -67,7 +67,7 @@ func (env *ShellEnvironment) Home() string {
return home
}
func (env *ShellEnvironment) QueryWindowTitles(processName, windowTitleRegex string) (string, error) {
func (env *Shell) QueryWindowTitles(processName, windowTitleRegex string) (string, error) {
defer env.Trace(time.Now(), "WindowTitle", windowTitleRegex)
title, err := queryWindowTitles(processName, windowTitleRegex)
if err != nil {
@ -76,17 +76,17 @@ func (env *ShellEnvironment) QueryWindowTitles(processName, windowTitleRegex str
return title, err
}
func (env *ShellEnvironment) IsWsl() bool {
func (env *Shell) IsWsl() bool {
defer env.Trace(time.Now(), "IsWsl")
return false
}
func (env *ShellEnvironment) IsWsl2() bool {
func (env *Shell) IsWsl2() bool {
defer env.Trace(time.Now(), "IsWsl2")
return false
}
func (env *ShellEnvironment) TerminalWidth() (int, error) {
func (env *Shell) TerminalWidth() (int, error) {
defer env.Trace(time.Now(), "TerminalWidth")
if env.CmdFlags.TerminalWidth != 0 {
return env.CmdFlags.TerminalWidth, nil
@ -105,11 +105,11 @@ func (env *ShellEnvironment) TerminalWidth() (int, error) {
return int(info.Size.X), nil
}
func (env *ShellEnvironment) Platform() string {
func (env *Shell) Platform() string {
return WINDOWS
}
func (env *ShellEnvironment) CachePath() string {
func (env *Shell) CachePath() string {
defer env.Trace(time.Now(), "CachePath")
// get LOCALAPPDATA if present
if cachePath := returnOrBuildCachePath(env.Getenv("LOCALAPPDATA")); len(cachePath) != 0 {
@ -118,7 +118,7 @@ func (env *ShellEnvironment) CachePath() string {
return env.Home()
}
func (env *ShellEnvironment) LookWinAppPath(file string) (string, error) {
func (env *Shell) LookWinAppPath(file string) (string, error) {
winAppPath := filepath.Join(env.Getenv("LOCALAPPDATA"), `\Microsoft\WindowsApps\`)
command := file + ".exe"
isWinStoreApp := func() bool {
@ -140,7 +140,7 @@ func (env *ShellEnvironment) LookWinAppPath(file string) (string, error) {
// If the path ends in "\", the "(Default)" key in that path is retrieved.
//
// Returns a variant type if successful; nil and an error if not.
func (env *ShellEnvironment) WindowsRegistryKeyValue(path string) (*WindowsRegistryValue, error) {
func (env *Shell) WindowsRegistryKeyValue(path string) (*WindowsRegistryValue, error) {
env.Trace(time.Now(), "WindowsRegistryKeyValue", path)
// Format:
@ -221,19 +221,19 @@ func (env *ShellEnvironment) WindowsRegistryKeyValue(path string) (*WindowsRegis
return regValue, nil
}
func (env *ShellEnvironment) InWSLSharedDrive() bool {
func (env *Shell) InWSLSharedDrive() bool {
return false
}
func (env *ShellEnvironment) ConvertToWindowsPath(path string) string {
func (env *Shell) ConvertToWindowsPath(path string) string {
return strings.ReplaceAll(path, `\`, "/")
}
func (env *ShellEnvironment) ConvertToLinuxPath(path string) string {
func (env *Shell) ConvertToLinuxPath(path string) string {
return path
}
func (env *ShellEnvironment) DirIsWritable(path string) bool {
func (env *Shell) DirIsWritable(path string) bool {
defer env.Trace(time.Now(), "DirIsWritable")
info, err := os.Stat(path)
if err != nil {
@ -255,7 +255,7 @@ func (env *ShellEnvironment) DirIsWritable(path string) bool {
return true
}
func (env *ShellEnvironment) Connection(connectionType ConnectionType) (*Connection, error) {
func (env *Shell) Connection(connectionType ConnectionType) (*Connection, error) {
if env.networks == nil {
networks := env.getConnections()
if len(networks) == 0 {

View file

@ -1,13 +1,13 @@
//go:build !darwin
package environment
package platform
import (
"oh-my-posh/environment/battery"
"oh-my-posh/platform/battery"
"time"
)
func (env *ShellEnvironment) BatteryState() (*battery.Info, error) {
func (env *Shell) BatteryState() (*battery.Info, error) {
defer env.Trace(time.Now(), "BatteryState")
info, err := battery.Get()
if err != nil {

View file

@ -1,6 +1,6 @@
//go:build windows
package environment
package platform
import (
"errors"
@ -199,7 +199,7 @@ func readWinAppLink(path string) (string, error) {
// networks
func (env *ShellEnvironment) getConnections() []*Connection {
func (env *Shell) getConnections() []*Connection {
var pIFTable2 *MIN_IF_TABLE2
_, _, _ = hGetIfTable2.Call(uintptr(unsafe.Pointer(&pIFTable2)))
@ -327,7 +327,7 @@ var (
hWlanQueryInterface = wlanapi.NewProc("WlanQueryInterface")
)
func (env *ShellEnvironment) getWiFiSSID(guid windows.GUID) string {
func (env *Shell) getWiFiSSID(guid windows.GUID) string {
// Query wifi connection state
var pdwNegotiatedVersion uint32
var phClientHandle uint32

View file

@ -1,7 +1,7 @@
package segments
import (
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/properties"
"path/filepath"
)
@ -14,7 +14,7 @@ func (a *Angular) Template() string {
return languageTemplate
}
func (a *Angular) Init(props properties.Properties, env environment.Environment) {
func (a *Angular) Init(props properties.Properties, env platform.Environment) {
a.language = language{
env: env,
props: props,

View file

@ -2,14 +2,14 @@ package segments
import (
"fmt"
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/properties"
"strings"
)
type Aws struct {
props properties.Properties
env environment.Environment
env platform.Environment
Profile string
Region string
@ -23,7 +23,7 @@ func (a *Aws) Template() string {
return " {{ .Profile }}{{ if .Region }}@{{ .Region }}{{ end }} "
}
func (a *Aws) Init(props properties.Properties, env environment.Environment) {
func (a *Aws) Init(props properties.Properties, env platform.Environment) {
a.props = props
a.env = env
}

View file

@ -3,7 +3,7 @@ package segments
import (
"encoding/json"
"errors"
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/properties"
"path/filepath"
"strings"
@ -11,7 +11,7 @@ import (
type Az struct {
props properties.Properties
env environment.Environment
env platform.Environment
AzureSubscription
Origin string
@ -73,7 +73,7 @@ func (a *Az) Template() string {
return " {{ .Name }} "
}
func (a *Az) Init(props properties.Properties, env environment.Environment) {
func (a *Az) Init(props properties.Properties, env platform.Environment) {
a.props = props
a.env = env
}

View file

@ -1,7 +1,7 @@
package segments
import (
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/properties"
)
@ -13,7 +13,7 @@ func (az *AzFunc) Template() string {
return languageTemplate
}
func (az *AzFunc) Init(props properties.Properties, env environment.Environment) {
func (az *AzFunc) Init(props properties.Properties, env platform.Environment) {
az.language = language{
env: env,
props: props,

View file

@ -1,8 +1,8 @@
package segments
import (
"oh-my-posh/environment"
"oh-my-posh/mock"
"oh-my-posh/platform"
"oh-my-posh/properties"
"oh-my-posh/template"
"os"
@ -122,7 +122,7 @@ func TestAzSegment(t *testing.T) {
azureRmContext = string(content)
}
env.On("GOOS").Return(environment.LINUX)
env.On("GOOS").Return(platform.LINUX)
env.On("FileContent", filepath.Join(home, ".azure", "azureProfile.json")).Return(azureProfile)
env.On("Getenv", "POSH_AZURE_SUBSCRIPTION").Return(azureRmContext)
env.On("Getenv", "AZURE_CONFIG_DIR").Return("")

View file

@ -1,14 +1,14 @@
package segments
import (
"oh-my-posh/environment"
"oh-my-posh/environment/battery"
"oh-my-posh/platform"
"oh-my-posh/platform/battery"
"oh-my-posh/properties"
)
type Battery struct {
props properties.Properties
env environment.Environment
env platform.Environment
*battery.Info
Error string
@ -84,7 +84,7 @@ func (b *Battery) enabledWhileError(err error) bool {
return true
}
func (b *Battery) Init(props properties.Properties, env environment.Environment) {
func (b *Battery) Init(props properties.Properties, env platform.Environment) {
b.props = props
b.env = env
}

View file

@ -7,7 +7,7 @@ import (
"fmt"
"math"
"net/http"
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/properties"
"sort"
"time"
@ -16,7 +16,7 @@ import (
// segment struct, makes templating easier
type Brewfather struct {
props properties.Properties
env environment.Environment
env platform.Environment
Batch
TemperatureTrendIcon string
@ -322,7 +322,7 @@ func (bf *Brewfather) SGToPlato(sg float64) float64 {
return math.Round(100*((135.997*sg*sg*sg)-(630.272*sg*sg)+(1111.14*sg)-616.868)) / 100 // 2 decimal places
}
func (bf *Brewfather) Init(props properties.Properties, env environment.Environment) {
func (bf *Brewfather) Init(props properties.Properties, env platform.Environment) {
bf.props = props
bf.env = env
}

View file

@ -2,7 +2,7 @@ package segments
import (
"encoding/json"
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/properties"
)
@ -15,7 +15,7 @@ func (c *Cds) Template() string {
return languageTemplate
}
func (c *Cds) Init(props properties.Properties, env environment.Environment) {
func (c *Cds) Init(props properties.Properties, env platform.Environment) {
c.language = language{
env: env,
props: props,

View file

@ -2,8 +2,8 @@ package segments
import (
"fmt"
"oh-my-posh/environment"
"oh-my-posh/mock"
"oh-my-posh/platform"
"oh-my-posh/properties"
"path/filepath"
"testing"
@ -115,7 +115,7 @@ func TestCdsSegment(t *testing.T) {
"display_mode": tc.DisplayMode,
}
env.On("TemplateCache").Return(&environment.TemplateCache{
env.On("TemplateCache").Return(&platform.TemplateCache{
Env: make(map[string]string),
})

View file

@ -1,7 +1,7 @@
package segments
import (
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/properties"
)
@ -13,7 +13,7 @@ func (c *Cf) Template() string {
return languageTemplate
}
func (c *Cf) Init(props properties.Properties, env environment.Environment) {
func (c *Cf) Init(props properties.Properties, env platform.Environment) {
c.language = language{
env: env,
props: props,

View file

@ -1,14 +1,14 @@
package segments
import (
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/properties"
"regexp"
)
type CfTarget struct {
props properties.Properties
env environment.Environment
env platform.Environment
CfTargetDetails
}
@ -24,7 +24,7 @@ func (c *CfTarget) Template() string {
return "{{if .Org }}{{ .Org }}{{ end }}{{if .Space }}/{{ .Space }}{{ end }}"
}
func (c *CfTarget) Init(props properties.Properties, env environment.Environment) {
func (c *CfTarget) Init(props properties.Properties, env platform.Environment) {
c.props = props
c.env = env
}

View file

@ -2,8 +2,8 @@ package segments
import (
"fmt"
"oh-my-posh/environment"
"oh-my-posh/mock"
"oh-my-posh/platform"
"oh-my-posh/properties"
"path/filepath"
"testing"
@ -63,7 +63,7 @@ func TestCFSegment(t *testing.T) {
env.On("Pwd").Return("/usr/home/dev/my-app")
env.On("Home").Return("/usr/home")
env.On("TemplateCache").Return(&environment.TemplateCache{
env.On("TemplateCache").Return(&platform.TemplateCache{
Env: make(map[string]string),
})

View file

@ -1,7 +1,7 @@
package segments
import (
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/properties"
)
@ -13,7 +13,7 @@ func (c *Cmake) Template() string {
return languageTemplate
}
func (c *Cmake) Init(props properties.Properties, env environment.Environment) {
func (c *Cmake) Init(props properties.Properties, env platform.Environment) {
c.language = language{
env: env,
props: props,

View file

@ -1,14 +1,14 @@
package segments
import (
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/properties"
"strings"
)
type Cmd struct {
props properties.Properties
env environment.Environment
env platform.Environment
Output string
}
@ -71,7 +71,7 @@ func (c *Cmd) runScript(shell, script string) bool {
return len(c.Output) != 0
}
func (c *Cmd) Init(props properties.Properties, env environment.Environment) {
func (c *Cmd) Init(props properties.Properties, env platform.Environment) {
c.props = props
c.env = env
}

View file

@ -1,16 +1,16 @@
package segments
import (
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/properties"
"strings"
)
type Connection struct {
props properties.Properties
env environment.Environment
env platform.Environment
environment.Connection
platform.Connection
}
const (
@ -25,7 +25,7 @@ func (c *Connection) Enabled() bool {
types := c.props.GetString(Type, "wifi|ethernet")
connectionTypes := strings.Split(types, "|")
for _, connectionType := range connectionTypes {
network, err := c.env.Connection(environment.ConnectionType(connectionType))
network, err := c.env.Connection(platform.ConnectionType(connectionType))
if err != nil {
continue
}
@ -35,7 +35,7 @@ func (c *Connection) Enabled() bool {
return false
}
func (c *Connection) Init(props properties.Properties, env environment.Environment) {
func (c *Connection) Init(props properties.Properties, env platform.Environment) {
c.props = props
c.env = env
}

View file

@ -2,8 +2,8 @@ package segments
import (
"fmt"
"oh-my-posh/environment"
"oh-my-posh/mock"
"oh-my-posh/platform"
"oh-my-posh/properties"
"testing"
@ -12,7 +12,7 @@ import (
func TestConnection(t *testing.T) {
type connectionResponse struct {
Connection *environment.Connection
Connection *platform.Connection
Error error
}
cases := []struct {
@ -29,7 +29,7 @@ func TestConnection(t *testing.T) {
ConnectionType: "wifi",
Connections: []*connectionResponse{
{
Connection: &environment.Connection{
Connection: &platform.Connection{
Name: "WiFi",
Type: "wifi",
},
@ -41,8 +41,8 @@ func TestConnection(t *testing.T) {
ConnectionType: "wifi",
Connections: []*connectionResponse{
{
Connection: &environment.Connection{
Type: environment.WIFI,
Connection: &platform.Connection{
Type: platform.WIFI,
},
Error: fmt.Errorf("no connection"),
},
@ -55,14 +55,14 @@ func TestConnection(t *testing.T) {
ExpectedEnabled: true,
Connections: []*connectionResponse{
{
Connection: &environment.Connection{
Type: environment.WIFI,
Connection: &platform.Connection{
Type: platform.WIFI,
},
Error: fmt.Errorf("no connection"),
},
{
Connection: &environment.Connection{
Type: environment.ETHERNET,
Connection: &platform.Connection{
Type: platform.ETHERNET,
},
},
},
@ -72,14 +72,14 @@ func TestConnection(t *testing.T) {
ConnectionType: "wifi|ethernet",
Connections: []*connectionResponse{
{
Connection: &environment.Connection{
Type: environment.WIFI,
Connection: &platform.Connection{
Type: platform.WIFI,
},
Error: fmt.Errorf("no connection"),
},
{
Connection: &environment.Connection{
Type: environment.ETHERNET,
Connection: &platform.Connection{
Type: platform.ETHERNET,
},
Error: fmt.Errorf("no connection"),
},

View file

@ -1,7 +1,7 @@
package segments
import (
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/properties"
)
@ -13,7 +13,7 @@ func (c *Crystal) Template() string {
return languageTemplate
}
func (c *Crystal) Init(props properties.Properties, env environment.Environment) {
func (c *Crystal) Init(props properties.Properties, env platform.Environment) {
c.language = language{
env: env,
props: props,

View file

@ -1,7 +1,7 @@
package segments
import (
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/properties"
)
@ -18,7 +18,7 @@ func (d *Dart) Template() string {
return languageTemplate
}
func (d *Dart) Init(props properties.Properties, env environment.Environment) {
func (d *Dart) Init(props properties.Properties, env platform.Environment) {
d.language = language{
env: env,
props: props,

View file

@ -1,7 +1,7 @@
package segments
import (
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/properties"
)
@ -13,7 +13,7 @@ func (d *Deno) Template() string {
return languageTemplate
}
func (d *Deno) Init(props properties.Properties, env environment.Environment) {
func (d *Deno) Init(props properties.Properties, env platform.Environment) {
d.language = language{
env: env,
props: props,

View file

@ -2,7 +2,7 @@ package segments
import (
"oh-my-posh/constants"
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/properties"
)
@ -16,7 +16,7 @@ func (d *Dotnet) Template() string {
return " {{ if .Unsupported }}\uf071{{ else }}{{ .Full }}{{ end }} "
}
func (d *Dotnet) Init(props properties.Properties, env environment.Environment) {
func (d *Dotnet) Init(props properties.Properties, env platform.Environment) {
d.language = language{
env: env,
props: props,

View file

@ -2,8 +2,8 @@ package segments
import (
"oh-my-posh/constants"
"oh-my-posh/environment"
"oh-my-posh/mock"
"oh-my-posh/platform"
"oh-my-posh/properties"
"testing"
@ -29,7 +29,7 @@ func TestDotnetSegment(t *testing.T) {
env := new(mock.MockedEnvironment)
env.On("HasCommand", "dotnet").Return(tc.HasCommand)
if tc.ExitCode != 0 {
err := &environment.CommandError{ExitCode: tc.ExitCode}
err := &platform.CommandError{ExitCode: tc.ExitCode}
env.On("RunCommand", "dotnet", []string{"--version"}).Return("", err)
} else {
env.On("RunCommand", "dotnet", []string{"--version"}).Return(tc.Version, nil)
@ -39,7 +39,7 @@ func TestDotnetSegment(t *testing.T) {
env.On("PathSeparator").Return("")
env.On("Pwd").Return("/usr/home/project")
env.On("Home").Return("/usr/home")
env.On("TemplateCache").Return(&environment.TemplateCache{
env.On("TemplateCache").Return(&platform.TemplateCache{
Env: make(map[string]string),
})
props := properties.Map{

View file

@ -2,7 +2,7 @@ package segments
import (
"fmt"
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/properties"
"strconv"
@ -12,7 +12,7 @@ import (
type Executiontime struct {
props properties.Properties
env environment.Environment
env platform.Environment
FormattedMs string
Ms int64
@ -67,7 +67,7 @@ func (t *Executiontime) Template() string {
return " {{ .FormattedMs }} "
}
func (t *Executiontime) Init(props properties.Properties, env environment.Environment) {
func (t *Executiontime) Init(props properties.Properties, env platform.Environment) {
t.props = props
t.env = env
}

View file

@ -1,14 +1,14 @@
package segments
import (
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/properties"
"strconv"
)
type Exit struct {
props properties.Properties
env environment.Environment
env platform.Environment
Meaning string
}
@ -25,7 +25,7 @@ func (e *Exit) Enabled() bool {
return e.env.ErrorCode() != 0
}
func (e *Exit) Init(props properties.Properties, env environment.Environment) {
func (e *Exit) Init(props properties.Properties, env platform.Environment) {
e.props = props
e.env = env
}

View file

@ -1,8 +1,8 @@
package segments
import (
"oh-my-posh/environment"
"oh-my-posh/mock"
"oh-my-posh/platform"
"oh-my-posh/properties"
"testing"
@ -79,7 +79,7 @@ func TestExitWriterTemplateString(t *testing.T) {
for _, tc := range cases {
env := new(mock.MockedEnvironment)
env.On("ErrorCode").Return(tc.ExitCode)
env.On("TemplateCache").Return(&environment.TemplateCache{
env.On("TemplateCache").Return(&platform.TemplateCache{
Code: tc.ExitCode,
})
e := &Exit{

View file

@ -1,7 +1,7 @@
package segments
import (
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/properties"
)
@ -13,7 +13,7 @@ func (f *Flutter) Template() string {
return languageTemplate
}
func (f *Flutter) Init(props properties.Properties, env environment.Environment) {
func (f *Flutter) Init(props properties.Properties, env platform.Environment) {
f.language = language{
env: env,
props: props,

View file

@ -2,7 +2,7 @@ package segments
import (
"errors"
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/properties"
"path"
@ -15,7 +15,7 @@ const (
type Gcp struct {
props properties.Properties
env environment.Environment
env platform.Environment
Account string
Project string
@ -26,7 +26,7 @@ func (g *Gcp) Template() string {
return " {{ .Project }} "
}
func (g *Gcp) Init(props properties.Properties, env environment.Environment) {
func (g *Gcp) Init(props properties.Properties, env platform.Environment) {
g.props = props
g.env = env
}
@ -35,7 +35,7 @@ func (g *Gcp) Enabled() bool {
cfgDir := g.getConfigDirectory()
configFile, err := g.getActiveConfig(cfgDir)
if err != nil {
g.env.Log(environment.Error, "Gcp.Enabled()", err.Error())
g.env.Log(platform.Error, "Gcp.Enabled()", err.Error())
return false
}
@ -43,13 +43,13 @@ func (g *Gcp) Enabled() bool {
cfg := g.env.FileContent(cfgpath)
if len(cfg) == 0 {
g.env.Log(environment.Error, "Gcp.Enabled()", "config file is empty")
g.env.Log(platform.Error, "Gcp.Enabled()", "config file is empty")
return false
}
data, err := ini.Load([]byte(cfg))
if err != nil {
g.env.Log(environment.Error, "Gcp.Enabled()", err.Error())
g.env.Log(platform.Error, "Gcp.Enabled()", err.Error())
return false
}
@ -74,7 +74,7 @@ func (g *Gcp) getConfigDirectory() string {
if len(cfgDir) != 0 {
return cfgDir
}
if g.env.GOOS() == environment.WINDOWS {
if g.env.GOOS() == platform.WINDOWS {
return path.Join(g.env.Getenv("APPDATA"), "gcloud")
}
return path.Join(g.env.Home(), ".config", "gcloud")

View file

@ -4,8 +4,8 @@ import (
"path"
"testing"
"oh-my-posh/environment"
"oh-my-posh/mock"
"oh-my-posh/platform"
"github.com/stretchr/testify/assert"
mock2 "github.com/stretchr/testify/mock"
@ -57,7 +57,7 @@ func TestGcpSegment(t *testing.T) {
env.On("FileContent", fcPath).Return(tc.ActiveConfig)
cfgpath := path.Join("config", "configurations", "config_production")
env.On("FileContent", cfgpath).Return(tc.CfgData)
env.On("Log", environment.Error, "Gcp.Enabled()", mock2.Anything).Return()
env.On("Log", platform.Error, "Gcp.Enabled()", mock2.Anything).Return()
g := &Gcp{
env: env,
}
@ -84,7 +84,7 @@ func TestGetConfigDirectory(t *testing.T) {
},
{
Case: "Windows",
GOOS: environment.WINDOWS,
GOOS: platform.WINDOWS,
AppData: "/Users/posh/.config",
Expected: "/Users/posh/.config/gcloud",
},

View file

@ -3,7 +3,7 @@ package segments
import (
"fmt"
url2 "net/url"
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/properties"
"oh-my-posh/regex"
"path/filepath"
@ -127,7 +127,7 @@ func (g *Git) Enabled() bool {
return false
}
g.RepoName = environment.Base(g.env, g.convertToLinuxPath(g.realDir))
g.RepoName = platform.Base(g.env, g.convertToLinuxPath(g.realDir))
if g.IsBare {
g.getBareRepoInfo()
@ -227,15 +227,15 @@ func (g *Git) getBareRepoInfo() {
}
func (g *Git) setDir(dir string) {
dir = environment.ReplaceHomeDirPrefixWithTilde(g.env, dir) // align with template PWD
if g.env.GOOS() == environment.WINDOWS {
dir = platform.ReplaceHomeDirPrefixWithTilde(g.env, dir) // align with template PWD
if g.env.GOOS() == platform.WINDOWS {
g.Dir = strings.TrimSuffix(dir, `\.git`)
return
}
g.Dir = strings.TrimSuffix(dir, "/.git")
}
func (g *Git) hasWorktree(gitdir *environment.FileInfo) bool {
func (g *Git) hasWorktree(gitdir *platform.FileInfo) bool {
g.rootDir = gitdir.Path
dirPointer := strings.Trim(g.env.FileContent(gitdir.Path), " \r\n")
matches := regex.FindNamedRegexMatch(`^gitdir: (?P<dir>.*)$`, dirPointer)

View file

@ -3,8 +3,8 @@ package segments
import (
"errors"
"fmt"
"oh-my-posh/environment"
"oh-my-posh/mock"
"oh-my-posh/platform"
"oh-my-posh/properties"
"os"
"path/filepath"
@ -34,7 +34,7 @@ func TestEnabledGitNotFound(t *testing.T) {
}
func TestEnabledInWorkingDirectory(t *testing.T) {
fileInfo := &environment.FileInfo{
fileInfo := &platform.FileInfo{
Path: "/dir/hello",
ParentFolder: "/dir",
IsDir: true,
@ -121,7 +121,7 @@ func TestEnabledInWorktree(t *testing.T) {
ExpectedRootFolder: TestRootPath + "dev/separate/.git/posh",
},
}
fileInfo := &environment.FileInfo{
fileInfo := &platform.FileInfo{
Path: TestRootPath + "dev/.git",
ParentFolder: TestRootPath + "dev",
}
@ -186,7 +186,7 @@ func TestEnabledInBareRepo(t *testing.T) {
env.On("InWSLSharedDrive").Return(false)
env.On("GOOS").Return("")
env.On("HasCommand", "git").Return(true)
env.On("HasParentFilePath", ".git").Return(&environment.FileInfo{}, errors.New("nope"))
env.On("HasParentFilePath", ".git").Return(&platform.FileInfo{}, errors.New("nope"))
env.MockGitCommand(pwd, tc.IsBare, "rev-parse", "--is-bare-repository")
env.On("Pwd").Return(pwd)
env.On("FileContent", "/home/user/bare.git/HEAD").Return(tc.HEAD)

View file

@ -1,7 +1,7 @@
package segments
import (
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/properties"
"golang.org/x/mod/modfile"
@ -19,7 +19,7 @@ func (g *Golang) Template() string {
return languageTemplate
}
func (g *Golang) Init(props properties.Properties, env environment.Environment) {
func (g *Golang) Init(props properties.Properties, env platform.Environment) {
g.language = language{
env: env,
props: props,

View file

@ -3,8 +3,8 @@ package segments
import (
"errors"
"fmt"
"oh-my-posh/environment"
"oh-my-posh/mock"
"oh-my-posh/platform"
"oh-my-posh/properties"
"os"
"testing"
@ -26,7 +26,7 @@ func getMockedLanguageEnv(params *mockedLanguageParams) (*mock.MockedEnvironment
env.On("HasFiles", params.extension).Return(true)
env.On("Pwd").Return("/usr/home/project")
env.On("Home").Return("/usr/home")
env.On("TemplateCache").Return(&environment.TemplateCache{
env.On("TemplateCache").Return(&platform.TemplateCache{
Env: make(map[string]string),
})
props := properties.Map{
@ -67,7 +67,7 @@ func TestGolang(t *testing.T) {
env, props := getMockedLanguageEnv(params)
if tc.ParseModFile {
props[ParseModFile] = tc.ParseModFile
fileInfo := &environment.FileInfo{
fileInfo := &platform.FileInfo{
Path: "../go.mod",
ParentFolder: "./",
IsDir: false,

View file

@ -1,7 +1,7 @@
package segments
import (
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/properties"
)
@ -19,7 +19,7 @@ func (h *Haskell) Template() string {
return languageTemplate
}
func (h *Haskell) Init(props properties.Properties, env environment.Environment) {
func (h *Haskell) Init(props properties.Properties, env platform.Environment) {
ghcRegex := `(?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+).(?P<patch>[0-9]+)))`
ghcCmd := &cmd{
executable: "ghc",

View file

@ -3,8 +3,8 @@ package segments
import (
"errors"
"fmt"
"oh-my-posh/environment"
"oh-my-posh/mock"
"oh-my-posh/platform"
"oh-my-posh/properties"
"testing"
@ -63,7 +63,7 @@ func TestHaskell(t *testing.T) {
env.On("HasCommand", "ghc").Return(true)
env.On("RunCommand", "ghc", []string{"--numeric-version"}).Return(tc.GhcVersion, nil)
}
fileInfo := &environment.FileInfo{
fileInfo := &platform.FileInfo{
Path: "../stack.yaml",
ParentFolder: "./",
IsDir: false,
@ -77,7 +77,7 @@ func TestHaskell(t *testing.T) {
env.On("HasFiles", "*.hs").Return(true)
env.On("Pwd").Return("/usr/home/project")
env.On("Home").Return("/usr/home")
env.On("TemplateCache").Return(&environment.TemplateCache{
env.On("TemplateCache").Return(&platform.TemplateCache{
Env: make(map[string]string),
})

View file

@ -2,8 +2,8 @@ package segments
import (
"net"
"oh-my-posh/environment"
"oh-my-posh/http"
"oh-my-posh/platform"
"oh-my-posh/properties"
)
@ -61,7 +61,7 @@ func (i *IPify) getResult() (string, error) {
return data.IP, err
}
func (i *IPify) Init(props properties.Properties, env environment.Environment) {
func (i *IPify) Init(props properties.Properties, env platform.Environment) {
request := &http.Request{}
request.Init(env, props)

View file

@ -2,13 +2,13 @@ package segments
import (
"errors"
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/properties"
)
type ITerm struct {
props properties.Properties
env environment.Environment
env platform.Environment
PromptMark string
}
@ -54,7 +54,7 @@ func (i *ITerm) getResult() (string, error) {
return response, nil
}
func (i *ITerm) Init(props properties.Properties, env environment.Environment) {
func (i *ITerm) Init(props properties.Properties, env platform.Environment) {
i.props = props
i.env = env
}

View file

@ -2,7 +2,7 @@ package segments
import (
"fmt"
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/properties"
)
@ -14,7 +14,7 @@ func (j *Java) Template() string {
return languageTemplate
}
func (j *Java) Init(props properties.Properties, env environment.Environment) {
func (j *Java) Init(props properties.Properties, env platform.Environment) {
javaRegex := `(?: JRE)(?: \(.*\))? \((?P<version>(?P<major>[0-9]+)(?:\.(?P<minor>[0-9]+))?(?:\.(?P<patch>[0-9]+))?).*\),`
javaCmd := &cmd{
executable: "java",

View file

@ -1,7 +1,7 @@
package segments
import (
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/properties"
)
@ -13,7 +13,7 @@ func (j *Julia) Template() string {
return languageTemplate
}
func (j *Julia) Init(props properties.Properties, env environment.Environment) {
func (j *Julia) Init(props properties.Properties, env platform.Environment) {
j.language = language{
env: env,
props: props,

View file

@ -1,7 +1,7 @@
package segments
import (
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/properties"
)
@ -13,7 +13,7 @@ func (k *Kotlin) Template() string {
return languageTemplate
}
func (k *Kotlin) Init(props properties.Properties, env environment.Environment) {
func (k *Kotlin) Init(props properties.Properties, env platform.Environment) {
k.language = language{
env: env,
props: props,

View file

@ -1,7 +1,7 @@
package segments
import (
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/properties"
"path/filepath"
@ -13,7 +13,7 @@ const ParseKubeConfig properties.Property = "parse_kubeconfig"
type Kubectl struct {
props properties.Properties
env environment.Environment
env platform.Environment
Context string
@ -38,7 +38,7 @@ func (k *Kubectl) Template() string {
return " {{ .Context }}{{ if .Namespace }} :: {{ .Namespace }}{{ end }} "
}
func (k *Kubectl) Init(props properties.Properties, env environment.Environment) {
func (k *Kubectl) Init(props properties.Properties, env platform.Environment) {
k.props = props
k.env = env
}

View file

@ -2,8 +2,8 @@ package segments
import (
"fmt"
"oh-my-posh/environment"
"oh-my-posh/mock"
"oh-my-posh/platform"
"oh-my-posh/properties"
"os"
"path/filepath"
@ -117,7 +117,7 @@ func TestKubectlSegment(t *testing.T) {
}
var kubectlErr error
if tc.KubectlErr {
kubectlErr = &environment.CommandError{
kubectlErr = &platform.CommandError{
Err: "oops",
ExitCode: 1,
}

View file

@ -3,7 +3,7 @@ package segments
import (
"errors"
"fmt"
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/properties"
"oh-my-posh/regex"
"oh-my-posh/template"
@ -59,7 +59,7 @@ func (c *cmd) parse(versionInfo string) (*version, error) {
type language struct {
props properties.Properties
env environment.Environment
env platform.Environment
extensions []string
folders []string
commands []*cmd
@ -167,7 +167,7 @@ func (l *language) setVersion() error {
continue
}
versionStr, err = l.env.RunCommand(command.executable, command.args...)
if exitErr, ok := err.(*environment.CommandError); ok {
if exitErr, ok := err.(*platform.CommandError); ok {
l.exitCode = exitErr.ExitCode
lastError = fmt.Errorf("err executing %s with %s", command.executable, command.args)
continue

View file

@ -1,8 +1,8 @@
package segments
import (
"oh-my-posh/environment"
"oh-my-posh/mock"
"oh-my-posh/platform"
"oh-my-posh/properties"
"testing"
@ -53,7 +53,7 @@ func bootStrapLanguageTest(args *languageArgs) *language {
}
env.On("Pwd").Return(cwd)
env.On("Home").Return(home)
env.On("TemplateCache").Return(&environment.TemplateCache{
env.On("TemplateCache").Return(&platform.TemplateCache{
Env: make(map[string]string),
})
if args.properties == nil {
@ -353,7 +353,7 @@ func TestLanguageEnabledCommandExitCode(t *testing.T) {
enabledExtensions: []string{uni, corn},
enabledCommands: []string{"uni"},
version: universion,
expectedError: &environment.CommandError{ExitCode: expected},
expectedError: &platform.CommandError{ExitCode: expected},
}
lang := bootStrapLanguageTest(args)
assert.True(t, lang.Enabled())

View file

@ -1,7 +1,7 @@
package segments
import (
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/properties"
)
@ -17,7 +17,7 @@ func (l *Lua) Template() string {
return languageTemplate
}
func (l *Lua) Init(props properties.Properties, env environment.Environment) {
func (l *Lua) Init(props properties.Properties, env platform.Environment) {
l.language = language{
env: env,
props: props,

View file

@ -2,8 +2,8 @@ package segments
import (
"fmt"
"oh-my-posh/environment"
"oh-my-posh/mock"
"oh-my-posh/platform"
"oh-my-posh/properties"
"strings"
"testing"
@ -65,7 +65,7 @@ func TestLua(t *testing.T) {
env.On("HasFiles", "*.lua").Return(true)
env.On("Pwd").Return("/usr/home/project")
env.On("Home").Return("/usr/home")
env.On("TemplateCache").Return(&environment.TemplateCache{
env.On("TemplateCache").Return(&platform.TemplateCache{
Env: make(map[string]string),
})
props := properties.Map{

View file

@ -2,13 +2,13 @@ package segments
import (
"encoding/json"
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/properties"
)
type Nbgv struct {
props properties.Properties
env environment.Environment
env platform.Environment
VersionInfo
}
@ -45,7 +45,7 @@ func (n *Nbgv) Enabled() bool {
return n.VersionInfo.VersionFileFound
}
func (n *Nbgv) Init(props properties.Properties, env environment.Environment) {
func (n *Nbgv) Init(props properties.Properties, env platform.Environment) {
n.props = props
n.env = env
}

View file

@ -3,7 +3,7 @@ package segments
import (
"encoding/json"
"errors"
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/properties"
"time"
)
@ -11,7 +11,7 @@ import (
// segment struct, makes templating easier
type Nightscout struct {
props properties.Properties
env environment.Environment
env platform.Environment
NightscoutData
TrendIcon string
@ -139,7 +139,7 @@ func (ns *Nightscout) getResult() (*NightscoutData, error) {
return data, nil
}
func (ns *Nightscout) Init(props properties.Properties, env environment.Environment) {
func (ns *Nightscout) Init(props properties.Properties, env platform.Environment) {
ns.props = props
ns.env = env
}

View file

@ -2,7 +2,7 @@ package segments
import (
"fmt"
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/properties"
"oh-my-posh/regex"
)
@ -26,7 +26,7 @@ func (n *Node) Template() string {
return " {{ if .PackageManagerIcon }}{{ .PackageManagerIcon }} {{ end }}{{ .Full }} "
}
func (n *Node) Init(props properties.Properties, env environment.Environment) {
func (n *Node) Init(props properties.Properties, env platform.Environment) {
n.language = language{
env: env,
props: props,

View file

@ -1,7 +1,7 @@
package segments
import (
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/properties"
)
@ -17,7 +17,7 @@ func (n *Npm) Template() string {
return " \ue71e {{.Full}} "
}
func (n *Npm) Init(props properties.Properties, env environment.Environment) {
func (n *Npm) Init(props properties.Properties, env platform.Environment) {
n.language = language{
env: env,
props: props,

View file

@ -3,7 +3,7 @@ package segments
import (
"encoding/json"
"fmt"
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/properties"
"path/filepath"
)
@ -16,7 +16,7 @@ func (a *Nx) Template() string {
return languageTemplate
}
func (a *Nx) Init(props properties.Properties, env environment.Environment) {
func (a *Nx) Init(props properties.Properties, env platform.Environment) {
a.language = language{
env: env,
props: props,
@ -39,7 +39,7 @@ func (a *Nx) getVersion() (string, error) {
return getNodePackageVersion(a.language.env, "nx")
}
func getNodePackageVersion(env environment.Environment, nodePackage string) (string, error) {
func getNodePackageVersion(env platform.Environment, nodePackage string) (string, error) {
const fileName string = "package.json"
folder := filepath.Join(env.Pwd(), "node_modules", nodePackage)
if !env.HasFilesInDir(folder, fileName) {

View file

@ -1,8 +1,8 @@
package segments
import (
"oh-my-posh/environment"
"oh-my-posh/mock"
"oh-my-posh/platform"
"path/filepath"
"testing"
@ -30,7 +30,7 @@ func TestGetNodePackageVersion(t *testing.T) {
path := filepath.Join("posh", "node_modules", "nx")
env.On("HasFilesInDir", path, "package.json").Return(!tc.NoFiles)
env.On("FileContent", filepath.Join(path, "package.json")).Return(tc.PackageJSON)
env.On("TemplateCache").Return(&environment.TemplateCache{
env.On("TemplateCache").Return(&platform.TemplateCache{
Env: make(map[string]string),
})
got, err := getNodePackageVersion(env, "nx")

View file

@ -1,13 +1,13 @@
package segments
import (
"oh-my-posh/environment"
"oh-my-posh/platform"
"oh-my-posh/properties"
)
type Os struct {
props properties.Properties
env environment.Environment
env platform.Environment
Icon string
}
@ -68,18 +68,18 @@ func (oi *Os) Template() string {
func (oi *Os) Enabled() bool {
goos := oi.env.GOOS()
switch goos {
case environment.WINDOWS:
case platform.WINDOWS:
oi.Icon = oi.props.GetString(Windows, "\uE62A")
case environment.DARWIN:
case platform.DARWIN:
oi.Icon = oi.props.GetString(MacOS, "\uF179")
case environment.LINUX:
platform := oi.env.Platform()
case platform.LINUX:
pf := oi.env.Platform()
displayDistroName := oi.props.GetBool(DisplayDistroName, false)
if displayDistroName {
oi.Icon = platform
oi.Icon = pf
break
}
oi.Icon = oi.getDistroIcon(platform)
oi.Icon = oi.getDistroIcon(pf)
default:
oi.Icon = goos
}
@ -130,7 +130,7 @@ func (oi *Os) getDistroIcon(distro string) string {
return oi.props.GetString(Linux, "\uF17C")
}
func (oi *Os) Init(props properties.Properties, env environment.Environment) {
func (oi *Os) Init(props properties.Properties, env platform.Environment) {
oi.props = props
oi.env = env
}

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