libzypp 17.37.10

Table.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8----------------------------------------------------------------------/
9*
10* This file contains private API, this might break at any time between releases.
11* Strictly for internal use!
12*/
13
14#ifndef ZYPP_TUI_TABULE_H
15#define ZYPP_TUI_TABULE_H
16
17#include <iostream>
18#include <sstream>
19#include <string>
20#include <iosfwd>
21#include <set>
22#include <list>
23#include <vector>
24
25#include <boost/any.hpp>
26
27#include <zypp/base/String.h>
28#include <zypp/base/Exception.h>
29#include <zypp/sat/Solvable.h>
30#include <zypp/ui/Selectable.h>
31
32#include <zypp-tui/utils/ansi.h>
33#include <zypp-tui/utils/colors.h>
34
35 namespace ztui {
36
37 const char * asYesNo( bool val_r );
38
40 using SolvableCSI = std::pair<zypp::sat::Solvable, zypp::ui::Selectable::picklist_size_type>;
41
43// Custom sort index helpers
44 namespace csidetail
45{
47 template <typename T>
48 inline int simpleAnyTypeComp ( const boost::any &l_r, const boost::any &r_r )
49 {
50 T l = boost::any_cast<T>(l_r);
51 T r = boost::any_cast<T>(r_r);
52 return ( l < r ? -1 : l > r ? 1 : 0 );
53 }
54
55 template <>
56 inline int simpleAnyTypeComp<SolvableCSI> ( const boost::any &l_r, const boost::any &r_r )
57 {
58 SolvableCSI l = boost::any_cast<SolvableCSI>(l_r);
59 SolvableCSI r = boost::any_cast<SolvableCSI>(r_r);
60
61 if ( l.first == r.first )
62 return 0; // quick check Solvable Id
63
64 int cmp = l.first.name().compare( r.first.name() );
65 if ( cmp )
66 return cmp;
67
68 cmp = l.first.kind().compare( r.first.kind() );
69 if ( cmp )
70 return cmp;
71
72 if ( l.second == r.second )
73 return 0;
74 return ( l.second < r.second ? -1 : 1 ); // `>`! best version up
75 }
76} // namespace csidetail
77
78
80 enum TableLineStyle {
81 Ascii = 0,
82 Light,
83 Heavy,
84 Double,
85 Light3,
86 Heavy3,
87 LightHeavy,
88 LightDouble,
89 HeavyLight,
90 DoubleLight,
91 Colon,
92 none,
93 TLS_End,
94};
95
96 class Table;
97
99// Conditional Table column helpers.
100 namespace ctcdetail
101{
103 template<class Tif_,class Telse_>
104 struct ColumnIf
105 {
106 ColumnIf( bool condition_r, std::function<Tif_()> if_r, std::function<Telse_()> else_r )
107 { if ( condition_r ) _if = std::move(if_r); else _else = std::move(else_r); }
108 std::function<Tif_()> _if;
109 std::function<Telse_()> _else;
110 };
111
112 template<class Tif_>
113 struct ColumnIf<Tif_,Tif_>
114 {
115 ColumnIf( bool condition_r, std::function<Tif_()> if_r, std::function<Tif_()> else_r )
116 : _ifelse { condition_r ? std::move(if_r) : std::move(else_r) }
117 {}
118 ColumnIf( bool condition_r, std::function<Tif_()> && if_r )
119 { if ( condition_r ) _ifelse = std::move(if_r); }
120 std::function<Tif_()> _ifelse;
121 };
122}
123
140 template<class Tif_, class Telse_>
141 auto ColumnIf( bool condition_r, Tif_ && if_r, Telse_ && else_r ) -> ctcdetail::ColumnIf<decltype(if_r()),decltype(else_r())>
142{ return { condition_r, std::forward<Tif_>(if_r), std::forward<Telse_>(else_r) }; }
143
144 template<class Tif_>
145 auto ColumnIf( bool condition_r, Tif_ && if_r ) -> ctcdetail::ColumnIf<decltype(if_r()),decltype(if_r())>
146{ return { condition_r, std::forward<Tif_>(if_r) }; }
147
148
149 namespace table
150{
157 enum class CStyle
158 {
159 Default = 0,
160 Edition,
161 SortCi,
162 };
163}
164
165
166 class TableRow
167{
168 private:
169 std::ostream & dumpDetails( std::ostream & stream, const Table & parent ) const;
170
171 public:
172 struct Less;
173
174 TableRow()
175 : _ctxt( ColorContext::DEFAULT )
176 {}
177
178 explicit TableRow( unsigned c )
179 : _ctxt( ColorContext::DEFAULT )
180 { _columns.reserve(c); }
181
182 explicit TableRow( ColorContext ctxt_r )
183 : _ctxt( ctxt_r )
184 {}
185
186 TableRow( unsigned c, ColorContext ctxt_r )
187 : _ctxt( ctxt_r )
188 { _columns.reserve(c); }
189
190 TableRow & add( std::string s );
191
192 template<class Tp_>
193 TableRow & add( const Tp_ & val_r )
194 { return add( zypp::str::asString( val_r ) ); }
195
196
197 TableRow & addDetail( std::string s );
198
199 template<class Tp_>
200 TableRow & addDetail( const Tp_ & val_r )
201 { return addDetail( zypp::str::asString( val_r ) ); }
202
203
204 bool empty() const
205 { return _columns.empty(); }
206
207 // return number of columns
208 unsigned size() const
209 { return _columns.size(); }
210
211 unsigned cols() const
212 { return size(); }
213
215 std::ostream & dumbDumpTo( std::ostream & stream ) const;
217 std::ostream & dumpTo( std::ostream & stream, const Table & parent ) const;
218
219 using container = std::vector<std::string>;
220
221 const boost::any &userData() const
222 { return _userData; }
223
224 void userData( const boost::any &n_r )
225 { _userData = n_r; }
226
227 // BinaryPredicate
228
229 const container & columns() const
230 { return _translateColumns ? _translatedColumns : _columns; }
231
232 container & columns()
233 { return _translateColumns ? _translatedColumns : _columns; }
234
235 const container & columnsNoTr() const
236 { return _columns; }
237
238 container & columnsNoTr()
239 { return _columns; }
240
241 protected:
242 bool _translateColumns = false;
243 private:
244 container _columns;
245 container _translatedColumns;
246 container _details;
247 ColorContext _ctxt;
248 boost::any _userData;
249};
250
252 template<class Tp_>
253 TableRow & operator<<( TableRow & tr, Tp_ && val )
254{ return tr.add( zypp::asString( std::forward<Tp_>(val) ) ); }
255
256 template<class Tp_>
257 TableRow && operator<<( TableRow && tr, Tp_ && val )
258{ return std::move( tr << std::forward<Tp_>(val) ); }
259
261 template<class Tif_, class Telse_> TableRow & operator<<( TableRow & tr, const ctcdetail::ColumnIf<Tif_,Telse_> & val )
262{ if ( val._if ) tr.add( val._if() ); else if ( val._else ) tr.add( val._else() ); return tr; }
263
264 template<class Tif_, class Telse_> TableRow & operator<<( TableRow & tr, ctcdetail::ColumnIf<Tif_,Telse_> & val )
265{ if ( val._if ) tr.add( val._if() ); else if ( val._else ) tr.add( val._else() ); return tr; }
266
267 template<class Tif_, class Telse_> TableRow & operator<<( TableRow & tr, ctcdetail::ColumnIf<Tif_,Telse_> && val )
268{ if ( val._if ) tr.add( val._if() ); else if ( val._else ) tr.add( val._else() ); return tr; }
269
271 template<class Tif_> TableRow & operator<<( TableRow & tr, const ctcdetail::ColumnIf<Tif_,Tif_> & val )
272{ if ( val._ifelse ) tr.add( val._ifelse() ); return tr; }
273
274 template<class Tif_> TableRow & operator<<( TableRow & tr, ctcdetail::ColumnIf<Tif_,Tif_> & val )
275{ if ( val._ifelse ) tr.add( val._ifelse() ); return tr; }
276
277 template<class Tif_> TableRow & operator<<( TableRow & tr, ctcdetail::ColumnIf<Tif_,Tif_> && val )
278{ if ( val._ifelse ) tr.add( val._ifelse() ); return tr; }
279
280
281 class TableHeader : public TableRow
282{
283 public:
284 using CStyle = table::CStyle;
286 TableHeader (unsigned c = 0): TableRow (c) { _translateColumns = true; }
287
288 bool hasStyle( unsigned c, CStyle s ) const
289 { return _cstyle.count(c) && _cstyle.at(c) == s; }
290
291 CStyle style( unsigned c ) const
292 { return _cstyle.count(c) ? _cstyle.at(c) : CStyle::Default; }
293
294 void style( unsigned c, CStyle s )
295 { _cstyle[c] = s; }
296
297
298 std::set<unsigned> editionColumns() const
299 {
300 std::set<unsigned> ret;
301 for ( const auto & [c,s] : _cstyle ) {
302 if ( s == CStyle::Edition )
303 ret.insert( c );
304 }
305 return ret;
306 }
307
308 private:
309 std::map<unsigned,CStyle> _cstyle;
310};
311
313 template<class Tp_>
314 TableHeader & operator<<( TableHeader & th, Tp_ && val )
315{ static_cast<TableRow&>(th) << std::forward<Tp_>(val); return th; }
316
317 template<class Tp_>
318 TableHeader && operator<<( TableHeader && th, Tp_ && val )
319{ return std::move( th << std::forward<Tp_>(val) ); }
320
321
322 struct TableRow::Less
323{
324 using SortParam = std::tuple<unsigned,bool>;
325
326 Less( const TableHeader & header_r, const std::list<unsigned>& by_columns_r )
327 {
328 for ( unsigned curr_column : by_columns_r ) {
329 _by_columns.push_back( SortParam( curr_column, header_r.hasStyle( curr_column, table::CStyle::SortCi ) ) );
330 }
331 }
332
333 bool operator()( const TableRow & a_r, const TableRow & b_r ) const
334 {
335 int c = 0;
336 for ( const SortParam &sortParam : _by_columns ) {
337 if ( (c = compCol( sortParam, a_r, b_r )) )
338 return c < 0;
339 }
340 return false;
341 }
342
343 private:
344 int compCol( const SortParam & sortParam_r, const TableRow & a_r, const TableRow & b_r ) const
345 {
346 const auto & [ byColumn, sortCI ] { sortParam_r };
347 bool noL = byColumn >= a_r._columns.size();
348 bool noR = byColumn >= b_r._columns.size();
349
350 if ( noL || noR ) {
351 if ( noL && noR ) {
352 using csidetail::simpleAnyTypeComp;
353
354 const boost::any &lUserData = a_r.userData();
355 const boost::any &rUserData = b_r.userData();
356
357 if ( lUserData.empty() && !rUserData.empty() )
358 return -1;
359
360 else if ( !lUserData.empty() && rUserData.empty() )
361 return 1;
362
363 else if ( lUserData.empty() && rUserData.empty() )
364 return 0;
365
366 else if ( lUserData.type() != rUserData.type() ) {
367 ZYPP_THROW( zypp::Exception( zypp::str::form("Incompatible user types") ) );
368
369 } else if ( lUserData.type() == typeid(SolvableCSI) ) {
370 return simpleAnyTypeComp<SolvableCSI> ( lUserData, rUserData );
371
372 } else if ( lUserData.type() == typeid(std::string) ) {
373 return simpleAnyTypeComp<std::string>( lUserData, rUserData );
374
375 } else if ( lUserData.type() == typeid(unsigned) ) {
376 return simpleAnyTypeComp<unsigned>( lUserData, rUserData );
377
378 } else if ( lUserData.type() == typeid(int) ) {
379 return simpleAnyTypeComp<int>( lUserData, rUserData );
380
381 }
382 ZYPP_THROW( zypp::Exception( zypp::str::form("Unsupported user types") ) );
383 } else
384 return ( noL && ! noR ? -1 : ! noL && noR ? 1 : 0);
385 }
386 return defaultStrComp( sortCI, a_r._columns[byColumn], b_r._columns[byColumn] );
387 }
388
390 static int defaultStrComp( bool ci_r, const std::string & lhs, const std::string & rhs );
391
392 private:
393 std::list<SortParam> _by_columns;
394};
395
397 class Table
398{
399 public:
400 using container = std::list<TableRow>;
401
402 static TableLineStyle defaultStyle;
403
404 Table & add( TableRow tr );
405
406 Table & setHeader( TableHeader tr );
407
408
409 std::ostream & dumpTo( std::ostream & stream ) const;
410 bool empty() const { return _rows.empty(); }
411
412
414 static constexpr unsigned Unsorted = unsigned(-1);
416 static constexpr unsigned UserData = unsigned(-2);
417
419 unsigned defaultSortColumn() const { return _defaultSortColumn; }
420
422 void defaultSortColumn( unsigned byColumn_r ) { _defaultSortColumn = byColumn_r; }
423
425 void sort() { sort( unsigned(_defaultSortColumn ) ); }
426
428 void sort( unsigned byColumn_r ) { if ( byColumn_r != Unsorted ) _rows.sort( TableRow::Less( header(), { byColumn_r } ) ); }
429 void sort( const std::list<unsigned> & byColumns_r ) { if ( byColumns_r.size() ) _rows.sort( TableRow::Less( header(), byColumns_r ) ); }
430 void sort( std::list<unsigned> && byColumns_r ) { if ( byColumns_r.size() ) _rows.sort( TableRow::Less( header(), std::move(byColumns_r) ) ); }
431
433 template<class TCompare, std::enable_if_t<!std::is_integral_v<TCompare>, int> = 0>
434 void sort( TCompare && less_r ) { _rows.sort( std::forward<TCompare>(less_r) ); }
435
436 void lineStyle( TableLineStyle st );
437 void wrap( int force_break_after = -1 );
438 void allowAbbrev( unsigned column );
439 void margin( unsigned margin );
440
441 const TableHeader & header() const
442 { return _header; }
443 const container & rows() const
444 { return _rows; }
445 container & rows()
446 { return _rows; }
447
448 Table();
449
450 private:
451 void dumpRule( std::ostream & stream ) const;
452 void updateColWidths( const TableRow & tr ) const;
453
454 bool _has_header;
455 TableHeader _header;
456 container _rows;
457
459 mutable unsigned _max_col;
461 mutable std::vector<unsigned> _max_width;
463 mutable int _width;
465 TableLineStyle _style;
467 int _screen_width;
469 std::vector<bool> _abbrev_col;
471 unsigned _margin;
474 int _force_break_after;
476 bool _do_wrap;
477
478 zypp::DefaultIntegral<unsigned,Unsorted> _defaultSortColumn;
479
480 mutable bool _inHeader;
481
482 friend class TableRow;
483};
484
485 namespace table
486{
493 struct Column
494 {
495 Column( std::string header_r, CStyle style_r = CStyle::Default )
496 : _header( std::move(header_r) )
497 , _style( style_r )
498 {}
499 std::string _header;
500 CStyle _style;
501 };
502
503 inline TableHeader & operator<<( TableHeader & th, Column && obj )
504 { th.style( th.cols(), obj._style ); return th << std::move(obj._header); }
506 inline TableHeader && operator<<( TableHeader && th, Column && obj )
507 { return std::move( th << std::move(obj) ); }
508}
509
510
511 inline Table & operator<<( Table & table, TableRow tr )
512{ return table.add( std::move(tr) ); }
513
514 inline Table & operator<<( Table & table, TableHeader tr )
515{ return table.setHeader( std::move(tr) ); }
516
517
518 inline std::ostream & operator<<( std::ostream & stream, const Table & table )
519{ return table.dumpTo( stream ); }
520
521
533 class PropertyTable
534{
535 public:
536 PropertyTable()
537 { _table.lineStyle( ztui::Colon ); }
538
539 static const char * emptyListTag() { return "---"; }
540
541 public:
543 // Key / Value
544 template <class KeyType>
545 PropertyTable & add( const KeyType & key_r )
546 { _table << ( TableRow() << key_r << "" ); return *this; }
547
548 template <class KeyType, class ValueType>
549 PropertyTable & add( const KeyType & key_r, const ValueType & val_r )
550 { _table << ( TableRow() << key_r << val_r ); return *this; }
551
552 template <class KeyType>
553 PropertyTable & add( const KeyType & key_r, bool val_r )
554 { _table << ( TableRow() << key_r << asYesNo( val_r ) ); return *this; }
555
557 // Key / Value in details (e.g. Description:)
558 template <class ValueType>
559 PropertyTable & addDetail( const ValueType & val_r )
560 { last().addDetail( val_r ); return *this; }
561
562 template <class KeyType, class ValueType>
563 PropertyTable & addDetail( const KeyType & key_r, const ValueType & val_r )
564 { _table << ( TableRow() << key_r << "" ).addDetail( val_r ); return *this; }
565
567 // Key / Container<Value>
568 template <class KeyType, class Iterator_ >
569 PropertyTable & add( const KeyType & key_r, Iterator_ begin_r, Iterator_ end_r, bool forceDetails_r = false )
570 {
571 TableRow r;
572 r << key_r;
573 if ( begin_r != end_r )
574 {
575 unsigned cnt = 1;
576 Iterator_ first = begin_r++;
577 if ( begin_r == end_r && ! forceDetails_r )
578 r << *first; // only one value
579 else
580 {
581 r.addDetail( *first ); // list all in details
582 while ( begin_r != end_r )
583 {
584 ++cnt;
585 r.addDetail( *(begin_r++) );
586 }
587 r << "["+zypp::str::numstring(cnt)+"]"; // size as value
588 }
589 }
590 else
591 { r << emptyListTag(); } // dummy to get the ":" if empty
592 _table << r;
593 return *this;
594 }
595
596 template <class KeyType, class ContainerType>
597 PropertyTable & lst( const KeyType & key_r, const ContainerType & lst_r, bool forceDetails_r = false )
598 { return add( key_r, lst_r.begin(), lst_r.end(), forceDetails_r ); }
599
600 template <class KeyType, class ValueType>
601 PropertyTable & add( const KeyType & key_r, const std::set<ValueType> & lst_r, bool forceDetails_r = false )
602 { return lst( key_r, lst_r, forceDetails_r ); }
603 template <class KeyType, class ValueType>
604 PropertyTable & add( const KeyType & key_r, const std::list<ValueType> & lst_r, bool forceDetails_r = false )
605 { return lst( key_r, lst_r, forceDetails_r ); }
606 template <class KeyType, class ValueType>
607 PropertyTable & add( const KeyType & key_r, const std::vector<ValueType> & lst_r, bool forceDetails_r = false )
608 { return lst( key_r, lst_r, forceDetails_r ); }
609
611 // misc
612 PropertyTable & paint( ansi::Color color_r, bool cond_r = true )
613 {
614 if ( cond_r )
615 {
616 // FIXME re-coloring like this works only once
617 std::string & lastval( _table.rows().back().columns().back() );
618 lastval = ColorString( lastval, color_r ).str();
619 }
620 return *this;
621 }
622
623 TableRow & last()
624 { return _table.rows().back(); }
625
626 std::string & lastKey()
627 { return last().columns()[0]; }
628
629 std::string & lastValue()
630 { return last().columns()[1]; }
631
632 public:
633 friend std::ostream & operator << ( std::ostream & str, const PropertyTable & obj )
634 { return str << obj._table; }
635
636 private:
637 Table _table;
638};
639
640}
641
642// Local Variables:
643// c-basic-offset: 2
644// End:
645#endif
Selectable.h
Solvable.h
ansi.h
ztui::PropertyTable::add
PropertyTable & add(const KeyType &key_r, const std::set< ValueType > &lst_r, bool forceDetails_r=false)
Definition Table.h:601
ztui::PropertyTable::lastValue
std::string & lastValue()
Definition Table.h:629
ztui::PropertyTable::last
TableRow & last()
Definition Table.h:623
ztui::PropertyTable::lastKey
std::string & lastKey()
Definition Table.h:626
ztui::PropertyTable::_table
Table _table
Definition Table.h:637
ztui::PropertyTable::add
PropertyTable & add(const KeyType &key_r, const ValueType &val_r)
Definition Table.h:549
ztui::PropertyTable::add
PropertyTable & add(const KeyType &key_r, const std::vector< ValueType > &lst_r, bool forceDetails_r=false)
Definition Table.h:607
ztui::PropertyTable::addDetail
PropertyTable & addDetail(const KeyType &key_r, const ValueType &val_r)
Definition Table.h:563
ztui::PropertyTable::add
PropertyTable & add(const KeyType &key_r, Iterator_ begin_r, Iterator_ end_r, bool forceDetails_r=false)
Definition Table.h:569
ztui::PropertyTable::lst
PropertyTable & lst(const KeyType &key_r, const ContainerType &lst_r, bool forceDetails_r=false)
Definition Table.h:597
ztui::PropertyTable::addDetail
PropertyTable & addDetail(const ValueType &val_r)
Definition Table.h:559
ztui::PropertyTable::emptyListTag
static const char * emptyListTag()
Definition Table.h:539
ztui::PropertyTable::operator<<
friend std::ostream & operator<<(std::ostream &str, const PropertyTable &obj)
Definition Table.h:633
ztui::PropertyTable::add
PropertyTable & add(const KeyType &key_r)
Definition Table.h:545
ztui::PropertyTable::PropertyTable
PropertyTable()
Definition Table.h:536
ztui::PropertyTable::add
PropertyTable & add(const KeyType &key_r, bool val_r)
Definition Table.h:553
ztui::PropertyTable::paint
PropertyTable & paint(ansi::Color color_r, bool cond_r=true)
Definition Table.h:612
ztui::PropertyTable::add
PropertyTable & add(const KeyType &key_r, const std::list< ValueType > &lst_r, bool forceDetails_r=false)
Definition Table.h:604
ztui::TableHeader
Definition Table.h:282
ztui::TableHeader::TableHeader
TableHeader(unsigned c=0)
Constructor. Reserve place for c columns.
Definition Table.h:286
ztui::TableHeader::_cstyle
std::map< unsigned, CStyle > _cstyle
Column style and sort hints are remembered here.
Definition Table.h:309
ztui::TableHeader::editionColumns
std::set< unsigned > editionColumns() const
Definition Table.h:298
ztui::TableHeader::CStyle
table::CStyle CStyle
Definition Table.h:284
ztui::TableHeader::hasStyle
bool hasStyle(unsigned c, CStyle s) const
Definition Table.h:288
ztui::TableHeader::style
void style(unsigned c, CStyle s)
Definition Table.h:294
ztui::TableHeader::operator<<
TableHeader & operator<<(TableHeader &th, Tp_ &&val)
Add column.
Definition Table.h:314
ztui::TableHeader::style
CStyle style(unsigned c) const
Definition Table.h:291
ztui::TableRow
Definition Table.h:167
ztui::TableRow::add
TableRow & add(const Tp_ &val_r)
Definition Table.h:193
ztui::TableRow::empty
bool empty() const
Definition Table.h:204
ztui::TableRow::TableRow
TableRow(ColorContext ctxt_r)
Definition Table.h:182
ztui::TableRow::_columns
container _columns
Definition Table.h:244
ztui::TableRow::add
TableRow & add(std::string s)
Definition Table.cc:166
ztui::TableRow::columnsNoTr
container & columnsNoTr()
Definition Table.h:238
ztui::TableRow::_ctxt
ColorContext _ctxt
Definition Table.h:247
ztui::TableRow::_translatedColumns
container _translatedColumns
Definition Table.h:245
ztui::TableRow::cols
unsigned cols() const
Definition Table.h:211
ztui::TableRow::container
std::vector< std::string > container
Definition Table.h:219
ztui::TableRow::columns
container & columns()
Definition Table.h:232
ztui::TableRow::dumpDetails
std::ostream & dumpDetails(std::ostream &stream, const Table &parent) const
Definition Table.cc:195
ztui::TableRow::addDetail
TableRow & addDetail(std::string s)
Definition Table.cc:174
ztui::TableRow::columnsNoTr
const container & columnsNoTr() const
Definition Table.h:235
ztui::TableRow::TableRow
TableRow(unsigned c)
Definition Table.h:178
ztui::TableRow::addDetail
TableRow & addDetail(const Tp_ &val_r)
Definition Table.h:200
ztui::TableRow::_userData
boost::any _userData
user defined sort index, e.g. if string values don't work due to coloring
Definition Table.h:248
ztui::TableRow::TableRow
TableRow(unsigned c, ColorContext ctxt_r)
Definition Table.h:186
ztui::TableRow::operator<<
TableRow & operator<<(TableRow &tr, Tp_ &&val)
Add colummn.
Definition Table.h:253
ztui::TableRow::_details
container _details
Definition Table.h:246
ztui::TableRow::_translateColumns
bool _translateColumns
Definition Table.h:242
ztui::TableRow::dumpTo
std::ostream & dumpTo(std::ostream &stream, const Table &parent) const
output with parent table attributes
Definition Table.cc:206
ztui::TableRow::dumbDumpTo
std::ostream & dumbDumpTo(std::ostream &stream) const
tab separated output
Definition Table.cc:181
ztui::TableRow::size
unsigned size() const
Definition Table.h:208
ztui::TableRow::userData
void userData(const boost::any &n_r)
Definition Table.h:224
ztui::TableRow::userData
const boost::any & userData() const
Definition Table.h:221
ztui::TableRow::TableRow
TableRow()
Binary predicate for sorting.
Definition Table.h:174
ztui::TableRow::columns
const container & columns() const
Definition Table.h:229
ztui::Table
Definition Table.h:398
ztui::Table::sort
void sort(std::list< unsigned > &&byColumns_r)
Definition Table.h:430
ztui::Table::dumpRule
void dumpRule(std::ostream &stream) const
Definition Table.cc:385
ztui::Table::empty
bool empty() const
Definition Table.h:410
ztui::Table::setHeader
Table & setHeader(TableHeader tr)
Definition Table.cc:338
ztui::Table::updateColWidths
void updateColWidths(const TableRow &tr) const
Definition Table.cc:355
ztui::Table::sort
void sort(TCompare &&less_r)
Custom sort.
Definition Table.h:434
ztui::Table::_has_header
bool _has_header
Definition Table.h:454
ztui::Table::container
std::list< TableRow > container
Definition Table.h:400
ztui::Table::rows
const container & rows() const
Definition Table.h:443
ztui::Table::dumpTo
std::ostream & dumpTo(std::ostream &stream) const
Definition Table.cc:406
ztui::Table::_width
int _width
table width (columns)
Definition Table.h:463
ztui::Table::TableRow
friend class TableRow
Definition Table.h:482
ztui::Table::lineStyle
void lineStyle(TableLineStyle st)
Definition Table.cc:451
ztui::Table::wrap
void wrap(int force_break_after=-1)
Definition Table.cc:444
ztui::Table::header
const TableHeader & header() const
Definition Table.h:441
ztui::Table::defaultSortColumn
unsigned defaultSortColumn() const
Get the default sort column or Unsorted (default)
Definition Table.h:419
ztui::Table::_abbrev_col
std::vector< bool > _abbrev_col
whether to abbreviate the respective column if needed
Definition Table.h:469
ztui::Table::_max_width
std::vector< unsigned > _max_width
maximum width of respective columns
Definition Table.h:461
ztui::Table::sort
void sort(const std::list< unsigned > &byColumns_r)
Definition Table.h:429
ztui::Table::_style
TableLineStyle _style
table line drawing style
Definition Table.h:465
ztui::Table::add
Table & add(TableRow tr)
Definition Table.cc:332
ztui::Table::margin
void margin(unsigned margin)
Definition Table.cc:457
ztui::Table::_header
TableHeader _header
Definition Table.h:455
ztui::Table::Unsorted
static constexpr unsigned Unsorted
Unsorted - pseudo sort column indicating not to sort.
Definition Table.h:414
ztui::Table::Table
Table()
Definition Table.cc:319
ztui::Table::defaultSortColumn
void defaultSortColumn(unsigned byColumn_r)
Set a defaultSortColumn.
Definition Table.h:422
ztui::Table::sort
void sort(unsigned byColumn_r)
Sort by byColumn_r.
Definition Table.h:428
ztui::Table::_inHeader
bool _inHeader
Definition Table.h:480
ztui::Table::_screen_width
int _screen_width
amount of space we have to print this table
Definition Table.h:467
ztui::Table::_max_col
unsigned _max_col
maximum column index seen in this table
Definition Table.h:459
ztui::Table::rows
container & rows()
Definition Table.h:445
ztui::Table::_force_break_after
int _force_break_after
Definition Table.h:474
ztui::Table::UserData
static constexpr unsigned UserData
UserData - sort column using a custom sort index.
Definition Table.h:416
ztui::Table::_defaultSortColumn
zypp::DefaultIntegral< unsigned, Unsorted > _defaultSortColumn
Definition Table.h:478
ztui::Table::_margin
unsigned _margin
left/right margin in number of spaces
Definition Table.h:471
ztui::Table::_do_wrap
bool _do_wrap
Whether to wrap the table if it exceeds _screen_width.
Definition Table.h:476
ztui::Table::allowAbbrev
void allowAbbrev(unsigned column)
Definition Table.cc:345
ztui::Table::defaultStyle
static TableLineStyle defaultStyle
Definition Table.h:402
ztui::Table::_rows
container _rows
Definition Table.h:456
ztui::Table::sort
void sort()
Sort by defaultSortColumn.
Definition Table.h:425
ztui::ansi::ColorString
Colored string if do_colors.
Definition ansi.h:497
ztui::ansi::ColorString::str
std::string str() const
Return the colored string if do_colors.
Definition ansi.h:598
ztui::ansi::Color
Various ways to define ansi SGR sequences.
Definition ansi.h:173
zypp::DefaultIntegral
Integral type with defined initial value when default constructed.
Definition defaultintegral.h:42
zypp::Exception
Base class for Exception.
Definition Exception.h:153
colors.h
std
Definition Arch.h:364
str
String related utilities and Regular expression matching.
ztui::csidetail
Definition Table.h:45
ztui::csidetail::simpleAnyTypeComp< SolvableCSI >
int simpleAnyTypeComp< SolvableCSI >(const boost::any &l_r, const boost::any &r_r)
Definition Table.h:56
ztui::csidetail::simpleAnyTypeComp
int simpleAnyTypeComp(const boost::any &l_r, const boost::any &r_r)
Default comparator for custom sort indices (std::compare semantic).
Definition Table.h:48
ztui::ctcdetail
Definition Table.h:101
ztui::table
Definition Table.h:150
ztui::table::CStyle
CStyle
Table column styles.
Definition Table.h:158
ztui::table::CStyle::Edition
@ Edition
Editions with v-r setparator highlighted.
Definition Table.h:160
ztui::table::CStyle::SortCi
@ SortCi
String values to be sorted case insensitive.
Definition Table.h:161
ztui::table::CStyle::Default
@ Default
Definition Table.h:159
ztui
Definition application.cc:13
ztui::asYesNo
const char * asYesNo(bool val_r)
Definition Table.cc:32
ztui::ColumnIf
auto ColumnIf(bool condition_r, Tif_ &&if_r, Telse_ &&else_r) -> ctcdetail::ColumnIf< decltype(if_r()), decltype(else_r())>
Conditional Table column factory.
Definition Table.h:141
ztui::TableLineStyle
TableLineStyle
table drawing style
Definition Table.h:80
ztui::LightDouble
@ LightDouble
Definition Table.h:88
ztui::none
@ none
Definition Table.h:92
ztui::Light
@ Light
Definition Table.h:82
ztui::DoubleLight
@ DoubleLight
Definition Table.h:90
ztui::Ascii
@ Ascii
| - +
Definition Table.h:81
ztui::Heavy3
@ Heavy3
Definition Table.h:86
ztui::Light3
@ Light3
Definition Table.h:85
ztui::Heavy
@ Heavy
Definition Table.h:83
ztui::Double
@ Double
Definition Table.h:84
ztui::HeavyLight
@ HeavyLight
Definition Table.h:89
ztui::LightHeavy
@ LightHeavy
Definition Table.h:87
ztui::TLS_End
@ TLS_End
sentinel
Definition Table.h:93
ztui::Colon
@ Colon
Definition Table.h:91
ztui::SolvableCSI
std::pair< zypp::sat::Solvable, zypp::ui::Selectable::picklist_size_type > SolvableCSI
Custom sort index type for table rows representing solvables (like detailed search results).
Definition Table.h:40
ztui::ColorContext
ColorContext
Definition colors.h:35
ztui::ColorContext::DEFAULT
@ DEFAULT
Definition colors.h:36
zypp::str::numstring
std::string numstring(char n, int w=0)
Definition String.h:290
zypp::str::asString
const std::string & asString(const std::string &t)
Global asString() that works with std::string too.
Definition String.h:140
zypp::str::form
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Definition String.cc:39
zypp::operator<<
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
Definition SerialNumber.cc:52
zypp::asString
std::string asString(const Patch::Category &obj)
Definition Patch.cc:122
ztui::TableRow::Less
Definition Table.h:323
ztui::TableRow::Less::_by_columns
std::list< SortParam > _by_columns
Definition Table.h:393
ztui::TableRow::Less::SortParam
std::tuple< unsigned, bool > SortParam
column and sortCI
Definition Table.h:324
ztui::TableRow::Less::compCol
int compCol(const SortParam &sortParam_r, const TableRow &a_r, const TableRow &b_r) const
Definition Table.h:344
ztui::TableRow::Less::defaultStrComp
static int defaultStrComp(bool ci_r, const std::string &lhs, const std::string &rhs)
Natural('sort -V' like) [case insensitive] compare ignoring ANSI SGR chars.
Definition Table.cc:116
ztui::TableRow::Less::operator()
bool operator()(const TableRow &a_r, const TableRow &b_r) const
Definition Table.h:333
ztui::TableRow::Less::Less
Less(const TableHeader &header_r, const std::list< unsigned > &by_columns_r)
Definition Table.h:326
ztui::ctcdetail::ColumnIf< Tif_, Tif_ >::ColumnIf
ColumnIf(bool condition_r, std::function< Tif_()> if_r, std::function< Tif_()> else_r)
Definition Table.h:115
ztui::ctcdetail::ColumnIf< Tif_, Tif_ >::ColumnIf
ColumnIf(bool condition_r, std::function< Tif_()> &&if_r)
Definition Table.h:118
ztui::ctcdetail::ColumnIf< Tif_, Tif_ >::_ifelse
std::function< Tif_()> _ifelse
Definition Table.h:120
ztui::ctcdetail::ColumnIf
Remember either _if or _else function.
Definition Table.h:105
ztui::ctcdetail::ColumnIf::ColumnIf
ColumnIf(bool condition_r, std::function< Tif_()> if_r, std::function< Telse_()> else_r)
Definition Table.h:106
ztui::ctcdetail::ColumnIf::_else
std::function< Telse_()> _else
Definition Table.h:109
ztui::ctcdetail::ColumnIf::_if
std::function< Tif_()> _if
Definition Table.h:108
ztui::table::Column
Table column style setter.
Definition Table.h:494
ztui::table::Column::_style
CStyle _style
Definition Table.h:500
ztui::table::Column::Column
Column(std::string header_r, CStyle style_r=CStyle::Default)
Definition Table.h:495
ztui::table::Column::_header
std::string _header
Definition Table.h:499
ZYPP_THROW
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition Exception.h:459
Exception.h
String.h