mirror of
https://git.zap.org.au/git/trader.git
synced 2024-12-04 14:46:45 -05:00
Add center3(): centre three strings
This commit is contained in:
parent
885b49f19d
commit
a75ec7479d
67
src/intf.c
67
src/intf.c
@ -404,6 +404,73 @@ int center2 (WINDOW *win, int y, int attr_initial, int attr_string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------
|
||||||
|
Function: center3 - Centre three strings on the current line
|
||||||
|
Arguments: win - Window to use
|
||||||
|
y - Line on which to centre the string
|
||||||
|
attr_initial - Window attribute to use for initial string
|
||||||
|
attr_final - Window attribute to use for final string
|
||||||
|
attr_string - Window attribute to use for main string
|
||||||
|
initial - Fixed initial string
|
||||||
|
final - Fixed final string
|
||||||
|
format - printf()-like format string
|
||||||
|
... - printf()-like arguments
|
||||||
|
Returns: int - Return code from wprintw()
|
||||||
|
|
||||||
|
This function prints three strings in the centre of line y in the
|
||||||
|
window win. The initial string is printed using the window attributes
|
||||||
|
in attr_initial, the main string uses attr_string and the final string
|
||||||
|
uses attr_final. No spaces appear between the three strings. Please
|
||||||
|
note that wrefresh() is NOT called. Also note ordering of parameters!
|
||||||
|
*/
|
||||||
|
|
||||||
|
int center3 (WINDOW *win, int y, int attr_initial, int attr_final,
|
||||||
|
int attr_string, const char *initial, const char *final,
|
||||||
|
const char *format, ...)
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
|
||||||
|
int oldattr;
|
||||||
|
int len1, len2, len3;
|
||||||
|
int ret, x;
|
||||||
|
char *buf;
|
||||||
|
|
||||||
|
|
||||||
|
buf = malloc(BUFSIZE);
|
||||||
|
if (buf == NULL) {
|
||||||
|
err_exit("out of memory");
|
||||||
|
}
|
||||||
|
|
||||||
|
oldattr = getbkgd(win) & ~A_CHARTEXT;
|
||||||
|
wbkgdset(win, A_NORMAL | (oldattr & A_COLOR));
|
||||||
|
|
||||||
|
len1 = strlen(initial);
|
||||||
|
len3 = strlen(final);
|
||||||
|
|
||||||
|
va_start(args, format);
|
||||||
|
len2 = vsnprintf(buf, BUFSIZE, format, args);
|
||||||
|
va_end(args);
|
||||||
|
if (len2 < 0) {
|
||||||
|
free(buf);
|
||||||
|
return ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
x = (getmaxx(win) - (len1 + len2 + len3)) / 2;
|
||||||
|
wattrset(win, attr_initial);
|
||||||
|
mvwprintw(win, y, MAX(x, 2), "%s", initial);
|
||||||
|
wattrset(win, attr_string);
|
||||||
|
ret = wprintw(win, "%1.*s", getmaxx(win) - len1 - len3 - 4, buf);
|
||||||
|
wattrset(win, attr_final);
|
||||||
|
wprintw(win, "%s", final);
|
||||||
|
|
||||||
|
wattrset(win, oldattr);
|
||||||
|
wbkgdset(win, oldattr);
|
||||||
|
|
||||||
|
free(buf);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------
|
/*-----------------------------------------------------------------------
|
||||||
Function: attrpr - Print a string with special attributes
|
Function: attrpr - Print a string with special attributes
|
||||||
Arguments: win - Window to use
|
Arguments: win - Window to use
|
||||||
|
@ -176,6 +176,11 @@ extern int center2 (WINDOW *win, int y, int attr_initial, int attr_string,
|
|||||||
const char *initial, const char *format, ...)
|
const char *initial, const char *format, ...)
|
||||||
__attribute__((format (printf, 6, 7)));
|
__attribute__((format (printf, 6, 7)));
|
||||||
|
|
||||||
|
extern int center3 (WINDOW *win, int y, int attr_initial, int attr_final,
|
||||||
|
int attr_string, const char *initial, const char *final,
|
||||||
|
const char *format, ...)
|
||||||
|
__attribute__((format (printf, 8, 9)));
|
||||||
|
|
||||||
extern int attrpr (WINDOW *win, int attr, const char *format, ...)
|
extern int attrpr (WINDOW *win, int attr, const char *format, ...)
|
||||||
__attribute__((format (printf, 3, 4)));
|
__attribute__((format (printf, 3, 4)));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user