refactor: better engine write function

This commit is contained in:
Jan De Dobbeleer 2020-12-23 13:31:21 +01:00 committed by Jan De Dobbeleer
parent 8e226ac332
commit eb42e0c93a

View file

@ -166,21 +166,22 @@ func (e *engine) render() {
} }
func (e *engine) write() { func (e *engine) write() {
switch e.env.getShellName() {
case zsh:
if *e.env.getArgs().Eval { if *e.env.getArgs().Eval {
fmt.Printf("PS1=\"%s\"", e.renderer.string()) fmt.Printf("PS1=\"%s\"", e.renderer.string())
if e.env.getShellName() == zsh {
fmt.Printf("\nRPROMPT=\"%s\"", e.rprompt) fmt.Printf("\nRPROMPT=\"%s\"", e.rprompt)
}
return return
} }
case pwsh, powershell5, bash:
if e.rprompt != "" && (e.env.getShellName() == pwsh || e.env.getShellName() == powershell5) { if e.rprompt != "" {
e.renderer.saveCursorPosition() e.renderer.saveCursorPosition()
e.renderer.carriageForward() e.renderer.carriageForward()
e.renderer.setCursorForRightWrite(e.rprompt, 0) e.renderer.setCursorForRightWrite(e.rprompt, 0)
e.renderer.print(e.rprompt) e.renderer.print(e.rprompt)
e.renderer.restoreCursorPosition() e.renderer.restoreCursorPosition()
} }
}
fmt.Print(e.renderer.string()) fmt.Print(e.renderer.string())
} }