libzypp  17.35.12
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
78 
81  Ascii = 0,
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  };
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 }
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) }; }
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 
176  {}
177 
178  explicit TableRow( unsigned c )
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
231 
234 
235  const container & columnsNoTr() const
236  { return _columns; }
237 
239  { return _columns; }
240 
241 protected:
242  bool _translateColumns = false;
243 private:
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) ) ); }
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; }
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; }
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; }
274 template<class Tif_> TableRow & operator<<( TableRow & tr, ctcdetail::ColumnIf<Tif_,Tif_> & val )
275 { if ( val._ifelse ) tr.add( val._ifelse() ); return tr; }
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:
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; }
317 template<class Tp_>
318 TableHeader && operator<<( TableHeader && th, Tp_ && val )
319 { return std::move( th << std::forward<Tp_>(val) ); }
320 
321 
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 ) {
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 
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; }
446  { return _rows; }
447 
448  Table();
449 
450 private:
451  void dumpRule( std::ostream & stream ) const;
452  void updateColWidths( const TableRow & tr ) const;
453 
457 
459  mutable unsigned _max_col;
461  mutable std::vector<unsigned> _max_width;
463  mutable int _width;
469  std::vector<bool> _abbrev_col;
471  unsigned _margin;
476  bool _do_wrap;
477 
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;
501  };
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 
534 {
535 public:
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 
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:
638 };
639 
640 }
641 
642 // Local Variables:
643 // c-basic-offset: 2
644 // End:
645 #endif
void defaultSortColumn(unsigned byColumn_r)
Set a defaultSortColumn.
Definition: Table.h:422
std::string asString(const Patch::Category &obj)
Definition: Patch.cc:122
TableRow & add(std::string s)
Definition: Table.cc:166
void userData(const boost::any &n_r)
Definition: Table.h:224
TableRow(unsigned c)
Definition: Table.h:178
container _rows
Definition: Table.h:456
std::tuple< unsigned, bool > SortParam
column and sortCI
Definition: Table.h:324
int _width
table width (columns)
Definition: Table.h:463
std::function< Tif_()> _ifelse
Definition: Table.h:120
Aligned key/value with multiline support Key : value 1 LongKey : value 2 Multiline : line 1 line 2 Ne...
Definition: Table.h:533
static int defaultStrComp(bool ci_r, const std::string &lhs, const std::string &rhs)
Natural(&#39;sort -V&#39; like) [case insensitive] compare ignoring ANSI SGR chars.
Definition: Table.cc:116
std::ostream & dumbDumpTo(std::ostream &stream) const
tab separated output
Definition: Table.cc:181
Colored string if do_colors.
Definition: ansi.h:496
void margin(unsigned margin)
Definition: Table.cc:457
Table & add(TableRow tr)
Definition: Table.cc:332
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:424
PropertyTable & add(const KeyType &key_r, bool val_r)
Definition: Table.h:553
sentinel
Definition: Table.h:93
bool hasStyle(unsigned c, CStyle s) const
Definition: Table.h:288
PropertyTable & lst(const KeyType &key_r, const ContainerType &lst_r, bool forceDetails_r=false)
Definition: Table.h:597
TableHeader && operator<<(TableHeader &&th, Column &&obj)
Definition: Table.h:506
Column(std::string header_r, CStyle style_r=CStyle::Default)
Definition: Table.h:495
void allowAbbrev(unsigned column)
Definition: Table.cc:345
std::vector< bool > _abbrev_col
whether to abbreviate the respective column if needed
Definition: Table.h:469
PropertyTable & add(const KeyType &key_r, const std::set< ValueType > &lst_r, bool forceDetails_r=false)
Definition: Table.h:601
String related utilities and Regular expression matching.
TableLineStyle
table drawing style
Definition: Table.h:80
TableHeader _header
Definition: Table.h:455
const std::string & asString(const std::string &t)
Global asString() that works with std::string too.
Definition: String.h:139
Definition: Arch.h:363
std::list< SortParam > _by_columns
Definition: Table.h:393
std::list< TableRow > container
Definition: Table.h:400
bool empty() const
Definition: Table.h:410
const container & rows() const
Definition: Table.h:443
int compCol(const SortParam &sortParam_r, const TableRow &a_r, const TableRow &b_r) const
Definition: Table.h:344
int _screen_width
amount of space we have to print this table
Definition: Table.h:467
PropertyTable & add(const KeyType &key_r, const std::vector< ValueType > &lst_r, bool forceDetails_r=false)
Definition: Table.h:607
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Definition: String.cc:37
bool _do_wrap
Whether to wrap the table if it exceeds _screen_width.
Definition: Table.h:476
PropertyTable & paint(ansi::Color color_r, bool cond_r=true)
Definition: Table.h:612
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
ColorContext
Definition: colors.h:34
TableLineStyle _style
table line drawing style
Definition: Table.h:465
const char * asYesNo(bool val_r)
Definition: Table.cc:32
const container & columnsNoTr() const
Definition: Table.h:235
std::map< unsigned, CStyle > _cstyle
Column style and sort hints are remembered here.
Definition: Table.h:309
std::string str() const
Return the colored string if do_colors.
Definition: ansi.h:598
PropertyTable & add(const KeyType &key_r)
Definition: Table.h:545
void sort()
Sort by defaultSortColumn.
Definition: Table.h:425
Table column style setter.
Definition: Table.h:493
std::function< Telse_()> _else
Definition: Table.h:109
std::ostream & dumpTo(std::ostream &stream) const
Definition: Table.cc:406
unsigned defaultSortColumn() const
Get the default sort column or Unsorted (default)
Definition: Table.h:419
const container & columns() const
Definition: Table.h:229
int _force_break_after
if _do_wrap is set, first break the table at this column; If negative, wrap as needed.
Definition: Table.h:474
const boost::any & userData() const
Definition: Table.h:221
TableRow(unsigned c, ColorContext ctxt_r)
Definition: Table.h:186
Various ways to define ansi SGR sequences.
Definition: ansi.h:172
unsigned cols() const
Definition: Table.h:211
std::vector< std::string > container
Definition: Table.h:219
std::string & lastValue()
Definition: Table.h:629
PropertyTable & addDetail(const ValueType &val_r)
Definition: Table.h:559
unsigned _margin
left/right margin in number of spaces
Definition: Table.h:471
bool _translateColumns
Definition: Table.h:242
PropertyTable & addDetail(const KeyType &key_r, const ValueType &val_r)
Definition: Table.h:563
container & columns()
Definition: Table.h:232
container _translatedColumns
Definition: Table.h:245
std::vector< unsigned > _max_width
maximum width of respective columns
Definition: Table.h:461
Table & setHeader(TableHeader tr)
Definition: Table.cc:338
std::ostream & dumpDetails(std::ostream &stream, const Table &parent) const
Definition: Table.cc:195
ColorContext _ctxt
Definition: Table.h:247
void updateColWidths(const TableRow &tr) const
Definition: Table.cc:355
TableRow && operator<<(TableRow &&tr, Tp_ &&val)
Definition: Table.h:257
static const char * emptyListTag()
Definition: Table.h:539
void sort(std::list< unsigned > &&byColumns_r)
Definition: Table.h:430
std::function< Tif_()> _if
Definition: Table.h:108
CStyle
Table column styles.
Definition: Table.h:157
container _details
Definition: Table.h:246
std::ostream & dumpTo(std::ostream &stream, const Table &parent) const
output with parent table attributes
Definition: Table.cc:206
void sort(TCompare &&less_r)
Custom sort.
Definition: Table.h:434
TableHeader(unsigned c=0)
Constructor. Reserve place for c columns.
Definition: Table.h:286
std::string numstring(char n, int w=0)
Definition: String.h:289
boost::any _userData
user defined sort index, e.g. if string values don&#39;t work due to coloring
Definition: Table.h:248
Editions with v-r setparator highlighted.
void lineStyle(TableLineStyle st)
Definition: Table.cc:451
Less(const TableHeader &header_r, const std::list< unsigned > &by_columns_r)
Definition: Table.h:326
bool operator()(const TableRow &a_r, const TableRow &b_r) const
Definition: Table.h:333
container & columnsNoTr()
Definition: Table.h:238
zypp::DefaultIntegral< unsigned, Unsorted > _defaultSortColumn
Definition: Table.h:478
ColumnIf(bool condition_r, std::function< Tif_()> if_r, std::function< Telse_()> else_r)
Definition: Table.h:106
const TableHeader & header() const
Definition: Table.h:441
PropertyTable & add(const KeyType &key_r, const std::list< ValueType > &lst_r, bool forceDetails_r=false)
Definition: Table.h:604
TableRow()
Binary predicate for sorting.
Definition: Table.h:174
String values to be sorted case insensitive.
bool _inHeader
Definition: Table.h:480
Base class for Exception.
Definition: Exception.h:146
| - +
Definition: Table.h:81
unsigned _max_col
maximum column index seen in this table
Definition: Table.h:459
PropertyTable & add(const KeyType &key_r, const ValueType &val_r)
Definition: Table.h:549
TableRow & addDetail(std::string s)
Definition: Table.cc:174
TableRow(ColorContext ctxt_r)
Definition: Table.h:182
void style(unsigned c, CStyle s)
Definition: Table.h:294
std::string & lastKey()
Definition: Table.h:626
TableHeader & operator<<(TableHeader &th, Column &&obj)
Definition: Table.h:503
TableRow & operator<<(TableRow &tr, Tp_ &&val)
Definition: Table.h:253
unsigned size() const
Definition: Table.h:208
void dumpRule(std::ostream &stream) const
Definition: Table.cc:385
TableRow & add(const Tp_ &val_r)
Definition: Table.h:193
TableRow & addDetail(const Tp_ &val_r)
Definition: Table.h:200
int simpleAnyTypeComp< SolvableCSI >(const boost::any &l_r, const boost::any &r_r)
Definition: Table.h:56
static constexpr unsigned UserData
UserData - sort column using a custom sort index.
Definition: Table.h:416
static constexpr unsigned Unsorted
Unsorted - pseudo sort column indicating not to sort.
Definition: Table.h:414
friend std::ostream & operator<<(std::ostream &str, const PropertyTable &obj)
Definition: Table.h:633
void sort(unsigned byColumn_r)
Sort by byColumn_r.
Definition: Table.h:428
CStyle style(unsigned c) const
Definition: Table.h:291
Remember either _if or _else function.
Definition: Table.h:104
void wrap(int force_break_after=-1)
Definition: Table.cc:444
static TableLineStyle defaultStyle
Definition: Table.h:402
container & rows()
Definition: Table.h:445
TableRow & last()
Definition: Table.h:623
std::set< unsigned > editionColumns() const
Definition: Table.h:298
TableHeader & operator<<(TableHeader &th, Tp_ &&val)
Definition: Table.h:314
ColumnIf(bool condition_r, std::function< Tif_()> if_r, std::function< Tif_()> else_r)
Definition: Table.h:115
container _columns
Definition: Table.h:244
std::pair< zypp::sat::Solvable, zypp::ui::Selectable::picklist_size_type > SolvableCSI
_("Yes") or _("No")
Definition: Table.h:40
bool empty() const
Definition: Table.h:204
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
std::string _header
Definition: Table.h:499
bool _has_header
Definition: Table.h:454
PropertyTable & add(const KeyType &key_r, Iterator_ begin_r, Iterator_ end_r, bool forceDetails_r=false)
Definition: Table.h:569
ColumnIf(bool condition_r, std::function< Tif_()> &&if_r)
Definition: Table.h:118
void sort(const std::list< unsigned > &byColumns_r)
Definition: Table.h:429