[2742] in BarnOwl Developers

home help back first fref pref prev next nref lref last post

Re: [PATCH] Show how far you are in a long message

daemon@ATHENA.MIT.EDU (Jason Gross)
Sat Nov 6 23:53:47 2010

In-Reply-To: <1289100866-14400-1-git-send-email-jgross@mit.edu>
From: Jason Gross <jgross@MIT.EDU>
Date: Sat, 6 Nov 2010 23:53:13 -0400
To: barnowl-dev@mit.edu

Alternatively, DD suggested something of the form current-lines /
total lines.  The following patch (as a replacement for the patch that
I did before) does this (but doesn't refactor the ints to bools):

diff --git a/sepbar.c b/sepbar.c
index f0ff246..7eea9bc 100644
--- a/sepbar.c
+++ b/sepbar.c
@@ -53,7 +53,11 @@ 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");
+    cur_numlines =3D owl_global_get_curmsg_vert_offset(&g) + 1;
+    cur_totallines =3D owl_message_get_numlines(owl_view_get_element(v,
owl_global_get_curmsg(&g)));
+    wprintw(sepwin, " -- %d/%d", cur_numlines, cur_totallines);
+    waddstr(sepwin, "> ");
     wattroff(sepwin, A_BOLD);
   }

-Jason

On Sat, Nov 6, 2010 at 11:34 PM, Jason Gross <jgross@mit.edu> wrote:
>
> 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. =A0The 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).
> ---
> =A0mainwin.c | =A0 38 ++++++++++++++++++++++----------------
> =A0owl.h =A0 =A0 | =A0 =A05 +++--
> =A0sepbar.c =A0| =A0 =A09 ++++++++-
> =A03 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);
>
> =A0void owl_mainwin_init(owl_mainwin *mw, owl_window *window)
> =A0{
> - =A0mw->curtruncated=3D0;
> - =A0mw->lastdisplayed=3D-1;
> + =A0mw->curtruncated =3D false;
> + =A0mw->lastdisplayed =3D -1;
> =A0 mw->window =3D g_object_ref(window);
> =A0 /* for now, just assume this object lasts forever */
> =A0 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)
> =A0 =A0 if (viewsize=3D=3D0) {
> =A0 =A0 =A0 owl_global_set_topmsg(&g, 0);
> =A0 =A0 }
> - =A0 =A0mw->curtruncated=3D0;
> - =A0 =A0mw->lastdisplayed=3D-1;
> + =A0 =A0mw->curtruncated =3D false;
> + =A0 =A0mw->lastdisplayed =3D -1;
> =A0 =A0 return;
> =A0 }
>
> =A0 /* write the messages out */
> =A0 isfull=3D0;
> - =A0mw->curtruncated=3D0;
> - =A0mw->lasttruncated=3D0;
> + =A0mw->curtruncated =3D false;
> + =A0mw->lasttruncated =3D false;
>
> =A0 for (i=3Dtopmsg; i<viewsize; i++) {
> =A0 =A0 if (isfull) break;
> @@ -89,7 +89,7 @@ static void owl_mainwin_redraw(owl_window *w, WINDOW *r=
ecwin, void *user_data)
> =A0 =A0 savey=3Dy;
>
> =A0 =A0 /* if it's the current message, account for a vert_offset */
> - =A0 =A0if (i=3D=3Dowl_global_get_curmsg(&g)) {
> + =A0 =A0if (i =3D=3D owl_global_get_curmsg(&g)) {
> =A0 =A0 =A0 start=3Dowl_global_get_curmsg_vert_offset(&g);
> =A0 =A0 =A0 lines=3Dowl_message_get_numlines(m)-start;
> =A0 =A0 } else {
> @@ -112,8 +112,11 @@ static void owl_mainwin_redraw(owl_window *w, WINDOW=
 *recwin, void *user_data)
> =A0 =A0 }
>
> =A0 =A0 /* if we'll fill the screen print a partial message */
> - =A0 =A0if ((y+lines > recwinlines) && (i=3D=3Dowl_global_get_curmsg(&g)=
)) mw->curtruncated=3D1;
> - =A0 =A0if (y+lines > recwinlines) mw->lasttruncated=3D1;
> + =A0 =A0if ((y+lines > recwinlines) && (i =3D=3D owl_global_get_curmsg(&=
g))) {
> + =A0 =A0 =A0mw->curtruncated =3D true;
> + =A0 =A0 =A0mw->curmessagevisiblelines =3D recwinlines - y;
> + =A0 =A0}
> + =A0 =A0if (y+lines > recwinlines) mw->lasttruncated =3D true;
> =A0 =A0 if (y+lines > recwinlines-1) {
> =A0 =A0 =A0 isfull=3D1;
> =A0 =A0 =A0 owl_message_curs_waddstr(m, recwin,
> @@ -170,20 +173,23 @@ static void owl_mainwin_redraw(owl_window *w, WINDO=
W *recwin, void *user_data)
> =A0}
>
>
> -int owl_mainwin_is_curmsg_truncated(const owl_mainwin *mw)
> +bool owl_mainwin_is_curmsg_truncated(const owl_mainwin *mw)
> =A0{
> - =A0if (mw->curtruncated) return(1);
> - =A0return(0);
> + =A0return mw->curtruncated;
> =A0}
>
> -int owl_mainwin_is_last_msg_truncated(const owl_mainwin *mw)
> +bool owl_mainwin_is_last_msg_truncated(const owl_mainwin *mw)
> =A0{
> - =A0if (mw->lasttruncated) return(1);
> - =A0return(0);
> + =A0return mw->lasttruncated;
> =A0}
>
> =A0int owl_mainwin_get_last_msg(const owl_mainwin *mw)
> =A0{
> =A0 /* return the number of the last message displayed. -1 if none */
> - =A0return(mw->lastdisplayed);
> + =A0return mw->lastdisplayed;
> =A0}
> +
> +int owl_mainwin_get_numlines_visible_in_curmsg(const owl_mainwin *mw)
> +{
> + =A0return(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 {
> =A0} owl_style;
>
> =A0typedef struct _owl_mainwin {
> - =A0int curtruncated;
> - =A0int lasttruncated;
> + =A0bool curtruncated;
> + =A0bool lasttruncated;
> =A0 int lastdisplayed;
> + =A0int curmessagevisiblelines;
> =A0 owl_window *window;
> =A0} 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)
> =A0 const owl_view *v;
> =A0 int x, y, i;
> =A0 const char *foo, *appendtosepbar;
> + =A0int cur_numlines, cur_totallines;
> +
>
> =A0 ml=3Dowl_global_get_msglist(&g);
> =A0 v=3Dowl_global_get_current_view(&g);
> @@ -53,7 +55,12 @@ static void sepbar_redraw(owl_window *w, WINDOW *sepwi=
n, void *user_data)
> =A0 =A0 getyx(sepwin, y, x);
> =A0 =A0 wmove(sepwin, y, x+2);
> =A0 =A0 wattron(sepwin, A_BOLD);
> - =A0 =A0waddstr(sepwin, " <truncated> ");
> + =A0 =A0waddstr(sepwin, " <truncated");
> + =A0 =A0/* Calculate how far we are through the current message */
> + =A0 =A0cur_totallines =3D owl_message_get_numlines(owl_view_get_element=
(v, owl_global_get_curmsg(&g)));
> + =A0 =A0cur_numlines =3D owl_global_get_curmsg_vert_offset(&g) + owl_mai=
nwin_get_numlines_visible_in_curmsg(owl_global_get_mainwin(&g));
> + =A0 =A0wprintw(sepwin, " -- %d%% through", 100 * cur_numlines / cur_tot=
allines);
> + =A0 =A0waddstr(sepwin, "> ");
> =A0 =A0 wattroff(sepwin, A_BOLD);
> =A0 }
>
> --
> 1.7.0.4
>

home help back first fref pref prev next nref lref last post