Optimize terminal buffering
This commit is contained in:
parent
9312d20a0f
commit
dad3026ba0
|
@ -3,8 +3,7 @@ local LogColors = { [LogDebug] = 'pink',
|
|||
[LogInfo] = 'white',
|
||||
[LogWarning] = 'yellow',
|
||||
[LogError] = 'red' }
|
||||
local MaxLogLines = 512
|
||||
local LabelHeight = 16
|
||||
local MaxLogLines = 128
|
||||
local MaxHistory = 1000
|
||||
|
||||
local oldenv = getfenv(0)
|
||||
|
@ -24,6 +23,9 @@ local poped = false
|
|||
local oldPos
|
||||
local oldSize
|
||||
local firstShown = false
|
||||
local flushEvent
|
||||
local cachedLines = {}
|
||||
local disabled = false
|
||||
|
||||
-- private functions
|
||||
local function navigateCommand(step)
|
||||
|
@ -104,6 +106,7 @@ local function doCommand()
|
|||
end
|
||||
|
||||
local function onLog(level, message, time)
|
||||
if disabled then return end
|
||||
-- avoid logging while reporting logs (would cause a infinite loop)
|
||||
if logLocked then return end
|
||||
|
||||
|
@ -137,9 +140,11 @@ function init()
|
|||
g_keyboard.bindKeyDown('Enter', doCommand, commandTextEdit)
|
||||
g_keyboard.bindKeyDown('Escape', hide, terminalWindow)
|
||||
|
||||
terminalBuffer = terminalWindow:recursiveGetChildById('terminalBuffer')
|
||||
terminalSelectText = terminalWindow:recursiveGetChildById('terminalSelectText')
|
||||
terminalBuffer = terminalWindow:getChildById('terminalBuffer')
|
||||
terminalSelectText = terminalWindow:getChildById('terminalSelectText')
|
||||
terminalSelectText.onDoubleClick = popWindow
|
||||
terminalSelectText.onMouseWheel = function(a,b,c) terminalBuffer:onMouseWheel(b,c) end
|
||||
terminalBuffer.onScrollChange = function(self, value) terminalSelectText:setTextVirtualOffset(value) end
|
||||
|
||||
g_logger.setOnLog(onLog)
|
||||
g_logger.fireOldMessages()
|
||||
|
@ -148,6 +153,8 @@ end
|
|||
function terminate()
|
||||
g_settings.setList('terminal-history', commandHistory)
|
||||
|
||||
removeEvent(flushEvent)
|
||||
|
||||
if poped then
|
||||
oldPos = terminalWindow:getPosition()
|
||||
oldSize = terminalWindow:getSize()
|
||||
|
@ -231,22 +238,41 @@ end
|
|||
function disable()
|
||||
terminalButton:hide()
|
||||
g_keyboard.unbindKeyDown('Ctrl+T')
|
||||
disabled = true
|
||||
end
|
||||
|
||||
function flushLines()
|
||||
local numLines = terminalBuffer:getChildCount() + #cachedLines
|
||||
local fulltext = terminalSelectText:getText()
|
||||
|
||||
for _,line in pairs(cachedLines) do
|
||||
-- delete old lines if needed
|
||||
if numLines > MaxLogLines then
|
||||
local len = #terminalBuffer:getChildByIndex(1):getText()
|
||||
terminalBuffer:getChildByIndex(1):destroy()
|
||||
fulltext = string.sub(fulltext, len)
|
||||
end
|
||||
|
||||
local label = g_ui.createWidget('TerminalLabel', terminalBuffer)
|
||||
label:setId('terminalLabel' .. numLines)
|
||||
label:setText(line.text)
|
||||
label:setColor(line.color)
|
||||
|
||||
fulltext = fulltext .. '\n' .. line.text
|
||||
end
|
||||
|
||||
terminalSelectText:setText(fulltext)
|
||||
|
||||
cachedLines = {}
|
||||
flushEvent = nil
|
||||
end
|
||||
|
||||
function addLine(text, color)
|
||||
-- delete old lines if needed
|
||||
local numLines = terminalBuffer:getChildCount() + 1
|
||||
if numLines > MaxLogLines then
|
||||
terminalBuffer:getChildByIndex(1):destroy()
|
||||
if not flushEvent then
|
||||
flushEvent = scheduleEvent(flushLines, 10)
|
||||
end
|
||||
|
||||
-- create new line label
|
||||
local label = g_ui.createWidget('TerminalLabel', terminalBuffer)
|
||||
label:setId('terminalLabel' .. numLines)
|
||||
label:setText(text)
|
||||
label:setColor(color)
|
||||
|
||||
terminalSelectText:setText(terminalSelectText:getText() .. '\n' .. text)
|
||||
table.insert(cachedLines, {text=text, color=color})
|
||||
end
|
||||
|
||||
function executeCommand(command)
|
||||
|
|
|
@ -42,29 +42,23 @@ UIWindow
|
|||
visible: false
|
||||
|
||||
ScrollablePanel
|
||||
id: terminalScrollArea
|
||||
id: terminalBuffer
|
||||
focusable: false
|
||||
anchors.left: parent.left
|
||||
anchors.right: terminalScroll.left
|
||||
anchors.top: terminalScroll.top
|
||||
anchors.bottom: commandSymbolLabel.top
|
||||
layout:
|
||||
type: verticalBox
|
||||
align-bottom: true
|
||||
vertical-scrollbar: terminalScroll
|
||||
inverted-scroll: true
|
||||
margin-left: 2
|
||||
|
||||
Panel
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
id: terminalBuffer
|
||||
layout:
|
||||
type: verticalBox
|
||||
fit-children: true
|
||||
focusable: false
|
||||
|
||||
TerminalSelectText
|
||||
id: terminalSelectText
|
||||
anchors.fill: terminalBuffer
|
||||
TerminalSelectText
|
||||
id: terminalSelectText
|
||||
anchors.fill: terminalBuffer
|
||||
focusable: false
|
||||
|
||||
VerticalScrollBar
|
||||
id: terminalScroll
|
||||
|
|
|
@ -73,23 +73,23 @@ end
|
|||
|
||||
function UIScrollArea:setVerticalScrollBar(scrollbar)
|
||||
self.verticalScrollBar = scrollbar
|
||||
self.verticalScrollBar.onValueChange = function(scrollbar, value)
|
||||
connect(self.verticalScrollBar, 'onValueChange', function(scrollbar, value)
|
||||
local virtualOffset = self:getVirtualOffset()
|
||||
virtualOffset.y = value
|
||||
self:setVirtualOffset(virtualOffset)
|
||||
if self.onScrollbarChange then self:onScrollbarChange(value) end
|
||||
end
|
||||
signalcall(self.onScrollChange, self, virtualOffset)
|
||||
end)
|
||||
self:updateScrollBars()
|
||||
end
|
||||
|
||||
function UIScrollArea:setHorizontalScrollBar(scrollbar)
|
||||
self.horizontalScrollBar = scrollbar
|
||||
self.horizontalScrollBar.onValueChange = function(scrollbar, value)
|
||||
connect(self.horizontalScrollBar, 'onValueChange', function(scrollbar, value)
|
||||
local virtualOffset = self:getVirtualOffset()
|
||||
virtualOffset.x = value
|
||||
self:setVirtualOffset(virtualOffset)
|
||||
if self.onScrollbarChange then self:onScrollbarChange(value) end
|
||||
end
|
||||
signalcall(self.onScrollChange, self, virtualOffset)
|
||||
end)
|
||||
self:updateScrollBars()
|
||||
end
|
||||
|
||||
|
|
|
@ -70,9 +70,11 @@ void UITextEdit::drawSelf(Fw::DrawPane drawPane)
|
|||
return;
|
||||
|
||||
if(hasSelection()) {
|
||||
g_painter->setColor(m_color);
|
||||
for(int i=0;i<m_selectionStart;++i)
|
||||
g_painter->drawTexturedRect(m_glyphsCoords[i], texture, m_glyphsTexCoords[i]);
|
||||
if(m_color != Color::alpha) {
|
||||
g_painter->setColor(m_color);
|
||||
for(int i=0;i<m_selectionStart;++i)
|
||||
g_painter->drawTexturedRect(m_glyphsCoords[i], texture, m_glyphsTexCoords[i]);
|
||||
}
|
||||
|
||||
for(int i=m_selectionStart;i<m_selectionEnd;++i) {
|
||||
g_painter->setColor(m_selectionBackgroundColor);
|
||||
|
@ -81,10 +83,12 @@ void UITextEdit::drawSelf(Fw::DrawPane drawPane)
|
|||
g_painter->drawTexturedRect(m_glyphsCoords[i], texture, m_glyphsTexCoords[i]);
|
||||
}
|
||||
|
||||
g_painter->setColor(m_color);
|
||||
for(int i=m_selectionEnd;i<textLength;++i)
|
||||
g_painter->drawTexturedRect(m_glyphsCoords[i], texture, m_glyphsTexCoords[i]);
|
||||
} else {
|
||||
if(m_color != Color::alpha) {
|
||||
g_painter->setColor(m_color);
|
||||
for(int i=m_selectionEnd;i<textLength;++i)
|
||||
g_painter->drawTexturedRect(m_glyphsCoords[i], texture, m_glyphsTexCoords[i]);
|
||||
}
|
||||
} else if(m_color != Color::alpha) {
|
||||
g_painter->setColor(m_color);
|
||||
for(int i=0;i<textLength;++i)
|
||||
g_painter->drawTexturedRect(m_glyphsCoords[i], texture, m_glyphsTexCoords[i]);
|
||||
|
|
Loading…
Reference in New Issue