@@ -23,11 +23,24 @@ func (c *Console) Start() error {
2323 c .printLogo (c )
2424 }
2525
26- for {
26+ lastLine := "" // used to check if last read line is empty.
27+
28+ for i := 0 ; ; i ++ {
2729 // Identical to printing it at the end of the loop, and
2830 // leaves some space between the logo and the first prompt.
31+
32+ // If NewlineAfter is set but NewlineWhenEmpty is not set, we do a check to see
33+ // if the last line was empty. If it wasn't, then we can print.
34+ //fmt.Println(lastLine, len(lastLine))
2935 if c .NewlineAfter {
30- fmt .Println ()
36+ if ! c .NewlineWhenEmpty && i != 0 {
37+ // Print on the condition that the last input wasn't empty.
38+ if ! c .lineEmpty (lastLine ) {
39+ fmt .Println ()
40+ }
41+ } else {
42+ fmt .Println ()
43+ }
3144 }
3245
3346 // Always ensure we work with the active menu, with freshly
@@ -44,13 +57,19 @@ func (c *Console) Start() error {
4457
4558 // Block and read user input.
4659 line , err := c .shell .Readline ()
47-
4860 if c .NewlineBefore {
49- fmt .Println ()
61+ if ! c .NewlineWhenEmpty {
62+ if ! c .lineEmpty (line ) {
63+ fmt .Println ()
64+ }
65+ } else {
66+ fmt .Println ()
67+ }
5068 }
5169
5270 if err != nil {
5371 menu .handleInterrupt (err )
72+ lastLine = line
5473 continue
5574 }
5675
@@ -63,10 +82,12 @@ func (c *Console) Start() error {
6382 args , err := c .parse (line )
6483 if err != nil {
6584 fmt .Printf ("Parsing error: %s\n " , err .Error ())
85+ lastLine = line
6686 continue
6787 }
6888
6989 if len (args ) == 0 {
90+ lastLine = line
7091 continue
7192 }
7293
@@ -75,6 +96,7 @@ func (c *Console) Start() error {
7596 args , err = c .runLineHooks (args )
7697 if err != nil {
7798 fmt .Printf ("Line error: %s\n " , err .Error ())
99+ lastLine = line
78100 continue
79101 }
80102
@@ -83,9 +105,10 @@ func (c *Console) Start() error {
83105 // the library user is responsible for setting
84106 // the cobra behavior.
85107 // If it's an interrupt, we take care of it.
86- if err : = c .execute (menu , args , false ); err != nil {
108+ if err = c .execute (menu , args , false ); err != nil {
87109 fmt .Println (err )
88110 }
111+ lastLine = line
89112 }
90113}
91114
0 commit comments