From 1eb386084c57314c05607ca80c048f0c6fdc3b80 Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Sun, 19 May 2019 11:38:51 +0200 Subject: [PATCH] SerialConnect: add a clear/reset menu. Change-Id: I0435ba679e19094d201d65ac0c6290cd194ec344 Reviewed-on: https://review.haiku-os.org/c/1463 Reviewed-by: waddlesplash --- src/apps/serialconnect/SerialApp.h | 3 +- src/apps/serialconnect/SerialWindow.cpp | 22 +++++++++---- src/apps/serialconnect/TermView.cpp | 41 +++++++++++++++++++++++-- src/apps/serialconnect/TermView.h | 7 +++-- 4 files changed, 62 insertions(+), 11 deletions(-) diff --git a/src/apps/serialconnect/SerialApp.h b/src/apps/serialconnect/SerialApp.h index 31da080e08..b8d0740c7d 100644 --- a/src/apps/serialconnect/SerialApp.h +++ b/src/apps/serialconnect/SerialApp.h @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017, Adrien Destugues, pulkomandy@gmail.com + * Copyright 2012-2019, Adrien Destugues, pulkomandy@pulkomandy.tk * Distributed under the terms of the MIT licence. */ @@ -65,6 +65,7 @@ enum messageConstants { kMsgProgress = 'prog', kMsgSettings = 'stty', kMsgSendFile = 'sndf', + kMsgClear = 'cler', }; #endif diff --git a/src/apps/serialconnect/SerialWindow.cpp b/src/apps/serialconnect/SerialWindow.cpp index 6890c69070..e4c3e3e2be 100644 --- a/src/apps/serialconnect/SerialWindow.cpp +++ b/src/apps/serialconnect/SerialWindow.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017, Adrien Destugues, pulkomandy@pulkomandy.tk + * Copyright 2012-2019, Adrien Destugues, pulkomandy@pulkomandy.tk * Distributed under the terms of the MIT licence. */ @@ -58,6 +58,7 @@ SerialWindow::SerialWindow() r.right = r.left + B_V_SCROLL_BAR_WIDTH; r.top -= 1; r.bottom -= B_H_SCROLL_BAR_HEIGHT - 1; + BScrollBar* scrollBar = new BScrollBar(r, "scrollbar", NULL, 0, 0, B_VERTICAL); @@ -81,18 +82,15 @@ SerialWindow::SerialWindow() fConnectionMenu = new BMenu("Connection"); fFileMenu = new BMenu("File"); BMenu* settingsMenu = new BMenu("Settings"); + BMenu* editMenu = new BMenu("Edit"); fConnectionMenu->SetRadioMode(true); menuBar->AddItem(fConnectionMenu); + menuBar->AddItem(editMenu); menuBar->AddItem(fFileMenu); menuBar->AddItem(settingsMenu); - // TODO edit menu - what's in it ? Usual copy/paste would be nice but we - // need a way to select text in the window. - //BMenu* editMenu = new BMenu("Edit"); - //menuBar->AddItem(editMenu); - BMenuItem* logFile = new BMenuItem("Log to file" B_UTF8_ELLIPSIS, new BMessage(kMsgLogfile)); fFileMenu->AddItem(logFile); @@ -119,6 +117,13 @@ SerialWindow::SerialWindow() xmodemReceive->SetEnabled(false); #endif + // Items for the edit menu + BMenuItem* clearScreen = new BMenuItem("Clear history", + new BMessage(kMsgClear)); + editMenu->AddItem(clearScreen); + + // TODO copy (when we have selection), paste + // Configuring all this by menus may be a bit unhandy. Make a setting // window instead ? fBaudrateMenu = new BMenu("Baud rate"); @@ -440,6 +445,11 @@ void SerialWindow::MessageReceived(BMessage* message) return; } + case kMsgClear: + { + fTermView->Clear(); + return; + } case kMsgProgress: { // File transfer progress diff --git a/src/apps/serialconnect/TermView.cpp b/src/apps/serialconnect/TermView.cpp index 646f19d18b..072830301b 100644 --- a/src/apps/serialconnect/TermView.cpp +++ b/src/apps/serialconnect/TermView.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015, Adrien Destugues, pulkomandy@gmail.com + * Copyright 2012-2019, Adrien Destugues, pulkomandy@pulkomandy.tk * Distributed under the terms of the MIT licence. */ @@ -266,6 +266,20 @@ TermView::PushBytes(const char* bytes, size_t length) } +void +TermView::Clear() +{ + while(fScrollBuffer.ItemAt(0)) { + free(fScrollBuffer.RemoveItem(0l)); + } + + vterm_state_reset(vterm_obtain_state(fTerm), 1); + vterm_screen_reset(fTermScreen, 1); + + _UpdateScrollbar(); +} + + // #pragma mark - @@ -437,6 +451,13 @@ TermView::_PushLine(int cols, const VTermScreenCell* cells) free(fScrollBuffer.RemoveItem(kScrollBackSize)); + _UpdateScrollbar(); +} + + +void +TermView::_UpdateScrollbar() +{ int availableRows, availableCols; vterm_get_size(fTerm, &availableRows, &availableCols); @@ -462,6 +483,14 @@ TermView::_PushLine(int cols, const VTermScreenCell* cells) } +int +TermView::_PopLine(int cols, VTermScreenCell* cells) +{ + /* TODO can be used when switching to alt screen and when resizing */ + return 0; +} + + /* static */ int TermView::_Damage(VTermRect rect, void* user) { @@ -492,6 +521,14 @@ TermView::_PushLine(int cols, const VTermScreenCell* cells, void* user) } +/* static */ int +TermView::_PopLine(int cols, VTermScreenCell* cells, void* user) +{ + TermView* view = (TermView*)user; + return view->_PopLine(cols, cells); +} + + const VTermScreenCallbacks TermView::sScreenCallbacks = { &TermView::_Damage, @@ -502,5 +539,5 @@ VTermScreenCallbacks TermView::sScreenCallbacks = { /*.bell =*/ NULL, /*.resize =*/ NULL, &TermView::_PushLine, - /*.sb_popline =*/ NULL, + &TermView::_PopLine, }; diff --git a/src/apps/serialconnect/TermView.h b/src/apps/serialconnect/TermView.h index aec5cee88a..355e8d4cd7 100644 --- a/src/apps/serialconnect/TermView.h +++ b/src/apps/serialconnect/TermView.h @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015, Adrien Destugues, pulkomandy@gmail.com + * Copyright 2012-2019, Adrien Destugues, pulkomandy@pulkomandy.tk * Distributed under the terms of the MIT licence. */ @@ -28,6 +28,7 @@ class TermView: public BView void SetLineTerminator(BString bytes); void PushBytes(const char* bytes, const size_t length); + void Clear(); private: void _Init(); @@ -42,13 +43,15 @@ class TermView: public BView void _MoveCursor(VTermPos pos, VTermPos oldPos, int visible); void _PushLine(int cols, const VTermScreenCell* cells); + int _PopLine(int cols, VTermScreenCell* cells); + void _UpdateScrollbar(); static int _Damage(VTermRect rect, void* user); static int _MoveCursor(VTermPos pos, VTermPos oldPos, int visible, void* user); static int _PushLine(int cols, const VTermScreenCell* cells, void* user); - static int _PopLine(int cols, const VTermScreenCell* cells, + static int _PopLine(int cols, VTermScreenCell* cells, void* user); private: