Skip to content

[lldb] Add color support to StreamString #77380

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

Merged
merged 1 commit into from
Jan 10, 2024

Conversation

PortalPete
Copy link
Contributor

@PortalPete PortalPete commented Jan 8, 2024

This change just adds a bool colors parameter to the StreamString class's constructor, which it passes up to its superclass’s constructor.

I'm working on another patch that prints out error messages using a StreamString but I wasn't getting colorized text because of this missing implementation detail.

rdar://120671168

This change just adds a `bool colors` parameter to the `StreamString` class's constructor, which it passes up to its superclass’s constructor.

rdar://120671168
@llvmbot
Copy link
Member

llvmbot commented Jan 8, 2024

@llvm/pr-subscribers-lldb

Author: Pete Lawrence (PortalPete)

Changes

This change just adds a bool colors parameter to the StreamString class's constructor, which it passes up to its superclass’s constructor.

rdar://120671168


Full diff: https://github.com/llvm/llvm-project/pull/77380.diff

2 Files Affected:

  • (modified) lldb/include/lldb/Utility/StreamString.h (+1-1)
  • (modified) lldb/source/Utility/StreamString.cpp (+1-1)
diff --git a/lldb/include/lldb/Utility/StreamString.h b/lldb/include/lldb/Utility/StreamString.h
index 4c568acdcc6f60..3d675caf8f3f43 100644
--- a/lldb/include/lldb/Utility/StreamString.h
+++ b/lldb/include/lldb/Utility/StreamString.h
@@ -22,7 +22,7 @@ namespace lldb_private {
 
 class StreamString : public Stream {
 public:
-  StreamString();
+  StreamString(bool colors = false);
 
   StreamString(uint32_t flags, uint32_t addr_size, lldb::ByteOrder byte_order);
 
diff --git a/lldb/source/Utility/StreamString.cpp b/lldb/source/Utility/StreamString.cpp
index 745a85b7576520..0d35ccbdbbd0f5 100644
--- a/lldb/source/Utility/StreamString.cpp
+++ b/lldb/source/Utility/StreamString.cpp
@@ -11,7 +11,7 @@
 using namespace lldb;
 using namespace lldb_private;
 
-StreamString::StreamString() : Stream(0, 4, eByteOrderBig) {}
+StreamString::StreamString(bool colors) : Stream(0, 4, eByteOrderBig, colors) {}
 
 StreamString::StreamString(uint32_t flags, uint32_t addr_size,
                            ByteOrder byte_order)

@DavidSpickett
Copy link
Collaborator

Surprised that no one is using that constructor, and if that's true - is this change to support something else or just making sure we don't make a mistake in future if we do use this class?

@PortalPete
Copy link
Contributor Author

Surprised that no one is using that constructor, and if that's true - is this change to support something else or just making sure we don't make a mistake in future if we do use this class?

Me too!
I'm was working on another patch and figured out this is why I couldn't colorize the text using StringStream. As it is today, StreamString blocks the ability to enable color with its Stream superclass, which was probably just a simple oversight.

The good news is that everything that uses it today (without arguments) won't see any difference, thanks to the default argument to the new parameter, making it opt-in / off by default.

@adrian-prantl adrian-prantl merged commit cd7eaaa into llvm:main Jan 10, 2024
PortalPete added a commit to swiftlang/llvm-project that referenced this pull request Jan 23, 2024
This change just adds a `bool colors` parameter to the `StreamString`
class's constructor, which it passes up to its superclass’s constructor.

I'm working on another patch that prints out error messages using a
`StreamString` but I wasn't getting colorized text because of this
missing implementation detail.

rdar://120671168
justinfargnoli pushed a commit to justinfargnoli/llvm-project that referenced this pull request Jan 28, 2024
This change just adds a `bool colors` parameter to the `StreamString`
class's constructor, which it passes up to its superclass’s constructor.

I'm working on another patch that prints out error messages using a
`StreamString` but I wasn't getting colorized text because of this
missing implementation detail.

rdar://120671168
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants