Optimize the terminal output speed

This commit is contained in:
Markus Gans 2020-10-19 23:38:12 +02:00
parent 6a8459c52b
commit 3c467c9c07
32 changed files with 70 additions and 212 deletions

View File

@ -1,3 +1,6 @@
2020-10-19 Markus Gans <guru.mail@muenster.de>
* Optimize the terminal output speed
2020-10-17 Markus Gans <guru.mail@muenster.de>
* Fixes unit test segfault

View File

@ -183,7 +183,6 @@ void Background::cb_changed()
, int(green.getValue())
, int(blue.getValue()) );
redraw();
updateTerminal();
}
//----------------------------------------------------------------------
@ -205,7 +204,6 @@ void Background::cb_choice()
, int(green.getValue())
, int(blue.getValue()) );
redraw();
updateTerminal();
}
//----------------------------------------------------------------------

View File

@ -335,7 +335,6 @@ void Calc::onKeyPress (finalcut::FKeyEvent* ev)
}
drawDispay();
updateTerminal();
}
ev->accept();
@ -394,7 +393,6 @@ void Calc::cb_buttonClicked (Calc::button key)
}
drawDispay();
updateTerminal();
if ( infix_operator && ! isDataEntryKey(key) )
input = "";

View File

@ -294,7 +294,6 @@ void EventLog::onTimer (finalcut::FTimerEvent*)
str("");
scrolltext.scrollToEnd();
redraw();
updateTerminal();
}
}

View File

@ -225,7 +225,7 @@ void RotoZoomer::onShow (finalcut::FShowEvent*)
for (path = 1; path < loops; path++)
{
redraw();
updateTerminal();
processTerminalUpdate();
}
end = system_clock::now();
@ -244,8 +244,6 @@ void RotoZoomer::onTimer (finalcut::FTimerEvent*)
path++;
redraw();
updateTerminal();
flush();
}
//----------------------------------------------------------------------

View File

@ -237,8 +237,6 @@ void MainWindow::draw()
if ( finalcut::FTerm::isMonochron() )
setReverse(false);
updateTerminal();
}
//----------------------------------------------------------------------

View File

@ -159,9 +159,6 @@ void ProgressDialog::onTimer (finalcut::FTimerEvent*)
if ( getStatusBar() )
getStatusBar()->drawMessage();
updateTerminal();
flush();
}
//----------------------------------------------------------------------

View File

@ -153,7 +153,6 @@ void SmallWindow::onTimer (finalcut::FTimerEvent*)
top_right_label.redraw();
bottom_label.unsetEmphasis();
bottom_label.redraw();
updateTerminal();
delOwnTimers();
}
@ -344,8 +343,6 @@ void Window::activateWindow (finalcut::FDialog* win) const
if ( has_raised )
win->redraw();
updateTerminal();
}
//----------------------------------------------------------------------

View File

@ -971,9 +971,6 @@ void FApplication::unselectMenubarItems() const
if ( FWidget::getStatusBar() )
FWidget::getStatusBar()->drawMessage();
updateTerminal();
flush();
}
}
@ -1290,13 +1287,13 @@ bool FApplication::processNextEvent()
if ( is_timeout )
{
FObject::getCurrentTime (&time_last_event);
processTerminalUpdate(); // before user input
processKeyboardEvent();
processMouseEvent();
processResizeEvent();
processTerminalUpdate();
processTerminalUpdate(); // after user input
processCloseWidget();
processLogger();
updateTerminal();
}
processExternalUserEvent();

View File

@ -50,8 +50,6 @@ void FBusyIndicator::start()
running = true;
createIndicatorText();
show();
updateTerminal();
flush();
addTimer(TIMER);
}
@ -61,8 +59,6 @@ void FBusyIndicator::stop()
delOwnTimers();
running = false;
hide();
updateTerminal();
flush();
}
@ -119,8 +115,6 @@ void FBusyIndicator::onTimer (finalcut::FTimerEvent*)
// Redraw the rotated pattern
createIndicatorText();
redraw();
updateTerminal();
flush();
}
} // namespace finalcut

View File

@ -331,8 +331,6 @@ void FButtonGroup::onFocusIn (FFocusEvent* in_ev)
if ( getStatusBar() )
{
getStatusBar()->drawMessage();
updateTerminal();
flush();
}
}
@ -507,8 +505,6 @@ void FButtonGroup::directFocus()
if ( getStatusBar() )
{
getStatusBar()->drawMessage();
updateTerminal();
flush();
}
}

View File

@ -102,8 +102,6 @@ void FDropDownListBox::hide()
setOpenMenu(nullptr);
const auto& t_geometry = getTermGeometryWithShadow();
restoreVTerm (t_geometry);
updateTerminal();
flush();
}
@ -428,8 +426,6 @@ void FComboBox::onMouseDown (FMouseEvent* ev)
else
list_window.hide();
}
updateTerminal();
}
//----------------------------------------------------------------------

View File

@ -447,8 +447,6 @@ void FDialog::activateDialog()
if ( getStatusBar() )
getStatusBar()->drawMessage();
updateTerminal();
}
//----------------------------------------------------------------------
@ -530,8 +528,7 @@ void FDialog::onMouseDown (FMouseEvent* ev)
else // ev->getButton() != fc::LeftButton
{
// Click on titlebar menu button
if ( ms.mouse_x < 4 && ms.mouse_y == 1
&& dialog_menu->isShown() )
if ( ms.mouse_x < 4 && ms.mouse_y == 1 && dialog_menu->isShown() )
leaveMenu(); // close menu
cancelMouseResize(); // Cancel resize
@ -690,8 +687,6 @@ void FDialog::onAccel (FAccelEvent*)
if ( has_raised )
redraw();
updateTerminal();
}
}
@ -717,8 +712,6 @@ void FDialog::onWindowActive (FEvent*)
if ( getStatusBar() )
getStatusBar()->drawMessage();
updateTerminal();
}
//----------------------------------------------------------------------
@ -1227,9 +1220,6 @@ void FDialog::leaveMenu()
if ( getStatusBar() )
getStatusBar()->drawMessage();
updateTerminal();
flush();
}
//----------------------------------------------------------------------
@ -1273,9 +1263,6 @@ void FDialog::selectFirstMenuItem()
if ( getStatusBar() )
getStatusBar()->drawMessage();
updateTerminal();
flush();
}
//----------------------------------------------------------------------
@ -1480,12 +1467,10 @@ inline void FDialog::raiseActivateDialog()
//----------------------------------------------------------------------
inline void FDialog::lowerActivateDialog()
{
const bool has_lowered = lowerWindow();
lowerWindow();
if ( ! isWindowActive() )
activateDialog();
else if ( has_lowered )
updateTerminal();
}
//----------------------------------------------------------------------
@ -1624,7 +1609,6 @@ void FDialog::cancelMouseResize()
resize_click_pos.setPoint (0, 0);
drawBorder();
updateTerminal();
}
//----------------------------------------------------------------------

View File

@ -205,11 +205,7 @@ void FLabel::onMouseDown (FMouseEvent* ev)
accel_widget->redraw();
if ( getStatusBar() )
{
accel_widget->getStatusBar()->drawMessage();
updateTerminal();
flush();
}
}
}
@ -232,11 +228,7 @@ void FLabel::onAccel (FAccelEvent* ev)
FApplication::sendEvent(accel_widget, &in);
if ( getStatusBar() )
{
accel_widget->getStatusBar()->drawMessage();
updateTerminal();
flush();
}
}
}

View File

@ -357,7 +357,7 @@ void FLineEdit::onKeyPress (FKeyEvent* ev)
&& key != fc::Fkey_enter )
{
drawInputField();
updateTerminal();
processTerminalUpdate();
}
}
@ -397,7 +397,7 @@ void FLineEdit::onMouseDown (FMouseEvent* ev)
adjustTextOffset();
drawInputField();
updateTerminal();
processTerminalUpdate();
}
}
@ -431,7 +431,7 @@ void FLineEdit::onMouseMove (FMouseEvent* ev)
adjustTextOffset();
drawInputField();
updateTerminal();
processTerminalUpdate();
}
// auto-scrolling when dragging mouse outside the widget
@ -534,7 +534,7 @@ void FLineEdit::onTimer (FTimerEvent*)
adjustTextOffset();
drawInputField();
updateTerminal();
processTerminalUpdate();
}
//----------------------------------------------------------------------
@ -554,11 +554,7 @@ void FLineEdit::onAccel (FAccelEvent* ev)
redraw();
if ( getStatusBar() )
{
getStatusBar()->drawMessage();
updateTerminal();
flush();
}
}
}
@ -584,11 +580,7 @@ void FLineEdit::onFocusIn (FFocusEvent*)
}
if ( getStatusBar() )
{
getStatusBar()->drawMessage();
updateTerminal();
flush();
}
}
//----------------------------------------------------------------------

