"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var logger_exports = {};
__export(logger_exports, {
  Logger: () => Logger
});
module.exports = __toCommonJS(logger_exports);
var import_base_logger = require("./base-logger");
class Logger extends import_base_logger.BaseLogger {
  static _previousLine;
  // this is global to the whole process
  print(message, props = {}) {
    this.cleanup();
    const stream = props.stderr ? "err" : "out";
    const { prefix } = props;
    if (prefix) {
      this.render(`${prefix} ${message}
`, stream);
      return;
    }
    this.render(`${message}
`, stream);
  }
  line() {
    this.cleanup();
    const currentLine = new _SingleLineLogger({ ...this.opts });
    Logger._previousLine = currentLine;
    return currentLine;
  }
  cleanup() {
    if (Logger._previousLine) {
      Logger._previousLine.commit();
      Logger._previousLine = void 0;
    }
  }
}
class _SingleLineLogger extends import_base_logger.BaseLogger {
  _commited = false;
  commit() {
    if (this._commited) {
      return;
    }
    this._commited = true;
    this.print("");
  }
  print(message, props = {}) {
    let suffix;
    if (!this._commited && this.opts.outStream.isTTY) {
      this.opts.outStream.clearLine(0);
      this.opts.outStream.cursorTo(0);
      suffix = "";
    } else {
      suffix = "\n";
    }
    const { prefix } = props;
    if (prefix) {
      this.render(`${prefix} ${message}${suffix}`);
      return;
    }
    this.render(message + suffix);
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  Logger
});
//# sourceMappingURL=index.js.map
