mirror of
https://github.com/esphome/esp-web-tools.git
synced 2025-07-25 12:46:44 +00:00
Create TimestampTransformer and use it in EwtConsole (#501)
This commit is contained in:
parent
ec35b6aa69
commit
9261c2c24e
@ -1,6 +1,7 @@
|
||||
import { ColoredConsole, coloredConsoleStyles } from "../util/console-color";
|
||||
import { sleep } from "../util/sleep";
|
||||
import { LineBreakTransformer } from "../util/line-break-transformer";
|
||||
import { TimestampTransformer } from "../util/timestamp-transformer";
|
||||
import { Logger } from "../const";
|
||||
|
||||
export class EwtConsole extends HTMLElement {
|
||||
@ -95,6 +96,7 @@ export class EwtConsole extends HTMLElement {
|
||||
signal: abortSignal,
|
||||
})
|
||||
.pipeThrough(new TransformStream(new LineBreakTransformer()))
|
||||
.pipeThrough(new TransformStream(new TimestampTransformer()))
|
||||
.pipeTo(
|
||||
new WritableStream({
|
||||
write: (chunk) => {
|
||||
|
12
src/util/timestamp-transformer.ts
Normal file
12
src/util/timestamp-transformer.ts
Normal file
@ -0,0 +1,12 @@
|
||||
export class TimestampTransformer implements Transformer<string, string> {
|
||||
transform(
|
||||
chunk: string,
|
||||
controller: TransformStreamDefaultController<string>,
|
||||
) {
|
||||
const date = new Date();
|
||||
const h = date.getHours().toString().padStart(2, "0");
|
||||
const m = date.getMinutes().toString().padStart(2, "0");
|
||||
const s = date.getSeconds().toString().padStart(2, "0");
|
||||
controller.enqueue(`[${h}:${m}:${s}]${chunk}`);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user