           add err.message
 
         ).on("done", ->
-          add '\nCounts are in order of source, comments, and total.'
-          add '\nFiles\n-----'
-          for path, c of files
-            add pad(c.sloc) + pad(c.cloc) + pad(c.loc) +  '  ' + path
+          add '\nGenerated by the Atom Editor package Line-Count.'
+          add '\nResults for directory ' + rootDirPath + '.'
+          add 'Counts are in order of source, comments, and total.'
 
-          add '\nTypes\n-----'
-          for type, c of typeData
-            add pad(c.sloc) + pad(c.cloc) + pad(c.loc) + '  ' + type
-
-          add '\nTotal\n-----'
-          c = total['']
-          add pad(c.sloc) + pad(c.cloc) + pad(c.loc)
+          printSection 'Files', files
+          printSection 'Types', typeData
+          printSection 'Total', total
 
           editor.setText text
 

  for k, v of b
    a[k] ?= 0
    a[k] += v


module.exports =


  open: ->
    text = ''
    add = (txt) -> text += (txt ? '') + '\n'

    printSection = (title, data) ->
      add '\n' + title + '\n-----'
      maxS = maxC = maxT = 0
      for label, c of data
        maxS = Math.max maxS, c.sloc
        maxC = Math.max maxC, c.cloc
        maxT = Math.max maxT, c.loc
        ws = ('' + maxS).length + 1
        wc = ('' + maxC).length + 1
        wt = ('' + maxT).length + 1
      for label, c of data
        add pad(c.sloc, ws) + pad(c.cloc, wc) + pad(c.loc, wt) + '  ' + label

    atom.workspaceView.open('Line Count').then (editor) ->
      rootDirPath = atom.project.getRootDirectory().path
