Skip to content

Commit 1c0ae58

Browse files
azizkprincemaple
authored andcommitted
Commands: show mix_format panel on stderr output.
Fixed hiding mix_format panel when error-free again.
1 parent c963e5f commit 1c0ae58

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

commands/mix_format.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,26 +80,32 @@ def call_mix_format(window, **kwargs):
8080
)
8181
return
8282

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)
8584

8685
panel_name = 'mix_format'
8786
panel_params = {'panel': 'output.%s' % panel_name}
8887
window.run_command('erase_view', panel_params)
88+
output_view = None
8989

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:
98105
output_view.set_read_only(True)
99-
window.run_command('show_panel', panel_params)
100106
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

Comments
 (0)