-
Notifications
You must be signed in to change notification settings - Fork 21
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
yoink qtcreator's ansi handler #105
base: master
Are you sure you want to change the base?
Conversation
if (startPos < text.count()) | ||
outputTextBrowser->textCursor().insertText(text.mid(startPos), format); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you hooked this to output text browser's insert signal or w/e then ANSI escapes would be colored for all plugins instead of just the server plugin. Also we may want an option to disable ANSI later and I'm not sure how granular such an option should be, I think Visual Studio has one to disable its color output.
QList<Utils::FormattedText> txts = ansiHandler.parseText(QString::fromStdString(log.message() + "\n")); | ||
for (auto& str : txts) { | ||
emit LogOutput(str.text, str.format); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ANSI escape stuff itself could have been made a plugin and more loosely coupled but I suppose that might be overkill.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I guess this is fine because now all plugins have ability to log formatted output of their own.
|
||
static QColor ansiColor(uint code) | ||
{ | ||
if (code < 8) return QColor(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use R_EXPECT
here, albeit this tightly couples this component with the rest of our code base making it harder to pull updates to this source from Qt again.
Line 29 in b3cc0ac
#define R_EXPECT(cond, ret) \ |
Rather than change this source, what we could do actually is wrap QTC_ASSERT
to R_EXPECT
so we can easily pull updated versions of this source in the future.
// strippedText always starts with "\e[" | ||
QString strippedText = input.text.mid(escapePos); | ||
while (!strippedText.isEmpty()) { | ||
while (strippedText.startsWith(escape)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you dropped two other asserts from the original here.
https://github.com/qt-creator/qt-creator/blob/fc9bdf1255741f9261572d8560c6d8d1def76828/src/libs/utils/ansiescapecodehandler.cpp#L95
https://github.com/qt-creator/qt-creator/blob/fc9bdf1255741f9261572d8560c6d8d1def76828/src/libs/utils/ansiescapecodehandler.cpp#L104
Also, I like how QTC_ASSERT
accepts break as an argument, we should do that maybe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think i just used older version
|
||
// \e[K is not supported. Just strip it. | ||
if (strippedText.startsWith(eraseToEol)) { | ||
strippedText.remove(0, 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you comment out just this single line (not the continue!) you will see the letter k on both sides of text that you would expect to be colored. That means GCC is coloring its output using specific ANSI escapes which this ANSI escape handler does not support. That is why color output is still not working while it is correctly bold and such.
Ok after some testing, I don't have any idea how Qt Creator manages to keep the view at the bottom without applying the text cursor like I do above. It seems like they do somewhere for the "Compile Output" window in Qt Creator but I can't find where. However, I dislike doing it this way because this is how LGM did it, and it doesn't let you scroll up at all while output is coming (very annoying!). I like the behavior of This is much closer to how a terminal actually behaves and in fact is exactly what my testing shows in MSYS2 for me. |
If fundies insists, Robert, let him use this. I think it's ugly as stop-gaps go, but it'll work. Another alternative is this library: https://github.com/theZiz/aha/blob/master/aha.c Seems we could copy-paste that instead. It's MPL-licensed, which is closer to LGPL. It might support that weird |
That weird |
No description provided.