Prompt support in macros: $[Text].

This commit is contained in:
Felicity Tarnell 2014-03-08 12:54:05 +00:00
parent 0bf6dd5766
commit 0959aad655
2 changed files with 46 additions and 9 deletions

42
tts.c
View file

@ -741,14 +741,46 @@ input_char(win, c)
WINDOW *win;
wchar_t *c;
{
if (macro_pos) {
if (*macro_pos) {
wchar_t *pr, *s, *r;
if (!macro_pos)
return wget_wch(win, c);
if (!*macro_pos) {
input_macro(NULL);
return wget_wch(win, c);
}
if (macro_pos[0] != '$' || macro_pos[1] != '[') {
*c = *macro_pos++;
return 0;
}
free(macro_text);
macro_text = macro_pos = NULL;
}
/* Handle $[prompt string] escapes */
pr = calloc(sizeof(wchar_t), wcslen(macro_pos) - 1);
for (r = pr, s = macro_pos + 2; ; s++) {
if (*s == '\0') {
cmderr(L"Unterminated $[ prompt in macro");
input_macro(NULL);
return wget_wch(win, c);
}
if (*s == ']')
break;
*r++ = *s;
}
s++;
macro_pos = NULL;
r = prompt(pr, NULL, NULL);
free(pr);
pr = calloc(sizeof(wchar_t), wcslen(r) + wcslen(s) + 1);
wcscpy(pr, r);
wcscat(pr, s);
free(macro_text);
macro_text = macro_pos = pr;
*c = *macro_pos++;
return 0;
}

View file

@ -49,7 +49,12 @@ bind k prev
# string which will be executed as if it was typed. For example, the
# following macro would add a new entry called "test", and set its timer to
# 30 minutes.
#macro t "atest\n+30:00\n"
#macro t "atest\n+30m\n"
# Macros can also prompt for input from the user using $[Prompt string]; the
# $[...] will be replaced with the user's input. For example, this macro will
# prompt for the name of a new entry, then set its duration to 30m:
#macro t "a$[Description:]\n+30m\n"
#### Styling
#