Skip to content

Commit

Permalink
feat: add SetString and String methods
Browse files Browse the repository at this point in the history
  • Loading branch information
wobsoriano committed Sep 16, 2023
1 parent a24cc9e commit f25dd6a
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 33 deletions.
12 changes: 12 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
75 changes: 51 additions & 24 deletions playground.ts
Original file line number Diff line number Diff line change
@@ -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: "┴",
}
17 changes: 8 additions & 9 deletions src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f25dd6a

Please sign in to comment.