diff --git a/lib/cjs.ts b/lib/cjs.ts index bda4241..dbe2ef3 100644 --- a/lib/cjs.ts +++ b/lib/cjs.ts @@ -3,7 +3,7 @@ import { cliui, UIOptions } from './index.js' const stringWidth = require('string-width') const stripAnsi = require('strip-ansi') const wrap = require('wrap-ansi') -export default function ui (opts: UIOptions) { +export default function ui (opts?: UIOptions) { return cliui(opts, { stringWidth, stripAnsi, diff --git a/lib/index.ts b/lib/index.ts index 0673c3a..efb457c 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -11,11 +11,14 @@ const bottom = 2 const left = 3 export interface UIOptions { - width: number; + width?: number; wrap?: boolean; rows?: string[]; } +// The width should be worked out by the time we are constructing the actual class. +type UIConstructorOptions = UIOptions & {width:number}; + interface Column { text: string; width?: number; @@ -45,7 +48,7 @@ export class UI { wrap: boolean; rows: ColumnArray[]; - constructor (opts: UIOptions) { + constructor (opts: UIConstructorOptions) { this.width = opts.width this.wrap = opts.wrap ?? true this.rows = [] @@ -380,7 +383,7 @@ function alignCenter (str: string, width: number): string { } let mixin: Mixin -export function cliui (opts: Partial, _mixin: Mixin) { +export function cliui (opts: UIOptions | undefined, _mixin: Mixin) { mixin = _mixin return new UI({ width: opts?.width || getWindowWidth(),