mirror of
https://github.com/Zygo/bees.git
synced 2025-06-15 17:26:15 +02:00
table: add a simple text table renderer
This should help clean up some of the uglier status outputs. Supports: * multi-line table cells * character fills * sparse tables * insert, delete by row and column * vertical separators and not much else. Signed-off-by: Zygo Blaxell <bees@furryterror.org>
This commit is contained in:
@ -8,6 +8,7 @@ PROGRAMS = \
|
||||
process \
|
||||
progress \
|
||||
seeker \
|
||||
table \
|
||||
task \
|
||||
|
||||
all: test
|
||||
|
63
test/table.cc
Normal file
63
test/table.cc
Normal file
@ -0,0 +1,63 @@
|
||||
#include "tests.h"
|
||||
|
||||
#include "crucible/table.h"
|
||||
|
||||
using namespace crucible;
|
||||
using namespace std;
|
||||
|
||||
void
|
||||
print_table(const Table::Table& t)
|
||||
{
|
||||
cerr << "BEGIN TABLE\n";
|
||||
cerr << t;
|
||||
cerr << "END TABLE\n";
|
||||
cerr << endl;
|
||||
}
|
||||
|
||||
void
|
||||
test_table()
|
||||
{
|
||||
Table::Table t;
|
||||
t.insert_row(Table::endpos, vector<Table::Content> {
|
||||
Table::Text("Hello, World!"),
|
||||
Table::Text("2"),
|
||||
Table::Text("3"),
|
||||
Table::Text("4"),
|
||||
});
|
||||
print_table(t);
|
||||
t.insert_row(Table::endpos, vector<Table::Content> {
|
||||
Table::Text("Greeting"),
|
||||
Table::Text("two"),
|
||||
Table::Text("three"),
|
||||
Table::Text("four"),
|
||||
});
|
||||
print_table(t);
|
||||
t.insert_row(Table::endpos, vector<Table::Content> {
|
||||
Table::Fill('-'),
|
||||
Table::Text("ii"),
|
||||
Table::Text("iii"),
|
||||
Table::Text("iv"),
|
||||
});
|
||||
print_table(t);
|
||||
t.mid(" | ");
|
||||
t.left("| ");
|
||||
t.right(" |");
|
||||
print_table(t);
|
||||
t.insert_col(1, vector<Table::Content> {
|
||||
Table::Text("1"),
|
||||
Table::Text("one"),
|
||||
Table::Text("i"),
|
||||
Table::Text("I"),
|
||||
});
|
||||
print_table(t);
|
||||
t.at(2, 1) = Table::Text("Two\nLines");
|
||||
print_table(t);
|
||||
}
|
||||
|
||||
int
|
||||
main(int, char**)
|
||||
{
|
||||
RUN_A_TEST(test_table());
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
Reference in New Issue
Block a user