#include <cstring>
#include <cstdlib>
-#include <zypp/base/Logger.h>
+#include <zypp/base/LogTools.h>
+#include <zypp/base/String.h>
+#include <zypp/base/DtorReset.h>
+#include "utils/colors.h"
#include "utils/console.h"
#include "utils/text.h"
+#include "Zypper.h"
#include "Table.h"
// libzypp logger settings
int curpos = parent._margin;
// whether to break the line now in order to wrap it to screen width
bool do_wrap = false;
+ // On a table with 2 edition columns highlight the editions
+ // except for the common prefix.
+ std::string::size_type editionSep( std::string::npos );
+
for (unsigned c = 0; i != e ; ++i, ++c)
{
if (seen_first)
}
else
{
- stream << s;
+ string s(*i);
+ if ( !parent._inHeader && parent.editionStyle( c ) && Zypper::instance()->config().do_colors )
+ {
+ // Edition column
+ if ( parent._editionStyle.size() == 2 )
+ {
+ // 2 Edition columns - highlight difference
+ if ( editionSep == std::string::npos )
+ {
+ editionSep = zypp::str::commonPrefix( _columns[*parent._editionStyle.begin()],
+ _columns[*(++parent._editionStyle.begin())] );
+ }
+
+ if ( editionSep == 0 )
+ {
+ fprint_color( stream, s, COLOR_CONTEXT_HIGHLIGHT );
+ }
+ else if ( editionSep == s.size() )
+ {
+ stream << s;
+ }
+ else
+ {
+ stream << s.substr( 0, editionSep );
+ fprint_color( stream, s.substr( editionSep ), COLOR_CONTEXT_HIGHLIGHT );
+ }
+ }
+ else
+ {
+ // highlight edition-release separator
+ editionSep = s.find( '-' );
+ if ( editionSep != std::string::npos )
+ {
+ stream << s.substr( 0, editionSep );
+ fprint_color( stream, "-", COLOR_CONTEXT_HIGHLIGHT );
+ stream << s.substr( editionSep+1 );
+ }
+ else // no release part
+ {
+ stream << s;
+ }
+ }
+ }
+ else // no special style
+ {
+ stream << s;
+ }
stream.width (parent._max_width[c] - ssize);
}
stream << "";
, _margin(0)
, _force_break_after(-1)
, _do_wrap(false)
+ , _inHeader( false )
{}
void Table::add (const TableRow& tr) {
}
if (_has_header) {
+ zypp::DtorReset inHeader( _inHeader, false );
+ _inHeader = true;
_header.dumpTo (stream, *this);
dumpRule (stream);
}
#include <iosfwd>
#include <list>
#include <vector>
+
using std::string;
using std::ostream;
using std::list;
friend class Table;
};
+/** \relates TableRow */
+inline TableRow & operator<<( TableRow & tr, const string & s )
+{
+ tr.add (s);
+ return tr;
+}
+
class TableHeader : public TableRow {
public:
//! Constructor. Reserve place for c columns.
TableHeader (unsigned c = 0): TableRow (c) {}
};
-inline
-TableRow& operator << (TableRow& tr, const string& s) {
+/** \relates TableHeader */
+inline TableHeader & operator<<( TableHeader & tr, const string & s )
+{
tr.add (s);
return tr;
}
Table ();
+ // poor workaroud missing column styles and table entry objects
+ void setEditionStyle( unsigned column )
+ { _editionStyle.insert( column ); }
+
private:
void dumpRule (ostream &stream) const;
void updateColWidths (const TableRow& tr);
//! Whether to wrap the table if it exceeds _screen_width
bool _do_wrap;
+ mutable bool _inHeader;
+ std::set<unsigned> _editionStyle;
+ bool editionStyle( unsigned column ) const
+ { return _editionStyle.find( column ) != _editionStyle.end(); }
+
friend class TableRow;
};
+namespace table
+{
+ /** TableHeader manipulator */
+ struct EditionStyleSetter
+ {
+ EditionStyleSetter( Table & table_r, const std::string & header_r )
+ : _table( table_r )
+ , _header( header_r )
+ {}
+ Table & _table;
+ std::string _header;
+ };
+
+ /** \relates table::EditionStyleSetter */
+ inline TableHeader & operator<< ( TableHeader & th, const EditionStyleSetter & obj )
+ {
+ obj._table.setEditionStyle( th.cols() );
+ th.add( obj._header );
+ return th;
+ }
+}
+
+
inline
Table& operator << (Table& table, const TableRow& tr) {
table.add (tr);