Skip to content

Instantly share code, notes, and snippets.

@b0o
Last active April 19, 2024 06:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save b0o/eba7cda63ee7f7eb27f70936c1fda90b to your computer and use it in GitHub Desktop.
Save b0o/eba7cda63ee7f7eb27f70936c1fda90b to your computer and use it in GitHub Desktop.
local n = require 'nui-components'
local signal = n.create_signal {
name = '',
description = '',
}
local function test_ui()
local renderer = n.create_renderer {
width = 60,
height = 12,
}
local body = function()
return n.rows(
n.paragraph {
is_focusable = false,
lines = signal.name:dup():map(function(name)
return {
-- Use math.random so we can see when renders occur:
n.line(n.text('Name: ', 'Keyword'), name .. ' (' .. math.random(1, 100) .. ')'),
}
end),
},
n.paragraph {
is_focusable = false,
lines = signal.description:dup():map(function(description)
return {
-- Use math.random so we can see when renders occur
n.line(n.text('Description: ', 'Keyword'), description .. ' (' .. math.random(1, 100) .. ')'),
}
end),
},
n.gap(1),
n.form(
{ id = 'form' },
n.text_input {
autofocus = true,
max_lines = 1,
border_label = 'Name',
on_change = function(val)
signal.name = val
end,
},
n.text_input {
max_lines = 1,
border_label = 'Description',
on_change = function(val)
signal.description = val
end,
}
)
)
end
renderer:render(body)
end
vim.api.nvim_create_user_command('TestUI', test_ui, {})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment