visit1985 / mdp

A command-line based markdown presentation tool.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Vertically centred slides?

spinningarrow opened this issue · comments

Is it possible to have slides vertically centred on the terminal?

Currently this is not possible. The calculation for how many rows are available/needed is quite complex. Especially since we already support pandoc URLs.

You can work around this by inserting empty lines in your slides.

I see. Thanks for the response! Unfortunately, the problem with inserting empty lines is the same - it is not aware of how many rows are available so may not always be centred (while presenting, I often increase the font size of the terminal till it looks big enough and it's hard to gauge how many lines will be available).

First off: This is an amazing project, @visit1985. Clean code, with good comments means it's easy to try your hand at contributing.

@spinningarrow: Since there's already a pass in ncurses_display that estimates the number of lines of text (including the number of pandoc URLs) for each slide, all that should be needed is to store those values as a property of each slide, and use them to add a vertical offset to the arguments to add_line:

diff --git a/include/markdown.h b/include/markdown.h
index 7a435a8..8e33c8e 100644
--- a/include/markdown.h
+++ b/include/markdown.h
@@ -74,6 +74,7 @@ typedef struct _slide_t {
     struct _slide_t *next;
     int lines;
     int stop;
+    int lines_consumed;
 } slide_t;
 
 typedef struct _deck_t {
diff --git a/src/viewer.c b/src/viewer.c
index d23ed73..2cf5911 100644
--- a/src/viewer.c
+++ b/src/viewer.c
@@ -158,6 +158,7 @@ int ncurses_display(deck_t *deck, int notrans, int nofade, int invert, int reloa
             max_lines_slide = sc;
         }
 
+        slide->lines_consumed = lc;
         slide = slide->next;
         ++sc;
     }
@@ -337,7 +338,8 @@ int ncurses_display(deck_t *deck, int notrans, int nofade, int invert, int reloa
 
         // print lines
         while(line) {
-            add_line(content, l, (COLS - max_cols) / 2, line, max_cols, colors);
+            add_line(content, l + ((LINES - slide->lines_consumed - bar_top - bar_bottom) / 2),
+                     (COLS - max_cols) / 2, line, max_cols, colors);
 
             // raise stop counter if we pass a line having a stop bit
             if(CHECK_BIT(line->bits, IS_STOP))

So long as the line-counting logic in ncurses_display is already correct (and based on my testing it is), then the above patch should do the trick.

I'll file a pull request soon for this.

Awesome @ethanherbertson, thanks a lot! 🙌