2010-03-11 20:12:44 -03:00
|
|
|
#include <newt.h>
|
2010-08-10 15:49:07 -03:00
|
|
|
#include <signal.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <string.h>
|
2010-03-12 10:48:12 -03:00
|
|
|
#include <sys/ttydefaults.h>
|
2010-03-11 20:12:44 -03:00
|
|
|
|
|
|
|
#include "cache.h"
|
2010-08-10 15:49:07 -03:00
|
|
|
#include "debug.h"
|
2010-08-06 17:35:02 -03:00
|
|
|
#include "ui/browser.h"
|
2010-08-08 19:48:31 -03:00
|
|
|
#include "ui/helpline.h"
|
2010-03-11 20:12:44 -03:00
|
|
|
|
2010-08-06 17:35:02 -03:00
|
|
|
newtComponent newt_form__new(void);
|
2010-08-10 15:49:07 -03:00
|
|
|
int popup_menu(int argc, char * const argv[]);
|
|
|
|
int ui__help_window(const char *text);
|
|
|
|
bool dialog_yesno(const char *msg);
|
2010-08-06 17:35:02 -03:00
|
|
|
|
2010-08-10 14:54:09 -03:00
|
|
|
char browser__last_msg[1024];
|
2010-03-26 21:16:22 -03:00
|
|
|
|
|
|
|
int browser__show_help(const char *format, va_list ap)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
static int backlog;
|
|
|
|
|
|
|
|
ret = vsnprintf(browser__last_msg + backlog,
|
|
|
|
sizeof(browser__last_msg) - backlog, format, ap);
|
|
|
|
backlog += ret;
|
|
|
|
|
|
|
|
if (browser__last_msg[backlog - 1] == '\n') {
|
2010-05-11 18:01:23 -03:00
|
|
|
ui_helpline__puts(browser__last_msg);
|
2010-03-26 21:16:22 -03:00
|
|
|
newtRefresh();
|
|
|
|
backlog = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-03-12 10:48:12 -03:00
|
|
|
static void newt_form__set_exit_keys(newtComponent self)
|
|
|
|
{
|
2010-05-16 20:29:38 -03:00
|
|
|
newtFormAddHotKey(self, NEWT_KEY_LEFT);
|
2010-03-12 10:48:12 -03:00
|
|
|
newtFormAddHotKey(self, NEWT_KEY_ESCAPE);
|
|
|
|
newtFormAddHotKey(self, 'Q');
|
|
|
|
newtFormAddHotKey(self, 'q');
|
|
|
|
newtFormAddHotKey(self, CTRL('c'));
|
|
|
|
}
|
|
|
|
|
2010-08-06 17:35:02 -03:00
|
|
|
newtComponent newt_form__new(void)
|
2010-03-12 10:48:12 -03:00
|
|
|
{
|
|
|
|
newtComponent self = newtForm(NULL, NULL, 0);
|
|
|
|
if (self)
|
|
|
|
newt_form__set_exit_keys(self);
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-08-10 15:49:07 -03:00
|
|
|
int popup_menu(int argc, char * const argv[])
|
2010-03-24 16:40:14 -03:00
|
|
|
{
|
|
|
|
struct newtExitStruct es;
|
|
|
|
int i, rc = -1, max_len = 5;
|
|
|
|
newtComponent listbox, form = newt_form__new();
|
|
|
|
|
|
|
|
if (form == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
listbox = newtListbox(0, 0, argc, NEWT_FLAG_RETURNEXIT);
|
|
|
|
if (listbox == NULL)
|
|
|
|
goto out_destroy_form;
|
|
|
|
|
2010-05-10 10:51:25 -03:00
|
|
|
newtFormAddComponent(form, listbox);
|
2010-03-24 16:40:14 -03:00
|
|
|
|
|
|
|
for (i = 0; i < argc; ++i) {
|
|
|
|
int len = strlen(argv[i]);
|
|
|
|
if (len > max_len)
|
|
|
|
max_len = len;
|
|
|
|
if (newtListboxAddEntry(listbox, argv[i], (void *)(long)i))
|
|
|
|
goto out_destroy_form;
|
|
|
|
}
|
|
|
|
|
|
|
|
newtCenteredWindow(max_len, argc, NULL);
|
|
|
|
newtFormRun(form, &es);
|
|
|
|
rc = newtListboxGetCurrent(listbox) - NULL;
|
|
|
|
if (es.reason == NEWT_EXIT_HOTKEY)
|
|
|
|
rc = -1;
|
|
|
|
newtPopWindow();
|
|
|
|
out_destroy_form:
|
|
|
|
newtFormDestroy(form);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2010-08-10 15:49:07 -03:00
|
|
|
int ui__help_window(const char *text)
|
2010-05-16 21:04:27 -03:00
|
|
|
{
|
|
|
|
struct newtExitStruct es;
|
|
|
|
newtComponent tb, form = newt_form__new();
|
|
|
|
int rc = -1;
|
|
|
|
int max_len = 0, nr_lines = 0;
|
|
|
|
const char *t;
|
|
|
|
|
|
|
|
if (form == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
t = text;
|
|
|
|
while (1) {
|
|
|
|
const char *sep = strchr(t, '\n');
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if (sep == NULL)
|
|
|
|
sep = strchr(t, '\0');
|
|
|
|
len = sep - t;
|
|
|
|
if (max_len < len)
|
|
|
|
max_len = len;
|
|
|
|
++nr_lines;
|
|
|
|
if (*sep == '\0')
|
|
|
|
break;
|
|
|
|
t = sep + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
tb = newtTextbox(0, 0, max_len, nr_lines, 0);
|
|
|
|
if (tb == NULL)
|
|
|
|
goto out_destroy_form;
|
|
|
|
|
|
|
|
newtTextboxSetText(tb, text);
|
|
|
|
newtFormAddComponent(form, tb);
|
|
|
|
newtCenteredWindow(max_len, nr_lines, NULL);
|
|
|
|
newtFormRun(form, &es);
|
|
|
|
newtPopWindow();
|
|
|
|
rc = 0;
|
|
|
|
out_destroy_form:
|
|
|
|
newtFormDestroy(form);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2010-08-10 15:49:07 -03:00
|
|
|
bool dialog_yesno(const char *msg)
|
2010-03-24 16:40:14 -03:00
|
|
|
{
|
|
|
|
/* newtWinChoice should really be accepting const char pointers... */
|
|
|
|
char yes[] = "Yes", no[] = "No";
|
2010-04-05 12:04:23 -03:00
|
|
|
return newtWinChoice(NULL, yes, no, (char *)msg) == 1;
|
2010-03-24 16:40:14 -03:00
|
|
|
}
|
|
|
|
|
2010-07-30 10:06:06 -03:00
|
|
|
static void newt_suspend(void *d __used)
|
|
|
|
{
|
|
|
|
newtSuspend();
|
|
|
|
raise(SIGTSTP);
|
|
|
|
newtResume();
|
|
|
|
}
|
|
|
|
|
2010-03-11 20:12:44 -03:00
|
|
|
void setup_browser(void)
|
|
|
|
{
|
2010-05-22 11:25:40 -03:00
|
|
|
if (!isatty(1) || !use_browser || dump_trace) {
|
2010-05-26 13:22:26 -03:00
|
|
|
use_browser = 0;
|
perf tui: Allow disabling the TUI on a per command basis in ~/.perfconfig
Using the same scheme as for git's/perf's pager setup, i.e. if one
doesn't want to, on a newt enabled perf binary, to disable the TUI for
'perf report', its just a matter of doing:
[root@doppio linux-2.6-tip]# printf "[tui]\n\nreport = off\n" >
/root/.perfconfig
[root@doppio linux-2.6-tip]# cat /root/.perfconfig
[tui]
report = off
[root@doppio linux-2.6-tip]#
System wide settings are also possible, by editing /etc/perfconfig, etc,
i.e. the git machinery for config files applies to perf as well, so when
in doubt where to put your settings, consult the git documentation, if
it fails, please let us know.
Suggested-by: Ingo Molnar <mingo@elte.hu>
Discussed-with: Stephane Eranian <eranian@google.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-05-20 22:01:10 -03:00
|
|
|
setup_pager();
|
2010-03-11 20:12:44 -03:00
|
|
|
return;
|
perf tui: Allow disabling the TUI on a per command basis in ~/.perfconfig
Using the same scheme as for git's/perf's pager setup, i.e. if one
doesn't want to, on a newt enabled perf binary, to disable the TUI for
'perf report', its just a matter of doing:
[root@doppio linux-2.6-tip]# printf "[tui]\n\nreport = off\n" >
/root/.perfconfig
[root@doppio linux-2.6-tip]# cat /root/.perfconfig
[tui]
report = off
[root@doppio linux-2.6-tip]#
System wide settings are also possible, by editing /etc/perfconfig, etc,
i.e. the git machinery for config files applies to perf as well, so when
in doubt where to put your settings, consult the git documentation, if
it fails, please let us know.
Suggested-by: Ingo Molnar <mingo@elte.hu>
Discussed-with: Stephane Eranian <eranian@google.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-05-20 22:01:10 -03:00
|
|
|
}
|
2010-03-11 20:12:44 -03:00
|
|
|
|
perf tui: Allow disabling the TUI on a per command basis in ~/.perfconfig
Using the same scheme as for git's/perf's pager setup, i.e. if one
doesn't want to, on a newt enabled perf binary, to disable the TUI for
'perf report', its just a matter of doing:
[root@doppio linux-2.6-tip]# printf "[tui]\n\nreport = off\n" >
/root/.perfconfig
[root@doppio linux-2.6-tip]# cat /root/.perfconfig
[tui]
report = off
[root@doppio linux-2.6-tip]#
System wide settings are also possible, by editing /etc/perfconfig, etc,
i.e. the git machinery for config files applies to perf as well, so when
in doubt where to put your settings, consult the git documentation, if
it fails, please let us know.
Suggested-by: Ingo Molnar <mingo@elte.hu>
Discussed-with: Stephane Eranian <eranian@google.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-05-20 22:01:10 -03:00
|
|
|
use_browser = 1;
|
2010-03-11 20:12:44 -03:00
|
|
|
newtInit();
|
|
|
|
newtCls();
|
2010-07-30 10:06:06 -03:00
|
|
|
newtSetSuspendCallback(newt_suspend, NULL);
|
2010-05-11 18:01:23 -03:00
|
|
|
ui_helpline__puts(" ");
|
2010-08-06 17:35:02 -03:00
|
|
|
ui_browser__init();
|
2010-03-11 20:12:44 -03:00
|
|
|
}
|
|
|
|
|
2010-03-22 13:10:25 -03:00
|
|
|
void exit_browser(bool wait_for_ok)
|
2010-03-11 20:12:44 -03:00
|
|
|
{
|
perf tui: Allow disabling the TUI on a per command basis in ~/.perfconfig
Using the same scheme as for git's/perf's pager setup, i.e. if one
doesn't want to, on a newt enabled perf binary, to disable the TUI for
'perf report', its just a matter of doing:
[root@doppio linux-2.6-tip]# printf "[tui]\n\nreport = off\n" >
/root/.perfconfig
[root@doppio linux-2.6-tip]# cat /root/.perfconfig
[tui]
report = off
[root@doppio linux-2.6-tip]#
System wide settings are also possible, by editing /etc/perfconfig, etc,
i.e. the git machinery for config files applies to perf as well, so when
in doubt where to put your settings, consult the git documentation, if
it fails, please let us know.
Suggested-by: Ingo Molnar <mingo@elte.hu>
Discussed-with: Stephane Eranian <eranian@google.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-05-20 22:01:10 -03:00
|
|
|
if (use_browser > 0) {
|
2010-03-22 13:10:25 -03:00
|
|
|
if (wait_for_ok) {
|
|
|
|
char title[] = "Fatal Error", ok[] = "Ok";
|
|
|
|
newtWinMessage(title, ok, browser__last_msg);
|
|
|
|
}
|
2010-03-11 20:12:44 -03:00
|
|
|
newtFinished();
|
2010-03-22 13:10:25 -03:00
|
|
|
}
|
2010-03-11 20:12:44 -03:00
|
|
|
}
|