Re: subshell prompt fix



Hi Leonard,

On Wed, 2004-11-17 at 03:45 +0100, Leonard den Ottolander wrote:
> How does the attached patch make the prompt look on BSD?
> 
> Are there better ways to clear the line?

I'm sending two patches to fix the promptfix problem. The first one
(promptfix-simple) is pretty simple and it uses the fact that when '\r'
is sent to the shell, it not only sets the writing position to the first
column, but also clears the whole line (at least in my case). This needs
testing.

The second patch behaves more "rigorously" as it sets the position to
the beginning and assumes that '\r' won't clear the line. So it clears
only the part of the line, where the previous prompt was written. So it
remembers a size of previous prompt. This frees us from solving of COLS,
etc. problems and won't draw more characters than needed.

This version of the patches is #ifdef'd only for linux since it's tested
there. As far as I had a mail-clash with pchel there is different
workaround needed or different prompt drawing bug is present on other
environments such as FreeBSD. Unfortunately I have no access to such box
so I'll let to someone else to fix it for *BSD.

greetings,
Jindrich

-- 
Jindrich Novy <jnovy redhat com>, http://people.redhat.com/jnovy/
--- mc-4.6.1-20041117/src/main.c.promptfix	2004-10-22 07:47:25.000000000 +0200
+++ mc-4.6.1-20041117/src/main.c	2004-11-17 16:25:28.000000000 +0100
@@ -434,7 +434,14 @@
 do_update_prompt (void)
 {
     if (update_prompt) {
+#ifdef __linux__
+	printf ("\r%s", subshell_prompt);
+#else
+	/* FIXME: Subshell prompt displaying is buggy
+		  also on other OSes (FreeBSD), but
+		  requires different workaround */
 	printf ("%s", subshell_prompt);
+#endif
 	fflush (stdout);
 	update_prompt = 0;
     }
--- mc-4.6.1-20041117/src/subshell.c.promptfix	2004-11-03 20:43:17.000000000 +0100
+++ mc-4.6.1-20041117/src/subshell.c	2004-11-17 19:16:06.000000000 +0100
@@ -106,6 +106,9 @@ enum subshell_state_enum subshell_state;
 /* Holds the latest prompt captured from the subshell */
 char *subshell_prompt = NULL;
 
+/* Size of last prompt in characters */
+int prompt_lastsize = 0;
+
 /* Initial length of the buffer for the subshell's prompt */
 #define INITIAL_PROMPT_SIZE 10
 
@@ -612,8 +615,12 @@ read_subshell_prompt (void)
 
 	subshell_prompt[prompt_pos] = '\0';
     }
+
     if (rc == 0 && bytes == 0)
 	return FALSE;
+
+    prompt_lastsize = strlen (subshell_prompt);
+
     return TRUE;
 }
 
--- mc-4.6.1-20041117/src/subshell.h.promptfix	2002-12-24 01:13:44.000000000 +0100
+++ mc-4.6.1-20041117/src/subshell.h	2004-11-17 19:20:19.000000000 +0100
@@ -20,6 +20,9 @@ extern enum subshell_state_enum subshell
 /* Holds the latest prompt captured from the subshell */
 extern char *subshell_prompt;
 
+/* Size of last prompt in characters */
+extern int prompt_lastsize;
+
 /* For the `how' argument to various functions */
 enum {QUIETLY, VISIBLY};
 
--- mc-4.6.1-20041117/src/main.c.promptfix	2004-10-22 07:47:25.000000000 +0200
+++ mc-4.6.1-20041117/src/main.c	2004-11-17 20:05:01.000000000 +0100
@@ -434,7 +434,14 @@ void
 do_update_prompt (void)
 {
     if (update_prompt) {
+#ifdef __linux__
+	printf ("\r%*c\r%s", prompt_lastsize, ' ', subshell_prompt);
+#else
+	/* FIXME: Subshell prompt displaying is buggy
+		  also on other platforms (FreeBSD), but
+		  requires different workaround */
 	printf ("%s", subshell_prompt);
+#endif
 	fflush (stdout);
 	update_prompt = 0;
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]