Linux: color ASCII drawing classLinux C++ Timer Class: How can I improve the accuracy?Draw an ASCII checkerboardBasic GNU/Linux C++ serial I/O classASCII triangle in JCode that prints ASCII bowties to screen given inputsSPI Connection Class on embedded LinuxDrawing a Checked GridASCII MandelbrotInteractive Linux upgrade script - Follow-up #1Drawing a snowman in ASCII art

Most cost effective thermostat setting: consistent temperature vs. lowest temperature possible

How to simplify this time periods definition interface?

What's the meaning of “spike” in the context of “adrenaline spike”?

What should tie a collection of short-stories together?

how to draw discrete time diagram in tikz

Unexpected result from ArcLength

How to use deus ex machina safely?

My Graph Theory Students

Python if-else code style for reduced code for rounding floats

Is a party consisting of only a bard, a cleric, and a warlock functional long-term?

Who is flying the vertibirds?

A limit with limit zero everywhere must be zero somewhere

Happy pi day, everyone!

Existence of subset with given Hausdorff dimension

Stiffness of a cantilever beam

Interplanetary conflict, some disease destroys the ability to understand or appreciate music

It's a yearly task, alright

Are ETF trackers fundamentally better than individual stocks?

Min function accepting varying number of arguments in C++17

Use void Apex method in Lightning Web Component

Why doesn't the EU now just force the UK to choose between referendum and no-deal?

Property of summation

Do the common programs (for example: "ls", "cat") in Linux and BSD come from the same source code?

What is the rarity of this homebrew magic staff?



Linux: color ASCII drawing class


Linux C++ Timer Class: How can I improve the accuracy?Draw an ASCII checkerboardBasic GNU/Linux C++ serial I/O classASCII triangle in JCode that prints ASCII bowties to screen given inputsSPI Connection Class on embedded LinuxDrawing a Checked GridASCII MandelbrotInteractive Linux upgrade script - Follow-up #1Drawing a snowman in ASCII art













5












$begingroup$


I am working on a pseudo graphical interface for a chess engine I wrote. I want to draw a colored chess board with ascii pieces. To abstract the pure std::cout << std::endl; I wrote this little class to organize an ascii-character "framebuffer":



#include <iostream>
#include <sys/ioctl.h>
#include <unistd.h>
#include <vector>
#include <string>
#include <cassert>
#include <chrono>
#include <thread>

struct Color

unsigned char r;
unsigned char g;
unsigned char b;
;

class Framebuffer

std::vector<char> charBuffer;
std::vector<Color> textColorBuffer;
std::vector<Color> backgroundColorBuffer;
static const int frametime = 33;

public:

const size_t width;
const size_t height;

Framebuffer() :
width([]()
winsize w;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
return w.ws_col;
()),
height([]()
winsize w;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
return w.ws_row;
())

charBuffer = std::vector<char>(height*width);
textColorBuffer = std::vector<Color>(height*width);
backgroundColorBuffer = std::vector<Color>(height*width);
clear();

void clear()

for(auto& i : charBuffer)

i = ' ';

for(auto& i : textColorBuffer)

i = 255,255,255;

for(auto& i : backgroundColorBuffer)

i = 0,0,0;


void setChar(size_t col,size_t row, char c)

assert(row < height && col < width && row >= 0 && col >= 0);
charBuffer.at(row*width + col) = c;

void setChar(size_t col, size_t row, std::vector<std::string> box)

assert(row < height && col < width && row >= 0 && col >= 0);
for(size_t rowOffset = 0; rowOffset<box.size(); rowOffset++)

for(size_t colOffset = 0; colOffset<box[rowOffset].size(); colOffset++)

setChar(col+colOffset, row+rowOffset, box[rowOffset][colOffset]);



void setTextColor(size_t col,size_t row, Color color)

assert(row < height && col < width && row >= 0 && col >= 0);
textColorBuffer.at(row*width + col) = color;

void setTextColor(size_t col, size_t row, std::vector<std::vector<Color>> box)

assert(row < height && col < width && row >= 0 && col >= 0);
for(size_t rowOffset = 0; rowOffset<box.size(); rowOffset++)

