From cc2d88f7a57fc825bf8597f3b3c1cb85b21c003b Mon Sep 17 00:00:00 2001 From: Bjorn Winckler Date: Sat, 10 Jan 2009 17:37:49 +0100 Subject: [PATCH] Show output from external commands as it happens Previously, all output was sent to the frontend at once so only the last few rows were visible. This was a bit disconcerting when a command took a bit of time because there was no feedback that anything was happening. The downside to this patch is that it takes a bit longer for a command to finish since the frontend has to do more drawing. --- src/MacVim/gui_macvim.m | 42 ++++++++++++++++++++++++++++++++++++++++++ src/os_unix.c | 4 +++- src/proto/gui_macvim.pro | 2 ++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/MacVim/gui_macvim.m b/src/MacVim/gui_macvim.m index 138c859c..cea57bbd 100644 --- a/src/MacVim/gui_macvim.m +++ b/src/MacVim/gui_macvim.m @@ -210,6 +210,48 @@ gui_mch_flush(void) } + void +gui_macvim_flush(void) +{ + // This function counts how many times it is called and only flushes the + // draw queue if called sufficiently often. The first few times it is + // called it will flush often, but the more it is called the less likely is + // it that anything will be flushed. (The counter resets itself if the + // function isn't called for a second.) + // + // NOTE: Should only be used in loops where it is impossible to know how + // often Vim needs to flush. It was written to handle output from external + // commands (see mch_call_shell() in os_unix.c). + + static CFAbsoluteTime lastTime = 0; + static int delay = 1; + static int counter = 0; + static int scrolls = 0; + + CFAbsoluteTime nowTime = CFAbsoluteTimeGetCurrent(); + CFAbsoluteTime delta = nowTime - lastTime; + if (delta > 1.0) + delay = 1; + + // We assume that each call corresponds roughly to one line out output. + // When one page has scrolled by we increase the delay before the next + // flush. + if (++scrolls > gui.num_rows) { + delay <<= 1; + if (delay > 0x10000) + delay = 0x10000; + scrolls = 0; + } + + if (++counter > delay) { + gui_macvim_force_flush(); + counter = 0; + } + + lastTime = nowTime; +} + + /* Force flush output to MacVim. Do not call this method unless absolutely * necessary. */ void diff --git a/src/os_unix.c b/src/os_unix.c index 533faa8a..6f8a78fd 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -4435,8 +4435,10 @@ mch_call_shell(cmd, options) cursor_on(); out_flush(); # if FEAT_GUI_MACVIM - if (gui.in_use) + if (gui.in_use) { fast_breakcheck(); + gui_macvim_flush(); + } # endif if (got_int) break; diff --git a/src/proto/gui_macvim.pro b/src/proto/gui_macvim.pro index 6798c13a..d0c1efe7 100644 --- a/src/proto/gui_macvim.pro +++ b/src/proto/gui_macvim.pro @@ -14,6 +14,8 @@ gui_mch_update(void); void gui_mch_flush(void); void +gui_macvim_flush(void); + void gui_macvim_force_flush(void); int gui_mch_wait_for_chars(int wtime); -- 2.11.4.GIT