@@ -33,6 +33,8 @@ func (c *Console) StartContext(ctx context.Context) error {
3333 lastLine := "" // used to check if last read line is empty.
3434
3535 for {
36+ // Print a newline after the last output if NewlineAfter is true
37+ // and the last line was not empty.
3638 c .displayPostRun (lastLine )
3739
3840 // Always ensure we work with the active menu, with freshly
@@ -47,15 +49,10 @@ func (c *Console) StartContext(ctx context.Context) error {
4749 }
4850
4951 // Block and read user input.
50- input , err := c .shell .Readline ()
51-
52- c .displayPostRun (input )
53-
52+ input , err := c .shell .Readline ()
5453 if err != nil {
5554 menu .handleInterrupt (err )
56-
57- lastLine = input
58-
55+ lastLine = input
5956 continue
6057 }
6158
@@ -72,7 +69,7 @@ func (c *Console) StartContext(ctx context.Context) error {
7269 }
7370
7471 if len (args ) == 0 {
75- lastLine = input
72+ lastLine = input
7673 continue
7774 }
7875
@@ -84,6 +81,10 @@ func (c *Console) StartContext(ctx context.Context) error {
8481 continue
8582 }
8683
84+ // Print a newline before executing the command if NewlineBefore is true
85+ // and the last line was not empty.
86+ c .displayPreRun (input )
87+
8788 // Run all pre-run hooks and the command itself
8889 // Don't check the error: if its a cobra error,
8990 // the library user is responsible for setting
@@ -93,7 +94,7 @@ func (c *Console) StartContext(ctx context.Context) error {
9394 menu .ErrorHandler (ExecutionError {newError (err , "" )})
9495 }
9596
96- lastLine = input
97+ lastLine = input
9798 }
9899}
99100
0 commit comments