Skip to content

Commit

Permalink
Initialize default colors
Browse files Browse the repository at this point in the history
  • Loading branch information
boatbomber committed Sep 18, 2022
1 parent a8ca6dd commit 8f852bd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@boatbomber/highlighter",
"version": "0.5.0",
"version": "0.5.1",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
29 changes: 15 additions & 14 deletions src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,6 @@ local Highlighter = {
defaultLexer = require(script.lexer),
}

function Highlighter.setTokenColors(colors: HighlighterColors)
for token, color in colors do
TokenColors[token] = color
ColorFormatter[color] = string.format(
'<font color="#%.2x%.2x%.2x">',
color.R * 255,
color.G * 255,
color.B * 255
) .. "%s</font>"
end

Highlighter.refresh()
end

function Highlighter.refresh(): ()
-- Rehighlight existing labels using latest colors
for textObject, data in pairs(LastData) do
Expand Down Expand Up @@ -250,4 +236,19 @@ function Highlighter.highlight(props: HighlightProps)
return cleanup
end

function Highlighter.setTokenColors(colors: HighlighterColors)
for token, color in colors do
TokenColors[token] = color
ColorFormatter[color] = string.format(
'<font color="#%.2x%.2x%.2x">',
color.R * 255,
color.G * 255,
color.B * 255
) .. "%s</font>"
end

Highlighter.refresh()
end
Highlighter.setTokenColors(TokenColors)

return Highlighter :: Highlighter
2 changes: 1 addition & 1 deletion wally.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "boatbomber/highlighter"
description = "RichText highlighting Lua code with a pure Lua lexer"
version = "0.5.0"
version = "0.5.1"
license = "MIT"
authors = ["boatbomber (https://boatbomber.com)"]
registry = "https://github.com/upliftgames/wally-index"
Expand Down

0 comments on commit 8f852bd

Please sign in to comment.