aafulei / color-console Goto Github PK
View Code? Open in Web Editor NEWA lightweight header-only C++ library to bring colors to your Windows console with a very-easy-to-use API.
License: MIT License
A lightweight header-only C++ library to bring colors to your Windows console with a very-easy-to-use API.
License: MIT License
I want to try to dye a string that is defined by a cin >> input, and make the string reference the color each time the string is called.
I.E.
string firstName
cin >> firstName
how do I do this?
You are using a lot of std::string types and always copy them. Consider using const char* pointer since you are only using raw literal strings. This will avoid unnecessary copys and allocations (this of course depends on the implementation of std::string and if its using short string optimisation)
And I took a deeper look at your code. Why are you not just using an enum value that already has the value needed for the win32 api? Something like
enum class hue {black = 0, .... }
Then you would just need to overload the stream operator for the enum.
color-console-error.txt
See errors in file.
Not all functions are marked with the keywords inline or constexpr or are templated. As a result if one would include this headder more than twice the linker is going to complain.
I'd like to use this lib with wcout to dispaly utf16 characters, but when writing
wcout << dye::green(L"hello");
I get the error:
error: no match for 'operator<<' (operand types are 'std::wostream' {aka 'std::basic_ostream<wchar_t>'} and 'dye::R<const wchar_t*>' {aka 'dye::colorful<const wchar_t*>'})
wcout << dye::green(L"hello");
~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Any quick solution for this issue?
Error LNK1169 one or more multiply defined symbols found
Error LNK2005 "void __cdecl hue::set_text(class std::basic_string<char,struct std::char_traits,class std::allocator >)" (?set_text@hue@@yaxv?$basic_string@DU?$char_traits@D@std@@v?$allocator@D@2@@std@@@z) already defined in person.obj
Error LNK2005 "void __cdecl hue::set_background(class std::basic_string<char,struct std::char_traits,class std::allocator >)" (?set_background@hue@@yaxv?$basic_string@DU?$char_traits@D@std@@v?$allocator@D@2@@std@@@z) already defined in person.obj C++_Weak_ptr
Severity Code Description Project File Line Suppression State
Error LNK2005 "void __cdecl hue::set(int,int)" (?set@hue@@yaxhh@Z) already defined in person.obj C++_Weak_ptr
_there are still as many as 300 more link errors like this happend when i tried to compile the program.
_when you include color-console library inside a user defined class this link errors happen, but if you use it without being included
in any class no errors generate.
please help me what shoul i do now?
FIX the problem sooooooooooooooooooon
thank you very much helped me a lot!
I'm making a code editor based on the vim type terminal
Not sure what library conflicts with windows.h as some library also defines byte, was necessary to add #define WIN32_LEAN_AND_MEAN at the top of the header file to make it work, without the macro, throws a bunch of compilation errors like this:
In file included from c:\mingdef\mingw\x86_64-w64-mingw32\include\wtypes.h:8, from c:\mingdef\mingw\x86_64-w64-mingw32\include\winscard.h:10, from c:\mingdef\mingw\x86_64-w64-mingw32\include\windows.h:97, from {path} headers/color.hpp:11, from {path} testing.cpp:7: c:\mingdef\mingw\x86_64-w64-mingw32\include\rpcndr.h:64:11: error: reference to 'byte' is ambiguous 64 | typedef byte cs_byte; | ^~~~
Add a new macro that can support function-like call for hue namespace
#define color(operation,content) operation << content << hue::reset
std::cout<<color(hue::red, "Hello world!"); //(color red)
std::cout<<color(hue::red, "Hello world!") << "just kidding"; //first one color red
std::cout<<color(hue::red, "Hello world!" << "just kidding") ; //2 string color red
all three work, everything outside of the color macro will be reset to original, because this macro call hue::reset
after all operation
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.