diff --git a/src/prompt/engine.go b/src/prompt/engine.go index e97fc6cc5d0e..19f65b81c562 100644 --- a/src/prompt/engine.go +++ b/src/prompt/engine.go @@ -541,6 +541,11 @@ func (e *Engine) rectifyTerminalWidth(diff int) { e.Env.Flags().TerminalWidth += diff } +func (e *Engine) cancelNewline() bool { + row, _ := e.Env.CursorPosition() + return e.Env.Flags().Cleared || e.Env.Flags().PromptCount == 1 || row == 1 +} + // New returns a prompt engine initialized with the // given configuration options, and is ready to print any // of the prompt components. diff --git a/src/prompt/extra.go b/src/prompt/extra.go index 072c83174278..6a506736add8 100644 --- a/src/prompt/extra.go +++ b/src/prompt/extra.go @@ -61,7 +61,7 @@ func (e *Engine) ExtraPrompt(promptType ExtraPromptType) string { promptText = err.Error() } - if promptType == Transient && prompt.Newline { + if promptType == Transient && prompt.Newline && !e.cancelNewline() { promptText = fmt.Sprintf("%s%s", e.getNewline(), promptText) } diff --git a/src/prompt/primary.go b/src/prompt/primary.go index 227b7e5b9bab..130b6e4315e0 100644 --- a/src/prompt/primary.go +++ b/src/prompt/primary.go @@ -73,8 +73,7 @@ func (e *Engine) writePrimaryPromptInternal(needsPrimaryRPrompt, fromCache bool) for i, block := range blocks { // do not print a leading newline when we're at the first row and the prompt is cleared if i == 0 { - row, _ := e.Env.CursorPosition() - cancelNewline = e.Env.Flags().Cleared || e.Env.Flags().PromptCount == 1 || row == 1 + cancelNewline = e.cancelNewline() } // skip setting a newline when we didn't print anything yet diff --git a/website/docs/configuration/transient.mdx b/website/docs/configuration/transient.mdx index df21315cdd1d..7e1f65e54a99 100644 --- a/website/docs/configuration/transient.mdx +++ b/website/docs/configuration/transient.mdx @@ -49,7 +49,7 @@ You need to extend or create a custom theme with your transient prompt. For exam | `background_templates` | `array` | [color templates][color-templates] | | `template` | `string` | a go [text/template][go-text-template] template extended with [sprig][sprig] utilizing the properties below - defaults to `{{ .Shell }}> ` | | `filler` | `string` | when you want to create a line with a repeated set of characters spanning the width of the terminal. Will be added _after_ the `template` text | -| `newline` | `boolean` | add a newline before the prompt | +| `newline` | `boolean` | add a newline before the prompt. The newline will not be printed under the same conditions as for primary prompt [newlines][block-newline]. | ## Enable the feature @@ -67,3 +67,4 @@ clink set prompt.transient always [templates]: /docs/configuration/templates [color-templates]: /docs/configuration/colors#color-templates [cstp]: /docs/configuration/templates#cross-segment-template-properties +[block-newline]: /docs/configuration/block#newline