slmenu / slmenu.c

Diff from to
 static size_t nextrune(int);
 static void   readstdin(void);
 static int    run(void);
-static void   setup(int);
+static void   setup(void);
 static size_t textw(const char*);
 static size_t textwn(const char*, int);
 static char   text[BUFSIZ] = "";
+static int    barpos = 0;
 static int    mw;
 static int    inputw, promptw;
 static size_t cursor;
 cleanup() {
-	fprintf(stderr, "\033[G\033[K");
+	if(barpos==0) fprintf(stderr, "\n");
+	else fprintf(stderr, "\033[G\033[K");
 	tcsetattr(0, TCSANOW, &tio_old);
 			return EXIT_FAILURE;
 		case CONTROL('M'): /* Return */
 		case CONTROL('J'):
-			puts(sel ? sel->text : text);
-			return EXIT_SUCCESS;
+			if(sel) strncpy(text, sel->text, sizeof text); /* Complete the input first, when hitting return */
+			cursor = strlen(text);
+			match(TRUE);
+			drawmenu();
+			/* fallthrough */
 		case CONTROL(']'):
 		case CONTROL('\\'): /* These are usually close enough to RET to replace Shift+RET, again due to console limitations */
-setup(int position) {
+setup(void) {
 	int fd, result=-1;
 	struct winsize ws;
 	inputw=MIN(inputw, mw/3);
-	if(position!=0) fprintf(stderr, "\033[%iH", (position>0 || result<0)?0:ws.ws_row);
+	if(barpos!=0) fprintf(stderr, "\033[%iH", (barpos>0 || result<0)?0:ws.ws_row);
 main(int argc, char **argv) {
 	int i;
-	int position=0;
 	for(i=0; i<argc; i++)
 		if(!strcmp(argv[i], "-v")) {
 		else if(!strcmp(argv[i], "-i"))
 			fstrncmp = strncasecmp;
 		else if(!strcmp(argv[i], "-t"))
-			position=1;
+			barpos=1;
 		else if(!strcmp(argv[i], "-b"))
-			position=-1;
+			barpos=-1;
-	setup(position);
+	setup();
 	i = run();
 	return i;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.