From d9a3733138eb86fcfd570e826ee327a308f0459a Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Thu, 12 Mar 2009 14:43:12 +0100 Subject: [PATCH] Automatic commit --- selector.cc | 30 ++++++++++++++++++++++++++-- smarthist.sh | 55 ---------------------------------------------------- 2 files changed, 28 insertions(+), 57 deletions(-) delete mode 100755 smarthist.sh diff --git a/selector.cc b/selector.cc index eb44a61..c63a1d3 100644 --- a/selector.cc +++ b/selector.cc @@ -44,6 +44,10 @@ #include #include #include +#include +#include +#include +#include using namespace std; @@ -427,8 +431,30 @@ int main(int argc, char **argv) { if((key == KEY_ENTER || key == '\n') && temporary_line >= 0 && temporary_line < nb_lines) { char *tty = ttyname (STDIN_FILENO); int fd = open(tty, O_WRONLY); - write(fd, lines[temporary_line], strlen(lines[temporary_line])); - close(fd); + + 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 { diff --git a/smarthist.sh b/smarthist.sh deleted file mode 100755 index 71f7c93..0000000 --- a/smarthist.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/bash - -# -# selector is a simple shell command for selection of strings with a -# dynamic pattern-matching. -# -# Copyright (c) 2009 Francois Fleuret -# Written by Francois Fleuret -# -# This file is part of selector. -# -# selector is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 3 as -# published by the Free Software Foundation. -# -# selector is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with selector. If not, see . -# - -# You can add in your ~/.inputrc something like -# Control-h: "smarthist.sh\n" -# so that C-h will invoke this script - -EXE=./selector - -# We do not want a security breach - -OUT=`mktemp /tmp/selector.XXXXXX` -touch ${OUT} -chmod go-rwx ${OUT} - -${EXE} -o ${OUT} -f ~/.bash_history -# ${EXE} -b -o ${OUT} -f ~/.bash_history - -# We set the echo off - -OLD_SETTINGS=`stty -g` -stty -echo raw - -# Put the line we got into the tty buffer - -writevt `tty` "`cat ${OUT}`" - -# Set back the echo as it was - -stty ${OLD_SETTINGS} - -# Remove the file containing what we got from the selector - -\rm ${OUT} -- 2.20.1