1

I have an issue with a log output in a buffer, that i get from Flutter / Dart via akinsho/flutter-tools.nvim. The log contains some ANSI color codes, see below. I believe the actual color code is the [38;5;12m and [0m on each line, but correct me if I'm wrong.

D/VRI[MainActivity]( 3255): Cancelling draw. cancelDueToPreDrawListener=true cancelDueToSync=false
I/flutter ( 3255): [38;5;12mProvider<NotificationService> Created - value: Instance of 'NotificationService'[0m
I/flutter ( 3255): [38;5;12mBaseNotificationService | onAppStarted - [0m
I/flutter ( 3255): [38;5;12mProvider<FirebaseMessagingRepository> Created - value: Instance of 'FirebaseMessagingRepository'[0m
I/flutter ( 3255): [38;5;12mProvider<RemoteConfigService> Updated - Value: Instance of 'RemoteConfigService'[0m
D/VRI[MainActivity]( 3255): Cancelling draw. cancelDueToPreDrawListener=true cancelDueToSync=false
I/flutter ( 3255): [38;5;12msharedLocalizationsProvider Created - value: Instance of 'SharedLocalizationsSv'[0m

What I'm trying to do is to get the lines to have the correct colors, and I have tried a few different plugins, such as norcalli/nvim-colorizer.lua, chrisbra/Colorizer and MTDL9/vim-log-highlighting.

But I can't get any of them to do what I want. The first two doesn't work at all (the color doesn't change). Neither automatically, nor by running the command that is supposed to colorize the current buffer. And the third plugin does work, but it doesn't colorize based on ANSI codes.

I'm sure I'm doing something wrong, but I just can't figure out what. Any help is appreciated!

Here is my config, if that is of interest: https://github.com/Hannnes1/nvim-config

Update: I tried the AnsiEsc.vim plugin (from here), and that almost works. It removed all the escape codes from the Flutter log, but didn't change any colors. However, when I tried it in the sample in :h AnsiEsc, it colors some codes, like [30;5mblack[m , but not [30;48;5;22m/ \[m. Not sure what the reason for that is.

Update 2: I can get the colors to work if I disable 24-bit color (reset termguicolors to false). So I would need to find a way to make ANSI escape sequences work with 24-bit colors, I think?

7
  • Log output sounds like a case for less -R - unless you need to be able to edit the log, of course.
    – Friedrich
    Feb 26 at 21:49
  • I don't need to edit the log, so less -R might work. Are you able to tell how I might do that? It seems like (and forgive me if I use the wrong terminology), the log is just a buffer named FLUTTER_DEV_LOG, and not a file or anything. Feb 26 at 22:05
  • There should be some similar questions floating around here; maybe one of those answers your question?
    – D. Ben Knoble
    Feb 26 at 23:44
  • (You can write the buffer to a file, if you need.)
    – D. Ben Knoble
    Feb 26 at 23:45
  • Alright, thanks! I will look around Feb 27 at 6:49

1 Answer 1

0

I believe your example lack the ^[ aka Esc character obtained by hitting Ctrl vEsc.

With these character inserted I have the following result:

enter image description here

For the following text:

I/flutter ( 3255): ^[[38;5;12msharedLocalizationsProvider Created - value: Instance of 'SharedLocalizationsSv'^[[0m
D/VRI[MainActivity]( 3255): Cancelling draw. cancelDueToPreDrawListener=true cancelDueToSync=false
I/flutter ( 3255): ^[[38;5;12mProvider<NotificationService> Created - value: Instance of 'NotificationService'^[[0m
I/flutter ( 3255): ^[[38;5;12mBaseNotificationService | onAppStarted - ^[[0m
I/flutter ( 3255): ^[[38;5;12mProvider<FirebaseMessagingRepository> Created - value: Instance of 'FirebaseMessagingRepository'^[[0m
I/flutter ( 3255): ^[[38;5;12mProvider<RemoteConfigService> Updated - Value: Instance of 'RemoteConfigService'^[[0m
D/VRI[MainActivity]( 3255): Cancelling draw. cancelDueToPreDrawListener=true cancelDueToSync=false
I/flutter ( 3255): ^[[38;5;12msharedLocalizationsProvider Created - value: Instance of 'SharedLocalizationsSv'^[[0m
^[[30;48;5;22mBlack on Green^[[m

Where ^[ again are the Esc character obtained by hitting Ctrl vEsc.

Remark: I inserted them in your text by running:

:%s/\[\d\+/^[&/g

Where ^[ is obtained by hitting Ctrl vEsc :-)

4
  • Does this still work when you :set termguicolors as OP wrote in his update 2? To me, it seems the original problem was not the escapes or the plugin but ANSI escapes with termguicolors.
    – Friedrich
    Feb 27 at 10:33
  • 1
    On gVim it works whatever the value of termguicolors on Vim and nvim it is indeed only working is off (:set notermguicolors) and it seems that on nvim-qt it doesn't work whatever the value of termguicolors. Feb 27 at 11:11
  • 1
    Thanks, you confirm what OP writes. Based on :help termguicolors I would not assume it to have any effect in a GUI version. Now the question remains: can we have termguicolors and ANSI color escapes or are they mutually exclusive? I don't know and I'd be in favor of setting notermguicolors (the default).
    – Friedrich
    Feb 27 at 12:05
  • 1
    Thanks for your reply, and for confirming that :set termguicolors doesn't work. I just noticed that the correct escape codes were removed when I posted. It is actually correct in nvim. I might just look for an alternative to the plugin instead. Feb 27 at 18:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.