Oh yeah, i promised in the help to use the terminal width by default didnt i
This commit is contained in:
parent
c703a04b67
commit
3b36b76ef6
|
@ -24,6 +24,9 @@
|
|||
#include "justifyRight.h"
|
||||
#include "stringHelper.h"
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
@ -31,7 +34,6 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
void usage(const std::string& program)
|
||||
{
|
||||
std::cout << "justify - simple text alignment tool." << std::endl;
|
||||
|
@ -232,9 +234,17 @@ bool justify(const Settings& settings)
|
|||
int main(int argc, char* argv[])
|
||||
{
|
||||
std::vector<std::string> arguments(argv, argv + argc);
|
||||
Settings settings = parseArgs(arguments);
|
||||
Settings settings = parseArgs(arguments);
|
||||
if (settings.error) return 1;
|
||||
if (settings.shouldExit) return 0;
|
||||
if (settings.cols == 0)
|
||||
{
|
||||
// Get terminal width (to use as a default)
|
||||
/// @TODO make sure this works on most unixes
|
||||
winsize termSize;
|
||||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &termSize);
|
||||
settings.cols = termSize.ws_col;
|
||||
}
|
||||
return justify(settings) == true ? 0 : 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ enum class Justification { CENTER, FILL, LEFT, RIGHT };
|
|||
|
||||
struct Settings
|
||||
{
|
||||
size_t cols{80};
|
||||
size_t cols{};
|
||||
bool error{false};
|
||||
bool shouldExit{false};
|
||||
std::string inFile;
|
||||
|
|
Loading…
Reference in New Issue