Last active
April 19, 2024 06:40
-
-
Save b0o/eba7cda63ee7f7eb27f70936c1fda90b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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