aboutsummaryrefslogtreecommitdiff
path: root/st.c
diff options
context:
space:
mode:
authorChristoph Lohmann <20h@r-36.net>2013-04-13 08:48:17 +0200
committerChristoph Lohmann <20h@r-36.net>2013-04-13 08:48:17 +0200
commit4018b2c5075c1cab603ca137ef5f6d68b9cee483 (patch)
treede5e851b2c58484d379d029c1d51c171236aca1f /st.c
parentddd429ea2478beeb7d17d9b548abd9173049dcc6 (diff)
downloadst-4018b2c5075c1cab603ca137ef5f6d68b9cee483.tar.gz
st-4018b2c5075c1cab603ca137ef5f6d68b9cee483.zip
Making the copy and pasting consistent.
The copying and pasting in the terminald and GUI world is flawed. Due to the discussion on the mailinglist it seems that sending '\n' is what GUIs expect and '\r' what terminal applications want. St now implements that behaviour.
Diffstat (limited to 'st.c')
-rw-r--r--st.c35
1 files changed, 31 insertions, 4 deletions
diff --git a/st.c b/st.c
index 93058b9..49a9770 100644
--- a/st.c
+++ b/st.c
@@ -788,9 +788,18 @@ selcopy(void) {
788 memcpy(ptr, p, size); 788 memcpy(ptr, p, size);
789 ptr += size; 789 ptr += size;
790 } 790 }
791 /* \n at the end of every selected line except for the last one */ 791
792 /*
793 * Copy and pasting of line endings is inconsistent
794 * in the inconsistent terminal and GUI world.
795 * The best solution seems like to produce '\n' when
796 * something is copied from st and convert '\n' to
797 * '\r', when something to be pasted is received by
798 * st.
799 * FIXME: Fix the computer world.
800 */
792 if(is_selected && y < sel.e.y) 801 if(is_selected && y < sel.e.y)
793 *ptr++ = '\r'; 802 *ptr++ = '\n';
794 } 803 }
795 *ptr = 0; 804 *ptr = 0;
796 } 805 }
@@ -801,7 +810,7 @@ void
801selnotify(XEvent *e) { 810selnotify(XEvent *e) {
802 ulong nitems, ofs, rem; 811 ulong nitems, ofs, rem;
803 int format; 812 int format;
804 uchar *data; 813 uchar *data, *last, *repl;
805 Atom type; 814 Atom type;
806 815
807 ofs = 0; 816 ofs = 0;
@@ -812,7 +821,25 @@ selnotify(XEvent *e) {
812 fprintf(stderr, "Clipboard allocation failed\n"); 821 fprintf(stderr, "Clipboard allocation failed\n");
813 return; 822 return;
814 } 823 }
815 ttywrite((const char *) data, nitems * format / 8); 824
825 /*
826 * As seen in selcopy:
827 * Line endings are inconsistent in the terminal and GUI world
828 * copy and pasting. When receiving some selection data,
829 * replace all '\n' with '\r'.
830 * FIXME: Fix the computer world.
831 */
832 repl = data;
833 last = data + nitems * format / 8;
834 while((repl = memchr(repl, '\n', last - repl))) {
835 *repl++ = '\r';
836 }
837
838 last = data + nitems * format / 8;
839 repl = data;
840
841
842 ttywrite((const char *)data, nitems * format / 8);
816 XFree(data); 843 XFree(data);
817 /* number of 32-bit chunks returned */ 844 /* number of 32-bit chunks returned */
818 ofs += nitems * format / 32; 845 ofs += nitems * format / 32;