Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display weird when use ASCII art. #245

Closed
singlexyz opened this issue Jun 6, 2024 · 2 comments
Closed

Display weird when use ASCII art. #245

singlexyz opened this issue Jun 6, 2024 · 2 comments

Comments

@singlexyz
Copy link

vim.system({ "cowsay", "hello world" }, { text = true }, function (obj)
  vim.schedule(function ()
    require("fidget").notify(obj.stdout) -- display weird
    vim.notify(obj.stdout) -- display fine
  end)
end)

require("fidget").notify

image

Default vim.notify

image
@j-hui
Copy link
Owner

j-hui commented Jun 6, 2024

Yeah, this happens because Fidget right-aligns the lines of text it is given.

You can fix that by padding the lines of text with spaces like this:

local function pad_lines(s)
    local lines = vim.split(s, "\n")
    local w = 0
    for _, line in ipairs(lines) do
      w = math.max(w, #line)
    end
    for l, line in ipairs(lines) do
      lines[l] = line .. string.rep(" ", w - #line)
    end
    return table.concat(lines, "\n")
end

vim.system({ "cowsay", "hello world" }, { text = true }, function (obj)
  vim.schedule(function ()
    local stdout = pad_lines(obj.stdout)
    require("fidget").notify(stdout) -- display fixed?
    vim.notify(stdout) -- display fine
  end)
end)

@singlexyz
Copy link
Author

Yeah, this happens because Fidget right-aligns the lines of text it is given.

You can fix that by padding the lines of text with spaces like this:

local function pad_lines(s)
    local lines = vim.split(s, "\n")
    local w = 0
    for _, line in ipairs(lines) do
      w = math.max(w, #line)
    end
    for l, line in ipairs(lines) do
      lines[l] = line .. string.rep(" ", w - #line)
    end
    return table.concat(lines, "\n")
end

vim.system({ "cowsay", "hello world" }, { text = true }, function (obj)
  vim.schedule(function ()
    local stdout = pad_lines(obj.stdout)
    require("fidget").notify(stdout) -- display fixed?
    vim.notify(stdout) -- display fine
  end)
end)

nice-good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants