Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/prompt/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/prompt/extra.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
3 changes: 1 addition & 2 deletions src/prompt/primary.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion website/docs/configuration/transient.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Loading