for(size_t colOffset = 0; colOffset<box[rowOffset].size(); colOffset++)

setTextColor(col+colOffset, row+rowOffset, box[rowOffset][colOffset]);



void setBackgroundColor(size_t col,size_t row, Color color)

assert(row < height && col < width && row >= 0 && col >= 0);
backgroundColorBuffer.at(row*width + col) = color;

void setBackgroundColor(size_t col, size_t row, std::vector<std::vector<Color>> box)

assert(row < height && col < width && row >= 0 && col >= 0);
for(size_t rowOffset = 0; rowOffset<box.size(); rowOffset++)

for(size_t colOffset = 0; colOffset<box[rowOffset].size(); colOffset++)

setBackgroundColor(col+colOffset, row+rowOffset, box[rowOffset][colOffset]);



char getChar(size_t col, size_t row)

assert(row < height && col < width && row >= 0 && col >= 0);
return charBuffer.at(row*width + col);

Color getTextColor(size_t col, size_t row)

assert(row < height && col < width && row >= 0 && col >= 0);
return textColorBuffer.at(row*width + col);

Color getBackgroundColor(size_t col, size_t row)

assert(row < height && col < width && row >= 0 && col >= 0);
return backgroundColorBuffer.at(row*width + col);

void print()

static std::thread printerThread;
if(printerThread.joinable())

printerThread.join();

auto printer = [this]()

std::string output = "";
for(size_t row = 0; row<height; row++)

for(size_t col = 0; col<width; col++)

Color textColor = getTextColor(col, row);
Color backgroundColor = getBackgroundColor(col, row);
output += "33[38;2;";
output += std::to_string((int)textColor.r) + ";";
output += std::to_string((int)textColor.g) + ";";
output += std::to_string((int)textColor.b) + "m";
output += "33[48;2;";
output += std::to_string((int)backgroundColor.r) + ";";
output += std::to_string((int)backgroundColor.g) + ";";
output += std::to_string((int)backgroundColor.b) + "m";
output += getChar(col, row);

if(row != height - 1)

output += "n";


std::this_thread::sleep_for(std::chrono::milliseconds(frametime));
std::system("clear");
std::cout << output << std::flush;
;
printerThread = std::thread(printer);

;









share|improve this question









