This module adds support for controlling the style of the text in Hammerspoon.
More detailed documentation is being worked on and will be provided in the Hammerspoon Wiki at https://github.com/Hammerspoon/hammerspoon/wiki. The documentation here is a condensed version provided for use within the Hammerspoon Dash docset and the inline help provided by the help
console command within Hammerspoon.
The following list of attributes key-value pairs are recognized by this module and can be adjusted, set, or removed for objects by the various methods provided by this module. The list of attributes is provided here for reference; anywhere in the documentation you see a reference to the attributes key-value pairs
, refer back to here for specifics:
font
- A table containing the font name and size, specified by the keys name
and size
. Default is the System Font at 27 points for hs.drawing
text objects; otherwise the default is Helvetica at 12 points. You may also specify this as a string, which will be taken as the font named in the string at the default size, when setting this attribute.color
- A table indicating the color of the text as described in hs.drawing.color
. Default is white for hs.drawing text objects; otherwise the default is black.backgroundColor
- Default nil, no background color (transparent).underlineColor
- Default nil, same as color
.strikethroughColor
- Default nil, same as color
.strokeColor
- Default nil, same as color
.strokeWidth
- Default 0, no stroke; positive, stroke alone; negative, stroke and fill (a typical value for outlined text would be 3.0)paragraphStyle
- A table containing the paragraph style. This table may contain any number of the following keys:alignment
- A string indicating the texts alignment. The string may contain a value of "left", "right", "center", "justified", or "natural". Default is "natural".lineBreak
- A string indicating how text that doesn't fit into the drawingObjects rectangle should be handled. The string may be one of "wordWrap", "charWrap", "clip", "truncateHead", "truncateTail", or "truncateMiddle". Default is "wordWrap".baseWritingDirection
- A string indicating the base writing direction for the lines of text. The string may be one of "natural", "leftToRight", or "rightToLeft". Default is "natural".tabStops
- An array of defined tab stops. Default is an array of 12 left justified tab stops 28 points apart. Each element of the array may contain the following keys:location
- A floating point number indicating the number of points the tab stap is located from the line's starting margin (see baseWritingDirection).tabStopType
- A string indicating the type of the tab stop: "left", "right", "center", or "decimal"defaultTabInterval
- A positive floating point number specifying the default tab stop distance in points after the last assigned stop in the tabStops field.firstLineHeadIndent
- A positive floating point number specifying the distance, in points, from the leading margin of a frame to the beginning of the paragraph's first line. Default 0.0.headIndent
- A positive floating point number specifying the distance, in points, from the leading margin of a text container to the beginning of lines other than the first. Default 0.0.tailIndent
- A floating point number specifying the distance, in points, from the margin of a frame to the end of lines. If positive, this value is the distance from the leading margin (for example, the left margin in left-to-right text). If 0 or negative, it's the distance from the trailing margin. Default 0.0.maximumLineHeight
- A positive floating point number specifying the maximum height that any line in the frame will occupy, regardless of the font size. Glyphs exceeding this height will overlap neighboring lines. A maximum height of 0 implies no line height limit. Default 0.0.minimumLineHeight
- A positive floating point number specifying the minimum height that any line in the frame will occupy, regardless of the font size. Default 0.0.lineSpacing
- A positive floating point number specifying the space in points added between lines within the paragraph (commonly known as leading). Default 0.0.paragraphSpacing
- A positive floating point number specifying the space added at the end of the paragraph to separate it from the following paragraph. Default 0.0.paragraphSpacingBefore
- A positive floating point number specifying the distance between the paragraph's top and the beginning of its text content. Default 0.0.lineHeightMultiple
- A positive floating point number specifying the line height multiple. The natural line height of the receiver is multiplied by this factor (if not 0) before being constrained by minimum and maximum line height. Default 0.0.hyphenationFactor
- The hyphenation factor, a value ranging from 0.0 to 1.0 that controls when hyphenation is attempted. By default, the value is 0.0, meaning hyphenation is off. A factor of 1.0 causes hyphenation to be attempted always.tighteningFactorForTruncation
- A floating point number. When the line break mode specifies truncation, the system attempts to tighten inter character spacing as an alternative to truncation, provided that the ratio of the text width to the line fragment width does not exceed 1.0 + the value of tighteningFactorForTruncation. Otherwise the text is truncated at a location determined by the line break mode. The default value is 0.05.allowsTighteningForTruncation
- A boolean indicating whether the system may tighten inter-character spacing before truncating text. Only available in macOS 10.11 or newer. Default true.headerLevel
- An integer number from 0 to 6 inclusive which specifies whether the paragraph is to be treated as a header, and at what level, for purposes of HTML generation. Defaults to 0.superscript
- An integer indicating if the text is to be displayed as a superscript (positive) or a subscript (negative) or normal (0).ligature
- An integer. Default 1, standard ligatures; 0, no ligatures; 2, all ligatures.strikethroughStyle
- An integer representing the strike-through line style. See hs.styledtext.lineStyles
, hs.styledtext.linePatterns
and hs.styledtext.lineAppliesTo
.underlineStyle
- An integer representing the underline style. See hs.styledtext.lineStyles
, hs.styledtext.linePatterns
and hs.styledtext.lineAppliesTo
.baselineOffset
- A floating point value, as points offset from baseline. Default 0.0.kerning
- A floating point value, as points by which to modify default kerning. Default nil to use default kerning specified in font file; 0.0, kerning off; non-zero, points by which to modify default kerning.obliqueness
- A floating point value, as skew to be applied to glyphs. Default 0.0, no skew.expansion
- A floating point value, as log of expansion factor to be applied to glyphs. Default 0.0, no expansion.shadow
- Default nil, indicating no drop shadow. A table describing the drop shadow effect for the text. The table may contain any of the following keys:offset
- A table with h
and w
keys (a size structure) which specify horizontal and vertical offsets respectively for the shadow. Positive values always extend down and to the right from the user's perspective.blurRadius
- A floating point value specifying the shadow's blur radius. A value of 0 indicates no blur, while larger values produce correspondingly larger blurring. The default value is 0.color
- The default shadow color is black with an alpha of 1/3. If you set this property to nil, the shadow is not drawn.To make the hs.styledtext
objects easier to use, in addition to the module specific functions and methods defined, some of the Lua String library has been reproduced to perform similar functions on these objects. See the help section for each method for more information on their use:
hs.styledtext:byte
hs.styledtext:find
hs.styledtext:gmatch
hs.styledtext:len
hs.styledtext:lower
hs.styledtext:match
hs.styledtext:rep
hs.styledtext:sub
hs.styledtext:upper
In addition, the following metamethods have been included:
string
..object
yields the string values concatenatedobject
..string
yields a new hs.styledtext
object with string
appendedhs.styledtext
objects yields a new hs.styledtext
object containing the concatenation of the two objectshs.styledtext:isIdentical
if you need to compare attributes as well.Note that due to differences in the way Lua determines when to use metamethods for equality comparisons versus relative-position comparisons, ==/~= cannot compare an object to a Lua string (it will always return false because the types are different). You must use object:getString() ==/~= string
. (see hs.styledtext:getString
)
Signature | hs.styledtext.defaultFonts |
---|---|
Type | Constant |
Description | A table containing the system default fonts and sizes. |
Notes | |
Source | extensions/styledtext/internal.m |
Signature | hs.styledtext.fontTraits -> table |
---|---|
Type | Constant |
Description | A table for containing Font Trait masks for use with `hs.styledtext.fontNamesWithTraits(...)` |
Source | extensions/styledtext/internal.m |
Signature | hs.styledtext.lineAppliesTo |
---|---|
Type | Constant |
Description | A table of values indicating how the line for underlining or strike-through are applied to the text. |
Notes | |
Source | extensions/styledtext/internal.m |
Signature | hs.styledtext.linePatterns |
---|---|
Type | Constant |
Description | A table of patterns which apply to the line for underlining or strike-through. |
Notes | |
Source | extensions/styledtext/internal.m |
Signature | hs.styledtext.lineStyles |
---|---|
Type | Constant |
Description | A table of styles which apply to the line for underlining or strike-through. |
Notes | |
Source | extensions/styledtext/internal.m |
Signature | hs.styledtext.convertFont(fontTable, trait) -> table |
---|---|
Type | Function |
Description | Returns the font which most closely matches the given font and the trait change requested. |
Parameters |
|
Returns |
|
Source | extensions/styledtext/internal.m |
Signature | hs.styledtext.fontFamilies() -> table |
---|---|
Type | Function |
Description | Returns the names of all font families installed for the system. |
Parameters |
|
Returns |
|
Source | extensions/styledtext/internal.m |
Signature | hs.styledtext.fontInfo(font) -> table |
---|---|
Type | Function |
Description | Get information about the font Specified in the attributes table. |
Parameters |
|
Returns |
|
Source | extensions/styledtext/internal.m |
Signature | hs.styledtext.fontNames() -> table |
---|---|
Type | Function |
Description | Returns the names of all installed fonts for the system. |
Parameters |
|
Returns |
|
Source | extensions/styledtext/internal.m |
Signature | hs.styledtext.fontNamesWithTraits(fontTraitMask) -> table |
---|---|
Type | Function |
Description | Returns the names of all installed fonts for the system with the specified traits. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/styledtext/internal.m |
Signature | hs.styledtext.fontPath(font) -> table |
---|---|
Type | Function |
Description | Get the path of a font. |
Parameters |
|
Returns |
|
Source | extensions/styledtext/internal.m |
Signature | hs.styledtext.fontsForFamily(familyName) -> table |
---|---|
Type | Function |
Description | Returns an array containing fonts available for the specified font family or nil if no fonts for the specified family are present. |
Parameters |
|
Returns |
|
Source | extensions/styledtext/init.lua |
Signature | hs.styledtext.loadFont(path) -> boolean[, string] |
---|---|
Type | Function |
Description | Loads a font from a file at the specified path. |
Parameters |
|
Returns |
|
Source | extensions/styledtext/internal.m |
Signature | hs.styledtext.validFont(font) -> boolean |
---|---|
Type | Function |
Description | Checks to see if a font is valid. |
Parameters |
|
Returns |
|
Source | extensions/styledtext/internal.m |
Signature | hs.styledtext.ansi(string, [attributes]) -> styledText object |
---|---|
Type | Constructor |
Description | Create an `hs.styledtext` object from the string provided, converting ANSI SGR color and some font sequences into the appropriate attributes. Attributes to apply to the resulting string may also be optionally provided. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/styledtext/init.lua |
Signature | hs.styledtext.getStyledTextFromData(data, [type]) -> styledText object |
---|---|
Type | Constructor |
Description | Converts the provided data into a styled text string. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/styledtext/internal.m |
Signature | hs.styledtext.getStyledTextFromFile(file, [type]) -> styledText object |
---|---|
Type | Constructor |
Description | Converts the data in the specified file into a styled text string. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/styledtext/internal.m |
Signature | hs.styledtext.new(string, [attributes]) -> styledText object |
---|---|
Type | Constructor |
Description | Create an `hs.styledtext` object from the string or table representation provided. Attributes to apply to the resulting string may also be optionally provided. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/styledtext/internal.m |
Signature | hs.styledtext:asTable([starts], [ends]) -> table |
---|---|
Type | Method |
Description | Returns the table representation of the `hs.styledtext` object or its specified substring. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/styledtext/internal.m |
Signature | hs.styledtext:byte([starts], [ends]) -> integer, ... |
---|---|
Type | Method |
Description | Returns the internal numerical representation of the characters in the `hs.styledtext` object specified by the given indicies. Mimics the Lua `string.byte` function. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/styledtext/init.lua |
Signature | hs.styledtext:convert([type]) -> string |
---|---|
Type | Method |
Description | Converts the styledtext object into the data format specified. |
Parameters |
|
Returns |
|
Source | extensions/styledtext/internal.m |
Signature | hs.styledtext:copy(styledText) -> styledText object |
---|---|
Type | Method |
Description | Create a copy of the `hs.styledtext` object. |
Parameters |
|
Returns |
|
Source | extensions/styledtext/internal.m |
Signature | hs.styledtext:find(pattern, [init, [plain]]) -> start, end, ... | nil |
---|---|
Type | Method |
Description | Returns the indicies of the first occurrence of the specified pattern in the text of the `hs.styledtext` object. Mimics the Lua `string.find` function. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/styledtext/init.lua |
Signature | hs.styledtext:getString([starts], [ends]) -> string |
---|---|
Type | Method |
Description | Returns the text of the `hs.styledtext` object as a Lua String |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/styledtext/internal.m |
Signature | hs.styledtext:gmatch(pattern) -> iterator-function |
---|---|
Type | Method |
Description | Returns an iterator function which will return the captures (or the entire pattern) of the next match of the specified pattern in the text of the `hs.styledtext` object each time it is called. Mimics the Lua `string.gmatch` function. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/styledtext/init.lua |
Signature | hs.styledtext:isIdentical(styledText) -> boolean |
---|---|
Type | Method |
Description | Determine if the `styledText` object is identical to the one specified. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/styledtext/internal.m |
Signature | hs.styledtext:len() -> integer |
---|---|
Type | Method |
Description | Returns the length of the text of the `hs.styledtext` object. Mimics the Lua `string.len` function. |
Parameters |
|
Returns |
|
Source | extensions/styledtext/internal.m |
Signature | hs.styledtext:lower() -> styledText object |
---|---|
Type | Method |
Description | Returns a copy of the `hs.styledtext` object with all alpha characters converted to lower case. Mimics the Lua `string.lower` function. |
Parameters |
|
Returns |
|
Source | extensions/styledtext/internal.m |
Signature | hs.styledtext:match(pattern, [init]) -> match ... | nil |
---|---|
Type | Method |
Description | Returns the first occurrence of the captures in the specified pattern (or the complete pattern, if no captures are specified) in the text of the `hs.styledtext` object. Mimics the Lua `string.match` function. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/styledtext/init.lua |
Signature | hs.styledtext:removeStyle(attributes, [starts], [ends]) -> styledText object |
---|---|
Type | Method |
Description | Return a copy of the `hs.styledtext` object containing the changes to its attributes specified in the `attributes` table. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/styledtext/internal.m |
Signature | hs.styledtext:rep(n, [separator]) -> styledText object |
---|---|
Type | Method |
Description | Returns an `hs.styledtext` object which contains `n` repetitions of the `hs.styledtext` object, optionally with `separator` between each repetition. Mimics the Lua `string.rep` function. |
Parameters |
|
Returns |
|
Source | extensions/styledtext/init.lua |
Signature | hs.styledtext:setString(string, [starts], [ends], [clear]) -> styledText object |
---|---|
Type | Method |
Description | Return a copy of the `hs.styledtext` object containing the changes to its attributes specified in the `attributes` table. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/styledtext/internal.m |
Signature | hs.styledtext:setStyle(attributes, [starts], [ends], [clear]) -> styledText object |
---|---|
Type | Method |
Description | Return a copy of the `hs.styledtext` object containing the changes to its attributes specified in the `attributes` table. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/styledtext/internal.m |
Signature | hs.styledtext:sub(starts, [ends]) -> styledText object |
---|---|
Type | Method |
Description | Returns a substring, including the style attributes, specified by the given indicies from the `hs.styledtext` object. Mimics the Lua `string.sub` function. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/styledtext/internal.m |
Signature | hs.styledtext:upper() -> styledText object |
---|---|
Type | Method |
Description | Returns a copy of the `hs.styledtext` object with all alpha characters converted to upper case. Mimics the Lua `string.upper` function. |
Parameters |
|
Returns |
|
Source | extensions/styledtext/internal.m |