Skip to content

Commit

Permalink
chore!: use enums for Borders
Browse files Browse the repository at this point in the history
  • Loading branch information
wobsoriano committed Sep 18, 2023
1 parent 22b150c commit a0768f4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,16 @@ const str = NewStyle()
Adding borders is easy:

```js
import { NewStyle, Border } from 'blipgloss'

// Add a purple, rectangular border
const style = NewStyle()
.BorderStyle('normal')
.BorderStyle(Border.Normal)
.BorderForeground("63")

// Set a rounded, yellow-on-purple border to the top and left
const anotherStyle = NewStyle()
.BorderStyle('rounded')
.BorderStyle(Border.Rounded)
.BorderForeground("228")
.BorderBackground("63")
.BorderTop(true).
Expand Down
8 changes: 4 additions & 4 deletions examples/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ const titleStyle = blipgloss.NewStyle().
const descStyle = blipgloss.NewStyle().MarginTop(1)

const infoStyle = blipgloss.NewStyle().
BorderStyle('normal').
BorderStyle(blipgloss.Border.Normal).
BorderTop(true).
BorderForeground(subtle)

// Dialog.

const dialogBoxStyle = blipgloss.NewStyle().
Border('rounded').
Border(blipgloss.Border.Rounded).
BorderForeground('#874BFD').
Padding(1, 0).
BorderTop(true).
Expand All @@ -107,14 +107,14 @@ const activeButtonStyle = buttonStyle.Copy().
// List.

const list = blipgloss.NewStyle().
Border('normal', false, true, false, false).
Border(blipgloss.Border.Normal, false, true, false, false).
BorderForeground(subtle).
MarginRight(2).
Height(8).
Width(columnWidth + 1)

const listHeader = (text: string) => blipgloss.NewStyle().
BorderStyle('normal').
BorderStyle(blipgloss.Border.Normal).
BorderBottom(true).
BorderForeground(subtle).
MarginRight(2).
Expand Down
16 changes: 10 additions & 6 deletions src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,15 @@ export type CustomBorder = {
BottomRight?: string
}

export type BorderStyle = 'rounded' | 'double' | 'normal' | 'hidden' | 'thick' | CustomBorder
export enum Border {
Rounded = 'rounded',
Double = 'double',
Normal = 'normal',
Hidden = 'hidden',
Thick = 'thick'
}

export type BorderStyle = Border | CustomBorder

export class Style {
#handle: number
Expand Down Expand Up @@ -369,10 +377,6 @@ export function HasDarkBackground(): boolean {

// Utilities

function combineArgs(args: string[]) {
return args.join(",");
}

function getStringAndFreePtr(textPtr: Pointer | null) {
if (!textPtr) {
throw new Error('Pointer required')
Expand Down Expand Up @@ -439,7 +443,7 @@ export function WithWhitespaceChars(char: string) {
}

export function Place(width: number, height: number, hPos: number, vPos: number, str: string, ...whitespaceOptions: string[]) {
const combinedOptions = combineArgs(whitespaceOptions)
const combinedOptions = whitespaceOptions.join(',')
const textPtr = symbols.Place(width, height, hPos, vPos, ptr(encode(str)), ptr(encode(combinedOptions)))
return getStringAndFreePtr(textPtr);
}

0 comments on commit a0768f4

Please sign in to comment.