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

Does not support newlines from anything printed (like love.errorhandler) #8

Open
NicePotato-MS opened this issue Mar 27, 2023 · 4 comments

Comments

@NicePotato-MS
Copy link

NicePotato-MS commented Mar 27, 2023

it just goes offscreen

@NicePotato-MS
Copy link
Author

I have fixed the function myself, and opened a pull request #9

I changed the add_to_output from

function add_to_output(...)
    local arg = {...}
    local narg = select("#", ...)

    for i = 1, narg do
        arg[i] = tostring(arg[i])
    end

    msg = parse.color(table.concat(arg, " "))
    table.insert(output_buffer, msg)
end

to

function splitString(...)
    local lines = {}
    for _, str in ipairs({...}) do
      for line in str:gmatch("[^\r\n]+") do
        table.insert(lines, line)
      end
    end
    return lines
end  

function add_to_output(...)
    for k, arg in ipairs(splitString(...)) do
        msg = parse.color(table.concat({arg}, " "))
        table.insert(output_buffer, msg)
    end
end

@NicePotato-MS
Copy link
Author

Updated to support some edge cases

function splitString(...)
	local lines = {}
	for _, arg in ipairs({...}) do
	  	if arg == nil then
			-- Handle nil values
			table.insert(lines, "<nil>")
	 	 elseif type(arg) ~= "string" and type(arg) ~= "boolean" then
			-- Handle non-string and non-boolean values
			table.insert(lines, tostring(arg))
	  	else
			local str = tostring(arg)
		if type(arg) == "boolean" then
		  -- Convert boolean values to lowercase strings
		  str = str:lower()
		end
			for line in str:gmatch("[^\r\n]*\r?\n") do
		  	-- Handle empty lines
		  	if line ~= "\r\n" and line ~= "\n" then
					table.insert(lines, line)
		  		end
			end
	  	end
	end
	return lines
end

@NicePotato-MS
Copy link
Author

You may actually want to check that, I'm not sure if that's completely correct

@NicePotato-MS
Copy link
Author

Yea, that actually completely breaks everything, adjust the first one

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

1 participant