-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2890275
commit d9be2e2
Showing
11 changed files
with
498 additions
and
245 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,111 @@ | ||
# Highlighter | ||
RichText highlighting Lua code with a pure Lua lexer | ||
|
||
## Installation | ||
|
||
Wally: | ||
|
||
```toml | ||
[dependencies] | ||
Highlighter = "boatbomber/[email protected]" | ||
``` | ||
|
||
Roblox Model: | ||
|
||
Download from [Releases](https://github.com/boatbomber/Highlighter/releases) | ||
|
||
|
||
## API | ||
|
||
**Functions:** | ||
|
||
Usage: | ||
```Lua | ||
local Highlighter = require(script.Highlighter) | ||
function Highlighter.highlight(props: types.HighlightProps): () -> () | ||
``` | ||
|
||
Highlighter.highlight({ | ||
-- The object to syntax highlight | ||
textObject: TextLabel | TextBox, | ||
-- The source text for highlighting- defaults to textObject.Text | ||
src: string?, | ||
-- Update even if there are no changes since last highlight | ||
forceUpdate: boolean?, | ||
-- Lexer for tokenizing src, defaults to the bundled Lua lexer | ||
lexer: Lexer?, | ||
}) | ||
Highlights the given textObject with the given props and returns a cleanup function. | ||
Highlighting will automatically update when needed, so the cleanup function will disconnect | ||
those connections and remove all labels. | ||
|
||
```Lua | ||
function Highlighter.refresh(): () | ||
``` | ||
|
||
Refreshes all highlighted textObjects. Automatically runs when the theme changes. | ||
|
||
```Lua | ||
function Highlighter.setTokenColors(colors: types.TokenColors): () | ||
``` | ||
|
||
Sets the token colors to the given colors and refreshes all highlighted textObjects. | ||
|
||
```Lua | ||
function Highlighter.getTokenColor(tokenName: types.TokenName): Color3 | ||
``` | ||
|
||
Gets a token color by name. | ||
Mainly useful for setting "background" token color on other UI objects behind your text. | ||
|
||
```Lua | ||
function Highlighter.matchStudioSettings(): () | ||
``` | ||
|
||
Matches the token colors to the Studio theme settings and refreshes all highlighted textObjects. | ||
Does nothing when not run in a Studio plugin. | ||
|
||
**Types:** | ||
|
||
```Lua | ||
type TextObject = TextLabel | TextBox | ||
|
||
type TokenName = | ||
"background" | ||
| "iden" | ||
| "keyword" | ||
| "builtin" | ||
| "string" | ||
| "number" | ||
| "comment" | ||
| "operator" | ||
| "custom" | ||
|
||
type TokenColors = { | ||
["background"]: Color3?, | ||
["iden"]: Color3?, | ||
["keyword"]: Color3?, | ||
["builtin"]: Color3?, | ||
["string"]: Color3?, | ||
["number"]: Color3?, | ||
["comment"]: Color3?, | ||
["operator"]: Color3?, | ||
["custom"]: Color3?, | ||
} | ||
|
||
type HighlightProps = { | ||
textObject: TextObject, | ||
src: string?, | ||
forceUpdate: boolean?, | ||
lexer: Lexer?, | ||
customLang: { [string]: string }?, | ||
} | ||
|
||
type Lexer = { | ||
scan: (src: string) -> () -> (string, string), | ||
navigator: () -> any, | ||
finished: boolean?, | ||
} | ||
``` | ||
|
||
Changing the highlight colors: | ||
## Simple Example | ||
|
||
```Lua | ||
Highlighter.setTokenColors({ | ||
tokenName = Color3.new(...), | ||
... | ||
local Highlighter = require(script.Highlighter) | ||
|
||
-- When using in a Studio Plugin, this will automatically match the Studio theme | ||
Highlighter.matchStudioSettings() | ||
|
||
-- Add syntax highlighting to myTextLabel | ||
Highlighter.highlight({ | ||
textObject: myTextLabel, | ||
}) | ||
-- Automatically triggers Highlighter.refresh() which updates existing highlights to the new colors | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,8 @@ | |
|
||
# To add a new tool, add an entry to this table. | ||
[tools] | ||
rojo = "rojo-rbx/rojo@7.2.1" | ||
rojo = "rojo-rbx/rojo@7.3.0" | ||
run-in-roblox = "rojo-rbx/[email protected]" | ||
wally = "upliftgames/[email protected].1" | ||
selene = "Kampfkarren/selene@0.21.0" | ||
stylua = "JohnnyMorganz/stylua@0.14.3" | ||
wally = "upliftgames/[email protected].2" | ||
selene = "Kampfkarren/selene@0.25.0" | ||
stylua = "JohnnyMorganz/stylua@0.18.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"name":"Highlighter","className":"ModuleScript","filePaths":["src\\init.lua","default.project.json"],"children":[{"name":"lexer","className":"ModuleScript","filePaths":["src\\lexer\\init.lua"],"children":[{"name":"language","className":"ModuleScript","filePaths":["src\\lexer\\language.lua"]}]}]} | ||
{"name":"Highlighter","className":"ModuleScript","filePaths":["src\\init.lua","default.project.json"],"children":[{"name":"lexer","className":"ModuleScript","filePaths":["src\\lexer\\init.lua"],"children":[{"name":"language","className":"ModuleScript","filePaths":["src\\lexer\\language.lua"]}]},{"name":"theme","className":"ModuleScript","filePaths":["src\\theme.lua"]},{"name":"types","className":"ModuleScript","filePaths":["src\\types.lua"]},{"name":"utility","className":"ModuleScript","filePaths":["src\\utility.lua"]}]} |
Oops, something went wrong.