Skip to content

Commit 0aafd67

Browse files
committed
feat: goprompt learns about prompt start marks that you can set for iterm and other terminal emulators
1 parent 180a8d2 commit 0aafd67

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

cmd/goprompt/cmdRender.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,18 @@ var (
2121
"prompt-loading", false,
2222
"is prompt query not yet done rendering",
2323
)
24-
flgRColorMode = cmdRender.PersistentFlags().String(
25-
"color-mode", "none",
26-
"color rendering mode of the prompt (zsh, ascii, none)",
24+
flgREscapeMode = cmdRender.PersistentFlags().String(
25+
"escape-mode", "none",
26+
"color / escape rendering mode of the prompt (zsh, ascii, none)",
2727
)
2828
flgRMode = cmdRender.PersistentFlags().String(
2929
"prompt-mode", "normal",
3030
"mode of the prompt (normal, edit)",
3131
)
32+
flgRPromptStartMark = cmdRender.PersistentFlags().String(
33+
"prompt-mark-start", "",
34+
"mark to place at the start of the prompt (first prompt line)",
35+
)
3236
)
3337

3438
func init() {
@@ -61,7 +65,7 @@ func setColorMode(mode string) {
6165
magentaC = wrapC("%F{magenta}", "%F{reset}")
6266
greyC = wrapC("%F{black}", "%F{reset}")
6367
newline = "\n%{\r%}"
64-
68+
6569
} else if mode == "ascii" {
6670
redC = color.Red.Render
6771
greenC = color.Green.Render
@@ -74,7 +78,7 @@ func setColorMode(mode string) {
7478
}
7579

7680
func cmdRenderRun(_ *cobra.Command, _ []string) error {
77-
setColorMode(*flgRColorMode)
81+
setColorMode(*flgREscapeMode)
7882

7983
if _, err := os.Stdin.Stat(); err != nil {
8084
fmt.Printf("%#v", err)
@@ -258,7 +262,14 @@ func cmdRenderRun(_ *cobra.Command, _ []string) error {
258262
}
259263
promptLines = append(promptLines, promptMarker)
260264

261-
fmt.Print(strings.Join(promptLines, newline))
265+
// Add prompt mark to last line
266+
lastLine := len(promptLines) - 1
267+
if lastLine >= 0 {
268+
promptLines[lastLine] = fmt.Sprintf("%v%v", *flgRPromptStartMark, promptLines[lastLine])
269+
}
270+
271+
fullPrompt := strings.Join(promptLines, newline)
272+
fmt.Print(fullPrompt)
262273

263274
return nil
264275
}

plugin/zsh/prompt_asynczle_setup.zsh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# In a file `prompt_asynczle_setup` available on `fpath`
22
emulate -L zsh
33

4+
typeset -g ZSH_ASYNC_PROMPT_START_MARK=${ZSH_ASYNC_PROMPT_START_MARK:-}
45
typeset -g ZSH_ASYNC_PROMPT_TIMEOUT=${ZSH_ASYNC_PROMPT_TIMEOUT:-5s}
56
typeset -g ZSH_ASYNC_PROMPT_EXEC=${GOPROMPT}
67

@@ -59,7 +60,8 @@ __async_prompt_render() {
5960
${ZSH_ASYNC_PROMPT_EXEC} render \
6061
--prompt-mode "$MODE" \
6162
--prompt-loading="$LOADING" \
62-
--color-mode "zsh"
63+
--prompt-mark-start "$ZSH_ASYNC_PROMPT_START_MARK" \
64+
--escape-mode "zsh"
6365
}
6466

6567
#-------------------------------------------------------------------------------

0 commit comments

Comments
 (0)