+/* Same as statusline_addstr(), but hilight "<str>" sequences if the terminal
+ * supports it */
+static void
+statusline_addhlstr(const char *str)
+{
+#if defined(A_BOLD) && defined(A_NORMAL) && defined(A_DIM)
+ const char *p = str, *start = str;
+ char *tmp;
+ int pos = 0;
+
+ while(1) {
+ if(!*p || strchr("<>", *p)) {
+ if(p - start > 0) {
+ wattrset(bottom, (*p == '>') ? A_BOLD : A_NORMAL);
+ tmp = xstrndup(start, p - start);
+ mvwaddstr(bottom, 1, pos, tmp);
+ free(tmp);
+ pos += p - start;
+ }
+ if(*p) {
+ start = p + 1;
+
+ /* show tag markers */
+ wattrset(bottom, A_DIM);
+ mvwaddch(bottom, 1, pos++, *p);
+ }
+ }
+
+ if(!*p) {
+ wattrset(bottom, A_NORMAL);
+ break;
+ }
+
+ p++;
+ }
+#else
+ mvwaddstr(bottom, 1, 0, str);
+#endif
+
+ refresh();
+ wrefresh(bottom);
+}
+
+int
+statusline_askchoice(const char *msg, const char *choices, short dflt)
+{
+ char *s;
+ int ch;
+
+ assert((dflt < 0) || (dflt > strlen(choices)));
+
+ if(dflt) {
+ s = mkstr("%s [%c]", msg, choices[dflt - 1]);
+ statusline_addhlstr(s);
+ free(s);
+ } else
+ statusline_addhlstr(msg);
+
+ while(1)
+ {
+ ch = tolower(getch());
+
+ if(ch == 7) /* ctrl+G */
+ return 0;
+
+ if(dflt && (ch == '\r')) /* default choice */
+ return dflt;
+
+ if((s = strchr(choices, ch)))
+ return (s - choices + 1);
+ }
+}
+