From be17c5f6f7db6086e5199858629818b58146b35a Mon Sep 17 00:00:00 2001 From: Guo Rui Date: Sat, 11 Jul 2009 01:04:36 +0800 Subject: [PATCH] First (hopefully) working version of caption processing. --- src/display.c | 5 +++++ src/lua.c | 27 +++++++++++++++++++++++++++ src/screen.c | 6 ------ src/scripts/caption.lua | 18 ++++++++++++++++++ 4 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 src/scripts/caption.lua diff --git a/src/display.c b/src/display.c index 651a281..74ce3e6 100644 --- a/src/display.c +++ b/src/display.c @@ -3002,6 +3002,11 @@ int y, from, to, isblank; if (y == cv->c_ye + 1 && from >= cv->c_xs && from <= cv->c_xe) { p = Layer2Window(cv->c_layer); +#ifdef SCRIPT + /*FIXME: is it okey to bypass all the following code?*/ + if (trigger_sevent(&globalevents.processcaption, cv)) + continue; +#endif buf = MakeWinMsgEv(captionstring, p, '%', cv->c_xe - cv->c_xs + (cv->c_xe + 1 < D_width || D_CLP), &cv->c_captev, 0); if (cv->c_captev.timeout.tv_sec) evenq(&cv->c_captev); diff --git a/src/lua.c b/src/lua.c index eedb10d..b7539ac 100644 --- a/src/lua.c +++ b/src/lua.c @@ -614,7 +614,34 @@ static const luaL_reg canvas_metamethods[] = { {0, 0} }; +extern struct mchar mchar_so; +static int +canvas_update_caption(lua_State *L) +{ + struct canvas *cv = check_canvas(L, 1); + unsigned int len; + const char *caption = luaL_checklstring(L, 3, &len); + int l, padlen; + padlen = cv->c_xe - cv->c_xs + + (display ? (cv->c_xe + 1 < D_width || D_CLP): 0); + struct win *w = Layer2Window(cv->c_layer); + char * buf = MakeWinMsgEv((char *)caption, w, '%', padlen, &cv->c_captev, 0); + if (cv->c_captev.timeout.tv_sec) + evenq(&cv->c_captev); + l = strlen(buf); + + GotoPos(cv->c_xs, cv->c_ye+1); + /*XXX:what does this mean?*/ + SetRendition(&mchar_so); + if (l > cv->c_xe - cv->c_xs + 1) + l = cv->c_xe - cv->c_xs + 1; + PutWinMsg(buf, cv->c_xs, l); + + return 0; +} + static const struct Xet_reg canvas_setters[] = { + {"caption", 0, 0, canvas_update_caption/*absolute setter*/}, {0, 0} }; diff --git a/src/screen.c b/src/screen.c index 40b69e6..c445b12 100644 --- a/src/screen.c +++ b/src/screen.c @@ -2538,12 +2538,6 @@ int rec; winmsg_numrend = -winmsg_numrend; *p = '\0'; -#ifdef SCRIPT - /* FIXME: Need a way to pass result back.*/ - if (str == hstatusstring || str == captionstring) - if (trigger_sevent(&globalevents.processcaption, display, str == hstatusstring)) - return winmsg_buf; -#endif if (!display) return winmsg_buf; diff --git a/src/scripts/caption.lua b/src/scripts/caption.lua new file mode 100644 index 0000000..c5ba970 --- /dev/null +++ b/src/scripts/caption.lua @@ -0,0 +1,18 @@ +function captionprocess (canvas) + display = canvas.display + windows = screen.windows() + + caption = " " + for i, w in ipairs(windows) do + if w == canvas.window then + caption = caption .. "%{= b}" + end + caption = caption .. string.format("%d: %s", w.number, w.title) + caption = caption .. " " + end + + canvas.caption = caption + return 1 +end + +screen.hook("processcaption", captionprocess); -- 2.11.4.GIT