File: usage.c

package info (click to toggle)
nrss 0.3.9-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, lenny, squeeze, stretch, wheezy
  • size: 204 kB
  • ctags: 380
  • sloc: ansic: 2,603; makefile: 74
file content (70 lines) | stat: -rw-r--r-- 1,787 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* NRSS - ncurses RSS reader
   Copyright (C) 2007 Jack Miller <jjm2n4@umr.edu>

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License version 2 as 
   published by the Free Software Foundation.
*/
#include "nrss.h"
#include "interface.h"

void usage()
{
    int i = 0;
    int y = 0;
    int bound = NUM_FBINDINGS;
    int len = 0;

    int max = 0;
    int pmax = 0;

    for (i = 0; i < NUM_FBINDINGS; i++) {
        logit("Bind: %d\n", nc->keys[i].bind);
        if(nc->keys[i].bind != 0) {
            len = strlen(nc->keys[i].descr);
            if (len > max)
                max = len;

            len = strlen(nc->keys[i].printable);
            if (len > pmax)
                pmax = len;
        }
        else
            bound--;
    }

    ni->usage = newwin(bound + 2, max + pmax + 5,
                       ni->height - bound - 5,
                       ni->width - (max + pmax + 6));

    wbkgdset(ni->usage, ' ' | COLOR_PAIR(THEME_DEF));
    wattron(ni->usage, COLOR_PAIR(THEME_DEF));
    wclear(ni->usage);

    ni->pusage = new_panel(ni->usage);

    for (i = 0; i < NUM_FBINDINGS; i++) {
        if(nc->keys[i].bind != 0) {
            mvwprintw(ni->usage, y + 1,
                    2 + (pmax - strlen(nc->keys[i].printable)),
                    "%s", nc->keys[i].printable);
            mvwprintw(ni->usage, y + 1, 3 + pmax, "%s", nc->keys[i].descr);
        }
        y++;
    }

    wborder(ni->usage, ACS_VLINE, ACS_VLINE, ACS_HLINE, ACS_HLINE,
            ACS_ULCORNER, ACS_URCORNER, ACS_LLCORNER, ACS_LRCORNER);

    update_panels();
    doupdate();
}

void usage_off()
{
    del_panel(ni->pusage);
    delwin(ni->usage);
    ni->usage = NULL;
    update_panels();
    doupdate();
}