- // ofstream out("/tmp/selector.out");
- // if(key == KEY_ENTER || key == '\n') {
- // out << lines[highlighted_line] << endl;
- // } else {
- // out << endl;
- // }
- // out.flush();
+ if(output_to_vt_buffer) {
+ if((key == KEY_ENTER || key == '\n') && temporary_line >= 0 && temporary_line < nb_lines) {
+ char *tty = ttyname (STDIN_FILENO);
+ int fd = open(tty, O_WRONLY);
+
+ struct termios oldtio, newtio;
+
+ if (fd >= 0) {
+ // Save current port settings
+ tcgetattr(fd,&oldtio);
+ bzero(&newtio, sizeof(newtio));
+ newtio.c_cflag = 0;
+ newtio.c_iflag = 0;
+ newtio.c_oflag = 0;
+ // Set input mode (non-canonical, *no echo*,...)
+ newtio.c_lflag = 0;
+ tcflush(fd, TCIFLUSH);
+ tcsetattr(fd,TCSANOW, &newtio);
+ for(char *k = lines[temporary_line]; *k; k++) {
+ ioctl(fd, TIOCSTI, k);
+ }
+ // Restore the old settings
+ tcsetattr(fd,TCSANOW, &oldtio);
+ close(fd);
+ } else {
+ cerr << "Can not open " << tty << endl;
+ exit(1);
+ }
+ }
+ } else {
+
+ ofstream out(output_filename);
+ if(out.fail()) {
+ cerr << "Can not open " << output_filename << " for writing." << endl;
+ exit(1);
+ } else {
+ if((key == KEY_ENTER || key == '\n') && temporary_line >= 0 && temporary_line < nb_lines) {
+ out << lines[temporary_line] << endl;
+ } else {
+ out << endl;
+ }
+ out.flush();
+ }
+ }