]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- added option to abbreviate columns in table
authorArvin Schnell <aschnell@suse.de>
Thu, 17 Dec 2020 11:25:33 +0000 (12:25 +0100)
committerArvin Schnell <aschnell@suse.de>
Thu, 17 Dec 2020 11:36:52 +0000 (12:36 +0100)
21 files changed:
.github/workflows/ci-debian.yml
.github/workflows/ci-fedora.yml
.github/workflows/ci-ubuntu.yml
VERSION
client/GlobalOptions.cc
client/GlobalOptions.h
client/cmd-list.cc
client/utils/Makefile.am
client/utils/Table.cc
client/utils/Table.h
client/utils/TableFormatter.cc
client/utils/TableFormatter.h
client/utils/console.cc
client/utils/console.h
dists/debian/changelog
dists/debian/snapper-Debian.dsc.in.in
dists/debian/snapper-Raspbian.dsc.in.in
dists/debian/snapper-xUbuntu.dsc.in.in
doc/snapper.xml.in
package/snapper.changes
snapper.spec.in

index ca3f4aff090f92e12a2c6190a354391106cc1518..4282d2d1f718762e6c6209feb17870f02791387d 100644 (file)
@@ -10,7 +10,7 @@ jobs:
     steps:
 
     - name: Install additional packages
-      run: apt-get update && apt-get install -y --no-install-recommends acl-dev autoconf automake bzip2 docbook-xsl e2fslibs-dev g++ gettext libboost-dev libboost-system-dev libboost-test-dev libboost-thread-dev libbtrfs-dev libdbus-1-dev libjson-c-dev libmount-dev libpam-dev libtool libxml2-dev libz-dev locales-all make xsltproc
+      run: apt-get update && apt-get install -y --no-install-recommends acl-dev autoconf automake bzip2 docbook-xsl e2fslibs-dev g++ gettext libboost-dev libboost-system-dev libboost-test-dev libboost-thread-dev libbtrfs-dev libdbus-1-dev libjson-c-dev libmount-dev libpam-dev libtool libxml2-dev libz-dev locales-all make ncurses-dev xsltproc
 
     - name: List installed packages
       run: apt list --installed | sort
index 48996a332ec92fa5feae0c18ac7d0cc6922f34bd..83e59f7c861fb0bc2d93bdc9c3228062924efe9a 100644 (file)
@@ -10,7 +10,7 @@ jobs:
     steps:
 
     - name: Install additional packages
-      run: dnf -y install acl autoconf automake boost-devel btrfs-progs-devel bzip2 dbus-devel diffutils docbook-style-xsl e2fsprogs-devel gcc-c++ gettext glibc-langpack-de glibc-langpack-en json-c-devel libacl-devel libmount-devel libtool libxml2-devel libxslt make pam-devel
+      run: dnf -y install acl autoconf automake boost-devel btrfs-progs-devel bzip2 dbus-devel diffutils docbook-style-xsl e2fsprogs-devel gcc-c++ gettext glibc-langpack-de glibc-langpack-en json-c-devel libacl-devel libmount-devel libtool libxml2-devel libxslt make ncurses-devel pam-devel
 
     - name: List installed packages
       run: rpm -qa | sort
index b89799fc841e91dec24059dd9227a83952d4a99e..a34440e0ae33be2d47bc4fc61f9348682a054d55 100644 (file)
@@ -10,7 +10,7 @@ jobs:
     steps:
 
     - name: Install additional packages
-      run: apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends acl-dev autoconf automake bzip2 docbook-xsl e2fslibs-dev g++ gettext language-pack-de language-pack-en libboost-dev libboost-system-dev libboost-test-dev libboost-thread-dev libbtrfs-dev libdbus-1-dev libjson-c-dev libmount-dev libpam-dev libtool libxml2-dev libz-dev make xsltproc
+      run: apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends acl-dev autoconf automake bzip2 docbook-xsl e2fslibs-dev g++ gettext language-pack-de language-pack-en libboost-dev libboost-system-dev libboost-test-dev libboost-thread-dev libbtrfs-dev libdbus-1-dev libjson-c-dev libmount-dev libpam-dev libtool libxml2-dev libz-dev make ncurses-dev xsltproc
 
     - name: List installed packages
       run: apt list --installed | sort
diff --git a/VERSION b/VERSION
index 832bad274048acaac69e0e57dbcfdcc111572591..7d87d9947c2de74ef8044547b2181e65af943b6e 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.8.14
+0.8.15
index 06239bc93fbb40221b910c0f757fabdb6fdc0d34..a939b12bb94ae77ea3919dfe8a1183f08a16d4cc 100644 (file)
@@ -43,6 +43,7 @@ namespace snapper
            + _("\t--utc\t\t\t\tDisplay dates and times in UTC.") + '\n'
            + _("\t--iso\t\t\t\tDisplay dates and times in ISO format.") + '\n'
            + _("\t--table-style, -t <style>\tTable style (integer).") + '\n'