View File

@ -352,8 +352,7 @@ void FListBox::onMouseDown (FMouseEvent* ev)
if ( yoffset_before != yoffset )
vbar->drawBar();
updateTerminal();
flush();
processTerminalUpdate();
}
}
@ -426,8 +425,7 @@ void FListBox::onMouseMove (FMouseEvent* ev)
if ( yoffset_before != yoffset )
vbar->drawBar();
updateTerminal();
flush();
processTerminalUpdate();
}
// Auto-scrolling when dragging mouse outside the widget
@ -504,8 +502,7 @@ void FListBox::onTimer (FTimerEvent*)
if ( yoffset_before != yoffset )
vbar->drawBar();
updateTerminal();
flush();
processTerminalUpdate();
}
//----------------------------------------------------------------------
@ -547,8 +544,7 @@ void FListBox::onWheel (FWheelEvent* ev)
if ( yoffset_before != yoffset )
vbar->drawBar();
updateTerminal();
flush();
processTerminalUpdate();
}
//----------------------------------------------------------------------
@ -1082,8 +1078,7 @@ inline void FListBox::updateDrawing (bool draw_vbar, bool draw_hbar)
if ( draw_hbar )
hbar->drawBar();
updateTerminal();
flush();
processTerminalUpdate();
}
//----------------------------------------------------------------------
@ -1803,8 +1798,7 @@ void FListBox::cb_vbarChange (const FWidget*)
if ( yoffset_before != yoffset )
vbar->drawBar();
updateTerminal();
flush();
processTerminalUpdate();
}
}
@ -1862,11 +1856,8 @@ void FListBox::cb_hbarChange (const FWidget*)
inc_search.clear();
if ( isShown() )
{
drawList();
updateTerminal();
flush();
}
if ( scrollType >= FScrollbar::scrollStepBackward )
{
@ -1875,8 +1866,7 @@ void FListBox::cb_hbarChange (const FWidget*)
if ( xoffset_before != xoffset )
hbar->drawBar();
updateTerminal();
flush();
processTerminalUpdate();
}
}

View File

@ -1116,8 +1116,7 @@ void FListView::onMouseDown (FMouseEvent* ev)
if ( first_line_position_before != first_visible_line.getPosition() )
vbar->drawBar();
updateTerminal();
flush();
processTerminalUpdate();
}
}
}
@ -1221,8 +1220,7 @@ void FListView::onMouseMove (FMouseEvent* ev)
if ( first_line_position_before != first_visible_line.getPosition() )
vbar->drawBar();
updateTerminal();
flush();
processTerminalUpdate();
}
// auto-scrolling when dragging mouse outside the widget
@ -1308,8 +1306,7 @@ void FListView::onTimer (FTimerEvent*)
if ( first_line_position_before != first_visible_line.getPosition() )
vbar->drawBar();
updateTerminal();
flush();
processTerminalUpdate();
}
//----------------------------------------------------------------------
@ -1347,8 +1344,7 @@ void FListView::onWheel (FWheelEvent* ev)
if ( first_line_position_before != first_visible_line.getPosition() )
vbar->drawBar();
updateTerminal();
flush();
processTerminalUpdate();
}
//----------------------------------------------------------------------
@ -2152,8 +2148,7 @@ void FListView::updateDrawing (bool draw_vbar, bool draw_hbar)
if ( draw_hbar )
hbar->drawBar();
updateTerminal();
flush();
processTerminalUpdate();
}
//----------------------------------------------------------------------
@ -2872,8 +2867,7 @@ void FListView::cb_vbarChange (const FWidget*)
if ( first_line_position_before != first_visible_line.getPosition() )
vbar->drawBar();
updateTerminal();
flush();
processTerminalUpdate();
}
}
@ -2929,8 +2923,6 @@ void FListView::cb_hbarChange (const FWidget*)
{
drawHeadlines();
drawList();
updateTerminal();
flush();
}
if ( scrollType >= FScrollbar::scrollStepBackward )
@ -2940,8 +2932,7 @@ void FListView::cb_hbarChange (const FWidget*)
if ( xoffset_before != xoffset )
hbar->drawBar();
updateTerminal();
flush();
processTerminalUpdate();
}
}

