@@ -56,6 +56,22 @@ class ConsoleTable {
5656 }
5757 }
5858
59+ void add_row (const std::vector<TableData::TableCell>& row_data, bool is_full_line) {
60+ data.push_back ({ row_data, is_full_line });
61+
62+ if (is_full_line)
63+ return ;
64+
65+ size_t i = 0 ;
66+ for (const TableData::TableCell& data: row_data) {
67+ if (data.type == TableData::TableCell::String) {
68+ columns_width[i] = std::max (data.s .size () + SPACE_AMOUNT,
69+ columns_width[i]);
70+ }
71+ i++;
72+ }
73+ }
74+
5975 void render () const {
6076 // Some columns headers have been defined, we can create the table normally
6177 if (column_headers.size () > 0 ) {
@@ -69,10 +85,56 @@ class ConsoleTable {
6985
7086 // Render the data
7187 for (size_t i = 0 ; i < data.size (); i++) {
72- std::cout << COLUMN_SEPARATOR;
73- for (size_t j = 0 ; j < data[i].data .size (); j++) {
74- renderCell (data[i].data [j], columns_width[j]);
88+ if (!data[i].is_full_line ) {
7589 std::cout << COLUMN_SEPARATOR;
90+ for (size_t j = 0 ; j < data[i].data .size (); j++) {
91+ renderCell (data[i].data [j], columns_width[j]);
92+ std::cout << COLUMN_SEPARATOR;
93+ }
94+ }
95+ else {
96+ unsigned in_line = 0 ;
97+ bool prepare_new_line = true ;
98+ bool prepare_end_line = false ;
99+ for (size_t j = 0 ; j < data[i].data .size (); j++) {
100+ if (prepare_new_line) {
101+ std::cout << COLUMN_SEPARATOR << " " ;
102+ in_line += 2 ;
103+ prepare_new_line = false ;
104+ }
105+
106+ if (in_line + data[i].data [j].s .size () < total_width - 2 ) {
107+ std::cout << data[i].data [j].s ;
108+ in_line += data[i].data [j].s .size ();
109+ }
110+ else {
111+ std::string substr = data[i].data [j].s .substr (0 , total_width - in_line - 5 );
112+ std::cout << substr << " ..." ;
113+
114+ in_line += substr.size () + 3 ;
115+ prepare_end_line = true ;
116+ }
117+
118+ if (j == data[i].data .size () - 1 ) {
119+ prepare_end_line = true ;
120+ }
121+ else {
122+ in_line += 2 ;
123+ std::cout << " , " ;
124+ }
125+
126+ if (prepare_end_line) {
127+ std::cout << std::string (total_width - in_line, ' ' ) << COLUMN_SEPARATOR;
128+ prepare_end_line = false ;
129+ prepare_new_line = true ;
130+ in_line = 0 ;
131+
132+ // Newline if there are still data to print
133+ if (j < data[i].data .size () - 1 ) {
134+ std::cout << std::endl;
135+ }
136+ }
137+ }
76138 }
77139
78140 if (i < data.size () - 1 || add_final_ls) {
@@ -207,28 +269,16 @@ void print_frame_impl(const CANFrame& frame) {
207269 }
208270}
209271
210- void print_signal_impl (const CANSignal& sig) {
211- std::cout << " SIGNAL[" << sig.name () << " ]: " << std::endl;
212- std::cout << " \t start bit:\t " << sig.start_bit () << std::endl;
213- std::cout << " \t length:\t\t " << sig.length () << std::endl;
214- std::cout << " \t endianness:\t\t " << ((sig.endianness () == CANSignal::BigEndian)
215- ? " BigEndian" : " LittleEndian" ) << std::endl;
216- std::cout << " \t signedness:\t\t " << ((sig.signedness () == CANSignal::Signed)
217- ? " Signed" : " Unsigned" ) << std::endl;
218- std::cout << " \t scale:\t " << sig.scale () << std::endl;
219- std::cout << " \t offset:\t " << sig.offset () << std::endl;
220- std::cout << " \t range:\t " << sig.range ().min << " -> " << sig.range ().max << std::endl;
221-
222-
223- if (sig.choices ().size () > 0 ) {
224- std::cout << " \t choices:" << std::endl;
225-
226- for (const auto & choice: sig.choices ()) {
227- std::string result = " " ;
228- result += std::to_string (choice.first ) + " -> \" " + choice.second + " \" , " ;
229- std::cout << " \t\t " << result << std::endl;
230- }
272+ std::vector<ConsoleTable::TableData::TableCell> createSignalChoicesVector (const CANSignal& sig) {
273+ std::vector<ConsoleTable::TableData::TableCell> result;
274+
275+ for (const auto & choice: sig.choices ()) {
276+ result.push_back (
277+ createStr (std::to_string (choice.first ) + " -> \" " + choice.second + " \" " )
278+ );
231279 }
280+
281+ return result;
232282}
233283
234284void CppCAN::can_parse::print_single_frame (CANDatabase& db, uint32_t can_id) {
@@ -260,6 +310,10 @@ void CppCAN::can_parse::print_single_frame(CANDatabase& db, uint32_t can_id) {
260310 signal.endianness () == CANSignal::BigEndian ? createStr (" BigEndian" ) : createStr (" LittleEndian" ),
261311 createStr (" [" + std::to_string (signal.range ().min ) + " , " + std::to_string (signal.range ().max ) + " ]" )
262312 }, false );
313+
314+ if (signal.choices ().size () > 0 ) {
315+ console_table.add_row (createSignalChoicesVector (signal), true );
316+ }
263317 }
264318
265319 summary_header.render ();
0 commit comments