Remove readline dep and use native prompt

- `nnn` is all about navigational convenience so the user doesn't have to type
- the binary size increases due to readline linkage
- alternative workflow: ^G, cd, `nnn`
- readline required using the prompt and the history would stay after quit
This commit is contained in:
Arun Prakash Jana 2018-08-16 22:54:49 +05:30
parent 9d3f75f63b
commit 8b8e644cf5
No known key found for this signature in database
GPG key ID: A75979F35C080412
4 changed files with 7 additions and 96 deletions

View file

@ -8,7 +8,6 @@ INSTALL ?= install
CFLAGS ?= -O3 CFLAGS ?= -O3
CFLAGS += -Wall -Wextra -Wno-unused-parameter CFLAGS += -Wall -Wextra -Wno-unused-parameter
LDLIBS = -lreadline
ifeq ($(shell $(PKG_CONFIG) ncursesw && echo 1),1) ifeq ($(shell $(PKG_CONFIG) ncursesw && echo 1),1)
CFLAGS += $(shell $(PKG_CONFIG) --cflags ncursesw) CFLAGS += $(shell $(PKG_CONFIG) --cflags ncursesw)

View file

@ -65,7 +65,6 @@ Have fun with it! Missing a feature? Want to contribute? Head to the rolling [To
- [sample scripts](#sample-scripts) - [sample scripts](#sample-scripts)
- [change dir color](#change-dir-color) - [change dir color](#change-dir-color)
- [file copy, move, delete](#file-copy-move-delete) - [file copy, move, delete](#file-copy-move-delete)
- [boost chdir prompt](#boost-chdir-prompt)
- [work faster at rename prompt](#work-faster-at-rename-prompt) - [work faster at rename prompt](#work-faster-at-rename-prompt)
- [set idle timeout](#set-idle-timeout) - [set idle timeout](#set-idle-timeout)
- [show hot plugged drives](#show-hot-plugged-drives) - [show hot plugged drives](#show-hot-plugged-drives)
@ -137,7 +136,7 @@ Intrigued? Find out [HOW](https://github.com/jarun/nnn/wiki/performance-factors)
#### Dependencies #### Dependencies
`nnn` needs libreadline, libncursesw (on Linux or ncurses on OS X) and standard libc. `nnn` needs libncursesw (on Linux or ncurses on OS X) and standard libc.
#### From a package manager #### From a package manager
@ -164,7 +163,7 @@ Packages for Arch Linux, CentOS, Debian, Fedora and Ubuntu are available with th
To cook yourself, download the [latest stable release](https://github.com/jarun/nnn/releases/latest) or clone this repository (*risky*). Then install the dependencies and compile (e.g. on Ubuntu 16.04): To cook yourself, download the [latest stable release](https://github.com/jarun/nnn/releases/latest) or clone this repository (*risky*). Then install the dependencies and compile (e.g. on Ubuntu 16.04):
$ sudo apt-get install libncursesw5-dev libreadline6-dev $ sudo apt-get install libncursesw5-dev
$ make $ make
$ sudo make install $ sudo make install
@ -480,10 +479,6 @@ Any other value disables colored directories.
In addition, `nnn` integrates with vidir. vidir supports batch file move and delete. In addition, `nnn` integrates with vidir. vidir supports batch file move and delete.
#### boost chdir prompt
`nnn` uses libreadline for the chdir prompt input. So all the fantastic features of readline (e.g. case insensitive tab completion, history, reverse-i-search) are available to you based on your readline [configuration](https://wiki.archlinux.org/index.php/Readline).
#### work faster at rename prompt #### work faster at rename prompt
The rename prompt supports some bash-like command-line shortcuts - <kbd>^A</kbd>, <kbd>^E</kbd>, <kbd>^U</kbd>. <kbd>^L</kbd> clears the name. The rename prompt supports some bash-like command-line shortcuts - <kbd>^A</kbd>, <kbd>^E</kbd>, <kbd>^U</kbd>. <kbd>^L</kbd> clears the name.

74
nnn.c
View file

@ -73,8 +73,6 @@
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#include <readline/history.h>
#include <readline/readline.h>
#ifndef __USE_XOPEN_EXTENDED #ifndef __USE_XOPEN_EXTENDED
#define __USE_XOPEN_EXTENDED 1 #define __USE_XOPEN_EXTENDED 1
#endif #endif
@ -849,25 +847,6 @@ xchartohex(char c)
return c; return c;
} }
/* Trim all whitespace from both ends, / from end */
static char *
strstrip(char *s)
{
if (!s || !*s)
return s;
size_t len = strlen(s) - 1;
while (len != 0 && (isspace(s[len]) || s[len] == '/'))
--len;
s[len + 1] = '\0';
while (*s && isspace(*s))
++s;
return s;
}
static char * static char *
getmime(const char *file) getmime(const char *file)
{ {
@ -2625,45 +2604,12 @@ nochange:
break; break;
case SEL_CD: case SEL_CD:
{ {
char *input; int truecd = 0;
int truecd;
/* Save the program start dir */ tmp = xreadline(NULL, "cd: ");
tmp = getcwd(newpath, PATH_MAX); if (tmp == NULL || tmp[0] == '\0')
if (tmp == NULL) {
printwarn();
goto nochange;
}
/* Switch to current path for readline(3) */
if (chdir(path) == -1) {
printwarn();
goto nochange;
}
exitcurses();
tmp = readline("cd: ");
refresh();
/* Change back to program start dir */
if (chdir(newpath) == -1)
printwarn();
if (tmp[0] == '\0')
break; break;
/* Add to readline(3) history */
add_history(tmp);
input = tmp;
tmp = strstrip(tmp);
if (tmp[0] == '\0') {
free(input);
break;
}
truecd = 0;
if (tmp[0] == '~') { if (tmp[0] == '~') {
/* Expand ~ to HOME absolute path */ /* Expand ~ to HOME absolute path */
char *home = getenv("HOME"); char *home = getenv("HOME");
@ -2671,30 +2617,23 @@ nochange:
if (home) if (home)
snprintf(newpath, PATH_MAX, "%s%s", home, tmp + 1); snprintf(newpath, PATH_MAX, "%s%s", home, tmp + 1);
else { else {
free(input);
printmsg(messages[STR_NOHOME_ID]); printmsg(messages[STR_NOHOME_ID]);
goto nochange; goto nochange;
} }
} else if (tmp[0] == '-' && tmp[1] == '\0') { } else if (tmp[0] == '-' && tmp[1] == '\0') {
if (lastdir[0] == '\0') { if (lastdir[0] == '\0')
free(input);
break; break;
}
/* Switch to last visited dir */ /* Switch to last visited dir */
xstrlcpy(newpath, lastdir, PATH_MAX); xstrlcpy(newpath, lastdir, PATH_MAX);
truecd = 1; truecd = 1;
} else if ((r = all_dots(tmp))) { } else if ((r = all_dots(tmp))) {
if (r == 1) { if (r == 1)
/* Always in the current dir */ /* Always in the current dir */
free(input);
break; break;
}
/* Show a message if already at / */ /* Show a message if already at / */
if (istopdir(path)) { if (istopdir(path)) {
free(input);
/* Continue in navigate-as-you-type mode, if enabled */ /* Continue in navigate-as-you-type mode, if enabled */
if (cfg.filtermode) if (cfg.filtermode)
presel = FILTER; presel = FILTER;
@ -2716,7 +2655,6 @@ nochange:
dir = xdirname(dir); dir = xdirname(dir);
if (access(dir, R_OK) == -1) { if (access(dir, R_OK) == -1) {
printwarn(); printwarn();
free(input);
goto nochange; goto nochange;
} }
} }
@ -2735,8 +2673,6 @@ nochange:
} else } else
mkpath(path, tmp, newpath, PATH_MAX); mkpath(path, tmp, newpath, PATH_MAX);
free(input);
if (!xdiraccess(newpath)) if (!xdiraccess(newpath))
goto nochange; goto nochange;

View file

@ -14,17 +14,14 @@ packages:
- pkg-config - pkg-config
deps: deps:
- ncurses - ncurses
- readline
centos7.2: centos7.2:
builddeps: builddeps:
- make - make
- gcc - gcc
- pkgconfig - pkgconfig
- ncurses-devel - ncurses-devel
- readline-devel
deps: deps:
- ncurses - ncurses
- readline
commands: commands:
pre: pre:
- yum install epel-release - yum install epel-release
@ -34,10 +31,8 @@ packages:
- gcc - gcc
- pkgconfig - pkgconfig
- ncurses-devel - ncurses-devel
- readline-devel
deps: deps:
- ncurses - ncurses
- readline
commands: commands:
pre: pre:
- yum install epel-release - yum install epel-release
@ -47,67 +42,53 @@ packages:
- gcc - gcc
- pkg-config - pkg-config
- libncursesw5-dev - libncursesw5-dev
- libreadline-dev
deps: deps:
- libncursesw5 - libncursesw5
- readline-common
fedora25: fedora25:
builddeps: builddeps:
- make - make
- gcc - gcc
- pkgconfig - pkgconfig
- ncurses-devel - ncurses-devel
- readline-devel
deps: deps:
- ncurses - ncurses
- readline
fedora26: fedora26:
builddeps: builddeps:
- make - make
- gcc - gcc
- pkg-config - pkg-config
- ncurses-devel - ncurses-devel
- readline-devel
deps: deps:
- ncurses - ncurses
- readline
fedora27: fedora27:
builddeps: builddeps:
- make - make
- gcc - gcc
- pkg-config - pkg-config
- ncurses-devel - ncurses-devel
- readline-devel
deps: deps:
- ncurses - ncurses
- readline
# opensuse42.3: # opensuse42.3:
# builddeps: # builddeps:
# - make # - make
# - gcc # - gcc
# - pkg-config # - pkg-config
# - ncurses-devel # - ncurses-devel
# - readline-devel
# deps: # deps:
# - ncurses # - ncurses
# - readline
ubuntu16.04: ubuntu16.04:
builddeps: builddeps:
- make - make
- gcc - gcc
- pkg-config - pkg-config
- libncursesw5-dev - libncursesw5-dev
- libreadline6-dev
deps: deps:
- libncursesw5 - libncursesw5
- libreadline6
ubuntu18.04: ubuntu18.04:
builddeps: builddeps:
- make - make
- gcc - gcc
- pkg-config - pkg-config
- libncursesw5-dev - libncursesw5-dev
- libreadline-dev
deps: deps:
- libncursesw5 - libncursesw5
- libreadline7