From 29c03ca4c317f24f8212b1aee9b677c03ba368ed Mon Sep 17 00:00:00 2001 From: Robert Soriano Date: Sun, 31 Jul 2022 20:50:19 -0700 Subject: [PATCH] feat: Align method --- main.go | 6 ++++++ playground.ts | 26 +++++++++----------------- src/ffi.ts | 8 ++++++-- src/lib.ts | 5 +++++ 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/main.go b/main.go index bdc61bb..fcff311 100644 --- a/main.go +++ b/main.go @@ -147,3 +147,9 @@ func Width(text *C.char) int { func Height(text *C.char) int { return lipgloss.Height(str(text)) } + +//export Align +func Align(fieldPtr *C.char, position float64) { + style := m[str(fieldPtr)] + style.Align(lipgloss.Position(position)) +} diff --git a/playground.ts b/playground.ts index 1b02674..e97991f 100644 --- a/playground.ts +++ b/playground.ts @@ -6,28 +6,20 @@ const style = blipgloss.NewStyle() .Bold(true) .Foreground("#FAFAFA") .Background("#7D56F4") -.PaddingTop(2) -.PaddingBottom(2) -.PaddingLeft(4) -.Width(20) +// .PaddingTop(2) +// .PaddingBottom(2) +// .PaddingLeft(4) +.Width(30) +.Align(blipgloss.Position.Right) -console.log(style.Render("Hello, bun.")) +// console.log(style.Render("Hello, bun.")) const style2 = style.Copy() .Background({ Light: "#2B2D42", Dark: "#F8F32B" }) -.Width(30) - -console.log(style2.Render("Hello, bun clone.")) - -const test = blipgloss.JoinHorizontal( - blipgloss.Position.Top, - style.Render("Hello, bunz."), - style2.Render("Hello, bun clonez.") -) - -console.log(blipgloss.Width(style2.Render("Hello, bun clone."))) +.Width(20) +.Align(blipgloss.Position.Top) -// style.FreeString() +console.log(style.Render("Hello, bun clone.")) diff --git a/src/ffi.ts b/src/ffi.ts index 42156ed..212bd9d 100644 --- a/src/ffi.ts +++ b/src/ffi.ts @@ -58,11 +58,11 @@ export const { symbols } = dlopen(location, { returns: FFIType.void }, JoinHorizontal: { - args: [FFIType.float, FFIType.ptr], + args: [FFIType.f64, FFIType.ptr], returns: FFIType.ptr }, JoinVertical: { - args: [FFIType.float, FFIType.ptr], + args: [FFIType.f64, FFIType.ptr], returns: FFIType.ptr }, Width: { @@ -73,6 +73,10 @@ export const { symbols } = dlopen(location, { args: [FFIType.ptr], returns: FFIType.int }, + Align: { + args: [FFIType.float], + returns: FFIType.void + }, FreeString: { args: [FFIType.ptr], returns: FFIType.void diff --git a/src/lib.ts b/src/lib.ts index 49e5c68..218aef8 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -181,6 +181,11 @@ export class Style { return this.SetBooleanValue('Reverse', val) } + Align(position: Position | number) { + symbols.Align(this.#handle, position) + return this + } + Render(text: string) { const textPtr = symbols.Render(this.#handle, ptr(encode(text))) const textStr = new CString(textPtr)