Skip to content

Commit a1b37c0

Browse files
sravioliDrKJeff16
authored andcommitted
feat(ribbon): add type annotations
1 parent e849b9d commit a1b37c0

5 files changed

Lines changed: 151 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ This project also features type annotations for various WezTerm plugins.
8888
| [quick_domains.wezterm](https://github.com/DavidRR-F/quick_domains.wezterm) | [docs/quick-domains.md](./docs/quick-domains.md) | [:h wezterm-types-plugin.quick_domains.txt](./doc/wezterm-types-plugin.quick_domains.txt) |
8989
| [quickselect.wezterm](https://github.com/quantonganh/quickselect.wezterm) | [docs/quickselect.md](./docs/quickselect.md) | [:h wezterm-types-plugin.quickselect.txt](./doc/wezterm-types-plugin.quickselect.txt) |
9090
| [resurrect.wezterm](https://github.com/MLFlexer/resurrect.wezterm) | [docs/resurrect.md](./docs/resurrect.md) | [:h wezterm-types-plugin.resurrect.txt](./doc/wezterm-types-plugin.resurrect.txt) |
91+
| [ribbon.wz](https://github.com/sravioli/ribbon.wz) | [docs/ribbon.md](./docs/ribbon.md) | [:h wezterm-types-plugin.ribbon.txt](./doc/wezterm-types-plugin.ribbon.txt) |
9192
| [rosepine](https://github.com/neapsix/wezterm) | [docs/rosepine.md](./docs/rosepine.md) | [:h wezterm-types-plugin.rosepine.txt](./doc/wezterm-types-plugin.rosepine.txt) |
9293
| [sessionizer.wezterm](https://github.com/mikkasendke/sessionizer.wezterm) | [docs/sessionizer.md](./docs/sessionizer.md) | [:h wezterm-types-plugin.sessionizer.txt](./doc/wezterm-types-plugin.sessionizer.txt) |
9394
| [smart-splits.nvim](https://github.com/mrjones2014/smart-splits.nvim) | [docs/smart-splits.md](./docs/smart-splits.md) | [:h wezterm-types-plugin.smart-splits.txt](./doc/wezterm-types-plugin.smart-splits.txt) |
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*wezterm-types-plugin.ribbon.txt* `ribbon` types
2+
3+
RIBBON.WZ ~
4+
5+
You can import type annotations for `sravioli/ribbon.wz`
6+
<https://github.com/sravioli/ribbon.wz> as shown below:
7+
8+
>lua
9+
---@type Ribbon.Api
10+
local ribbon = wezterm.plugin.require("https://github.com/sravioli/ribbon.wz")
11+
<
12+
13+
Generated by panvimdoc <https://github.com/kdheepak/panvimdoc>
14+
15+
vim:tw=78:ts=8:noet:ft=help:norl:

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ We will keep adding more community plugins as we find them.
2424
- [quick_domains.wezterm](./quick-domains.md)
2525
- [quickselect.wezterm](./quickselect.md)
2626
- [resurrect.wezterm](./resurrect.md)
27+
- [ribbon.wz](./ribbon.md)
2728
- [rosepine](./rosepine.md)
2829
- [sessionizer.wezterm](./sessionizer.md)
2930
- [smart-splits.nvim](./smart-splits.md)

docs/ribbon.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
### `ribbon.wz`
2+
3+
You can import type annotations for
4+
[`sravioli/ribbon.wz`](https://github.com/sravioli/ribbon.wz) as shown below:
5+
6+
```lua
7+
---@type Ribbon.Api
8+
local ribbon = wezterm.plugin.require("https://github.com/sravioli/ribbon.wz")
9+
```
10+
11+
<!-- vim: set ts=2 sts=2 sw=2 et ai si sta: -->
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
---@meta
2+
---@diagnostic disable:unused-local
3+
4+
---@alias Ribbon.Attribute string|string[]
5+
---@alias Ribbon.FormatItem string|table
6+
7+
---@class Ribbon.LogConfig
8+
---@field enabled boolean
9+
---@field threshold "DEBUG"|"INFO"|"WARN"|"ERROR"|integer
10+
---@field sinks? table Accepted for compatibility with older layout options.
11+
12+
---@class Ribbon.Defaults
13+
---@field foreground? string Default foreground color.
14+
---@field background? string Default background color.
15+
---@field attributes table<string, table|string> Named text attributes.
16+
---@field colors table<string, boolean> ANSI color-name lookup table.
17+
18+
---@class Ribbon.TextConfig
19+
---@field strip boolean Trim text before inserting it.
20+
---@field max_length? integer Maximum text length before truncation.
21+
---@field transform? fun(text: string): string Text transform callback.
22+
23+
---@class Ribbon.Config
24+
---@field log Ribbon.LogConfig
25+
---@field defaults Ribbon.Defaults
26+
---@field attribute_aliases table<string, string|string[]> Attribute aliases.
27+
---@field validate_attributes boolean Warn or error on unknown attributes.
28+
---@field strict_mode boolean Error on unknown attributes when validation is enabled.
29+
---@field text Ribbon.TextConfig
30+
---@field atomic boolean Reset attributes after every text segment.
31+
32+
---@class Ribbon.ConfigModule
33+
local Config = {}
34+
35+
---Configure Ribbon.
36+
---@param opts? table Partial Ribbon configuration.
37+
---@return Ribbon.Config config
38+
function Config.setup(opts) end
39+
40+
---Return the active Ribbon configuration.
41+
---@return Ribbon.Config config
42+
function Config.get() end
43+
44+
---Return a copy of Ribbon defaults.
45+
---@return Ribbon.Config defaults
46+
function Config.defaults() end
47+
48+
---@class Ribbon
49+
---@field atomic? boolean Whether attributes reset after each segment.
50+
---@field log table Logger instance.
51+
local R = {}
52+
53+
---Add an element to the ribbon.
54+
---@param action "append"|"prepend"
55+
---@param background? string Background color name or value.
56+
---@param foreground? string Foreground color name or value.
57+
---@param text? string Text to insert.
58+
---@param attributes? Ribbon.Attribute Text attributes or aliases.
59+
---@return Ribbon|nil self
60+
function R:add(action, background, foreground, text, attributes) end
61+
62+
---Append a formatted text segment.
63+
---@param background? string Background color name or value.
64+
---@param foreground? string Foreground color name or value.
65+
---@param text? string Text to insert.
66+
---@param attributes? Ribbon.Attribute Text attributes or aliases.
67+
---@return Ribbon|nil self
68+
function R:append(background, foreground, text, attributes) end
69+
70+
---Prepend a formatted text segment.
71+
---@param background? string Background color name or value.
72+
---@param foreground? string Foreground color name or value.
73+
---@param text? string Text to insert.
74+
---@param attributes? Ribbon.Attribute Text attributes or aliases.
75+
---@return Ribbon|nil self
76+
function R:prepend(background, foreground, text, attributes) end
77+
78+
---Append raw `wezterm.format` items.
79+
---@param items Ribbon.FormatItem|Ribbon.FormatItem[]|nil Format item or list of items.
80+
---@return Ribbon self
81+
function R:append_items(items) end
82+
83+
---Prepend raw `wezterm.format` items.
84+
---@param items Ribbon.FormatItem|Ribbon.FormatItem[]|nil Format item or list of items.
85+
---@return Ribbon self
86+
function R:prepend_items(items) end
87+
88+
---Clear all ribbon items.
89+
---@return Ribbon self
90+
function R:clear() end
91+
92+
---Append a reset-attributes marker.
93+
function R:reset_attributes() end
94+
95+
---Render with `wezterm.format`.
96+
---@return string formatted
97+
function R:format() end
98+
99+
---Log the ribbon contents.
100+
---@param formatted boolean Log rendered text when true, raw items when false.
101+
function R:debug(formatted) end
102+
103+
---Return the raw format items.
104+
---@return Ribbon.FormatItem[] items
105+
function R:items() end
106+
107+
---@class Ribbon.Api
108+
---@field config Ribbon.ConfigModule Configuration helpers.
109+
local M = {}
110+
111+
---Create a Ribbon instance.
112+
---@param self_or_name? Ribbon.Api|string Ribbon API table when called with `:`, or a name when called with `.`.
113+
---@param name_or_atomic? string|boolean Ribbon name when called with `:`, or atomic flag when called with `.`.
114+
---@param atomic? boolean Atomic flag when called with `:`.
115+
---@return Ribbon ribbon
116+
function M.new(self_or_name, name_or_atomic, atomic) end
117+
118+
---Configure Ribbon.
119+
---@param opts? table Partial Ribbon configuration.
120+
---@return Ribbon.Config config
121+
function M.setup(opts) end
122+
123+
-- vim: set ts=2 sts=2 sw=2 et ai si sta:

0 commit comments

Comments
 (0)