cellar now outputs pretty shit when it detects stdout is a terminal

This commit is contained in:
Nicholas O'Connor
2017-03-24 19:30:58 -07:00
parent c877663932
commit 4e67bd40c5
4 changed files with 127 additions and 6 deletions

View File

@@ -34,6 +34,7 @@ void cellar::print_header() {
}
int main(int argc, char* argv[]) {
output::detect_colors();
if (argc == 1) {
print_header();
cout << "\n(try \"cellar help\" if you're confused)" << endl;

View File

@@ -1,14 +1,55 @@
#include <iostream>
#include <string>
#include <unistd.h>
#include "ansicol.hpp"
#include "output.hpp"
void cellar::output::statement(std::string str_message) {
std::cout << "* " << str_message << std::endl;
using namespace std;
using namespace cellar::output;
bool cellar::output::colors;
void cellar::output::detect_colors() {
int tty = isatty(fileno(stdout));
if (tty == 1) {
colors = true;
} else {
colors = false;
}
}
void cellar::output::warning(std::string str_message) {
std::cerr << "* " << str_message << std::endl;
void cellar::output::statement(string str_message) {
if (colors) {
cout << ansicol::green << " >";
cout << ansicol::green_bold << "> ";
cout << ansicol::reset;
} else {
cout << "STAT ";
}
cout << str_message << endl;
}
void cellar::output::error(std::string str_message) {
std::cerr << "* " << str_message << std::endl;
void cellar::output::warning(string str_message) {
if (colors) {
cerr << ansicol::yellow << " >";
cerr << ansicol::yellow_bold << "> ";
cerr << ansicol::reset;
} else {
cerr << "WARN ";
}
cerr << str_message << endl;
}
void cellar::output::error(string str_message) {
if (colors) {
cerr << ansicol::red << " >";
cerr << ansicol::red_bold << "> ";
cerr << ansicol::reset;
} else {
cerr << "ERR! ";
}
cerr << str_message << endl;
}