hSaria / ChromaTerm

Color your Terminal with RegEx!
MIT License
188 stars 32 forks source link

Existing colors in the input are not overridden #95

Closed ciscohack closed 2 years ago

ciscohack commented 2 years ago

Environment

Hello Expert,

Chromaterm Script is not functioning properly. Today i installed cleaned chromaterm and trigger not working properly and it matches partial keywords. This is applicable for SSH/Telnet and local log files.

image

Check this IP is not fully matching and same for port and many other keywords. I thought my old config has problem so installed cleaned to test it and found it's script bug. If this could be fix would be good but don't know how much it's doable

-Praveen

hSaria commented 2 years ago

Can you include your configuration file? Thanks

On 15 Dec 2021, at 18:23, ciscohack @.***> wrote:

Environment

OS: Terminal: ChromaTerm: Hello Expert,

Chromaterm Script is not functioning properly. Today i installed cleaned chromaterm and trigger not working properly and it matches partial keywords. This is applicable for SSH/Telnet and local log files.

https://user-images.githubusercontent.com/11479557/146243255-c2c01bcc-e5de-4c70-80b7-6dcd7466d8df.png Check this IP is not fully matching and same for port and many other keywords. I thought my old config has problem so installed cleaned to test it and found it's script bug. If this could be fix would be good but don't know how much it's doable

-Praveen

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/hSaria/ChromaTerm/issues/95, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIE5AHB3UMDAYCJMTFUSFYDURDMIZANCNFSM5KEKHEPQ. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

ciscohack commented 2 years ago

There is not configuration. whatever you provide by default is only i tested

ciscohack commented 2 years ago

here is the config .chromaterm.yml.zip

hSaria commented 2 years ago

Using your config, I cannot reproduce the issue. Are you sure you attached the config file in your home directory (i.e. ~/.chromaterm.yml)?

Also, your IPv6 color "f##ffdbff" is incorrect; it should be "f#ffdbff". You should see a warning whenever you use ChromaTerm.

On 15 Dec 2021, at 18:31, ciscohack @.***> wrote:

There is not configuration. whatever you provide by default is only i tested

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/hSaria/ChromaTerm/issues/95#issuecomment-995060688, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIE5AHG6ZHDLWZWAGY2OTT3URDNG3ANCNFSM5KEKHEPQ. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

ciscohack commented 2 years ago

Using your config, I cannot reproduce the issue. Are you sure you attached the config file in your home directory (i.e. ~/.chromaterm.yml)? Also, your IPv6 color "f##ffdbff" is incorrect; it should be "f#ffdbff". You should see a warning whenever you use ChromaTerm. On 15 Dec 2021, at 18:31, ciscohack @.***> wrote: There is not configuration. whatever you provide by default is only i tested — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#95 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIE5AHG6ZHDLWZWAGY2OTT3URDNG3ANCNFSM5KEKHEPQ. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

yes Config is in my home directory and yes IPv6 had problem which i already fixed it. it's strange. okay do one thing install this tool first "https://github.com/sharkdp/bat" then do ct bat hopefully you will reproduce the problem

hSaria commented 2 years ago

If you run “echo 127.0.0.1:55667 | ct”, does that that trigger the issue?

On 15 Dec 2021, at 8:33 pm, ciscohack @.***> wrote:

 Using your config, I cannot reproduce the issue. Are you sure you attached the config file in your home directory (i.e. ~/.chromaterm.yml)? Also, your IPv6 color "f##ffdbff" is incorrect; it should be "f#ffdbff". You should see a warning whenever you use ChromaTerm. … On 15 Dec 2021, at 18:31, ciscohack @.***> wrote: There is not configuration. whatever you provide by default is only i tested — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#95 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIE5AHG6ZHDLWZWAGY2OTT3URDNG3ANCNFSM5KEKHEPQ. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

yes Config is in my home directory and yes IPv6 had problem which i already fixed it. it's strange.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

hSaria commented 2 years ago

After mentioning bat, the issue becomes apparent; the same text is matching on bat and ct. Let me see what can be done about that.

On 15 Dec 2021, at 20:33, ciscohack @.***> wrote:

Using your config, I cannot reproduce the issue. Are you sure you attached the config file in your home directory (i.e. ~/.chromaterm.yml)? Also, your IPv6 color "f##ffdbff" is incorrect; it should be "f#ffdbff". You should see a warning whenever you use ChromaTerm. … <x-msg://1/#> On 15 Dec 2021, at 18:31, ciscohack @.***> wrote: There is not configuration. whatever you provide by default is only i tested — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#95 (comment) https://github.com/hSaria/ChromaTerm/issues/95#issuecomment-995060688>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIE5AHG6ZHDLWZWAGY2OTT3URDNG3ANCNFSM5KEKHEPQ https://github.com/notifications/unsubscribe-auth/AIE5AHG6ZHDLWZWAGY2OTT3URDNG3ANCNFSM5KEKHEPQ. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

yes Config is in my home directory and yes IPv6 had problem which i already fixed it. it's strange.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/hSaria/ChromaTerm/issues/95#issuecomment-995191825, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIE5AHEQ3OWZH5BACIIJ2MTURD3P5ANCNFSM5KEKHEPQ. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

ciscohack commented 2 years ago

After mentioning bat, the issue becomes apparent; the same text is matching on bat and ct. Let me see what can be done about that. On 15 Dec 2021, at 20:33, ciscohack @.> wrote: Using your config, I cannot reproduce the issue. Are you sure you attached the config file in your home directory (i.e. ~/.chromaterm.yml)? Also, your IPv6 color "f##ffdbff" is incorrect; it should be "f#ffdbff". You should see a warning whenever you use ChromaTerm. … <x-msg://1/#> On 15 Dec 2021, at 18:31, ciscohack @.> wrote: There is not configuration. whatever you provide by default is only i tested — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#95 (comment) <#95 (comment)>>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIE5AHG6ZHDLWZWAGY2OTT3URDNG3ANCNFSM5KEKHEPQ https://github.com/notifications/unsubscribe-auth/AIE5AHG6ZHDLWZWAGY2OTT3URDNG3ANCNFSM5KEKHEPQ. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. yes Config is in my home directory and yes IPv6 had problem which i already fixed it. it's strange. — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#95 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIE5AHEQ3OWZH5BACIIJ2MTURD3P5ANCNFSM5KEKHEPQ. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

Yes i think now we understand the problem.. it's bat and ct conflict ... need to find a way to make ct precedence over other program when pipe... Thanks brother for looking into it..

One more thing i have notice where chromaterm behaviour is different. in iterm2 native trigger if you define any keyword like FTP or anythiing thing and in your console if anything match to this word in beginning or end it shows the trigger but Chromaterm not behave like that don't know why.

Here is the example : chromaterm:--

image

iterm2 Native trigger :

image

hSaria commented 2 years ago

I already have a fix ready to makes it so ChromaTerm will overwrite any existing colors. Just doing some polishing.

As for iterm2 triggers, that's expected as the terminal emulator will override any existing colors. It cannot be "fixed" since ChromaTerm merely suggests the color code to use and the terminal emulator chooses to honor or ignore the suggestion.

On 16 Dec 2021, at 03:37, ciscohack @.***> wrote:

After mentioning bat, the issue becomes apparent; the same text is matching on bat and ct. Let me see what can be done about that. … <x-msg://2/#> On 15 Dec 2021, at 20:33, ciscohack @.> wrote: Using your config, I cannot reproduce the issue. Are you sure you attached the config file in your home directory (i.e. ~/.chromaterm.yml)? Also, your IPv6 color "f##ffdbff" is incorrect; it should be "f#ffdbff". You should see a warning whenever you use ChromaTerm. … x-msg://1/# On 15 Dec 2021, at 18:31, ciscohack @.> wrote: There is not configuration. whatever you provide by default is only i tested — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#95 https://github.com/hSaria/ChromaTerm/issues/95 (comment) <#95 (comment) https://github.com/hSaria/ChromaTerm/issues/95#issuecomment-995060688>>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIE5AHG6ZHDLWZWAGY2OTT3URDNG3ANCNFSM5KEKHEPQ https://github.com/notifications/unsubscribe-auth/AIE5AHG6ZHDLWZWAGY2OTT3URDNG3ANCNFSM5KEKHEPQ https://github.com/notifications/unsubscribe-auth/AIE5AHG6ZHDLWZWAGY2OTT3URDNG3ANCNFSM5KEKHEPQ https://github.com/notifications/unsubscribe-auth/AIE5AHG6ZHDLWZWAGY2OTT3URDNG3ANCNFSM5KEKHEPQ. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. yes Config is in my home directory and yes IPv6 had problem which i already fixed it. it's strange. — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#95 (comment) https://github.com/hSaria/ChromaTerm/issues/95#issuecomment-995191825>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIE5AHEQ3OWZH5BACIIJ2MTURD3P5ANCNFSM5KEKHEPQ https://github.com/notifications/unsubscribe-auth/AIE5AHEQ3OWZH5BACIIJ2MTURD3P5ANCNFSM5KEKHEPQ. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

Yes i think now we understand the problem.. it's bat and ct conflict ... need to find a way to make ct precedence over other program when pipe... Thanks brother for looking into it..

One more thing i have notice where chromaterm behaviour is different. in iterm2 native trigger if you define any keyword like FTP or anythiing thing and in your console if anything match to this word in beginning or end it shows the trigger but Chromaterm not behave like that don't know why.

Here is the example : chromaterm:--

https://user-images.githubusercontent.com/11479557/146303718-88bd2ac8-976d-4c1c-aeb2-dedce3797623.png iterm2 Native trigger :

https://user-images.githubusercontent.com/11479557/146303777-dcaac25d-a162-46af-a869-3e62f77cbfec.png — You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/hSaria/ChromaTerm/issues/95#issuecomment-995410043, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIE5AHA2C3WTFBTSRBQUGSDURFNGVANCNFSM5KEKHEPQ. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

hSaria commented 2 years ago

ChromaTerm v0.8.2 released with this issue fixed. Thanks for reporting it!

ciscohack commented 2 years ago

Thanks a lot for quick fix my friend .. your are champion

ciscohack commented 2 years ago

@hSaria One quick help or suggestion. Is there any way/trick so i could mention or configure my iterm2 like that whenever i open my iterm2 CT automatically pipe for ssh/telnet and other logs reading. currently i do like ct bat <file? or cat | ct.. but if there is some way in iterm2 to do and reference CT in it so it does this automatically

hSaria commented 2 years ago

Yes, you can make it so ChromaTerm launches your shell.

Open the settings for iTerm2 and navigate to the Profiles tab. Select the profile you're using (e.g. Default) and under the general tab, change the Command to Custom Shell and set the value to:

/usr/local/bin/ct /bin/zsh --login

If you're using a different shell, like bash, change zsh to bash.

Make sure to comment out your aliases/functions for ssh or telnet in your .zshrc or .bash_profile so you don't spawn ChromaTerm anymore.

ciscohack commented 2 years ago

you are awesome my friend thanks working fine everything now. Only hyperterm this trick not working "/usr/local/bin/ct /bin/zsh --login" but any iterm2 this works awesome . Thanks

hSaria commented 2 years ago

I haven't tested Hyper.is, but I think you set shell to /usr/local/bin/ct and shellArgs to ['/bin/zsh', '--login'].

Edit: Just tested it on Hyper.is terminal and it works as described above.

ciscohack commented 2 years ago

I haven't tested Hyper.is, but I think you set shell to /usr/local/bin/ct and shellArgs to ['/bin/zsh', '--login'].

Edit: Just tested it on Hyper.is terminal and it works as described above.

yes it's working fine Thanks a lot my friend

ciscohack commented 2 years ago

@hSaria My friend once question and help after using setting " /usr/local/bin/ct /bin/zsh --login" in my iterm2 profile while working with cli i keep getting message like below screenshot. What i understand this happen due to some delay or latency caused chromaterm sometime not able to highlight for millisecond and then fixed automatically but it keeps on coming in some regular interval. is this can be address some way

image

hSaria commented 2 years ago

Can you give me more information please? I can tell that the code above is malformed, but I need to be able to recreate so I know what is triggering it. At a minimum, I need the rest of the line.

ciscohack commented 2 years ago

So you need tmux/zsh for your iterm2 then use this setting in your iterm2 "/usr/local/bin/ct /bin/zsh --login" by doing this you will able to recreate if you remove this " /usr/local/bin/ct /bin/zsh --login" then you will not see character like below screenshot

image

hSaria commented 2 years ago

Thanks a lot. Can I get the output for “tmux show-options -g | grep status” so I can use the same settings?

On 19 Dec 2021, at 6:25 pm, ciscohack @.***> wrote:

 So you need tmux/zsh for your iterm2 then use this setting in your iterm2 "/usr/local/bin/ct /bin/zsh --login" by doing this you will able to recreate if you remove this " /usr/local/bin/ct /bin/zsh --login" then you will not see character like below screenshot

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you were mentioned.

hSaria commented 2 years ago

No need for the output; I'm able to recreate the problem on my end. Working on a fix as we speak.

hSaria commented 2 years ago

Version 0.8.3 was released with a fix. Thanks again for your help.

ciscohack commented 2 years ago

Version 0.8.3 was released with a fix. Thanks again for your help.

Thanks @hSaria You are super fast my friend.. Once again thanks for addressing my query superfast.. let me upgrade my chromaterm

ciscohack commented 2 years ago

@hSaria Now Chormaterm is much more stable and better. long time back i reported an issue with ssh sometime CT not match whole trigger or partial match after using this " /usr/local/bin/ct /bin/zsh --login" that seems also solved. but one small issue noticed that is i feel very small latency issue don't know how to repro. but of you type on CLI any thing based on trigger or theme color scheme it highlight the sentence little delay. you can try rest all issue solved and it's super stable now. Thanks

hSaria commented 2 years ago

Glad it's working better. As for the small latency, that's because of the keyboard typing detection mechanism and how zsh inserts special characters that interferes with it. I've got a fix that will be included in the next version of ChromaTerm. If you want to try it out (would greatly appreciate the feedback), you can run the following:

git clone https://github.com/hSaria/ChromaTerm.git
cd ChromaTerm
python3 setup.py install

To revert back to normal, you can run pip3 install --force-reinstall chromaterm.

ciscohack commented 2 years ago

@hSaria Thanks a lot. I have just installed and will test it and share my feedback

ciscohack commented 2 years ago

@hSaria I don't know below behaviour is due to new change or still script have some issue with latency. i don't see that latency resolved yet.

image

Here is iterm2 setting image

hSaria commented 2 years ago

The latency issue isn't on the script side; it's the SSH server that's slow to send the input so ChromaTerm assumes there's nothing left to receive and processes the data as is. In the case of Cisco devices, this seems to be the norm with their custom SSH server implementation; I’ve experienced this even when SSH-ing to a local ASA 1000V. Adding workarounds in ChromaTerm might fix it for the ASA, but could break it for everything else.

I've pushed a change in an attempt to detect when the application needs more time to send data. To try the changes out, go back to the directory in which you downloaded ChromaTerm then run

cd ChromaTerm
git pull
python3 setup.py install

P.S. I would be remiss not to warn you on the use of Telnet as the primary means of connecting to a device; it's all clear-text which is incredibly risks.

ciscohack commented 2 years ago

@hSaria Thanks for the new update and i have installed will test it.

Regarding telnet yes you are correct and hardly use telnet but this is lab device and network simulator which work on telnet so i use it. I am just trying to make our loverly CT tool awesome for all scenario... Thanks once again friend for help

hSaria commented 2 years ago

Ah, that makes more sense regarding telnet.

Thanks a lot for the testing; you’re definitely helping improve ChromaTerm . I’ll wait for your feedback before publishing the next version.

On 24 Dec 2021, at 4:44 am, ciscohack @.***> wrote:

 @hSaria Thanks for the new update and i have installed will test it.

Regarding telnet yes you are correct and hardly use telnet but this is lab device and network simulator which work on telnet so i use it. I am just trying to make our loverly CT tool awesome for all scenario... Thanks once again friend for help

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you were mentioned.

ciscohack commented 2 years ago

@hSaria Still having issue but this is build is better than previous one but results not very good

image

image

SSH session also have some latency and delay in matching trigger but telnet is worse

This is ssh... in ssh also have delay but telnet is worse .. see number 1 is showing yellow but in few second CT correct and match it.. do not get confused with telnet written in screenshot .. this is ssh session

image

hSaria commented 2 years ago

One of those problems is easy to fix.

