When using the -x option, the part of the line before the separator is not returned.
[selector.git] / selector.cc
index 8e03818..4d86da2 100644 (file)
@@ -1037,10 +1037,20 @@ int main(int argc, char **argv) {
 
   if((key == KEY_ENTER || key == '\n')) {
 
-    if(output_to_vt_buffer) {
-      if(displayed_focus_line >= 0 && displayed_focus_line < nb_lines) {
-        inject_into_tty_buffer(lines[displayed_focus_line]);
+    char *t;
+
+    if(displayed_focus_line >= 0 && displayed_focus_line < nb_lines) {
+      t = lines[displayed_focus_line];
+      if(label_separator) {
+        while(*t && *t != label_separator) t++;
+        if(*t) t++;
       }
+    } else {
+      t = 0;
+    }
+
+    if(output_to_vt_buffer && t) {
+      inject_into_tty_buffer(t);
     }
 
     if(output_filename[0]) {
@@ -1049,8 +1059,8 @@ int main(int argc, char **argv) {
         cerr << "Can not open " << output_filename << " for writing." << endl;
         exit(1);
       } else {
-        if(displayed_focus_line >= 0 && displayed_focus_line < nb_lines) {
-          out << lines[displayed_focus_line] << endl;
+        if(t) {
+          out << t << endl;
         } else {
           out << endl;
         }