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 ( import (
"fmt" "fmt"
"oh-my-posh/environment" "oh-my-posh/platform"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@ -33,7 +33,7 @@ You can do the following:
_ = cmd.Help() _ = cmd.Help()
return return
} }
env := &environment.ShellEnvironment{ env := &platform.Shell{
Version: cliVersion, Version: cliVersion,
} }
env.Init() env.Init()
@ -42,7 +42,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(), environment.CacheFile) cacheFilePath := filepath.Join(env.CachePath(), platform.CacheFile)
err := os.Remove(cacheFilePath) err := os.Remove(cacheFilePath)
if err != nil { if err != nil {
fmt.Println(err.Error()) fmt.Println(err.Error())
@ -50,7 +50,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(), environment.CacheFile) cacheFilePath := filepath.Join(env.CachePath(), platform.CacheFile)
editFileWithEditor(cacheFilePath) editFileWithEditor(cacheFilePath)
} }
}, },

View file

@ -3,7 +3,7 @@ package cli
import ( import (
"fmt" "fmt"
"oh-my-posh/engine" "oh-my-posh/engine"
"oh-my-posh/environment" "oh-my-posh/platform"
"path/filepath" "path/filepath"
"strings" "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.`, A backup of the current config can be found at ~/myconfig.omp.json.bak.`,
Args: cobra.NoArgs, Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
env := &environment.ShellEnvironment{ env := &platform.Shell{
Version: cliVersion, Version: cliVersion,
CmdFlags: &environment.Flags{ CmdFlags: &platform.Flags{
Config: config, 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, "~") { 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,7 +5,7 @@ import (
"oh-my-posh/color" "oh-my-posh/color"
"oh-my-posh/console" "oh-my-posh/console"
"oh-my-posh/engine" "oh-my-posh/engine"
"oh-my-posh/environment" "oh-my-posh/platform"
"oh-my-posh/shell" "oh-my-posh/shell"
"github.com/spf13/cobra" "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.`, Exports the config to an image file using customized output options.`,
Args: cobra.NoArgs, Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
env := &environment.ShellEnvironment{ env := &platform.Shell{
Version: cliVersion, Version: cliVersion,
CmdFlags: &environment.Flags{ CmdFlags: &platform.Flags{
Config: config, Config: config,
Shell: shell.PLAIN, Shell: shell.PLAIN,
}, },

View file

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

View file

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

View file

@ -2,8 +2,8 @@ package cli
import ( import (
"fmt" "fmt"
"oh-my-posh/environment"
"oh-my-posh/font" "oh-my-posh/font"
"oh-my-posh/platform"
"github.com/spf13/cobra" "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 { if len(args) > 1 {
fontName = args[1] fontName = args[1]
} }
env := &environment.ShellEnvironment{} env := &platform.Shell{}
env.Init() env.Init()
needsAdmin := env.GOOS() == environment.WINDOWS && !env.Root() needsAdmin := env.GOOS() == platform.WINDOWS && !env.Root()
font.Run(fontName, needsAdmin) font.Run(fontName, needsAdmin)
return return
case "configure": case "configure":

View file

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

View file

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

View file

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

View file

@ -2,13 +2,13 @@ package color
import ( import (
"fmt" "fmt"
"oh-my-posh/environment" "oh-my-posh/platform"
"strconv" "strconv"
"github.com/gookit/color" "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 := &DefaultColors{}
defaultColors.SetAccentColor(env, accentColor) defaultColors.SetAccentColor(env, accentColor)
colors = defaultColors colors = defaultColors

View file

@ -2,15 +2,13 @@
package color package color
import ( import "oh-my-posh/platform"
"oh-my-posh/environment"
)
func GetAccentColor(env environment.Environment) (*RGB, error) { func GetAccentColor(env platform.Environment) (*RGB, error) {
return nil, &environment.NotImplemented{} 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 { if len(defaultColor) == 0 {
return return
} }

View file

@ -2,18 +2,18 @@ package color
import ( import (
"errors" "errors"
"oh-my-posh/environment" "oh-my-posh/platform"
"github.com/gookit/color" "github.com/gookit/color"
) )
func GetAccentColor(env environment.Environment) (*RGB, error) { func GetAccentColor(env platform.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 != environment.DWORD { if err != nil || value.ValueType != platform.DWORD {
return nil, err return nil, err
} }
return &RGB{ return &RGB{
@ -23,7 +23,7 @@ func GetAccentColor(env environment.Environment) (*RGB, error) {
}, nil }, nil
} }
func (d *DefaultColors) SetAccentColor(env environment.Environment, defaultColor string) { func (d *DefaultColors) SetAccentColor(env platform.Environment, defaultColor string) {
rgb, err := GetAccentColor(env) rgb, err := GetAccentColor(env)
if err != nil { if err != nil {
d.accent = &Color{ d.accent = &Color{

View file

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

View file

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

View file

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

View file

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

View file

@ -6,7 +6,7 @@ import (
"fmt" "fmt"
"io" "io"
"oh-my-posh/color" "oh-my-posh/color"
"oh-my-posh/environment" "oh-my-posh/platform"
"oh-my-posh/properties" "oh-my-posh/properties"
"oh-my-posh/segments" "oh-my-posh/segments"
"oh-my-posh/template" "oh-my-posh/template"
@ -57,7 +57,7 @@ type Config struct {
origin string origin string
eval bool eval bool
updated bool updated bool
env environment.Environment env platform.Environment
} }
// MakeColors creates instance of AnsiColors to use in AnsiWriter according to // 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 // 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 := loadConfig(env)
cfg.env = env cfg.env = env
// only migrate automatically when the switch isn't set // only migrate automatically when the switch isn't set
@ -115,7 +115,7 @@ func LoadConfig(env environment.Environment) *Config {
return cfg return cfg
} }
func loadConfig(env environment.Environment) *Config { func loadConfig(env platform.Environment) *Config {
defer env.Trace(time.Now(), "config.loadConfig") defer env.Trace(time.Now(), "config.loadConfig")
var cfg Config var cfg Config
configFile := env.Flags().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() origin := cfg.backup()
cfg.Migrate(env) cfg.Migrate(env)
cfg.Write(cfg.format) cfg.Write(cfg.format)

View file

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

View file

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

View file

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

View file

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

View file

@ -1,8 +1,8 @@
package engine package engine
import ( import (
"oh-my-posh/environment"
"oh-my-posh/mock" "oh-my-posh/mock"
"oh-my-posh/platform"
"oh-my-posh/properties" "oh-my-posh/properties"
"testing" "testing"
@ -88,7 +88,7 @@ func (m *MockedWriter) Template() string {
return m.template 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) { func TestIconOverride(t *testing.T) {
cases := []struct { cases := []struct {

View file

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

View file

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

View file

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

View file

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

View file

@ -4,21 +4,21 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"io" "io"
"oh-my-posh/environment" "oh-my-posh/platform"
"oh-my-posh/properties" "oh-my-posh/properties"
) )
type Request struct { type Request struct {
props properties.Properties 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.env = env
r.props = props 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 { if data, err := getCacheValue[a](r, url); err == nil {
return data, 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 { if val, found := r.env.Cache().Get(key); found {
err := json.Unmarshal([]byte(val), &data) err := json.Unmarshal([]byte(val), &data)
if err != nil { if err != nil {
r.env.Log(environment.Error, "OAuth", err.Error()) r.env.Log(platform.Error, "OAuth", err.Error())
return data, err return data, err
} }
return data, nil return data, nil
} }
err := errors.New("no data in cache") 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 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 var data a
httpTimeout := r.props.GetInt(properties.HTTPTimeout, properties.DefaultHTTPTimeout) httpTimeout := r.props.GetInt(properties.HTTPTimeout, properties.DefaultHTTPTimeout)
responseBody, err := r.env.HTTPRequest(url, body, httpTimeout, requestModifiers...) responseBody, err := r.env.HTTPRequest(url, body, httpTimeout, requestModifiers...)
if err != nil { if err != nil {
r.env.Log(environment.Error, "OAuth", err.Error()) r.env.Log(platform.Error, "OAuth", err.Error())
return data, err return data, err
} }
err = json.Unmarshal(responseBody, &data) err = json.Unmarshal(responseBody, &data)
if err != nil { if err != nil {
r.env.Log(environment.Error, "OAuth", err.Error()) r.env.Log(platform.Error, "OAuth", err.Error())
return data, err return data, err
} }

View file

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

View file

@ -3,8 +3,8 @@ package mock
import ( import (
"io" "io"
"io/fs" "io/fs"
"oh-my-posh/environment" "oh-my-posh/platform"
"oh-my-posh/environment/battery" "oh-my-posh/platform/battery"
"time" "time"
mock "github.com/stretchr/testify/mock" mock "github.com/stretchr/testify/mock"
@ -119,9 +119,9 @@ func (env *MockedEnvironment) Root() bool {
return args.Bool(0) return args.Bool(0)
} }
func (env *MockedEnvironment) Flags() *environment.Flags { func (env *MockedEnvironment) Flags() *platform.Flags {
arguments := env.Called() arguments := env.Called()
return arguments.Get(0).(*environment.Flags) return arguments.Get(0).(*platform.Flags)
} }
func (env *MockedEnvironment) BatteryState() (*battery.Info, error) { 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) 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) 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) 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) (*environment.FileInfo, error) { func (env *MockedEnvironment) HasParentFilePath(path string) (*platform.FileInfo, error) {
args := env.Called(path) 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 { func (env *MockedEnvironment) StackCount() int {
@ -179,9 +179,9 @@ func (env *MockedEnvironment) CachePath() string {
return args.String(0) return args.String(0)
} }
func (env *MockedEnvironment) Cache() environment.Cache { func (env *MockedEnvironment) Cache() platform.Cache {
args := env.Called() args := env.Called()
return args.Get(0).(environment.Cache) return args.Get(0).(platform.Cache)
} }
func (env *MockedEnvironment) Close() { func (env *MockedEnvironment) Close() {
@ -208,14 +208,14 @@ func (env *MockedEnvironment) ConvertToLinuxPath(path string) string {
return args.String(0) 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) 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() args := env.Called()
return args.Get(0).(*environment.TemplateCache) return args.Get(0).(*platform.TemplateCache)
} }
func (env *MockedEnvironment) LoadTemplateCache() { func (env *MockedEnvironment) LoadTemplateCache() {
@ -246,7 +246,7 @@ func (env *MockedEnvironment) Trace(start time.Time, function string, args ...st
_ = env.Called(start, function, args) _ = 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) _ = env.Called(logType, funcName, message)
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,7 +1,7 @@
package segments package segments
import ( import (
"oh-my-posh/environment" "oh-my-posh/platform"
"oh-my-posh/properties" "oh-my-posh/properties"
"path/filepath" "path/filepath"
) )
@ -14,7 +14,7 @@ func (a *Angular) Template() string {
return languageTemplate 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{ a.language = language{
env: env, env: env,
props: props, props: props,

View file

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

View file

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

View file

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

View file

@ -1,8 +1,8 @@
package segments package segments
import ( import (
"oh-my-posh/environment"
"oh-my-posh/mock" "oh-my-posh/mock"
"oh-my-posh/platform"
"oh-my-posh/properties" "oh-my-posh/properties"
"oh-my-posh/template" "oh-my-posh/template"
"os" "os"
@ -122,7 +122,7 @@ func TestAzSegment(t *testing.T) {
azureRmContext = string(content) 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("FileContent", filepath.Join(home, ".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

@ -1,14 +1,14 @@
package segments package segments
import ( import (
"oh-my-posh/environment" "oh-my-posh/platform"
"oh-my-posh/environment/battery" "oh-my-posh/platform/battery"
"oh-my-posh/properties" "oh-my-posh/properties"
) )
type Battery struct { type Battery struct {
props properties.Properties props properties.Properties
env environment.Environment env platform.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 environment.Environment) { func (b *Battery) Init(props properties.Properties, env platform.Environment) {
b.props = props b.props = props
b.env = env b.env = env
} }

View file

@ -7,7 +7,7 @@ import (
"fmt" "fmt"
"math" "math"
"net/http" "net/http"
"oh-my-posh/environment" "oh-my-posh/platform"
"oh-my-posh/properties" "oh-my-posh/properties"
"sort" "sort"
"time" "time"
@ -16,7 +16,7 @@ import (
// segment struct, makes templating easier // segment struct, makes templating easier
type Brewfather struct { type Brewfather struct {
props properties.Properties props properties.Properties
env environment.Environment env platform.Environment
Batch Batch
TemperatureTrendIcon string 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 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.props = props
bf.env = env bf.env = env
} }

View file

@ -2,7 +2,7 @@ package segments
import ( import (
"encoding/json" "encoding/json"
"oh-my-posh/environment" "oh-my-posh/platform"
"oh-my-posh/properties" "oh-my-posh/properties"
) )
@ -15,7 +15,7 @@ func (c *Cds) Template() string {
return languageTemplate 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{ c.language = language{
env: env, env: env,
props: props, props: props,

View file

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

View file

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

View file

@ -1,14 +1,14 @@
package segments package segments
import ( import (
"oh-my-posh/environment" "oh-my-posh/platform"
"oh-my-posh/properties" "oh-my-posh/properties"
"regexp" "regexp"
) )
type CfTarget struct { type CfTarget struct {
props properties.Properties props properties.Properties
env environment.Environment env platform.Environment
CfTargetDetails CfTargetDetails
} }
@ -24,7 +24,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 environment.Environment) { func (c *CfTarget) Init(props properties.Properties, env platform.Environment) {
c.props = props c.props = props
c.env = env c.env = env
} }

View file

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

View file

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

View file

@ -1,14 +1,14 @@
package segments package segments
import ( import (
"oh-my-posh/environment" "oh-my-posh/platform"
"oh-my-posh/properties" "oh-my-posh/properties"
"strings" "strings"
) )
type Cmd struct { type Cmd struct {
props properties.Properties props properties.Properties
env environment.Environment env platform.Environment
Output string Output string
} }
@ -71,7 +71,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 environment.Environment) { func (c *Cmd) Init(props properties.Properties, env platform.Environment) {
c.props = props c.props = props
c.env = env c.env = env
} }

View file

@ -1,16 +1,16 @@
package segments package segments
import ( import (
"oh-my-posh/environment" "oh-my-posh/platform"
"oh-my-posh/properties" "oh-my-posh/properties"
"strings" "strings"
) )
type Connection struct { type Connection struct {
props properties.Properties props properties.Properties
env environment.Environment env platform.Environment
environment.Connection platform.Connection
} }
const ( const (
@ -25,7 +25,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(environment.ConnectionType(connectionType)) network, err := c.env.Connection(platform.ConnectionType(connectionType))
if err != nil { if err != nil {
continue continue
} }
@ -35,7 +35,7 @@ func (c *Connection) Enabled() bool {
return false 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.props = props
c.env = env c.env = env
} }

View file

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

View file

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

View file

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

View file

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

View file

@ -2,7 +2,7 @@ package segments
import ( import (
"oh-my-posh/constants" "oh-my-posh/constants"
"oh-my-posh/environment" "oh-my-posh/platform"
"oh-my-posh/properties" "oh-my-posh/properties"
) )
@ -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 environment.Environment) { func (d *Dotnet) Init(props properties.Properties, env platform.Environment) {
d.language = language{ d.language = language{
env: env, env: env,
props: props, props: props,

View file

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

View file

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

View file

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

View file

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

View file

@ -1,7 +1,7 @@
package segments package segments
import ( import (
"oh-my-posh/environment" "oh-my-posh/platform"
"oh-my-posh/properties" "oh-my-posh/properties"
) )
@ -13,7 +13,7 @@ func (f *Flutter) Template() string {
return languageTemplate 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{ f.language = language{
env: env, env: env,
props: props, props: props,

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,7 +1,7 @@
package segments package segments
import ( import (
"oh-my-posh/environment" "oh-my-posh/platform"
"oh-my-posh/properties" "oh-my-posh/properties"
) )
@ -13,7 +13,7 @@ func (j *Julia) Template() string {
return languageTemplate 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{ j.language = language{
env: env, env: env,
props: props, props: props,

View file

@ -1,7 +1,7 @@
package segments package segments
import ( import (
"oh-my-posh/environment" "oh-my-posh/platform"
"oh-my-posh/properties" "oh-my-posh/properties"
) )
@ -13,7 +13,7 @@ func (k *Kotlin) Template() string {
return languageTemplate 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{ k.language = language{
env: env, env: env,
props: props, props: props,

View file

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

View file

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

View file

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

View file

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

View file

@ -1,7 +1,7 @@
package segments package segments
import ( import (
"oh-my-posh/environment" "oh-my-posh/platform"
"oh-my-posh/properties" "oh-my-posh/properties"
) )
@ -17,7 +17,7 @@ func (l *Lua) Template() string {
return languageTemplate 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{ l.language = language{
env: env, env: env,
props: props, props: props,

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

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