Add linux-next specific files for 20110831
[linux-2.6/next.git] / tools / perf / util / ui / progress.c
blobd7fc399d36b30767ac5d1495597c0c8d9ec05d46
1 #include <stdlib.h>
2 #include <newt.h>
3 #include "../cache.h"
4 #include "progress.h"
6 struct ui_progress {
7 newtComponent form, scale;
8 };
10 struct ui_progress *ui_progress__new(const char *title, u64 total)
12 struct ui_progress *self = malloc(sizeof(*self));
14 if (self != NULL) {
15 int cols;
17 if (use_browser <= 0)
18 return self;
19 newtGetScreenSize(&cols, NULL);
20 cols -= 4;
21 newtCenteredWindow(cols, 1, title);
22 self->form = newtForm(NULL, NULL, 0);
23 if (self->form == NULL)
24 goto out_free_self;
25 self->scale = newtScale(0, 0, cols, total);
26 if (self->scale == NULL)
27 goto out_free_form;
28 newtFormAddComponent(self->form, self->scale);
29 newtRefresh();
32 return self;
34 out_free_form:
35 newtFormDestroy(self->form);
36 out_free_self:
37 free(self);
38 return NULL;
41 void ui_progress__update(struct ui_progress *self, u64 curr)
44 * FIXME: We should have a per UI backend way of showing progress,
45 * stdio will just show a percentage as NN%, etc.
47 if (use_browser <= 0)
48 return;
49 newtScaleSet(self->scale, curr);
50 newtRefresh();
53 void ui_progress__delete(struct ui_progress *self)
55 if (use_browser > 0) {
56 newtFormDestroy(self->form);
57 newtPopWindow();
59 free(self);