* [tig PATCH v2 0/2] popup menu
@ 2009-02-22 14:09 Giuseppe Bilotta
2009-02-22 14:09 ` [tig PATCH v2 1/2] Popup menu Giuseppe Bilotta
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Giuseppe Bilotta @ 2009-02-22 14:09 UTC (permalink / raw)
To: Jonas Fonseca; +Cc: git, Giuseppe Bilotta
Second version, in two patches. The first one is just the same as
previous one, minus a couple of leftovers.
The second one reimplements the menu drawing routine so that it can be
called when necessary to redraw the menu entirely, e.g. after a resize
or when background loading finishes.
Giuseppe Bilotta (2):
Popup menu
Popup menu: redraw as needed
tig.c | 149 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 147 insertions(+), 2 deletions(-)
^ permalink raw reply [flat|nested] 6+ messages in thread
* [tig PATCH v2 1/2] Popup menu
2009-02-22 14:09 [tig PATCH v2 0/2] popup menu Giuseppe Bilotta
@ 2009-02-22 14:09 ` Giuseppe Bilotta
2009-02-22 14:09 ` [tig PATCH v2 2/2] Popup menu: redraw as needed Giuseppe Bilotta
2009-02-25 22:32 ` [tig PATCH v2 0/2] popup menu Jonas Fonseca
2 siblings, 0 replies; 6+ messages in thread
From: Giuseppe Bilotta @ 2009-02-22 14:09 UTC (permalink / raw)
To: Jonas Fonseca; +Cc: git, Giuseppe Bilotta
Make the menu into a popup window that complements the status prompt.
Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
---
tig.c | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 113 insertions(+), 2 deletions(-)
diff --git a/tig.c b/tig.c
index 20a40b9..9b9c34b 100644
--- a/tig.c
+++ b/tig.c
@@ -6542,6 +6542,98 @@ utf8_length(const char **start, size_t skip, int *width, size_t max_width, int *
return string - *start;
}
+/*
+ * Popup management
+ */
+
+struct popup {
+ WINDOW *win;
+ int width;
+ bool hotkeys;
+ int selected;
+};
+
+static struct popup menu;
+
+
+static void
+menu_popup(void)
+{
+ wnoutrefresh(menu.win);
+}
+
+static void
+menu_popdown(void)
+{
+ delwin(menu.win);
+ menu.win = NULL;
+ redraw_display(FALSE);
+}
+
+static void
+menu_create(int height, int width, const char* title, bool hotkeys)
+{
+ WINDOW *win;
+ int ymax, xmax, top, left;
+ enum line_type type = LINE_TITLE_FOCUS;
+
+ getmaxyx(stdscr, ymax, xmax);
+ top = (ymax - height)/2;
+ left = (xmax - width)/2;
+ if (top < 0)
+ top = 0;
+ if (left < 0)
+ left = 0;
+
+ win = newwin(height, width, top, left);
+ wbkgd(win, COLOR_PAIR(type));
+
+ box(win, 0, 0);
+ wattrset(win, get_line_attr(type));
+ mvwprintw(win, 0, (width-strlen(title))/2, " %s ", title);
+
+ menu.win = win;
+ menu.width = width;
+ menu.hotkeys = hotkeys;
+ menu.selected = -1;
+}
+
+static void
+menu_set_line_attr(int index, enum line_type type)
+{
+ WINDOW *win = menu.win;
+ int width = menu.width-2;
+ mvwchgat(win, index+1, 1, width,
+ get_line_attr(type), type, NULL);
+}
+
+static void
+menu_putline(int index, const struct menu_item *item)
+{
+ WINDOW *win = menu.win;
+ bool hotkeys = menu.hotkeys;
+ if (hotkeys) {
+ if (item->hotkey)
+ mvwprintw(win, index+1, 2, "[%c] %s", (char) item->hotkey, item->text);
+ else
+ mvwprintw(win, index+1, 6, "%s", item->text);
+ } else {
+ mvwprintw(win, index+1, 2, "%s", item->text);
+ }
+}
+
+static void
+menu_select(int index)
+{
+ if (menu.selected >= 0) {
+ menu_set_line_attr(menu.selected, LINE_TITLE_FOCUS);
+ }
+ if (index >= 0) {
+ menu_set_line_attr(index, LINE_CURSOR);
+ }
+ menu.selected = index;
+ menu_popup();
+}
/*
* Status management
@@ -6836,14 +6928,30 @@ static bool prompt_menu(const char *prompt, const struct menu_item *items, int *
{
enum input_status status = INPUT_OK;
int size = 0;
+ int width = strlen(prompt+2);
+ bool hotkeys = false;
+ int i;
- while (items[size].text)
+ while (items[size].text) {
+ int w = strlen(items[size].text);
+ if (w > width)
+ width = w;
+ if (items[size].hotkey)
+ hotkeys = true;
size++;
+ }
+ /* padding */
+ width += hotkeys ? 8 : 4;
+
+ menu_create(size+2, width, prompt, hotkeys);
+ for (i=0; i < size; ++i)
+ menu_putline(i, &items[i]);
+ menu_popup();
+
while (status == INPUT_OK) {
const struct menu_item *item = &items[*selected];
int key;
- int i;
mvwprintw(status_win, 0, 0, "%s (%d of %d) ",
prompt, *selected + 1, size);
@@ -6851,6 +6959,7 @@ static bool prompt_menu(const char *prompt, const struct menu_item *items, int *
wprintw(status_win, "[%c] ", (char) item->hotkey);
wprintw(status_win, "%s", item->text);
wclrtoeol(status_win);
+ menu_select(*selected);
key = get_input(COLS - 1);
switch (key) {
@@ -6886,6 +6995,8 @@ static bool prompt_menu(const char *prompt, const struct menu_item *items, int *
}
}
+ menu_popdown();
+
/* Clear the status window */
status_empty = FALSE;
report("");
--
1.6.2.rc1.258.g1d592.dirty
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [tig PATCH v2 2/2] Popup menu: redraw as needed
2009-02-22 14:09 [tig PATCH v2 0/2] popup menu Giuseppe Bilotta
2009-02-22 14:09 ` [tig PATCH v2 1/2] Popup menu Giuseppe Bilotta
@ 2009-02-22 14:09 ` Giuseppe Bilotta
2009-02-22 18:36 ` [tig PATCH v2bis " Giuseppe Bilotta
2009-02-25 22:32 ` [tig PATCH v2 0/2] popup menu Jonas Fonseca
2 siblings, 1 reply; 6+ messages in thread
From: Giuseppe Bilotta @ 2009-02-22 14:09 UTC (permalink / raw)
To: Jonas Fonseca; +Cc: git, Giuseppe Bilotta
Redraw the popup menu after a resize or an update during background
loading.
Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
---
tig.c | 132 ++++++++++++++++++++++++++++++++++++++++++----------------------
1 files changed, 86 insertions(+), 46 deletions(-)
diff --git a/tig.c b/tig.c
index 9b9c34b..96ab26d 100644
--- a/tig.c
+++ b/tig.c
@@ -2274,6 +2274,8 @@ resize_display(void)
}
}
+static void menu_redraw(void);
+
static void
redraw_display(bool clear)
{
@@ -2286,6 +2288,8 @@ redraw_display(bool clear)
redraw_view(view);
update_view_title(view);
}
+
+ menu_redraw();
}
static void
@@ -2952,6 +2956,10 @@ update_view(struct view *view)
/* Update the title _after_ the redraw so that if the redraw picks up a
* commit reference in view->ref it'll be available here. */
update_view_title(view);
+
+ /* Redraw menu if needed */
+ menu_redraw();
+
return TRUE;
}
@@ -6549,6 +6557,9 @@ utf8_length(const char **start, size_t skip, int *width, size_t max_width, int *
struct popup {
WINDOW *win;
int width;
+ int height;
+ const char *title;
+ const struct menu_item *items;
bool hotkeys;
int selected;
};
@@ -6557,6 +6568,32 @@ static struct popup menu;
static void
+menu_set_line_attr(int index, enum line_type type)
+{
+ WINDOW *win = menu.win;
+ int width = menu.width-2;
+ mvwchgat(win, index+1, 1, width,
+ get_line_attr(type), type, NULL);
+}
+
+static void
+menu_putline(int index, const struct menu_item *item, bool selected)
+{
+ WINDOW *win = menu.win;
+ bool hotkeys = menu.hotkeys;
+ if (hotkeys) {
+ if (item->hotkey)
+ mvwprintw(win, index+1, 2, "[%c] %s", (char) item->hotkey, item->text);
+ else
+ mvwprintw(win, index+1, 6, "%s", item->text);
+ } else {
+ mvwprintw(win, index+1, 2, "%s", item->text);
+ }
+ if (selected)
+ menu_set_line_attr(index, LINE_CURSOR);
+}
+
+static void
menu_popup(void)
{
wnoutrefresh(menu.win);
@@ -6571,55 +6608,62 @@ menu_popdown(void)
}
static void
-menu_create(int height, int width, const char* title, bool hotkeys)
+menu_redraw(void)
{
- WINDOW *win;
- int ymax, xmax, top, left;
- enum line_type type = LINE_TITLE_FOCUS;
-
- getmaxyx(stdscr, ymax, xmax);
- top = (ymax - height)/2;
- left = (xmax - width)/2;
- if (top < 0)
- top = 0;
- if (left < 0)
- left = 0;
-
- win = newwin(height, width, top, left);
- wbkgd(win, COLOR_PAIR(type));
+ WINDOW *win = menu.win;
+ if (win)
+ {
+ int width = menu.width;
+ int height = menu.height;
+ const char *title = menu.title;
+ const struct menu_item *items = menu.items;
- box(win, 0, 0);
- wattrset(win, get_line_attr(type));
- mvwprintw(win, 0, (width-strlen(title))/2, " %s ", title);
+ int ymax, xmax, top, left;
+ enum line_type type = LINE_TITLE_FOCUS;
+ int i;
- menu.win = win;
- menu.width = width;
- menu.hotkeys = hotkeys;
- menu.selected = -1;
+ getmaxyx(stdscr, ymax, xmax);
+ top = (ymax - height)/2;
+ left = (xmax - width)/2;
+ if (top < 0)
+ top = 0;
+ if (left < 0)
+ left = 0;
+
+ mvwin(win, top, left);
+ wbkgd(win, COLOR_PAIR(type));
+
+ box(win, 0, 0);
+ wattrset(win, get_line_attr(type));
+ mvwprintw(win, 0, (width-strlen(title))/2, " %s ", title);
+
+ for (i=0; items[i].text; ++i) {
+ menu_putline(i, &items[i], i==menu.selected);
+ if (items[i].hotkey)
+ menu.hotkeys = true;
+ }
+ menu_popup();
+ }
}
static void
-menu_set_line_attr(int index, enum line_type type)
+menu_create(int height, int width, const char *title, const struct menu_item *items)
{
- WINDOW *win = menu.win;
- int width = menu.width-2;
- mvwchgat(win, index+1, 1, width,
- get_line_attr(type), type, NULL);
-}
+ int i=0;
+ menu.win = newwin(height, width, 0, 0);
+ menu.width = width;
+ menu.height = height;
+ menu.title = title;
+ menu.items = items;
+ menu.hotkeys = false;
+ for(;items[i].text;++i)
+ if (items[i].hotkey) {
+ menu.hotkeys=true;
+ break;
+ }
+ menu.selected = -1;
-static void
-menu_putline(int index, const struct menu_item *item)
-{
- WINDOW *win = menu.win;
- bool hotkeys = menu.hotkeys;
- if (hotkeys) {
- if (item->hotkey)
- mvwprintw(win, index+1, 2, "[%c] %s", (char) item->hotkey, item->text);
- else
- mvwprintw(win, index+1, 6, "%s", item->text);
- } else {
- mvwprintw(win, index+1, 2, "%s", item->text);
- }
+ menu_redraw();
}
static void
@@ -6943,11 +6987,7 @@ static bool prompt_menu(const char *prompt, const struct menu_item *items, int *
/* padding */
width += hotkeys ? 8 : 4;
- menu_create(size+2, width, prompt, hotkeys);
- for (i=0; i < size; ++i)
- menu_putline(i, &items[i]);
- menu_popup();
-
+ menu_create(size+2, width, prompt, items);
while (status == INPUT_OK) {
const struct menu_item *item = &items[*selected];
--
1.6.2.rc1.258.g1d592.dirty
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [tig PATCH v2bis 2/2] Popup menu: redraw as needed
2009-02-22 14:09 ` [tig PATCH v2 2/2] Popup menu: redraw as needed Giuseppe Bilotta
@ 2009-02-22 18:36 ` Giuseppe Bilotta
0 siblings, 0 replies; 6+ messages in thread
From: Giuseppe Bilotta @ 2009-02-22 18:36 UTC (permalink / raw)
To: Jonas Fonseca; +Cc: git, Giuseppe Bilotta
Redraw the popup menu after a resize or an update during background
loading.
Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
---
Of course, I forgot some leftovers here too. Here's the cleaned up patch for this.
tig.c | 126 ++++++++++++++++++++++++++++++++++++++++++-----------------------
1 files changed, 82 insertions(+), 44 deletions(-)
diff --git a/tig.c b/tig.c
index 9b9c34b..1d7dcce 100644
--- a/tig.c
+++ b/tig.c
@@ -2274,6 +2274,8 @@ resize_display(void)
}
}
+static void menu_redraw(void);
+
static void
redraw_display(bool clear)
{
@@ -2286,6 +2288,8 @@ redraw_display(bool clear)
redraw_view(view);
update_view_title(view);
}
+
+ menu_redraw();
}
static void
@@ -2952,6 +2956,10 @@ update_view(struct view *view)
/* Update the title _after_ the redraw so that if the redraw picks up a
* commit reference in view->ref it'll be available here. */
update_view_title(view);
+
+ /* Redraw menu if needed */
+ menu_redraw();
+
return TRUE;
}
@@ -6549,6 +6557,9 @@ utf8_length(const char **start, size_t skip, int *width, size_t max_width, int *
struct popup {
WINDOW *win;
int width;
+ int height;
+ const char *title;
+ const struct menu_item *items;
bool hotkeys;
int selected;
};
@@ -6557,6 +6568,32 @@ static struct popup menu;
static void
+menu_set_line_attr(int index, enum line_type type)
+{
+ WINDOW *win = menu.win;
+ int width = menu.width-2;
+ mvwchgat(win, index+1, 1, width,
+ get_line_attr(type), type, NULL);
+}
+
+static void
+menu_putline(int index, const struct menu_item *item, bool selected)
+{
+ WINDOW *win = menu.win;
+ bool hotkeys = menu.hotkeys;
+ if (hotkeys) {
+ if (item->hotkey)
+ mvwprintw(win, index+1, 2, "[%c] %s", (char) item->hotkey, item->text);
+ else
+ mvwprintw(win, index+1, 6, "%s", item->text);
+ } else {
+ mvwprintw(win, index+1, 2, "%s", item->text);
+ }
+ if (selected)
+ menu_set_line_attr(index, LINE_CURSOR);
+}
+
+static void
menu_popup(void)
{
wnoutrefresh(menu.win);
@@ -6571,55 +6608,60 @@ menu_popdown(void)
}
static void
-menu_create(int height, int width, const char* title, bool hotkeys)
+menu_redraw(void)
{
- WINDOW *win;
- int ymax, xmax, top, left;
- enum line_type type = LINE_TITLE_FOCUS;
+ WINDOW *win = menu.win;
+ if (win)
+ {
+ int width = menu.width;
+ int height = menu.height;
+ const char *title = menu.title;
+ const struct menu_item *items = menu.items;
- getmaxyx(stdscr, ymax, xmax);
- top = (ymax - height)/2;
- left = (xmax - width)/2;
- if (top < 0)
- top = 0;
- if (left < 0)
- left = 0;
+ int ymax, xmax, top, left;
+ enum line_type type = LINE_TITLE_FOCUS;
+ int i;
- win = newwin(height, width, top, left);
- wbkgd(win, COLOR_PAIR(type));
+ getmaxyx(stdscr, ymax, xmax);
+ top = (ymax - height)/2;
+ left = (xmax - width)/2;
+ if (top < 0)
+ top = 0;
+ if (left < 0)
+ left = 0;
- box(win, 0, 0);
- wattrset(win, get_line_attr(type));
- mvwprintw(win, 0, (width-strlen(title))/2, " %s ", title);
+ mvwin(win, top, left);
+ wbkgd(win, COLOR_PAIR(type));
- menu.win = win;
- menu.width = width;
- menu.hotkeys = hotkeys;
- menu.selected = -1;
-}
+ box(win, 0, 0);
+ wattrset(win, get_line_attr(type));
+ mvwprintw(win, 0, (width-strlen(title))/2, " %s ", title);
-static void
-menu_set_line_attr(int index, enum line_type type)
-{
- WINDOW *win = menu.win;
- int width = menu.width-2;
- mvwchgat(win, index+1, 1, width,
- get_line_attr(type), type, NULL);
+ for (i=0; items[i].text; ++i)
+ menu_putline(i, &items[i], i==menu.selected);
+
+ menu_popup();
+ }
}
static void
-menu_putline(int index, const struct menu_item *item)
+menu_create(int height, int width, const char *title, const struct menu_item *items)
{
- WINDOW *win = menu.win;
- bool hotkeys = menu.hotkeys;
- if (hotkeys) {
- if (item->hotkey)
- mvwprintw(win, index+1, 2, "[%c] %s", (char) item->hotkey, item->text);
- else
- mvwprintw(win, index+1, 6, "%s", item->text);
- } else {
- mvwprintw(win, index+1, 2, "%s", item->text);
- }
+ int i=0;
+ menu.win = newwin(height, width, 0, 0);
+ menu.width = width;
+ menu.height = height;
+ menu.title = title;
+ menu.items = items;
+ menu.hotkeys = false;
+ for(;items[i].text;++i)
+ if (items[i].hotkey) {
+ menu.hotkeys=true;
+ break;
+ }
+ menu.selected = -1;
+
+ menu_redraw();
}
static void
@@ -6943,11 +6985,7 @@ static bool prompt_menu(const char *prompt, const struct menu_item *items, int *
/* padding */
width += hotkeys ? 8 : 4;
- menu_create(size+2, width, prompt, hotkeys);
- for (i=0; i < size; ++i)
- menu_putline(i, &items[i]);
- menu_popup();
-
+ menu_create(size+2, width, prompt, items);
while (status == INPUT_OK) {
const struct menu_item *item = &items[*selected];
--
1.6.2.rc1.258.g1d592.dirty
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [tig PATCH v2 0/2] popup menu
2009-02-22 14:09 [tig PATCH v2 0/2] popup menu Giuseppe Bilotta
2009-02-22 14:09 ` [tig PATCH v2 1/2] Popup menu Giuseppe Bilotta
2009-02-22 14:09 ` [tig PATCH v2 2/2] Popup menu: redraw as needed Giuseppe Bilotta
@ 2009-02-25 22:32 ` Jonas Fonseca
2009-02-25 22:56 ` Giuseppe Bilotta
2 siblings, 1 reply; 6+ messages in thread
From: Jonas Fonseca @ 2009-02-25 22:32 UTC (permalink / raw)
To: Giuseppe Bilotta; +Cc: git
On Sun, Feb 22, 2009 at 15:09, Giuseppe Bilotta
<giuseppe.bilotta@gmail.com> wrote:
> Second version, in two patches. The first one is just the same as
> previous one, minus a couple of leftovers.
>
> The second one reimplements the menu drawing routine so that it can be
> called when necessary to redraw the menu entirely, e.g. after a resize
> or when background loading finishes.
I didn't read them through very carefully yet, so will "queue" them
for now until I get fully back to tig. There are still some quirks
that might needs to be addressed related with resizing, but this could
also be fixed later. Anyway, I would like to think a bit more whether
or not I like the cute menus, and also whether options might be served
better by introducing an option view.
Regarding the "tig branch", would you mind if I postpone applying it
until the branch view develops into something that is actually usable?
--
Jonas Fonseca
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [tig PATCH v2 0/2] popup menu
2009-02-25 22:32 ` [tig PATCH v2 0/2] popup menu Jonas Fonseca
@ 2009-02-25 22:56 ` Giuseppe Bilotta
0 siblings, 0 replies; 6+ messages in thread
From: Giuseppe Bilotta @ 2009-02-25 22:56 UTC (permalink / raw)
To: Jonas Fonseca; +Cc: git
On Wed, Feb 25, 2009 at 11:32 PM, Jonas Fonseca <jonas.fonseca@gmail.com> wrote:
> On Sun, Feb 22, 2009 at 15:09, Giuseppe Bilotta
> <giuseppe.bilotta@gmail.com> wrote:
>> Second version, in two patches. The first one is just the same as
>> previous one, minus a couple of leftovers.
>>
>> The second one reimplements the menu drawing routine so that it can be
>> called when necessary to redraw the menu entirely, e.g. after a resize
>> or when background loading finishes.
>
> I didn't read them through very carefully yet, so will "queue" them
> for now until I get fully back to tig. There are still some quirks
> that might needs to be addressed related with resizing, but this could
> also be fixed later. Anyway, I would like to think a bit more whether
> or not I like the cute menus, and also whether options might be served
> better by introducing an option view.
I like the minimalistic interface of tig, but when the user has to
select among a fixed number of choices it's much better to be able to
see all of them. The idea of a menu view which is not a popup is
probably good too, but it might have issues with the switching (what
if q is a hotkey? how would you close the view?)
> Regarding the "tig branch", would you mind if I postpone applying it
> until the branch view develops into something that is actually usable?
Please, be my guest 8-) I'm not even convinced it's useful anymore 8-)
("tig branch", not the branch view).
--
Giuseppe "Oblomov" Bilotta
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2009-02-25 22:57 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-22 14:09 [tig PATCH v2 0/2] popup menu Giuseppe Bilotta
2009-02-22 14:09 ` [tig PATCH v2 1/2] Popup menu Giuseppe Bilotta
2009-02-22 14:09 ` [tig PATCH v2 2/2] Popup menu: redraw as needed Giuseppe Bilotta
2009-02-22 18:36 ` [tig PATCH v2bis " Giuseppe Bilotta
2009-02-25 22:32 ` [tig PATCH v2 0/2] popup menu Jonas Fonseca
2009-02-25 22:56 ` Giuseppe Bilotta
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).