@@ -26,6 +26,12 @@ def __init__(self, args, env, callback, query=None, encoding='utf-8',
2626 self .silenceErrors = silenceErrors
2727 self .process = None
2828
29+ if 'show_query' not in self .options :
30+ self .options ['show_query' ] = False
31+ elif self .options ['show_query' ] not in ['top' , 'bottom' ]:
32+ self .options ['show_query' ] = 'top' if (isinstance (self .options ['show_query' ], bool )
33+ and self .options ['show_query' ]) else False
34+
2935 def run (self ):
3036 if not self .query :
3137 return
@@ -61,18 +67,24 @@ def run(self):
6167 if self .stream :
6268 self .process .stdin .write (self .query .encode ())
6369 self .process .stdin .close ()
70+ hasWritten = False
71+
6472 for line in self .process .stdout :
6573 self .callback (line .decode (self .encoding ,
6674 'replace' ).replace ('\r ' , '' ))
75+ hasWritten = True
6776
6877 queryTimerEnd = time .time ()
6978 # we are done with the output, terminate the process
7079 if self .process :
7180 self .process .terminate ()
81+ else :
82+ if hasWritten :
83+ self .callback ('\n ' )
7284
73- if 'show_query' in self . options and self .options ['show_query' ]:
85+ if self .options ['show_query' ]:
7486 formattedQueryInfo = self ._formatShowQuery (self .query , queryTimerStart , queryTimerEnd )
75- self .callback (formattedQueryInfo )
87+ self .callback (formattedQueryInfo + ' \n ' )
7688
7789 return
7890
@@ -92,9 +104,16 @@ def run(self):
92104 resultString += errors .decode (self .encoding ,
93105 'replace' ).replace ('\r ' , '' )
94106
95- if 'show_query' in self .options and self .options ['show_query' ]:
107+ if self .process == None and resultString != '' :
108+ resultString += '\n '
109+
110+ if self .options ['show_query' ]:
96111 formattedQueryInfo = self ._formatShowQuery (self .query , queryTimerStart , queryTimerEnd )
97- resultString = "{0}\n {1}" .format (formattedQueryInfo , resultString )
112+ queryPlacement = self .options ['show_query' ]
113+ if queryPlacement == 'top' :
114+ resultString = "{0}\n {1}" .format (formattedQueryInfo , resultString )
115+ elif queryPlacement == 'bottom' :
116+ resultString = "{0}{1}\n " .format (resultString , formattedQueryInfo )
98117
99118 self .callback (resultString )
100119
0 commit comments