Skip to content

Commit db4c0b9

Browse files
committed
Fix multi line prompt
Signed-off-by: Tiago Natel de Moura <[email protected]>
1 parent 4b216ee commit db4c0b9

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

cmd/nash/cli.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,25 @@ func cli(shell *nash.Shell) error {
9090

9191
func docli(shell *nash.Shell, rline *readline.Instance) error {
9292
var (
93-
content bytes.Buffer
94-
lineidx int
95-
line string
96-
parse *parser.Parser
97-
tr *ast.Tree
98-
err error
93+
content bytes.Buffer
94+
lineidx int
95+
line string
96+
parse *parser.Parser
97+
tr *ast.Tree
98+
err error
99+
unfinished bool
100+
prompt string
99101
)
100102

101103
for {
102-
if fn, ok := shell.GetFn("nash_repl_before"); ok {
104+
if fn, ok := shell.GetFn("nash_repl_before"); ok && !unfinished {
103105
execFn(shell, fn)
104106
}
105107

106-
prompt := shell.Prompt()
108+
if !unfinished {
109+
prompt = shell.Prompt()
110+
}
111+
107112
rline.SetPrompt(prompt)
108113

109114
line, err = rline.Readline()
@@ -160,6 +165,7 @@ func docli(shell *nash.Shell, rline *readline.Instance) error {
160165
goto cont
161166
} else if errBlock, ok := err.(BlockNotFinished); ok && errBlock.Unfinished() {
162167
prompt = ">>> "
168+
unfinished = true
163169
goto cont
164170
}
165171

@@ -169,6 +175,7 @@ func docli(shell *nash.Shell, rline *readline.Instance) error {
169175
goto cont
170176
}
171177

178+
unfinished = false
172179
content.Reset()
173180

174181
_, err = shell.ExecuteTree(tr)
@@ -178,7 +185,7 @@ func docli(shell *nash.Shell, rline *readline.Instance) error {
178185
}
179186

180187
cont:
181-
if fn, ok := shell.GetFn("nash_repl_after"); ok {
188+
if fn, ok := shell.GetFn("nash_repl_after"); ok && !unfinished {
182189
var status sh.Obj
183190
var ok bool
184191

0 commit comments

Comments
 (0)