Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added functionilty for ansi code highlighting #132

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

TomJHKR
Copy link

@TomJHKR TomJHKR commented Dec 2, 2024

Hello,

Issue:
Whilst working with ANSI Color codes there was no functionality to highlight these colors

Fix:
Ive done my best to try add ansi code highlighting functionality for this package,
It should work as with the testing file all seems to be fine, although I dont do to much programming in lua.

Basically just using a lookup table so there may be codes missing. I'm not aware of a way to convert the ansi codes to hex so this seemed logical

If there is anything for me to fix / tidy up in order to be merged please let me know

@brenoprata10
Copy link
Owner

Hello, sorry for the late reply. Could you please remove all of the text formatting in your PR and leaving only what is needed for the new feat to work?

@TomJHKR
Copy link
Author

TomJHKR commented Dec 17, 2024

Hello, sure thing, my auto format went a little crazy haha, I'll get this done sometime this evening.
Thanks for the plug-in!

@TomJHKR
Copy link
Author

TomJHKR commented Dec 18, 2024

Hey @brenoprata10 ,

Should be all good to go now :)

@brenoprata10
Copy link
Owner

Thanks for your contribution, I will review/test till the end of the week 👍

@brenoprata10
Copy link
Owner

Hey o/
I've not forgotten about your PR, as it's quite big, it will require some major testing from my part to make sure it won't break anything

---@usage get_ansi_named_color_value("\033[31m") => Returns '#FF0000'
function M.get_ansi_named_color_value(color)
local color_code = nil
if string.match(color, "\\033[[0-9;]*m") then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you could reuse M.ansi_regex = "\\033%[[0-9;]*m" here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey is this what you were meaning?

function M.get_ansi_named_color_value(color)
	local color_code = nil
	if string.match(color, patterns.ansi_regex) then

Comment on lines 39 to 45
-- Checking to match on ansi codes to remove naughty chars
if string.match(color_value, "\\") then
local g1, g2 = string.match(color_value, "([0-9]);?([0-9]+)m")
if g1 and g2 then
color_value = g1 .. g2
end
end
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove naughty chars using the gsub below? [!(),%s%.-/%%=:\"']+

Copy link
Author

@TomJHKR TomJHKR Dec 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello

	return 'nvim-highlight-colors-' .. string.gsub(color_value, "#", ""):gsub("\\[0-9]*%[", ""):gsub("[!(),%s%.-/%%=:\"';%[%]]+", "")

let me know if this is what you were after, i believe this should be more ideal

@TomJHKR
Copy link
Author

TomJHKR commented Dec 23, 2024

Hello, ive made the suggested changes, let me know if theres anything additional to change, ive tried to keep it minimal :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants