Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 029d72e6 authored by Simon Chan's avatar Simon Chan
Browse files

feat(bin): add `tail` option support to `logcat`

parent cb21cd24
Loading
Loading
Loading
Loading
+19 −3
Original line number Diff line number Diff line
@@ -90,9 +90,17 @@ export interface LogcatFormatModifiers {
}

export interface LogcatOptions {
    dump?: boolean;
    pid?: number;
    ids?: LogId[];
    dump?: boolean | undefined;
    pid?: number | undefined;
    ids?: LogId[] | undefined;
    tail?: number | Date | undefined;
}

function formatTailTime(date: Date) {
    // Tail time supports multiple formats,
    // `sssss.mmm` is simplest to implement
    const timestamp = date.getTime();
    return ((timestamp / 1000) | 0) + "." + (timestamp % 1000);
}

const NANOSECONDS_PER_SECOND = /* #__PURE__ */ BigInt(1e9);
@@ -503,6 +511,14 @@ export class Logcat extends AdbCommandBase {
            if (options?.ids) {
                args.push("-b", Logcat.joinLogId(options.ids));
            }
            if (options?.tail) {
                args.push(
                    "-t",
                    typeof options.tail === "number"
                        ? options.tail.toString()
                        : formatTailTime(options.tail),
                );
            }

            // TODO: make `spawn` return synchronously with streams pending
            // so it's easier to chain them.