KiTTY icon indicating copy to clipboard operation
KiTTY copied to clipboard

Poor man's syntax highlighting

Open kellerza opened this issue 6 years ago • 6 comments

Since the forum seems to be closed, I'l post this here. This is an enhancement request, and a suggestion for a workaround to get syntax highlighting. Very handy when configuring routers and could also help when looking for certain text in logs.

In current versions of Kitty, you can (mis-)use the URL highlighting feature to underline words

image

My example pattern highlights Enabled, Up, Down and IP addresses:

(Enabled|Up|Down|([0-9]{1,3}\.){3}[0-9]{1,3})

It would be even better if you could have a list of regular expressions with colours, for example: Up->green, down->red and IP Addresses->blue. Hopefully this will inspire someone to implement this... the URL highlighting patch is probably a good place to start :wink:

kellerza avatar May 10 '19 09:05 kellerza

Hi @cyd01 ,

I suggest to copy/move/link this in the Wiki and close this issue.

What you think?

lars18th avatar May 12 '20 14:05 lars18th

Like @kellerza wrote, this is an enhancement request which is not fulfilled or denied, yet.

But the workaround to highlight keywords as links could be moved to a wiki.

CWempe avatar May 12 '20 14:05 CWempe

Here is a suggestion:

Another way to implement this "Poor man's syntax highlighting" could be to have multiple RegEx fields with individual options/font settings.

Example:

field name user defined Value
RegEx 1 (((((https?|ftp|svn)://)|www.)(([0-9]+.[0-9]+.[0-9]+.[0-9]+)|localhost|([a-zA-Z0-9-]+.)[a-zA-Z0-9-]+.(com|net|org|info|biz|int|gov|name|edu|[a-zA-Z][a-zA-Z]))(:[0-9]+)?((/|?)[^ "][^ ,;.:">)])?)|(mailto://[a-zA-Z0-9-.]+@[a-zA-Z0-9-.]+.[a-z]{2,}))
font settings 1 underlined, clickable
RegEx 2 (up|enabled)
font settings 2 green, underlined
RegEx 3 (down|disabled)
font settings 3 red, bold
RegEx 4 (notconnected|([0-9]{1,3}.){3}[0-9]{1,3})
font settings 4 bright cyan
RegEx 5 (down|disabled)
font settings 5 white, red background

So I would think these options/font settings would make sense:

What I personally do not need (to reduce the effort for the developer):

  • 256 colors
  • color picker or checkboxes for font style The user can just type the name of the colors and styles (e.g. `red, bold,

If Kitty had this feature it would make managing my switches and routers much more comfortable. 🤩

What do others think? Would you need more or less options? How many RegEx fields would be best?

CWempe avatar May 13 '20 10:05 CWempe

Hi @CWempe ,

What do others think?

I think it's an interesting idea.

lars18th avatar May 14 '20 06:05 lars18th

Indeed @CWempe my idea was multiple RegExes with individual results. Look at this screencast to see it in action.

Limited colors is not an issue, just basic ANSI colors should be ok. Even if this is only configurable in config files it will be acceptable.

Maybe 8 regexes? Will probably have to see when this has a performance hit.

kellerza avatar May 14 '20 13:05 kellerza

@cyd01 Any thoughts from your side?

Do you think this would be possible to implement?

Limited colors is not an issue, just basic ANSI colors should be ok. Even if this is only configurable in config files it will be acceptable.

Maybe it would make sense to link the RegExes to the colors defined under Window > Colours instead of custom colors for each RegEx.

image

This would make it compatible with putty color schemes.

But I would be happy either way.

CWempe avatar Feb 23 '21 11:02 CWempe

Issue closed due to inactivity

cyd01 avatar May 23 '23 18:05 cyd01

No worries, I've been using labctl color to do the highlighting.

It works nicely with most terminals: Kitty / Windows Terminal / inside VSCode

kellerza avatar May 24 '23 06:05 kellerza