+           + _("\t--abbreviate\t\t\tAllow to abbreviate table columns.") + '\n'
            + _("\t--machine-readable <format>\tSet a machine-readable output format (csv, json).") + '\n'
            + _("\t--csvout\t\t\tSet CSV output format.") + '\n'
            + _("\t--jsonout\t\t\tSet JSON output format.") + '\n'
@@ -64,6 +65,7 @@ namespace snapper
            Option("utc",               no_argument),
            Option("iso",               no_argument),
            Option("table-style",       required_argument,      't'),
+           Option("abbreviate",        no_argument),
            Option("machine-readable",  required_argument),
            Option("csvout",            no_argument),
            Option("jsonout",           no_argument),
@@ -88,6 +90,7 @@ namespace snapper
        _version = opts.has_option("version");
        _help = opts.has_option("help");
        _table_style = table_style_value(opts);
+       _abbreviate = opts.has_option("abbreviate");
        _output_format = output_format_value(opts);
        _separator = separator_value(opts);
        _config = config_value(opts);
index 9c953dfdb487ef28bbf0251b2bfb12e1ca60ad06..4694dd631a3c91c36bac13fa7cb99d6ae667e31b 100644 (file)
@@ -53,6 +53,7 @@ namespace snapper
        bool version() const { return _version; }
        bool help() const { return _help; }
        TableStyle table_style() const { return _table_style; }
+       bool abbreviate() const { return _abbreviate; }
        OutputFormat output_format() const { return _output_format; }
        string separator() const { return _separator; }
        string config() const { return _config; }
@@ -80,6 +81,7 @@ namespace snapper
        bool _version;
        bool _help;
        TableStyle _table_style;
+       bool _abbreviate;
        OutputFormat _output_format;
        string _separator;
        string _config;
index 9ec872ea80c37cd569f0e17cdb2ee680e44df498..68b32ef8d191d94459225c7cd2b112d9903f308a 100644 (file)
@@ -555,6 +555,8 @@ namespace snapper
                                continue;
 
                            formatter.header().push_back(header_for(list_mode, column));
+                           formatter.abbrev().push_back(global_options.abbreviate() &&
+                                                        column == Column::DESCRIPTION);
                        }
 
                        for (const ProxySnapshot& snapshot : output_helper.snapshots)
index 092b3cfd0734daa69c1a2bfc530a8a23bb707a2d..c55fc4aece2b4adf37cb4d97549e7574390a8f9f 100644 (file)
@@ -18,6 +18,5 @@ libutils_la_SOURCES =                         \
        CsvFormatter.cc     CsvFormatter.h      \
        JsonFormatter.cc    JsonFormatter.h
 
-
-libutils_la_LIBADD = ../../snapper/libsnapper.la
+libutils_la_LIBADD = ../../snapper/libsnapper.la -ltinfo
 
index 7990ae22c770d0a956f051d8b521a1f9a8219778..659dcc0b05c2d01a00a0ded69cb835c6b297d7f3 100644 (file)
@@ -130,7 +130,7 @@ Table::Table()
   , _max_width(1, 0)
   , _width(0)
   , _style (Ascii)
-  , _screen_width(get_screen_width())
+  , _screen_width(snapper::get_screen_width())
   , _margin(0)
   , _force_break_after(-1)
   , _do_wrap(false)
@@ -147,14 +147,14 @@ void Table::setHeader (const TableHeader& tr) {
   updateColWidths (tr);
 }
 
-void Table::allowAbbrev(unsigned column) {
-  if (column >= _abbrev_col.size()) {
-    _abbrev_col.reserve(column + 1);
-    _abbrev_col.insert(_abbrev_col.end(), column - _abbrev_col.size() + 1, false);
-  }
-  _abbrev_col[column] = true;
+
+void
+Table::set_abbrev(const vector<bool>& abbrev)
+{
+    _abbrev_col = abbrev;
 }
 
+
 void Table::updateColWidths (const TableRow& tr) {
   // how much columns the separators add to the width of the table
   int sepwidth = _style == none ? 2 : 3;
index b5e1f12becba946f43ba61530dcf311a47fe21ad..b2beab175c78b02e8e308f1c7ba79bed12c14405 100644 (file)
@@ -111,7 +111,7 @@ public:
 
   void set_style(TableStyle st);
   void wrap(int force_break_after = -1);
-  void allowAbbrev(unsigned column);
+  void set_abbrev(const vector<bool>& abbrev);
   void margin(unsigned margin);
 
   Table ();
@@ -164,7 +164,5 @@ ostream& operator << (ostream& stream, const Table& table) {
   table.dumpTo (stream);
   return stream;
 }
-// Local Variables:
-// c-basic-offset: 2
-// End:
+
 #endif
index b8a756b94dae5137e92d245958fa839af380b3a9..1f61431dd5b755607323bab074a9f82ff83948c0 100644 (file)
@@ -44,6 +44,7 @@ namespace snapper
            table_header.add(column.first, column.second);
 
        table.setHeader(table_header);
+       table.set_abbrev(table_formatter._abbrev);
 
        for (const vector<string>& row : table_formatter._rows)
        {
index c1b13663814d5319e6ae9d8af2d7f167a93dd4fc..cca2e0453436aef4eeae95baad77cac6190688c1 100644 (file)
@@ -50,6 +50,7 @@ namespace snapper
        TableFormatter& operator=(const TableFormatter&) = delete;
 
        vector<pair<string, TableAlign>>& header() { return _header; }
+       vector<bool>& abbrev() { return _abbrev; }
        vector<vector<string>>& rows() { return _rows; }
 
        friend ostream& operator<<(ostream& stream, const TableFormatter& table_formatter);
@@ -59,6 +60,7 @@ namespace snapper
        const TableStyle style;
 
        vector<pair<string, TableAlign>> _header;
+       vector<bool> _abbrev;
        vector<vector<string>> _rows;
 
     };
index 32d42721994d9e6b1cbf79e8057ad3e5d6930abc..c0ef53db73945a1ea596b908d0c6b0198f1f3c9a 100644 (file)
@@ -9,28 +9,56 @@
  * Miscellaneous console utilities.
  */
 
+
+#include <stdlib.h>
 #include <unistd.h>
-#include <string>
-#include <fstream>
-#include <iostream>
-#include <cstdlib>
+#include <term.h>
 
-using namespace std;
 
-unsigned get_screen_width()
+namespace snapper
 {
-  if (!::isatty(STDOUT_FILENO))
-    return -1; // no clipping
 
-  int width = 80;
 
-  const char *cols_env = getenv("COLUMNS");
-  if (cols_env)
-    width  = ::atoi (cols_env);
+    unsigned
+    get_screen_width_pure()
+    {
+       if (!isatty(STDOUT_FILENO))
+           return -1; // no clipping
+
+       int width = 0;
+
+       const char* cols_env = getenv("COLUMNS");
+       if (cols_env)
+       {
+           width = atoi(cols_env);
+       }
+       else
+       {
+           // use terminfo from ncurses
+           setupterm(NULL, STDOUT_FILENO, NULL);
+           width = tigetnum("cols");
+
+           /*
+           // use readline
+           rl_initialize();
+           rl_get_screen_size(NULL, &width);
+           */
+       }
+
+       // safe default
+       if (width <= 0)
+           width = 80;
+
+       return width;
+    }
+
+
+    unsigned
+    get_screen_width()
+    {
+       static unsigned width = get_screen_width_pure();
 
-  // safe default
-  if (!width)
-    width = 80;
+       return width;
+    }
 
-  return width;
 }
index db7dad6650a647939c1339c68266ed8fbc2caa1e..9c01d6340f11af8ff39fe72f8212675e922f1673 100644 (file)
@@ -9,16 +9,23 @@
  * Miscellaneous console utilities.
  */
 
-#ifndef CONSOLE_H_
-#define CONSOLE_H_
-
-/**
- * Reads COLUMNS environment variable or gets the screen width from readline,
- * in that order. Falls back to 80 if all that fails.
- *
- * \NOTE In case stdout is not connected to a terminal max. unsigned
- * is returned. This should prevent clipping when output is redirected.
- */
-unsigned get_screen_width();
+#ifndef SNAPPER_CONSOLE_H
+#define SNAPPER_CONSOLE_H
+
+
+namespace snapper
+{
+
+    /**
+     * Reads COLUMNS environment variable or gets the screen width from terminfo
+     * or readline, in that order. Falls back to 80 if all that fails.
+     *
+     * \NOTE In case stdout is not connected to a terminal max. unsigned
+     * is returned. This should prevent clipping when output is redirected.
+     */
+    unsigned get_screen_width();
+
+}
+
 
-#endif /* CONSOLE_H_ */
+#endif
index 49a5fce709092aed3119d9709b1859d5958eff30..8ed4d52a493ea2c36e81eebd054a14a1154f9076 100644 (file)
@@ -1,3 +1,9 @@
+snapper (0.8.15) stable; urgency=low
+
+  * Updated to version 0.8.15
+
+ -- Arvin Schnell <aschnell@suse.com>  THu, 17 Dec 2020 10:22:04 +0000
+
 snapper (0.8.14) stable; urgency=low
 
   * Updated to version 0.8.14
index 8c52c0e2a31c05a8e4231170157b0af3e9a6541a..9350cbf57f30b1100e362a6dc56fe4431b16bbba 100644 (file)
@@ -4,7 +4,7 @@ Version: @VERSION@-1
 Binary: snapper
 Maintainer: Arvin Schnell <aschnell@suse.com>
 Architecture: any
-Build-Depends: debhelper (>= 4.1.16), acl-dev, dbus, g++, libboost-dev, libboost-thread-dev, libboost-system-dev, libboost-test-dev, libxml2-dev, libz-dev, libdbus-1-dev, libjson-c-dev, libpam-dev, xsltproc, docbook-xsl, locales-all
+Build-Depends: debhelper (>= 4.1.16), acl-dev, dbus, g++, libboost-dev, libboost-thread-dev, libboost-system-dev, libboost-test-dev, libxml2-dev, libz-dev, libdbus-1-dev, libjson-c-dev, libpam-dev, xsltproc, docbook-xsl, locales-all, ncurses-dev
 #
 # The 'Files' line is generated during 'make package':
 # Files:
index 8c52c0e2a31c05a8e4231170157b0af3e9a6541a..9350cbf57f30b1100e362a6dc56fe4431b16bbba 100644 (file)
@@ -4,7 +4,7 @@ Version: @VERSION@-1
 Binary: snapper
 Maintainer: Arvin Schnell <aschnell@suse.com>
 Architecture: any
-Build-Depends: debhelper (>= 4.1.16), acl-dev, dbus, g++, libboost-dev, libboost-thread-dev, libboost-system-dev, libboost-test-dev, libxml2-dev, libz-dev, libdbus-1-dev, libjson-c-dev, libpam-dev, xsltproc, docbook-xsl, locales-all
+Build-Depends: debhelper (>= 4.1.16), acl-dev, dbus, g++, libboost-dev, libboost-thread-dev, libboost-system-dev, libboost-test-dev, libxml2-dev, libz-dev, libdbus-1-dev, libjson-c-dev, libpam-dev, xsltproc, docbook-xsl, locales-all, ncurses-dev
 #
 # The 'Files' line is generated during 'make package':
 # Files:
index b01e8ec0eee8dece74ce27ffd0bd07ddc9f1b4f3..6a25d85c26b0f7cbd05ed910644048acf5659a40 100644 (file)
@@ -4,7 +4,7 @@ Version: @VERSION@-1
 Binary: snapper
 Maintainer: Arvin Schnell <aschnell@suse.com>
 Architecture: any
-Build-Depends: debhelper (>= 4.1.16), acl-dev, dbus, g++, libboost-dev, libboost-thread-dev, libboost-system-dev, libboost-test-dev, libxml2-dev, libz-dev, libdbus-1-dev, libjson-c-dev, libpam-dev, xsltproc, docbook-xsl, language-pack-en, language-pack-de
+Build-Depends: debhelper (>= 4.1.16), acl-dev, dbus, g++, libboost-dev, libboost-thread-dev, libboost-system-dev, libboost-test-dev, libxml2-dev, libz-dev, libdbus-1-dev, libjson-c-dev, libpam-dev, xsltproc, docbook-xsl, language-pack-en, language-pack-de, ncurses-dev
 #
 # The 'Files' line is generated during 'make package':
 # Files:
index 16195fd8c4e1c1ac1357e4e19449ea84550da833..337eae0ad421c29f9176b528372c53198fc688a2 100644 (file)
          <para>Specifies table style. Table style is identified by an integer number.</para>
        </listitem>
       </varlistentry>
+      <varlistentry>
+       <term><option>--abbreviate</option></term>
+       <listitem>
+         <para>Try to abbreviate texts in some columns so that tables fit the width of the screen.</para>
+       </listitem>
+      </varlistentry>
       <varlistentry>
        <term><option>--machine-readable <replaceable>format</replaceable></option></term>
        <listitem>
index 242f7dde91b58819fd6ecf106344ff215d1f5c4e..9235de30f9757654e2a1be5d623e14706deae733 100644 (file)
@@ -1,3 +1,10 @@
+-------------------------------------------------------------------
+Thu Dec 17 12:20:59 CET 2020 - aschnell@suse.com
+
+- added option to abbreviate columns in table (see
+  gh#openSUSE/snapper#268)
+- version 0.8.15
+
 -------------------------------------------------------------------
 Fri Dec 04 10:05:05 CET 2020 - aschnell@suse.com
 
index 20a350188c76f52fcc98fbc8769475d9cf7029da..4e980f2634861e3f96219b188710ed1c6881d01f 100644 (file)
@@ -41,6 +41,7 @@ BuildRequires:  libacl-devel
 BuildRequires:  libtool
 BuildRequires:  libxml2-devel
 BuildRequires:  e2fsprogs-devel
+BuildRequires:  ncurses-devel
 %if 0%{?suse_version} > 1230
 BuildRequires:  libbtrfs-devel
 %endif