MunifTanjim / nui.nvim

UI Component Library for Neovim.
MIT License
1.62k stars 57 forks source link

add Item to Menu #323

Closed Cris-lml007 closed 9 months ago

Cris-lml007 commented 9 months ago

i want add new item to menu, but i not know how do. this my code:

local Input=require('nui.input')
local Menu=require('nui.menu')
local Layout=require('nui.layout')
require('file')

local lin=loadSessions()

local menu=Menu({
    enter=false,
    border='double'
    },{
        lines=lin,
        max_width=20,
        keymap={
            focus_next="<Down>",
            focus_prev="<Up>",
            close="<Esc>",
            submit="<CR>"
        }
    }
)

local input=Input({
    enter=true,
    border={
        style='double',
        text={
            top="Sessions",
            top_align='center'
        }
    },
},{
    prompt="> ",
    on_change=function (value)
        --update lines of menu
    end
}
)

local layout=Layout(
    {
        position="50%",
        size={
            width="60%",
            height="60%",
        }
    },
    Layout.Box({
        Layout.Box(input,{size="10%"}),
        Layout.Box(menu,{size="50%"})
    },{dir='col'})
)

layout:mount()
MunifTanjim commented 9 months ago

Menu should only be used when it's directly interactive. If you're only using it to display some lines, you should use Popup + NuiTree instead.

local popup = Popup({
  border = 'double',
})

local tree = Tree({
  bufnr = popup.bufnr,
  nodes = {
    Tree.Node({ text = "A" }),
    Tree.Node({ text = "B" }),
  },
})

tree:render()

Then for adding new item:

tree:add_node(Tree.Node({ text = "C" }))
tree:render()
Cris-lml007 commented 9 months ago

mmmmmmm....it is not expected.