View File

@ -110,8 +110,6 @@ void FMenu::hide()
FWindow::hide();
const auto& t_geometry = getTermGeometryWithShadow();
restoreVTerm (t_geometry);
updateTerminal();
flush();
if ( ! isSubMenu() )
{
@ -206,9 +204,6 @@ void FMenu::onMouseDown (FMouseEvent* ev)
if ( getStatusBar() )
getStatusBar()->drawMessage();
updateTerminal();
flush();
}
return;
@ -316,8 +311,7 @@ void FMenu::onMouseMove (FMouseEvent* ev)
else if ( ms.hide_sub_menu )
{
closeOpenedSubMenu();
updateTerminal();
flush();
processTerminalUpdate();
}
}
@ -615,9 +609,6 @@ void FMenu::openSubMenu (FMenu* sub_menu, bool select)
if ( getStatusBar() )
getStatusBar()->drawMessage();
updateTerminal();
flush();
}
//----------------------------------------------------------------------
@ -728,9 +719,6 @@ void FMenu::mouseDownSubmenu (const FMenuItem* m_item)
if ( getStatusBar() )
getStatusBar()->drawMessage();
updateTerminal();
flush();
}
}
@ -798,9 +786,6 @@ bool FMenu::mouseUpOverList (const FPoint& mouse_pos)
if ( getStatusBar() )
getStatusBar()->drawMessage();
updateTerminal();
flush();
}
return true;
@ -1073,8 +1058,6 @@ bool FMenu::selectNextItem()
getStatusBar()->drawMessage();
redraw();
updateTerminal();
flush();
break;
}
@ -1123,8 +1106,6 @@ bool FMenu::selectPrevItem()
getStatusBar()->drawMessage();
redraw();
updateTerminal();
flush();
break;
}
}
@ -1186,8 +1167,6 @@ bool FMenu::hotkeyMenu (FKeyEvent* ev)
hideSubMenus();
hide();
hideSuperMenus();
updateTerminal();
flush();
ev->accept();
item->processClicked();
}
@ -1527,9 +1506,6 @@ inline void FMenu::selectPrevMenu (FKeyEvent* ev)
if ( getStatusBar() )
getStatusBar()->drawMessage();
updateTerminal();
flush();
}
else
keypressMenuBar(ev); // select previous menu
@ -1600,9 +1576,6 @@ inline void FMenu::closeMenu()
if ( getStatusBar() )
getStatusBar()->drawMessage();
updateTerminal();
flush();
}
//----------------------------------------------------------------------

View File

@ -79,7 +79,6 @@ void FMenuBar::hide()
FColor bg = wc->term_bg;
setColor (fg, bg);
print() << FPoint{1, 1} << FString{getDesktopWidth(), L' '};
updateTerminal();
FWindow::hide();
}
@ -825,10 +824,7 @@ void FMenuBar::mouseDownOverList (const FMouseEvent* ev)
}
if ( focus_changed )
{
redraw();
updateTerminal();
}
}
//----------------------------------------------------------------------
@ -920,10 +916,7 @@ void FMenuBar::mouseMoveOverList (const FMouseEvent* ev)
}
if ( focus_changed )
{
redraw();
updateTerminal();
}
}
//----------------------------------------------------------------------
@ -972,8 +965,6 @@ void FMenuBar::leaveMenuBar()
if ( getStatusBar() )
getStatusBar()->drawMessage();
updateTerminal();
flush();
mouse_down = false;
}

View File

@ -250,8 +250,6 @@ void FMenuItem::openMenu() const
dd_menu->show();
dd_menu->raiseWindow();
dd_menu->redraw();
updateTerminal();
flush();
}
//----------------------------------------------------------------------

View File

@ -64,8 +64,6 @@ void FProgressbar::setPercentage (std::size_t percentage_value)
drawProgressLabel();
drawProgressBar();
}
updateTerminal();
}
//----------------------------------------------------------------------
@ -126,8 +124,6 @@ void FProgressbar::reset()
drawProgressLabel();
drawProgressBar();
}
updateTerminal();
}
@ -182,9 +178,6 @@ void FProgressbar::drawProgressBar()
if ( FTerm::isMonochron() )
setReverse(false);
updateTerminal();
flush();
}
//----------------------------------------------------------------------

View File

@ -352,7 +352,7 @@ void FScrollbar::onMouseMove (FMouseEvent* ev)
{
setValue(new_val);
drawBar();
updateTerminal();
processTerminalUpdate();
processScroll();
}
}
@ -757,7 +757,7 @@ void FScrollbar::jumpToClickPos (int x, int y)
{
setValue(new_val);
drawBar();
updateTerminal();
processTerminalUpdate();
scroll_type = FScrollbar::scrollJump;
processScroll();
}

View File

@ -411,7 +411,7 @@ void FScrollView::scrollTo (int x, int y)
viewport->has_changes = true;
copy2area();
updateTerminal();
processTerminalUpdate();
}
//----------------------------------------------------------------------

View File

@ -371,7 +371,6 @@ inline void FSpinBox::updateInputField()
input_field << pfix << value << sfix;
input_field.redraw();
redraw();
updateTerminal();
}
//----------------------------------------------------------------------

View File

@ -189,7 +189,6 @@ void FStatusBar::hide()
const FColor bg = wc->term_bg;
setColor (fg, bg);
print() << FPoint{1, 1} << FString{getDesktopWidth(), L' '};
updateTerminal();
FWindow::hide();
}

View File

@ -123,8 +123,6 @@ void FSwitch::draw()
drawLabel();
drawCheckButton();
FToggleButton::draw();
updateTerminal();
flush();
}
//----------------------------------------------------------------------

View File

@ -184,7 +184,7 @@ void FTextView::scrollTo (int x, int y)
}
drawText();
updateTerminal();
processTerminalUpdate();
}
//----------------------------------------------------------------------
@ -328,7 +328,6 @@ void FTextView::clear()
<< FString{size, L' '};
}
updateTerminal();
processChanged();
}
@ -476,7 +475,7 @@ void FTextView::onWheel (FWheelEvent* ev)
if ( isShown() )
drawText();
updateTerminal();
processTerminalUpdate();
}
//----------------------------------------------------------------------
@ -621,8 +620,6 @@ void FTextView::draw()
}
setCursorPos ({int(getWidth()), int(getHeight())});
updateTerminal();
flush();
}
//----------------------------------------------------------------------

View File

@ -222,11 +222,7 @@ void FToggleButton::onMouseDown (FMouseEvent* ev)
redraw();
if ( getStatusBar() )
{
getStatusBar()->drawMessage();
updateTerminal();
flush();
}
}
//----------------------------------------------------------------------
@ -299,11 +295,7 @@ void FToggleButton::onAccel (FAccelEvent* ev)
redraw();
if ( getStatusBar() )
{
getStatusBar()->drawMessage();
updateTerminal();
flush();
}
processClick();
ev->accept();
@ -474,10 +466,7 @@ void FToggleButton::onKeyPress (FKeyEvent* ev)
}
if ( ev->isAccepted() )
{
draw();
updateTerminal();
}
}

View File

