refactor: render segment text in sequence

This commit is contained in:
Jan De Dobbeleer 2024-08-05 14:28:47 +02:00 committed by Jan De Dobbeleer
parent 9e1942035f
commit 0853a527a7
3 changed files with 6 additions and 18 deletions

View file

@ -79,7 +79,6 @@ func (b *Block) executeSegmentLogic() {
}
b.setEnabledSegments()
b.setSegmentsText()
}
func (b *Block) setEnabledSegments() {
@ -94,15 +93,3 @@ func (b *Block) setEnabledSegments() {
}(segment)
}
}
func (b *Block) setSegmentsText() {
wg := sync.WaitGroup{}
wg.Add(len(b.Segments))
defer wg.Wait()
for _, segment := range b.Segments {
go func(s *Segment) {
defer wg.Done()
s.setText()
}(segment)
}
}

View file

@ -59,9 +59,8 @@ type Segment struct {
Newline bool `json:"newline,omitempty" toml:"newline,omitempty"`
CacheDuration cache.Duration `json:"cache_duration,omitempty" toml:"cache_duration,omitempty"`
Enabled bool `json:"-" toml:"-"`
Text string `json:"-" toml:"-"`
Enabled bool `json:"-" toml:"-"`
Text string `json:"-" toml:"-"`
env runtime.Environment
writer SegmentWriter
@ -205,8 +204,8 @@ func (segment *Segment) writerCacheKey() string {
return fmt.Sprintf("segment_cache_writer_%s_%s", segment.Name(), segment.env.Pwd())
}
func (segment *Segment) setText() {
if !segment.Enabled || len(segment.Text) != 0 {
func (segment *Segment) SetText() {
if !segment.Enabled {
return
}

View file

@ -323,6 +323,8 @@ func (e *Engine) filterSegments(block *config.Block) {
segments := make([]*config.Segment, 0)
for _, segment := range block.Segments {
segment.SetText()
if !segment.Enabled && segment.ResolveStyle() != config.Accordion {
continue
}