mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-26 03:24:04 -08:00
fix(template): store segment data synchronous
This commit is contained in:
parent
665b487727
commit
1bebcd1f5d
|
@ -138,8 +138,9 @@ func (segment *Segment) Render() {
|
|||
return
|
||||
}
|
||||
|
||||
segment.writer.SetText(text)
|
||||
segment.SetText(text)
|
||||
segment.setCache()
|
||||
segment.env.TemplateCache().AddSegmentData(segment.Name(), segment.writer)
|
||||
}
|
||||
|
||||
func (segment *Segment) Text() string {
|
||||
|
|
|
@ -1,36 +1,58 @@
|
|||
package maps
|
||||
|
||||
import "sync"
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
func NewConcurrent() *Concurrent {
|
||||
var cm Concurrent
|
||||
return &cm
|
||||
return &Concurrent{
|
||||
data: make(map[string]any),
|
||||
}
|
||||
}
|
||||
|
||||
type Concurrent sync.Map
|
||||
type Concurrent struct {
|
||||
data map[string]any
|
||||
sync.RWMutex
|
||||
}
|
||||
|
||||
func (cm *Concurrent) Set(key string, value any) {
|
||||
(*sync.Map)(cm).Store(key, value)
|
||||
cm.Lock()
|
||||
defer cm.Unlock()
|
||||
|
||||
if cm.data == nil {
|
||||
cm.data = make(map[string]any)
|
||||
}
|
||||
|
||||
cm.data[key] = value
|
||||
}
|
||||
|
||||
func (cm *Concurrent) Get(key string) (any, bool) {
|
||||
return (*sync.Map)(cm).Load(key)
|
||||
cm.RLock()
|
||||
defer cm.RUnlock()
|
||||
|
||||
if cm.data == nil {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
value, ok := cm.data[key]
|
||||
return value, ok
|
||||
}
|
||||
|
||||
func (cm *Concurrent) Delete(key string) {
|
||||
(*sync.Map)(cm).Delete(key)
|
||||
cm.Lock()
|
||||
defer cm.Unlock()
|
||||
|
||||
delete(cm.data, key)
|
||||
}
|
||||
|
||||
func (cm *Concurrent) Contains(key string) bool {
|
||||
_, ok := (*sync.Map)(cm).Load(key)
|
||||
_, ok := cm.Get(key)
|
||||
return ok
|
||||
}
|
||||
|
||||
func (cm *Concurrent) ToSimple() Simple {
|
||||
list := make(map[string]any)
|
||||
(*sync.Map)(cm).Range(func(key, value any) bool {
|
||||
list[key.(string)] = value
|
||||
return true
|
||||
})
|
||||
return list
|
||||
cm.RLock()
|
||||
defer cm.RUnlock()
|
||||
|
||||
return cm.data
|
||||
}
|
||||
|
|
|
@ -3,9 +3,7 @@ package maps
|
|||
type Simple map[string]any
|
||||
|
||||
func (m Simple) ToConcurrent() *Concurrent {
|
||||
var cm Concurrent
|
||||
for k, v := range m {
|
||||
cm.Set(k, v)
|
||||
return &Concurrent{
|
||||
data: m,
|
||||
}
|
||||
return &cm
|
||||
}
|
||||
|
|
|
@ -37,10 +37,10 @@ type Terminal struct {
|
|||
deviceCache *cache.File
|
||||
sessionCache *cache.File
|
||||
tmplCache *cache.Template
|
||||
lsDirMap maps.Concurrent
|
||||
cwd string
|
||||
host string
|
||||
networks []*Connection
|
||||
lsDirMap maps.Concurrent
|
||||
}
|
||||
|
||||
func (term *Terminal) Init() {
|
||||
|
|
Loading…
Reference in a new issue