Skip to content

API: nvim_list_uis #8004

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed

API: nvim_list_uis #8004

wants to merge 6 commits into from

Conversation

geekodour
Copy link
Contributor

@geekodour geekodour commented Feb 12, 2018

nvim_list_uis returns a list of UI dicts.

running

./nvim -u NONE +"echo nvim_list_uis()" 

returns

[{'ext_cmdline': v:false, 'ext_wildmenu': v:false, 'ext_popupmenu': v:false, 'width': 192, 'height': 47, 'ext_tabline': v:false}]

running

./nvim -u NONE --headless +"echo nvim_list_uis()" 

returns []

#7438

@bfredl
Copy link
Member

bfredl commented Feb 13, 2018

@geekodour it should also list the ui options, #7759 will help with that as it will provide a list with option names, I will clean it up and get it merged.

@geekodour
Copy link
Contributor Author

geekodour commented Feb 13, 2018

@bfredl Yes. For now I'll just add in the other UI properties other than height and width and squash the previous commits together.

edit:
adding it now

@geekodour geekodour changed the title [WIP] Added nvim_list_uis method to vim.c [RFC] Added nvim_list_uis method to vim.c Feb 14, 2018
Dictionary dic = ARRAY_DICT_INIT;
PUT(dic, "width", INTEGER_OBJ(uis[i]->width));
PUT(dic, "height", INTEGER_OBJ(uis[i]->height));
PUT(dic, "ui_options", OBJECT_OBJ(api_metadata().items[3].value));
Copy link
Member

Choose a reason for hiding this comment

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

Metadata is effectively a compile-time constant, instead use a UIExtension k loop with ui_ext_names[k] and ui->ui_ext[k]. Also I think we can just include the options in the top level dict for each UI.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay, if we include the options at the top level dict, should I omit ui_options ?

Copy link
Member

Choose a reason for hiding this comment

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

Yes.

Copy link
Contributor Author

@geekodour geekodour Feb 15, 2018

Choose a reason for hiding this comment

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

@bfredl I spent quite a lot of time figuring this out but failed,
putting the following inside nvim_list_uis does not work because no way
uis[i]->ui_ext_names[i] is valid.

for (UIExtension i = 0; i < kUIExtCount; i++) {
  PUT(dic, ui_ext_names[i], copy_object(uis[i]->ui_ext_names[i]));
}

I don't know if ui->ui_ext[k] can help here, because ui_ext is a bool and is a belongs to the ui

Either will have to just hardcode the ui_options properties one by one else have to use some kind of offset as described here i guess: http://c-faq.com/struct/fieldnames.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another problem I faced was determining the type of ui_option, here copy_object will only take in Objects what about other structures?

Copy link
Member

Choose a reason for hiding this comment

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

ui->ui_ext[i] is a bool because the extension options are all bools. So BOOLEAN_OBJ() should be used and not copy_object. In fact all ui options are currently bool, unless we also count height and width as options.

Copy link
Contributor Author

@geekodour geekodour Feb 15, 2018

Choose a reason for hiding this comment

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

Yes, I implemented that at first, like this, and thought would not work if ui_ext_names had corresponding diff types of types in ui_ext, which i now realize does not happen in C :

for (UIExtension j = 0; j < kUIExtCount; j++) {
  PUT(dic, ui_ext_names[j], BOOLEAN_OBJ(uis[i]->ui_ext[j]));
}

But I didn't realize corresponding ui_ext for ui_ext_names had all bools as of now. I got confused. This works fine for now. It was so simple!

output is something like this:

[{'ext_cmdline': v:false, 'ext_wildmenu': v:false, 'ext_popupmenu': v:false, 'width': 95, 'height': 47, 'ext_tabline': v:false}]

I've pushed the changes: 1fc83d0

@bfredl
Copy link
Member

bfredl commented Feb 15, 2018

the commit history looks weird, did you merge the branch with a rebased copy of itself?

@geekodour
Copy link
Contributor Author

@bfredl yes, I'll fix it and force push it in a while.

@geekodour
Copy link
Contributor Author

geekodour commented Feb 16, 2018

@bfredl Fixed the branch rebase issue. better now.

[{'ext_cmdline': v:false, 'ext_wildmenu': v:false, 'ext_popupmenu': v:false, 'width': 192, 'height': 47, 'ext_tabline': v:false}]

