mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-28 20:39:40 -08:00
fix: remove segment from cache on empty template
This commit is contained in:
parent
51fd45dc60
commit
8ba753e08c
|
@ -47,6 +47,7 @@ type Segment struct {
|
|||
writer SegmentWriter
|
||||
text string
|
||||
styleCache SegmentStyle
|
||||
name string
|
||||
}
|
||||
|
||||
// SegmentTiming holds the timing context for a segment
|
||||
|
@ -427,6 +428,18 @@ func (segment *Segment) string() string {
|
|||
return text
|
||||
}
|
||||
|
||||
func (segment *Segment) Name() string {
|
||||
if len(segment.name) != 0 {
|
||||
return segment.name
|
||||
}
|
||||
name := segment.Alias
|
||||
if len(name) == 0 {
|
||||
name = c.Title(language.English).String(string(segment.Type))
|
||||
}
|
||||
segment.name = name
|
||||
return name
|
||||
}
|
||||
|
||||
func (segment *Segment) SetEnabled(env platform.Environment) {
|
||||
defer func() {
|
||||
err := recover()
|
||||
|
@ -456,11 +469,7 @@ func (segment *Segment) SetEnabled(env platform.Environment) {
|
|||
}
|
||||
if segment.writer.Enabled() {
|
||||
segment.Enabled = true
|
||||
name := segment.Alias
|
||||
if len(name) == 0 {
|
||||
name = c.Title(language.English).String(string(segment.Type))
|
||||
}
|
||||
env.TemplateCache().AddSegmentData(name, segment.writer)
|
||||
env.TemplateCache().AddSegmentData(segment.Name(), segment.writer)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -470,6 +479,10 @@ func (segment *Segment) SetText() {
|
|||
}
|
||||
segment.text = segment.string()
|
||||
segment.Enabled = len(strings.ReplaceAll(segment.text, " ", "")) > 0
|
||||
if !segment.Enabled {
|
||||
segment.env.TemplateCache().RemoveSegmentData(segment.Name())
|
||||
}
|
||||
|
||||
if segment.Interactive {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -163,6 +163,12 @@ func (t *TemplateCache) AddSegmentData(key string, value interface{}) {
|
|||
t.Unlock()
|
||||
}
|
||||
|
||||
func (t *TemplateCache) RemoveSegmentData(key string) {
|
||||
t.Lock()
|
||||
delete(t.Segments, key)
|
||||
t.Unlock()
|
||||
}
|
||||
|
||||
type Environment interface {
|
||||
Getenv(key string) string
|
||||
Pwd() string
|
||||
|
|
Loading…
Reference in a new issue