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
$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);
;
c++ console linux ascii-art
$endgroup$
add a comment |
$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);
;
c++ console linux ascii-art
$endgroup$
add a comment |
$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);
;
c++ console linux ascii-art
$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
c++ console linux ascii-art
asked 6 hours ago
Darius DuesentriebDarius Duesentrieb
23017
23017
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
- Order your includes at least by portable / non-portable.
- Not a huge fan of omitting
privateand putting all the private members up top. IMO a class interface should go frompublictoprivatewhich 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
memsetin your clear function? - Pedantic people might complain about the missing header for
size_tand the missingstd::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 dostd::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
flushas opposed to relying onendl - Not sure if you use
Colorelsewhere 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.
$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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
$begingroup$
- Order your includes at least by portable / non-portable.
- Not a huge fan of omitting
privateand putting all the private members up top. IMO a class interface should go frompublictoprivatewhich 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
memsetin your clear function? - Pedantic people might complain about the missing header for
size_tand the missingstd::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 dostd::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
flushas opposed to relying onendl - Not sure if you use
Colorelsewhere 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.
$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
add a comment |
$begingroup$
- Order your includes at least by portable / non-portable.
- Not a huge fan of omitting
privateand putting all the private members up top. IMO a class interface should go frompublictoprivatewhich 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
memsetin your clear function? - Pedantic people might complain about the missing header for
size_tand the missingstd::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 dostd::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
flushas opposed to relying onendl - Not sure if you use
Colorelsewhere 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.
$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
add a comment |
$begingroup$
- Order your includes at least by portable / non-portable.
- Not a huge fan of omitting
privateand putting all the private members up top. IMO a class interface should go frompublictoprivatewhich 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
memsetin your clear function? - Pedantic people might complain about the missing header for
size_tand the missingstd::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 dostd::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
flushas opposed to relying onendl - Not sure if you use
Colorelsewhere 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.
$endgroup$
- Order your includes at least by portable / non-portable.
- Not a huge fan of omitting
privateand putting all the private members up top. IMO a class interface should go frompublictoprivatewhich 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
memsetin your clear function? - Pedantic people might complain about the missing header for
size_tand the missingstd::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 dostd::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
flushas opposed to relying onendl - Not sure if you use
Colorelsewhere 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.
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
add a comment |
$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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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