libzypp  17.32.4
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-core/base/Gettext.h>
30 #include <zypp/sat/Solvable.h>
31 #include <zypp/ui/Selectable.h>
32 
33 #include <zypp-tui/utils/ansi.h>
34 #include <zypp-tui/utils/colors.h>
35 
36 namespace ztui {
37 
38 inline const char * asYesNo( bool val_r ) { return val_r ? _("Yes") : _("No"); }
39 
41 using SolvableCSI = std::pair<zypp::sat::Solvable, zypp::ui::Selectable::picklist_size_type>;
42 
44 // Custom sort index helpers
45 namespace csidetail
46 {
48  template <typename T>
49  inline int simpleAnyTypeComp ( const boost::any &l_r, const boost::any &r_r )
50  {
51  T l = boost::any_cast<T>(l_r);
52  T r = boost::any_cast<T>(r_r);
53  return ( l < r ? -1 : l > r ? 1 : 0 );
54  }
55 
56  template <>
57  inline int simpleAnyTypeComp<SolvableCSI> ( const boost::any &l_r, const boost::any &r_r )
58  {
59  SolvableCSI l = boost::any_cast<SolvableCSI>(l_r);
60  SolvableCSI r = boost::any_cast<SolvableCSI>(r_r);
61 
62  if ( l.first == r.first )
63  return 0; // quick check Solvable Id
64 
65  int cmp = l.first.name().compare( r.first.name() );
66  if ( cmp )
67  return cmp;
68 
69  cmp = l.first.kind().compare( r.first.kind() );
70  if ( cmp )
71  return cmp;
72 
73  if ( l.second == r.second )
74  return 0;
75  return ( l.second < r.second ? -1 : 1 ); // `>`! best version up
76  }
77 } // namespace csidetail
79 
82  Ascii = 0,
95 };
96 
97 class Table;
98 
100 // Conditional Table column helpers.
101 namespace ctcdetail
102 {
104  template<class Tif_,class Telse_>
105  struct ColumnIf
106  {
107  ColumnIf( bool condition_r, std::function<Tif_()> if_r, std::function<Telse_()> else_r )
108  { if ( condition_r ) _if = std::move(if_r); else _else = std::move(else_r); }
109  std::function<Tif_()> _if;
110  std::function<Telse_()> _else;
111  };
113  template<class Tif_>
114  struct ColumnIf<Tif_,Tif_>
115  {
116  ColumnIf( bool condition_r, std::function<Tif_()> if_r, std::function<Tif_()> else_r )
117  : _ifelse { condition_r ? std::move(if_r) : std::move(else_r) }
118  {}
119  ColumnIf( bool condition_r, std::function<Tif_()> && if_r )
120  { if ( condition_r ) _ifelse = std::move(if_r); }
121  std::function<Tif_()> _ifelse;
122  };
123 }
141 template<class Tif_, class Telse_>
142 auto ColumnIf( bool condition_r, Tif_ && if_r, Telse_ && else_r ) -> ctcdetail::ColumnIf<decltype(if_r()),decltype(else_r())>
143 { return { condition_r, std::forward<Tif_>(if_r), std::forward<Telse_>(else_r) }; }
145 template<class Tif_>
146 auto ColumnIf( bool condition_r, Tif_ && if_r ) -> ctcdetail::ColumnIf<decltype(if_r()),decltype(if_r())>
147 { return { condition_r, std::forward<Tif_>(if_r) }; }
148 
149 
150 namespace table
151 {
158  enum class CStyle
159  {
160  Default = 0,
161  Edition,
162  SortCi,
163  };
164 }
165 
166 
167 class TableRow
168 {
169 private:
170  std::ostream & dumpDetails( std::ostream & stream, const Table & parent ) const;
171 
172 public:
173  struct Less;
174 
177  {}
178 
179  explicit TableRow( unsigned c )
181  { _columns.reserve(c); }
182 
183  explicit TableRow( ColorContext ctxt_r )
184  : _ctxt( ctxt_r )
185  {}
186 
187  TableRow( unsigned c, ColorContext ctxt_r )
188  : _ctxt( ctxt_r )
189  { _columns.reserve(c); }
190 
191  TableRow & add( std::string s );
192 
193  template<class Tp_>
194  TableRow & add( const Tp_ & val_r )
195  { return add( zypp::str::asString( val_r ) ); }
196 
197 
198  TableRow & addDetail( std::string s );
199 
200  template<class Tp_>
201  TableRow & addDetail( const Tp_ & val_r )
202  { return addDetail( zypp::str::asString( val_r ) ); }
203 
204 
205  bool empty() const
206  { return _columns.empty(); }
207 
208  // return number of columns
209  unsigned size() const
210  { return _columns.size(); }
211 
212  unsigned cols() const
213  { return size(); }
214 
216  std::ostream & dumbDumpTo( std::ostream & stream ) const;
218  std::ostream & dumpTo( std::ostream & stream, const Table & parent ) const;
219 
220  using container = std::vector<std::string>;
221 
222  const boost::any &userData() const
223  { return _userData; }
224 
225  void userData( const boost::any &n_r )
226  { _userData = n_r; }
227 
228  // BinaryPredicate
229 
230  const container & columns() const
232 
235 
236  const container & columnsNoTr() const
237  { return _columns; }
238 
240  { return _columns; }
241 
242 protected:
243  bool _translateColumns = false;
244 private:
249  boost::any _userData;
250 };
251 
253 template<class Tp_>
254 TableRow & operator<<( TableRow & tr, Tp_ && val )
255 { return tr.add( zypp::asString( std::forward<Tp_>(val) ) ); }
257 template<class Tp_>
258 TableRow && operator<<( TableRow && tr, Tp_ && val )
259 { return std::move( tr << std::forward<Tp_>(val) ); }
260 
262 template<class Tif_, class Telse_> TableRow & operator<<( TableRow & tr, const ctcdetail::ColumnIf<Tif_,Telse_> & val )
263 { if ( val._if ) tr.add( val._if() ); else if ( val._else ) tr.add( val._else() ); return tr; }
265 template<class Tif_, class Telse_> TableRow & operator<<( TableRow & tr, ctcdetail::ColumnIf<Tif_,Telse_> & val )
266 { if ( val._if ) tr.add( val._if() ); else if ( val._else ) tr.add( val._else() ); return tr; }
268 template<class Tif_, class Telse_> TableRow & operator<<( TableRow & tr, ctcdetail::ColumnIf<Tif_,Telse_> && val )
269 { if ( val._if ) tr.add( val._if() ); else if ( val._else ) tr.add( val._else() ); return tr; }
270 
272 template<class Tif_> TableRow & operator<<( TableRow & tr, const ctcdetail::ColumnIf<Tif_,Tif_> & val )
273 { if ( val._ifelse ) tr.add( val._ifelse() ); return tr; }
275 template<class Tif_> TableRow & operator<<( TableRow & tr, ctcdetail::ColumnIf<Tif_,Tif_> & val )
276 { if ( val._ifelse ) tr.add( val._ifelse() ); return tr; }
278 template<class Tif_> TableRow & operator<<( TableRow & tr, ctcdetail::ColumnIf<Tif_,Tif_> && val )
279 { if ( val._ifelse ) tr.add( val._ifelse() ); return tr; }
280 
281 
282 class TableHeader : public TableRow
283 {
284 public:
287  TableHeader (unsigned c = 0): TableRow (c) { _translateColumns = true; }
288 
289  bool hasStyle( unsigned c, CStyle s ) const
290  { return _cstyle.count(c) && _cstyle.at(c) == s; }
291 
292  CStyle style( unsigned c ) const
293  { return _cstyle.count(c) ? _cstyle.at(c) : CStyle::Default; }
294 
295  void style( unsigned c, CStyle s )
296  { _cstyle[c] = s; }
297 
298 
299  std::set<unsigned> editionColumns() const
300  {
301  std::set<unsigned> ret;
302  for ( const auto & [c,s] : _cstyle ) {
303  if ( s == CStyle::Edition )
304  ret.insert( c );
305  }
306  return ret;
307  }
308 
309 private:
310  std::map<unsigned,CStyle> _cstyle;
311 };
312 
314 template<class Tp_>
315 TableHeader & operator<<( TableHeader & th, Tp_ && val )
316 { static_cast<TableRow&>(th) << std::forward<Tp_>(val); return th; }
318 template<class Tp_>
319 TableHeader && operator<<( TableHeader && th, Tp_ && val )
320 { return std::move( th << std::forward<Tp_>(val) ); }
321 
322 
324 {
325  using SortParam = std::tuple<unsigned,bool>;
326 
327  Less( const TableHeader & header_r, const std::list<unsigned>& by_columns_r )
328  {
329  for ( unsigned curr_column : by_columns_r ) {
330  _by_columns.push_back( SortParam( curr_column, header_r.hasStyle( curr_column, table::CStyle::SortCi ) ) );
331  }
332  }
333 
334  bool operator()( const TableRow & a_r, const TableRow & b_r ) const
335  {
336  int c = 0;
337  for ( const SortParam &sortParam : _by_columns ) {
338  if ( (c = compCol( sortParam, a_r, b_r )) )
339  return c < 0;
340  }
341  return false;
342  }
343 
344 private:
345  int compCol( const SortParam & sortParam_r, const TableRow & a_r, const TableRow & b_r ) const
346  {
347  const auto & [ byColumn, sortCI ] { sortParam_r };
348  bool noL = byColumn >= a_r._columns.size();
349  bool noR = byColumn >= b_r._columns.size();
350 
351  if ( noL || noR ) {
352  if ( noL && noR ) {
354 
355  const boost::any &lUserData = a_r.userData();
356  const boost::any &rUserData = b_r.userData();
357 
358  if ( lUserData.empty() && !rUserData.empty() )
359  return -1;
360 
361  else if ( !lUserData.empty() && rUserData.empty() )
362  return 1;
363 
364  else if ( lUserData.empty() && rUserData.empty() )
365  return 0;
366 
367  else if ( lUserData.type() != rUserData.type() ) {
368  ZYPP_THROW( zypp::Exception( zypp::str::form("Incompatible user types") ) );
369 
370  } else if ( lUserData.type() == typeid(SolvableCSI) ) {
371  return simpleAnyTypeComp<SolvableCSI> ( lUserData, rUserData );
372 
373  } else if ( lUserData.type() == typeid(std::string) ) {
374  return simpleAnyTypeComp<std::string>( lUserData, rUserData );
375 
376  } else if ( lUserData.type() == typeid(unsigned) ) {
377  return simpleAnyTypeComp<unsigned>( lUserData, rUserData );
378 
379  } else if ( lUserData.type() == typeid(int) ) {
380  return simpleAnyTypeComp<int>( lUserData, rUserData );
381 
382  }
383  ZYPP_THROW( zypp::Exception( zypp::str::form("Unsupported user types") ) );
384  } else
385  return ( noL && ! noR ? -1 : ! noL && noR ? 1 : 0);
386  }
387  return defaultStrComp( sortCI, a_r._columns[byColumn], b_r._columns[byColumn] );
388  }
389 
391  static int defaultStrComp( bool ci_r, const std::string & lhs, const std::string & rhs );
392 
393 private:
394  std::list<SortParam> _by_columns;
395 };
396 
398 class Table
399 {
400 public:
401  using container = std::list<TableRow>;
402 
404 
405  Table & add( TableRow tr );
406 
407  Table & setHeader( TableHeader tr );
408 
409 
410  std::ostream & dumpTo( std::ostream & stream ) const;
411  bool empty() const { return _rows.empty(); }
412 
413 
415  static constexpr unsigned Unsorted = unsigned(-1);
417  static constexpr unsigned UserData = unsigned(-2);
418 
420  unsigned defaultSortColumn() const { return _defaultSortColumn; }
421 
423  void defaultSortColumn( unsigned byColumn_r ) { _defaultSortColumn = byColumn_r; }
424 
426  void sort() { sort( unsigned(_defaultSortColumn ) ); }
427 
429  void sort( unsigned byColumn_r ) { if ( byColumn_r != Unsorted ) _rows.sort( TableRow::Less( header(), { byColumn_r } ) ); }
430  void sort( const std::list<unsigned> & byColumns_r ) { if ( byColumns_r.size() ) _rows.sort( TableRow::Less( header(), byColumns_r ) ); }
431  void sort( std::list<unsigned> && byColumns_r ) { if ( byColumns_r.size() ) _rows.sort( TableRow::Less( header(), std::move(byColumns_r) ) ); }
432 
434  template<class TCompare, std::enable_if_t<!std::is_integral_v<TCompare>, int> = 0>
435  void sort( TCompare && less_r ) { _rows.sort( std::forward<TCompare>(less_r) ); }
436 
437  void lineStyle( TableLineStyle st );
438  void wrap( int force_break_after = -1 );
439  void allowAbbrev( unsigned column );
440  void margin( unsigned margin );
441 
442  const TableHeader & header() const
443  { return _header; }
444  const container & rows() const
445  { return _rows; }
447  { return _rows; }
448 
449  Table();
450 
451 private:
452  void dumpRule( std::ostream & stream ) const;
453  void updateColWidths( const TableRow & tr ) const;
454 
458 
460  mutable unsigned _max_col;
462  mutable std::vector<unsigned> _max_width;
464  mutable int _width;
470  std::vector<bool> _abbrev_col;
472  unsigned _margin;
477  bool _do_wrap;
478 
480 
481  mutable bool _inHeader;
482 
483  friend class TableRow;
484 };
485 
486 namespace table
487 {
494  struct Column
495  {
496  Column( std::string header_r, CStyle style_r = CStyle::Default )
497  : _header( std::move(header_r) )
498  , _style( style_r )
499  {}
500  std::string _header;
502  };
504  inline TableHeader & operator<<( TableHeader & th, Column && obj )
505  { th.style( th.cols(), obj._style ); return th << std::move(obj._header); }
507  inline TableHeader && operator<<( TableHeader && th, Column && obj )
508  { return std::move( th << std::move(obj) ); }
509 }
510 
511 
512 inline Table & operator<<( Table & table, TableRow tr )
513 { return table.add( std::move(tr) ); }
514 
515 inline Table & operator<<( Table & table, TableHeader tr )
516 { return table.setHeader( std::move(tr) ); }
517 
518 
519 inline std::ostream & operator<<( std::ostream & stream, const Table & table )
520 { return table.dumpTo( stream ); }
521 
522 
535 {
536 public:
539 
540  static const char * emptyListTag() { return "---"; }
541 
542 public:
544  // Key / Value
545  template <class KeyType>
546  PropertyTable & add( const KeyType & key_r )
547  { _table << ( TableRow() << key_r << "" ); return *this; }
548 
549  template <class KeyType, class ValueType>
550  PropertyTable & add( const KeyType & key_r, const ValueType & val_r )
551  { _table << ( TableRow() << key_r << val_r ); return *this; }
552 
553  template <class KeyType>
554  PropertyTable & add( const KeyType & key_r, bool val_r )
555  { _table << ( TableRow() << key_r << asYesNo( val_r ) ); return *this; }
556 
558  // Key / Value in details (e.g. Description:)
559  template <class ValueType>
560  PropertyTable & addDetail( const ValueType & val_r )
561  { last().addDetail( val_r ); return *this; }
562 
563  template <class KeyType, class ValueType>
564  PropertyTable & addDetail( const KeyType & key_r, const ValueType & val_r )
565  { _table << ( TableRow() << key_r << "" ).addDetail( val_r ); return *this; }
566 
568  // Key / Container<Value>
569  template <class KeyType, class Iterator_ >
570  PropertyTable & add( const KeyType & key_r, Iterator_ begin_r, Iterator_ end_r, bool forceDetails_r = false )
571  {
572  TableRow r;
573  r << key_r;
574  if ( begin_r != end_r )
575  {
576  unsigned cnt = 1;
577  Iterator_ first = begin_r++;
578  if ( begin_r == end_r && ! forceDetails_r )
579  r << *first; // only one value
580  else
581  {
582  r.addDetail( *first ); // list all in details
583  while ( begin_r != end_r )
584  {
585  ++cnt;
586  r.addDetail( *(begin_r++) );
587  }
588  r << "["+zypp::str::numstring(cnt)+"]"; // size as value
589  }
590  }
591  else
592  { r << emptyListTag(); } // dummy to get the ":" if empty
593  _table << r;
594  return *this;
595  }
596 
597  template <class KeyType, class ContainerType>
598  PropertyTable & lst( const KeyType & key_r, const ContainerType & lst_r, bool forceDetails_r = false )
599  { return add( key_r, lst_r.begin(), lst_r.end(), forceDetails_r ); }
600 
601  template <class KeyType, class ValueType>
602  PropertyTable & add( const KeyType & key_r, const std::set<ValueType> & lst_r, bool forceDetails_r = false )
603  { return lst( key_r, lst_r, forceDetails_r ); }
604  template <class KeyType, class ValueType>
605  PropertyTable & add( const KeyType & key_r, const std::list<ValueType> & lst_r, bool forceDetails_r = false )
606  { return lst( key_r, lst_r, forceDetails_r ); }
607  template <class KeyType, class ValueType>
608  PropertyTable & add( const KeyType & key_r, const std::vector<ValueType> & lst_r, bool forceDetails_r = false )
609  { return lst( key_r, lst_r, forceDetails_r ); }
610 
612  // misc
613  PropertyTable & paint( ansi::Color color_r, bool cond_r = true )
614  {
615  if ( cond_r )
616  {
617  // FIXME re-coloring like this works only once
618  std::string & lastval( _table.rows().back().columns().back() );
619  lastval = ColorString( lastval, color_r ).str();
620  }
621  return *this;
622  }
623 
625  { return _table.rows().back(); }
626 
627  std::string & lastKey()
628  { return last().columns()[0]; }
629 
630  std::string & lastValue()
631  { return last().columns()[1]; }
632 
633 public:
634  friend std::ostream & operator << ( std::ostream & str, const PropertyTable & obj )
635  { return str << obj._table; }
636 
637 private:
639 };
640 
641 }
642 
643 // Local Variables:
644 // c-basic-offset: 2
645 // End:
646 #endif
void defaultSortColumn(unsigned byColumn_r)
Set a defaultSortColumn.
Definition: Table.h:423
std::string asString(const Patch::Category &obj)
Definition: Patch.cc:122
TableRow & add(std::string s)
Definition: Table.cc:163
void userData(const boost::any &n_r)
Definition: Table.h:225
TableRow(unsigned c)
Definition: Table.h:179
container _rows
Definition: Table.h:457
std::tuple< unsigned, bool > SortParam
column and sortCI
Definition: Table.h:325
int _width
table width (columns)
Definition: Table.h:464
std::function< Tif_()> _ifelse
Definition: Table.h:121
Aligned key/value with multiline support Key : value 1 LongKey : value 2 Multiline : line 1 line 2 Ne...
Definition: Table.h:534
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:113
std::ostream & dumbDumpTo(std::ostream &stream) const
tab separated output
Definition: Table.cc:178
Colored string if do_colors.
Definition: ansi.h:496
#define _(MSG)
Definition: Gettext.h:37
void margin(unsigned margin)
Definition: Table.cc:454
Table & add(TableRow tr)
Definition: Table.cc:329
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:429
PropertyTable & add(const KeyType &key_r, bool val_r)
Definition: Table.h:554
sentinel
Definition: Table.h:94
bool hasStyle(unsigned c, CStyle s) const
Definition: Table.h:289
PropertyTable & lst(const KeyType &key_r, const ContainerType &lst_r, bool forceDetails_r=false)
Definition: Table.h:598
TableHeader && operator<<(TableHeader &&th, Column &&obj)
Definition: Table.h:507
Column(std::string header_r, CStyle style_r=CStyle::Default)
Definition: Table.h:496
void allowAbbrev(unsigned column)
Definition: Table.cc:342
std::vector< bool > _abbrev_col
whether to abbreviate the respective column if needed
Definition: Table.h:470
PropertyTable & add(const KeyType &key_r, const std::set< ValueType > &lst_r, bool forceDetails_r=false)
Definition: Table.h:602
String related utilities and Regular expression matching.
TableLineStyle
table drawing style
Definition: Table.h:81
TableHeader _header
Definition: Table.h:456
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:394
std::list< TableRow > container
Definition: Table.h:401
bool empty() const
Definition: Table.h:411
const container & rows() const
Definition: Table.h:444
int compCol(const SortParam &sortParam_r, const TableRow &a_r, const TableRow &b_r) const
Definition: Table.h:345
int _screen_width
amount of space we have to print this table
Definition: Table.h:468
PropertyTable & add(const KeyType &key_r, const std::vector< ValueType > &lst_r, bool forceDetails_r=false)
Definition: Table.h:608
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:477
PropertyTable & paint(ansi::Color color_r, bool cond_r=true)
Definition: Table.h:613
int simpleAnyTypeComp(const boost::any &l_r, const boost::any &r_r)
Default comparator for custom sort indices (std::compare semantic).
Definition: Table.h:49
ColorContext
Definition: colors.h:34
TableLineStyle _style
table line drawing style
Definition: Table.h:466
const container & columnsNoTr() const
Definition: Table.h:236
std::map< unsigned, CStyle > _cstyle
Column style and sort hints are remembered here.
Definition: Table.h:310
std::string str() const
Return the colored string if do_colors.
Definition: ansi.h:598
PropertyTable & add(const KeyType &key_r)
Definition: Table.h:546
void sort()
Sort by defaultSortColumn.
Definition: Table.h:426
Table column style setter.
Definition: Table.h:494
std::function< Telse_()> _else
Definition: Table.h:110
std::ostream & dumpTo(std::ostream &stream) const
Definition: Table.cc:403
unsigned defaultSortColumn() const
Get the default sort column or Unsorted (default)
Definition: Table.h:420
const container & columns() const
Definition: Table.h:230
int _force_break_after
if _do_wrap is set, first break the table at this column; If negative, wrap as needed.
Definition: Table.h:475
const boost::any & userData() const
Definition: Table.h:222
TableRow(unsigned c, ColorContext ctxt_r)
Definition: Table.h:187
Various ways to define ansi SGR sequences.
Definition: ansi.h:172
unsigned cols() const
Definition: Table.h:212
std::vector< std::string > container
Definition: Table.h:220
std::string & lastValue()
Definition: Table.h:630
PropertyTable & addDetail(const ValueType &val_r)
Definition: Table.h:560
unsigned _margin
left/right margin in number of spaces
Definition: Table.h:472
bool _translateColumns
Definition: Table.h:243
PropertyTable & addDetail(const KeyType &key_r, const ValueType &val_r)
Definition: Table.h:564
container & columns()
Definition: Table.h:233
container _translatedColumns
Definition: Table.h:246
std::vector< unsigned > _max_width
maximum width of respective columns
Definition: Table.h:462
Table & setHeader(TableHeader tr)
Definition: Table.cc:335
std::ostream & dumpDetails(std::ostream &stream, const Table &parent) const
Definition: Table.cc:192
ColorContext _ctxt
Definition: Table.h:248
void updateColWidths(const TableRow &tr) const
Definition: Table.cc:352
TableRow && operator<<(TableRow &&tr, Tp_ &&val)
Definition: Table.h:258
static const char * emptyListTag()
Definition: Table.h:540
void sort(std::list< unsigned > &&byColumns_r)
Definition: Table.h:431
std::function< Tif_()> _if
Definition: Table.h:109
CStyle
Table column styles.
Definition: Table.h:158
container _details
Definition: Table.h:247
std::ostream & dumpTo(std::ostream &stream, const Table &parent) const
output with parent table attributes
Definition: Table.cc:203
void sort(TCompare &&less_r)
Custom sort.
Definition: Table.h:435
TableHeader(unsigned c=0)
Constructor. Reserve place for c columns.
Definition: Table.h:287
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:249
Editions with v-r setparator highlighted.
void lineStyle(TableLineStyle st)
Definition: Table.cc:448
Less(const TableHeader &header_r, const std::list< unsigned > &by_columns_r)
Definition: Table.h:327
bool operator()(const TableRow &a_r, const TableRow &b_r) const
Definition: Table.h:334
container & columnsNoTr()
Definition: Table.h:239
zypp::DefaultIntegral< unsigned, Unsorted > _defaultSortColumn
Definition: Table.h:479
ColumnIf(bool condition_r, std::function< Tif_()> if_r, std::function< Telse_()> else_r)
Definition: Table.h:107
const TableHeader & header() const
Definition: Table.h:442
PropertyTable & add(const KeyType &key_r, const std::list< ValueType > &lst_r, bool forceDetails_r=false)
Definition: Table.h:605
TableRow()
Binary predicate for sorting.
Definition: Table.h:175
String values to be sorted case insensitive.
bool _inHeader
Definition: Table.h:481
Base class for Exception.
Definition: Exception.h:146
| - +
Definition: Table.h:82
unsigned _max_col
maximum column index seen in this table
Definition: Table.h:460
PropertyTable & add(const KeyType &key_r, const ValueType &val_r)
Definition: Table.h:550
TableRow & addDetail(std::string s)
Definition: Table.cc:171
TableRow(ColorContext ctxt_r)
Definition: Table.h:183
void style(unsigned c, CStyle s)
Definition: Table.h:295
std::string & lastKey()
Definition: Table.h:627
TableHeader & operator<<(TableHeader &th, Column &&obj)
Definition: Table.h:504
TableRow & operator<<(TableRow &tr, Tp_ &&val)
Definition: Table.h:254
unsigned size() const
Definition: Table.h:209
void dumpRule(std::ostream &stream) const
Definition: Table.cc:382
TableRow & add(const Tp_ &val_r)
Definition: Table.h:194
TableRow & addDetail(const Tp_ &val_r)
Definition: Table.h:201
int simpleAnyTypeComp< SolvableCSI >(const boost::any &l_r, const boost::any &r_r)
Definition: Table.h:57
static constexpr unsigned UserData
UserData - sort column using a custom sort index.
Definition: Table.h:417
static constexpr unsigned Unsorted
Unsorted - pseudo sort column indicating not to sort.
Definition: Table.h:415
friend std::ostream & operator<<(std::ostream &str, const PropertyTable &obj)
Definition: Table.h:634
void sort(unsigned byColumn_r)
Sort by byColumn_r.
Definition: Table.h:429
CStyle style(unsigned c) const
Definition: Table.h:292
Remember either _if or _else function.
Definition: Table.h:105
void wrap(int force_break_after=-1)
Definition: Table.cc:441
static TableLineStyle defaultStyle
Definition: Table.h:403
container & rows()
Definition: Table.h:446
TableRow & last()
Definition: Table.h:624
std::set< unsigned > editionColumns() const
Definition: Table.h:299
TableHeader & operator<<(TableHeader &th, Tp_ &&val)
Definition: Table.h:315
ColumnIf(bool condition_r, std::function< Tif_()> if_r, std::function< Tif_()> else_r)
Definition: Table.h:116
container _columns
Definition: Table.h:245
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:41
bool empty() const
Definition: Table.h:205
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:142
std::string _header
Definition: Table.h:500
bool _has_header
Definition: Table.h:455
const char * asYesNo(bool val_r)
Definition: Table.h:38
PropertyTable & add(const KeyType &key_r, Iterator_ begin_r, Iterator_ end_r, bool forceDetails_r=false)
Definition: Table.h:570
ColumnIf(bool condition_r, std::function< Tif_()> &&if_r)
Definition: Table.h:119
void sort(const std::list< unsigned > &byColumns_r)
Definition: Table.h:430