Module textredux.core.style
The style module lets you define and use custom, non-lexer-based styles.
What's a style?
Textredux styling provides an abstraction layer over the lexer based style
creation. A style is thus just a table with certain properties, almost exactly
the same as for style created for a lexer or theme. Please see the documentation
for
lexer.style
for information about the available fields. Colors should be defined in the
standard '#rrggbb'
notation.
Defining styles
You define a new style by assigning a table with its properties to the module:
local reduxstyle = require 'textredux.core.style' reduxstyle.foo_header = { italics = true, fore = '#680000' }
As has been previously said, it's often a good idea to base your custom styles on an existing default style. Similarily to defining a lexer style in Textadept you can achieve this by concatenating styles:
reduxstyle.foo_header = style.string .. { underlined = true }
NB: Watch out for the mistake of assigning the style to a local variable:
local header = reduxstyle.string .. { underlined = true }
This will not work, as the style is not correctly defined with the style module, necessary to ensure styles are correctly defined when new buffers are created.
In order to avoid name clashes, it's suggested that you name any custom styles
by prefixing their name with the name of your module. E.g. if your module is
named awesome
, then name your style something like style.awesome_style
.
Updating styles
To make them fit better with your theme or preferences you can change styles
already set by overwriting their properties in your init.lua
:
local textredux = require('textredux') local reduxstyle = textredux.core.style reduxstyle.list_match_highlight.fore = reduxstyle.class.fore reduxstyle.fs_directory.italics = true
Using styles
You typically use a style by inserting text through
textredux.core.buffer's text insertion methods, specifying the style.
Please see also the example in examples/buffer_styling.lua
.
reduxbuffer:add_text('Foo header text', reduxstyle.foo_header)
The default styles
Textredux piggybacks on the default lexer styles defined by a user's theme, and makes them available for your Textredux interfaces. The big benefit of this is that by using those styles or basing your custom styles on them, your interface stands a much higher chance of blending in well with the color scheme used. As an example, your custom style with cyan foreground text might look great with your own dark theme, but may be pretty near invisible for some user with a light blue background.
You can read more about the default lexer styles in the
Textadept lexer documentation.
You access a default style (or any style for that matter), by indexing the
style module, like so: style.<name>
. For reference, the default styles
available are these:
- style.nothing
- style.whitespace
- style.comment
- style.string
- style.number
- style.keyword
- style.identifier
- style.operator
- style.error
- style.preproc
- style.constant
- style.variable
- style.function
- style.class
- style.type
- style.default
- style.line_number
- style.bracelight
- style.bracebad
- style.controlchar
- style.indentguide
- style.calltip