UNPKG

@struktoai/mirage-core

Version:

A Unified Virtual Filesystem For AI Agents

45 lines • 2.46 kB
import { type ByteSource } from '../../../io/types.ts'; import type { PathSpec, ReadStreamFn } from '../../../types.ts'; import type { CommandFnResult, Context } from '../../config.ts'; import { type FlagValue } from '../../spec/types.ts'; export interface WcRow { values: number[]; label: string | null; } export interface WcFlags { lines: boolean; words: boolean; bytes: boolean; chars: boolean; maxLineLength: boolean; total: 'auto' | 'always' | 'only' | 'never'; } export declare function parseFlags(bag: Record<string, FlagValue>): WcFlags | string; /** * GNU wc's column width, which it takes from the operands. * * One operand, or stdin, shown with one count prints unpadded. Otherwise the * width is the digits of the regular files' total size, and at least 7 once * any operand is a stream or a directory, whose size GNU cannot know * (coreutils 9.7). A redirected file reaches mirage as a stream, so * `wc < file` pads to 7 where GNU pads to the file's size. `sizes` holds, per * operand that opened, a regular file's size or null for a stream or a * directory; `operands` counts the operands given, 1 for stdin. Mirrors * Python's number_width. */ export declare function numberWidth(sizes: readonly (number | null)[], operands: number, counts: number): number; export declare function formatWcLines(rows: WcRow[], width?: number | null): string[]; export declare function formatCountRows(rows: WcRow[], totalValues: number[], operandCount: number, total: WcFlags['total'], width?: number | null): ByteSource | null; /** How many columns a row shows under these flags. */ export declare function shownCounts(flags: WcFlags): number; /** * Run wc over resolved operands, GNU semantics. Lines counted alone are asked * of `lineCount` first, so a mount that can count a file's lines on its own * (a `COUNT(*)` on a table) does not send it; null, or no `lineCount`, reads * the file. A row counted that way has no byte size, so the columns are as * wide as the printed numbers. Bytes counted alone are asked of `sizeOf` * first, as GNU takes a regular file's size from its stat. Mirrors Python's * `wc_generic` and `format_multi`. */ export declare function wcGeneric(paths: PathSpec[], texts: string[], ctx: Context, stream: ReadStreamFn, lineCount?: (p: PathSpec) => Promise<number | null>, sizeOf?: (p: PathSpec) => Promise<number | null>): Promise<CommandFnResult>; //# sourceMappingURL=wc.d.ts.map