All files register-terminal-output.ts

100% Statements 27/27
100% Branches 9/9
100% Functions 2/2
100% Lines 27/27

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 411x 1x 1x                 1x 4x 4x 4x 4x 4x 1x 1x   4x 1x 1x 1x     2x 4x 1x 1x 4x     1x 4x 4x 4x 4x 2x 2x  
import * as vscode from "vscode";
import { registerProposedGlobalTerminalOutput } from "./proposed-global-stream";
import { registerStableShellExecutionTerminalOutput } from "./stable-shell-execution";
import type { TerminalOutputRegisterDeps, TerminalOutputFallbackMode } from "./types";
 
/**
 * Wires terminal output sources per user setting:
 * - auto: stable shell execution read() if API exists; else proposed global stream; never both.
 * - proposed-only: proposed only.
 * - off: neither.
 */
export function registerTerminalOutput(
  context: vscode.ExtensionContext,
  deps: TerminalOutputRegisterDeps,
): void {
  const mode = deps.getFallbackMode();
  if (mode === "off") {
    return;
  }
 
  if (mode === "proposed-only") {
    registerProposedGlobalTerminalOutput(context, deps);
    return;
  }
 
  // mode === "auto"
  const stableOk = registerStableShellExecutionTerminalOutput(context, deps);
  if (!stableOk) {
    registerProposedGlobalTerminalOutput(context, deps);
  }
}
 
/** Reads `remoot-bridge.terminalOutputFallback` (for tests / callers). */
export function getTerminalOutputFallbackFromConfig(): TerminalOutputFallbackMode {
  const v = vscode.workspace
    .getConfiguration("remoot-bridge")
    .get<string>("terminalOutputFallback", "auto");
  if (v === "proposed-only" || v === "off") return v;
  return "auto";
}