Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

767 B
Raw Blame
import type { OutputMode } from "../output/output-mode.js";
import type { Environment } from "../render/capabilities.js";

export type OutputSource = "flag" | "env" | "terminal" | "pipe";

export function outputProvenance(input: {
  readonly json: boolean;
  readonly human: boolean;
  readonly env: Environment;
  readonly stdoutIsTTY: boolean;
}): { readonly mode: OutputMode; readonly source: OutputSource } {
  if (input.json) return { mode: "json", source: "flag" };
  if (input.human) return { mode: "human", source: "flag" };
  if (input.env.KANEO_JSON === "true" || input.env.KANEO_JSON === "1") {
    return { mode: "json", source: "env" };
  }
  return input.stdoutIsTTY
    ? { mode: "human", source: "terminal" }
    : { mode: "json", source: "pipe" };
}