UNPKG

@yuebai008/cli

Version:

Command line interface for rapid qg-minigame development

1 lines 1.06 kB
import{ObjectWrapper}from"./Object.js";import{reveal}from"./Revealer.js";let consoleInstance;export class Console extends ObjectWrapper{#e;constructor(){super(),this.#e=[]}static instance(e){return consoleInstance&&!e?.forceNew||(consoleInstance=new Console),consoleInstance}static removeInstance(){consoleInstance=void 0}addMessage(e,s,t){const n=new Message(e,s||MessageLevel.Info,Date.now(),t||!1);this.#e.push(n),this.dispatchEventToListeners(Events.MessageAdded,n)}log(e){this.addMessage(e,MessageLevel.Info)}warn(e){this.addMessage(e,MessageLevel.Warning)}error(e){this.addMessage(e,MessageLevel.Error,!0)}messages(){return this.#e}show(){this.showPromise()}showPromise(){return reveal(this)}}export var Events;!function(e){e.MessageAdded="messageAdded"}(Events||(Events={}));export var MessageLevel;!function(e){e.Info="info",e.Warning="warning",e.Error="error"}(MessageLevel||(MessageLevel={}));export class Message{text;level;timestamp;show;constructor(e,s,t,n){this.text=e,this.level=s,this.timestamp="number"==typeof t?t:Date.now(),this.show=n}}