poke-devel
[Top][All Lists]
Advanced

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

Little project proposal: pk-table


From: Jose E. Marchesi
Subject: Little project proposal: pk-table
Date: Sun, 26 Jul 2020 13:58:43 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

[In case some of you are bored and looking for ideas for a weekend hack
 :)]

Hi people!

In poke we have several commands that emit tabulated data: list of IO
spaces, list of variables, and the like.

Unfortunately, our current approach for this is simplistic and dumb, and
just tries (but not very hard) to keep stuff aligned in the output by
inserting tabs.  Typical sequence of emitting the table header followed
by the data:

  pk_term_class ("table_header");
  pk_puts ("IOS\tName\t\tSource\n");
  pk_term_end_class ("table_header");

  for (...)
    pk_printf ("#%d\t%s\t\t%s\n", ... );

That doesn't work very well :(

So, I propose to add a new little module to poke (not libpoke) called
pk-table, which would be used like this:

  table = pk_table_new ();

  pk_table_header (table, "IOS", NULL);
  pk_table_header (table, "Name", NULL);

  for (...)
  {
    pk_table_row (table, NULL);

    pk_table_column (table, "10", "integer", NULL);
    pk_table_column (table, "<global>", NULL);
    ...
  }

  pk_table_print (table);
  pk_table_free (table);

As you can see, pk-table will collect the data (rows and columns) and
then print them out at `pk_table_print' time.  At that point, it has all
information it needs to format everything nicely (with spaces).

Note how the pk_table_header, pk_table_row and pk_table_column functions
get a variable number of string arguments (finished by NULL) with names
of extra styling classes to apply to their contents, for example:

  pk_table_column (table, "10", "integer", NULL);
                              | list of extra styling classes
                              +------------------------------

pk-table will always use styles like "table_header" and "table_row" and
"table_column", that the user can customize in the poke.css file.

WDYT?



reply via email to

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