$endgroup$
















    5












    $begingroup$


    I am working on a pseudo graphical interface for a chess engine I wrote. I want to draw a colored chess board with ascii pieces. To abstract the pure std::cout << std::endl; I wrote this little class to organize an ascii-character "framebuffer":



    #include <iostream>
    #include <sys/ioctl.h>
    #include <unistd.h>
    #include <vector>
    #include <string>
    #include <cassert>
    #include <chrono>
    #include <thread>

    struct Color

    unsigned char r;
    unsigned char g;
    unsigned char b;
    ;

    class Framebuffer

    std::vector<char> charBuffer;
    std::vector<Color> textColorBuffer;
    std::vector<Color> backgroundColorBuffer;
    static const int frametime = 33;

    public:

    const size_t width;
    const size_t height;

    Framebuffer() :
    width([]()
    winsize w;
    ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
    return w.ws_col;
    ()),
    height([]()
    winsize w;
    ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
    return w.ws_row;
    ())

    charBuffer = std::vector<char>(height*width);
    textColorBuffer = std::vector<Color>(height*width);
    backgroundColorBuffer = std::vector<Color>(height*width);
    clear();

    void clear()

    for(auto& i : charBuffer)

    i = ' ';

    for(auto& i : textColorBuffer)

    i = 255,255,255;

    for(auto& i : backgroundColorBuffer)

    i = 0,0,0;


    void setChar(size_t col,size_t row, char c)

    assert(row < height && col < width && row >= 0 && col >= 0);
    charBuffer.at(row*width + col) = c;

    void setChar(size_t col, size_t row, std::vector<std::string> box)

    assert(row < height && col < width && row >= 0 && col >= 0);
    for(size_t rowOffset = 0; rowOffset<box.size(); rowOffset++)

    for(size_t colOffset = 0; colOffset<box[rowOffset].size(); colOffset++)

    setChar(col+colOffset, row+rowOffset, box[rowOffset][colOffset]);



    void setTextColor(size_t col,size_t row, Color color)

    assert(row < height && col < width && row >= 0 && col >= 0);
    textColorBuffer.at(row*width + col) = color;

    void setTextColor(size_t col, size_t row, std::vector<std::vector<Color>> box)

    assert(row < height && col < width && row >= 0 && col >= 0);
    for(size_t rowOffset = 0; rowOffset<box.size(); rowOffset++)

    for(size_t colOffset = 0; colOffset<box[rowOffset].size(); colOffset++)

    setTextColor(col+colOffset, row+rowOffset, box[rowOffset][colOffset]);



    void setBackgroundColor(size_t col,size_t row, Color color)

    assert(row < height && col < width && row >= 0 && col >= 0);
    backgroundColorBuffer.at(row*width + col) = color;

    void setBackgroundColor(size_t col, size_t row, std::vector<std::vector<Color>> box)

    assert(row < height && col < width && row >= 0 && col >= 0);
    for(size_t rowOffset = 0; rowOffset<box.size(); rowOffset++)

    for(size_t colOffset = 0; colOffset<box[rowOffset].size(); colOffset++)

    setBackgroundColor(col+colOffset, row+rowOffset, box[rowOffset][colOffset]);



    char getChar(size_t col, size_t row)

    assert(row < height && col < width && row >= 0 && col >= 0);
    return charBuffer.at(row*width + col);

    Color getTextColor(size_t col, size_t row)

    assert(row < height && col < width && row >= 0 && col >= 0);
    return textColorBuffer.at(row*width + col);

    Color getBackgroundColor(size_t col, size_t row)

    assert(row < height && col < width && row >= 0 && col >= 0);
    return backgroundColorBuffer.at(row*width + col);

    void print()

    static std::thread printerThread;
    if(printerThread.joinable())

    printerThread.join();

    auto printer = [this]()

    std::string output = "";
    for(size_t row = 0; row<height; row++)

    for(size_t col = 0; col<width; col++)

    Color textColor = getTextColor(col, row);
    Color backgroundColor = getBackgroundColor(col, row);
    output += "33[38;2;";
    output += std::to_string((int)textColor.r) + ";";
    output += std::to_string((int)textColor.g) + ";";
    output += std::to_string((int)textColor.b) + "m";
    output += "33[48;2;";
    output += std::to_string((int)backgroundColor.r) + ";";
    output += std::to_string((int)backgroundColor.g) + ";";
    output += std::to_string((int)backgroundColor.b) + "m";
    output += getChar(col, row);

    if(row != height - 1)

    output += "n";


    std::this_thread::sleep_for(std::chrono::milliseconds(frametime));
    std::system("clear");
    std::cout << output << std::flush;
    ;
    printerThread = std::thread(printer);

    ;









    share|improve this question









    $endgroup$














      5












      5








      5





      $begingroup$


      I am working on a pseudo graphical interface for a chess engine I wrote. I want to draw a colored chess board with ascii pieces. To abstract the pure std::cout << std::endl; I wrote this little class to organize an ascii-character "framebuffer":



      #include <iostream>
      #include <sys/ioctl.h>
      #include <unistd.h>
      #include <vector>
      #include <string>
      #include <cassert>
      #include <chrono>
      #include <thread>

      struct Color

      unsigned char r;
      unsigned char g;
      unsigned char b;
      ;

      class Framebuffer

      std::vector<char> charBuffer;
      std::vector<Color> textColorBuffer;
      std::vector<Color> backgroundColorBuffer;
      static const int frametime = 33;

      public:

      const size_t width;
      const size_t height;

      Framebuffer() :
      width([]()
      winsize w;
      ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
      return w.ws_col;
      ()),
      height([]()
      winsize w;
      ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
      return w.ws_row;
      ())

      charBuffer = std::vector<char>(height*width);
      textColorBuffer = std::vector<Color>(height*width);
      backgroundColorBuffer = std::vector<Color>(height*width);
      clear();

      void clear()

      for(auto& i : charBuffer)

      i = ' ';

      for(auto& i : textColorBuffer)

      i = 255,255,255;

      for(auto& i : backgroundColorBuffer)

      i = 0,0,0;


      void setChar(size_t col,size_t row, char c)

      assert(row < height && col < width && row >= 0 && col >= 0);
      charBuffer.at(row*width + col) = c;

      void setChar(size_t col, size_t row, std::vector<std::string> box)

      assert(row < height && col < width && row >= 0 && col >= 0);
      for(size_t rowOffset = 0; rowOffset<box.size(); rowOffset++)

      for(size_t colOffset = 0; colOffset<box[rowOffset].size(); colOffset++)

      setChar(col+colOffset, row+rowOffset, box[rowOffset][colOffset]);



      void setTextColor(size_t col,size_t row, Color color)

      assert(row < height && col < width && row >= 0 && col >= 0);
      textColorBuffer.at(row*width + col) = color;

      void setTextColor(size_t col, size_t row, std::vector<std::vector<Color>> box)

      assert(row < height && col < width && row >= 0 && col >= 0);
      for(size_t rowOffset = 0; rowOffset<box.size(); rowOffset++)

      for(size_t colOffset = 0; colOffset<box[rowOffset].size(); colOffset++)

      setTextColor(col+colOffset, row+rowOffset, box[rowOffset][colOffset]);



      void setBackgroundColor(size_t col,size_t row, Color color)

      assert(row < height && col < width && row >= 0 && col >= 0);
      backgroundColorBuffer.at(row*width + col) = color;

      void setBackgroundColor(size_t col, size_t row, std::vector<std::vector<Color>> box)

      assert(row < height && col < width && row >= 0 && col >= 0);
      for(size_t rowOffset = 0; rowOffset<box.size(); rowOffset++)

      for(size_t colOffset = 0; colOffset<box[rowOffset].size(); colOffset++)

      setBackgroundColor(col+colOffset, row+rowOffset, box[rowOffset][colOffset]);



      char getChar(size_t col, size_t row)

      assert(row < height && col < width && row >= 0 && col >= 0);
      return charBuffer.at(row*width + col);

      Color getTextColor(size_t col, size_t row)

      assert(row < height && col < width && row >= 0 && col >= 0);
      return textColorBuffer.at(row*width + col);

      Color getBackgroundColor(size_t col, size_t row)

      assert(row < height && col < width && row >= 0 && col >= 0);
      return backgroundColorBuffer.at(row*width + col);

      void print()

      static std::thread printerThread;
      if(printerThread.joinable())

      printerThread.join();

      auto printer = [this]()

      std::string output = "";
      for(size_t row = 0; row<height; row++)

      for(size_t col = 0; col<width; col++)

      Color textColor = getTextColor(col, row);
      Color backgroundColor = getBackgroundColor(col, row);
      output += "33[38;2;";
      output += std::to_string((int)textColor.r) + ";";
      output += std::to_string((int)textColor.g) + ";";
      output += std::to_string((int)textColor.b) + "m";
      output += "33[48;2;";
      output += std::to_string((int)backgroundColor.r) + ";";
      output += std::to_string((int)backgroundColor.g) + ";";
      output += std::to_string((int)backgroundColor.b) + "m";
      output += getChar(col, row);

      if(row != height - 1)

      output += "n";


      std::this_thread::sleep_for(std::chrono::milliseconds(frametime));
      std::system("clear");
      std::cout << output << std::flush;
      ;
      printerThread = std::thread(printer);

      ;









      share|improve this question









      $endgroup$




      I am working on a pseudo graphical interface for a chess engine I wrote. I want to draw a colored chess board with ascii pieces. To abstract the pure std::cout << std::endl; I wrote this little class to organize an ascii-character "framebuffer":



      #include <iostream>
      #include <sys/ioctl.h>
      #include <unistd.h>
      #include <vector>
      #include <string>
      #include <cassert>
      #include <chrono>
      #include <thread>

      struct Color

      unsigned char r;
      unsigned char g;
      unsigned char b;
      ;

      class Framebuffer

      std::vector<char> charBuffer;
      std::vector<Color> textColorBuffer;
      std::vector<Color> backgroundColorBuffer;
      static const int frametime = 33;

      public:

      const size_t width;
      const size_t height;

      Framebuffer() :
      width([]()
      winsize w;
      ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
      return w.ws_col;
      ()),
      height([]()
      winsize w;
      ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
      return w.ws_row;
      ())

      charBuffer = std::vector<char>(height*width);
      textColorBuffer = std::vector<Color>(height*width);
      backgroundColorBuffer = std::vector<Color>(height*width);
      clear();

      void clear()

      for(auto& i : charBuffer)

      i = ' ';

      for(auto& i : textColorBuffer)

      i = 255,255,255;

      for(auto& i : backgroundColorBuffer)

      i = 0,0,0;


      void setChar(size_t col,size_t row, char c)

      assert(row < height && col < width && row >= 0 && col >= 0);
      charBuffer.at(row*width + col) = c;

      void setChar(size_t col, size_t row, std::vector<std::string> box)

      assert(row < height && col < width && row >= 0 && col >= 0);
      for(size_t rowOffset = 0; rowOffset<box.size(); rowOffset++)

      for(size_t colOffset = 0; colOffset<box[rowOffset].size(); colOffset++)

      setChar(col+colOffset, row+rowOffset, box[rowOffset][colOffset]);



      void setTextColor(size_t col,size_t row, Color color)

      assert(row < height && col < width && row >= 0 && col >= 0);
      textColorBuffer.at(row*width + col) = color;

      void setTextColor(size_t col, size_t row, std::vector<std::vector<Color>> box)

      assert(row < height && col < width && row >= 0 && col >= 0);
      for(size_t rowOffset = 0; rowOffset<box.size(); rowOffset++)

      for(size_t colOffset = 0; colOffset<box[rowOffset].size(); colOffset++)

      setTextColor(col+colOffset, row+rowOffset, box[rowOffset][colOffset]);



      void setBackgroundColor(size_t col,size_t row, Color color)

      assert(row < height && col < width && row >= 0 && col >= 0);
      backgroundColorBuffer.at(row*width + col) = color;

      void setBackgroundColor(size_t col, size_t row, std::vector<std::vector<Color>> box)

      assert(row < height && col < width && row >= 0 && col >= 0);
      for(size_t rowOffset = 0; rowOffset<box.size(); rowOffset++)

      for(size_t colOffset = 0; colOffset<box[rowOffset].size(); colOffset++)

      setBackgroundColor(col+colOffset, row+rowOffset, box[rowOffset][colOffset]);



      char getChar(size_t col, size_t row)

      assert(row < height && col < width && row >= 0 && col >= 0);
      return charBuffer.at(row*width + col);

      Color getTextColor(size_t col, size_t row)

      assert(row < height && col < width && row >= 0 && col >= 0);
      return textColorBuffer.at(row*width + col);

      Color getBackgroundColor(size_t col, size_t row)

      assert(row < height && col < width && row >= 0 && col >= 0);
      return backgroundColorBuffer.at(row*width + col);

      void print()

      static std::thread printerThread;
      if(printerThread.joinable())

      printerThread.join();

      auto printer = [this]()

      std::string output = "";
      for(size_t row = 0; row<height; row++)

      for(size_t col = 0; col<width; col++)

      Color textColor = getTextColor(col, row);
      Color backgroundColor = getBackgroundColor(col, row);
      output += "33[38;2;";
      output += std::to_string((int)textColor.r) + ";";
      output += std::to_string((int)textColor.g) + ";";
      output += std::to_string((int)textColor.b) + "m";
      output += "33[48;2;";
      output += std::to_string((int)backgroundColor.r) + ";";
      output += std::to_string((int)backgroundColor.g) + ";";
      output += std::to_string((int)backgroundColor.b) + "m";
      output += getChar(col, row);

      if(row != height - 1)

      output += "n";


      std::this_thread::sleep_for(std::chrono::milliseconds(frametime));
      std::system("clear");
      std::cout << output << std::flush;
      ;
      printerThread = std::thread(printer);

      ;






      c++ console linux ascii-art






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 6 hours ago









      Darius DuesentriebDarius Duesentrieb

      23017




      23017




















          1 Answer
          1






          active

          oldest

          votes


















          2












          $begingroup$

          • Order your includes at least by portable / non-portable.

          • Not a huge fan of omitting private and putting all the private members up top. IMO a class interface should go from public to private which makes for easier reading as a user.

          • The whole thing is a bit hard to read. Some linebreaks and maybe even spaces would make this easier on the eyes.

          • Is there a reason not to use memset in your clear function?

          • Pedantic people might complain about the missing header for size_t and the missing std:: qualifier.


          • std::string output = ""; initializing strings this way always looks weird to me. std::string s; should suffice but to declare intent more clearly you can do std::string"";. Purely subjective though.

          • Always a good idea to get into the habit of using prefix operator over postfix operator.

          • I do like that you signal intent with flush as opposed to relying on endl

          • Not sure if you use Color elsewhere but it could probably be an implementation detail instead of being free.

          • You explicitly state this is for linux so you probably know that system("clear") is non-portable and are okay with it.





          share|improve this answer









          $endgroup$












          • $begingroup$
            #include <sys/ioctl.h> #include <unistd.h> are the non-portables, right?
            $endgroup$
            – Darius Duesentrieb
            4 hours ago










          • $begingroup$
            @DariusDuesentrieb As far as I can tell, yes.
            $endgroup$
            – yuri
            3 hours ago










          Your Answer





          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "196"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f215519%2flinux-color-ascii-drawing-class%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2












          $begingroup$

          • Order your includes at least by portable / non-portable.

          • Not a huge fan of omitting private and putting all the private members up top. IMO a class interface should go from public to private which makes for easier reading as a user.

          • The whole thing is a bit hard to read. Some linebreaks and maybe even spaces would make this easier on the eyes.

          • Is there a reason not to use memset in your clear function?

          • Pedantic people might complain about the missing header for size_t and the missing std:: qualifier.


          • std::string output = ""; initializing strings this way always looks weird to me. std::string s; should suffice but to declare intent more clearly you can do std::string"";. Purely subjective though.

          • Always a good idea to get into the habit of using prefix operator over postfix operator.

          • I do like that you signal intent with flush as opposed to relying on endl

          • Not sure if you use Color elsewhere but it could probably be an implementation detail instead of being free.

          • You explicitly state this is for linux so you probably know that system("clear") is non-portable and are okay with it.





          share|improve this answer









          $endgroup$












          • $begingroup$
            #include <sys/ioctl.h> #include <unistd.h> are the non-portables, right?
            $endgroup$
            – Darius Duesentrieb
            4 hours ago










          • $begingroup$
            @DariusDuesentrieb As far as I can tell, yes.
            $endgroup$
            – yuri
            3 hours ago















          2












          $begingroup$

          • Order your includes at least by portable / non-portable.

          • Not a huge fan of omitting private and putting all the private members up top. IMO a class interface should go from public to private which makes for easier reading as a user.

          • The whole thing is a bit hard to read. Some linebreaks and maybe even spaces would make this easier on the eyes.

          • Is there a reason not to use memset in your clear function?

          • Pedantic people might complain about the missing header for size_t and the missing std:: qualifier.


          • std::string output = ""; initializing strings this way always looks weird to me. std::string s; should suffice but to declare intent more clearly you can do std::string"";. Purely subjective though.

          • Always a good idea to get into the habit of using prefix operator over postfix operator.

          • I do like that you signal intent with flush as opposed to relying on endl

          • Not sure if you use Color elsewhere but it could probably be an implementation detail instead of being free.

          • You explicitly state this is for linux so you probably know that system("clear") is non-portable and are okay with it.





          share|improve this answer









          $endgroup$












          • $begingroup$
            #include <sys/ioctl.h> #include <unistd.h> are the non-portables, right?
            $endgroup$
            – Darius Duesentrieb
            4 hours ago










          • $begingroup$
            @DariusDuesentrieb As far as I can tell, yes.
            $endgroup$
            – yuri
            3 hours ago













          2












          2








          2





          $begingroup$

          • Order your includes at least by portable / non-portable.

          • Not a huge fan of omitting private and putting all the private members up top. IMO a class interface should go from public to private which makes for easier reading as a user.

          • The whole thing is a bit hard to read. Some linebreaks and maybe even spaces would make this easier on the eyes.

          • Is there a reason not to use memset in your clear function?

          • Pedantic people might complain about the missing header for size_t and the missing std:: qualifier.


          • std::string output = ""; initializing strings this way always looks weird to me. std::string s; should suffice but to declare intent more clearly you can do std::string"";. Purely subjective though.

          • Always a good idea to get into the habit of using prefix operator over postfix operator.

          • I do like that you signal intent with flush as opposed to relying on endl

          • Not sure if you use Color elsewhere but it could probably be an implementation detail instead of being free.

          • You explicitly state this is for linux so you probably know that system("clear") is non-portable and are okay with it.





          share|improve this answer









          $endgroup$



          • Order your includes at least by portable / non-portable.

          • Not a huge fan of omitting private and putting all the private members up top. IMO a class interface should go from public to private which makes for easier reading as a user.

          • The whole thing is a bit hard to read. Some linebreaks and maybe even spaces would make this easier on the eyes.

          • Is there a reason not to use memset in your clear function?

          • Pedantic people might complain about the missing header for size_t and the missing std:: qualifier.


          • std::string output = ""; initializing strings this way always looks weird to me. std::string s; should suffice but to declare intent more clearly you can do std::string"";. Purely subjective though.

          • Always a good idea to get into the habit of using prefix operator over postfix operator.

          • I do like that you signal intent with flush as opposed to relying on endl

          • Not sure if you use Color elsewhere but it could probably be an implementation detail instead of being free.

          • You explicitly state this is for linux so you probably know that system("clear") is non-portable and are okay with it.






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 5 hours ago









          yuriyuri

          3,60921034




          3,60921034











          • $begingroup$
            #include <sys/ioctl.h> #include <unistd.h> are the non-portables, right?
            $endgroup$
            – Darius Duesentrieb
            4 hours ago










          • $begingroup$
            @DariusDuesentrieb As far as I can tell, yes.
            $endgroup$
            – yuri
            3 hours ago
















          • $begingroup$
            #include <sys/ioctl.h> #include <unistd.h> are the non-portables, right?
            $endgroup$
            – Darius Duesentrieb
            4 hours ago










          • $begingroup$
            @DariusDuesentrieb As far as I can tell, yes.
            $endgroup$
            – yuri
            3 hours ago















          $begingroup$
          #include <sys/ioctl.h> #include <unistd.h> are the non-portables, right?
          $endgroup$
          – Darius Duesentrieb
          4 hours ago




          $begingroup$
          #include <sys/ioctl.h> #include <unistd.h> are the non-portables, right?
          $endgroup$
          – Darius Duesentrieb
          4 hours ago












          $begingroup$
          @DariusDuesentrieb As far as I can tell, yes.
          $endgroup$
          – yuri
          3 hours ago




          $begingroup$
          @DariusDuesentrieb As far as I can tell, yes.
          $endgroup$
          – yuri
          3 hours ago

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Code Review Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f215519%2flinux-color-ascii-drawing-class%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          名間水力發電廠 目录 沿革 設施 鄰近設施 註釋 外部連結 导航菜单23°50′10″N 120°42′41″E / 23.83611°N 120.71139°E / 23.83611; 120.7113923°50′10″N 120°42′41″E / 23.83611°N 120.71139°E / 23.83611; 120.71139計畫概要原始内容臺灣第一座BOT 模式開發的水力發電廠-名間水力電廠名間水力發電廠 水利署首件BOT案原始内容《小檔案》名間電廠 首座BOT水力發電廠原始内容名間電廠BOT - 經濟部水利署中區水資源局

          格濟夫卡 參考資料 导航菜单51°3′40″N 34°2′21″E / 51.06111°N 34.03917°E / 51.06111; 34.03917ГезівкаПогода в селі 编辑或修订