promptfix II
- From: Jindrich Novy <jnovy redhat com>
- To: MC Devel <mc-devel gnome org>
- Subject: promptfix II
- Date: Thu, 02 Dec 2004 10:46:26 +0100
Hello mc-devel,
I'm sending again the reimplementation of promptfix patch from 24.11.
with comments. There were some problems with
http://mail.gnome.org/archives/ in that time so it didn't appeared there
and it was only available in emails.
------------------------------------------------------------------
Please see:
http://mail.gnome.org/archives/mc-devel/2004-November/msg00031.html
for the bug reproduction.
The attached patch does the following:
1st hunk:
the removed part caused to cut out the beginning of the prompt so we
get:
<truncated dir name>]$
instead of:
[jnovy obelix <shortened dir name>]$
this part of code just prints the whole prompt without shortening to
subshell_prompt to let the prompt be displayed correctly via load_prompt
().
2nd hunk:
fix of the prompt drawing in subshell. It should display correct prompt
if it's size is less than COLS and redraw only the part of line where
was a previous prompt. If the prompt is larger that COLS, it'll draw the
prompt at a new line. Some additional work for this should be done since
we can use escape sequences to improve it a bit. And maybe we should cap
the value of COLS, etc.
3rd hunk:
Displays shrinked prompt in the panel (not subshell) mode with using
name_trunc(). This part is needed to let the prompt be displayed as
noted in the comment to 1st hunk.
Any comments are welcome.
greetings,
Jindrich
--
Jindrich Novy <jnovy redhat com>, http://people.redhat.com/jnovy/
--- mc-4.6.1-20041124/src/subshell.c.promptfix 2004-11-03 20:43:17.000000000 +0100
+++ mc-4.6.1-20041124/src/subshell.c 2004-11-24 10:24:49.760461024 +0100
@@ -596,19 +596,15 @@
bytes = read (subshell_pty, pty_buffer, pty_buffer_size);
/* Extract the prompt from the shell output */
-
- for (i = 0; i < bytes; ++i)
- if (pty_buffer[i] == '\n' || pty_buffer[i] == '\r') {
- prompt_pos = 0;
- } else {
- if (!pty_buffer[i])
- continue;
-
- subshell_prompt[prompt_pos++] = pty_buffer[i];
- if (prompt_pos == prompt_size)
- subshell_prompt =
- g_realloc (subshell_prompt, prompt_size *= 2);
- }
+ for (i = 0; i < bytes; ++i) {
+ if (pty_buffer[i] == '\n' || pty_buffer[i] == '\r' ||
+ !pty_buffer[i]) continue;
+
+ subshell_prompt[prompt_pos++] = pty_buffer[i];
+ if (prompt_pos == prompt_size)
+ subshell_prompt =
+ g_realloc (subshell_prompt, prompt_size *= 2);
+ }
subshell_prompt[prompt_pos] = '\0';
}
--- mc-4.6.1-20041124/src/main.c.promptfix 2004-10-22 07:47:25.000000000 +0200
+++ mc-4.6.1-20041124/src/main.c 2004-11-24 10:28:29.172105384 +0100
@@ -433,8 +433,14 @@
void
do_update_prompt (void)
{
+ static int prompt_size = 0;
+
if (update_prompt) {
- printf ("%s", subshell_prompt);
+ if ( !prompt_size || prompt_size > COLS ) {
+ printf (!prompt_size ? "\r%*c\r%s" : "\n\r%*c\r%s", COLS, ' ',
+ subshell_prompt);
+ } else
+ printf ("\r%*c\r%s", prompt_size, ' ', subshell_prompt);
fflush (stdout);
update_prompt = 0;
}
@@ -699,15 +705,11 @@
prompt = strip_ctrl_codes (subshell_prompt);
prompt_len = strlen (prompt);
- /* Check for prompts too big */
- if (COLS > 8 && prompt_len > COLS - 8) {
- prompt[COLS - 8] = 0;
- prompt_len = COLS - 8;
- }
- label_set_text (the_prompt, prompt);
- winput_set_origin ((WInput *) cmdline, prompt_len,
- COLS - prompt_len);
-
+ /* Shrink the prompt if it's too big */
+ label_set_text (the_prompt, name_trunc (prompt, COLS - 8));
+ prompt_len = prompt_len <= COLS - 8 ? prompt_len : COLS - 8;
+ winput_set_origin ((WInput *) cmdline, prompt_len,
+ COLS - prompt_len);
/* since the prompt has changed, and we are called from one of the
* get_event channels, the prompt updating does not take place
* automatically: force a cursor update and a screen refresh
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]