1 /* FDUPES Copyright (c) 2018 Adrian Lopez
3 Permission is hereby granted, free of charge, to any person
4 obtaining a copy of this software and associated documentation files
5 (the "Software"), to deal in the Software without restriction,
6 including without limitation the rights to use, copy, modify, merge,
7 publish, distribute, sublicense, and/or sell copies of the Software,
8 and to permit persons to whom the Software is furnished to do so,
9 subject to the following conditions:
11 The above copyright notice and this permission notice shall be
12 included in all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
24 #include "ncurses-print.h"
25 #include "ncurses-status.h"
27 struct status_text *status_text_alloc(struct status_text *status, size_t width)
29 struct status_text *result;
35 result = (struct status_text*) malloc(sizeof(struct status_text));
39 result->left = (wchar_t*) malloc((width+1) * sizeof(wchar_t));
40 if (result->left == 0)
46 result->right = (wchar_t*) malloc((width+1) * sizeof(wchar_t));
47 if (result->right == 0)
54 result->left[0] = '\0';
55 result->right[0] = '\0';
57 result->width = width;
61 if (status->width >= width)
64 newleft = (wchar_t*) realloc(status->left, (width+1) * sizeof(wchar_t));
68 newright = (wchar_t*) realloc(status->right, (width+1) * sizeof(wchar_t));
76 result->left = newleft;
77 result->right = newright;
78 result->width = width;
84 void free_status_text(struct status_text *status)
91 void format_status_left(struct status_text *status, wchar_t *format, ...)
100 size = vwprintflength(format, aq);
102 status_text_alloc(status, size);
104 vswprintf(status->left, status->width + 1, format, ap);
110 void format_status_right(struct status_text *status, wchar_t *format, ...)
116 va_start(ap, format);
119 size = vwprintflength(format, aq);
121 status_text_alloc(status, size);
123 vswprintf(status->right, status->width + 1, format, ap);
129 void print_status(WINDOW *statuswin, struct status_text *status)
136 cols = getmaxx(statuswin);
138 text = (wchar_t*)malloc((cols + 1) * sizeof(wchar_t));
140 l = wcslen(status->left);
141 for (x = 0; x < l && x < cols; ++x)
142 text[x] = status->left[x];
143 for (x = l; x < cols; ++x)
146 l = wcslen(status->right);
147 for (x = cols; x >= 1 && l >= 1; --x, --l)
148 text[x - 1] = status->right[l - 1];
152 mvwaddnwstr(statuswin, 0, 0, text, wcslen(text));