Skip to content

Commit

Permalink
Remove baleia #11
Browse files Browse the repository at this point in the history
  • Loading branch information
quolpr committed Jan 15, 2025
1 parent 3a6ee82 commit fd5f4d8
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 50 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- **Live-Scrolling Results:** Continuously scroll through test results as they are generated. But stop scrolling if you decided to scroll up.
- **Real-Time Feedback:** View the results of tests immediately as they run, without waiting for the completion of the test suite.
- **Test Duration Timer:** Display a timer to monitor the duration of ongoing tests.
- **ANSI colors** _EXPERIMETAL_
- **ANSI colors** builtin support.
- **Easy to write your own adapter:** It's just all about running cmd and piping results to `quicktest`.

https://github.com/user-attachments/assets/9fcb3e17-f521-4660-9d9a-d9f763de5a1b
Expand All @@ -31,7 +31,7 @@ With Lazy:
},
-- split or popup mode, when argument not specified
default_win_mode = "split",
use_experimental_colorizer = true
use_builtin_colorizer = true
})
end,
dependencies = {
Expand Down Expand Up @@ -125,7 +125,7 @@ qt.setup({
},
-- split or popup mode, when argument not specified
default_win_mode = "split",
use_experimental_colorizer = true
use_builtin_colorizer = true
})

vim.keymap.set("n", "<leader>tl", qt.run_line, {
Expand Down Expand Up @@ -255,8 +255,6 @@ qt.setup({
},
-- split or popup mode, when argument not specified
default_win_mode = "split",
-- Baleia make coloured output. Requires baleia package. Can cause crashes https://github.com/quolpr/quicktest.nvim/issues/11
use_baleia = false
})

-- Find nearest test under cursor and run in popup
Expand Down
3 changes: 1 addition & 2 deletions lua/quicktest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ local module = require("quicktest.module")
local config = {
adapters = {},
default_win_mode = "split",
use_baleia = false,
use_experimental_colorizer = false,
use_builtin_colorizer = true,
popup_options = {
enter = true,
focusable = true,
Expand Down
6 changes: 5 additions & 1 deletion lua/quicktest/adapters/vitest/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,11 @@ M.run = function(params, send)

job:start()

return job.pid
---@type integer
---@diagnostic disable-next-line: assign-type-mismatch
local pid = job.pid

return pid
end

-- ---@param params VitestRunParams
Expand Down
28 changes: 14 additions & 14 deletions lua/quicktest/colored_printer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ end
function ColoredPrinter:setup_highlight_groups()
local basic_colors = {
["30"] = "Black",
["31"] = "DarkRed",
["32"] = "DarkGreen",
["33"] = "DarkYellow",
["34"] = "DarkBlue",
["35"] = "DarkMagenta",
["36"] = "DarkCyan",
["37"] = "LightGrey",
["90"] = "DarkGrey",
["91"] = "LightRed",
["92"] = "LightGreen",
["93"] = "LightYellow",
["94"] = "LightBlue",
["95"] = "LightMagenta",
["96"] = "LightCyan",
["31"] = "Red",
["32"] = "Green",
["33"] = "Yellow",
["34"] = "Blue",
["35"] = "Magenta",
["36"] = "Cyan",
["37"] = "White",
["90"] = "Grey",
["91"] = "Red",
["92"] = "Green",
["93"] = "Yellow",
["94"] = "Blue",
["95"] = "Magenta",
["96"] = "Cyan",
["97"] = "White",
}

Expand Down
40 changes: 12 additions & 28 deletions lua/quicktest/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ local M = {}
---@class QuicktestConfig
---@field adapters QuicktestAdapter[]
---@field default_win_mode WinModeWithoutAuto
---@field use_baleia boolean
---@field use_experimental_colorizer boolean
---@field use_builtin_colorizer boolean

--- @type {id: number, started_at: number, pid: number?} | nil
local current_job = nil
Expand Down Expand Up @@ -74,16 +73,6 @@ local function get_adapter_by_name(adapters, name)
return adapter
end

local baleia_pkg = nil
local get_baleia = function()
if baleia_pkg then
return baleia_pkg
else
baleia_pkg = require("baleia").setup({ name = "QuicktestOutputColors" })
return baleia_pkg
end
end

--- @param adapter QuicktestAdapter
--- @param params any
--- @param config QuicktestConfig
Expand All @@ -98,22 +87,17 @@ function M.run(adapter, params, config, opts)
end
end

local set_ansi_lines = vim.api.nvim_buf_set_lines
if config.use_baleia then
set_ansi_lines = get_baleia().buf_set_lines
else
--- @param buf integer
--- @param start integer
--- @param finish number
--- @param strict_indexing boolean
--- @param replacements string[]
set_ansi_lines = function(buf, start, finish, strict_indexing, replacements)
local new_lines = {}
for i, line in ipairs(replacements) do
new_lines[i] = string.gsub(line, "[\27\155][][()#;?%d]*[A-PRZcf-ntqry=><~]", "")
end
vim.api.nvim_buf_set_lines(buf, start, finish, strict_indexing, new_lines)
--- @param buf integer
--- @param start integer
--- @param finish number
--- @param strict_indexing boolean
--- @param replacements string[]
local set_ansi_lines = function(buf, start, finish, strict_indexing, replacements)
local new_lines = {}
for i, line in ipairs(replacements) do
new_lines[i] = string.gsub(line, "[\27\155][][()#;?%d]*[A-PRZcf-ntqry=><~]", "")
end
vim.api.nvim_buf_set_lines(buf, start, finish, strict_indexing, new_lines)
end

local printer = colorized_printer.new()
Expand Down Expand Up @@ -225,7 +209,7 @@ function M.run(adapter, params, config, opts)
table.insert(lines, "")
table.insert(lines, "")

if config.use_experimental_colorizer then
if config.use_builtin_colorizer then
printer:set_next_lines(lines, buf, 2)
else
local line_count = vim.api.nvim_buf_line_count(buf)
Expand Down

0 comments on commit fd5f4d8

Please sign in to comment.