pkulchenko / ZeroBraneStudio

Lightweight Lua-based IDE for Lua with code completion, syntax highlighting, live coding, remote debugger, and code analyzer; supports Lua 5.1, 5.2, 5.3, 5.4, LuaJIT and other Lua interpreters on Windows, macOS, and Linux
http://studio.zerobrane.com/
Other
2.61k stars 519 forks source link

Color text output via outputfilter #684

Closed CetoBasilius closed 6 years ago

CetoBasilius commented 8 years ago

We have an internal logging system which adds an identifier to messages depending on how they call the library.

logger.info adds an [I] logger.warn adds a [W] logger.error adds a [E] logger.debug adds a [D]

Here is a screenshot:

screen shot 2016-08-05 at 12 51 39 pm

Would like to be able to color specific lines depending on what some sort of parser finds, for example, in the outputfilter this could be done by finding the desired pattern and return or set the next line text color.

debugger.outputfilter = function(m)
    if string.find(m, "[E]") then
        ide:GetOutput():setTextColor(1, 0, 0)
    end
    return m
end

Something like that. could it be possible? or any other way?

Here is an example for a quick google search for "colored output console" (Not the prettiest)

screen shot 2016-08-05 at 12 51 39 pm

Maybe just color the "[E]" via a spec file for the console? That's another idea.

pkulchenko commented 8 years ago

This should be possible, but is likely to require couple of new API calls to be added, so I'll take a look after the next release is out.

CetoBasilius commented 8 years ago

Sounds good. It occurred to me that maybe i could rewire the output console to use a spec file (If it does not already). I see the local/remote console already uses this method:

screen shot 2016-08-06 at 11 49 12 am

Maybe just adding a new spec file to recognize [E], [W], [D], [I] as keywords and color them? will experiment and see what i can make of it.

EDIT: Adding a spec file to the console works! after running SetupKeywords(ide.frame.bottomnotebook.errorlog,"lua",nil,ide.config.stylesoutshell,ide.font.oNormal,ide.font.oItalic) on the local console i get this on my output window:

screen shot 2016-08-06 at 12 05 39 pm

Maybe i can somehow add it to my configuration file, will make my log spec file and come back with results!

EDIT2: I just can't seem to get it to work. I can get the letters colored if i add them as keywords, but not the colors i want to assign to them, Also could not get the [] to get colored. I guess the outputfilter way would be way easier for users who are not too familiar with zerobranes source code. Will keep trying though.

pkulchenko commented 8 years ago

@CetoBasilius, the colors are controlled by keywords0, keywords1, etc. settings (assigned as stylesoutshell.keywords0.fg = {255, 0, 0} for example). You can modify the values using something like (not that the color of keywords[1] is unfortunately controlled by keywords0 and so on as the numbers in keywords0 constants are 0-based):

local luaspec = ide.specs.lua
luaspec.keywords[1] = luaspec.keywords[1] .. ' Main Database Localization'

I think coloring of square brackets is problematic as it's controlled by the lexer. Things should get easier when I finish integrating LexLPeg as it will allow you to add your own lexer written in Lua, so you can parse and color editor/Output/Console content almost any way you want.

CetoBasilius commented 8 years ago

That sounds great. Had no luck with the spec file approach. Explored ZBS all the way around though, very good project.

pkulchenko commented 8 years ago

I've been making progress with the LexLPeg lexer, so it's likely to be included in the next release.

pedro-andrade-inpe commented 6 years ago

Are there any news related to this issue? I saw that release 1.5 has something new related to LexLPeg.

pkulchenko commented 6 years ago

@pedro-andrade-inpe, yes, there have been further improvements to LexLPeg, which should not be working on all supported platforms (OSX support was included in 1.60 and Linux will be included in 1.70), but there haven't been any new work done on this issue.

What would you be specifically interested in? Do you need some arbitrary color (like, "output this line and color it red"), or do you need colors according to some format (like, "the output follows this format, which has elements with specific colors")?

pedro-andrade-inpe commented 6 years ago

I need to have colored output in the same way of Linux/Mac terminal. For example:

screen shot 2017-10-10 at 09 11 21

In ZeroBrane I got:

screen shot 2017-10-10 at 09 13 30

If the code in the description of the issue (debugger.outputfilter = ...) works, I could try to write a package for ZBS.

pkulchenko commented 6 years ago

@pedro-andrade-inpe, it should be possible using the ErrorList lexer as it supports escape sequences, but I can't get it to work. I posted a message to the Scintilla maillist and will update when I hear back.

pedro-andrade-inpe commented 6 years ago

Very nice! Looking forward to use this functionality! Thanks!

pkulchenko commented 6 years ago

@pedro-andrade-inpe, @CetoBasilius, I've implemented support for ansi-color escapes in the Output panel, so you can color the output using those escapes. It's enabled by default, but can be turned off with output.showansi=false setting.

For example, the following script should print all supported colors in the Output panel when executed from the IDE:

for i = 0,8 do
  print(("%s \027[%dmXYZ\027[0m normal"):format(30+i, 30+i))
end
for i = 0,8 do
  print(("%s \027[1;%dmXYZ\027[0m bright"):format(38+i, 30+i))
end