stream, dir, callback) {
  if (callback !== undefined) {
    validateFunction(callback, 'callback');
  }

  if (stream === null || stream === undefined) {
    if (typeof callback === 'function') process.nextTick(callback, null);
    return true;
  }

  const type =
    dir < 0 ? kClearToLineBeginning : dir > 0 ? kClearToLineEnd : kClearLine;
  return stream.write(type, callback);
}

/**
 * clears the screen from the current position of the cursor down
 */

function clearScreenDown(stream, callback) {
  if (callback !== undefined) {
    validateFunction(callback, 'callback');
  }

  if (stream === null || stream === undefined) {
    if (typeof callback === 'function') process.nextTick(callback, null);
    return true;
  }

  return stream.write(kClearScreenDown, callback);
}

module.exports = {
  clearLine,
  clearScreenDown,
  cursorTo,
  moveCursor,
};
