mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-03-05 20:49:04 -08:00
feat(transient): allow setting a newline
This commit is contained in:
parent
67b7e6a959
commit
8b6933160a
|
@ -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:"-"`
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue