mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-01-16 05:38:27 -08:00
parent
4093b79649
commit
d5f87c81be
|
@ -354,6 +354,8 @@ const (
|
|||
)
|
||||
|
||||
func (e *Engine) PrintExtraPrompt(promptType ExtraPromptType) string {
|
||||
// populate env with latest context
|
||||
e.Env.LoadTemplateCache()
|
||||
var prompt *Segment
|
||||
switch promptType {
|
||||
case Debug:
|
||||
|
|
|
@ -3,6 +3,7 @@ package environment
|
|||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
@ -35,7 +36,8 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
lock = sync.RWMutex{}
|
||||
lock = sync.RWMutex{}
|
||||
TEMPLATECACHE = fmt.Sprintf("template_cache_%d", os.Getppid())
|
||||
)
|
||||
|
||||
type Flags struct {
|
||||
|
@ -181,6 +183,7 @@ type Environment interface {
|
|||
ConvertToWindowsPath(path string) string
|
||||
WifiNetwork() (*WifiInfo, error)
|
||||
TemplateCache() *TemplateCache
|
||||
LoadTemplateCache()
|
||||
Log(logType LogType, funcName, message string)
|
||||
Trace(start time.Time, function string, args ...string)
|
||||
}
|
||||
|
@ -659,9 +662,29 @@ func (env *ShellEnvironment) Cache() Cache {
|
|||
}
|
||||
|
||||
func (env *ShellEnvironment) Close() {
|
||||
defer env.Trace(time.Now(), "Close")
|
||||
templateCache, err := json.Marshal(env.TemplateCache())
|
||||
if err == nil {
|
||||
env.fileCache.Set(TEMPLATECACHE, string(templateCache), 1440)
|
||||
}
|
||||
env.fileCache.Close()
|
||||
}
|
||||
|
||||
func (env *ShellEnvironment) LoadTemplateCache() {
|
||||
defer env.Trace(time.Now(), "LoadTemplateCache")
|
||||
val, OK := env.fileCache.Get(TEMPLATECACHE)
|
||||
if !OK {
|
||||
return
|
||||
}
|
||||
var templateCache TemplateCache
|
||||
err := json.Unmarshal([]byte(val), &templateCache)
|
||||
if err != nil {
|
||||
env.Log(Error, "LoadTemplateCache", err.Error())
|
||||
return
|
||||
}
|
||||
env.tmplCache = &templateCache
|
||||
}
|
||||
|
||||
func (env *ShellEnvironment) Logs() string {
|
||||
return env.logBuilder.String()
|
||||
}
|
||||
|
|
|
@ -218,6 +218,10 @@ func (env *MockedEnvironment) TemplateCache() *environment.TemplateCache {
|
|||
return args.Get(0).(*environment.TemplateCache)
|
||||
}
|
||||
|
||||
func (env *MockedEnvironment) LoadTemplateCache() {
|
||||
_ = env.Called()
|
||||
}
|
||||
|
||||
func (env *MockedEnvironment) MockGitCommand(dir, returnValue string, args ...string) {
|
||||
args = append([]string{"-C", dir, "--no-optional-locks", "-c", "core.quotepath=false", "-c", "color.status=false"}, args...)
|
||||
env.On("RunCommand", "git", args).Return(returnValue, nil)
|
||||
|
|
Loading…
Reference in a new issue