-
-
Notifications
You must be signed in to change notification settings - Fork 9
Utils.Class.Layout
The Utils.Class.Layout
module is a Lua class designed to simplify the creation
and management of formatted text layouts in Wezterm. It abstracts the complexity
of handling Wezterm's
FormatItem
objects by providing a clear and concise API.
-- Layout used when formatting the tab title.
-- Some code has been removed.
local wt = require "wezterm"
local Utils = require "utils"
local str = Utils.fn.str
local Icon = Utils.class.icon
local tabicons = Icon.Sep.tb
wt.on("format-tab-title", function(tab, _, _, config, hover, max_width)
-- [...]
local Title = Utils.class.layout:new "TabTitle"
-- [...]
local title = str.format_tab_title(tab, config, max_width)
Title:push(bg, fg, tab_idx == 0 and tabicons.leftmost or tabicons.left, attributes)
Title:push(fg, bg, (unseen_output and Icon.Notification or Icon.Nums[tab_idx + 1] or "") .. " ", attributes)
Title:push(fg, bg, title, attributes)
Title:push(bg, fg, Icon.Sep.block .. tabicons.right, attributes)
return Title
end)
- Simplified Layout Management: Provides a straightforward way to build and manage text layouts with various attributes.
-
Attribute Support: Supports all attributes defined by Wezterm's
FormatItem
, including underline styles, text intensity, and color settings. - Color Handling: Allows defining colors using ANSI colors, named colors, RGB values, or Wezterm's color objects.
- Logging: Includes logging capabilities to help debug layout creation and formatting processes.
The Utils.Class.Layout
class is designed to encapsulate the complexity of
Wezterm's formatting options, making it easier to manage and debug text layouts.
The class supports the following attributes for text styling:
-
"None"
: Reset attributes. -
"NoUnderline"
: No underline. -
"Single"
: Single underline. -
"Double"
: Double underline. -
"Curly"
: Curly underline. -
"Dotted"
: Dotted underline. -
"Dashed"
: Dashed underline. -
"Normal"
: Normal intensity. -
"Bold"
: Bold intensity. -
"Half"
: Half intensity. -
"Italic"
: Italic text. -
"NoItalic"
: No italic text.
Creates a new Utils.Class.Layout
instance.
-
name
[string
] (optional) - (default:"Layout"
) name of the layout; used when logging.
-
instance
[Utils.Class.Layout
] - new class instance.
local layout = Layout:new("LeftStatus")
Adds a text element to the layout with specified background and foreground colors and optional attributes.
-
background
[string
] - background color of the element -
foreground
[string
] - foreground color of the element -
text
[string
] - text to add. -
attributes
[table
] (optional) - list of attributes to styletext
.
-
self
[Utils.Class.Layout
] - updated class instance.
layout:push("Black", "White", "Hello World", { "Bold", "Italic" })
Clears all elements from the layout.
-
self
[Utils.Class.Layout
] - cleared class instance.
layout:clear()
Formats the layout using Wezterm's wezterm.format()
.
-
format
[string
] - formatted layout.
local formatted = layout:format()
Logs the layout to Wezterm's debug console.
-
formatted
[Boolean
] (optional) - whether to log layout formatted or not.
layout:debug(true)
This module is licensed under the GNU General Public License v3.0. For more information, refer to the license.