mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-11-10 04:54:03 -08:00
fix(platform): avoid duplicate creations of template cache
This commit is contained in:
parent
c3c7c9e6e0
commit
61fa281894
|
@ -190,6 +190,7 @@ type TemplateCache struct {
|
|||
SHLVL int
|
||||
Segments SegmentsCache
|
||||
|
||||
initialized bool
|
||||
sync.RWMutex
|
||||
}
|
||||
|
||||
|
@ -312,6 +313,7 @@ func (env *Shell) Init() {
|
|||
env.cmdCache = &commandCache{
|
||||
commands: NewConcurrentMap(),
|
||||
}
|
||||
env.tmplCache = &TemplateCache{}
|
||||
env.SetPromptCount()
|
||||
}
|
||||
|
||||
|
@ -776,6 +778,7 @@ func (env *Shell) LoadTemplateCache() {
|
|||
env.Error(err)
|
||||
return
|
||||
}
|
||||
templateCache.initialized = true
|
||||
env.tmplCache = &templateCache
|
||||
}
|
||||
|
||||
|
@ -785,19 +788,21 @@ func (env *Shell) Logs() string {
|
|||
|
||||
func (env *Shell) TemplateCache() *TemplateCache {
|
||||
defer env.Trace(time.Now())
|
||||
if env.tmplCache != nil {
|
||||
return env.tmplCache
|
||||
tmplCache := env.tmplCache
|
||||
tmplCache.Lock()
|
||||
defer tmplCache.Unlock()
|
||||
|
||||
if tmplCache.initialized {
|
||||
return tmplCache
|
||||
}
|
||||
|
||||
tmplCache := &TemplateCache{
|
||||
Root: env.Root(),
|
||||
Shell: env.Shell(),
|
||||
ShellVersion: env.CmdFlags.ShellVersion,
|
||||
Code: env.ErrorCode(),
|
||||
WSL: env.IsWsl(),
|
||||
Segments: make(map[string]interface{}),
|
||||
PromptCount: env.CmdFlags.PromptCount,
|
||||
}
|
||||
tmplCache.Root = env.Root()
|
||||
tmplCache.Shell = env.Shell()
|
||||
tmplCache.ShellVersion = env.CmdFlags.ShellVersion
|
||||
tmplCache.Code = env.ErrorCode()
|
||||
tmplCache.WSL = env.IsWsl()
|
||||
tmplCache.Segments = make(map[string]interface{})
|
||||
tmplCache.PromptCount = env.CmdFlags.PromptCount
|
||||
tmplCache.Env = make(map[string]string)
|
||||
tmplCache.Var = make(map[string]interface{})
|
||||
|
||||
|
@ -838,7 +843,7 @@ func (env *Shell) TemplateCache() *TemplateCache {
|
|||
tmplCache.SHLVL = shlvl
|
||||
}
|
||||
|
||||
env.tmplCache = tmplCache
|
||||
tmplCache.initialized = true
|
||||
return tmplCache
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue