mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 20:01:27 +00:00
Confirm program quit whan multiple contexts are active
This commit is contained in:
parent
fabcc488ea
commit
07e643b10f
46
src/nnn.c
46
src/nnn.c
|
@ -434,12 +434,22 @@ static void printerr(int linenum)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Print prompt on the last line */
|
/* Print prompt on the last line */
|
||||||
static void printprompt(char *str)
|
static void printprompt(const char *str)
|
||||||
{
|
{
|
||||||
clearprompt();
|
clearprompt();
|
||||||
|
if (str)
|
||||||
printw(str);
|
printw(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int get_input(const char *prompt)
|
||||||
|
{
|
||||||
|
printprompt(prompt);
|
||||||
|
cleartimeout();
|
||||||
|
int r = getch();
|
||||||
|
settimeout();
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
/* Increase the limit on open file descriptors, if possible */
|
/* Increase the limit on open file descriptors, if possible */
|
||||||
static rlim_t max_openfds()
|
static rlim_t max_openfds()
|
||||||
{
|
{
|
||||||
|
@ -3123,10 +3133,7 @@ nochange:
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sel == SEL_OPEN) {
|
if (sel == SEL_OPEN) {
|
||||||
printprompt("press 'c' for cli mode");
|
r = get_input("press 'c' for cli mode");
|
||||||
cleartimeout();
|
|
||||||
r = getch();
|
|
||||||
settimeout();
|
|
||||||
if (r == 'c')
|
if (r == 'c')
|
||||||
r = F_NORMAL;
|
r = F_NORMAL;
|
||||||
else
|
else
|
||||||
|
@ -3195,10 +3202,7 @@ nochange:
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if it's a dir or file */
|
/* Check if it's a dir or file */
|
||||||
printprompt("press 'f'(ile) or 'd'(ir)");
|
r = get_input("press 'f'(ile) or 'd'(ir)");
|
||||||
cleartimeout();
|
|
||||||
r = getch();
|
|
||||||
settimeout();
|
|
||||||
if (r == 'f') {
|
if (r == 'f') {
|
||||||
r = openat(fd, tmp, O_CREAT, 0666);
|
r = openat(fd, tmp, O_CREAT, 0666);
|
||||||
close(r);
|
close(r);
|
||||||
|
@ -3246,11 +3250,7 @@ nochange:
|
||||||
/* Check if another file with same name exists */
|
/* Check if another file with same name exists */
|
||||||
if (faccessat(fd, tmp, F_OK, AT_SYMLINK_NOFOLLOW) != -1) {
|
if (faccessat(fd, tmp, F_OK, AT_SYMLINK_NOFOLLOW) != -1) {
|
||||||
/* File with the same name exists */
|
/* File with the same name exists */
|
||||||
printprompt("press 'y' to overwrite");
|
if (get_input("press 'y' to overwrite") != 'y') {
|
||||||
cleartimeout();
|
|
||||||
r = getch();
|
|
||||||
settimeout();
|
|
||||||
if (r != 'y') {
|
|
||||||
close(fd);
|
close(fd);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -3361,8 +3361,18 @@ nochange:
|
||||||
dentfree(dents);
|
dentfree(dents);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case SEL_CDQUIT:
|
case SEL_CDQUIT: // fallthrough
|
||||||
{
|
case SEL_QUIT:
|
||||||
|
for (r = 0; r < MAX_CTX; ++r)
|
||||||
|
if (r != cfg.curctx && g_ctx[r].c_cfg.ctxactive) {
|
||||||
|
r = get_input("press 'y' to quit all contexts");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(r == MAX_CTX || r == 'y'))
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (sel == SEL_CDQUIT) {
|
||||||
tmp = getenv("NNN_TMPFILE");
|
tmp = getenv("NNN_TMPFILE");
|
||||||
if (!tmp) {
|
if (!tmp) {
|
||||||
printmsg("set NNN_TMPFILE");
|
printmsg("set NNN_TMPFILE");
|
||||||
|
@ -3375,10 +3385,8 @@ nochange:
|
||||||
fprintf(fp, "cd \"%s\"", path);
|
fprintf(fp, "cd \"%s\"", path);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Fall through to exit */
|
|
||||||
} // fallthrough
|
|
||||||
case SEL_QUIT:
|
|
||||||
dentfree(dents);
|
dentfree(dents);
|
||||||
return;
|
return;
|
||||||
} /* switch (sel) */
|
} /* switch (sel) */
|
||||||
|
|
Loading…
Reference in a new issue