Skip to content

Commit

Permalink
Merge pull request #100 from edisonhello/upgrade/bump-1.5
Browse files Browse the repository at this point in the history
Bump version to 1.5.0
  • Loading branch information
p-ranav authored Feb 20, 2023
2 parents b5518f4 + 3fcf6fa commit b35db4c
Show file tree
Hide file tree
Showing 16 changed files with 177 additions and 315 deletions.
115 changes: 1 addition & 114 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,117 +1,4 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: false
IndentPPDirectives: None
IndentWidth: 2
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
RawStringFormats:
- Language: TextProto
Delimiters:
- 'pb'
- 'proto'
BasedOnStyle: google
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 8
UseTab: Never
ColumnLimit: 100
...

2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.8)
project(tabulate VERSION 1.4.0 LANGUAGES CXX)
project(tabulate VERSION 1.5.0 LANGUAGES CXX)
option(tabulate_BUILD_TESTS OFF)
option(SAMPLES "Build Samples" OFF)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<a href="https://github.com/p-ranav/tabulate/blob/master/LICENSE">
<img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="license"/>
</a>
<img src="https://img.shields.io/badge/version-1.4-blue.svg?cacheSeconds=2592000" alt="version"/>
<img src="https://img.shields.io/badge/version-1.5-blue.svg?cacheSeconds=2592000" alt="version"/>
</p>

<p align="center">
Expand Down
5 changes: 4 additions & 1 deletion clang-format.bash
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
#!/usr/bin/env bash
find ./include ./samples -type f \( -iname \*.cpp -o -iname \*.hpp \) | xargs clang-format -style="{ColumnLimit : 100}" -i
find ./include ./samples -type f \
\( -iname \*.cpp -o \
\( -iname \*.hpp -a ! -name optional_lite.hpp -a ! -name variant_lite.hpp -a ! -name string_view_lite.hpp \) \) \
| xargs clang-format -style=file -i
2 changes: 2 additions & 0 deletions generate-single-include.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
python3 utils/amalgamate/amalgamate.py -c single_include.json -s .
10 changes: 6 additions & 4 deletions include/tabulate/format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,15 +405,16 @@ class Format {
current_line_length = 0;
}

// If the current word is too long to fit on a line even on it's own then
// split the word up.
// If the current word is too long to fit on a line even on it's own
// then split the word up.
while (get_sequence_length(word, locale, is_multi_byte_character_support_enabled) > width) {
result += word.substr(0, width - 1) + "-";
word = word.substr(width - 1);
result += '\n';
}

