fix(warp): support rprompt

This commit is contained in:
Jan De Dobbeleer 2022-12-08 11:30:21 +01:00 committed by Jan De Dobbeleer
parent 1e50107ff6
commit 2cba140522

View file

@ -104,8 +104,7 @@ func (e *Engine) printPWD() {
func (e *Engine) newline() {
// WARP terminal will remove \n from the prompt, so we hack a newline in
if e.Env.Getenv("TERM_PROGRAM") == "WarpTerminal" {
// fmt.Println("TERM_PROGRAM")
if e.isWarp() {
e.write(e.Ansi.LineBreak())
} else {
e.write("\n")
@ -113,6 +112,10 @@ func (e *Engine) newline() {
e.currentLineLength = 0
}
func (e *Engine) isWarp() bool {
return e.Env.Getenv("TERM_PROGRAM") == "WarpTerminal"
}
func (e *Engine) shouldFill(block *Block, length int) (string, bool) {
if len(block.Filler) == 0 {
return "", false
@ -271,6 +274,17 @@ func (e *Engine) print() string {
if !e.Env.Flags().Eval {
break
}
// Warp doesn't support RPROMPT so we need to write it manually
if e.isWarp() {
e.write(e.Ansi.SaveCursorPosition())
e.write(e.Ansi.CarriageForward())
e.write(e.Ansi.GetCursorForRightWrite(e.rpromptLength, 0))
e.write(e.rprompt)
e.write(e.Ansi.RestoreCursorPosition())
// escape double quotes contained in the prompt
prompt := fmt.Sprintf("PS1=\"%s\"", strings.ReplaceAll(e.string(), `"`, `\"`))
return prompt
}
// escape double quotes contained in the prompt
prompt := fmt.Sprintf("PS1=\"%s\"", strings.ReplaceAll(e.string(), `"`, `\"`))
prompt += fmt.Sprintf("\nRPROMPT=\"%s\"", e.rprompt)