Textformat
-
Ich schreibe zurzeit eine Konsolen Anwendung (Cross-Plattform)
und wollte heute Farben support implementieren:textformat.cpp
#include <textformat.h> const char * TEXTFORMAT::BLACK = "\xc2\xa7""0"; const char * TEXTFORMAT::NAVY = "\xc2\xa7""1"; const char * TEXTFORMAT::GREEN = "\xc2\xa7""2";textformat.h
#ifndef _TEXTFORMAT_H #define _TEXTFORMAT_H class TEXTFORMAT { public: static const char * BLACK; static const char * NAVY; static const char * GREEN; }; #endifund jetzt wollte ICH euch fragen ob ihr eine Methode kennt womit ich meinen Text in Grüner Farbe ausgeben könnte kennt?
Server->getLogger->info(TEXTFORMAT::GREEN"Grünner Text")Als beispiel
-
windows:
//farben werte kannste hier rauslesen, bin gerade zu faul die msdn seite zu suchen: namespace foreground { typedef int type; type blue = 0x1; type green = 0x2; type red = 0x4; type intensity = 0x8; } namespace background { typedef unsigned type; type black = 0; type blue = 0x10; type green = 0x20; type red = 0x40; type intensity = 0x80; }HANDLE console_hwnd = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(console_hwnd, background | foreground); //ausgabe //ggf. wieder farbe zurücksetzenwobei background und foreground werte von oben sind.
bb
-
Danke doch ich suche eine Methode für Cross Plattform Support
Ich schreibe zurzeit eine Konsolen Anwendung (Cross-Plattform)
-
Sanjey schrieb:
Danke doch ich suche eine Methode für Cross Plattform Support
Ich schreibe zurzeit eine Konsolen Anwendung (Cross-Plattform)
Es gibt aber keine cross-platform Methode, um die Farbe zu setzen, direkt in der Standardbibliothek.
Du hast zwei Möglichkeiten:
-Du lädst dir eine externe, cross-platform Bibliothek herunter
-Du implementierst die Funktionen selber, intern switcht so eine Bibliothek nämlich auch nur via #ifdef die Funktionen abhängig von der Implementierung.