mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-11-14 23:14:05 -08:00
refactor: remove linebreak block type
This commit is contained in:
parent
b5afe0edaf
commit
f1cd609c7d
|
@ -18,8 +18,6 @@ type Overflow string
|
||||||
const (
|
const (
|
||||||
// Prompt writes one or more Segments
|
// Prompt writes one or more Segments
|
||||||
Prompt BlockType = "prompt"
|
Prompt BlockType = "prompt"
|
||||||
// LineBreak creates a line break in the prompt
|
|
||||||
LineBreak BlockType = "newline"
|
|
||||||
// RPrompt is a right aligned prompt
|
// RPrompt is a right aligned prompt
|
||||||
RPrompt BlockType = "rprompt"
|
RPrompt BlockType = "rprompt"
|
||||||
// Left aligns left
|
// Left aligns left
|
||||||
|
@ -53,10 +51,6 @@ func (b *Block) Init(env runtime.Environment) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Block) Enabled() bool {
|
func (b *Block) Enabled() bool {
|
||||||
if b.Type == LineBreak {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, segment := range b.Segments {
|
for _, segment := range b.Segments {
|
||||||
if segment.Enabled {
|
if segment.Enabled {
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -13,7 +13,6 @@ func TestBlockEnabled(t *testing.T) {
|
||||||
Segments []*Segment
|
Segments []*Segment
|
||||||
Expected bool
|
Expected bool
|
||||||
}{
|
}{
|
||||||
{Case: "line break block", Expected: true, Type: LineBreak},
|
|
||||||
{Case: "prompt enabled", Expected: true, Type: Prompt, Segments: []*Segment{{Enabled: true}}},
|
{Case: "prompt enabled", Expected: true, Type: Prompt, Segments: []*Segment{{Enabled: true}}},
|
||||||
{Case: "prompt disabled", Expected: false, Type: Prompt, Segments: []*Segment{{Enabled: false}}},
|
{Case: "prompt disabled", Expected: false, Type: Prompt, Segments: []*Segment{{Enabled: false}}},
|
||||||
{Case: "prompt enabled multiple", Expected: true, Type: Prompt, Segments: []*Segment{{Enabled: false}, {Enabled: true}}},
|
{Case: "prompt enabled multiple", Expected: true, Type: Prompt, Segments: []*Segment{{Enabled: false}, {Enabled: true}}},
|
||||||
|
|
|
@ -168,19 +168,6 @@ func (e *Engine) getTitleTemplateText() string {
|
||||||
func (e *Engine) renderBlock(block *config.Block, cancelNewline bool) bool {
|
func (e *Engine) renderBlock(block *config.Block, cancelNewline bool) bool {
|
||||||
defer e.applyPowerShellBleedPatch()
|
defer e.applyPowerShellBleedPatch()
|
||||||
|
|
||||||
// This is deprecated but we leave it in to not break configs
|
|
||||||
// It is encouraged to use "newline": true on block level
|
|
||||||
// rather than the standalone linebreak block
|
|
||||||
if block.Type == config.LineBreak {
|
|
||||||
// do not print a newline to avoid a leading space
|
|
||||||
// when we're printing the first primary prompt in
|
|
||||||
// the shell
|
|
||||||
if !cancelNewline {
|
|
||||||
e.writeNewline()
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
block.Init(e.Env)
|
block.Init(e.Env)
|
||||||
|
|
||||||
if !block.Enabled() {
|
if !block.Enabled() {
|
||||||
|
@ -201,7 +188,7 @@ func (e *Engine) renderBlock(block *config.Block, cancelNewline bool) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
switch block.Type { //nolint:exhaustive
|
switch block.Type {
|
||||||
case config.Prompt:
|
case config.Prompt:
|
||||||
if block.Alignment == config.Left {
|
if block.Alignment == config.Left {
|
||||||
e.currentLineLength += length
|
e.currentLineLength += length
|
||||||
|
|
Loading…
Reference in a new issue