diff options
author | Arun Prakash Jana <engineerarun@gmail.com> | 2018-08-16 22:54:49 +0530 |
---|---|---|
committer | Arun Prakash Jana <engineerarun@gmail.com> | 2018-08-16 22:54:49 +0530 |
commit | 8b8e644cf50492967a5f24d32ad36cfe74b13aa0 (patch) | |
tree | b1c462ef92f2dc8afc0d35a579de048f2c66c650 | |
parent | 9d3f75f63b71d80d9ae753956476e801b687e6f3 (diff) | |
download | nnn-8b8e644cf50492967a5f24d32ad36cfe74b13aa0.tar.gz |
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
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | README.md | 9 | ||||
-rw-r--r-- | nnn.c | 74 | ||||
-rw-r--r-- | packagecore.yaml | 19 |
4 files changed, 7 insertions, 96 deletions
@@ -8,7 +8,6 @@ INSTALL ?= install CFLAGS ?= -O3 CFLAGS += -Wall -Wextra -Wno-unused-parameter -LDLIBS = -lreadline ifeq ($(shell $(PKG_CONFIG) ncursesw && echo 1),1) CFLAGS += $(shell $(PKG_CONFIG) --cflags ncursesw) @@ -65,7 +65,6 @@ Have fun with it! Missing a feature? Want to contribute? Head to the rolling [To - [sample scripts](#sample-scripts) - [change dir color](#change-dir-color) - [file copy, move, delete](#file-copy-move-delete) - - [boost chdir prompt](#boost-chdir-prompt) - [work faster at rename prompt](#work-faster-at-rename-prompt) - [set idle timeout](#set-idle-timeout) - [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 -`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 @@ -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): - $ sudo apt-get install libncursesw5-dev libreadline6-dev + $ sudo apt-get install libncursesw5-dev $ make $ 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. -#### 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 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. @@ -73,8 +73,6 @@ #include <string.h> #include <time.h> #include <unistd.h> -#include <readline/history.h> -#include <readline/readline.h> #ifndef __USE_XOPEN_EXTENDED #define __USE_XOPEN_EXTENDED 1 #endif @@ -849,25 +847,6 @@ xchartohex(char 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 * getmime(const char *file) { @@ -2625,44 +2604,11 @@ nochange: break; case SEL_CD: { - char *input; - int truecd; - - /* Save the program start dir */ - tmp = getcwd(newpath, PATH_MAX); - if (tmp == NULL) { - printwarn(); - goto nochange; - } - - /* Switch to current path for readline(3) */ - if (chdir(path) == -1) { - printwarn(); - goto nochange; - } + int truecd = 0; - exitcurses(); - tmp = readline("cd: "); - refresh(); - - /* Change back to program start dir */ - if (chdir(newpath) == -1) - printwarn(); - - if (tmp[0] == '\0') - break; - - /* Add to readline(3) history */ - add_history(tmp); - - input = tmp; - tmp = strstrip(tmp); - if (tmp[0] == '\0') { - free(input); + tmp = xreadline(NULL, "cd: "); + if (tmp == NULL || tmp[0] == '\0') break; - } - - truecd = 0; if (tmp[0] == '~') { /* Expand ~ to HOME absolute path */ @@ -2671,30 +2617,23 @@ nochange: if (home) snprintf(newpath, PATH_MAX, "%s%s", home, tmp + 1); else { - free(input); printmsg(messages[STR_NOHOME_ID]); goto nochange; } } else if (tmp[0] == '-' && tmp[1] == '\0') { - if (lastdir[0] == '\0') { - free(input); + if (lastdir[0] == '\0') break; - } /* Switch to last visited dir */ xstrlcpy(newpath, lastdir, PATH_MAX); truecd = 1; } else if ((r = all_dots(tmp))) { - if (r == 1) { + if (r == 1) /* Always in the current dir */ - free(input); break; - } /* Show a message if already at / */ if (istopdir(path)) { - free(input); - /* Continue in navigate-as-you-type mode, if enabled */ if (cfg.filtermode) presel = FILTER; @@ -2716,7 +2655,6 @@ nochange: dir = xdirname(dir); if (access(dir, R_OK) == -1) { printwarn(); - free(input); goto nochange; } } @@ -2735,8 +2673,6 @@ nochange: } else mkpath(path, tmp, newpath, PATH_MAX); - free(input); - if (!xdiraccess(newpath)) goto nochange; diff --git a/packagecore.yaml b/packagecore.yaml index dec05a5..7ebf84a 100644 --- a/packagecore.yaml +++ b/packagecore.yaml @@ -14,17 +14,14 @@ packages: - pkg-config deps: - ncurses - - readline centos7.2: builddeps: - make - gcc - pkgconfig - ncurses-devel - - readline-devel deps: - ncurses - - readline commands: pre: - yum install epel-release @@ -34,10 +31,8 @@ packages: - gcc - pkgconfig - ncurses-devel - - readline-devel deps: - ncurses - - readline commands: pre: - yum install epel-release @@ -47,67 +42,53 @@ packages: - gcc - pkg-config - libncursesw5-dev - - libreadline-dev deps: - libncursesw5 - - readline-common fedora25: builddeps: - make - gcc - pkgconfig - ncurses-devel - - readline-devel deps: - ncurses - - readline fedora26: builddeps: - make - gcc - pkg-config - ncurses-devel - - readline-devel deps: - ncurses - - readline fedora27: builddeps: - make - gcc - pkg-config - ncurses-devel - - readline-devel deps: - ncurses - - readline # opensuse42.3: # builddeps: # - make # - gcc # - pkg-config # - ncurses-devel -# - readline-devel # deps: # - ncurses -# - readline ubuntu16.04: builddeps: - make - gcc - pkg-config - libncursesw5-dev - - libreadline6-dev deps: - libncursesw5 - - libreadline6 ubuntu18.04: builddeps: - make - gcc - pkg-config - libncursesw5-dev - - libreadline-dev deps: - libncursesw5 - - libreadline7 |