Are you using console (i.e. telnet to the device's virtual console connection)? I want to figure out the setup you're using so I can recreate it myself.

ciscohack commented 2 years ago

One of those problems is easy to fix.

Are you using console (i.e. telnet to the device's virtual console connection)? I want to figure out the setup you're using so I can recreate it myself.

i have one observation.. if you read any log offline CT work nice but when it comes to live reading ssh/telnet then trigger work with delay ..like once you typed and hit enter then few second it highlight the keywords

hSaria commented 2 years ago

Are you using iterm2 highlighting (called Trigger, I believe) combined with ChromaTerm?

ciscohack commented 2 years ago

yes and i can' live without these 2 combination. :😜😂

I use iterm2 latest nightly build

hSaria commented 2 years ago

In that case, it's very difficult for me to rely on the your screenshots, besides the one that shows malformed codes, which I'm currently fixing.

Regarding the delay in highlighting, that's how iterm2's highlighting works; it's interval-based.

What's your setup? Console-over-telnet to a local VM of an ASA 1000v?

ciscohack commented 2 years ago

In that case, it's very difficult for me to rely on the your screenshots, besides the one that shows malformed codes, which I'm currently fixing.

Regarding the delay in highlighting, that's how iterm2's highlighting works; it's interval-based.

What's your setup? Console-over-telnet to a local VM of an ASA 1000v?

I have couple of setup.. with network simulator i use mostly telnet but with real gear i use ssh

i have 2 regex i don't know why these 2 not matching for which it should match

here is the sample can you help me to know why..

regex: .([0-9]+$) >>> this should match anything like this .Port like suppose if you have ip.port format log the match Ip color with existing regex .port part should match with this

![Uploading image.png…]()

regex: ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).[0-9]+$

this regex also have same purpose what i mentioned in above but it match complete IP.Port format

hSaria commented 2 years ago

with network simulator i use mostly telnet

Can you be more specific? I need to recreate that setup to verify how ChromaTerm works with laggy output (i.e. console).

Regarding your regex, you need to escape the . as it's a special character in RegEx (it means any character).

\.([0-9]+$)
^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.[0-9]+$

# More compact IPv4 regex, extracted from the default rules
((25[0-5]|(2[0-4]|[0-1]?\d)?\d)\.){3}(25[0-5]|(2[0-4]|[0-1]?\d)?\d)

Also, you're using ^ (start of line) and $ (end of line) so it won't match if it's in the middle of a line.

ciscohack commented 2 years ago

@hSaria I have Cisco Firepower devices which connected over ssh first then inside that we have command connect module 1 console to connect the app... Second i use eve-ng network simulator and that use telnet.

let share you my config.. try in your setup and do not share with anyone please.

I tried my regex in regex101 and it's working there but no with CT.

If you find any mistake in my config and any regex which can be make better please correct it and do share.. thanks for helping me once again

hSaria commented 2 years ago

No need to share the config. I just need the general setup. I can work with what you gave me; thanks.

It does't work because you're using $ which only matches at the end of a string. So hello .123 would match but not hello .123 world.

Also, instead of using two rules, you can more accurately match it with just one and use group-specific colors.

#### Replace these two rules
- description: IPv4
  # regex: \b(?<!\.)((25[0-5]|(2[0-4]|[0-1]?\d)?\d)\.){3}(25[0-5]|(2[0-4]|[0-1]?\d)?\d)(/\d+)?(?!\.)\b
  regex: \b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b
  color: f#00ffff
  exclusive: True

- description: Match IP.Port Number-- new one
  regex: \.([0-9]+$)
  # color: bold f#ffda8a
  color: bold f#ffbddb
  exclusive: True

#### with this rule
- description: IPv4
  regex: \b((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))(?:\.([0-9]+))?\b
  color:
    1: f#00ffff
    2: bold f#ffbddb
  exclusive: True

P.S. Make sure you understand the difference between capturing groups and non-capturing groups. The numbers 1 and 2 refer to the capturing groups.

Edit: Good god, man. You have so many rules. Way more than I do.

ciscohack commented 2 years ago

@hSaria Thanks for correction and it working fine.. I am not expert like you in regex .. just trying my best.. you are beast in knowledge my friend and i am blessed to meet with you. Thanks if you find and correct more in my config do share the corrections

ciscohack commented 2 years ago

@hSaria Any new update or fix brother. you able to repro the issue

hSaria commented 2 years ago

v0.8.4 was released 3 days ago containing improvements to highlighting. The issue with malformed codes was fixed (it's the OSC one in the release notes).

You can upgrade with pip3 install -U chromaterm.

ciscohack commented 2 years ago

okay Thanks brother i forgot the command to check the existing installed version. please help me to know

hSaria commented 2 years ago

pip3 show chromaterm

ciscohack commented 2 years ago

pip3 show chromaterm

Thanks my friend!

one query in Chromaterm do we not support this style regex match statement

\b(i?<=[\W\s]|^)(((fe|ge|xe|gr|lt|vcp)-\d\d\d)|(((b)?me|em|fab|fxp|lo|pp(d|e)?|st|swfab)[0-2]|dsc|gre|irb|jsrv|lsi|mtun|pimd|pime|tap|vlan|Vlan|vme|VLAN|vtep)|((ae|reth)\d))(.\d*)?(?=[\W\s]|$)\b

(i?<=[\W\s]|^)((DROTHER|POINT_TO_POINT|POINT_TO_MULTIPOINT|BROADCAST|NON_BROADCAST|LOOPBACK|SHAM_LINK|3101|1587|transit|Transit|nssa|NSSA|stub|Stub|Superbackbone))(?=[\W\s]|$)

Do you have regex statement list to match all routing protocol like BGP,OSPF,EIGRP and MPLS and LDP, multicast protocols

hSaria commented 2 years ago

ChromaTerm supports it, but you've made a mistake at the start. You meant to use case

# Wrong
\b(i?<=[\W\s]|^)

# Right
(?i)\b(?<=[\W\s]|^)

(?i) means the regex is case insensitive. (?<=...) is positive lookbehind.

Also, you don't need (?<=[\W\s]|^) if you're using \b (see Python docs). Same goes for (?=[\W\s]|$)

# For example, replace this
(?i)\b(?<=[\W\s]|^)(hello|hi)(?=[\W\s]|$)\b

# with this
(?i)\b(hello|hi)\b

Don't add random bits to your regex if you're unsure of what they do. You'll end up with a spaghetti regex.

Spend some time understanding the different features of Regex by reviewing a Regex and parsing it visually. Avoid using websites as they will only tell you what's in a regex but don't teach you how to comprehend or create a regex yourself (i.e. without their help).

What I do is copy the regex to a text editor and then unpack manually. For example:

# Original
\b(?<!\.)((25[0-5]|(2[0-4]|[0-1]?\d)?\d)\.){3}(25[0-5]|(2[0-4]|[0-1]?\d)?\d)(/\d+)?\b

# After every long NORMAL group `()` or alternation `|`, insert a new line and indent accordingly
\b(?<!\.)(
    (
        25[0-5]|
        (2[0-4]|[0-1]?\d)?\d
    )\.
){3}(
    25[0-5]|
    (2[0-4]|[0-1]?\d)?\d
)(/\d+)?\b

I highly recommend doing this whenever you see a regex that looks complicated. If you see a special group (?...) then look them up in the docs.

You can use the verbose flag, if you want to use long-form regex or add comments. In fact, ChromaTerm v0.9.0 uses verbose mode for some of the longer default rules.

# Old
 - description: MAC address
   regex: (?i)\b((?<!:)([\da-f]{1,2}:){5}[\da-f]{1,2}(?!:)|(?<!\.)([\da-f]{4}\.){2}[\da-f]{4}(?!\.))\b
   color: f.type-4
   exclusive: true

# New (notice the additional `x` in the first special group for flags).
# The `|` in `regex: |` is YAML syntax that means multiline string; IT IS NOT PART OF THE REGEX.
 - description: MAC address
   regex: |
     (?ix)\b(
         (?<!:)([\da-f]{1,2}:){5}[\da-f]{1,2}(?!:)|  # 11:22:33:aa:bb:cc
         (?<!\.)([\da-f]{4}\.){2}[\da-f]{4}(?!\.)  # 1122.33aa.bbcc
     )\b
   color: f.type-4
   exclusive: true
ciscohack commented 2 years ago

@hSaria Thanks once again. I think i have then hell lot of mistake in my config and i am not proficient regex player like you. Could you please help me getting some good resource, links and article to deep dive regex from beginner to advance. i wants to write regex like you.

ciscohack commented 2 years ago

@hSaria You said this to me "Spend some time understanding the different featuresRegex by reviewing a Regex and parsing it visually" is there any tool where i can debug the regex and see it visually. i use regex101.com and the regex i shared is working in that tool but you pin point lots of mistake so that tool is not reliable for debugging.. how can i visually see my regex in action

hSaria commented 2 years ago

For me, doing it manually feels like the best way, as I’ve described it in the example above. The tools online work fine, but they don’t teach you how to fish, so to speak; they just hand you the fish.

On 28 Dec 2021, at 5:46 pm, ciscohack @.***> wrote:  @hSaria You said this to me "Spend some time understanding the different featuresRegex by reviewing a Regex and parsing it visually" is there any tool where i can debug the regex and see it visually. i use regex101.com and the regex i shared is working in that tool but you pin point lots of mistake so that tool is not reliable for debugging.. how can i visually see my regex in action

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you were mentioned.