diff --git a/README.md b/README.md index c51bb8e..f6b0f8b 100644 --- a/README.md +++ b/README.md @@ -169,7 +169,18 @@ const anotherStyle = NewStyle() .BorderTop(true). .BorderLeft(true) -// TODO: Make own border +// Make your own border +const style = NewStyle() + .BorderStyle({ + Top: "._.:*:", + Bottom: "._.:*:", + Left: "|*", + Right: "|*", + TopLeft: "*", + TopRight: "*", + BottomLeft: "*", + BottomRight: "*", + }) ``` ## Copying Styles diff --git a/main.go b/main.go index b535d63..53e3974 100644 --- a/main.go +++ b/main.go @@ -206,3 +206,16 @@ func BorderStyle(fieldPtr, borderStylePtr *C.char) { style.BorderStyle(lipgloss.ThickBorder()) } } + +//export CustomBorder +func CustomBorder(fieldPtr, valuePtr *C.char) { + style := getStyle(fieldPtr) + border := lipgloss.Border{} + err := json.Unmarshal([]byte(str(valuePtr)), &border) + + if err != nil { + panic("Unable to parse custom border") + } + + style.BorderStyle(border) +} diff --git a/playground.ts b/playground.ts index 20d827b..cefc781 100644 --- a/playground.ts +++ b/playground.ts @@ -12,7 +12,16 @@ const style = blipgloss.NewStyle() .Width(30) .Padding(1, 4, 2) .Align(blipgloss.Position.Right) -.BorderStyle('rounded') +.BorderStyle({ + Top: "._.:*:", + Bottom: "._.:*:", + Left: "|*", + Right: "|*", + TopLeft: "*", + TopRight: "*", + BottomLeft: "*", + BottomRight: "*", +}) // console.log(style.Render("Hello, bun.")) diff --git a/src/ffi.ts b/src/ffi.ts index 3338d86..a122aab 100644 --- a/src/ffi.ts +++ b/src/ffi.ts @@ -89,6 +89,10 @@ export const { symbols } = dlopen(location, { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.void }, + CustomBorder: { + args: [FFIType.ptr, FFIType.ptr], + returns: FFIType.void + }, FreeString: { args: [FFIType.ptr], returns: FFIType.void diff --git a/src/lib.ts b/src/lib.ts index 73b47d1..fdffc1e 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -16,7 +16,18 @@ export enum Position { Right = 1.0 } -type BorderStyle = 'rounded' | 'double' | 'normal' | 'hidden' | 'thick' +export type CustomBorder = { + Top?: string + Bottom?: string + Left?: string + Right?: string + TopLeft?: string + TopRight?: string + BottomLeft?: string + BottomRight?: string +} + +export type BorderStyle = 'rounded' | 'double' | 'normal' | 'hidden' | 'thick' | CustomBorder export class Style { #handle: number @@ -158,7 +169,11 @@ export class Style { } BorderStyle(style: BorderStyle) { - symbols.BorderStyle(this.#handle, ptr(encode(style))) + if (typeof style === 'string') { + symbols.BorderStyle(this.#handle, ptr(encode(style))) + } else { + symbols.CustomBorder(this.#handle, ptr(encode(JSON.stringify(style)))) + } return this }