@ -183,9 +183,10 @@ void FVTerm::hideCursor (bool enable) const
const char* visibility_str = FTerm::cursorsVisibilityString (enable);
if ( visibility_str )
appendOutputBuffer(visibility_str);
if ( ! visibility_str )
return;
appendOutputBuffer(visibility_str);
flush();
}
@ -286,24 +287,8 @@ void FVTerm::updateTerminal() const
}
}
const auto& data = FTerm::getFTermData();
// Checks if the resizing of the terminal is not finished
if ( data && data->hasTermResized() )
return;
// Monitor whether the terminal size has changed
if ( isTermSizeChanged() )
{
raise (SIGWINCH); // Send SIGWINCH
return;
}
// Update data on VTerm
updateVTerm();
// Checks if VTerm has changes
if ( ! vterm->has_changes )
if ( ! hasPendingUpdates(vterm) )
return;
for (uInt y{0}; y < uInt(vterm->height); y++)
@ -630,9 +615,13 @@ void FVTerm::flush()
while ( ! output_buffer->empty() )
{
static const FTerm::defaultPutChar& FTermPutchar = FTerm::putchar();
if ( FTermPutchar )
{
FTermPutchar (output_buffer->front());
output_buffer->pop();
}
}
std::fflush(stdout);
}
@ -1283,7 +1272,23 @@ void FVTerm::processTerminalUpdate() const
// Retains terminal updates if there are unprocessed inputs
static constexpr int max_skip = 8;
if ( ! terminal_update_pending )
const auto& data = FTerm::getFTermData();
// Checks if the resizing of the terminal is not finished
if ( data && data->hasTermResized() )
return;
// Monitor whether the terminal size has changed
if ( isTermSizeChanged() )
{
raise (SIGWINCH); // Send SIGWINCH
return;
}
// Update data on VTerm
updateVTerm();
if ( ! terminal_update_pending && ! hasPendingUpdates(vterm) )
return;
if ( ! keyboard->isInputDataPending() )
@ -1652,7 +1657,7 @@ void FVTerm::updateVTerm() const
{
// Updates the character data from all areas to VTerm
if ( vdesktop && vdesktop->has_changes )
if ( hasPendingUpdates(vdesktop) )
{
putArea(vdesktop);
vdesktop->has_changes = false;
@ -1671,7 +1676,7 @@ void FVTerm::updateVTerm() const
if ( ! (v_win && v_win->visible) )
continue;
if ( v_win->has_changes )
if ( hasPendingUpdates(v_win) )
{
putArea(v_win);
v_win->has_changes = false;
@ -2941,6 +2946,12 @@ inline bool FVTerm::isTermSizeCheckTimeout()
return FObject::isTimeout (&last_term_size_check, term_size_check_timeout);
}
//----------------------------------------------------------------------
inline bool FVTerm::hasPendingUpdates (FTermArea* area)
{
return ( area && area->has_changes ) ? true : false;
}
//----------------------------------------------------------------------
inline void FVTerm::markAsPrinted (uInt pos, uInt line)
{

View File

@ -905,12 +905,8 @@ void FWidget::redraw()
finishTerminalUpdate();
if ( redraw_root_widget == this )
{
updateTerminal();
flush();
redraw_root_widget = nullptr;
}
}
//----------------------------------------------------------------------
void FWidget::resize()
@ -976,8 +972,6 @@ void FWidget::show()
if ( show_root_widget && show_root_widget == this )
{
finishTerminalUpdate();
updateTerminal();
flush();
show_root_widget = nullptr;
}
@ -1953,8 +1947,6 @@ bool FWidget::changeFocus ( FWidget* follower, FWidget* parent
{
redraw();
follower->redraw();
updateTerminal();
flush();
}
}

View File

@ -929,9 +929,6 @@ void closeDropDown (const FWidget* widget, const FPoint& mouse_position)
if ( FWidget::getStatusBar() )
FWidget::getStatusBar()->drawMessage();
widget->updateTerminal();
FVTerm::flush();
}
} // namespace finalcut

View File

@ -340,7 +340,7 @@ class FVTerm
// Constants
// Buffer size for character output on the terminal
static constexpr uInt TERMINAL_OUTPUT_BUFFER_SIZE = 32768;
static constexpr uInt TERMINAL_OUTPUT_BUFFER_SIZE = 131072;
// Methods
void resetTextAreaToDefault ( const FTermArea*
@ -417,6 +417,7 @@ class FVTerm
bool isInsideTerminal (const FPoint&) const;
bool isTermSizeChanged() const;
static bool isTermSizeCheckTimeout();
static bool hasPendingUpdates (FTermArea*);
static void markAsPrinted (uInt, uInt);
static void markAsPrinted (uInt, uInt, uInt);
static void newFontChanges (FChar*&);