Skip to content

Commit

Permalink
Split console output into shorter lines to improve memory usage and h…
Browse files Browse the repository at this point in the history
…andling.
  • Loading branch information
pkulchenko committed Dec 3, 2014
1 parent 395fb2e commit d6593ab
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/editor/shellbox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

local ide = ide
local unpack = table.unpack or unpack
--
-- shellbox - a lua testbed environment within the IDE
--

local bottomnotebook = ide.frame.bottomnotebook
local out = bottomnotebook.shellbox
Expand Down Expand Up @@ -147,8 +144,23 @@ local function shellPrint(marker, ...)
local x = select(i,...)
text = text .. tostring(x)..(i < cnt and "\t" or "")
end

-- split the text into smaller chunks as one large line
-- is difficult to handle for the editor
local prev, maxlength = 0, ide.config.debugger.maxdatalength
if #text > maxlength and not text:find("\n.") then
text = text:gsub("()(%s+)", function(p, s)
if p-prev >= maxlength then
prev = p
return "\n"
else
return s
end
end)
end

-- add "\n" if it is missing
if text then text = text:gsub("\n+$", "") .. "\n" end
text = text:gsub("\n+$", "") .. "\n"

local lines = out:GetLineCount()
local promptLine = isPrompt and getPromptLine() or nil
Expand Down

0 comments on commit d6593ab

Please sign in to comment.