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
helpconsole 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
size. Default is the System Font at 27 points for
hs.drawingtext 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
strikethroughColor- Default nil, same as
strokeColor- Default nil, same as
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
underlineStyle- An integer representing the underline style. See
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
wkeys (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.styledtextobjects 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:
In addition, the following metamethods have been included:
objectyields the string values concatenated
stringyields a new
hs.styledtextobjects yields a new
hs.styledtextobject containing the concatenation of the two objects
- len: #object yields the length of the text contained in the object
- eq: object ==/~= object yields a boolean indicating if the text of the two objects is equal or not. Use
hs.styledtext:isIdenticalif you need to compare attributes as well.
- lt, le: allows <, >, <=, and >= comparisons between objects and strings in which the text of an object is compared with the text of another or a Lua string.
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() ==/=
- Constants - Useful values which cannot be changed
- Functions - API calls offered directly by the extension
- Constructors - API calls which return an object, typically one that offers API methods
- Methods - API calls which can only be made on an object returned by a constructor
| 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.styledtextobject. Mimics the Lua
string.findfunction. | | Parameters |
- pattern - a string containing the pattern to locate. See the Lua manual, section 6.4.1 (
help.lua._man._6_4_1) for more details.
- init - an optional integer specifying the location within the text to start the pattern search
- plain - an optional boolean specifying whether or not to treat the pattern as plain text (i.e. an exact match). Defaults to false. If you wish to specify this argument, you must also specify init.
| | Returns |