// Remove leading whitespace from the word so the new line starts flush to the left.
// Remove leading whitespace from the word so the new line starts flush
// to the left.
word = trim_left(word);
}
result += word;
Expand Down Expand Up @@ -772,7 +773,8 @@ class Format {

std::string word = input.substr(start_index, index - start_index);
char next_character = input.substr(index, 1)[0];
// Unlike whitespace, dashes and the like should stick to the word occurring before it.
// Unlike whitespace, dashes and the like should stick to the word
// occurring before it.
if (isspace(next_character)) {
result.push_back(word);
result.push_back(std::string(1, next_character));
Expand Down
79 changes: 31 additions & 48 deletions include/tabulate/printer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,19 @@ class Printer {

static void print_table(std::ostream &stream, TableInternal &table);

static void
print_row_in_cell(std::ostream &stream, TableInternal &table,
const std::pair<size_t, size_t> &index,
const std::pair<size_t, size_t> &dimension,
size_t num_columns, size_t row_index,
const std::vector<std::string> &splitted_cell_text);
static void print_row_in_cell(std::ostream &stream, TableInternal &table,
const std::pair<size_t, size_t> &index,
const std::pair<size_t, size_t> &dimension, size_t num_columns,
size_t row_index,
const std::vector<std::string> &splitted_cell_text);

static bool print_cell_border_top(std::ostream &stream, TableInternal &table,
const std::pair<size_t, size_t> &index,
const std::pair<size_t, size_t> &dimension,
size_t num_columns);
static bool
print_cell_border_bottom(std::ostream &stream, TableInternal &table,
const std::pair<size_t, size_t> &index,
const std::pair<size_t, size_t> &dimension,
size_t num_columns);
const std::pair<size_t, size_t> &dimension, size_t num_columns);
static bool print_cell_border_bottom(std::ostream &stream, TableInternal &table,
const std::pair<size_t, size_t> &index,
const std::pair<size_t, size_t> &dimension,
size_t num_columns);

static void apply_element_style(std::ostream &stream, Color foreground_color,
Color background_color,
Expand All @@ -72,26 +69,21 @@ class Printer {
apply_font_style(stream, style);
}

static void reset_element_style(std::ostream &stream) {
stream << termcolor::reset;
}
static void reset_element_style(std::ostream &stream) { stream << termcolor::reset; }

private:
static void print_content_left_aligned(std::ostream &stream,
const std::string &cell_content,
const Format &format,
size_t text_with_padding_size,
static void print_content_left_aligned(std::ostream &stream, const std::string &cell_content,
const Format &format, size_t text_with_padding_size,
size_t column_width) {

// Apply font style
apply_element_style(stream, *format.font_color_,
*format.font_background_color_, *format.font_style_);
apply_element_style(stream, *format.font_color_, *format.font_background_color_,
*format.font_style_);
stream << cell_content;
// Only apply font_style to the font
// Not the padding. So calling apply_element_style with font_style = {}
reset_element_style(stream);
apply_element_style(stream, *format.font_color_,
*format.font_background_color_, {});
apply_element_style(stream, *format.font_color_, *format.font_background_color_, {});

if (text_with_padding_size < column_width) {
for (size_t j = 0; j < (column_width - text_with_padding_size); ++j) {
Expand All @@ -100,10 +92,8 @@ class Printer {
}
}

static void print_content_center_aligned(std::ostream &stream,
const std::string &cell_content,
const Format &format,
size_t text_with_padding_size,
static void print_content_center_aligned(std::ostream &stream, const std::string &cell_content,
const Format &format, size_t text_with_padding_size,
size_t column_width) {
auto num_spaces = column_width - text_with_padding_size;
if (num_spaces % 2 == 0) {
Expand All @@ -112,14 +102,13 @@ class Printer {
stream << " ";

// Apply font style
apply_element_style(stream, *format.font_color_,
*format.font_background_color_, *format.font_style_);
apply_element_style(stream, *format.font_color_, *format.font_background_color_,
*format.font_style_);
stream << cell_content;
// Only apply font_style to the font
// Not the padding. So calling apply_element_style with font_style = {}
reset_element_style(stream);
apply_element_style(stream, *format.font_color_,
*format.font_background_color_, {});
apply_element_style(stream, *format.font_color_, *format.font_background_color_, {});

for (size_t j = 0; j < num_spaces / 2; ++j)
stream << " ";
Expand All @@ -129,24 +118,21 @@ class Printer {
stream << " ";

// Apply font style
apply_element_style(stream, *format.font_color_,
*format.font_background_color_, *format.font_style_);
apply_element_style(stream, *format.font_color_, *format.font_background_color_,
*format.font_style_);
stream << cell_content;
// Only apply font_style to the font
// Not the padding. So calling apply_element_style with font_style = {}
reset_element_style(stream);
apply_element_style(stream, *format.font_color_,
*format.font_background_color_, {});
apply_element_style(stream, *format.font_color_, *format.font_background_color_, {});

for (size_t j = 0; j < num_spaces - num_spaces_before; ++j)
stream << " ";
}
}

static void print_content_right_aligned(std::ostream &stream,
const std::string &cell_content,
const Format &format,
size_t text_with_padding_size,
static void print_content_right_aligned(std::ostream &stream, const std::string &cell_content,
const Format &format, size_t text_with_padding_size,
size_t column_width) {
if (text_with_padding_size < column_width) {
for (size_t j = 0; j < (column_width - text_with_padding_size); ++j) {
Expand All @@ -155,14 +141,13 @@ class Printer {
}

// Apply font style
apply_element_style(stream, *format.font_color_,
*format.font_background_color_, *format.font_style_);
apply_element_style(stream, *format.font_color_, *format.font_background_color_,
*format.font_style_);
stream << cell_content;
// Only apply font_style to the font
// Not the padding. So calling apply_element_style with font_style = {}
reset_element_style(stream);
apply_element_style(stream, *format.font_color_,
*format.font_background_color_, {});
apply_element_style(stream, *format.font_color_, *format.font_background_color_, {});
}

static void apply_font_style(std::ostream &stream, FontStyle style) {
Expand Down Expand Up @@ -196,8 +181,7 @@ class Printer {
}
}

static void apply_foreground_color(std::ostream &stream,
Color foreground_color) {
static void apply_foreground_color(std::ostream &stream, Color foreground_color) {
switch (foreground_color) {
case Color::grey:
stream << termcolor::grey;
Expand Down Expand Up @@ -229,8 +213,7 @@ class Printer {
}
}

static void apply_background_color(std::ostream &stream,
Color background_color) {
static void apply_background_color(std::ostream &stream, Color background_color) {
switch (background_color) {
case Color::grey:
stream << termcolor::on_grey;
Expand Down
6 changes: 2 additions & 4 deletions include/tabulate/table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ class Table {
public:
Table() : table_(TableInternal::create()) {}

using Row_t =
std::vector<variant<std::string, const char *, string_view, Table>>;
using Row_t = std::vector<variant<std::string, const char *, string_view, Table>>;

Table &add_row(const Row_t &cells) {

Expand Down Expand Up @@ -123,8 +122,7 @@ class Table {

class RowIterator {
public:
explicit RowIterator(std::vector<std::shared_ptr<Row>>::iterator ptr)
: ptr(ptr) {}
explicit RowIterator(std::vector<std::shared_ptr<Row>>::iterator ptr) : ptr(ptr) {}

RowIterator operator++() {
++ptr;
Expand Down
Loading

0 comments on commit b35db4c

Please sign in to comment.