           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
 

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

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

  'html'
]

pad = (num, w) ->
  num = '' + num
  while num.length < w then num = ' ' + num
  ' ' + num

addAttrs = (sfx, aIn, b) ->
