commit 26237bb9ef919e33f48fac5e43c5e8146fb4e39d
parent 1ad89946404bfd3dd355fd2210c5f6853caeec8e
Author: Claudio Alessi <smoppy@gmail.com>
Date: Thu, 3 Mar 2016 16:40:28 +0100
Add column names.
Also fix a double form creation in mysql_listview().
Diffstat:
2 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/core.c b/core.c
@@ -307,7 +307,10 @@ stfl_putitem(Item *item) {
void
mysql_listview(MYSQL_RES *res) {
+ MYSQL_FIELD *fds;
Item *item;
+ char txt[512];
+ int i, len;
cleanupitems(selview->items);
selview->nitems = mysql_items(res, &selview->items);
@@ -315,12 +318,18 @@ mysql_listview(MYSQL_RES *res) {
if(!selview->form)
selview->form = stfl_create(L"<items.stfl>");
- /* XXX columns row */
+ /* column names */
+ fds = mysql_fetch_fields(res);
+ len = mysql_num_fields(res);
+ txt[0] = '\0';
+ for(i = 0; i < len; ++i) {
+ if(i)
+ strncat(txt, " | ", sizeof txt);
+ strncat(txt, fds[i].name, sizeof txt);
+ }
+ stfl_setf("title", "%s", txt);
stfl_modify(selview->form, L"items", L"replace_inner", L"vbox"); /* clear */
- if(selview->items)
- selview->form = stfl_create(L"<items.stfl>");
-
for(item = selview->items; item; item = item->next)
stfl_putitem(item);
}
diff --git a/items.stfl b/items.stfl
@@ -3,7 +3,7 @@
vbox[main]
label
@style_normal:fg=black,bg=white
- text[ttext]:"The mutt of MySQL - Work in progress..."
+ text[title]:"The mutt of MySQL - Work in progress..."
.expand:h
list[items]
@style_normal:fg=white,bg=black