SerialConnect: add a clear/reset menu.
Change-Id: I0435ba679e19094d201d65ac0c6290cd194ec344 Reviewed-on: https://review.haiku-os.org/c/1463 Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
506f9764d4
commit
1eb386084c
@@ -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.
|
* Distributed under the terms of the MIT licence.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -65,6 +65,7 @@ enum messageConstants {
|
|||||||
kMsgProgress = 'prog',
|
kMsgProgress = 'prog',
|
||||||
kMsgSettings = 'stty',
|
kMsgSettings = 'stty',
|
||||||
kMsgSendFile = 'sndf',
|
kMsgSendFile = 'sndf',
|
||||||
|
kMsgClear = 'cler',
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2017, Adrien Destugues, [email protected]
|
* Copyright 2012-2019, Adrien Destugues, [email protected]
|
||||||
* Distributed under the terms of the MIT licence.
|
* Distributed under the terms of the MIT licence.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -58,6 +58,7 @@ SerialWindow::SerialWindow()
|
|||||||
r.right = r.left + B_V_SCROLL_BAR_WIDTH;
|
r.right = r.left + B_V_SCROLL_BAR_WIDTH;
|
||||||
r.top -= 1;
|
r.top -= 1;
|
||||||
r.bottom -= B_H_SCROLL_BAR_HEIGHT - 1;
|
r.bottom -= B_H_SCROLL_BAR_HEIGHT - 1;
|
||||||
|
|
||||||
BScrollBar* scrollBar = new BScrollBar(r, "scrollbar", NULL, 0, 0,
|
BScrollBar* scrollBar = new BScrollBar(r, "scrollbar", NULL, 0, 0,
|
||||||
B_VERTICAL);
|
B_VERTICAL);
|
||||||
|
|
||||||
@@ -81,18 +82,15 @@ SerialWindow::SerialWindow()
|
|||||||
fConnectionMenu = new BMenu("Connection");
|
fConnectionMenu = new BMenu("Connection");
|
||||||
fFileMenu = new BMenu("File");
|
fFileMenu = new BMenu("File");
|
||||||
BMenu* settingsMenu = new BMenu("Settings");
|
BMenu* settingsMenu = new BMenu("Settings");
|
||||||
|
BMenu* editMenu = new BMenu("Edit");
|
||||||
|
|
||||||
fConnectionMenu->SetRadioMode(true);
|
fConnectionMenu->SetRadioMode(true);
|
||||||
|
|
||||||
menuBar->AddItem(fConnectionMenu);
|
menuBar->AddItem(fConnectionMenu);
|
||||||
|
menuBar->AddItem(editMenu);
|
||||||
menuBar->AddItem(fFileMenu);
|
menuBar->AddItem(fFileMenu);
|
||||||
menuBar->AddItem(settingsMenu);
|
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,
|
BMenuItem* logFile = new BMenuItem("Log to file" B_UTF8_ELLIPSIS,
|
||||||
new BMessage(kMsgLogfile));
|
new BMessage(kMsgLogfile));
|
||||||
fFileMenu->AddItem(logFile);
|
fFileMenu->AddItem(logFile);
|
||||||
@@ -119,6 +117,13 @@ SerialWindow::SerialWindow()
|
|||||||
xmodemReceive->SetEnabled(false);
|
xmodemReceive->SetEnabled(false);
|
||||||
#endif
|
#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
|
// Configuring all this by menus may be a bit unhandy. Make a setting
|
||||||
// window instead ?
|
// window instead ?
|
||||||
fBaudrateMenu = new BMenu("Baud rate");
|
fBaudrateMenu = new BMenu("Baud rate");
|
||||||
@@ -440,6 +445,11 @@ void SerialWindow::MessageReceived(BMessage* message)
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
case kMsgClear:
|
||||||
|
{
|
||||||
|
fTermView->Clear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
case kMsgProgress:
|
case kMsgProgress:
|
||||||
{
|
{
|
||||||
// File transfer progress
|
// File transfer progress
|
||||||
|
|||||||
@@ -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.
|
* 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 -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
@@ -437,6 +451,13 @@ TermView::_PushLine(int cols, const VTermScreenCell* cells)
|
|||||||
|
|
||||||
free(fScrollBuffer.RemoveItem(kScrollBackSize));
|
free(fScrollBuffer.RemoveItem(kScrollBackSize));
|
||||||
|
|
||||||
|
_UpdateScrollbar();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TermView::_UpdateScrollbar()
|
||||||
|
{
|
||||||
int availableRows, availableCols;
|
int availableRows, availableCols;
|
||||||
vterm_get_size(fTerm, &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
|
/* static */ int
|
||||||
TermView::_Damage(VTermRect rect, void* user)
|
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
|
const
|
||||||
VTermScreenCallbacks TermView::sScreenCallbacks = {
|
VTermScreenCallbacks TermView::sScreenCallbacks = {
|
||||||
&TermView::_Damage,
|
&TermView::_Damage,
|
||||||
@@ -502,5 +539,5 @@ VTermScreenCallbacks TermView::sScreenCallbacks = {
|
|||||||
/*.bell =*/ NULL,
|
/*.bell =*/ NULL,
|
||||||
/*.resize =*/ NULL,
|
/*.resize =*/ NULL,
|
||||||
&TermView::_PushLine,
|
&TermView::_PushLine,
|
||||||
/*.sb_popline =*/ NULL,
|
&TermView::_PopLine,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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.
|
* Distributed under the terms of the MIT licence.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -28,6 +28,7 @@ class TermView: public BView
|
|||||||
void SetLineTerminator(BString bytes);
|
void SetLineTerminator(BString bytes);
|
||||||
|
|
||||||
void PushBytes(const char* bytes, const size_t length);
|
void PushBytes(const char* bytes, const size_t length);
|
||||||
|
void Clear();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _Init();
|
void _Init();
|
||||||
@@ -42,13 +43,15 @@ class TermView: public BView
|
|||||||
void _MoveCursor(VTermPos pos, VTermPos oldPos,
|
void _MoveCursor(VTermPos pos, VTermPos oldPos,
|
||||||
int visible);
|
int visible);
|
||||||
void _PushLine(int cols, const VTermScreenCell* cells);
|
void _PushLine(int cols, const VTermScreenCell* cells);
|
||||||
|
int _PopLine(int cols, VTermScreenCell* cells);
|
||||||
|
void _UpdateScrollbar();
|
||||||
|
|
||||||
static int _Damage(VTermRect rect, void* user);
|
static int _Damage(VTermRect rect, void* user);
|
||||||
static int _MoveCursor(VTermPos pos, VTermPos oldPos,
|
static int _MoveCursor(VTermPos pos, VTermPos oldPos,
|
||||||
int visible, void* user);
|
int visible, void* user);
|
||||||
static int _PushLine(int cols, const VTermScreenCell* cells,
|
static int _PushLine(int cols, const VTermScreenCell* cells,
|
||||||
void* user);
|
void* user);
|
||||||
static int _PopLine(int cols, const VTermScreenCell* cells,
|
static int _PopLine(int cols, VTermScreenCell* cells,
|
||||||
void* user);
|
void* user);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user