From 3c01f6bf79c51e952d4d985474d151176d74260b Mon Sep 17 00:00:00 2001 From: Steven Arcangeli Date: Sat, 4 Dec 2021 12:50:09 -0800 Subject: [PATCH] test: add a test for input highlighting --- test/manual/highlight.lua | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 test/manual/highlight.lua diff --git a/test/manual/highlight.lua b/test/manual/highlight.lua new file mode 100644 index 0000000..3a0da87 --- /dev/null +++ b/test/manual/highlight.lua @@ -0,0 +1,30 @@ +-- Run this test with :source % + +vim.cmd([[ + highlight RBP1 guibg=Red ctermbg=red + highlight RBP2 guibg=Yellow ctermbg=yellow + highlight RBP3 guibg=Green ctermbg=green + highlight RBP4 guibg=Blue ctermbg=blue +]]) +local rainbow_levels = 4 +local function rainbow_hl(cmdline) + local ret = {} + local lvl = 0 + for i = 1, string.len(cmdline) do + local char = string.sub(cmdline, i, i) + if char == "(" then + table.insert(ret, { i - 1, i, string.format("RBP%d", (lvl % rainbow_levels) + 1) }) + lvl = lvl + 1 + elseif char == ")" then + lvl = lvl - 1 + table.insert(ret, { i - 1, i, string.format("RBP%d", (lvl % rainbow_levels) + 1) }) + end + end + return ret +end + +vim.ui.input({ + prompt = "Rainbow: ", + default = "((()(())))", + highlight = rainbow_hl, +}, function() end)