{{! Create a collapsible div to represent invocation of an external tool. }}
<div id="__{{workunit.id}}__tool_invocation">
{{#collapsible}}id={{workunit.id}}-cmd&title=cmdline&class_prefix=cmd{{/collapsible}}
{{#collapsible}}id={{workunit.id}}-stdout&title=stdout&class_prefix=greyed{{#stdout_initially_open}}&initially_open=1{{/stdout_initially_open}}{{/collapsible}}
{{#collapsible}}id={{workunit.id}}-stderr&title=stderr&class_prefix=greyed{{/collapsible}}
</div>
<script>
  $(function(){
    pants.collapsible.hasContent('{{workunit.id}}');
    pants.collapsible.hasContent('{{workunit.id}}-cmd');
    pants.append('#__{{workunit.id}}__tool_invocation', '#{{workunit.id}}-content');
    pants.appendString('{{{workunit.cmd}}}', '#{{workunit.id}}-cmd-content');
      {{! Only tail the stdout/stderr if the enclosing collapsible is visible, or when we first open
       it, as there could be hundreds of these on the page. }}
    var startTailing = function() {
      pants.poller.startTailing('{{workunit.id}}_stdout', '{{html_path_base}}/{{workunit.id}}.stdout', '#{{workunit.id}}-stdout-content', function() { pants.collapsible.hasContent('{{workunit.id}}-stdout'); });
      pants.poller.startTailing('{{workunit.id}}_stderr', '{{html_path_base}}/{{workunit.id}}.stderr', '#{{workunit.id}}-stderr-content', function() { pants.collapsible.hasContent('{{workunit.id}}-stderr'); });
    }
    if ($('#{{workunit.id}}-content').is(':visible')) {
      startTailing();
    } else {
    $('#{{workunit.id}}-header').one('click', startTailing);
    }
  });
</script>
