Skip to content

Commit

Permalink
refactor: remove vertical_offset for transient prompt
Browse files Browse the repository at this point in the history
relates to #807
  • Loading branch information
JanDeDobbeleer committed Jun 23, 2021
1 parent fb83354 commit 3fd70ce
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
2 changes: 0 additions & 2 deletions docs/docs/beta.mdx
Expand Up @@ -123,8 +123,6 @@ The configuration has the following properties:
- foreground: `string` [color][colors]
- template: `string` - A go [text/template][go-text-template] template extended with [sprig][sprig] utilizing the
properties below. Defaults to `{{ .Shell }}> <#f7dc66>{{ .Command }}</>`
- vertical_offset: `int` - Move the prompt up or down x lines. For example `vertical_offset: 1` moves the prompt down one line, `vertical_offset: -1`
moves it up one line. Useful when you have a multiline prompt. Defaults to `0`

#### Template Properties

Expand Down
7 changes: 3 additions & 4 deletions src/config.go
Expand Up @@ -32,10 +32,9 @@ type Config struct {
}

type TransientPrompt struct {
Template string `config:"template"`
Background string `config:"background"`
Foreground string `config:"foreground"`
VerticalOffset int `config:"vertical_offset"`
Template string `config:"template"`
Background string `config:"background"`
Foreground string `config:"foreground"`
}

const (
Expand Down
11 changes: 9 additions & 2 deletions src/engine.go
Expand Up @@ -232,8 +232,15 @@ func (e *engine) renderTransientPrompt(command string) string {
prompt := template.renderPlainContextTemplate(context)
e.colorWriter.write(e.config.TransientPrompt.Background, e.config.TransientPrompt.Foreground, prompt)
transientPrompt := e.ansi.carriageBackward()
if e.config.TransientPrompt.VerticalOffset != 0 {
transientPrompt += e.ansi.changeLine(e.config.TransientPrompt.VerticalOffset)
// calculate offset for multiline prompt
lineOffset := 0
for _, block := range e.config.Blocks {
if block.Newline {
lineOffset--
}
}
if lineOffset != 0 {
transientPrompt += e.ansi.changeLine(lineOffset)
}
return transientPrompt + e.colorWriter.string() + e.ansi.clearEOL
}
5 changes: 0 additions & 5 deletions themes/schema.json
Expand Up @@ -1601,11 +1601,6 @@
"title": "Transient Prompt Template",
"default": "{{ .Shell }}> <#f7dc66>{{ .Command }}</>"
},
"vertical_offset": {
"type": "integer",
"title": "Transient Prompt vertical offset",
"default": 0
},
"background": { "$ref": "#/definitions/color" },
"foreground": { "$ref": "#/definitions/color" }
}
Expand Down

0 comments on commit 3fd70ce

Please sign in to comment.