Skip to content

Commit 2d4fc57

Browse files
committed
fix: make options and opt.width optional for client and match implementation
1 parent af3145d commit 2d4fc57

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

lib/cjs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { cliui, UIOptions } from './index.js'
33
const stringWidth = require('string-width')
44
const stripAnsi = require('strip-ansi')
55
const wrap = require('wrap-ansi')
6-
export default function ui (opts: UIOptions) {
6+
export default function ui (opts?: UIOptions) {
77
return cliui(opts, {
88
stringWidth,
99
stripAnsi,

lib/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@ const bottom = 2
1111
const left = 3
1212

1313
export interface UIOptions {
14-
width: number;
14+
width?: number;
1515
wrap?: boolean;
1616
rows?: string[];
1717
}
1818

19+
// The width should be worked out by the time we are constructing the actual class.
20+
type UIConstructorOptions = UIOptions & {width:number};
21+
1922
interface Column {
2023
text: string;
2124
width?: number;
@@ -45,7 +48,7 @@ export class UI {
4548
wrap: boolean;
4649
rows: ColumnArray[];
4750

48-
constructor (opts: UIOptions) {
51+
constructor (opts: UIConstructorOptions) {
4952
this.width = opts.width
5053
this.wrap = opts.wrap ?? true
5154
this.rows = []
@@ -380,7 +383,7 @@ function alignCenter (str: string, width: number): string {
380383
}
381384

382385
let mixin: Mixin
383-
export function cliui (opts: Partial<UIOptions>, _mixin: Mixin) {
386+
export function cliui (opts: UIOptions | undefined, _mixin: Mixin) {
384387
mixin = _mixin
385388
return new UI({
386389
width: opts?.width || getWindowWidth(),

0 commit comments

Comments
 (0)