<commit_before>var fs = require('fs')
var readline = require('readline')
var SerialPort = require('serialport').SerialPort

var argv = require('yargs')
  .usage('Usage: $0 [options] [filename]')
  .alias('p', 'port')
  .nargs('p', 1)
  .default('p', '/dev/tty.usbmodem1411')
  .describe('p', 'Serial port path')
  .alias('b', 'baudrate')
  .nargs('b', 1)
  .default('b', 57600)
  .describe('b', 'Serial port baudrate')
  .help('h')
  .alias('h', 'help')
  .argv

var file = argv._[0]

var printer = new SerialPort(argv.port, { baudrate: argv.baudrate }, false)

printer.on('open', function () {
  console.log('Connected to printer!')
})

printer.on('data', function (data) {
  console.log('< ', data)
})

printer.open(function (err) {
  console.log('Could not connect!', err)
  process.exit(1)
})

var gcodeStreamer
if (file) {
  fs.open(file, function (err, data) {
    if (err) {
      console.log(err)
      process.exit(1)
    }

    gcodeStreamer = readline.createInterface({
      input: data,
      output: process.stdout
    })

    var gcode = data.toString().split('\n')
    gcode.forEach(function (line) {
      console.log('> ', line)
      printer.write(line)
    })
  })
  printer.drain()
} else {
  gcodeStreamer = readline.createInterface({
    input: process.stdin,
    output: process.stdout
  })
}

gcodeStreamer.setPrompt('> ')
gcodeStreamer.prompt()

gcodeStreamer.on('line', function (line) {
  // printer.write(line)
  gcodeStreamer.prompt()
}).on('close', function () {
  printer.drain()
  printer.close()
})<commit_msg>Woops didn't finish clean up after refactor :bath:<commit_after>var fs = require('fs')
var readline = require('readline')
var SerialPort = require('serialport').SerialPort

var argv = require('yargs')
  .usage('Usage: $0 [options] [filename]')
  .alias('p', 'port')
  .nargs('p', 1)
  .default('p', '/dev/tty.usbmodem1411')
  .describe('p', 'Serial port path')
  .alias('b', 'baudrate')
  .nargs('b', 1)
  .default('b', 57600)
  .describe('b', 'Serial port baudrate')
  .help('h')
  .alias('h', 'help')
  .argv

var file = argv._[0]

var printer = new SerialPort(argv.port, { baudrate: argv.baudrate }, false)

printer.on('open', function () {
  console.log('Connected to printer!')
})

printer.on('data', function (data) {
  console.log('< ', data)
})

printer.open(function (err) {
  console.log('Could not connect!', err)
  process.exit(1)
})

var gcodeStreamer
if (file) {
  fs.open(file, function (err, data) {
    if (err) {
      console.log(err)
      process.exit(1)
    }

    gcodeStreamer = readline.createInterface({
      input: data,
      output: process.stdout
    })
  })
  printer.drain()
} else {
  gcodeStreamer = readline.createInterface({
    input: process.stdin,
    output: process.stdout
  })
}

gcodeStreamer.setPrompt('> ')
gcodeStreamer.prompt()

gcodeStreamer.on('line', function (line) {
  printer.write(line)
  gcodeStreamer.prompt()
}).on('close', function () {
  printer.drain()
  printer.close()
})
{'fraction_non_alphanumeric': 0.1880456682337139, 'fraction_numerical': 0.010073875083948958, 'mean_word_length': 3.7436305732484074, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5465965', 'n_tokens_mistral': 1113, 'n_tokens_neox': 1093, 'n_words': 223}