This is the output after running nvim_list_uis now.
I wonder why is there a prefixed v: for the bool values in the UI dict.

@geekodour
Copy link
Contributor Author

Also about failing tests,

function nvim_list_uis has too low since value. For new functions set it to 4.
How are the FUNC_API_SINCE used?

@bfredl
Copy link
Member

bfredl commented Feb 16, 2018

It refers to the API revision this function will be part of. The current (stable) one is 3, therefore new functions should set it to 4.

@bfredl
Copy link
Member

bfredl commented Feb 16, 2018

I wonder why is there a prefixed v: for the bool values in the UI dict.

Because booleans are quite new in vimscript, so adding keywords could break existing codes. Therefore the reserved v: namespace was used.

for (unsigned int i = 0; i < ui_count ; i++) {
Dictionary dic = ARRAY_DICT_INIT;
PUT(dic, "width", INTEGER_OBJ(uis[i]->width));
PUT(dic, "height", INTEGER_OBJ(uis[i]->height));
Copy link
Member

Choose a reason for hiding this comment

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

also "rgb", BOOLEAN_OBJ(uis[i]->rgb)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I'll list all the other properties now.


#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "api/vim.c.generated.h"
#endif

extern UI *uis[MAX_UI_COUNT];
extern size_t ui_count;
Copy link
Member

@justinmk justinmk Feb 20, 2018

Choose a reason for hiding this comment

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

This is what I wanted to avoid. I would suggest instead creating a wrapper function in ui.h, and just call it from nvim_list_uis() (which lives in vim.c):

Array nvim_list_uis(void)
  FUNC_API_SINCE(4)
{
  return ui_list();
}

Then we avoid pulling UI stuff into vim.c.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I get it now. will implement it today. thanks!

@geekodour
Copy link
Contributor Author

fixing failing tests now.

src/nvim/ui.c Outdated
Array ui_list(void)
{
Array all_uis = ARRAY_DICT_INIT;
for (unsigned int i = 0; i < ui_count ; i++) {
Copy link
Member

Choose a reason for hiding this comment

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

we usually use size_t, unless you chose unsigned int for a specific reason.

@justinmk
Copy link
Member

justinmk commented Feb 25, 2018

LGTM, just needs a couple tests ( test/functional/api/vim_spec.lua ):

  describe('nvim_list_uis', function()                                       
    it('returns empty if --headless', function()                             
      clear({args={'--headless'}})                                           
      ...                                                                    
    end)                                                                     
    it('returns attached UIs', function()                                    
      local screen = Screen.new(20, 4)                                       
      screen:attach()                                                        
      local screen2 = Screen.new(20, 4)                                      
      screen2:attach()                                                       
      ...                                                                    
    end)                                                                
  end)                                                                       

@justinmk justinmk changed the title [RFC] Added nvim_list_uis method to vim.c API: nvim_list_uis Feb 25, 2018
@@ -1468,3 +1469,13 @@ Float nvim__id_float(Float flt)
{
return flt;
}

/// Returns Array of UI Dictionaries for the currently running TUI
/// and empty Array otherwise
Copy link
Member

Choose a reason for hiding this comment

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

Returns all UIs, not just the TUI :) I'll fix this in the merge.

@justinmk justinmk added this to the 0.2.3 milestone Mar 3, 2018
@justinmk justinmk added the api libnvim, Nvim RPC API label Mar 3, 2018
@@ -533,3 +533,19 @@ bool ui_is_external(UIExtension widget)
{
return ui_ext[widget];
}

Array ui_list(void)
Copy link
Member

Choose a reason for hiding this comment

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

renamed to ui_array for reason explained in #8060 (comment)

@justinmk
Copy link
Member

justinmk commented Mar 3, 2018

Merged, thanks!

@justinmk justinmk closed this Mar 3, 2018
justinmk pushed a commit that referenced this pull request Mar 3, 2018
justinmk added a commit that referenced this pull request Jun 11, 2018
FEATURES:
3cc7ebf #7234 built-in VimL expression parser
6a7c904 #4419 implement <Cmd> key to invoke command in any mode
b836328 #7679 'startup: treat stdin as text instead of commands'
58b210e :digraphs : highlight with hl-SpecialKey #2690
7a13611 #8276 'startup: Let `-s -` read from stdin'
1e71978 events: VimSuspend, VimResume #8280
1e7d5e8 #6272 'stdpath()'
f96d99a #8247 server: introduce --listen
e8c39f7 #8226 insert-mode: interpret unmapped META as ESC
98e7112 msg: do not scroll entire screen (#8088)
f72630b #8055 let negative 'writedelay' show all redraws
5d2dd2e win: has("wsl") on Windows Subsystem for Linux #7330
a4f6cec cmdline: CmdlineEnter and CmdlineLeave autocommands (#7422)
207b7ca #6844 channels: support buffered output and bytes sockets/stdio

API:
f85cbea #7917 API: buffer updates
418abfc #6743 API: list information about all channels/jobs.
36b2e3f #8375 API: nvim_get_commands
273d2cd #8329 API: Make nvim_set_option() update `:verbose set …`
8d40b36 #8371 API: more reliable/descriptive VimL errors
ebb1acb #8353 API: nvim_call_dict_function
9f994bb #8004 API: nvim_list_uis
3405704 #7520 API/UI: forward option updates to UIs
911b1e4 #7821 API: improve nvim_command_output

WINDOWS OS:
9cefd83 #8084, #8516 build/win: support MSVC
ee4e1fd win: Fix reading content from stdin (#8267)

TUI:
ffb8904 #8309 TUI: add support for mouse release events in urxvt
8d5a46e #8081 TUI: implement "standout" attribute
6071637 TUI: support TERM=konsole-256color
67848c0 #7653 TUI: report TUI info with -V3 ('verbose' >= 3)
3d0ee17 TUI/rxvt: enable focus-reporting
d109f56 #7640 TUI: 'term' option: reflect effective terminal behavior

FIXES:
ed6a113 #8273 'job-control: avoid kill-timer race'
4e02f1a #8107 'jobs: separate process-group'
451c48a terminal: flush vterm output buffer on pty output #8486
5d6732f :checkhealth fixes #8335
53f11dc #8218 'Fix errors reported by PVS'
d05712f inccommand: pause :terminal redraws (#8307)
51af911 inccommand: do not execute trailing commands #8256
84359a4 terminal: resize to the max dimensions (#8249)
d49c1dd #8228 Make vim_fgets() return the same values as in Vim
60e96a4 screen: winhl=Normal:Background should not override syntax (#8093)
0c59ac1 #5908 'shada: Also save numbered marks'
ba87a2c cscope: ignore EINTR while reading the prompt (#8079)
b1412dc #7971 ':terminal Enter/Leave should not increment jumplist'
3a5721e TUI: libtermkey: force CSI driver for mouse input #7948
6ff13d7 #7720 TUI: faster startup
1c6e956 #7862 TUI: fix resize-related segfaults
a58c909 #7676 TUI: always hide cursor when flushing, never flush buffers during unibilium output
303e1df #7624 TUI: disable BCE almost always
249bdb0 #7761 mark: Make sure that jumplist item will not have zero lnum
6f41ce0 #7704 macOS: Set $LANG based on the system locale
a043899 #7633 'Retry fgets on EINTR'

CHANGES:
ad60927 #8304 default to 'nofsync'
f3f1970 #8035 defaults: 'fillchars'
a6052c7 #7984 defaults: sidescroll=1
b69fa86 #7888 defaults: enable cscopeverbose
7c4bb23 defaults: do :filetype stuff unless explicitly "off"
2aa308c #5658 'Apply :lmap in macros'
8ce6393 terminal: Leave 'relativenumber' alone (#8360)
e46534b #4486 refactor: Remove maxmem, maxmemtot options
131aad9 win: defaults: 'shellcmdflag', 'shellxquote' #7343
c57d315 #8031 jobwait(): return -2 on interrupt also with timeout
6452831 clipboard: macOS: fallback to tmux if pbcopy is broken #7940
300d365 #7919 Make 'langnoremap' apply directly after a map
ada1956 #7880 'lua/executor: Remove lightuserdata'

INTERNAL:
de0a954 #7806 internal statistics for list impl
dee78a4 #7708 rewrite internal list impl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api libnvim, Nvim RPC API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants