summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/cursesview.c34
-rw-r--r--src/slices.c14
2 files changed, 36 insertions, 12 deletions
diff --git a/src/cursesview.c b/src/cursesview.c
index b032356..ddd5a2f 100644
--- a/src/cursesview.c
+++ b/src/cursesview.c
@@ -13,6 +13,7 @@ extern int end;
// window updated by cursesUpdateSliceDump callback from "worker" thread, with a mutex for prevent fuzzy concurrent updates
WINDOW *winUpdateSliceDump=NULL;
static pthread_mutex_t ncursesWriteMutex = PTHREAD_MUTEX_INITIALIZER;
+address_t sliceDumpBegin, sliceDumpEnd;
// Helpers declaration (below the interesting code of this file)
int cursesInit(WINDOW *wins[], PANEL *panels[], int count);
@@ -24,16 +25,19 @@ void makeWin(WINDOW **win, PANEL **panel, int h, int w, int y, int x, char title
void cursesMainLoop(slices_evt_t *slicesEvt) {
WINDOW *wins[CURSESWIN_COUNT];
PANEL *panels[CURSESWIN_COUNT];
+ char msgViewedArea[255];
int ch, i;
- char str[2];
cursesInit(wins, panels, CURSESWIN_COUNT);
+ sliceDumpBegin=slicesEvt->data->min;
+ sliceDumpEnd=slicesEvt->data->max;
+
wattron(wins[CURSESWIN_COUNT-1], COLOR_PAIR(4));
- mvwprintw(wins[CURSESWIN_COUNT-1], 1, 0, "(F2 to Exit)");
+ mvwprintw(wins[CURSESWIN_COUNT-1], 1, 0, "F2:Exit F5:Zoom left F6:Unzoom left F7:Unzoom right F8:Zoom right");
// wattroff(wins[CURSESWIN_COUNT-1], COLOR_PAIR(4));
- update_panels();
+// update_panels();
doupdate();
/* Enable worker listener */
@@ -46,11 +50,25 @@ void cursesMainLoop(slices_evt_t *slicesEvt) {
pthread_mutex_lock(&ncursesWriteMutex);
switch(ch) {
+ // Zoom handling
+ case KEY_F(5):
+ sliceDumpEnd=(sliceDumpBegin+sliceDumpEnd)/2;
+ break;
+ case KEY_F(6):
+ sliceDumpBegin=slicesEvt->data->min;
+ break;
+ case KEY_F(7):
+ sliceDumpEnd=slicesEvt->data->max;
+ break;
+ case KEY_F(8):
+ sliceDumpBegin=(sliceDumpBegin+sliceDumpEnd)/2;
+ break;
+
+ // Panel focus
case '1':
case '2':
case '3':
- str[0]=ch; str[1]='\0'; // int (ascii value+flags) to string
- i=strtol(str, (char **)NULL, 10); // string to real integer
+ i=ch-'0';
if (i>0 && i<=CURSESWIN_COUNT) {
top_panel(panels[i-1]);
update_panels();
@@ -60,6 +78,10 @@ void cursesMainLoop(slices_evt_t *slicesEvt) {
doupdate();
+ sprintf(msgViewedArea, "Viewing [%lli-%lli] of [%lli-%lli] working region ", sliceDumpBegin, sliceDumpEnd, slicesEvt->data->min, slicesEvt->data->max);
+ wattron(wins[0], COLOR_PAIR(4));
+ mvwprintw(wins[0], 1, 0, msgViewedArea);
+
pthread_mutex_unlock(&ncursesWriteMutex);
}
@@ -127,7 +149,7 @@ void cursesUpdateSliceDump(slices_evt_t *slicesEvt, slice_t *modifiedSlice) {
//TODO : refesh only right parts of the representation
pthread_mutex_lock(&ncursesWriteMutex);
- toPrint=slicesDump(slicesEvt->data, &blockSize, charCount, slicesEvt->data->min, slicesEvt->data->max);
+ toPrint=slicesDump(slicesEvt->data, &blockSize, charCount, sliceDumpBegin, sliceDumpEnd);
if (toPrint != NULL) {
attron(COLOR_PAIR(4));
mvwprintw(winUpdateSliceDump, 1, 0, toPrint);
diff --git a/src/slices.c b/src/slices.c
index e84facf..36f7bb1 100644
--- a/src/slices.c
+++ b/src/slices.c
@@ -214,19 +214,21 @@ char *slicesDump(slices_t *slices, address_t *blockSize, unsigned int charCount,
//For each slice
while (curr != NULL) {
- // If is (partially) contained in the [begin,end] interval
- if ( (curr->begin >= begin && curr->begin <=end) || ( curr->end >= end && curr->end <= end ) ) {
-
+ // If "curr" slice is (partially) contained/visible in the [begin,end] display interval
+ if ( !(curr->end < begin) && !(curr->begin > end) ) {
// Draw the slice on the right number of characters
- sb=MAX(0, (curr->begin - begin) / *blockSize);
+ // Mathematically correct, but crashes because address_t is UNSIGNED
+ // sb=MAX(0, (curr->begin - begin) / *blockSize);
+ sb=(curr->begin < begin)?0:(curr->begin - begin) / *blockSize;
se=MIN((curr->end - begin) / *blockSize, charCount-1);
- // Debug assertion
+ /* Debug "assertion"
if (sb >= charCount || se >= charCount) {
printf("BUG : sb==%lli, se=%lli, charCount==%i\n", sb, se, charCount);
+ printf("BUG : MAX(0, (%lli - %lli) / %lli)", curr->begin, begin, *blockSize);
pthread_mutex_unlock(&(slices->writeOrConsistentReadMutex));
exit(42);
- }
+ }*/
// Choose from the current slice status the right char to draw
switch (curr->status) {