Oh yeah, i promised in the help to use the terminal width by default didnt i

This commit is contained in:
John Sennesael 2022-03-16 18:52:03 -05:00
parent c703a04b67
commit 3b36b76ef6
2 changed files with 13 additions and 3 deletions

View File

@ -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;
}

View File

@ -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;