Changeset 249

Show
Ignore:
Timestamp:
04/30/08 11:40:51 (7 months ago)
Author:
conrad
Message:

When stdout is a tty, use stderr to ensure there is a newline before
the shell prompt.

(Modified) patch from Yair K.:

If the used selection does not end with a newline, then:

A) If 'xsel -o' than the command prompt may overwrite the last line (depends

on $PS1, shell, etc. but I think quite likely to happen)

B) 'xsel -a -o -i' doesn't display the last line (on Linux at least). The

last line will still exist after appending, but it isn't displayed. This is
(I suspect) because stdout is line-buffered, so stdout isn't flushed yet.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • xsel/trunk/xsel.c

    r248 r249  
    21592159    /* Get the current selection */ 
    21602160    old_sel = get_selection_text (selection); 
    2161     if (old_sel) printf ("%s", old_sel); 
     2161    if (old_sel) 
     2162      { 
     2163         printf ("%s", old_sel); 
     2164         if (!do_append && *old_sel != '\0' && isatty(1) && 
     2165             old_sel[xs_strlen (old_sel) - 1] != '\n') 
     2166           { 
     2167             fflush (stdout); 
     2168             fprintf (stderr, "\n\\ No newline at end of selection\n"); 
     2169           } 
     2170      } 
    21622171  } 
    21632172 
     
    21692178  } 
    21702179  else if (do_input || !dont_input) { 
     2180    if ((do_output || !dont_output) && isatty(1)) fflush (stdout); 
    21712181    if (do_append) { 
    21722182      if (!old_sel) old_sel = get_selection_text (selection);