Browse Source

Add a key to display an entry uri

Thanks to Nick <nick@njw.name> for the suggestion and work he did on it!
master
Quentin Rameau 5 years ago
parent
commit
3eabb27085
  1. 1
      config.def.h
  2. 28
      ui_ti.c
  3. 47
      ui_txt.c

1
config.def.h

@ -9,6 +9,7 @@
#define _key_end 'G' /* move to the bottom of page */
#define _key_pgnext 'l' /* view highlighted item */
#define _key_pgprev 'h' /* view previous item */
#define _key_uri 'u' /* print item uri */
#define _key_fetch 'L' /* refetch current item */
#define _key_help '?' /* display help */
#define _key_quit 'q' /* exit sacc */

28
ui_ti.c

@ -152,6 +152,30 @@ displaystatus(Item *item)
fflush(stdout);
}
static void
displayuri(Item *item)
{
putp(tparm(save_cursor));
putp(tparm(cursor_address, lines-1, 0));
putp(tparm(enter_standout_mode));
switch (item->type) {
case 'i':
break;
case 'h':
printf("%s: %s", item->username, item->selector);
break;
default:
printf("%s: %s:%s%s",
item->username, item->host, item->port, item->selector);
break;
}
putp(tparm(exit_standout_mode));
putp(tparm(restore_cursor));
fflush(stdout);
}
void
uidisplay(Item *entry)
{
@ -377,6 +401,10 @@ uiselectitem(Item *entry)
if (entry->raw)
continue;
return entry;
case _key_uri:
if (dir)
displayuri(dir->items[dir->curline]);
continue;
case _key_help: /* FALLTHROUGH */
return help(entry);
default:

47
ui_txt.c

@ -132,6 +132,24 @@ uidisplay(Item *entry)
fflush(stdout);
}
void
printuri(Item *item, size_t i)
{
if (!item)
return;
switch (item->type) {
case 'i':
break;
case 'h':
printf("%zu: %s: %s\n", i, item->username, item->selector);
break;
default:
printf("%zu: %s: %s:%s%s\n", i, item->username,
item->host, item->port, item->selector);
break;
}
}
Item *
uiselectitem(Item *entry)
{
@ -147,8 +165,7 @@ uiselectitem(Item *entry)
if (!c)
c = 'h';
do {
item = -1;
for (;;) {
printstatus(entry, c);
fflush(stdout);
@ -156,10 +173,21 @@ uiselectitem(Item *entry)
putchar('\n');
return NULL;
}
if (isdigit(*buf))
if (isdigit(*buf)) {
c = '\0';
else if (!strcmp(buf+1, "\n"))
nl = '\0';
if (sscanf(buf, "%d%c", &item, &nl) != 2 || nl != '\n')
item = -1;
} else if (!strcmp(buf+1, "\n")) {
item = -1;
c = *buf;
} else if (isdigit(*(buf+1))) {
nl = '\0';
if (sscanf(buf+1, "%d%c", &item, &nl) != 2 || nl != '\n')
item = -1;
else
c = *buf;
}
switch (c) {
case '\0':
@ -193,6 +221,10 @@ uiselectitem(Item *entry)
if (entry->raw)
continue;
return entry;
case 'u':
if (item > 0 && item <= nitems)
printuri(dir->items[item-1], item);
continue;
case 'h':
case '?':
help();
@ -205,10 +237,9 @@ uiselectitem(Item *entry)
if (*buf < '0' || *buf > '9')
continue;
nl = '\0';
if (sscanf(buf, "%d%c", &item, &nl) != 2 || nl != '\n')
item = -1;
} while (item < 0 || item > nitems);
if (item > 0 && item <= nitems);
break;
}
if (item > 0)
return dir->items[item-1];

Loading…
Cancel
Save