@@ -80,26 +80,32 @@ def call_mix_format(window, **kwargs):
80
80
)
81
81
return
82
82
83
- proc = subprocess .Popen (cmd , stdout = subprocess .PIPE , stderr = subprocess .PIPE , cwd = cwd )
84
- stderr_data = proc .communicate ()[1 ]
83
+ proc = subprocess .Popen (cmd , cwd = cwd , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
85
84
86
85
panel_name = 'mix_format'
87
86
panel_params = {'panel' : 'output.%s' % panel_name }
88
87
window .run_command ('erase_view' , panel_params )
88
+ output_view = None
89
89
90
- if stderr_data .strip ():
91
- first_lines = '$ %s\n \n ' % ' ' .join (map (shlex .quote , cmd ))
92
- output_view = window .create_output_panel (panel_name )
93
- ov_settings = output_view .settings ()
94
- ov_settings .set ('result_file_regex' , r'/([^/]+):(\d+):(\d+)' )
95
- output_view .set_read_only (False )
96
- output_view .run_command ('append' , {'characters' : first_lines })
97
- output_view .run_command ('append' , {'characters' : stderr_data .decode ()})
90
+ while proc .poll () is None :
91
+ stderr_line = proc .stderr .readline ().decode (encoding = 'UTF-8' )
92
+
93
+ if stderr_line :
94
+ if not output_view :
95
+ first_lines = '$ cd %s && %s\n \n ' % (shlex .quote (cwd ), ' ' .join (map (shlex .quote , cmd )))
96
+ output_view = window .create_output_panel (panel_name )
97
+ output_view .settings ().set ('result_file_regex' , r'/([^/]+):(\d+):(\d+)' )
98
+ output_view .set_read_only (False )
99
+ output_view .run_command ('append' , {'characters' : first_lines })
100
+ window .run_command ('show_panel' , panel_params )
101
+
102
+ output_view .run_command ('append' , {'characters' : stderr_line })
103
+
104
+ if output_view :
98
105
output_view .set_read_only (True )
99
- window .run_command ('show_panel' , panel_params )
100
106
else :
101
- # FIXME: closes any panel...
102
- # window.run_command('hide_panel', panel_params)
103
- print_status_msg (
104
- 'Formatted %s %s!' % (file_path and 'file' or 'directory' , repr (file_path or cwd ))
105
- )
107
+ if window . active_panel () == panel_params [ ' panel' ]:
108
+ window .run_command ('hide_panel' , panel_params )
109
+
110
+ msg = 'Formatted %s %s!' % (file_path and 'file' or 'directory' , repr (file_path or cwd ))
111
+ print_status_msg ( msg )
0 commit comments