'use strict'

const path = require('path')
const rtfRenderer = require('../lib/')
const execa = require('execa')

module.exports = function codeHighlight(clipboard, settings) {
  const fontface = settings.getSync('fontface')
  const theme = settings.getSync('theme')
  const input = clipboard.readText()
  const output = rtfRenderer.highlightAuto(input, {
    fontface,
    theme
  }).value
  clipboard.writeRTF(output)

  // Pasting into the active application
  execa('osascript', [path.resolve('./src/paste.as')]).then((result) => {
    console.log(result.stdout)
  })
}

@@ -384,16 +384,17 @@
 ).value%0A
+%0A
   clipbo
@@ -406,166 +406,43 @@
 rite
-RTF(output)%0A%0A  // Pasting into the active application%0A  execa('osascript', %5Bpath.resolve('./src/paste.as')%5D).then((result) =%3E %7B%0A    console.log(result.stdo
+(%7B%0A    text: input,%0A    rtf: outp
 ut
-)
 %0A  %7D

Write original string to the clipboard as text and new as RTF