refactor: rename environmentInfo

This commit is contained in:
Jan De Dobbeleer 2022-01-01 20:09:52 +01:00 committed by Jan De Dobbeleer
parent 29e019511a
commit e1f50ef885
54 changed files with 90 additions and 90 deletions

View file

@ -33,7 +33,7 @@ type Block struct {
Segments []*Segment `config:"segments"`
Newline bool `config:"newline"`
env environmentInfo
env Environment
writer promptWriter
ansi *ansiUtils
activeSegment *Segment
@ -42,13 +42,13 @@ type Block struct {
activeForeground string
}
func (b *Block) init(env environmentInfo, writer promptWriter, ansi *ansiUtils) {
func (b *Block) init(env Environment, writer promptWriter, ansi *ansiUtils) {
b.env = env
b.writer = writer
b.ansi = ansi
}
func (b *Block) initPlain(env environmentInfo, config *Config) {
func (b *Block) initPlain(env Environment, config *Config) {
b.ansi = &ansiUtils{}
b.ansi.init(plain)
b.writer = &AnsiWriter{

View file

@ -8,7 +8,7 @@ import (
// MakeColors creates instance of AnsiColors to use in AnsiWriter according to
// environment and configuration.
func MakeColors(env environmentInfo, cfg *Config) AnsiColors {
func MakeColors(env Environment, cfg *Config) AnsiColors {
cacheDisabled := env.getenv("OMP_CACHE_DISABLED") == "1"
return makeColors(cfg.Palette, !cacheDisabled)
}

View file

@ -58,7 +58,7 @@ func printConfigError(err error, eval bool) {
}
// GetConfig returns the default configuration including possible user overrides
func GetConfig(env environmentInfo) *Config {
func GetConfig(env Environment) *Config {
cfg, err := loadConfig(env)
if err != nil {
return getDefaultConfig(err.Error())
@ -66,7 +66,7 @@ func GetConfig(env environmentInfo) *Config {
return cfg
}
func loadConfig(env environmentInfo) (*Config, error) {
func loadConfig(env Environment) (*Config, error) {
var cfg Config
configFile := *env.getArgs().Config
eval := *env.getArgs().Eval

View file

@ -6,7 +6,7 @@ import (
)
type consoleTitle struct {
env environmentInfo
env Environment
config *Config
ansi *ansiUtils
}

View file

@ -8,7 +8,7 @@ import (
type engine struct {
config *Config
env environmentInfo
env Environment
writer promptWriter
ansi *ansiUtils
consoleTitle *consoleTitle

View file

@ -88,7 +88,7 @@ type wifiInfo struct {
Error string
}
type environmentInfo interface {
type Environment interface {
getenv(key string) string
getcwd() string
homeDir() string

View file

@ -323,7 +323,7 @@ func getShellInitScript(executable, configFile, script string) string {
return script
}
func getConsoleBackgroundColor(env environmentInfo, backgroundColorTemplate string) string {
func getConsoleBackgroundColor(env Environment, backgroundColorTemplate string) string {
if len(backgroundColorTemplate) == 0 {
return backgroundColorTemplate
}

View file

@ -80,7 +80,7 @@ func matchString(pattern, text string) bool {
return re.MatchString(text)
}
func dirMatchesOneOf(env environmentInfo, dir string, regexes []string) bool {
func dirMatchesOneOf(env Environment, dir string, regexes []string) bool {
normalizedCwd := strings.ReplaceAll(dir, "\\", "/")
normalizedHomeDir := strings.ReplaceAll(env.homeDir(), "\\", "/")

View file

@ -36,7 +36,7 @@ func (s *ScmStatus) String() string {
type scm struct {
props Properties
env environmentInfo
env Environment
}
const (
@ -48,7 +48,7 @@ const (
FullBranchPath Property = "full_branch_path"
)
func (s *scm) init(props Properties, env environmentInfo) {
func (s *scm) init(props Properties, env Environment) {
s.props = props
s.env = env
}

View file

@ -24,7 +24,7 @@ type Segment struct {
writer SegmentWriter
stringValue string
active bool
env environmentInfo
env Environment
}
// SegmentTiming holds the timing context for a segment
@ -56,7 +56,7 @@ type Properties interface {
type SegmentWriter interface {
enabled() bool
string() string
init(props Properties, env environmentInfo)
init(props Properties, env Environment)
}
// SegmentStyle the syle of segment, for more information, see the constants
@ -246,7 +246,7 @@ func (segment *Segment) background() string {
return segment.getColor(segment.BackgroundTemplates, color)
}
func (segment *Segment) mapSegmentWithWriter(env environmentInfo) error {
func (segment *Segment) mapSegmentWithWriter(env Environment) error {
segment.env = env
functions := map[SegmentType]SegmentWriter{
OWM: &owm{},
@ -304,7 +304,7 @@ func (segment *Segment) mapSegmentWithWriter(env environmentInfo) error {
return errors.New("unable to map writer")
}
func (segment *Segment) setStringValue(env environmentInfo) {
func (segment *Segment) setStringValue(env Environment) {
defer func() {
err := recover()
if err == nil {

View file

@ -13,7 +13,7 @@ func (a *angular) string() string {
return a.language.string()
}
func (a *angular) init(props Properties, env environmentInfo) {
func (a *angular) init(props Properties, env Environment) {
a.language = language{
env: env,
props: props,

View file

@ -7,7 +7,7 @@ import (
type aws struct {
props Properties
env environmentInfo
env Environment
Profile string
Region string
}
@ -16,7 +16,7 @@ const (
defaultUser = "default"
)
func (a *aws) init(props Properties, env environmentInfo) {
func (a *aws) init(props Properties, env Environment) {
a.props = props
a.env = env
}

View file

@ -8,7 +8,7 @@ import (
type az struct {
props Properties
env environmentInfo
env Environment
AzureSubscription
}
@ -91,7 +91,7 @@ func (a *az) string() string {
return text
}
func (a *az) init(props Properties, env environmentInfo) {
func (a *az) init(props Properties, env Environment) {
a.props = props
a.env = env
}

View file

@ -8,7 +8,7 @@ func (az *azfunc) string() string {
return az.language.string()
}
func (az *azfunc) init(props Properties, env environmentInfo) {
func (az *azfunc) init(props Properties, env Environment) {
az.language = language{
env: env,
props: props,

View file

@ -8,7 +8,7 @@ import (
type batt struct {
props Properties
env environmentInfo
env Environment
battery.Battery
Percentage int
@ -118,7 +118,7 @@ func (b *batt) string() string {
return text
}
func (b *batt) init(props Properties, env environmentInfo) {
func (b *batt) init(props Properties, env Environment) {
b.props = props
b.env = env
}

View file

@ -14,7 +14,7 @@ import (
// segment struct, makes templating easier
type brewfather struct {
props Properties
env environmentInfo
env Environment
Batch
TemperatureTrendIcon string
@ -335,7 +335,7 @@ func (bf *brewfather) SGToPlato(sg float64) float64 {
return math.Round(100*((135.997*sg*sg*sg)-(630.272*sg*sg)+(1111.14*sg)-616.868)) / 100 // 2 decimal places
}
func (bf *brewfather) init(props Properties, env environmentInfo) {
func (bf *brewfather) init(props Properties, env Environment) {
bf.props = props
bf.env = env
}

View file

@ -4,7 +4,7 @@ import "strings"
type command struct {
props Properties
env environmentInfo
env Environment
value string
}
@ -48,7 +48,7 @@ func (c *command) string() string {
return c.value
}
func (c *command) init(props Properties, env environmentInfo) {
func (c *command) init(props Properties, env Environment) {
c.props = props
c.env = env
}

View file

@ -8,7 +8,7 @@ func (c *crystal) string() string {
return c.language.string()
}
func (c *crystal) init(props Properties, env environmentInfo) {
func (c *crystal) init(props Properties, env Environment) {
c.language = language{
env: env,
props: props,

View file

@ -8,7 +8,7 @@ func (d *dart) string() string {
return d.language.string()
}
func (d *dart) init(props Properties, env environmentInfo) {
func (d *dart) init(props Properties, env Environment) {
d.language = language{
env: env,
props: props,

View file

@ -422,7 +422,7 @@ const (
type envvar struct {
props Properties
env environmentInfo
env Environment
Value string
}
@ -454,7 +454,7 @@ func (e *envvar) string() string {
return text
}
func (e *envvar) init(props Properties, env environmentInfo) {
func (e *envvar) init(props Properties, env Environment) {
e.props = props
e.env = env
}

View file

@ -21,7 +21,7 @@ func (d *dotnet) string() string {
return version
}
func (d *dotnet) init(props Properties, env environmentInfo) {
func (d *dotnet) init(props Properties, env Environment) {
d.language = language{
env: env,
props: props,

View file

@ -10,7 +10,7 @@ import (
type executiontime struct {
props Properties
env environmentInfo
env Environment
FormattedMs string
Ms int64
@ -63,7 +63,7 @@ func (t *executiontime) string() string {
return t.FormattedMs
}
func (t *executiontime) init(props Properties, env environmentInfo) {
func (t *executiontime) init(props Properties, env Environment) {
t.props = props
t.env = env
}

View file

@ -4,7 +4,7 @@ import "strconv"
type exit struct {
props Properties
env environmentInfo
env Environment
Code int
Text string
@ -21,7 +21,7 @@ func (e *exit) string() string {
return e.getFormattedText()
}
func (e *exit) init(props Properties, env environmentInfo) {
func (e *exit) init(props Properties, env Environment) {
e.props = props
e.env = env
}

View file

@ -16,7 +16,7 @@ func (g *golang) string() string {
return g.language.string()
}
func (g *golang) init(props Properties, env environmentInfo) {
func (g *golang) init(props Properties, env Environment) {
g.language = language{
env: env,
props: props,

View file

@ -2,7 +2,7 @@ package main
type ipify struct {
props Properties
env environmentInfo
env Environment
IP string
}
@ -66,7 +66,7 @@ func (i *ipify) getResult() (string, error) {
return response, nil
}
func (i *ipify) init(props Properties, env environmentInfo) {
func (i *ipify) init(props Properties, env Environment) {
i.props = props
i.env = env
}

View file

@ -10,7 +10,7 @@ func (j *java) string() string {
return j.language.string()
}
func (j *java) init(props Properties, env environmentInfo) {
func (j *java) init(props Properties, env Environment) {
javaRegex := `(?: JRE)(?: \(.*\))? \((?P<version>(?P<major>[0-9]+)(?:\.(?P<minor>[0-9]+))?(?:\.(?P<patch>[0-9]+))?).*\),`
javaCmd := &cmd{
executable: "java",

View file

@ -8,7 +8,7 @@ func (j *julia) string() string {
return j.language.string()
}
func (j *julia) init(props Properties, env environmentInfo) {
func (j *julia) init(props Properties, env Environment) {
j.language = language{
env: env,
props: props,

View file

@ -11,7 +11,7 @@ const ParseKubeConfig Property = "parse_kubeconfig"
type kubectl struct {
props Properties
env environmentInfo
env Environment
Context string
KubeContext
}
@ -44,7 +44,7 @@ func (k *kubectl) string() string {
return text
}
func (k *kubectl) init(props Properties, env environmentInfo) {
func (k *kubectl) init(props Properties, env Environment) {
k.props = props
k.env = env
}

View file

@ -48,7 +48,7 @@ func (c *cmd) parse(versionInfo string) (*version, error) {
type language struct {
props Properties
env environmentInfo
env Environment
extensions []string
commands []*cmd
versionURLTemplate string

View file

@ -6,7 +6,7 @@ import (
type nbgv struct {
props Properties
env environmentInfo
env Environment
nbgv *versionInfo
}
@ -52,7 +52,7 @@ func (n *nbgv) string() string {
return text
}
func (n *nbgv) init(props Properties, env environmentInfo) {
func (n *nbgv) init(props Properties, env Environment) {
n.props = props
n.env = env
}

View file

@ -9,7 +9,7 @@ import (
// segment struct, makes templating easier
type nightscout struct {
props Properties
env environmentInfo
env Environment
NightscoutData
TrendIcon string
@ -148,7 +148,7 @@ func (ns *nightscout) getResult() (*NightscoutData, error) {
return data, nil
}
func (ns *nightscout) init(props Properties, env environmentInfo) {
func (ns *nightscout) init(props Properties, env Environment) {
ns.props = props
ns.env = env
}

View file

@ -26,7 +26,7 @@ func (n *node) string() string {
return n.language.renderTemplate(segmentTemplate, n)
}
func (n *node) init(props Properties, env environmentInfo) {
func (n *node) init(props Properties, env Environment) {
n.language = language{
env: env,
props: props,

View file

@ -6,7 +6,7 @@ import (
type osInfo struct {
props Properties
env environmentInfo
env Environment
OS string
}
@ -145,7 +145,7 @@ func (n *osInfo) getDistroName(distro, defaultName string) string {
return n.props.getString(Linux, "\uF17C")
}
func (n *osInfo) init(props Properties, env environmentInfo) {
func (n *osInfo) init(props Properties, env Environment) {
n.props = props
n.env = env
}

View file

@ -8,7 +8,7 @@ import (
type owm struct {
props Properties
env environmentInfo
env Environment
Temperature float64
Weather string
URL string
@ -173,7 +173,7 @@ func (d *owm) setStatus() error {
return nil
}
func (d *owm) init(props Properties, env environmentInfo) {
func (d *owm) init(props Properties, env Environment) {
d.props = props
d.env = env
}

View file

@ -9,7 +9,7 @@ import (
type path struct {
props Properties
env environmentInfo
env Environment
PWD string
Path string
@ -112,7 +112,7 @@ func (pt *path) formatWindowsDrive(pwd string) string {
return pwd + "\\"
}
func (pt *path) init(props Properties, env environmentInfo) {
func (pt *path) init(props Properties, env Environment) {
pt.props = props
pt.env = env
}
@ -358,7 +358,7 @@ func (pt *path) pathDepth(pwd string) int {
// Base returns the last element of path.
// Trailing path separators are removed before extracting the last element.
// If the path consists entirely of separators, Base returns a single separator.
func base(path string, env environmentInfo) string {
func base(path string, env Environment) string {
if path == "/" {
return path
}

View file

@ -8,7 +8,7 @@ func (n *php) string() string {
return n.language.string()
}
func (n *php) init(props Properties, env environmentInfo) {
func (n *php) init(props Properties, env Environment) {
n.language = language{
env: env,
props: props,

View file

@ -34,7 +34,7 @@ type plastic struct {
plasticWorkspaceFolder string // root folder of workspace
}
func (p *plastic) init(props Properties, env environmentInfo) {
func (p *plastic) init(props Properties, env Environment) {
p.props = props
p.env = env
}

View file

@ -4,7 +4,7 @@ import "strings"
type poshgit struct {
props Properties
env environmentInfo
env Environment
gitStatus string
}
@ -22,7 +22,7 @@ func (p *poshgit) string() string {
return p.gitStatus
}
func (p *poshgit) init(props Properties, env environmentInfo) {
func (p *poshgit) init(props Properties, env Environment) {
p.props = props
p.env = env
}

View file

@ -19,7 +19,7 @@ func (p *python) string() string {
return p.language.renderTemplate(segmentTemplate, p)
}
func (p *python) init(props Properties, env environmentInfo) {
func (p *python) init(props Properties, env Environment) {
p.language = language{
env: env,
props: props,

View file

@ -2,7 +2,7 @@ package main
type root struct {
props Properties
env environmentInfo
env Environment
}
const (
@ -18,7 +18,7 @@ func (rt *root) string() string {
return rt.props.getString(RootIcon, "\uF0E7")
}
func (rt *root) init(props Properties, env environmentInfo) {
func (rt *root) init(props Properties, env Environment) {
rt.props = props
rt.env = env
}

View file

@ -13,7 +13,7 @@ func (r *ruby) string() string {
return version
}
func (r *ruby) init(props Properties, env environmentInfo) {
func (r *ruby) init(props Properties, env Environment) {
r.language = language{
env: env,
props: props,

View file

@ -8,7 +8,7 @@ func (r *rust) string() string {
return r.language.string()
}
func (r *rust) init(props Properties, env environmentInfo) {
func (r *rust) init(props Properties, env Environment) {
r.language = language{
env: env,
props: props,

View file

@ -4,7 +4,7 @@ import "strings"
type session struct {
props Properties
env environmentInfo
env Environment
text string
UserName string
@ -45,7 +45,7 @@ func (s *session) string() string {
return s.getFormattedText()
}
func (s *session) init(props Properties, env environmentInfo) {
func (s *session) init(props Properties, env Environment) {
s.props = props
s.env = env
}

View file

@ -4,7 +4,7 @@ import "strings"
type shell struct {
props Properties
env environmentInfo
env Environment
}
const (
@ -28,7 +28,7 @@ func (s *shell) string() string {
return shellName
}
func (s *shell) init(props Properties, env environmentInfo) {
func (s *shell) init(props Properties, env Environment) {
s.props = props
s.env = env
}

View file

@ -6,7 +6,7 @@ import (
type spotify struct {
props Properties
env environmentInfo
env Environment
status string
artist string
track string
@ -39,7 +39,7 @@ func (s *spotify) string() string {
return fmt.Sprintf("%s%s%s%s", icon, s.artist, separator, s.track)
}
func (s *spotify) init(props Properties, env environmentInfo) {
func (s *spotify) init(props Properties, env Environment) {
s.props = props
s.env = env
}

View file

@ -8,7 +8,7 @@ import (
type sysinfo struct {
props Properties
env environmentInfo
env Environment
Precision int
// mem
PhysicalTotalMemory uint64
@ -53,7 +53,7 @@ func (s *sysinfo) string() string {
return text
}
func (s *sysinfo) init(props Properties, env environmentInfo) {
func (s *sysinfo) init(props Properties, env Environment) {
s.props = props
s.env = env
s.Precision = s.props.getInt(Precision, 2)

View file

@ -2,7 +2,7 @@ package main
type terraform struct {
props Properties
env environmentInfo
env Environment
WorkspaceName string
}
@ -20,7 +20,7 @@ func (tf *terraform) string() string {
return text
}
func (tf *terraform) init(props Properties, env environmentInfo) {
func (tf *terraform) init(props Properties, env Environment) {
tf.props = props
tf.env = env
}

View file

@ -2,7 +2,7 @@ package main
type text struct {
props Properties
env environmentInfo
env Environment
content string
}
@ -26,7 +26,7 @@ func (t *text) string() string {
return t.content
}
func (t *text) init(props Properties, env environmentInfo) {
func (t *text) init(props Properties, env Environment) {
t.props = props
t.env = env
}

View file

@ -4,7 +4,7 @@ import "time"
type tempus struct {
props Properties
env environmentInfo
env Environment
templateText string
CurrentDate time.Time
}
@ -40,7 +40,7 @@ func (t *tempus) string() string {
return t.getFormattedText()
}
func (t *tempus) init(props Properties, env environmentInfo) {
func (t *tempus) init(props Properties, env Environment) {
t.props = props
t.env = env
}

View file

@ -6,7 +6,7 @@ import (
type wakatime struct {
props Properties
env environmentInfo
env Environment
wtData
}
@ -73,7 +73,7 @@ func (w *wakatime) setAPIData() error {
return nil
}
func (w *wakatime) init(props Properties, env environmentInfo) {
func (w *wakatime) init(props Properties, env Environment) {
w.props = props
w.env = env
}

View file

@ -2,7 +2,7 @@ package main
type wifi struct {
props Properties
env environmentInfo
env Environment
wifiInfo
}
@ -44,7 +44,7 @@ func (w *wifi) string() string {
return text
}
func (w *wifi) init(props Properties, env environmentInfo) {
func (w *wifi) init(props Properties, env Environment) {
w.props = props
w.env = env
}

View file

@ -7,7 +7,7 @@ import (
type winreg struct {
props Properties
env environmentInfo
env Environment
Value string
}
@ -19,7 +19,7 @@ const (
Fallback Property = "fallback"
)
func (wr *winreg) init(props Properties, env environmentInfo) {
func (wr *winreg) init(props Properties, env Environment) {
wr.props = props
wr.env = env
}

View file

@ -7,7 +7,7 @@ import (
type ytm struct {
props Properties
env environmentInfo
env Environment
status playStatus
artist string
track string
@ -39,7 +39,7 @@ func (y *ytm) enabled() bool {
return err == nil
}
func (y *ytm) init(props Properties, env environmentInfo) {
func (y *ytm) init(props Properties, env Environment) {
y.props = props
y.env = env
}

View file

@ -19,7 +19,7 @@ const (
type textTemplate struct {
Template string
Context interface{}
Env environmentInfo
Env Environment
}
func (t *textTemplate) renderPlainContextTemplate(context map[string]interface{}) string {