diff --git a/src/config/segment.go b/src/config/segment.go index 2b9d88ea..0681d5b4 100644 --- a/src/config/segment.go +++ b/src/config/segment.go @@ -55,7 +55,7 @@ type Segment struct { Filler string `json:"filler,omitempty" toml:"filler,omitempty"` Background color.Ansi `json:"background" toml:"background"` Foreground color.Ansi `json:"foreground" toml:"foreground"` - // color.Set + Newline bool `json:"newline,omitempty" toml:"newline,omitempty"` Enabled bool `json:"-" toml:"-"` diff --git a/src/prompt/engine.go b/src/prompt/engine.go index 3664a63c..a3b469b2 100644 --- a/src/prompt/engine.go +++ b/src/prompt/engine.go @@ -119,26 +119,28 @@ func (e *Engine) pwd() { e.write(terminal.Pwd(pwdType, user, host, cwd)) } -func (e *Engine) newline() { - defer func() { - e.currentLineLength = 0 - }() - +func (e *Engine) getNewline() string { // WARP terminal will remove \n from the prompt, so we hack a newline in if e.isWarp() { - e.write(terminal.LineBreak()) - return + return terminal.LineBreak() } // TCSH needs a space before the LITERAL newline character or it will not render correctly // don't ask why, it be like that sometimes. // https://unix.stackexchange.com/questions/99101/properly-defining-a-multi-line-prompt-in-tcsh#comment1342462_322189 if e.Env.Shell() == shell.TCSH { - e.write(` \n`) - return + return ` \n` } - e.write("\n") + return "\n" +} + +func (e *Engine) writeNewline() { + defer func() { + e.currentLineLength = 0 + }() + + e.write(e.getNewline()) } func (e *Engine) isWarp() bool { @@ -192,7 +194,7 @@ func (e *Engine) renderBlock(block *config.Block, cancelNewline bool) bool { // when we're printin the first primary prompt in // the shell if !cancelNewline { - e.newline() + e.writeNewline() } return false } @@ -213,7 +215,7 @@ func (e *Engine) renderBlock(block *config.Block, cancelNewline bool) bool { // when we're printin the first primary prompt in // the shell if block.Newline && !cancelNewline { - e.newline() + e.writeNewline() } text, length := e.renderBlockSegments(block) @@ -244,7 +246,7 @@ func (e *Engine) renderBlock(block *config.Block, cancelNewline bool) bool { if !OK { switch block.Overflow { case config.Break: - e.newline() + e.writeNewline() case config.Hide: // make sure to fill if needed if padText, OK := e.shouldFill(block.Filler, space, 0); OK { diff --git a/src/prompt/extra.go b/src/prompt/extra.go index 927869d3..6eacb791 100644 --- a/src/prompt/extra.go +++ b/src/prompt/extra.go @@ -58,6 +58,10 @@ func (e *Engine) ExtraPrompt(promptType ExtraPromptType) string { promptText = err.Error() } + if promptType == Transient && prompt.Newline { + promptText = fmt.Sprintf("%s%s", e.getNewline(), promptText) + } + if promptType == Transient && e.Config.ShellIntegration { exitCode, _ := e.Env.StatusCodes() e.write(terminal.CommandFinished(exitCode, e.Env.Flags().NoExitCode)) diff --git a/themes/schema.json b/themes/schema.json index 3e5f57c6..aea8e579 100644 --- a/themes/schema.json +++ b/themes/schema.json @@ -4808,6 +4808,12 @@ "type": "string", "title": "Filler", "description": "Right aligned filler text, will span the remaining width" + }, + "newline": { + "type": "boolean", + "title": "Newline", + "description": "Add a newline before the prompt", + "default": false } } }, diff --git a/website/docs/configuration/transient.mdx b/website/docs/configuration/transient.mdx index dfc0fbef..c0f9d51c 100644 --- a/website/docs/configuration/transient.mdx +++ b/website/docs/configuration/transient.mdx @@ -44,14 +44,15 @@ You need to extend or create a custom theme with your transient prompt. For exam ## Properties -| Name | Type | Description | -| ---------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | -| `foreground` | `string` | [color][colors] | -| `foreground_templates` | `array` | [color templates][color-templates] | -| `background` | `string` | [color][colors] | -| `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 | +| Name | Type | Description | +| ---------------------- | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | +| `foreground` | `string` | [color][colors] | +| `foreground_templates` | `array` | [color templates][color-templates] | +| `background` | `string` | [color][colors] | +| `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 | ## Enable the feature