mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-27 03:49:40 -08:00
fix: ignore segments without writer
This commit is contained in:
parent
a639240f9c
commit
db212d513f
|
@ -90,8 +90,8 @@ func (e *engine) renderBlockSegments(block *Block) string {
|
|||
defer e.reset()
|
||||
e.activeBlock = block
|
||||
for _, segment := range block.Segments {
|
||||
props := segment.mapSegmentWithWriter(e.env)
|
||||
if !segment.enabled() {
|
||||
props, err := segment.mapSegmentWithWriter(e.env)
|
||||
if err != nil || !segment.enabled() {
|
||||
continue
|
||||
}
|
||||
e.activeSegment = segment
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package main
|
||||
|
||||
import "errors"
|
||||
|
||||
//Segment represent a single segment and it's configuration
|
||||
type Segment struct {
|
||||
Type SegmentType `json:"type"`
|
||||
|
@ -68,7 +70,7 @@ func (segment *Segment) enabled() bool {
|
|||
return segment.writer.enabled()
|
||||
}
|
||||
|
||||
func (segment *Segment) mapSegmentWithWriter(env environmentInfo) *properties {
|
||||
func (segment *Segment) mapSegmentWithWriter(env environmentInfo) (*properties, error) {
|
||||
functions := map[SegmentType]SegmentWriter{
|
||||
Session: &session{},
|
||||
Path: &path{},
|
||||
|
@ -92,7 +94,7 @@ func (segment *Segment) mapSegmentWithWriter(env environmentInfo) *properties {
|
|||
}
|
||||
writer.init(props, env)
|
||||
segment.writer = writer
|
||||
return props
|
||||
return props, nil
|
||||
}
|
||||
return nil
|
||||
return nil, errors.New("Unable to map writer")
|
||||
}
|
||||
|
|
|
@ -11,7 +11,9 @@ func TestMapSegmentWriterCanMap(t *testing.T) {
|
|||
Type: Session,
|
||||
}
|
||||
env := new(MockedEnvironment)
|
||||
sc.mapSegmentWithWriter(env)
|
||||
props, err := sc.mapSegmentWithWriter(env)
|
||||
assert.NotNil(t, props)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, sc.writer)
|
||||
}
|
||||
|
||||
|
@ -20,6 +22,7 @@ func TestMapSegmentWriterCannotMap(t *testing.T) {
|
|||
Type: "nilwriter",
|
||||
}
|
||||
env := new(MockedEnvironment)
|
||||
sc.mapSegmentWithWriter(env)
|
||||
assert.Nil(t, sc.writer)
|
||||
props, err := sc.mapSegmentWithWriter(env)
|
||||
assert.Nil(t, props)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue