|
3 | 3 | import subprocess |
4 | 4 | import shlex |
5 | 5 | from .utils import * |
| 6 | +from time import time as now |
| 7 | +from datetime import datetime |
6 | 8 |
|
7 | 9 | __author__ = 'Aziz Köksal' |
8 | 10 | |
@@ -87,25 +89,40 @@ def call_mix_format(window, **kwargs): |
87 | 89 | window.run_command('erase_view', panel_params) |
88 | 90 | output_view = None |
89 | 91 |
|
| 92 | + past_timestamp = now() |
| 93 | + panel_update_interval = 2 |
| 94 | + |
90 | 95 | while proc.poll() is None: |
91 | 96 | stderr_line = proc.stderr.readline().decode(encoding='UTF-8') |
92 | 97 |
|
93 | 98 | if stderr_line: |
94 | 99 | 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 | + output_view = create_mix_format_panel(window, panel_name, cmd, cwd) |
100 | 101 | window.run_command('show_panel', panel_params) |
101 | 102 |
|
102 | 103 | output_view.run_command('append', {'characters': stderr_line}) |
103 | 104 |
|
| 105 | + if now() - past_timestamp > panel_update_interval: |
| 106 | + output_view.show(output_view.size()) |
| 107 | + past_timestamp = now() |
| 108 | + |
104 | 109 | if output_view: |
105 | 110 | output_view.set_read_only(True) |
106 | 111 | else: |
107 | 112 | if window.active_panel() == panel_params['panel']: |
108 | 113 | window.run_command('hide_panel', panel_params) |
| 114 | + window.destroy_output_panel(panel_name) |
109 | 115 |
|
110 | 116 | msg = 'Formatted %s %s!' % (file_path and 'file' or 'directory', repr(file_path or cwd)) |
111 | 117 | print_status_msg(msg) |
| 118 | + |
| 119 | +def create_mix_format_panel(window, panel_name, cmd_args, cwd): |
| 120 | + first_lines = '$ cd %s && %s' % (shlex.quote(cwd), ' '.join(map(shlex.quote, cmd_args))) |
| 121 | + first_lines += '\n# Timestamp: %s\n\n' % datetime.now().replace(microsecond=0) |
| 122 | + |
| 123 | + output_view = window.create_output_panel(panel_name) |
| 124 | + output_view.settings().set('result_file_regex', r'/([^/]+):(\d+):(\d+)') |
| 125 | + output_view.set_read_only(False) |
| 126 | + output_view.run_command('append', {'characters': first_lines}) |
| 127 | + |
| 128 | + return output_view |
0 commit comments