A working c++ lollms client example

This commit is contained in:
Saifeddine ALOUI 2023-09-17 17:48:00 +02:00
parent 366ac14ba6
commit e04d2269bd
2 changed files with 84 additions and 0 deletions

View File

@ -0,0 +1,33 @@
#ifndef ASCIIColors_H
#define ASCIIColors_H
#include <iostream>
#include <string>
class ASCIIColors {
public:
// Color codes
static const std::string RESET;
static const std::string BLACK;
static const std::string RED;
static const std::string GREEN;
static const std::string YELLOW;
static const std::string BLUE;
static const std::string MAGENTA;
static const std::string CYAN;
static const std::string WHITE;
// Print text in the specified color
static void printColoredText(const std::string& text, const std::string& color, bool newLine = true, bool flush = true);
// Print text in a specific color with or without a newline, and optionally flush
static void red(const std::string& text, bool newLine = true, bool flush = true);
static void green(const std::string& text, bool newLine = true, bool flush = true);
static void yellow(const std::string& text, bool newLine = true, bool flush = true);
static void blue(const std::string& text, bool newLine = true, bool flush = true);
static void magenta(const std::string& text, bool newLine = true, bool flush = true);
static void cyan(const std::string& text, bool newLine = true, bool flush = true);
static void white(const std::string& text, bool newLine = true, bool flush = true);
};
#endif // ASCIIColors_H

View File

@ -0,0 +1,51 @@
#include "ASCIIColors.h"
// Define the ANSI escape codes
const std::string ASCIIColors::RESET = "\033[0m";
const std::string ASCIIColors::BLACK = "\033[30m";
const std::string ASCIIColors::RED = "\033[31m";
const std::string ASCIIColors::GREEN = "\033[32m";
const std::string ASCIIColors::YELLOW = "\033[33m";
const std::string ASCIIColors::BLUE = "\033[34m";
const std::string ASCIIColors::MAGENTA = "\033[35m";
const std::string ASCIIColors::CYAN = "\033[36m";
const std::string ASCIIColors::WHITE = "\033[37m";
// Print text in the specified color
void ASCIIColors::printColoredText(const std::string& text, const std::string& color, bool newLine, bool flush) {
std::cout << color << text << RESET;
if (newLine)
std::cout << std::endl;
else
if (flush)
std::cout.flush();
}
// Print text in a specific color with or without a newline, and optionally flush
void ASCIIColors::red(const std::string& text, bool newLine, bool flush) {
printColoredText(text, RED, newLine, flush);
}
void ASCIIColors::green(const std::string& text, bool newLine, bool flush) {
printColoredText(text, GREEN, newLine, flush);
}
void ASCIIColors::yellow(const std::string& text, bool newLine, bool flush) {
printColoredText(text, YELLOW, newLine, flush);
}
void ASCIIColors::blue(const std::string& text, bool newLine, bool flush) {
printColoredText(text, BLUE, newLine, flush);
}
void ASCIIColors::magenta(const std::string& text, bool newLine, bool flush) {
printColoredText(text, MAGENTA, newLine, flush);
}
void ASCIIColors::cyan(const std::string& text, bool newLine, bool flush) {
printColoredText(text, CYAN, newLine, flush);
}
void ASCIIColors::white(const std::string& text, bool newLine, bool flush) {
printColoredText(text, WHITE, newLine, flush);
}