// Generated by CoffeeScript 2.3.2
(function() {
  var ConfigNode, Console, Io, Readable, Writable, createReadStream, createWriteStream, readFrom, writeTo;

  ({ConfigNode} = require("@l.degener/irma-config"));

  ({Console} = require("console"));

  ({Readable, Writable} = require("stream"));

  ({createReadStream, createWriteStream} = require("fs"));

  readFrom = function(spec, opts, fallback) {
    if (spec != null) {
      if (spec instanceof Readable) {
        return spec;
      } else if (typeof spec === "string") {
        return createReadStream(spec, opts);
      } else {
        throw new Error(`Don't know how to read from ${spec}`);
      }
    } else {
      return fallback;
    }
  };

  writeTo = function(spec, opts, fallback) {
    if (spec != null) {
      if (spec instanceof Writable) {
        return spec;
      } else if (typeof spec === "string") {
        return createWriteStream(spec, opts);
      } else {
        throw new Error(`Don't know how to write to ${spec}`);
      }
    } else {
      return fallback;
    }
  };

  module.exports = Io = class Io extends ConfigNode {
    init() {
      var ref, ref1, ref2;
      this.stdin = readFrom(this._options.stdin, this._options.stdinOptions, process.stdin);
      this.stdout = writeTo(this._options.stdout, this._options.stdoutOptions, process.stdout);
      this.stderr = writeTo(this._options.stderr, this._options.stderrOptions, process.stderr);
      this.ignoreErrors = (ref = this._options.ignoreErrors) != null ? ref : true;
      this.colorMode = (ref1 = this._options.colorMode) != null ? ref1 : 'auto';
      this.inspectOptions = (ref2 = this._options.inspectOptions) != null ? ref2 : {};
      // this is only supported in node > 10.x

      //@console = new Console
      //  stdout: @stdout
      //  stderr: @stderr
      //  ignoreErrors: @ignoreErrors
      //  colorMode: @colorMode
      //  inspectOptions: @inspectOptions

      // this should work on older and newer versions, although the third argument
      // will be ignored for versions earlier then 10.
      return this.console = new Console(this.stdout, this.stderr, this.ignoreErrors);
    }

  };

}).call(this);
