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:23:04 +08:00
|
|
|
/**
|
|
|
|
* 子标签
|
|
|
|
*/
|
|
|
|
subTag = "";
|
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[] {
|
2024-12-24 21:23:04 +08:00
|
|
|
this.txtColor = 'black';
|
|
|
|
this.subTag = "init";
|
|
|
|
return this.log(``);
|
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:23:04 +08:00
|
|
|
return [
|
|
|
|
`*%c${this.tag}%c${this.subTag}%c${newline ? '\n' : ''}${message}`,
|
|
|
|
`color:${this.tagColor};background:${this.tagBackground};padding:0 4px`,
|
|
|
|
`color:white;background:black;padding:0 3px`,
|
|
|
|
`color:${this.txtColor};background:#e6e6e6;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 21:23:04 +08:00
|
|
|
this.subTag = "";
|
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 21:23:04 +08:00
|
|
|
this.subTag = "";
|
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 21:23:04 +08:00
|
|
|
this.subTag = "";
|
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';
|
2024-12-24 21:23:04 +08:00
|
|
|
this.subTag = 'message';
|
|
|
|
return this.log(`${msg}`);
|
2024-12-24 21:09:13 +08:00
|
|
|
}
|
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 21:23:04 +08:00
|
|
|
this.subTag = 'connect';
|
|
|
|
return this.log(`${msg}`);
|
2024-12-24 17:31:26 +08:00
|
|
|
}
|
|
|
|
disconnect(msg: string): string[] {
|
2024-12-24 21:09:13 +08:00
|
|
|
this.txtColor = 'black';
|
2024-12-24 21:23:04 +08:00
|
|
|
this.subTag = 'disconnect';
|
|
|
|
return this.log(`${msg}`);
|
2024-12-15 19:59:51 +08:00
|
|
|
}
|
|
|
|
}
|