dattanchu / bprinter Goto Github PK
View Code? Open in Web Editor NEWPretty printer for command line programs
License: MIT License
Pretty printer for command line programs
License: MIT License
This is a great library, thank you. I am having a problem where the rows do not add up to the column header. Here is my code:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <chrono>
#include <cstdio>
#include <thread>
#include "nlohmann/json.hpp"
#include "bprinter/table_printer.h"
#if defined(USE_BOOST_KARMA)
#include <boost/spirit/include/karma.hpp>
namespace karma = boost::spirit::karma;
#endif
using bprinter::TablePrinter;
// #include <BitcarbonConstants.hpp>
using namespace std;
using json = nlohmann::json;
std::string exec(const char* cmd) {
std::array<char, 128> buffer;
std::string result;
std::shared_ptr<FILE> pipe(popen(cmd, "r"), pclose);
if (!pipe) throw std::runtime_error("popen() failed!");
while (!feof(pipe.get())) {
if (fgets(buffer.data(), 128, pipe.get()) != nullptr)
result += buffer.data();
}
return result;
}
int main () {
const std::string CLEOS_OPTS = "";//"-u http://dev.cryptolions.io:38888";
const std::string ACCT_NAME = "eva";
double duration;
auto start = std::chrono::system_clock::now();
srand (time(NULL));
string command = "cleos " + CLEOS_OPTS + " get table -l 1000 " + ACCT_NAME
+ " " + ACCT_NAME + " rides";
cout << command << endl;
string result = exec (command.c_str());
json j = json::parse(result);
json row = j["rows"];
TablePrinter tp(&std::cout);
tp.AddColumn("RideId", 6);
tp.AddColumn("Driver", 10);
tp.AddColumn("Rider", 10);
tp.AddColumn("Dist Chg", 10);
tp.AddColumn("Time Chg", 10);
tp.AddColumn("Tip", 10);
tp.AddColumn("Comm", 10);
tp.AddColumn("World", 10);
tp.AddColumn("Total", 10);
tp.PrintHeader();
int counter = 0;
for (auto el : row) {
// string rideId = ;
// string driver = el["driver"];
// string rider = el["rider"];
tp << el["rideId"] << el["driver"] << el["rider"] << el["dist_charge"]
<< el["time_charge"] << el["tip_charge"]
<< el["comm_charge"] << el["world_charge"]
<< el["total_charge"];
counter++;
}
tp.PrintFooter();
auto end = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_seconds = end-start;
//duration = ( clock() - start ) / (double) CLOCKS_PER_SEC;
cout << "Receipts: " << counter;
cout << "::: Elapsed time: " << elapsed_seconds.count() << "s" << endl;
cout << "; RPS: " << counter / elapsed_seconds.count() << "\n";
return 0;
}
And here is the output. The header is perfect but the rows below do not match up. Any ideas?
thank you
+----------------------------------------------------------------------------------------------+
|RideId| Driver| Rider| Dist Chg| Time Chg| Tip| Comm| World| Total|
+----------------------------------------------------------------------------------------------+
|0|"driver1"|"rider2"|25500|0|28055|1275|1275|5|
|1|"driver3"|"rider1"|21964|2650|34128|4507|4507|500|
|2|"driver1"|"rider1"|25500|0|28055|1275|1275|5|
|3|"driver2"|"rider1"|58392|0|18356|12750|12750|0|
|4|"driver1"|"rider2"|25500|0|28055|1275|1275|5|
|5|"driver2"|"rider1"|25500|53|28112|1277|1277|5|
|6|"driver2"|"rider1"|25500|53|28112|1277|1277|5|
|7|"driver2"|"rider1"|25500|213|28288|1285|1285|5|
|8|"driver2"|"rider1"|25500|160|28231|1283|1283|5|
|9|"driver2"|"rider1"|25500|106|28171|1280|1280|5|
+----------------------------------------------------------------------------------------------+
Receipts: 10::: Elapsed time: 0.0357193s
; RPS: 279.961
Hi
Can you add functionality to remove entries from the table during runtime?
This would make it easier to use it event-based aka adding new entries when data arrives end removing entries from the table when they are not needed anymore
/tmp/ccuGj3Z9.o: In function main': kw.cpp:(.text+0x5d): undefined reference to
bprinter::TablePrinter::TablePrinter(std::ostream*, std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)'
kw.cpp:(.text+0xc2): undefined reference to bprinter::TablePrinter::AddColumn(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)' kw.cpp:(.text+0x127): undefined reference to
bprinter::TablePrinter::AddColumn(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, int)'
kw.cpp:(.text+0x18c): undefined reference to bprinter::TablePrinter::AddColumn(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)' kw.cpp:(.text+0x1f1): undefined reference to
bprinter::TablePrinter::AddColumn(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, int)'
kw.cpp:(.text+0x21b): undefined reference to bprinter::TablePrinter::PrintHeader()' kw.cpp:(.text+0x26b): undefined reference to
bprinter::TablePrinter::operator<<(double)'
kw.cpp:(.text+0x2bb): undefined reference to bprinter::TablePrinter::operator<<(double)' kw.cpp:(.text+0x347): undefined reference to
bprinter::TablePrinter::operator<<(double)'
kw.cpp:(.text+0x397): undefined reference to bprinter::TablePrinter::operator<<(double)' kw.cpp:(.text+0x45f): undefined reference to
bprinter::TablePrinter::operator<<(double)'
/tmp/ccuGj3Z9.o:kw.cpp:(.text+0x50f): more undefined references to bprinter::TablePrinter::operator<<(double)' follow /tmp/ccuGj3Z9.o: In function
main':
kw.cpp:(.text+0x51b): undefined reference to bprinter::TablePrinter::PrintFooter()' kw.cpp:(.text+0x527): undefined reference to
bprinter::TablePrinter::~TablePrinter()'
kw.cpp:(.text+0x624): undefined reference to bprinter::TablePrinter::~TablePrinter()' /tmp/ccuGj3Z9.o: In function
bprinter::TablePrinter& bprinter::TablePrinter::operator<< <char const*>(char const*)':
kw.cpp:(.text.ZN8bprinter12TablePrinterlsIPKcEERS0_T[ZN8bprinter12TablePrinterlsIPKcEERS0_T]+0xc3): undefined reference to bprinter::TablePrinter::get_num_columns() const' /tmp/ccuGj3Z9.o: In function
bprinter::TablePrinter& bprinter::TablePrinter::operator<< (int)':
kw.cpp:(.text.ZN8bprinter12TablePrinterlsIiEERS0_T[ZN8bprinter12TablePrinterlsIiEERS0_T]+0xc0): undefined reference to `bprinter::TablePrinter::get_num_columns() const'
collect2: error: ld returned 1 exit status
kw.txt
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.