poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[COMMITTED] pk-info: do not emit empty tables for computed fields


From: Jose E. Marchesi
Subject: [COMMITTED] pk-info: do not emit empty tables for computed fields
Date: Mon, 30 Jan 2023 01:10:42 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

Installed in both master and maint/poke-3.
Salud!

2023-01-30  Jose E. Marchesi  <jemarch@gnu.org>

        * poke/pk-info.pk (pk_info_type): Do not print a header for
        Computed Fields if there are no computed fields.
---
 ChangeLog       |  5 +++++
 poke/pk-info.pk | 36 ++++++++++++++++++++++++------------
 2 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c7e332c6..06871a37 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2023-01-30  Jose E. Marchesi  <jemarch@gnu.org>
+
+       * poke/pk-info.pk (pk_info_type): Do not print a header for
+       Computed Fields if there are no computed fields.
+
 2023-01-28  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>
 
        * libpoke/std.pk (isdigit): New function.
diff --git a/poke/pk-info.pk b/poke/pk-info.pk
index 8e8a29bf..125be88e 100644
--- a/poke/pk-info.pk
+++ b/poke/pk-info.pk
@@ -118,21 +118,33 @@ fun pk_info_type = (Pk_Type typ) void:
       }
       table.print_table;
 
-      print "Computed Fields:\n";
-      table = Pk_Table { num_columns = 2, indent = 2, max_column_size = 80 };
+      var ncomputedfields = lambda uint<32>:
+        {
+          var n = 0U;
+          for (var i = 0; i < typ.nfields; ++i)
+            if (typ.fcomputed[i])
+              ++n;
+          return n;
+        }();
 
-      table.row ("table-header");
-      table.column ("Name");
-      table.column ("Type");
-      for (var i = 0; i < typ.nfields; ++i)
+      if (ncomputedfields > 0)
       {
-        if (!typ.fcomputed[i])
-          continue;
-        table.row;
-        table.column (typ.fnames[i]);
-        table.column (typ.ftypes[i]);
+        print "Computed Fields:\n";
+        table = Pk_Table { num_columns = 2, indent = 2, max_column_size = 80 };
+
+        table.row ("table-header");
+        table.column ("Name");
+        table.column ("Type");
+        for (var i = 0; i < typ.nfields; ++i)
+        {
+          if (!typ.fcomputed[i])
+            continue;
+          table.row;
+          table.column (typ.fnames[i]);
+          table.column (typ.ftypes[i]);
+        }
+        table.print_table;
       }
-      table.print_table;
     }
 
     if (typ.nmethods > 0)
-- 
2.30.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]