diff --git a/main.go b/main.go index 9c331bf..9229510 100644 --- a/main.go +++ b/main.go @@ -51,6 +51,18 @@ func Render(keyPtr *C.char, text *C.char) *C.char { return ch(m[key].Render(str(text))) } +//export SetString +func SetString(keyPtr *C.char, text *C.char) { + key := str(keyPtr) + m[key].SetString(str(text)) +} + +//export String +func String(keyPtr *C.char) *C.char { + key := str(keyPtr) + return ch(m[key].String()) +} + //export Copy func Copy(keyPtr *C.char) *C.char { key := str(keyPtr) diff --git a/playground.ts b/playground.ts index 8748b2b..d2c417e 100644 --- a/playground.ts +++ b/playground.ts @@ -1,26 +1,53 @@ import * as blipgloss from './src' +import type { AdaptiveColor, CustomBorder } from './src' -// const style = new Style() - -const style = blipgloss.NewStyle() -.Bold(true) -.Foreground("#FAFAFA") -.Background("#7D56F4") -// .PaddingTop(2) -// .PaddingBottom(2) -// .PaddingLeft(4) -.Width(30) -.Padding(1, 4, 2) -.Align(blipgloss.Position.Right) -.BorderStyle({ - Top: "._.:*:", - Bottom: "._.:*:", - Left: "|*", - Right: "|*", - TopLeft: "*", - TopRight: "*", - BottomLeft: "*", - BottomRight: "*", -}) - -console.log(style.Render("Hello, bun clone.")) +const width = 96 +const columnWidth = 30 + +// Style definitions. + +// General +const subtle: AdaptiveColor = { + Light: '#D9DCCF', + Dark: '#383838' +} +const highlight: AdaptiveColor = { + Light: '#874BFD', + Dark: '#7D56F4' +} +const special: AdaptiveColor = { + Light: '#43BF6D', + Dark: '#73F59F' +} + +const divider = blipgloss.NewStyle() + .SetString('.') + .Padding(0, 11) + .Foreground(subtle) + .String(subtle) + +const url = blipgloss.NewStyle().Foreground(special).Render + +// Tabs. + +const activeTabBorder: CustomBorder = { + Top: "─", + Bottom: " ", + Left: "│", + Right: "│", + TopLeft: "╭", + TopRight: "╮", + BottomLeft: "┘", + BottomRight: "└", +} + +const tabBorder: CustomBorder = { + Top: "─", + Bottom: "─", + Left: "│", + Right: "│", + TopLeft: "╭", + TopRight: "╮", + BottomLeft: "┴", + BottomRight: "┴", +} diff --git a/src/lib.ts b/src/lib.ts index 7dac696..1384789 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -2,26 +2,25 @@ import { CString, ptr } from 'bun:ffi' import { symbols } from './ffi' import { encode } from './utils' -type AdaptiveColor = { +export type AdaptiveColor = { Light: string Dark: string } -type CompleteColor = { +export type CompleteColor = { True: string ANSI256: string ANSI: string } -// type Pointer = number -type BlipglossColor = string | AdaptiveColor | CompleteColor +export type BlipglossColor = string | AdaptiveColor | CompleteColor export enum Position { Top = 0.0, - Bottom = 1.0, - Center = 0.5, - Left = 0.0, - Right = 1.0 + Bottom = 1.0, + Center = 0.5, + Left = 0.0, + Right = 1.0 } export type CustomBorder = { @@ -51,7 +50,7 @@ export class Style { private SetColorValue(key: string, value: BlipglossColor) { const isObject = typeof value !== 'string' const color = isObject ? ptr(encode(JSON.stringify(value))) : ptr(encode(value)) - + if (isObject) { if ('Light' in value) { // Adaptive color