Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make options and opt.width optional for client and match implementation #145

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/cjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 6 additions & 3 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = []
Expand Down Expand Up @@ -380,7 +383,7 @@ function alignCenter (str: string, width: number): string {
}

let mixin: Mixin
export function cliui (opts: Partial<UIOptions>, _mixin: Mixin) {
export function cliui (opts: UIOptions | undefined, _mixin: Mixin) {
mixin = _mixin
return new UI({
width: opts?.width || getWindowWidth(),
Expand Down