Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Change log font and add colors #453

Merged
merged 1 commit into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ <h2>Realtime Logs <button pButton (click)="toggleLogs()" style="margin-left: 15p
</h2>

<div *ngIf="showLogs" id="logs" #scrollContainer>
<div *ngFor="let log of logs">₿ {{log | ANSI}}</div>
<div *ngFor="let log of logs" [ngClass]="log.className">₿ {{log.text | ANSI}}</div>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
>div {
max-width: 100%;
line-break: anywhere;

font-family: 'Courier New', Courier, monospace;
}
}
}

.ansi-red { color: #ff0000; }
.ansi-green { color: #00ff00; }
.ansi-yellow { color: #ffff00; }
.ansi-blue { color: #0000ff; }
.ansi-magenta { color: #ff00ff; }
.ansi-cyan { color: #00ffff; }
.ansi-white { color: #ffffff; }
21 changes: 19 additions & 2 deletions main/http_server/axe-os/src/app/components/logs/logs.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class LogsComponent implements OnDestroy, AfterViewChecked {
@ViewChild('scrollContainer') private scrollContainer!: ElementRef;
public info$: Observable<ISystemInfo>;

public logs: string[] = [];
public logs: { className: string, text: string }[] = [];

private websocketSubscription?: Subscription;

Expand Down Expand Up @@ -55,7 +55,24 @@ export class LogsComponent implements OnDestroy, AfterViewChecked {
if (this.showLogs) {
this.websocketSubscription = this.websocketService.ws$.subscribe({
next: (val) => {
this.logs.push(val);
const matches = val.matchAll(/\[(\d+;\d+)m(.*?)(?=\[|\n|$)/g);
let className = 'ansi-white'; // default color

for (const match of matches) {
const colorCode = match[1].split(';')[1];
switch (colorCode) {
case '31': className = 'ansi-red'; break;
case '32': className = 'ansi-green'; break;
case '33': className = 'ansi-yellow'; break;
case '34': className = 'ansi-blue'; break;
case '35': className = 'ansi-magenta'; break;
case '36': className = 'ansi-cyan'; break;
case '37': className = 'ansi-white'; break;
}
}

this.logs.push({ className, text: val });

if (this.logs.length > 256) {
this.logs.shift();
}
Expand Down
Loading