37 lines
1015 B
TypeScript
Raw Normal View History

2024-12-15 19:59:51 +08:00
export class Terminal {
color = 'red';
background = 'yellow';
tag = 'terminal';
constructor(tag: string, color: string = 'red', background: string = 'yellow') {
this.color = color;
this.background = background;
this.tag = tag;
}
2024-12-24 17:31:26 +08:00
init(): string[] {
return this.log(`init`);
2024-12-15 19:59:51 +08:00
}
2024-12-24 17:31:26 +08:00
public log(message: string, newline: boolean = false): string[] {
return [`%c${this.tag}%c${newline ? '\n' : ''}${message}`, `color:${this.color};background:${this.background};padding:0 4px`, "color:black;margin-left:5px"];
2024-12-15 19:59:51 +08:00
}
2024-12-24 17:31:26 +08:00
public blue(message: string): string[] {
this.color = 'blue';
return this.log(message);
}
public green(message: string): string[] {
this.color = 'green';
return this.log(message);
}
public red(message: string): string[] {
this.color = 'red';
return this.log(message);
}
connect(msg: string): string[] {
return this.log(`[connect] ${msg}`);
}
disconnect(msg: string): string[] {
return this.log(`[disconnect] ${msg}`);
2024-12-15 19:59:51 +08:00
}
}