fix for readline terminal size problems when window is resized with open pager

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: fix for readline terminal size problems when window is resized with open pager
Date: 2015-12-08 18:07:50
Message-ID: CAHyXU0wv-bVMX8WO6-SUOE1GEiQG9NFA3nCKaRr_enmDntid+w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello,

The following patch deals with a long standing gripe of mine that the
terminal frequently gets garbled so that when typing. I guess this
problem is entirely dependent on pager settings and your interaction
patterns with the window (in particular, if you tend to resize the
window when the pager is open). Experimenting with the problem, it
became pretty clear: libreadline for whatever reason does not get the
signal from the kernal telling it that the bounds have changed. This
problem does not manifest 100% of the time, you may have to get the
pager to open, resize the window, close the pager, and recall a
previous long line (or type a new one) several times to get the
problem to occur. Nevertheless, the attached seems to end the
problem.

This adds a dependency to print.c on input.h for the readline macro
and the readline header.

merlin

diff --git a/src/bin/psql/print.c b/src/bin/psql/print.c
index 655850b..ede736e 100644
--- a/src/bin/psql/print.c
+++ b/src/bin/psql/print.c
@@ -27,6 +27,7 @@
#include "common.h"
#include "mbprint.h"
#include "print.h"
+#include "input.h"

/*
* We define the cancel_pressed flag in this file, rather than common.c where
@@ -2247,6 +2248,13 @@ ClosePager(FILE *pagerpipe)
#ifndef WIN32
pqsignal(SIGPIPE, SIG_DFL);
#endif
+#ifdef USE_READLINE
+ /*
+ * Force libreadline to recheck the terminal size in case pager may
+ * have handled any terminal resize events.
+ */
+ rl_resize_terminal();
+#endif
}
}

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2015-12-08 18:35:59 Re: Include ppc64le build type for back branches
Previous Message Robert Haas 2015-12-08 18:06:45 Re: Include ppc64le build type for back branches