Skip to content

Conversation

dzhou121
Copy link
Contributor

Part of PR #5686

@dzhou121 dzhou121 mentioned this pull request Feb 24, 2017
@marvim marvim added the RFC label Feb 24, 2017
@@ -413,5 +417,9 @@ of update.
["popupmenu_hide"]
The popupmenu is hidden.

["tabline", curtab, tabs]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An event is something that happens. Let's name this something more granular, e.g. "tabline_update". That follows the pattern of the existing "bg_update" and similar events.

@@ -5158,6 +5160,9 @@ static void last_status_rec(frame_T *fr, int statusline)
*/
int tabline_height(void)
{
if (tabline_external) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this query the UI structure instead of storing extra state in window.c? E.g. ui_is_widget_external(kUITabline), where the parameter is a enum like:

enum {
kUITabline,
kUIStatusline,
kUICmdline,
...
}

@@ -53,6 +53,10 @@ static bool pending_cursor_update = false;
static int busy = 0;
static int height, width;

static bool tabline_external = false;
static bool cmdline_external = false;
static bool wildmenu_external = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused about why this extra state is needed. Can the uis be iterated to find the flag instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that it's because we are worried about the possibility that a UI might connect that doesn't support a externalized widget. Hmmm... ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So shall I keep these as is?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it's fine.

src/nvim/ui.c Outdated
case kUIWildmenu:
return wildmenu_external;
default:
return false;
Copy link
Member

@justinmk justinmk Feb 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave out the default case. Our build settings will catch a missing case at compile-time. But for that to work, the enum needs to be typedef'd.

src/nvim/ui.h Outdated
kUITabline = 0
, kUICmdline
, kUIWildmenu
};
Copy link
Member

@justinmk justinmk Feb 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be a named type, e.g. UIWidget

typedef enum {
...
} UIWidget;

src/nvim/ui.c Outdated
@@ -548,3 +555,31 @@ static void ui_mode_change(void)
conceal_check_cursur_line();
}

bool ui_is_widget_external(int widget)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parameter should be UIWidget widget

@@ -6888,6 +6889,30 @@ static void draw_tabline(void)
int use_sep_chars = (t_colors < 8
);

if (ui_is_widget_external(kUITabline)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's factor this out to a new function, draw_tabline_ext().

if (ui_is_widget_external(kUITabline)) {
  draw_tabline_ext();
  return;
}

If possible, try to follow a similar pattern for other externalized widgets.

@justinmk
Copy link
Member

justinmk commented Feb 28, 2017

The built-in tabline supports mouse-clicks which run a user-defined VimL function (see kStlClickFuncRun, and the @ entry in :help 'statusline').

What are your thoughts about how externalized tabline widget can support that?

@dzhou121
Copy link
Contributor Author

dzhou121 commented Feb 28, 2017

The only way I can think of is that we output the raw format string to external ui and external ui can call the vimscript directly if that filed is clicked.

put draw_tabline_ext to a function
@justinmk
Copy link
Member

The only way I can think of is that we output the raw format string to external ui and external ui can call the vimscript directly if that filed is clicked.

Searching for kStlClickFuncRun looks useful.

In the "tabline_update" event, I think we need to include StlClickRecord info (build_stl_str_hl() parses the tab expression and then stores it. draw_tabline() can access this info via tab_page_click_defs.) It is handled in do_mouse(). The logic in do_mouse for handling tab-clicks can probably be extracted and wrapped in a new API function, nvim_tabpage_select().

We don't have to do that right now. The only thing we need to do is make sure the tabline_update event is flexible enough for future enhancements, so that UIs (in the future) can get the data they need to call nvim_tabpage_select() correctly.

I think that means for the ["tabline_update", curtab, tabs] event, tabs should be structured like this:

[[ {tabid}, {dict} ], ... ]

where {dict} may contain new fields in the future.

@@ -413,5 +417,9 @@ of update.
["popupmenu_hide"]
The popupmenu is hidden.

["tabline_update", curtab, tabs]
Nvim will send this event when drawing tabline. curtab is the tab id
of the current tab. tabs is an arrays of the form [tabid, tabname].
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tabs is an arrays of the form [tabid, { "name": name } ].

Then we can add new fields later.

@dzhou121 dzhou121 changed the title [RFC] allow external ui to draw tabline [RDY] allow external ui to draw tabline Mar 4, 2017
@marvim marvim added RDY and removed RFC labels Mar 4, 2017
@dzhou121
Copy link
Contributor Author

dzhou121 commented Mar 9, 2017

Anything else I need to improve to get this merged, cause I'm waiting to use the enum here for other external widgets.

@dzhou121 dzhou121 closed this Mar 9, 2017
@jszakmeister jszakmeister removed the RDY label Mar 9, 2017
@dzhou121 dzhou121 reopened this Mar 9, 2017
@marvim marvim added the RDY label Mar 9, 2017
@justinmk justinmk mentioned this pull request Apr 25, 2017
@justinmk
Copy link
Member

@dzhou121 Now that :help api-contract has been established we can accelerate the addition of new externalized UI widgets. I made some changes in #6583 , let me know what you think.

@justinmk
Copy link
Member

Merged in #6583. Thank you @dzhou121 !

@justinmk justinmk closed this Apr 27, 2017
@justinmk justinmk removed the RDY label Apr 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants