2024-12-15 19:59:51 +08:00
|
|
|
export class Terminal {
|
2024-12-24 21:09:13 +08:00
|
|
|
/**
|
|
|
|
* 标签
|
|
|
|
*/
|
2024-12-15 19:59:51 +08:00
|
|
|
tag = 'terminal';
|
2024-12-24 21:09:13 +08:00
|
|
|
/**
|
|
|
|
* 标签的颜色
|
|
|
|
*/
|
|
|
|
tagColor = 'red';
|
|
|
|
/**
|
|
|
|
* 标签的背景色
|
|
|
|
*/
|
|
|
|
tagBackground = 'yellow';
|
|
|
|
/**
|
|
|
|
* 日志文本的颜色
|
|
|
|
*/
|
|
|
|
txtColor = 'black';
|
|
|
|
|
|
|
|
constructor(tag: string, tagColor: string = 'red', tagBackground: string = 'yellow') {
|
|
|
|
this.tagColor = tagColor;
|
|
|
|
this.tagBackground = tagBackground;
|
2024-12-15 19:59:51 +08:00
|
|
|
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[] {
|
2024-12-24 21:09:13 +08:00
|
|
|
return [`%c${this.tag}%c${newline ? '\n' : ''}${message}`, `color:${this.tagColor};background:${this.tagBackground};padding:0 4px`, `color:${this.txtColor};margin-left:5px`];
|
2024-12-15 19:59:51 +08:00
|
|
|
}
|
2024-12-24 17:31:26 +08:00
|
|
|
public blue(message: string): string[] {
|
2024-12-24 21:09:13 +08:00
|
|
|
this.txtColor = 'blue';
|
2024-12-24 17:31:26 +08:00
|
|
|
return this.log(message);
|
|
|
|
}
|
|
|
|
public green(message: string): string[] {
|
2024-12-24 21:09:13 +08:00
|
|
|
this.txtColor = 'green';
|
2024-12-24 17:31:26 +08:00
|
|
|
return this.log(message);
|
|
|
|
}
|
|
|
|
public red(message: string): string[] {
|
2024-12-24 21:09:13 +08:00
|
|
|
this.txtColor = 'red';
|
2024-12-24 17:31:26 +08:00
|
|
|
return this.log(message);
|
|
|
|
}
|
2024-12-24 21:09:13 +08:00
|
|
|
message(msg: string): string[] {
|
|
|
|
this.txtColor = 'black';
|
|
|
|
return this.log(`[message] ${msg}`);
|
|
|
|
}
|
2024-12-24 17:31:26 +08:00
|
|
|
connect(msg: string): string[] {
|
2024-12-24 21:09:13 +08:00
|
|
|
this.txtColor = 'black';
|
2024-12-24 17:31:26 +08:00
|
|
|
return this.log(`[connect] ${msg}`);
|
|
|
|
}
|
|
|
|
disconnect(msg: string): string[] {
|
2024-12-24 21:09:13 +08:00
|
|
|
this.txtColor = 'black';
|
2024-12-24 17:31:26 +08:00
|
|
|
return this.log(`[disconnect] ${msg}`);
|
2024-12-15 19:59:51 +08:00
|
|
|
}
|
|
|
|
}
|