[2741] in BarnOwl Developers
[PATCH] Show how far you are in a long message
daemon@ATHENA.MIT.EDU (Jason Gross)
Sat Nov 6 23:34:29 2010
From: Jason Gross <jgross@MIT.EDU>
To: barnowl-dev@mit.edu
Date: Sat, 6 Nov 2010 23:34:26 -0400
Addresses most of ticket #119 - it show's how far you are in a long
message, but not in a message that you're typing. The display style
I've somewhat arbitrarily chosen to replace <truncated> with
<truncated -- $percent% through>.
I added an int curmessagevisiblelines to struct _owl_mainwin, and
I've also refactored curtruncated and lasttruncated to be bools (not
ints).
---
mainwin.c | 38 ++++++++++++++++++++++----------------
owl.h | 5 +++--
sepbar.c | 9 ++++++++-
3 files changed, 33 insertions(+), 19 deletions(-)
diff --git a/mainwin.c b/mainwin.c
index e5cc837..a0bbc1d 100644
--- a/mainwin.c
+++ b/mainwin.c
@@ -5,8 +5,8 @@ static void owl_mainwin_resized(owl_window *w, void *user_data);
void owl_mainwin_init(owl_mainwin *mw, owl_window *window)
{
- mw->curtruncated=0;
- mw->lastdisplayed=-1;
+ mw->curtruncated = false;
+ mw->lastdisplayed = -1;
mw->window = g_object_ref(window);
/* for now, just assume this object lasts forever */
g_signal_connect(window, "redraw", G_CALLBACK(owl_mainwin_redraw), mw);
@@ -70,15 +70,15 @@ static void owl_mainwin_redraw(owl_window *w, WINDOW *recwin, void *user_data)
if (viewsize==0) {
owl_global_set_topmsg(&g, 0);
}
- mw->curtruncated=0;
- mw->lastdisplayed=-1;
+ mw->curtruncated = false;
+ mw->lastdisplayed = -1;
return;
}
/* write the messages out */
isfull=0;
- mw->curtruncated=0;
- mw->lasttruncated=0;
+ mw->curtruncated = false;
+ mw->lasttruncated = false;
for (i=topmsg; i<viewsize; i++) {
if (isfull) break;
@@ -89,7 +89,7 @@ static void owl_mainwin_redraw(owl_window *w, WINDOW *recwin, void *user_data)
savey=y;
/* if it's the current message, account for a vert_offset */
- if (i==owl_global_get_curmsg(&g)) {
+ if (i == owl_global_get_curmsg(&g)) {
start=owl_global_get_curmsg_vert_offset(&g);
lines=owl_message_get_numlines(m)-start;
} else {
@@ -112,8 +112,11 @@ static void owl_mainwin_redraw(owl_window *w, WINDOW *recwin, void *user_data)
}
/* if we'll fill the screen print a partial message */
- if ((y+lines > recwinlines) && (i==owl_global_get_curmsg(&g))) mw->curtruncated=1;
- if (y+lines > recwinlines) mw->lasttruncated=1;
+ if ((y+lines > recwinlines) && (i == owl_global_get_curmsg(&g))) {
+ mw->curtruncated = true;
+ mw->curmessagevisiblelines = recwinlines - y;
+ }
+ if (y+lines > recwinlines) mw->lasttruncated = true;
if (y+lines > recwinlines-1) {
isfull=1;
owl_message_curs_waddstr(m, recwin,
@@ -170,20 +173,23 @@ static void owl_mainwin_redraw(owl_window *w, WINDOW *recwin, void *user_data)
}
-int owl_mainwin_is_curmsg_truncated(const owl_mainwin *mw)
+bool owl_mainwin_is_curmsg_truncated(const owl_mainwin *mw)
{
- if (mw->curtruncated) return(1);
- return(0);
+ return mw->curtruncated;
}
-int owl_mainwin_is_last_msg_truncated(const owl_mainwin *mw)
+bool owl_mainwin_is_last_msg_truncated(const owl_mainwin *mw)
{
- if (mw->lasttruncated) return(1);
- return(0);
+ return mw->lasttruncated;
}
int owl_mainwin_get_last_msg(const owl_mainwin *mw)
{
/* return the number of the last message displayed. -1 if none */
- return(mw->lastdisplayed);
+ return mw->lastdisplayed;
}
+
+int owl_mainwin_get_numlines_visible_in_curmsg(const owl_mainwin *mw)
+{
+ return(mw->curmessagevisiblelines);
+}
diff --git a/owl.h b/owl.h
index 881931f..b87eb81 100644
--- a/owl.h
+++ b/owl.h
@@ -392,9 +392,10 @@ typedef struct _owl_style {
} owl_style;
typedef struct _owl_mainwin {
- int curtruncated;
- int lasttruncated;
+ bool curtruncated;
+ bool lasttruncated;
int lastdisplayed;
+ int curmessagevisiblelines;
owl_window *window;
} owl_mainwin;
diff --git a/sepbar.c b/sepbar.c
index f0ff246..29ac8d3 100644
--- a/sepbar.c
+++ b/sepbar.c
@@ -15,6 +15,8 @@ static void sepbar_redraw(owl_window *w, WINDOW *sepwin, void *user_data)
const owl_view *v;
int x, y, i;
const char *foo, *appendtosepbar;
+ int cur_numlines, cur_totallines;
+
ml=owl_global_get_msglist(&g);
v=owl_global_get_current_view(&g);
@@ -53,7 +55,12 @@ static void sepbar_redraw(owl_window *w, WINDOW *sepwin, void *user_data)
getyx(sepwin, y, x);
wmove(sepwin, y, x+2);
wattron(sepwin, A_BOLD);
- waddstr(sepwin, " <truncated> ");
+ waddstr(sepwin, " <truncated");
+ /* Calculate how far we are through the current message */
+ cur_totallines = owl_message_get_numlines(owl_view_get_element(v, owl_global_get_curmsg(&g)));
+ cur_numlines = owl_global_get_curmsg_vert_offset(&g) + owl_mainwin_get_numlines_visible_in_curmsg(owl_global_get_mainwin(&g));
+ wprintw(sepwin, " -- %d%% through", 100 * cur_numlines / cur_totallines);
+ waddstr(sepwin, "> ");
wattroff(sepwin, A_BOLD);
}
--
1.7.0.4