lipgloss 0.0.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE.txt +21 -0
- data/README.md +467 -16
- data/ext/lipgloss/color.c +158 -0
- data/ext/lipgloss/extconf.rb +71 -0
- data/ext/lipgloss/extension.c +192 -0
- data/ext/lipgloss/extension.h +79 -0
- data/ext/lipgloss/list.c +147 -0
- data/ext/lipgloss/style.c +474 -0
- data/ext/lipgloss/style_border.c +237 -0
- data/ext/lipgloss/style_spacing.c +97 -0
- data/ext/lipgloss/style_unset.c +151 -0
- data/ext/lipgloss/table.c +242 -0
- data/ext/lipgloss/tree.c +192 -0
- data/go/color.go +168 -0
- data/go/go.mod +20 -0
- data/go/go.sum +34 -0
- data/go/layout.go +113 -0
- data/go/lipgloss.go +78 -0
- data/go/list.go +118 -0
- data/go/style.go +388 -0
- data/go/style_border.go +217 -0
- data/go/style_spacing.go +94 -0
- data/go/style_unset.go +129 -0
- data/go/table.go +218 -0
- data/go/tree.go +138 -0
- data/lib/lipgloss/border.rb +48 -0
- data/lib/lipgloss/color.rb +133 -0
- data/lib/lipgloss/position.rb +50 -0
- data/lib/lipgloss/style.rb +24 -0
- data/lib/lipgloss/table.rb +63 -0
- data/lib/lipgloss/version.rb +2 -1
- data/lib/lipgloss.rb +71 -2
- data/lipgloss.gemspec +34 -0
- metadata +41 -15
- data/CHANGELOG.md +0 -5
- data/CODE_OF_CONDUCT.md +0 -132
- data/Rakefile +0 -12
- data/sig/lipgloss.rbs +0 -4
data/go/tree.go
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
package main
|
|
2
|
+
|
|
3
|
+
import "C"
|
|
4
|
+
|
|
5
|
+
import (
|
|
6
|
+
"encoding/json"
|
|
7
|
+
lipglosstree "github.com/charmbracelet/lipgloss/tree"
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
func allocTree(tree *lipglosstree.Tree) uint64 {
|
|
11
|
+
treesMu.Lock()
|
|
12
|
+
defer treesMu.Unlock()
|
|
13
|
+
id := getNextID()
|
|
14
|
+
trees[id] = tree
|
|
15
|
+
|
|
16
|
+
return id
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
func getTree(id uint64) *lipglosstree.Tree {
|
|
20
|
+
treesMu.RLock()
|
|
21
|
+
defer treesMu.RUnlock()
|
|
22
|
+
|
|
23
|
+
return trees[id]
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//export lipgloss_tree_new
|
|
27
|
+
func lipgloss_tree_new() C.ulonglong {
|
|
28
|
+
return C.ulonglong(allocTree(lipglosstree.New()))
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
//export lipgloss_tree_root
|
|
32
|
+
func lipgloss_tree_root(root *C.char) C.ulonglong {
|
|
33
|
+
return C.ulonglong(allocTree(lipglosstree.Root(C.GoString(root))))
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
//export lipgloss_tree_free
|
|
37
|
+
func lipgloss_tree_free(id C.ulonglong) {
|
|
38
|
+
treesMu.Lock()
|
|
39
|
+
defer treesMu.Unlock()
|
|
40
|
+
delete(trees, uint64(id))
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
//export lipgloss_tree_set_root
|
|
44
|
+
func lipgloss_tree_set_root(id C.ulonglong, root *C.char) C.ulonglong {
|
|
45
|
+
tree := getTree(uint64(id)).Root(C.GoString(root))
|
|
46
|
+
|
|
47
|
+
return C.ulonglong(allocTree(tree))
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
//export lipgloss_tree_child
|
|
51
|
+
func lipgloss_tree_child(id C.ulonglong, child *C.char) C.ulonglong {
|
|
52
|
+
tree := getTree(uint64(id)).Child(C.GoString(child))
|
|
53
|
+
|
|
54
|
+
return C.ulonglong(allocTree(tree))
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
//export lipgloss_tree_child_tree
|
|
58
|
+
func lipgloss_tree_child_tree(id C.ulonglong, childTreeID C.ulonglong) C.ulonglong {
|
|
59
|
+
childTree := getTree(uint64(childTreeID))
|
|
60
|
+
tree := getTree(uint64(id)).Child(childTree)
|
|
61
|
+
|
|
62
|
+
return C.ulonglong(allocTree(tree))
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//export lipgloss_tree_children
|
|
66
|
+
func lipgloss_tree_children(id C.ulonglong, childrenJSON *C.char) C.ulonglong {
|
|
67
|
+
var children []string
|
|
68
|
+
|
|
69
|
+
if err := json.Unmarshal([]byte(C.GoString(childrenJSON)), &children); err != nil {
|
|
70
|
+
return id
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
anyChildren := make([]any, len(children))
|
|
74
|
+
|
|
75
|
+
for index, child := range children {
|
|
76
|
+
anyChildren[index] = child
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
tree := getTree(uint64(id)).Child(anyChildren...)
|
|
80
|
+
|
|
81
|
+
return C.ulonglong(allocTree(tree))
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
//export lipgloss_tree_enumerator
|
|
85
|
+
func lipgloss_tree_enumerator(id C.ulonglong, enumType C.int) C.ulonglong {
|
|
86
|
+
var enumerator lipglosstree.Enumerator
|
|
87
|
+
|
|
88
|
+
switch int(enumType) {
|
|
89
|
+
case 0:
|
|
90
|
+
enumerator = lipglosstree.DefaultEnumerator
|
|
91
|
+
case 1:
|
|
92
|
+
enumerator = lipglosstree.RoundedEnumerator
|
|
93
|
+
default:
|
|
94
|
+
enumerator = lipglosstree.DefaultEnumerator
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
tree := getTree(uint64(id)).Enumerator(enumerator)
|
|
98
|
+
|
|
99
|
+
return C.ulonglong(allocTree(tree))
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
//export lipgloss_tree_enumerator_style
|
|
103
|
+
func lipgloss_tree_enumerator_style(id C.ulonglong, styleID C.ulonglong) C.ulonglong {
|
|
104
|
+
style := getStyle(uint64(styleID))
|
|
105
|
+
tree := getTree(uint64(id)).EnumeratorStyle(style)
|
|
106
|
+
|
|
107
|
+
return C.ulonglong(allocTree(tree))
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
//export lipgloss_tree_item_style
|
|
111
|
+
func lipgloss_tree_item_style(id C.ulonglong, styleID C.ulonglong) C.ulonglong {
|
|
112
|
+
style := getStyle(uint64(styleID))
|
|
113
|
+
tree := getTree(uint64(id)).ItemStyle(style)
|
|
114
|
+
|
|
115
|
+
return C.ulonglong(allocTree(tree))
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
//export lipgloss_tree_root_style
|
|
119
|
+
func lipgloss_tree_root_style(id C.ulonglong, styleID C.ulonglong) C.ulonglong {
|
|
120
|
+
style := getStyle(uint64(styleID))
|
|
121
|
+
tree := getTree(uint64(id)).RootStyle(style)
|
|
122
|
+
|
|
123
|
+
return C.ulonglong(allocTree(tree))
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
//export lipgloss_tree_offset
|
|
127
|
+
func lipgloss_tree_offset(id C.ulonglong, start C.int, end C.int) C.ulonglong {
|
|
128
|
+
tree := getTree(uint64(id)).Offset(int(start), int(end))
|
|
129
|
+
|
|
130
|
+
return C.ulonglong(allocTree(tree))
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
//export lipgloss_tree_render
|
|
134
|
+
func lipgloss_tree_render(id C.ulonglong) *C.char {
|
|
135
|
+
tree := getTree(uint64(id))
|
|
136
|
+
|
|
137
|
+
return C.CString(tree.String())
|
|
138
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# rbs_inline: enabled
|
|
3
|
+
|
|
4
|
+
module Lipgloss
|
|
5
|
+
module Border
|
|
6
|
+
# Standard border with normal weight and 90 degree corners
|
|
7
|
+
# ┌───┐
|
|
8
|
+
# │ │
|
|
9
|
+
# └───┘
|
|
10
|
+
NORMAL = :normal
|
|
11
|
+
|
|
12
|
+
# Border with rounded corners
|
|
13
|
+
# ╭───╮
|
|
14
|
+
# │ │
|
|
15
|
+
# ╰───╯
|
|
16
|
+
ROUNDED = :rounded
|
|
17
|
+
|
|
18
|
+
# Thicker border
|
|
19
|
+
# ┏━━━┓
|
|
20
|
+
# ┃ ┃
|
|
21
|
+
# ┗━━━┛
|
|
22
|
+
THICK = :thick
|
|
23
|
+
|
|
24
|
+
# Double-line border
|
|
25
|
+
# ╔═══╗
|
|
26
|
+
# ║ ║
|
|
27
|
+
# ╚═══╝
|
|
28
|
+
DOUBLE = :double
|
|
29
|
+
|
|
30
|
+
# ASCII border (compatible with all terminals)
|
|
31
|
+
# +---+
|
|
32
|
+
# | |
|
|
33
|
+
# +---+
|
|
34
|
+
ASCII = :ascii
|
|
35
|
+
|
|
36
|
+
# Hidden border (spaces, maintains layout)
|
|
37
|
+
HIDDEN = :hidden
|
|
38
|
+
|
|
39
|
+
# Block border (full blocks)
|
|
40
|
+
# ████
|
|
41
|
+
# █ █
|
|
42
|
+
# ████
|
|
43
|
+
BLOCK = :block
|
|
44
|
+
|
|
45
|
+
OUTER_HALF_BLOCK = :outer_half_block
|
|
46
|
+
INNER_HALF_BLOCK = :inner_half_block
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# rbs_inline: enabled
|
|
3
|
+
|
|
4
|
+
module Lipgloss
|
|
5
|
+
# @rbs!
|
|
6
|
+
# type adaptive_color_hash = { light: String, dark: String }
|
|
7
|
+
# type complete_color_hash = { true_color: String, ansi256: String, ansi: String }
|
|
8
|
+
# type complete_adaptive_color_hash = { light: complete_color_hash, dark: complete_color_hash }
|
|
9
|
+
|
|
10
|
+
module ANSIColor
|
|
11
|
+
# @rbs!
|
|
12
|
+
# type ansi_color_symbol = :black | :red | :green | :yellow | :blue | :magenta | :cyan | :white | :bright_black | :bright_red | :bright_green | :bright_yellow | :bright_blue | :bright_magenta | :bright_cyan | :bright_white
|
|
13
|
+
# type ansi_color_value = ansi_color_symbol | Symbol | String | Integer
|
|
14
|
+
|
|
15
|
+
COLORS = {
|
|
16
|
+
black: "0",
|
|
17
|
+
red: "1",
|
|
18
|
+
green: "2",
|
|
19
|
+
yellow: "3",
|
|
20
|
+
blue: "4",
|
|
21
|
+
magenta: "5",
|
|
22
|
+
cyan: "6",
|
|
23
|
+
white: "7",
|
|
24
|
+
bright_black: "8",
|
|
25
|
+
bright_red: "9",
|
|
26
|
+
bright_green: "10",
|
|
27
|
+
bright_yellow: "11",
|
|
28
|
+
bright_blue: "12",
|
|
29
|
+
bright_magenta: "13",
|
|
30
|
+
bright_cyan: "14",
|
|
31
|
+
bright_white: "15"
|
|
32
|
+
}.freeze #: Hash[Symbol, String]
|
|
33
|
+
|
|
34
|
+
# @rbs value: ansi_color_value
|
|
35
|
+
# @rbs return: String
|
|
36
|
+
def self.resolve(value)
|
|
37
|
+
case value
|
|
38
|
+
when Symbol then COLORS.fetch(value) { raise ArgumentError, "Unknown ANSI color: #{value.inspect}" }
|
|
39
|
+
when String then value
|
|
40
|
+
when Integer then value.to_s
|
|
41
|
+
else raise ArgumentError, "ANSI color must be a Symbol, String, or Integer, got #{value.class}"
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Adaptive color that changes based on terminal background
|
|
47
|
+
#
|
|
48
|
+
# @example
|
|
49
|
+
# color = Lipgloss::AdaptiveColor.new(light: "#000000", dark: "#FFFFFF")
|
|
50
|
+
# style = Lipgloss::Style.new.foreground(color)
|
|
51
|
+
class AdaptiveColor
|
|
52
|
+
# @rbs @light: String
|
|
53
|
+
# @rbs @dark: String
|
|
54
|
+
|
|
55
|
+
attr_reader :light #: String
|
|
56
|
+
attr_reader :dark #: String
|
|
57
|
+
|
|
58
|
+
# @rbs light: String -- color to use on light backgrounds
|
|
59
|
+
# @rbs dark: String -- color to use on dark backgrounds
|
|
60
|
+
# @rbs return: void
|
|
61
|
+
def initialize(light:, dark:)
|
|
62
|
+
@light = light
|
|
63
|
+
@dark = dark
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# @rbs return: adaptive_color_hash
|
|
67
|
+
def to_h
|
|
68
|
+
{ light: @light, dark: @dark }
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Complete color with explicit values for each color profile
|
|
73
|
+
#
|
|
74
|
+
# @example
|
|
75
|
+
# color = Lipgloss::CompleteColor.new(
|
|
76
|
+
# true_color: "#0000FF",
|
|
77
|
+
# ansi256: 21,
|
|
78
|
+
# ansi: :blue
|
|
79
|
+
# )
|
|
80
|
+
class CompleteColor
|
|
81
|
+
# @rbs @true_color: String
|
|
82
|
+
# @rbs @ansi256: String
|
|
83
|
+
# @rbs @ansi: String
|
|
84
|
+
|
|
85
|
+
attr_reader :true_color #: String
|
|
86
|
+
attr_reader :ansi256 #: String
|
|
87
|
+
attr_reader :ansi #: String
|
|
88
|
+
|
|
89
|
+
# @rbs true_color: String -- 24-bit color (e.g., "#0000FF")
|
|
90
|
+
# @rbs ansi256: ANSIColor::ansi_color_value -- 8-bit ANSI color (0-255, or symbol for 0-15)
|
|
91
|
+
# @rbs ansi: ANSIColor::ansi_color_value -- 4-bit ANSI color (:red, :blue, etc., or 0-15)
|
|
92
|
+
# @rbs return: void
|
|
93
|
+
def initialize(true_color:, ansi256:, ansi:)
|
|
94
|
+
@true_color = true_color
|
|
95
|
+
@ansi256 = ANSIColor.resolve(ansi256)
|
|
96
|
+
@ansi = ANSIColor.resolve(ansi)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# @rbs return: complete_color_hash
|
|
100
|
+
def to_h
|
|
101
|
+
{ true_color: @true_color, ansi256: @ansi256, ansi: @ansi }
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# Complete adaptive color with explicit values for each color profile
|
|
106
|
+
# and separate options for light and dark backgrounds
|
|
107
|
+
#
|
|
108
|
+
# @example
|
|
109
|
+
# color = Lipgloss::CompleteAdaptiveColor.new(
|
|
110
|
+
# light: Lipgloss::CompleteColor.new(true_color: "#000", ansi256: :black, ansi: :black),
|
|
111
|
+
# dark: Lipgloss::CompleteColor.new(true_color: "#FFF", ansi256: :bright_white, ansi: :bright_white)
|
|
112
|
+
# )
|
|
113
|
+
class CompleteAdaptiveColor
|
|
114
|
+
# @rbs @light: CompleteColor
|
|
115
|
+
# @rbs @dark: CompleteColor
|
|
116
|
+
|
|
117
|
+
attr_reader :light #: CompleteColor
|
|
118
|
+
attr_reader :dark #: CompleteColor
|
|
119
|
+
|
|
120
|
+
# @rbs light: CompleteColor -- color for light backgrounds
|
|
121
|
+
# @rbs dark: CompleteColor -- color for dark backgrounds
|
|
122
|
+
# @rbs return: void
|
|
123
|
+
def initialize(light:, dark:)
|
|
124
|
+
@light = light
|
|
125
|
+
@dark = dark
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# @rbs return: complete_adaptive_color_hash
|
|
129
|
+
def to_h
|
|
130
|
+
{ light: @light.to_h, dark: @dark.to_h }
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# rbs_inline: enabled
|
|
3
|
+
|
|
4
|
+
module Lipgloss
|
|
5
|
+
# Position constants for alignment
|
|
6
|
+
#
|
|
7
|
+
# Positions are represented as floats from 0.0 to 1.0:
|
|
8
|
+
# - 0.0 = top/left
|
|
9
|
+
# - 0.5 = center
|
|
10
|
+
# - 1.0 = bottom/right
|
|
11
|
+
module Position
|
|
12
|
+
# Top alignment (0.0)
|
|
13
|
+
TOP = 0.0
|
|
14
|
+
|
|
15
|
+
# Bottom alignment (1.0)
|
|
16
|
+
BOTTOM = 1.0
|
|
17
|
+
|
|
18
|
+
# Left alignment (0.0)
|
|
19
|
+
LEFT = 0.0
|
|
20
|
+
|
|
21
|
+
# Right alignment (1.0)
|
|
22
|
+
RIGHT = 1.0
|
|
23
|
+
|
|
24
|
+
# Center alignment (0.5)
|
|
25
|
+
CENTER = 0.5
|
|
26
|
+
|
|
27
|
+
# @rbs!
|
|
28
|
+
# type position_symbol = :top | :bottom | :left | :right | :center
|
|
29
|
+
# type position_value = position_symbol | Symbol | String | Integer | Float
|
|
30
|
+
|
|
31
|
+
SYMBOLS = {
|
|
32
|
+
top: TOP,
|
|
33
|
+
bottom: BOTTOM,
|
|
34
|
+
left: LEFT,
|
|
35
|
+
right: RIGHT,
|
|
36
|
+
center: CENTER
|
|
37
|
+
}.freeze #: Hash[Symbol, Float]
|
|
38
|
+
|
|
39
|
+
# @rbs value: position_value
|
|
40
|
+
# @rbs return: Float
|
|
41
|
+
def self.resolve(value)
|
|
42
|
+
case value
|
|
43
|
+
when Symbol then SYMBOLS.fetch(value) { raise ArgumentError, "Unknown position: #{value.inspect}" }
|
|
44
|
+
when String then SYMBOLS.fetch(value.to_sym) { raise ArgumentError, "Unknown position: #{value.inspect}" }
|
|
45
|
+
when Numeric then value.to_f
|
|
46
|
+
else raise ArgumentError, "Position must be a Symbol or Numeric, got #{value.class}"
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# rbs_inline: enabled
|
|
3
|
+
|
|
4
|
+
module Lipgloss
|
|
5
|
+
class Style
|
|
6
|
+
# @rbs *positions: Position::position_value
|
|
7
|
+
# @rbs return: Style
|
|
8
|
+
def align(*positions)
|
|
9
|
+
_align(*positions.map { |p| Position.resolve(p) })
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# @rbs position: Position::position_value
|
|
13
|
+
# @rbs return: Style
|
|
14
|
+
def align_horizontal(position)
|
|
15
|
+
_align_horizontal(Position.resolve(position))
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# @rbs position: Position::position_value
|
|
19
|
+
# @rbs return: Style
|
|
20
|
+
def align_vertical(position)
|
|
21
|
+
_align_vertical(Position.resolve(position))
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# rbs_inline: enabled
|
|
3
|
+
|
|
4
|
+
module Lipgloss
|
|
5
|
+
# Ruby enhancements for the Table class
|
|
6
|
+
#
|
|
7
|
+
# The Table class is implemented in C, but this module adds
|
|
8
|
+
# Ruby-level conveniences like style_func with blocks.
|
|
9
|
+
class Table
|
|
10
|
+
# Header row constant (used in style_func)
|
|
11
|
+
HEADER_ROW = -1
|
|
12
|
+
|
|
13
|
+
# Set a style function that determines the style for each cell
|
|
14
|
+
#
|
|
15
|
+
# @example Alternating row colors
|
|
16
|
+
# table.style_func(rows: 2, columns: 2) do |row, column|
|
|
17
|
+
# if row == Lipgloss::Table::HEADER_ROW
|
|
18
|
+
# Lipgloss::Style.new.bold(true)
|
|
19
|
+
# elsif row.even?
|
|
20
|
+
# Lipgloss::Style.new.background("#333")
|
|
21
|
+
# else
|
|
22
|
+
# Lipgloss::Style.new.background("#444")
|
|
23
|
+
# end
|
|
24
|
+
# end
|
|
25
|
+
#
|
|
26
|
+
# @example Column-specific styling
|
|
27
|
+
# table.style_func(rows: 2, columns: 2) do |row, column|
|
|
28
|
+
# case column
|
|
29
|
+
# when 0 then Lipgloss::Style.new.bold(true)
|
|
30
|
+
# when 1 then Lipgloss::Style.new.foreground("#00FF00")
|
|
31
|
+
# else Lipgloss::Style.new
|
|
32
|
+
# end
|
|
33
|
+
# end
|
|
34
|
+
#
|
|
35
|
+
# @rbs rows: Integer -- number of data rows in the table
|
|
36
|
+
# @rbs columns: Integer -- number of columns in the table
|
|
37
|
+
# @rbs &block: (Integer, Integer) -> Style? -- block called for each cell position
|
|
38
|
+
# @rbs return: Table -- a new table with the style function applied
|
|
39
|
+
def style_func(rows:, columns:, &block)
|
|
40
|
+
raise ArgumentError, "block required" unless block_given?
|
|
41
|
+
raise ArgumentError, "rows must be >= 0" if rows.negative?
|
|
42
|
+
raise ArgumentError, "columns must be > 0" if columns <= 0
|
|
43
|
+
|
|
44
|
+
style_map = {} #: Hash[String, Style]
|
|
45
|
+
|
|
46
|
+
# Header row
|
|
47
|
+
columns.times do |column|
|
|
48
|
+
style = block.call(HEADER_ROW, column)
|
|
49
|
+
style_map["#{HEADER_ROW},#{column}"] = style if style
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Data rows
|
|
53
|
+
rows.times do |row|
|
|
54
|
+
columns.times do |column|
|
|
55
|
+
style = block.call(row, column)
|
|
56
|
+
style_map["#{row},#{column}"] = style if style
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
_style_func_map(style_map)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
data/lib/lipgloss/version.rb
CHANGED
data/lib/lipgloss.rb
CHANGED
|
@@ -1,8 +1,77 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
# rbs_inline: enabled
|
|
2
3
|
|
|
3
4
|
require_relative "lipgloss/version"
|
|
4
5
|
|
|
6
|
+
begin
|
|
7
|
+
major, minor, _patch = RUBY_VERSION.split(".") #: [String, String, String]
|
|
8
|
+
require_relative "lipgloss/#{major}.#{minor}/lipgloss"
|
|
9
|
+
rescue LoadError
|
|
10
|
+
require_relative "lipgloss/lipgloss"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
require_relative "lipgloss/position"
|
|
14
|
+
require_relative "lipgloss/border"
|
|
15
|
+
require_relative "lipgloss/color"
|
|
16
|
+
require_relative "lipgloss/style"
|
|
17
|
+
require_relative "lipgloss/table"
|
|
18
|
+
|
|
5
19
|
module Lipgloss
|
|
6
|
-
|
|
7
|
-
|
|
20
|
+
TOP = Position::TOP #: Float
|
|
21
|
+
BOTTOM = Position::BOTTOM #: Float
|
|
22
|
+
LEFT = Position::LEFT #: Float
|
|
23
|
+
RIGHT = Position::RIGHT #: Float
|
|
24
|
+
CENTER = Position::CENTER #: Float
|
|
25
|
+
|
|
26
|
+
NORMAL_BORDER = Border::NORMAL #: Symbol
|
|
27
|
+
ROUNDED_BORDER = Border::ROUNDED #: Symbol
|
|
28
|
+
THICK_BORDER = Border::THICK #: Symbol
|
|
29
|
+
DOUBLE_BORDER = Border::DOUBLE #: Symbol
|
|
30
|
+
HIDDEN_BORDER = Border::HIDDEN #: Symbol
|
|
31
|
+
BLOCK_BORDER = Border::BLOCK #: Symbol
|
|
32
|
+
ASCII_BORDER = Border::ASCII #: Symbol
|
|
33
|
+
|
|
34
|
+
NO_TAB_CONVERSION = -1 #: Integer
|
|
35
|
+
|
|
36
|
+
class << self
|
|
37
|
+
# @rbs position: Position::position_value
|
|
38
|
+
# @rbs *strings: String
|
|
39
|
+
# @rbs return: String
|
|
40
|
+
def join_horizontal(position, *strings)
|
|
41
|
+
_join_horizontal(Position.resolve(position), strings)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# @rbs position: Position::position_value
|
|
45
|
+
# @rbs *strings: String
|
|
46
|
+
# @rbs return: String
|
|
47
|
+
def join_vertical(position, *strings)
|
|
48
|
+
_join_vertical(Position.resolve(position), strings)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# @rbs width: Integer
|
|
52
|
+
# @rbs height: Integer
|
|
53
|
+
# @rbs horizontal: Position::position_value
|
|
54
|
+
# @rbs vertical: Position::position_value
|
|
55
|
+
# @rbs string: String
|
|
56
|
+
# @rbs return: String
|
|
57
|
+
def place(width, height, horizontal, vertical, string, **opts)
|
|
58
|
+
_place(width, height, Position.resolve(horizontal), Position.resolve(vertical), string, **opts)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# @rbs width: Integer
|
|
62
|
+
# @rbs position: Position::position_value
|
|
63
|
+
# @rbs string: String
|
|
64
|
+
# @rbs return: String
|
|
65
|
+
def place_horizontal(width, position, string)
|
|
66
|
+
_place_horizontal(width, Position.resolve(position), string)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# @rbs height: Integer
|
|
70
|
+
# @rbs position: Position::position_value
|
|
71
|
+
# @rbs string: String
|
|
72
|
+
# @rbs return: String
|
|
73
|
+
def place_vertical(height, position, string)
|
|
74
|
+
_place_vertical(height, Position.resolve(position), string)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
8
77
|
end
|
data/lipgloss.gemspec
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "lib/lipgloss/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "lipgloss"
|
|
7
|
+
spec.version = Lipgloss::VERSION
|
|
8
|
+
spec.authors = ["Marco Roth"]
|
|
9
|
+
spec.email = ["marco.roth@intergga.ch"]
|
|
10
|
+
|
|
11
|
+
spec.summary = "Ruby wrapper for Charm's lipgloss. CSS-like terminal styling library."
|
|
12
|
+
spec.description = "Style Definitions for Nice Terminal Layouts. Built with TUIs in mind."
|
|
13
|
+
spec.homepage = "https://github.com/marcoroth/lipgloss-ruby"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
spec.required_ruby_version = ">= 3.2.0"
|
|
16
|
+
|
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/marcoroth/lipgloss-ruby"
|
|
19
|
+
spec.metadata["changelog_uri"] = "https://github.com/marcoroth/lipgloss-ruby/releases"
|
|
20
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
|
21
|
+
|
|
22
|
+
spec.files = Dir[
|
|
23
|
+
"lipgloss.gemspec",
|
|
24
|
+
"LICENSE.txt",
|
|
25
|
+
"README.md",
|
|
26
|
+
"lib/**/*.rb",
|
|
27
|
+
"ext/**/*.{c,h,rb}",
|
|
28
|
+
"go/**/*.{go,mod,sum}",
|
|
29
|
+
"go/build/**/*"
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
spec.require_paths = ["lib"]
|
|
33
|
+
spec.extensions = ["ext/lipgloss/extconf.rb"]
|
|
34
|
+
end
|
metadata
CHANGED
|
@@ -1,36 +1,62 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lipgloss
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Marco Roth
|
|
8
|
-
bindir:
|
|
8
|
+
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies: []
|
|
12
|
-
description: Style
|
|
13
|
-
with the RubyGems infrastructure.
|
|
12
|
+
description: Style Definitions for Nice Terminal Layouts. Built with TUIs in mind.
|
|
14
13
|
email:
|
|
15
14
|
- marco.roth@intergga.ch
|
|
16
15
|
executables: []
|
|
17
|
-
extensions:
|
|
16
|
+
extensions:
|
|
17
|
+
- ext/lipgloss/extconf.rb
|
|
18
18
|
extra_rdoc_files: []
|
|
19
19
|
files:
|
|
20
|
-
-
|
|
21
|
-
- CODE_OF_CONDUCT.md
|
|
20
|
+
- LICENSE.txt
|
|
22
21
|
- README.md
|
|
23
|
-
-
|
|
22
|
+
- ext/lipgloss/color.c
|
|
23
|
+
- ext/lipgloss/extconf.rb
|
|
24
|
+
- ext/lipgloss/extension.c
|
|
25
|
+
- ext/lipgloss/extension.h
|
|
26
|
+
- ext/lipgloss/list.c
|
|
27
|
+
- ext/lipgloss/style.c
|
|
28
|
+
- ext/lipgloss/style_border.c
|
|
29
|
+
- ext/lipgloss/style_spacing.c
|
|
30
|
+
- ext/lipgloss/style_unset.c
|
|
31
|
+
- ext/lipgloss/table.c
|
|
32
|
+
- ext/lipgloss/tree.c
|
|
33
|
+
- go/color.go
|
|
34
|
+
- go/go.mod
|
|
35
|
+
- go/go.sum
|
|
36
|
+
- go/layout.go
|
|
37
|
+
- go/lipgloss.go
|
|
38
|
+
- go/list.go
|
|
39
|
+
- go/style.go
|
|
40
|
+
- go/style_border.go
|
|
41
|
+
- go/style_spacing.go
|
|
42
|
+
- go/style_unset.go
|
|
43
|
+
- go/table.go
|
|
44
|
+
- go/tree.go
|
|
24
45
|
- lib/lipgloss.rb
|
|
46
|
+
- lib/lipgloss/border.rb
|
|
47
|
+
- lib/lipgloss/color.rb
|
|
48
|
+
- lib/lipgloss/position.rb
|
|
49
|
+
- lib/lipgloss/style.rb
|
|
50
|
+
- lib/lipgloss/table.rb
|
|
25
51
|
- lib/lipgloss/version.rb
|
|
26
|
-
-
|
|
27
|
-
homepage: https://github.com/marcoroth/lipgloss
|
|
52
|
+
- lipgloss.gemspec
|
|
53
|
+
homepage: https://github.com/marcoroth/lipgloss-ruby
|
|
28
54
|
licenses:
|
|
29
55
|
- MIT
|
|
30
56
|
metadata:
|
|
31
|
-
homepage_uri: https://github.com/marcoroth/lipgloss
|
|
32
|
-
source_code_uri: https://github.com/marcoroth/lipgloss
|
|
33
|
-
changelog_uri: https://github.com/marcoroth/lipgloss/
|
|
57
|
+
homepage_uri: https://github.com/marcoroth/lipgloss-ruby
|
|
58
|
+
source_code_uri: https://github.com/marcoroth/lipgloss-ruby
|
|
59
|
+
changelog_uri: https://github.com/marcoroth/lipgloss-ruby/releases
|
|
34
60
|
rubygems_mfa_required: 'true'
|
|
35
61
|
rdoc_options: []
|
|
36
62
|
require_paths:
|
|
@@ -46,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
46
72
|
- !ruby/object:Gem::Version
|
|
47
73
|
version: '0'
|
|
48
74
|
requirements: []
|
|
49
|
-
rubygems_version:
|
|
75
|
+
rubygems_version: 4.0.3
|
|
50
76
|
specification_version: 4
|
|
51
|
-
summary: Ruby wrapper for Charm's lipgloss
|
|
77
|
+
summary: Ruby wrapper for Charm's lipgloss. CSS-like terminal styling library.
|
|
52
78
|
test_files: []
|