diff --git a/modules/client_terminal/terminal.lua b/modules/client_terminal/terminal.lua index 2ee2cd24..62a6878b 100644 --- a/modules/client_terminal/terminal.lua +++ b/modules/client_terminal/terminal.lua @@ -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 addLine(text, color) - -- delete old lines if needed - local numLines = terminalBuffer:getChildCount() + 1 - if numLines > MaxLogLines then - terminalBuffer:getChildByIndex(1):destroy() +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 - -- create new line label - local label = g_ui.createWidget('TerminalLabel', terminalBuffer) - label:setId('terminalLabel' .. numLines) - label:setText(text) - label:setColor(color) + terminalSelectText:setText(fulltext) + + cachedLines = {} + flushEvent = nil +end + +function addLine(text, color) + if not flushEvent then + flushEvent = scheduleEvent(flushLines, 10) + end - terminalSelectText:setText(terminalSelectText:getText() .. '\n' .. text) + table.insert(cachedLines, {text=text, color=color}) end function executeCommand(command) diff --git a/modules/client_terminal/terminal.otui b/modules/client_terminal/terminal.otui index c9729e92..afcd0a26 100644 --- a/modules/client_terminal/terminal.otui +++ b/modules/client_terminal/terminal.otui @@ -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 diff --git a/modules/corelib/ui/uiscrollarea.lua b/modules/corelib/ui/uiscrollarea.lua index d45f692d..ff8b375a 100644 --- a/modules/corelib/ui/uiscrollarea.lua +++ b/modules/corelib/ui/uiscrollarea.lua @@ -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 diff --git a/src/framework/ui/uitextedit.cpp b/src/framework/ui/uitextedit.cpp index f0adefe5..28974ca3 100644 --- a/src/framework/ui/uitextedit.cpp +++ b/src/framework/ui/uitextedit.cpp @@ -70,9 +70,11 @@ void UITextEdit::drawSelf(Fw::DrawPane drawPane) return; if(hasSelection()) { - g_painter->setColor(m_color); - for(int i=0;idrawTexturedRect(m_glyphsCoords[i], texture, m_glyphsTexCoords[i]); + if(m_color != Color::alpha) { + g_painter->setColor(m_color); + for(int i=0;idrawTexturedRect(m_glyphsCoords[i], texture, m_glyphsTexCoords[i]); + } for(int i=m_selectionStart;isetColor(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;idrawTexturedRect(m_glyphsCoords[i], texture, m_glyphsTexCoords[i]); - } else { + if(m_color != Color::alpha) { + g_painter->setColor(m_color); + for(int i=m_selectionEnd;idrawTexturedRect(m_glyphsCoords[i], texture, m_glyphsTexCoords[i]); + } + } else if(m_color != Color::alpha) { g_painter->setColor(m_color); for(int i=0;idrawTexturedRect(m_glyphsCoords[i], texture, m_glyphsTexCoords[i]);