2022-01-26 23:38:46 -08:00
|
|
|
package engine
|
2019-03-13 04:14:30 -07:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2022-01-26 04:09:21 -08:00
|
|
|
"oh-my-posh/color"
|
2022-01-26 22:44:35 -08:00
|
|
|
"oh-my-posh/console"
|
2022-01-26 01:23:18 -08:00
|
|
|
"oh-my-posh/environment"
|
2022-03-21 23:41:36 -07:00
|
|
|
"oh-my-posh/shell"
|
2022-01-26 06:54:36 -08:00
|
|
|
"oh-my-posh/template"
|
2021-03-20 00:49:49 -07:00
|
|
|
"strings"
|
2020-12-27 08:53:58 -08:00
|
|
|
"time"
|
2019-03-13 04:14:30 -07:00
|
|
|
)
|
|
|
|
|
2022-01-26 23:38:46 -08:00
|
|
|
type Engine struct {
|
|
|
|
Config *Config
|
|
|
|
Env environment.Environment
|
|
|
|
Writer color.Writer
|
|
|
|
Ansi *color.Ansi
|
|
|
|
ConsoleTitle *console.Title
|
|
|
|
Plain bool
|
2021-04-20 12:30:46 -07:00
|
|
|
|
2022-02-03 08:36:37 -08:00
|
|
|
console strings.Builder
|
|
|
|
currentLineLength int
|
|
|
|
rprompt string
|
|
|
|
rpromptLength int
|
2020-10-12 23:57:46 -07:00
|
|
|
}
|
|
|
|
|
2022-01-26 23:38:46 -08:00
|
|
|
func (e *Engine) write(text string) {
|
2021-04-20 12:30:46 -07:00
|
|
|
e.console.WriteString(text)
|
|
|
|
}
|
|
|
|
|
2022-01-26 23:38:46 -08:00
|
|
|
func (e *Engine) writeANSI(text string) {
|
|
|
|
if e.Plain {
|
2021-11-02 06:53:46 -07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
e.console.WriteString(text)
|
|
|
|
}
|
|
|
|
|
2022-01-26 23:38:46 -08:00
|
|
|
func (e *Engine) string() string {
|
2021-04-20 12:30:46 -07:00
|
|
|
return e.console.String()
|
|
|
|
}
|
|
|
|
|
2022-01-26 23:38:46 -08:00
|
|
|
func (e *Engine) canWriteRPrompt() bool {
|
|
|
|
consoleWidth, err := e.Env.TerminalWidth()
|
2021-05-25 09:31:23 -07:00
|
|
|
if err != nil || consoleWidth == 0 {
|
2021-05-22 07:50:34 -07:00
|
|
|
return true
|
|
|
|
}
|
2022-02-03 08:36:37 -08:00
|
|
|
promptWidth := e.currentLineLength
|
2021-05-22 07:50:34 -07:00
|
|
|
availableSpace := consoleWidth - promptWidth
|
2021-09-16 23:15:06 -07:00
|
|
|
// spanning multiple lines
|
|
|
|
if availableSpace < 0 {
|
|
|
|
overflow := promptWidth % consoleWidth
|
|
|
|
availableSpace = consoleWidth - overflow
|
2021-05-22 07:50:34 -07:00
|
|
|
}
|
|
|
|
promptBreathingRoom := 30
|
2022-02-03 08:36:37 -08:00
|
|
|
canWrite := (availableSpace - e.rpromptLength) >= promptBreathingRoom
|
2021-09-16 23:15:06 -07:00
|
|
|
return canWrite
|
2021-05-22 07:50:34 -07:00
|
|
|
}
|
|
|
|
|
2022-03-12 13:04:08 -08:00
|
|
|
func (e *Engine) PrintPrimary() string {
|
2022-01-26 23:38:46 -08:00
|
|
|
for _, block := range e.Config.Blocks {
|
2021-04-18 10:16:06 -07:00
|
|
|
e.renderBlock(block)
|
2019-03-13 04:14:30 -07:00
|
|
|
}
|
2022-03-14 11:14:10 -07:00
|
|
|
if len(e.Config.ConsoleTitleTemplate) > 0 {
|
2022-01-26 23:38:46 -08:00
|
|
|
e.writeANSI(e.ConsoleTitle.GetTitle())
|
2020-10-12 00:02:33 -07:00
|
|
|
}
|
2022-01-26 23:38:46 -08:00
|
|
|
e.writeANSI(e.Ansi.ColorReset())
|
|
|
|
if e.Config.FinalSpace {
|
2021-04-20 12:30:46 -07:00
|
|
|
e.write(" ")
|
2019-03-13 04:14:30 -07:00
|
|
|
}
|
2022-01-26 23:38:46 -08:00
|
|
|
if !e.Config.OSC99 {
|
2021-04-04 11:28:41 -07:00
|
|
|
return e.print()
|
2021-02-15 13:19:19 -08:00
|
|
|
}
|
2022-01-26 23:38:46 -08:00
|
|
|
cwd := e.Env.Pwd()
|
|
|
|
e.writeANSI(e.Ansi.ConsolePwd(cwd))
|
2021-04-04 11:28:41 -07:00
|
|
|
return e.print()
|
2020-12-17 23:59:45 -08:00
|
|
|
}
|
|
|
|
|
2022-02-03 08:36:37 -08:00
|
|
|
func (e *Engine) newline() {
|
|
|
|
e.write("\n")
|
|
|
|
e.currentLineLength = 0
|
|
|
|
}
|
|
|
|
|
2022-02-12 09:40:02 -08:00
|
|
|
func (e *Engine) shouldFill(block *Block, length int) (string, bool) {
|
|
|
|
if len(block.Filler) == 0 {
|
|
|
|
return "", false
|
|
|
|
}
|
|
|
|
terminalWidth, err := e.Env.TerminalWidth()
|
|
|
|
if err != nil && terminalWidth == 0 {
|
|
|
|
return "", false
|
|
|
|
}
|
|
|
|
padLength := terminalWidth - e.currentLineLength - length
|
|
|
|
if padLength <= 0 {
|
|
|
|
return "", false
|
|
|
|
}
|
|
|
|
e.Writer.Write("", "", block.Filler)
|
|
|
|
filler, lenFiller := e.Writer.String()
|
|
|
|
e.Writer.Reset()
|
|
|
|
if lenFiller == 0 {
|
|
|
|
return "", false
|
|
|
|
}
|
|
|
|
repeat := padLength / lenFiller
|
|
|
|
return strings.Repeat(filler, repeat), true
|
|
|
|
}
|
|
|
|
|
2022-01-26 23:38:46 -08:00
|
|
|
func (e *Engine) renderBlock(block *Block) {
|
2021-05-21 13:10:20 -07:00
|
|
|
// when in bash, for rprompt blocks we need to write plain
|
|
|
|
// and wrap in escaped mode or the prompt will not render correctly
|
2022-03-21 23:41:36 -07:00
|
|
|
if block.Type == RPrompt && e.Env.Shell() == shell.BASH {
|
2022-05-05 23:41:58 -07:00
|
|
|
block.InitPlain(e.Env, e.Config)
|
2021-05-21 13:10:20 -07:00
|
|
|
} else {
|
2022-05-05 23:41:58 -07:00
|
|
|
block.Init(e.Env, e.Writer, e.Ansi)
|
2021-05-21 13:10:20 -07:00
|
|
|
}
|
2022-05-05 23:41:58 -07:00
|
|
|
if !block.Enabled() {
|
2021-04-18 10:16:06 -07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if block.Newline {
|
2022-02-03 08:36:37 -08:00
|
|
|
e.newline()
|
2021-04-18 10:16:06 -07:00
|
|
|
}
|
|
|
|
switch block.Type {
|
|
|
|
// This is deprecated but leave if to not break current configs
|
|
|
|
// It is encouraged to used "newline": true on block level
|
|
|
|
// rather than the standalone the linebreak block
|
|
|
|
case LineBreak:
|
2022-02-03 08:36:37 -08:00
|
|
|
e.newline()
|
2021-04-18 10:16:06 -07:00
|
|
|
case Prompt:
|
|
|
|
if block.VerticalOffset != 0 {
|
2022-01-26 23:38:46 -08:00
|
|
|
e.writeANSI(e.Ansi.ChangeLine(block.VerticalOffset))
|
2021-04-18 10:16:06 -07:00
|
|
|
}
|
|
|
|
switch block.Alignment {
|
|
|
|
case Right:
|
2022-05-07 01:12:22 -07:00
|
|
|
text, length := block.RenderSegments()
|
2022-02-12 09:40:02 -08:00
|
|
|
if padText, OK := e.shouldFill(block, length); OK {
|
2022-02-04 08:22:40 -08:00
|
|
|
e.write(padText)
|
|
|
|
}
|
|
|
|
e.writeANSI(e.Ansi.CarriageForward())
|
2022-02-03 08:36:37 -08:00
|
|
|
e.writeANSI(e.Ansi.GetCursorForRightWrite(length, block.HorizontalOffset))
|
2022-02-04 08:22:40 -08:00
|
|
|
e.currentLineLength = 0
|
2022-02-03 08:36:37 -08:00
|
|
|
e.write(text)
|
2021-04-18 10:16:06 -07:00
|
|
|
case Left:
|
2022-05-07 01:12:22 -07:00
|
|
|
text, length := block.RenderSegments()
|
2022-02-03 08:36:37 -08:00
|
|
|
e.currentLineLength += length
|
|
|
|
e.write(text)
|
2021-04-18 10:16:06 -07:00
|
|
|
}
|
|
|
|
case RPrompt:
|
2022-05-07 01:12:22 -07:00
|
|
|
text, length := block.RenderSegments()
|
2022-02-03 08:36:37 -08:00
|
|
|
e.rpromptLength = length
|
2022-03-21 23:41:36 -07:00
|
|
|
if e.Env.Shell() == shell.BASH {
|
2022-02-03 08:36:37 -08:00
|
|
|
text = e.Ansi.FormatText(text)
|
2021-05-21 13:10:20 -07:00
|
|
|
}
|
2022-02-03 08:36:37 -08:00
|
|
|
e.rprompt = text
|
2021-04-18 10:16:06 -07:00
|
|
|
}
|
2021-04-21 12:20:18 -07:00
|
|
|
// Due to a bug in Powershell, the end of the line needs to be cleared.
|
|
|
|
// If this doesn't happen, the portion after the prompt gets colored in the background
|
|
|
|
// color of the line above the new input line. Clearing the line fixes this,
|
|
|
|
// but can hopefully one day be removed when this is resolved natively.
|
2022-03-21 23:41:36 -07:00
|
|
|
if e.Env.Shell() == shell.PWSH || e.Env.Shell() == shell.PWSH5 {
|
2022-01-26 23:38:46 -08:00
|
|
|
e.writeANSI(e.Ansi.ClearAfter())
|
2021-04-21 12:20:18 -07:00
|
|
|
}
|
2021-04-18 10:16:06 -07:00
|
|
|
}
|
|
|
|
|
2021-01-09 07:18:37 -08:00
|
|
|
// debug will loop through your config file and output the timings for each segments
|
2022-05-05 23:41:58 -07:00
|
|
|
func (e *Engine) PrintDebug(startTime time.Time, version string) string {
|
2021-04-18 10:16:06 -07:00
|
|
|
var segmentTimings []*SegmentTiming
|
2020-12-31 05:00:46 -08:00
|
|
|
largestSegmentNameLength := 0
|
2022-01-26 23:38:46 -08:00
|
|
|
e.write(fmt.Sprintf("\n\x1b[1mVersion:\x1b[0m %s\n", version))
|
2021-11-16 10:59:42 -08:00
|
|
|
e.write("\n\x1b[1mSegments:\x1b[0m\n\n")
|
2021-01-14 21:10:36 -08:00
|
|
|
// console title timing
|
2022-05-07 01:12:22 -07:00
|
|
|
titleStartTime := time.Now()
|
2022-03-14 11:14:10 -07:00
|
|
|
title := e.ConsoleTitle.GetTitle()
|
|
|
|
title = strings.TrimPrefix(title, "\x1b]0;")
|
|
|
|
title = strings.TrimSuffix(title, "\a")
|
2021-04-18 10:16:06 -07:00
|
|
|
segmentTiming := &SegmentTiming{
|
2022-02-02 03:16:39 -08:00
|
|
|
name: "ConsoleTitle",
|
|
|
|
nameLength: 12,
|
2022-03-14 11:14:10 -07:00
|
|
|
active: len(e.Config.ConsoleTitleTemplate) > 0,
|
|
|
|
text: title,
|
2022-05-07 01:12:22 -07:00
|
|
|
duration: time.Since(titleStartTime),
|
2021-01-14 21:10:36 -08:00
|
|
|
}
|
|
|
|
segmentTimings = append(segmentTimings, segmentTiming)
|
2020-12-27 08:53:58 -08:00
|
|
|
// loop each segments of each blocks
|
2022-01-26 23:38:46 -08:00
|
|
|
for _, block := range e.Config.Blocks {
|
2022-05-05 23:41:58 -07:00
|
|
|
block.Init(e.Env, e.Writer, e.Ansi)
|
2022-05-07 01:12:22 -07:00
|
|
|
longestSegmentName, timings := block.Debug()
|
2021-04-18 10:16:06 -07:00
|
|
|
segmentTimings = append(segmentTimings, timings...)
|
|
|
|
if longestSegmentName > largestSegmentNameLength {
|
|
|
|
largestSegmentNameLength = longestSegmentName
|
2020-12-27 08:53:58 -08:00
|
|
|
}
|
|
|
|
}
|
2021-01-14 21:10:36 -08:00
|
|
|
|
2020-12-31 05:00:46 -08:00
|
|
|
// pad the output so the tabs render correctly
|
|
|
|
largestSegmentNameLength += 7
|
2020-12-27 08:53:58 -08:00
|
|
|
for _, segment := range segmentTimings {
|
2022-02-02 03:16:39 -08:00
|
|
|
duration := segment.duration.Milliseconds()
|
|
|
|
segmentName := fmt.Sprintf("%s(%t)", segment.name, segment.active)
|
|
|
|
e.write(fmt.Sprintf("%-*s - %3d ms - %s\n", largestSegmentNameLength, segmentName, duration, segment.text))
|
2020-12-27 08:53:58 -08:00
|
|
|
}
|
2022-05-05 23:41:58 -07:00
|
|
|
e.write(fmt.Sprintf("\n\x1b[1mRun duration:\x1b[0m %s\n", time.Since(startTime)))
|
2022-01-26 23:38:46 -08:00
|
|
|
e.write(fmt.Sprintf("\n\x1b[1mCache path:\x1b[0m %s\n", e.Env.CachePath()))
|
2022-05-07 07:43:24 -07:00
|
|
|
e.write(fmt.Sprintf("\n\x1b[1mConfig path:\x1b[0m %s\n", e.Env.Flags().Config))
|
2021-11-16 10:59:42 -08:00
|
|
|
e.write("\n\x1b[1mLogs:\x1b[0m\n\n")
|
2022-01-26 23:38:46 -08:00
|
|
|
e.write(e.Env.Logs())
|
2021-04-20 12:30:46 -07:00
|
|
|
return e.string()
|
2020-12-27 08:53:58 -08:00
|
|
|
}
|
|
|
|
|
2022-01-26 23:38:46 -08:00
|
|
|
func (e *Engine) print() string {
|
|
|
|
switch e.Env.Shell() {
|
2022-03-21 23:41:36 -07:00
|
|
|
case shell.ZSH:
|
2022-03-12 13:04:08 -08:00
|
|
|
if !e.Env.Flags().Eval {
|
2021-05-21 13:10:20 -07:00
|
|
|
break
|
2020-12-23 04:31:21 -08:00
|
|
|
}
|
2021-05-21 13:10:20 -07:00
|
|
|
// escape double quotes contained in the prompt
|
2022-04-14 12:12:09 -07:00
|
|
|
prompt := fmt.Sprintf("PS1=\"%s\"", strings.ReplaceAll(e.string(), `"`, `\"`))
|
2021-05-21 13:10:20 -07:00
|
|
|
prompt += fmt.Sprintf("\nRPROMPT=\"%s\"", e.rprompt)
|
|
|
|
return prompt
|
2022-04-10 10:33:13 -07:00
|
|
|
case shell.PWSH, shell.PWSH5, shell.BASH, shell.PLAIN, shell.NU:
|
2022-01-26 23:38:46 -08:00
|
|
|
if e.rprompt == "" || !e.canWriteRPrompt() || e.Plain {
|
2021-05-21 13:10:20 -07:00
|
|
|
break
|
2020-12-17 23:59:45 -08:00
|
|
|
}
|
2022-01-26 23:38:46 -08:00
|
|
|
e.write(e.Ansi.SaveCursorPosition())
|
|
|
|
e.write(e.Ansi.CarriageForward())
|
2022-02-03 08:36:37 -08:00
|
|
|
e.write(e.Ansi.GetCursorForRightWrite(e.rpromptLength, 0))
|
2021-05-21 13:10:20 -07:00
|
|
|
e.write(e.rprompt)
|
2022-01-26 23:38:46 -08:00
|
|
|
e.write(e.Ansi.RestoreCursorPosition())
|
2020-12-15 05:58:15 -08:00
|
|
|
}
|
2021-04-20 12:30:46 -07:00
|
|
|
return e.string()
|
2019-03-13 04:14:30 -07:00
|
|
|
}
|
2021-06-05 07:14:44 -07:00
|
|
|
|
2022-03-12 13:04:08 -08:00
|
|
|
func (e *Engine) PrintTooltip(tip string) string {
|
2021-06-05 07:14:44 -07:00
|
|
|
tip = strings.Trim(tip, " ")
|
|
|
|
var tooltip *Segment
|
2022-01-26 23:38:46 -08:00
|
|
|
for _, tp := range e.Config.Tooltips {
|
2021-06-05 07:14:44 -07:00
|
|
|
if !tp.shouldInvokeWithTip(tip) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
tooltip = tp
|
|
|
|
}
|
|
|
|
if tooltip == nil {
|
|
|
|
return ""
|
|
|
|
}
|
2022-01-26 23:38:46 -08:00
|
|
|
if err := tooltip.mapSegmentWithWriter(e.Env); err != nil {
|
2021-06-05 07:14:44 -07:00
|
|
|
return ""
|
|
|
|
}
|
2022-02-02 03:16:39 -08:00
|
|
|
if !tooltip.writer.Enabled() {
|
2021-06-05 07:14:44 -07:00
|
|
|
return ""
|
|
|
|
}
|
2022-05-07 01:12:22 -07:00
|
|
|
tooltip.Enabled = true
|
2021-06-05 07:14:44 -07:00
|
|
|
// little hack to reuse the current logic
|
|
|
|
block := &Block{
|
|
|
|
Alignment: Right,
|
|
|
|
Segments: []*Segment{tooltip},
|
|
|
|
}
|
2022-01-26 23:38:46 -08:00
|
|
|
switch e.Env.Shell() {
|
2022-03-22 11:53:37 -07:00
|
|
|
case shell.ZSH, shell.CMD, shell.FISH:
|
2022-05-05 23:41:58 -07:00
|
|
|
block.Init(e.Env, e.Writer, e.Ansi)
|
2022-05-07 01:12:22 -07:00
|
|
|
text, _ := block.RenderSegments()
|
2022-02-03 08:36:37 -08:00
|
|
|
return text
|
2022-03-21 23:41:36 -07:00
|
|
|
case shell.PWSH, shell.PWSH5:
|
2022-05-05 23:41:58 -07:00
|
|
|
block.InitPlain(e.Env, e.Config)
|
2022-05-07 01:12:22 -07:00
|
|
|
text, length := block.RenderSegments()
|
2022-01-26 23:38:46 -08:00
|
|
|
e.write(e.Ansi.ClearAfter())
|
|
|
|
e.write(e.Ansi.CarriageForward())
|
2022-02-03 08:36:37 -08:00
|
|
|
e.write(e.Ansi.GetCursorForRightWrite(length, 0))
|
|
|
|
e.write(text)
|
2021-06-05 07:14:44 -07:00
|
|
|
return e.string()
|
|
|
|
}
|
2022-03-22 11:53:37 -07:00
|
|
|
return " "
|
2021-06-05 07:14:44 -07:00
|
|
|
}
|
2021-06-15 12:23:08 -07:00
|
|
|
|
2022-02-19 07:49:26 -08:00
|
|
|
type ExtraPromptType int
|
|
|
|
|
|
|
|
const (
|
|
|
|
Transient ExtraPromptType = iota
|
|
|
|
Valid
|
|
|
|
Error
|
2022-02-20 04:56:28 -08:00
|
|
|
Secondary
|
2022-03-15 12:16:04 -07:00
|
|
|
Debug
|
2022-02-19 07:49:26 -08:00
|
|
|
)
|
|
|
|
|
2022-03-12 13:04:08 -08:00
|
|
|
func (e *Engine) PrintExtraPrompt(promptType ExtraPromptType) string {
|
2022-03-27 06:38:12 -07:00
|
|
|
var prompt *Segment
|
2022-02-19 07:49:26 -08:00
|
|
|
switch promptType {
|
2022-03-15 12:16:04 -07:00
|
|
|
case Debug:
|
|
|
|
prompt = e.Config.DebugPrompt
|
2022-02-19 07:49:26 -08:00
|
|
|
case Transient:
|
|
|
|
prompt = e.Config.TransientPrompt
|
|
|
|
case Valid:
|
|
|
|
prompt = e.Config.ValidLine
|
|
|
|
case Error:
|
|
|
|
prompt = e.Config.ErrorLine
|
2022-02-20 04:56:28 -08:00
|
|
|
case Secondary:
|
|
|
|
prompt = e.Config.SecondaryPrompt
|
2022-02-19 07:49:26 -08:00
|
|
|
}
|
|
|
|
if prompt == nil {
|
2022-03-27 06:38:12 -07:00
|
|
|
prompt = &Segment{}
|
2021-09-09 11:02:30 -07:00
|
|
|
}
|
2022-02-19 07:49:26 -08:00
|
|
|
getTemplate := func(template string) string {
|
|
|
|
if len(template) != 0 {
|
|
|
|
return template
|
|
|
|
}
|
|
|
|
switch promptType { // nolint: exhaustive
|
2022-03-15 12:16:04 -07:00
|
|
|
case Debug:
|
|
|
|
return "[DBG]: "
|
2022-02-19 07:49:26 -08:00
|
|
|
case Transient:
|
|
|
|
return "{{ .Shell }}> "
|
2022-02-20 04:56:28 -08:00
|
|
|
case Secondary:
|
|
|
|
return "> "
|
2022-02-19 07:49:26 -08:00
|
|
|
default:
|
|
|
|
return ""
|
|
|
|
}
|
2021-06-15 12:23:08 -07:00
|
|
|
}
|
2022-01-26 06:54:36 -08:00
|
|
|
tmpl := &template.Text{
|
2022-02-19 07:49:26 -08:00
|
|
|
Template: getTemplate(prompt.Template),
|
2022-01-26 23:38:46 -08:00
|
|
|
Env: e.Env,
|
2021-06-15 12:23:08 -07:00
|
|
|
}
|
2022-02-19 07:49:26 -08:00
|
|
|
promptText, err := tmpl.Render()
|
2022-01-12 14:39:34 -08:00
|
|
|
if err != nil {
|
2022-02-19 07:49:26 -08:00
|
|
|
promptText = err.Error()
|
2022-01-12 14:39:34 -08:00
|
|
|
}
|
2022-03-24 04:53:20 -07:00
|
|
|
foreground := prompt.ForegroundTemplates.Resolve(nil, e.Env, prompt.Foreground)
|
|
|
|
background := prompt.BackgroundTemplates.Resolve(nil, e.Env, prompt.Background)
|
|
|
|
e.Writer.SetColors(background, foreground)
|
|
|
|
e.Writer.Write(background, foreground, promptText)
|
2022-01-26 23:38:46 -08:00
|
|
|
switch e.Env.Shell() {
|
2022-03-21 23:41:36 -07:00
|
|
|
case shell.ZSH:
|
2021-07-03 09:38:23 -07:00
|
|
|
// escape double quotes contained in the prompt
|
2022-02-03 08:36:37 -08:00
|
|
|
str, _ := e.Writer.String()
|
2022-02-20 04:56:28 -08:00
|
|
|
if promptType == Transient {
|
|
|
|
prompt := fmt.Sprintf("PS1=\"%s\"", strings.ReplaceAll(str, "\"", "\"\""))
|
|
|
|
// empty RPROMPT
|
|
|
|
prompt += "\nRPROMPT=\"\""
|
|
|
|
return prompt
|
|
|
|
}
|
|
|
|
return str
|
2022-04-10 10:33:13 -07:00
|
|
|
case shell.PWSH, shell.PWSH5, shell.CMD, shell.BASH, shell.FISH, shell.NU:
|
2022-02-03 08:36:37 -08:00
|
|
|
str, _ := e.Writer.String()
|
|
|
|
return str
|
2021-06-23 13:00:40 -07:00
|
|
|
}
|
2021-07-03 09:38:23 -07:00
|
|
|
return ""
|
2021-06-15 12:23:08 -07:00
|
|
|
}
|
2021-11-13 10:35:15 -08:00
|
|
|
|
2022-03-12 13:04:08 -08:00
|
|
|
func (e *Engine) PrintRPrompt() string {
|
2021-11-13 10:35:15 -08:00
|
|
|
filterRPromptBlock := func(blocks []*Block) *Block {
|
|
|
|
for _, block := range blocks {
|
|
|
|
if block.Type == RPrompt {
|
|
|
|
return block
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2022-01-26 23:38:46 -08:00
|
|
|
block := filterRPromptBlock(e.Config.Blocks)
|
2021-11-13 10:35:15 -08:00
|
|
|
if block == nil {
|
|
|
|
return ""
|
|
|
|
}
|
2022-05-05 23:41:58 -07:00
|
|
|
block.Init(e.Env, e.Writer, e.Ansi)
|
|
|
|
if !block.Enabled() {
|
2021-11-13 10:35:15 -08:00
|
|
|
return ""
|
|
|
|
}
|
2022-05-07 01:12:22 -07:00
|
|
|
text, length := block.RenderSegments()
|
2022-02-03 08:36:37 -08:00
|
|
|
e.rpromptLength = length
|
|
|
|
return text
|
2021-11-13 10:35:15 -08:00
|
|
|
}
|