From b96a64f3717c1ef01c4014dbe10fa57e01cd142a Mon Sep 17 00:00:00 2001 From: Mustache Dom <123716453+Mustachedom@users.noreply.github.com> Date: Mon, 29 Sep 2025 01:31:46 -0700 Subject: [PATCH] feature Prints now auto formats json to go downwards in prints so its easier to read `useCase` ```lua Prints.Debug('GTA', 5, {is = true, cool = true}) ``` --- lib/utility/shared/prints.lua | 63 ++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 16 deletions(-) diff --git a/lib/utility/shared/prints.lua b/lib/utility/shared/prints.lua index 6b73522..5c44b64 100644 --- a/lib/utility/shared/prints.lua +++ b/lib/utility/shared/prints.lua @@ -1,34 +1,65 @@ Prints = Prints or {} -local function printMessage(level, color, message) - if type(message) == 'table' then - message = json.encode(message) + +local function handle(result, value) + if type(value) == 'function' then + return tostring(value) end - print(color .. '[' .. level .. ']:', message) + return result end - ----This will print a colored message to the console with the designated prefix. ----@param message string -Prints.Info = function(message) - printMessage('INFO', '^5', message) +local function format(color, ...) + local data = {...} + for i = 1, #data do + if data[i] == nil then + data[i] = 'nil' + end + end + local newForm = {} + local jsonDecode = {sort_keys = true, indent = true, exception = handle} + for k, v in pairs(data) do + local formatted + if type(v) == 'table' then + formatted = json.encode(v, jsonDecode) + elseif type(v) == 'number' then + formatted = tostring(v) + elseif type(v) == 'boolean' then + formatted = tostring(v) + elseif type(v) == 'nil' then + formatted = 'nil Value' + elseif type(v) == 'string' then + formatted = v + elseif type(v) == 'function' then + formatted = tostring(v) + else + formatted = tostring(v) + end + table.insert(newForm, color .. formatted) + end + return table.concat(newForm, color .. ' \n ') end ---This will print a colored message to the console with the designated prefix. ---@param message string -Prints.Warn = function(message) - printMessage('WARN', '^3', message) +Prints.Info = function(...) + print('^5 [INFO] '.. format('^5 ', ...)) end ---This will print a colored message to the console with the designated prefix. ---@param message string -Prints.Error = function(message) - printMessage('ERROR', '^1', message) +Prints.Warn = function(...) + print('^3 [WARN] '.. format('^3', ...)) end ---This will print a colored message to the console with the designated prefix. ---@param message string -Prints.Debug = function(message) - printMessage('DEBUG', '^2', message) +Prints.Error = function(...) + print('^1 [ERROR] '.. format('^1', ...)) end -return Prints \ No newline at end of file +---This will print a colored message to the console with the designated prefix. +---@param message string +Prints.Debug = function(...) + print('^2 [DEBUG] '.. format('^2', ...)) +end + +return Prints