{"thread":{"id":"17947","subject":"[PATCH] Popup menu","startedAt":"2009-02-22T11:40:19Z","lastAt":"2009-02-22T13:00:50Z","messageCount":6,"participants":["Giuseppe Bilotta","Jonas Fonseca","Felipe Contreras"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"105761","messageId":"1235302820-32526-1-git-send-email-giuseppe.bilotta@gmail.com","threadId":"17947","inReplyTo":null,"subject":"[PATCH] Popup menu","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2009-02-22T11:40:19Z","receivedAt":"2009-02-22T11:40:19Z","isPatch":true,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"Make the menu into a popup window that complements the status prompt.\n\nSigned-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\n---\n\nWe should probably consider using the high-level menu and panel features from\nncurses if we want to do anything more complex.\n\n tig.c |  117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-\n 1 files changed, 115 insertions(+), 2 deletions(-)\n\ndiff --git a/tig.c b/tig.c\nindex 20a40b9..017b05f 100644\n--- a/tig.c\n+++ b/tig.c\n@@ -6542,6 +6542,100 @@ utf8_length(const char **start, size_t skip, int *width, size_t max_width, int *\n \treturn string - *start;\n }\n \n+/*\n+ * Popup management\n+ */\n+\n+struct popup {\n+\tWINDOW *win;\n+\tint width;\n+\tbool hotkeys;\n+\tint selected;\n+};\n+\n+static struct popup menu;\n+\n+\n+static void\n+menu_popup(void)\n+{\n+\twnoutrefresh(menu.win);\n+}\n+\n+static void\n+menu_popdown(void)\n+{\n+\tdelwin(menu.win);\n+\tmenu.win = NULL;\n+\tredraw_display(FALSE);\n+}\n+\n+static void\n+menu_create(int height, int width, const char* title, bool hotkeys)\n+{\n+\tWINDOW *win;\n+\tint ymax, xmax, top, left;\n+\tenum line_type type = LINE_TITLE_FOCUS;\n+\n+\tgetmaxyx(stdscr, ymax, xmax);\n+\ttop = (ymax - height)/2;\n+\tleft = (xmax - width)/2;\n+\tif (top < 0)\n+\t\ttop = 0;\n+\tif (left < 0)\n+\t\tleft = 0;\n+\n+\twin = newwin(height, width, top, left);\n+\twbkgd(win, COLOR_PAIR(type));\n+\n+\tbox(win, 0, 0);\n+\twattrset(win, get_line_attr(type));\n+\tmvwprintw(win, 0, (width-strlen(title))/2, \" %s \", title);\n+\n+\tmenu.win = win;\n+\tmenu.width = width;\n+\tmenu.hotkeys = hotkeys;\n+\tmenu.selected = -1;\n+}\n+\n+static void\n+menu_set_line_attr(int index, enum line_type type)\n+{\n+\tWINDOW *win = menu.win;\n+\tint width = menu.width-2;\n+\tmvwchgat(win, index+1, 1, width,\n+\t\t\tget_line_attr(type), type, NULL);\n+}\n+\n+static void\n+menu_putline(int index, const struct menu_item *item)\n+{\n+\tWINDOW *win = menu.win;\n+\tbool hotkeys = menu.hotkeys;\n+\tif (hotkeys) {\n+\t\tif (item->hotkey)\n+\t\t\tmvwprintw(win, index+1, 2, \"[%c] %s\", (char) item->hotkey, item->text);\n+\t\telse\n+\t\t\tmvwprintw(win, index+1, 6, \"%s\", item->text);\n+\t} else {\n+\t\tmvwprintw(win, index+1, 2, \"%s\", item->text);\n+\t}\n+}\n+\n+static void\n+menu_select(int index)\n+{\n+\tWINDOW *win = menu.win;\n+\tint width = menu.width-2;\n+\tif (menu.selected >= 0) {\n+\t\tmenu_set_line_attr(menu.selected, LINE_TITLE_FOCUS);\n+\t}\n+\tif (index >= 0) {\n+\t\tmenu_set_line_attr(index, LINE_CURSOR);\n+\t}\n+\tmenu.selected = index;\n+\tmenu_popup();\n+}\n \n /*\n  * Status management\n@@ -6836,14 +6930,30 @@ static bool prompt_menu(const char *prompt, const struct menu_item *items, int *\n {\n \tenum input_status status = INPUT_OK;\n \tint size = 0;\n+\tint width = strlen(prompt+2);\n+\tbool hotkeys = false;\n+\tint i;\n \n-\twhile (items[size].text)\n+\twhile (items[size].text) {\n+\t\tint w = strlen(items[size].text);\n+\t\tif (w > width)\n+\t\t\twidth = w;\n+\t\tif (items[size].hotkey)\n+\t\t\thotkeys = true;\n \t\tsize++;\n+\t}\n+\t/* padding */\n+\twidth += hotkeys ? 8 : 4;\n+\n+\tmenu_create(size+2, width, prompt, hotkeys);\n+\tfor (i=0; i < size; ++i)\n+\t\tmenu_putline(i, &items[i]);\n+\tmenu_popup();\n+\n \n \twhile (status == INPUT_OK) {\n \t\tconst struct menu_item *item = &items[*selected];\n \t\tint key;\n-\t\tint i;\n \n \t\tmvwprintw(status_win, 0, 0, \"%s (%d of %d) \",\n \t\t\t  prompt, *selected + 1, size);\n@@ -6851,6 +6961,7 @@ static bool prompt_menu(const char *prompt, const struct menu_item *items, int *\n \t\t\twprintw(status_win, \"[%c] \", (char) item->hotkey);\n \t\twprintw(status_win, \"%s\", item->text);\n \t\twclrtoeol(status_win);\n+\t\tmenu_select(*selected);\n \n \t\tkey = get_input(COLS - 1);\n \t\tswitch (key) {\n@@ -6886,6 +6997,8 @@ static bool prompt_menu(const char *prompt, const struct menu_item *items, int *\n \t\t}\n \t}\n \n+\tmenu_popdown();\n+\n \t/* Clear the status window */\n \tstatus_empty = FALSE;\n \treport(\"\");\n-- \n1.6.2.rc1.258.g1d592.dirty\n"},{"id":"105762","messageId":"1235302820-32526-2-git-send-email-giuseppe.bilotta@gmail.com","threadId":"17947","inReplyTo":"1235302820-32526-1-git-send-email-giuseppe.bilotta@gmail.com","subject":"[PATCH] 'tig branch' opens tig in branch view","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2009-02-22T11:40:20Z","receivedAt":"2009-02-22T11:40:20Z","isPatch":true,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\n---\n tig.1.txt |    4 ++++\n tig.c     |    6 ++++++\n 2 files changed, 10 insertions(+), 0 deletions(-)\n\ndiff --git a/tig.1.txt b/tig.1.txt\nindex db8a4d7..abcd9f3 100644\n--- a/tig.1.txt\n+++ b/tig.1.txt\n@@ -11,6 +11,7 @@ SYNOPSIS\n tig        [options] [revisions] [--] [paths]\n tig show   [options] [revisions] [--] [paths]\n tig blame  [rev] path\n+tig branch\n tig status\n tig <      [git command output]\n \n@@ -43,6 +44,9 @@ blame::\n \tShow given file annotated or blamed by commits.\n \tOptionally limited from given revision.\n \n+branch::\n+\tStart up in branch view.\n+\n status::\n \tStart up in status view.\n \ndiff --git a/tig.c b/tig.c\nindex 60d73d5..20a40b9 100644\n--- a/tig.c\n+++ b/tig.c\n@@ -7249,6 +7249,7 @@ static const char usage[] =\n \"Usage: tig        [options] [revs] [--] [paths]\\n\"\n \"   or: tig show   [options] [revs] [--] [paths]\\n\"\n \"   or: tig blame  [rev] path\\n\"\n+\"   or: tig branch\\n\"\n \"   or: tig status\\n\"\n \"   or: tig <      [git command output]\\n\"\n \"\\n\"\n@@ -7321,6 +7322,11 @@ parse_options(int argc, const char *argv[])\n \t\t\twarn(\"ignoring arguments after `%s'\", subcommand);\n \t\treturn REQ_VIEW_STATUS;\n \n+\t} else if (!strcmp(subcommand, \"branch\")) {\n+\t\tif (argc > 2)\n+\t\t\twarn(\"ignoring arguments after `%s'\", subcommand);\n+\t\treturn REQ_VIEW_BRANCH;\n+\n \t} else if (!strcmp(subcommand, \"blame\")) {\n \t\tif (argc <= 2 || argc > 4)\n \t\t\tdie(\"invalid number of options to blame\\n\\n%s\", usage);\n-- \n1.6.2.rc1.258.g1d592.dirty\n"},{"id":"105763","messageId":"2c6b72b30902220415q2d3cfa7dmd5fd584c89acbecc@mail.gmail.com","threadId":"17947","inReplyTo":"1235302820-32526-1-git-send-email-giuseppe.bilotta@gmail.com","subject":"Re: [PATCH] Popup menu","fromName":"Jonas Fonseca","fromEmail":"jonas.fonseca@gmail.com","sentAt":"2009-02-22T12:15:21Z","receivedAt":"2009-02-22T12:15:21Z","isPatch":true,"sender":{"key":"jonas.fonseca@gmail.com","avatar":"https://gravatar.com/avatar/9b7fa23cce50269e5d164312b6ac5ae818a180f837b38f28f3bdf689dd7f96cd?d=mp&s=160"},"body":"On Sun, Feb 22, 2009 at 12:40, Giuseppe Bilotta\n<giuseppe.bilotta@gmail.com> wrote:\n> Make the menu into a popup window that complements the status prompt.\n>\n> Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\n> ---\n>\n> We should probably consider using the high-level menu and panel features from\n> ncurses if we want to do anything more complex.\n\nFirst of all very cute. I take it as a comment that the menu thing I\nadded yesterday leaves a lot to be desired. :) I certainly agree it is\nlimited and would have liked to make it similar to Vim's horizontal\nmenu, but gave up when it got too complicated.\n\nAbout using the menu, panel and maybe even the form library: Yes, it\nmight make sense but then again I had also hoped to maybe at some\npoint try to get tig running on just the terminfo interface. But I\ndon't know if there is any compelling reason for doing this anymore,\nother than reducing the dependencies a bit.\n\nBTW, the code doesn't handle resizing or background loading (try\nstarting with `tig --stat` and immediately press 'o'). To fix this I\ndon't know if it would be better to \"rip off\" the status window and\nuse this as the menu window. It would require a few flags to make the\nresize code do the right thing.\n\n>  tig.c |  117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-\n>  1 files changed, 115 insertions(+), 2 deletions(-)\n>\n> diff --git a/tig.c b/tig.c\n> index 20a40b9..017b05f 100644\n> --- a/tig.c\n> +++ b/tig.c\n> @@ -6542,6 +6542,100 @@ utf8_length(const char **start, size_t skip, int *width, size_t max_width, int *\n> +static void\n> +menu_select(int index)\n> +{\n> +       WINDOW *win = menu.win;\n> +       int width = menu.width-2;\n> +       if (menu.selected >= 0) {\n> +               menu_set_line_attr(menu.selected, LINE_TITLE_FOCUS);\n> +       }\n> +       if (index >= 0) {\n> +               menu_set_line_attr(index, LINE_CURSOR);\n> +       }\n> +       menu.selected = index;\n> +       menu_popup();\n> +}\n>\n\ntig.c: In function 'menu_select':\ntig.c:6629: warning: unused variable 'width'\ntig.c:6628: warning: unused variable 'win'\n\n-- \nJonas Fonseca\n"},{"id":"105764","messageId":"94a0d4530902220426p3fae124cl2210fbfc04968033@mail.gmail.com","threadId":"17947","inReplyTo":"1235302820-32526-1-git-send-email-giuseppe.bilotta@gmail.com","subject":"Re: [PATCH] Popup menu","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2009-02-22T12:26:28Z","receivedAt":"2009-02-22T12:26:28Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Sun, Feb 22, 2009 at 1:40 PM, Giuseppe Bilotta\n<giuseppe.bilotta@gmail.com> wrote:\n> Make the menu into a popup window that complements the status prompt.\n\nPopup menu of what? Please prefix \"tig: \" in your subject.\n\n-- \nFelipe Contreras\n"},{"id":"105766","messageId":"cb7bb73a0902220457y7e9b18c5ka30ca523318cc223@mail.gmail.com","threadId":"17947","inReplyTo":"2c6b72b30902220415q2d3cfa7dmd5fd584c89acbecc@mail.gmail.com","subject":"Re: [PATCH] Popup menu","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2009-02-22T12:57:23Z","receivedAt":"2009-02-22T12:57:23Z","isPatch":true,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"On Sun, Feb 22, 2009 at 1:15 PM, Jonas Fonseca <jonas.fonseca@gmail.com> wrote:\n> On Sun, Feb 22, 2009 at 12:40, Giuseppe Bilotta\n> <giuseppe.bilotta@gmail.com> wrote:\n>> Make the menu into a popup window that complements the status prompt.\n>>\n>> Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\n>> ---\n>>\n>> We should probably consider using the high-level menu and panel features from\n>> ncurses if we want to do anything more complex.\n>\n> First of all very cute. I take it as a comment that the menu thing I\n> added yesterday leaves a lot to be desired. :) I certainly agree it is\n> limited and would have liked to make it similar to Vim's horizontal\n> menu, but gave up when it got too complicated.\n\nI wouldn't say your implementation left _a lot_ to be desired, but I\nfound it to be somewhat uninformative on the available options, which\nis why I tried this route instead.\n\n> About using the menu, panel and maybe even the form library: Yes, it\n> might make sense but then again I had also hoped to maybe at some\n> point try to get tig running on just the terminfo interface. But I\n> don't know if there is any compelling reason for doing this anymore,\n> other than reducing the dependencies a bit.\n\nIf reducing dependencies means having to reimplement most of them from\nscratch, it might not be worth it so much ;-)\n\n> BTW, the code doesn't handle resizing or background loading (try\n> starting with `tig --stat` and immediately press 'o'). To fix this I\n> don't know if it would be better to \"rip off\" the status window and\n> use this as the menu window. It would require a few flags to make the\n> resize code do the right thing.\n\nI was pretty sure resizing would bomb it, but I hadn't thought about\nbackground loading at all, I'll see if I can think about it a little.\n\n> tig.c: In function 'menu_select':\n> tig.c:6629: warning: unused variable 'width'\n> tig.c:6628: warning: unused variable 'win'\n\nOops, leftovers, I'll clean them up.\n\n-- \nGiuseppe \"Oblomov\" Bilotta\n"},{"id":"105767","messageId":"cb7bb73a0902220500x51aa4345hee7e6805989a065b@mail.gmail.com","threadId":"17947","inReplyTo":"94a0d4530902220426p3fae124cl2210fbfc04968033@mail.gmail.com","subject":"Re: [PATCH] Popup menu","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2009-02-22T13:00:50Z","receivedAt":"2009-02-22T13:00:50Z","isPatch":true,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"On Sun, Feb 22, 2009 at 1:26 PM, Felipe Contreras\n<felipe.contreras@gmail.com> wrote:\n> On Sun, Feb 22, 2009 at 1:40 PM, Giuseppe Bilotta\n> <giuseppe.bilotta@gmail.com> wrote:\n>> Make the menu into a popup window that complements the status prompt.\n>\n> Popup menu of what? Please prefix \"tig: \" in your subject.\n\nAwfully sorry, I forgot the \"[tig \" part in the subject prefix, I'd\nbetter set it in the git config. Thanks for the reminder.\n\n\n-- \nGiuseppe \"Oblomov\" Bilotta\n"}]}