Compare commits

32 Commits
Author SHA1 Message Date
Gokcehan 933b49d095 cleanup 2020-04-13 18:24:15 +03:00
Gokcehan c5d05b7683 add 'on-cd' to the documentation
Related #291
2020-04-13 17:58:03 +03:00
ath3 9c1836c18b Add possibility to execute commands when directory changes (on_chdir) (#291)
* Add possibility to execute commands when cwd changes (on_chdir)

* Renamed function and special command on_chdir (onChdir, on-cd), support select command
2020-03-20 22:01:47 +03:00
Doron Behar 6693709f36 Use doronbehar's fork of termbox (#311) 2020-03-20 21:59:30 +03:00
Vladimir Bauer 17949fc25a case 1 is unnecessary because there is the same logic in default (#293) 2020-03-18 23:44:10 +03:00
Gokcehan 3c5abbbc5d Revert "Error clear (#192)"
This reverts commit 30d3078559.
2019-12-23 16:33:45 +03:00
Gokcehan e0747fa2f9 use rune indices for word matching
Related #193
2019-12-23 16:00:10 +03:00
Gokcehan b0064df32c convert string indices to rune slice indices
Related #193
2019-12-23 02:35:32 +03:00
Nicholas Christopoulos 74eab96637 [t]csh files added (lfcd,lf-complete) (#264)
* [t]csh files added (lfcd,lf-complete)

* rename lf-complete.csh to lf.csh

* rename lf-complete.csh to lf.csh; i forgot the comment-line

* convert ^O esc-code to ^O string
2019-12-19 22:11:23 +03:00
David Pedersen d63e7a2076 Don't rename when name is the same. Fix #253 (#266)
Currently, renaming a file without changing the name will prompt for
replacing and then delete the file. This will instead cancel the
renaming if the old and new names are the same.
2019-12-18 01:39:02 +03:00
Gokcehan d5f989f373 show progress for delete operation
Related #238
2019-12-02 19:50:13 +03:00
Juris Arturs Majors f76bf30f65 Asynchronous delete (#238)
* Asynchronous deletion, similar to moving

* Reversed some sloppy new lines from previous commit

* Move delete operations to delete.go

* Simplify to use RemoveAll before

* Send errors directly to ui.exprChan directly
2019-12-02 14:27:58 +03:00
Gokcehan 8327505398 handle closing double quote properly
Related #249
2019-10-26 03:05:07 +03:00
Gokcehan 74ef9fcd83 escape path separator on windows 2019-10-25 20:51:22 +03:00
Gokcehan 0482340d5e keep trailing backslash during reverse escape 2019-10-25 20:50:00 +03:00
Gokcehan 7a4d1cc275 escape special characters with backslash 2019-10-25 20:17:49 +03:00
Juris Arturs Majors cd396605da Add automatically generated zsh completion (#239)
* Add automatically generated zsh completion

* Rename to lf.zsh and add simple installation instructions
2019-10-07 22:48:17 +03:00
Gokcehan c43026d1e2 cleanup 2019-10-07 22:31:51 +03:00
arolle 7b89126e04 Correct abbreviation of the home directory (#241)
The path has to start with the home directory to be shortened to `~`.
Previously a user named `user` would see `/media/backup~/files` when
browsing `/media/backup/home/user/files`.
2019-10-07 22:30:52 +03:00
Gokcehan ff4c36565c mention setsid in the documentation
Related #148 and #233
2019-10-07 20:23:08 +03:00
Vladimir Bauer cfc9e355b3 reduce switch times a bit (#236) 2019-10-07 19:08:39 +03:00
Gokcehan bc33f3154a cleanup 2019-10-04 21:49:18 +03:00
Kennedy Mwenja 9991a40e87 Sort by file extensions (#230)
- preserve natural ordering of filenames if extensions are the same
  or are missing
- files without extensions rank higher on ascending sort and lower
  on descending sort
2019-10-04 21:44:52 +03:00
Gokcehan 41339a9e5a add times library to travis 2019-09-18 21:57:00 +03:00
Kennedy Mwenja 9515bd73d0 Sort By Access Time and Change Time (#226)
- Add access time and change time as sort by types. This is
  powered by github.com/djherbis/times.
- Fall back to modification time if access time and change time
  cannot be determined.
- Add `sa` and `sc` as default bindings for sort by access time and
  sort by change time respectively.
- Add access time and change time to info types allowing them to be
  displayed by the file list in the ui
2019-09-18 21:52:30 +03:00
Doron Behar d13cc79bc4 Add lf.desktop (#222) 2019-08-30 17:32:23 +03:00
Yong Jie bba32beb8a Fix bug where lfcd.cmd does not CD to different drive (#221) 2019-08-28 20:05:18 +03:00
Daniel Martí 50ac367626 fix ineffective breaks, remove unused parameters (#210)
While at it, simplify a few pieces of code.
2019-08-12 14:52:27 +03:00
Gokcehan 3b34b20cb8 change default icons for special directories
Related #207
2019-08-12 14:41:58 +03:00
Gokcehan 6982ffe4cf allow double backslash escape without quotes
Related #142
2019-08-05 22:28:55 +03:00
Gokcehan 488bf9f6b6 cleanup 2019-07-30 17:06:11 +03:00
David Pedersen 2ab866d474 Make prompt for delete command more descriptive (#206)
This will make the prompt shown when running the delete command more descriptive.
Before: `delete?[y/N]:`
Now when deleting one file: `delete /tmp/abc [y/N]?`
Now when deleting selection: `delete 3 items [y/N]?`
2019-07-23 22:33:43 +03:00
29 changed files with 600 additions and 281 deletions

No files matched your search

+2 -1
View File
@@ -1,6 +1,7 @@
language: go language: go
install: install:
- go get github.com/nsf/termbox-go - go get github.com/doronbehar/termbox-go
- go get gopkg.in/djherbis/times.v1
before_deploy: before_deploy:
- gen/xbuild.sh - gen/xbuild.sh
deploy: deploy:
+25 -7
View File
@@ -179,6 +179,11 @@ func (app *app) loop() {
continue continue
} }
if app.nav.deleteTotal > 0 {
app.ui.echoerr("quit: delete operation in progress")
continue
}
log.Print("bye!") log.Print("bye!")
if err := app.writeHistory(); err != nil { if err := app.writeHistory(); err != nil {
@@ -232,6 +237,21 @@ func (app *app) loop() {
app.nav.moveUpdate = 0 app.nav.moveUpdate = 0
} }
app.ui.draw(app.nav) app.ui.draw(app.nav)
case n := <-app.nav.deleteCountChan:
app.nav.deleteCount += n
if app.nav.deleteUpdate++; app.nav.deleteUpdate >= 1000 {
app.nav.deleteUpdate = 0
app.ui.draw(app.nav)
}
case n := <-app.nav.deleteTotalChan:
app.nav.deleteTotal += n
if n < 0 {
app.nav.deleteCount += n
}
if app.nav.deleteTotal == 0 {
app.nav.deleteUpdate = 0
}
app.ui.draw(app.nav)
case d := <-app.nav.dirChan: case d := <-app.nav.dirChan:
prev, ok := app.nav.dirCache[d.path] prev, ok := app.nav.dirCache[d.path]
if ok { if ok {
@@ -323,6 +343,7 @@ func (app *app) runShell(s string, args []string, prefix string) {
cmd := shellCommand(s, args) cmd := shellCommand(s, args)
var out io.Reader var out io.Reader
var err error
switch prefix { switch prefix {
case "$", "!": case "$", "!":
cmd.Stdin = os.Stdin cmd.Stdin = os.Stdin
@@ -332,6 +353,8 @@ func (app *app) runShell(s string, args []string, prefix string) {
app.ui.pause() app.ui.pause()
defer app.ui.resume() defer app.ui.resume()
defer app.nav.renew() defer app.nav.renew()
err = cmd.Run()
case "%": case "%":
stdin, err := cmd.StdinPipe() stdin, err := cmd.StdinPipe()
if err != nil { if err != nil {
@@ -344,13 +367,8 @@ func (app *app) runShell(s string, args []string, prefix string) {
} }
out = stdout out = stdout
cmd.Stderr = cmd.Stdout cmd.Stderr = cmd.Stdout
} fallthrough
case "&":
var err error
switch prefix {
case "$", "!":
err = cmd.Run()
case "%", "&":
err = cmd.Start() err = cmd.Start()
} }
+2 -2
View File
@@ -10,7 +10,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/nsf/termbox-go" "github.com/doronbehar/termbox-go"
) )
func run() { func run() {
@@ -52,7 +52,7 @@ func readExpr() <-chan expr {
c, err := net.Dial(gSocketProt, gSocketPath) c, err := net.Dial(gSocketProt, gSocketPath)
for err != nil { for err != nil {
log.Printf(fmt.Sprintf("connecting server: %s", err)) log.Printf("connecting server: %s", err)
time.Sleep(duration) time.Sleep(duration)
duration *= 2 duration *= 2
c, err = net.Dial(gSocketProt, gSocketPath) c, err = net.Dial(gSocketProt, gSocketPath)
+1 -1
View File
@@ -7,7 +7,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/nsf/termbox-go" "github.com/doronbehar/termbox-go"
) )
const gAnsiColorResetMask = termbox.AttrBold | termbox.AttrUnderline | termbox.AttrReverse const gAnsiColorResetMask = termbox.AttrBold | termbox.AttrUnderline | termbox.AttrReverse
+1 -1
View File
@@ -3,7 +3,7 @@ package main
import ( import (
"testing" "testing"
"github.com/nsf/termbox-go" "github.com/doronbehar/termbox-go"
) )
func TestApplyAnsiCodes(t *testing.T) { func TestApplyAnsiCodes(t *testing.T) {
+4 -4
View File
@@ -256,13 +256,13 @@ func matchFile(s string) (matches []string, longest string) {
name := f.Name() name := f.Name()
if isRoot(s) || filepath.Base(s) != s { if isRoot(s) || filepath.Base(s) != s {
name = filepath.Join(filepath.Dir(s), f.Name()) name = filepath.Join(filepath.Dir(unescape(s)), f.Name())
} }
name = escape(name) name = escape(name)
item := f.Name() item := f.Name()
if f.Mode().IsDir() { if f.Mode().IsDir() {
item += string(filepath.Separator) item += escape(string(filepath.Separator))
} }
matches = append(matches, item) matches = append(matches, item)
@@ -272,7 +272,7 @@ func matchFile(s string) (matches []string, longest string) {
if f.Mode().IsRegular() { if f.Mode().IsRegular() {
longest = name + " " longest = name + " "
} else { } else {
longest = name + string(filepath.Separator) longest = name + escape(string(filepath.Separator))
} }
} }
} }
@@ -382,7 +382,7 @@ func completeShell(acc []rune) (matches []string, longestAcc []rune) {
longestAcc = []rune(longest) longestAcc = []rune(longest)
default: default:
matches, longest = matchFile(f[len(f)-1]) matches, longest = matchFile(f[len(f)-1])
longestAcc = append(acc[:len(acc)-len(f[len(f)-1])], []rune(longest)...) longestAcc = append(acc[:len(acc)-len([]rune(f[len(f)-1]))], []rune(longest)...)
} }
return return
-1
View File
@@ -21,7 +21,6 @@ func init() {
"áạàảãăắặằẳẵâấậầẩẫéẹèẻẽêếệềểễiíịìỉĩoóọòỏõôốộồổỗơớợờởỡúụùủũưứựừửữyýỵỳỷỹđ", "áạàảãăắặằẳẵâấậầẩẫéẹèẻẽêếệềểễiíịìỉĩoóọòỏõôốộồổỗơớợờởỡúụùủũưứựừửữyýỵỳỷỹđ",
"aaaaaaaaaaaaaaaaaeeeeeeeeeeeiiiiiioooooooooooooooooouuuuuuuuuuuyyyyyyd", "aaaaaaaaaaaaaaaaaeeeeeeeeeeeiiiiiioooooooooooooooooouuuuuuuuuuuyyyyyyd",
) )
} }
func appendTransliterate(base, norm string) { func appendTransliterate(base, norm string) {
+52 -13
View File
@@ -56,19 +56,19 @@ The following commands are provided by lf with default keybindings:
The following commands are provided by lf without default keybindings: The following commands are provided by lf without default keybindings:
draw draw the ui draw draw the ui
load load modified files and directories load load modified files and directories
sync synchronize copied/cut files with server sync synchronize copied/cut files with server
echo print arguments to the message line echo print arguments to the message line
echomsg same as echo but logging echomsg same as echo but logging
echoerr same as echomsg but red color echoerr same as echomsg but red color
cd change working directory to the argument cd change working directory to the argument
select change current file selection to the argument select change current file selection to the argument
glob-select select files that match the given glob glob-select select files that match the given glob
glob-unselect unselect files that match the given glob glob-unselect unselect files that match the given glob
source read the configuration file in the argument source read the configuration file in the argument
push simulate key pushes given in the argument push simulate key pushes given in the argument
delete remove the current file or selected file(s) delete remove the current file or selected file(s)
The following command line commands are provided by lf with default The following command line commands are provided by lf with default
keybindings: keybindings:
@@ -174,6 +174,9 @@ The following additional keybindings are provided by default:
map sn :set sortby natural; set info map sn :set sortby natural; set info
map ss :set sortby size; set info size map ss :set sortby size; set info size
map st :set sortby time; set info time map st :set sortby time; set info time
map sa :set sortby atime; set info atime
map sc :set sortby ctime; set info ctime
map se :set sortby ext; set info
map gh cd ~ map gh cd ~
The following keybindings to applications are provided by default: The following keybindings to applications are provided by default:
@@ -635,6 +638,9 @@ You may want to use either file extensions or mime types from 'file' command:
esac esac
}} }}
You may want to use 'setsid' before your opener command to have persistent
processes that continue to run after lf quits.
Following command is provided by default: Following command is provided by default:
cmd open &$OPENER $f cmd open &$OPENER $f
@@ -687,6 +693,39 @@ pipe with a SIGPIPE when enough lines are read. When everything else fails, you
can make use of the height argument to only feed the first portion of the file can make use of the height argument to only feed the first portion of the file
to a program for preview. to a program for preview.
Changing Directory
lf changes the working directory of the process to the current directory so
that shell commands always work in the displayed directory. After quitting, it
returns to the original directory where it is first launched like all shell
programs. If you want to stay in the current directory after quitting, you can
use one of the example wrapper shell scripts provided in the repository.
There is a special command 'on-cd' that runs a shell command when it is defined
and the directory is changed. You can define it just as you would define any
other command:
cmd on-cd &{{
# display git repository status in your prompt
source /usr/share/git/completion/git-prompt.sh
GIT_PS1_SHOWDIRTYSTATE=auto
GIT_PS1_SHOWSTASHSTATE=auto
GIT_PS1_SHOWUNTRACKEDFILES=auto
GIT_PS1_SHOWUPSTREAM=auto
git=$(__git_ps1 " (%s)") || true
fmt="\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f$git\033[0m"
lf -remote "send $id set promptfmt \"$fmt\""
}}
This command runs whenever you change directory but not on startup. You can add
an extra call to make it run on startup as well:
cmd on-cd &{{ # ... }}
on-cd
Note that all shell commands are possible but `%` and `&` are usually more
appropriate as `$` and `!` causes flickers and pauses respectively.
Colorschemes Colorschemes
lf tries to automatically adapt its colors to the environment. On startup, lf tries to automatically adapt its colors to the environment. On startup,
+58 -17
View File
@@ -59,19 +59,19 @@ The following commands are provided by lf with default keybindings:
The following commands are provided by lf without default keybindings: The following commands are provided by lf without default keybindings:
draw draw the ui draw draw the ui
load load modified files and directories load load modified files and directories
sync synchronize copied/cut files with server sync synchronize copied/cut files with server
echo print arguments to the message line echo print arguments to the message line
echomsg same as echo but logging echomsg same as echo but logging
echoerr same as echomsg but red color echoerr same as echomsg but red color
cd change working directory to the argument cd change working directory to the argument
select change current file selection to the argument select change current file selection to the argument
glob-select select files that match the given glob glob-select select files that match the given glob
glob-unselect unselect files that match the given glob glob-unselect unselect files that match the given glob
source read the configuration file in the argument source read the configuration file in the argument
push simulate key pushes given in the argument push simulate key pushes given in the argument
delete remove the current file or selected file(s) delete remove the current file or selected file(s)
The following command line commands are provided by lf with default The following command line commands are provided by lf with default
keybindings: keybindings:
@@ -128,15 +128,15 @@ The following options can be used to customize the behavior of lf:
tabstop integer (default 8) tabstop integer (default 8)
errorfmt string (default "\033[7;31;47m%s\033[0m") errorfmt string (default "\033[7;31;47m%s\033[0m")
filesep string (default "\n") filesep string (default "\n")
ifs string (default ”) (not exported if empty) ifs string (default '') (not exported if empty)
previewer string (default ”) (not filtered if empty) previewer string (default '') (not filtered if empty)
promptfmt string (default "\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f\033[0m") promptfmt string (default "\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f\033[0m")
shell string (default 'sh') shell string (default 'sh')
sortby string (default 'natural') sortby string (default 'natural')
timefmt string (default 'Mon Jan _2 15:04:05 2006') timefmt string (default 'Mon Jan _2 15:04:05 2006')
ratios string (default '1:2:3') ratios string (default '1:2:3')
info string (default ”) info string (default '')
shellopts string (default ”) shellopts string (default '')
The following variables are exported for shell commands: The following variables are exported for shell commands:
@@ -177,6 +177,9 @@ The following additional keybindings are provided by default:
map sn :set sortby natural; set info map sn :set sortby natural; set info
map ss :set sortby size; set info size map ss :set sortby size; set info size
map st :set sortby time; set info time map st :set sortby time; set info time
map sa :set sortby atime; set info atime
map sc :set sortby ctime; set info ctime
map se :set sortby ext; set info
map gh cd ~ map gh cd ~
The following keybindings to applications are provided by default: The following keybindings to applications are provided by default:
@@ -663,6 +666,9 @@ command:
esac esac
}} }}
You may want to use 'setsid' before your opener command to have persistent
processes that continue to run after lf quits.
Following command is provided by default: Following command is provided by default:
cmd open &$OPENER $f cmd open &$OPENER $f
@@ -718,6 +724,41 @@ everything else fails, you can make use of the height argument to only feed
the first portion of the file to a program for preview. the first portion of the file to a program for preview.
Changing Directory
lf changes the working directory of the process to the current directory so
that shell commands always work in the displayed directory. After quitting,
it returns to the original directory where it is first launched like all
shell programs. If you want to stay in the current directory after quitting,
you can use one of the example wrapper shell scripts provided in the
repository.
There is a special command 'on-cd' that runs a shell command when it is
defined and the directory is changed. You can define it just as you would
define any other command:
cmd on-cd &{{
# display git repository status in your prompt
source /usr/share/git/completion/git-prompt.sh
GIT_PS1_SHOWDIRTYSTATE=auto
GIT_PS1_SHOWSTASHSTATE=auto
GIT_PS1_SHOWUNTRACKEDFILES=auto
GIT_PS1_SHOWUPSTREAM=auto
git=$(__git_ps1 " (%s)") || true
fmt="\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f$git\033[0m"
lf -remote "send $id set promptfmt \"$fmt\""
}}
This command runs whenever you change directory but not on startup. You can
add an extra call to make it run on startup as well:
cmd on-cd &{{ # ... }}
on-cd
Note that all shell commands are possible but '%' and '&' are usually more
appropriate as '$' and '!' causes flickers and pauses respectively.
Colorschemes Colorschemes
lf tries to automatically adapt its colors to the environment. On startup, lf tries to automatically adapt its colors to the environment. On startup,
+12
View File
@@ -0,0 +1,12 @@
#
# For using these completions you must load it from .tcshrc
#
# source ~/.config/lf/lf.csh
#
set lf_args = "-command -cpuprofile -doc --help -last-dir-path -memprofile -remote -selection-path -server -version --version"
uncomplete lf
uncomplete lfcd
complete lf "C/-*/(${lf_args})/"
complete lfcd "C/-*/(${lf_args})/"
+29
View File
@@ -0,0 +1,29 @@
#compdef lf
# For using these completions you must:
# - rename this file to _lf
# - add the containing folder to $fpath in .zshrc, like this:
# '''
# fpath=(/path/to/folder/containing_lf $fpath)
# autoload -U compinit
# compinit
# '''
#
# zsh completions for 'lf'
# automatically generated with http://github.com/RobSis/zsh-completion-generator
local arguments
arguments=(
'-command[command to execute on client initialization]'
'-cpuprofile[path to the file to write the CPU profile]'
'-doc[show documentation]'
'-last-dir-path[path to the file to write the last dir on exit (to use for cd)]'
'-memprofile[path to the file to write the memory profile]'
'-remote[send remote command to server]'
'-selection-path[path to the file to write selected files on open (to use as open file dialog)]'
'-server[start server (automatic)]'
'-version[show version]'
'*:filename:_files'
)
_arguments -s $arguments
+6 -6
View File
@@ -5,11 +5,11 @@ rem You need to put this file to a folder in %PATH% variable.
:tmploop :tmploop
set tmpfile="%tmp%\lf.%random%.tmp" set tmpfile="%tmp%\lf.%random%.tmp"
if exist "%tmpfile%" goto:tmploop if exist %tmpfile% goto:tmploop
lf -last-dir-path="%tmpfile%" %* lf -last-dir-path=%tmpfile% %*
if not exist "%tmpfile%" exit if not exist %tmpfile% exit
set /p dir=<"%tmpfile%" set /p dir=<%tmpfile%
del /f "%tmpfile%" del /f %tmpfile%
if not exist "%dir%" exit if not exist "%dir%" exit
if "%dir%" == "%cd%" exit if "%dir%" == "%cd%" exit
cd "%dir%" cd /d "%dir%"
+13
View File
@@ -0,0 +1,13 @@
# Change working dir in shell to last dir in lf on exit.
#
# You need to either copy the content of this file to your shell rc file
# (e.g. ~/.tcshrc) or source this file directly:
#
# setenv LF_HOME "${HOME}/.config/lf"
# [ -e "${LF_HOME}/lfcd.csh" ] && source "${LF_HOME}/lfcd.csh"
#
# You may also like to assign a key to this command:
#
# bindkey -c "^O" lfcd
#
alias lfcd 'set _=`mktemp` && lf -last-dir-path=$_ "\!*" && set _=`cat $_ && rm -f $_` && [ -d "$_" ] && cd "$_"'
+1 -1
View File
@@ -38,7 +38,7 @@ map O $mimeopen --ask $f
cmd open ${{ cmd open ${{
case $(file --mime-type $f -b) in case $(file --mime-type $f -b) in
text/*) $EDITOR $fx;; text/*) $EDITOR $fx;;
*) for f in $fx; do $OPENER $f > /dev/null 2> /dev/null & done;; *) for f in $fx; do setsid $OPENER $f > /dev/null 2> /dev/null & done;;
esac esac
}} }}
+73 -47
View File
@@ -238,10 +238,6 @@ func (e *setExpr) eval(app *app, args []string) {
case "shell": case "shell":
gOpts.shell = e.val gOpts.shell = e.val
case "sortby": case "sortby":
if e.val != "natural" && e.val != "name" && e.val != "size" && e.val != "time" {
app.ui.echoerr("sortby: value should either be 'natural', 'name', 'size' or 'time'")
return
}
switch e.val { switch e.val {
case "natural": case "natural":
gOpts.sortType.method = naturalSort gOpts.sortType.method = naturalSort
@@ -251,6 +247,15 @@ func (e *setExpr) eval(app *app, args []string) {
gOpts.sortType.method = sizeSort gOpts.sortType.method = sizeSort
case "time": case "time":
gOpts.sortType.method = timeSort gOpts.sortType.method = timeSort
case "ctime":
gOpts.sortType.method = ctimeSort
case "atime":
gOpts.sortType.method = atimeSort
case "ext":
gOpts.sortType.method = extSort
default:
app.ui.echoerr("sortby: value should either be 'natural', 'name', 'size', 'time', 'atime', 'ctime' or 'ext'")
return
} }
app.nav.sort() app.nav.sort()
app.ui.sort() app.ui.sort()
@@ -281,8 +286,10 @@ func (e *setExpr) eval(app *app, args []string) {
case "info": case "info":
toks := strings.Split(e.val, ":") toks := strings.Split(e.val, ":")
for _, s := range toks { for _, s := range toks {
if s != "" && s != "size" && s != "time" { switch s {
app.ui.echoerr("info: should consist of 'size' or 'time' separated with colon") case "", "size", "time", "atime", "ctime":
default:
app.ui.echoerr("info: should consist of 'size', 'time', 'atime' or 'ctime' separated with colon")
return return
} }
} }
@@ -323,6 +330,12 @@ func (e *cmdExpr) eval(app *app, args []string) {
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
func onChdir(app *app) {
if cmd, ok := gOpts.cmds["on-cd"]; ok {
cmd.eval(app, nil)
}
}
func splitKeys(s string) (keys []string) { func splitKeys(s string) (keys []string) {
for i := 0; i < len(s); { for i := 0; i < len(s); {
r, w := utf8.DecodeRuneInString(s[i:]) r, w := utf8.DecodeRuneInString(s[i:])
@@ -459,11 +472,11 @@ func insert(app *app, arg string) {
} }
normal(app) normal(app)
case app.ui.cmdPrefix == "delete?[y/N]: ": case strings.HasPrefix(app.ui.cmdPrefix, "delete"):
normal(app) normal(app)
if arg == "y" { if arg == "y" {
if err := app.nav.del(); err != nil { if err := app.nav.del(app.ui); err != nil {
app.ui.echoerrf("delete: %s", err) app.ui.echoerrf("delete: %s", err)
return return
} }
@@ -480,7 +493,7 @@ func insert(app *app, arg string) {
normal(app) normal(app)
if arg == "y" { if arg == "y" {
if err := app.nav.rename(app.ui); err != nil { if err := app.nav.rename(); err != nil {
app.ui.echoerrf("rename: %s", err) app.ui.echoerrf("rename: %s", err)
return return
} }
@@ -528,6 +541,7 @@ func insert(app *app, arg string) {
if wd != path { if wd != path {
app.nav.marks["'"] = wd app.nav.marks["'"] = wd
onChdir(app)
} }
case app.ui.cmdPrefix == "mark-remove: ": case app.ui.cmdPrefix == "mark-remove: ":
normal(app) normal(app)
@@ -545,7 +559,6 @@ func insert(app *app, arg string) {
default: default:
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...) app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
} }
app.ui.loadFileInfo(app.nav)
} }
func (e *callExpr) eval(app *app, args []string) { func (e *callExpr) eval(app *app, args []string) {
@@ -604,6 +617,7 @@ func (e *callExpr) eval(app *app, args []string) {
} }
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
onChdir(app)
case "open": case "open":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" { if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app) normal(app)
@@ -622,6 +636,7 @@ func (e *callExpr) eval(app *app, args []string) {
} }
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
onChdir(app)
return return
} }
@@ -715,11 +730,17 @@ func (e *callExpr) eval(app *app, args []string) {
return return
} }
} else { } else {
if _, err := app.nav.currFileOrSelections(); err != nil { fileOrSelections, err := app.nav.currFileOrSelections()
if err != nil {
app.ui.echoerrf("delete: %s", err) app.ui.echoerrf("delete: %s", err)
return return
} }
app.ui.cmdPrefix = "delete?[y/N]: "
if selections := len(fileOrSelections); selections == 1 {
app.ui.cmdPrefix = "delete " + fileOrSelections[0] + " [y/N]? "
} else {
app.ui.cmdPrefix = "delete " + strconv.Itoa(selections) + " items [y/N]? "
}
} }
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
@@ -891,6 +912,7 @@ func (e *callExpr) eval(app *app, args []string) {
if wd != path { if wd != path {
app.nav.marks["'"] = wd app.nav.marks["'"] = wd
onChdir(app)
} }
case "select": case "select":
if len(e.args) != 1 { if len(e.args) != 1 {
@@ -920,6 +942,7 @@ func (e *callExpr) eval(app *app, args []string) {
if wd != path { if wd != path {
app.nav.marks["'"] = wd app.nav.marks["'"] = wd
onChdir(app)
} }
case "glob-select": case "glob-select":
if len(e.args) != 1 { if len(e.args) != 1 {
@@ -1077,6 +1100,9 @@ func (e *callExpr) eval(app *app, args []string) {
} }
oldPathTo := filepath.Join(wd, curr.Name()) oldPathTo := filepath.Join(wd, curr.Name())
newPathTo := filepath.Join(wd, s) newPathTo := filepath.Join(wd, s)
if oldPathTo == newPathTo {
return
}
app.nav.renameCache = []string{oldPathTo, newPathTo} app.nav.renameCache = []string{oldPathTo, newPathTo}
if dir, _ := filepath.Split(s); dir != "" { if dir, _ := filepath.Split(s); dir != "" {
@@ -1091,7 +1117,7 @@ func (e *callExpr) eval(app *app, args []string) {
return return
} }
if err := app.nav.rename(app.ui); err != nil { if err := app.nav.rename(); err != nil {
app.ui.echoerrf("rename: %s", err) app.ui.echoerrf("rename: %s", err)
return return
} }
@@ -1188,8 +1214,8 @@ func (e *callExpr) eval(app *app, args []string) {
update(app) update(app)
case "cmd-delete-unix-word": case "cmd-delete-unix-word":
ind := strings.LastIndex(strings.TrimRight(string(app.ui.cmdAccLeft), " "), " ") + 1 ind := strings.LastIndex(strings.TrimRight(string(app.ui.cmdAccLeft), " "), " ") + 1
app.ui.cmdYankBuf = app.ui.cmdAccLeft[ind:] app.ui.cmdYankBuf = []rune(string(app.ui.cmdAccLeft)[ind:])
app.ui.cmdAccLeft = app.ui.cmdAccLeft[:ind] app.ui.cmdAccLeft = []rune(string(app.ui.cmdAccLeft)[:ind])
update(app) update(app)
case "cmd-yank": case "cmd-yank":
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdYankBuf...) app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdYankBuf...)
@@ -1209,26 +1235,26 @@ func (e *callExpr) eval(app *app, args []string) {
if len(app.ui.cmdAccRight) == 0 { if len(app.ui.cmdAccRight) == 0 {
return return
} }
loc := reWordEnd.FindStringIndex(string(app.ui.cmdAccRight)) loc := reWordEnd.FindStringSubmatchIndex(string(app.ui.cmdAccRight))
if loc == nil { if loc == nil {
return return
} }
ind := loc[0] + 1 ind := loc[3]
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdAccRight[:ind]...) app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(string(app.ui.cmdAccRight)[:ind])...)
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:] app.ui.cmdAccRight = []rune(string(app.ui.cmdAccRight)[ind:])
case "cmd-word-back": case "cmd-word-back":
if len(app.ui.cmdAccLeft) == 0 { if len(app.ui.cmdAccLeft) == 0 {
return return
} }
locs := reWordBeg.FindAllStringIndex(string(app.ui.cmdAccLeft), -1) locs := reWordBeg.FindAllStringSubmatchIndex(string(app.ui.cmdAccLeft), -1)
if locs == nil { if locs == nil {
return return
} }
ind := locs[len(locs)-1][1] - 1 ind := locs[len(locs)-1][3]
old := app.ui.cmdAccRight old := app.ui.cmdAccRight
app.ui.cmdAccRight = append([]rune{}, app.ui.cmdAccLeft[ind:]...) app.ui.cmdAccRight = append([]rune{}, []rune(string(app.ui.cmdAccLeft)[ind:])...)
app.ui.cmdAccRight = append(app.ui.cmdAccRight, old...) app.ui.cmdAccRight = append(app.ui.cmdAccRight, old...)
app.ui.cmdAccLeft = app.ui.cmdAccLeft[:ind] app.ui.cmdAccLeft = []rune(string(app.ui.cmdAccLeft)[:ind])
case "cmd-capitalize-word": case "cmd-capitalize-word":
if len(app.ui.cmdAccRight) == 0 { if len(app.ui.cmdAccRight) == 0 {
return return
@@ -1240,48 +1266,48 @@ func (e *callExpr) eval(app *app, args []string) {
return return
} }
app.ui.cmdAccRight[ind] = unicode.ToUpper(app.ui.cmdAccRight[ind]) app.ui.cmdAccRight[ind] = unicode.ToUpper(app.ui.cmdAccRight[ind])
loc := reWordEnd.FindStringIndex(string(app.ui.cmdAccRight)) loc := reWordEnd.FindStringSubmatchIndex(string(app.ui.cmdAccRight))
if loc == nil { if loc == nil {
return return
} }
ind = loc[0] + 1 ind = loc[3]
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdAccRight[:ind]...) app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(string(app.ui.cmdAccRight)[:ind])...)
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:] app.ui.cmdAccRight = []rune(string(app.ui.cmdAccRight)[ind:])
update(app) update(app)
case "cmd-delete-word": case "cmd-delete-word":
if len(app.ui.cmdAccRight) == 0 { if len(app.ui.cmdAccRight) == 0 {
return return
} }
loc := reWordEnd.FindStringIndex(string(app.ui.cmdAccRight)) loc := reWordEnd.FindStringSubmatchIndex(string(app.ui.cmdAccRight))
if loc == nil { if loc == nil {
return return
} }
ind := loc[0] + 1 ind := loc[3]
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:] app.ui.cmdAccRight = []rune(string(app.ui.cmdAccRight)[ind:])
update(app) update(app)
case "cmd-uppercase-word": case "cmd-uppercase-word":
if len(app.ui.cmdAccRight) == 0 { if len(app.ui.cmdAccRight) == 0 {
return return
} }
loc := reWordEnd.FindStringIndex(string(app.ui.cmdAccRight)) loc := reWordEnd.FindStringSubmatchIndex(string(app.ui.cmdAccRight))
if loc == nil { if loc == nil {
return return
} }
ind := loc[0] + 1 ind := loc[3]
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(strings.ToUpper(string(app.ui.cmdAccRight[:ind])))...) app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(strings.ToUpper(string(app.ui.cmdAccRight)[:ind]))...)
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:] app.ui.cmdAccRight = []rune(string(app.ui.cmdAccRight)[ind:])
update(app) update(app)
case "cmd-lowercase-word": case "cmd-lowercase-word":
if len(app.ui.cmdAccRight) == 0 { if len(app.ui.cmdAccRight) == 0 {
return return
} }
loc := reWordEnd.FindStringIndex(string(app.ui.cmdAccRight)) loc := reWordEnd.FindStringSubmatchIndex(string(app.ui.cmdAccRight))
if loc == nil { if loc == nil {
return return
} }
ind := loc[0] + 1 ind := loc[3]
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(strings.ToLower(string(app.ui.cmdAccRight[:ind])))...) app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(strings.ToLower(string(app.ui.cmdAccRight)[:ind]))...)
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:] app.ui.cmdAccRight = []rune(string(app.ui.cmdAccRight)[ind:])
update(app) update(app)
case "cmd-transpose-word": case "cmd-transpose-word":
if len(app.ui.cmdAccLeft) == 0 { if len(app.ui.cmdAccLeft) == 0 {
@@ -1294,11 +1320,11 @@ func (e *callExpr) eval(app *app, args []string) {
} }
if len(app.ui.cmdAccRight) > 0 { if len(app.ui.cmdAccRight) > 0 {
loc := reWordEnd.FindStringIndex(string(app.ui.cmdAccRight)) loc := reWordEnd.FindStringSubmatchIndex(string(app.ui.cmdAccRight))
if loc != nil { if loc != nil {
ind := loc[0] + 1 ind := loc[3]
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdAccRight[:ind]...) app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(string(app.ui.cmdAccRight)[:ind])...)
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:] app.ui.cmdAccRight = []rune(string(app.ui.cmdAccRight)[ind:])
} }
} }
@@ -1309,11 +1335,11 @@ func (e *callExpr) eval(app *app, args []string) {
var acc []rune var acc []rune
acc = append(acc, app.ui.cmdAccLeft[:beg1]...) acc = append(acc, []rune(string(app.ui.cmdAccLeft)[:beg1])...)
acc = append(acc, app.ui.cmdAccLeft[beg2:end2]...) acc = append(acc, []rune(string(app.ui.cmdAccLeft)[beg2:end2])...)
acc = append(acc, app.ui.cmdAccLeft[end1:beg2]...) acc = append(acc, []rune(string(app.ui.cmdAccLeft)[end1:beg2])...)
acc = append(acc, app.ui.cmdAccLeft[beg1:end1]...) acc = append(acc, []rune(string(app.ui.cmdAccLeft)[beg1:end1])...)
acc = append(acc, app.ui.cmdAccLeft[end2:]...) acc = append(acc, []rune(string(app.ui.cmdAccLeft)[end2:])...)
app.ui.cmdAccLeft = acc app.ui.cmdAccLeft = acc
update(app) update(app)
+41 -15
View File
@@ -67,8 +67,8 @@ var gEvalTests = []struct {
{ {
`echo "hello\zworld"`, `echo "hello\zworld"`,
[]string{"echo", "helloworld", "\n"}, []string{"echo", `hello\zworld`, "\n"},
[]expr{&callExpr{"echo", []string{"helloworld"}, 1}}, []expr{&callExpr{"echo", []string{`hello\zworld`}, 1}},
}, },
{ {
@@ -90,7 +90,7 @@ var gEvalTests = []struct {
}, },
{ {
`echo hello\ world`, "echo hello\\\tworld",
[]string{"echo", "hello\tworld", "\n"}, []string{"echo", "hello\tworld", "\n"},
[]expr{&callExpr{"echo", []string{"hello\tworld"}, 1}}, []expr{&callExpr{"echo", []string{"hello\tworld"}, 1}},
}, },
@@ -101,10 +101,16 @@ var gEvalTests = []struct {
[]expr{&callExpr{"echo", []string{"hello\nworld"}, 1}}, []expr{&callExpr{"echo", []string{"hello\nworld"}, 1}},
}, },
{
`echo hello\\world`,
[]string{"echo", `hello\world`, "\n"},
[]expr{&callExpr{"echo", []string{`hello\world`}, 1}},
},
{ {
`echo hello\zworld`, `echo hello\zworld`,
[]string{"echo", "helloworld", "\n"}, []string{"echo", "hellozworld", "\n"},
[]expr{&callExpr{"echo", []string{"helloworld"}, 1}}, []expr{&callExpr{"echo", []string{"hellozworld"}, 1}},
}, },
{ {
@@ -125,6 +131,18 @@ var gEvalTests = []struct {
[]expr{&setExpr{"hidden", ""}, &setExpr{"preview", ""}}, []expr{&setExpr{"hidden", ""}, &setExpr{"preview", ""}},
}, },
{
`set ifs ""`,
[]string{"set", "ifs", "", "\n"},
[]expr{&setExpr{"ifs", ""}},
},
{
`set ifs "\n"`,
[]string{"set", "ifs", "\n", "\n"},
[]expr{&setExpr{"ifs", "\n"}},
},
{ {
"set ratios 1:2:3", "set ratios 1:2:3",
[]string{"set", "ratios", "1:2:3", "\n"}, []string{"set", "ratios", "1:2:3", "\n"},
@@ -292,13 +310,17 @@ var gEvalTests = []struct {
cd ~ cd ~
set hidden set hidden
}}`, }}`,
[]string{"cmd", "gohome", ":", "{{", []string{
"cmd", "gohome", ":", "{{",
"cd", "~", "\n", "cd", "~", "\n",
"set", "hidden", "\n", "set", "hidden", "\n",
"}}", "\n"}, "}}", "\n",
[]expr{&cmdExpr{"gohome", &listExpr{[]expr{ },
&callExpr{"cd", []string{"~"}, 1}, []expr{&cmdExpr{
&setExpr{"hidden", ""}}}, "gohome", &listExpr{[]expr{
&callExpr{"cd", []string{"~"}, 1},
&setExpr{"hidden", ""},
}},
}}, }},
}, },
@@ -307,13 +329,17 @@ var gEvalTests = []struct {
cd ~ cd ~
set hidden set hidden
}}`, }}`,
[]string{"map", "gh", ":", "{{", []string{
"map", "gh", ":", "{{",
"cd", "~", "\n", "cd", "~", "\n",
"set", "hidden", "\n", "set", "hidden", "\n",
"}}", "\n"}, "}}", "\n",
[]expr{&mapExpr{"gh", &listExpr{[]expr{ },
&callExpr{"cd", []string{"~"}, 1}, []expr{&mapExpr{
&setExpr{"hidden", ""}}}, "gh", &listExpr{[]expr{
&callExpr{"cd", []string{"~"}, 1},
&setExpr{"hidden", ""},
}},
}}, }},
}, },
+2 -1
View File
@@ -3,6 +3,7 @@ module github.com/gokcehan/lf
go 1.12 go 1.12
require ( require (
github.com/doronbehar/termbox-go v0.0.0-20191006141301-8c9470559e05
github.com/mattn/go-runewidth v0.0.4 github.com/mattn/go-runewidth v0.0.4
github.com/nsf/termbox-go v0.0.0-20190325093121-288510b9734e gopkg.in/djherbis/times.v1 v1.2.0
) )
+8 -6
View File
@@ -1,8 +1,10 @@
github.com/mattn/go-runewidth v0.0.3 h1:a+kO+98RDGEfo6asOGMmpodZq4FNtnGP54yps8BzLR4= github.com/doronbehar/termbox-go v0.0.0-20190817171036-93860e161317 h1:mdOm+1RdYwVwC4Wjb53M5L96fRwWJ8gI7YXwwiCsHTk=
github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/doronbehar/termbox-go v0.0.0-20190817171036-93860e161317/go.mod h1:cHYbFQiZNC8LPG6clYoLMKAl0xx7KR75RPsHtG/f1Hk=
github.com/doronbehar/termbox-go v0.0.0-20191006140624-aa2cdd26fb8c h1:qvLYQAhDCaMq+XiQ+t4YLaTJtUyHC1r20odd6ryKYIk=
github.com/doronbehar/termbox-go v0.0.0-20191006140624-aa2cdd26fb8c/go.mod h1:cHYbFQiZNC8LPG6clYoLMKAl0xx7KR75RPsHtG/f1Hk=
github.com/doronbehar/termbox-go v0.0.0-20191006141301-8c9470559e05 h1:pmXx7j8+mmkFJB2+qoB1C/Mz8SWvMlHTxSWOptJrr7E=
github.com/doronbehar/termbox-go v0.0.0-20191006141301-8c9470559e05/go.mod h1:cHYbFQiZNC8LPG6clYoLMKAl0xx7KR75RPsHtG/f1Hk=
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y= github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/nsf/termbox-go v0.0.0-20180613055208-5c94acc5e6eb h1:YahEjAGkJtCrkqgVHhX6n8ZX+CZ3hDRL9fjLYugLfSs= gopkg.in/djherbis/times.v1 v1.2.0 h1:UCvDKl1L/fmBygl2Y7hubXCnY7t4Yj46ZrBFNUipFbM=
github.com/nsf/termbox-go v0.0.0-20180613055208-5c94acc5e6eb/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ= gopkg.in/djherbis/times.v1 v1.2.0/go.mod h1:AQlg6unIsrsCEdQYhTzERy542dz6SFdQFZFv6mUY0P8=
github.com/nsf/termbox-go v0.0.0-20190325093121-288510b9734e h1:Vbib8wJAaMEF9jusI/kMSYMr/LtRzM7+F9MJgt/nH8k=
github.com/nsf/termbox-go v0.0.0-20190325093121-288510b9734e/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ=
+3
View File
@@ -15,6 +15,9 @@ func parseIcons() iconMap {
} }
defaultIcons := []string{ defaultIcons := []string{
"tw=🗀",
"st=🗀",
"ow=🗀",
"di=🗀", "di=🗀",
"fi=🗎", "fi=🗎",
} }
+49 -17
View File
@@ -68,19 +68,19 @@ The following commands are provided by lf with default keybindings:
The following commands are provided by lf without default keybindings: The following commands are provided by lf without default keybindings:
.PP .PP
.EX .EX
draw draw the ui draw draw the ui
load load modified files and directories load load modified files and directories
sync synchronize copied/cut files with server sync synchronize copied/cut files with server
echo print arguments to the message line echo print arguments to the message line
echomsg same as echo but logging echomsg same as echo but logging
echoerr same as echomsg but red color echoerr same as echomsg but red color
cd change working directory to the argument cd change working directory to the argument
select change current file selection to the argument select change current file selection to the argument
glob-select select files that match the given glob glob-select select files that match the given glob
glob-unselect unselect files that match the given glob glob-unselect unselect files that match the given glob
source read the configuration file in the argument source read the configuration file in the argument
push simulate key pushes given in the argument push simulate key pushes given in the argument
delete remove the current file or selected file(s) delete remove the current file or selected file(s)
.EE .EE
.PP .PP
The following command line commands are provided by lf with default keybindings: The following command line commands are provided by lf with default keybindings:
@@ -140,15 +140,15 @@ The following options can be used to customize the behavior of lf:
tabstop integer (default 8) tabstop integer (default 8)
errorfmt string (default "\e033[7;31;47m%s\e033[0m") errorfmt string (default "\e033[7;31;47m%s\e033[0m")
filesep string (default "\en") filesep string (default "\en")
ifs string (default ”) (not exported if empty) ifs string (default '') (not exported if empty)
previewer string (default ”) (not filtered if empty) previewer string (default '') (not filtered if empty)
promptfmt string (default "\e033[32;1m%u@%h\e033[0m:\e033[34;1m%w/\e033[0m\e033[1m%f\e033[0m") promptfmt string (default "\e033[32;1m%u@%h\e033[0m:\e033[34;1m%w/\e033[0m\e033[1m%f\e033[0m")
shell string (default 'sh') shell string (default 'sh')
sortby string (default 'natural') sortby string (default 'natural')
timefmt string (default 'Mon Jan _2 15:04:05 2006') timefmt string (default 'Mon Jan _2 15:04:05 2006')
ratios string (default '1:2:3') ratios string (default '1:2:3')
info string (default ”) info string (default '')
shellopts string (default ”) shellopts string (default '')
.EE .EE
.PP .PP
The following variables are exported for shell commands: The following variables are exported for shell commands:
@@ -197,6 +197,9 @@ The following additional keybindings are provided by default:
map sn :set sortby natural; set info map sn :set sortby natural; set info
map ss :set sortby size; set info size map ss :set sortby size; set info size
map st :set sortby time; set info time map st :set sortby time; set info time
map sa :set sortby atime; set info atime
map sc :set sortby ctime; set info ctime
map se :set sortby ext; set info
map gh cd ~ map gh cd ~
.EE .EE
.PP .PP
@@ -598,6 +601,8 @@ You may want to use either file extensions or mime types from 'file' command:
}} }}
.EE .EE
.PP .PP
You may want to use 'setsid' before your opener command to have persistent processes that continue to run after lf quits.
.PP
Following command is provided by default: Following command is provided by default:
.PP .PP
.EX .EX
@@ -633,6 +638,33 @@ Since this script is called for each file selection change it needs to be as eff
.EE .EE
.PP .PP
Another important consideration for efficiency is the use of programs with short startup times for preview. For this reason, 'highlight' is recommended over 'pygmentize' for syntax highlighting. Besides, it is also important that the application is processing the file on the fly rather than first reading it to the memory and then do the processing afterwards. This is especially relevant for big files. lf automatically closes the previewer script output pipe with a SIGPIPE when enough lines are read. When everything else fails, you can make use of the height argument to only feed the first portion of the file to a program for preview. Another important consideration for efficiency is the use of programs with short startup times for preview. For this reason, 'highlight' is recommended over 'pygmentize' for syntax highlighting. Besides, it is also important that the application is processing the file on the fly rather than first reading it to the memory and then do the processing afterwards. This is especially relevant for big files. lf automatically closes the previewer script output pipe with a SIGPIPE when enough lines are read. When everything else fails, you can make use of the height argument to only feed the first portion of the file to a program for preview.
.SH CHANGING DIRECTORY
lf changes the working directory of the process to the current directory so that shell commands always work in the displayed directory. After quitting, it returns to the original directory where it is first launched like all shell programs. If you want to stay in the current directory after quitting, you can use one of the example wrapper shell scripts provided in the repository.
.PP
There is a special command 'on-cd' that runs a shell command when it is defined and the directory is changed. You can define it just as you would define any other command:
.PP
.EX
cmd on-cd &{{
# display git repository status in your prompt
source /usr/share/git/completion/git-prompt.sh
GIT_PS1_SHOWDIRTYSTATE=auto
GIT_PS1_SHOWSTASHSTATE=auto
GIT_PS1_SHOWUNTRACKEDFILES=auto
GIT_PS1_SHOWUPSTREAM=auto
git=$(__git_ps1 " (%s)") || true
fmt="\e033[32;1m%u@%h\e033[0m:\e033[34;1m%w/\e033[0m\e033[1m%f$git\e033[0m"
lf -remote "send $id set promptfmt \e"$fmt\e""
}}
.EE
.PP
This command runs whenever you change directory but not on startup. You can add an extra call to make it run on startup as well:
.PP
.EX
cmd on-cd &{{ # ... }}
on-cd
.EE
.PP
Note that all shell commands are possible but `%` and `&` are usually more appropriate as `$` and `!` causes flickers and pauses respectively.
.SH COLORSCHEMES .SH COLORSCHEMES
lf tries to automatically adapt its colors to the environment. On startup, first '$LS_COLORS' environment variable is checked. This variable is used by GNU ls to configure its colors based on file types and extensions. The value of this variable is often set by GNU dircolors in a shell configuration file. dircolors program itself can be configured with a configuration file. dircolors supports 256 colors along with common attributes such as bold and underline. lf tries to automatically adapt its colors to the environment. On startup, first '$LS_COLORS' environment variable is checked. This variable is used by GNU ls to configure its colors based on file types and extensions. The value of this variable is often set by GNU dircolors in a shell configuration file. dircolors program itself can be configured with a configuration file. dircolors supports 256 colors along with common attributes such as bold and underline.
.PP .PP
+9
View File
@@ -0,0 +1,9 @@
[Desktop Entry]
Type=Application
Name=lf
Comment=Launches the lf file manager
Icon=utilities-terminal
Terminal=true
Exec=lf
Categories=ConsoleOnly;System;FileTools;FileManager
MimeType=inode/directory;
+16 -23
View File
@@ -41,22 +41,12 @@ func runeSliceWidthRange(rs []rune, beg, end int) []rune {
return nil return nil
} }
// This function is used to escape whitespaces with backlashes in a given // This function is used to escape whitespaces and special characters with
// string. If a whitespace is already escaped then it is not escaped again. // backlashes in a given string.
func escape(s string) string { func escape(s string) string {
esc := false
buf := make([]rune, 0, len(s)) buf := make([]rune, 0, len(s))
for _, r := range s { for _, r := range s {
if r == '\\' { if unicode.IsSpace(r) || r == '\\' || r == ';' || r == '#' {
esc = true
continue
}
if esc {
esc = false
buf = append(buf, '\\', r)
continue
}
if unicode.IsSpace(r) {
buf = append(buf, '\\') buf = append(buf, '\\')
} }
buf = append(buf, r) buf = append(buf, r)
@@ -65,26 +55,29 @@ func escape(s string) string {
} }
// This function is used to remove backlashes that are used to escape // This function is used to remove backlashes that are used to escape
// whitespaces in a given string. // whitespaces and special characters in a given string.
func unescape(s string) string { func unescape(s string) string {
esc := false esc := false
buf := make([]rune, 0, len(s)) buf := make([]rune, 0, len(s))
for _, r := range s { for _, r := range s {
if esc {
if !unicode.IsSpace(r) && r != '\\' && r != ';' && r != '#' {
buf = append(buf, '\\')
}
buf = append(buf, r)
esc = false
continue
}
if r == '\\' { if r == '\\' {
esc = true esc = true
continue continue
} }
if esc { esc = false
esc = false
if unicode.IsSpace(r) {
buf = append(buf, r)
} else {
buf = append(buf, '\\', r)
}
continue
}
buf = append(buf, r) buf = append(buf, r)
} }
if esc {
buf = append(buf, '\\')
}
return string(buf) return string(buf)
} }
+14 -3
View File
@@ -80,8 +80,13 @@ func TestEscape(t *testing.T) {
{"foo", "foo"}, {"foo", "foo"},
{"foo bar", `foo\ bar`}, {"foo bar", `foo\ bar`},
{"foo bar", `foo\ \ bar`}, {"foo bar", `foo\ \ bar`},
{`foo\ bar`, `foo\ bar`}, {`foo\bar`, `foo\\bar`},
{`foo\bar`, `foo\bar`}, {`foo\ bar`, `foo\\\ bar`},
{`foo;bar`, `foo\;bar`},
{`foo#bar`, `foo\#bar`},
{`foo\tbar`, `foo\\tbar`},
{"foo\tbar", "foo\\\tbar"},
{`foo\`, `foo\\`},
} }
for _, test := range tests { for _, test := range tests {
@@ -98,9 +103,15 @@ func TestUnescape(t *testing.T) {
}{ }{
{"", ""}, {"", ""},
{"foo", "foo"}, {"foo", "foo"},
{`foo\bar`, `foo\bar`},
{`foo\ bar`, "foo bar"}, {`foo\ bar`, "foo bar"},
{`foo\ \ bar`, "foo bar"}, {`foo\ \ bar`, "foo bar"},
{`foo\\bar`, `foo\bar`},
{`foo\\\ bar`, `foo\ bar`},
{`foo\;bar`, `foo;bar`},
{`foo\#bar`, `foo#bar`},
{`foo\\tbar`, `foo\tbar`},
{"foo\\\tbar", "foo\tbar"},
{`foo\`, `foo\`},
} }
for _, test := range tests { for _, test := range tests {
+133 -59
View File
@@ -13,6 +13,8 @@ import (
"strconv" "strconv"
"strings" "strings"
"time" "time"
times "gopkg.in/djherbis/times.v1"
) )
type linkState byte type linkState byte
@@ -25,9 +27,12 @@ const (
type file struct { type file struct {
os.FileInfo os.FileInfo
linkState linkState linkState linkState
path string path string
dirCount int dirCount int
accessTime time.Time
changeTime time.Time
ext string
} }
func readdir(path string) ([]*file, error) { func readdir(path string) ([]*file, error) {
@@ -62,11 +67,29 @@ func readdir(path string) ([]*file, error) {
} }
} }
ts := times.Get(lstat)
at := ts.AccessTime()
var ct time.Time
// from times docs: ChangeTime() panics unless HasChangeTime() is true
if ts.HasChangeTime() {
ct = ts.ChangeTime()
} else {
// fall back to ModTime if ChangeTime cannot be determined
ct = lstat.ModTime()
}
// returns an empty string if extension could not be determined
// i.e. directories, filenames without extensions
ext := filepath.Ext(fpath)
files = append(files, &file{ files = append(files, &file{
FileInfo: lstat, FileInfo: lstat,
linkState: linkState, linkState: linkState,
path: fpath, path: fpath,
dirCount: -1, dirCount: -1,
accessTime: at,
changeTime: ct,
ext: ext,
}) })
} }
@@ -124,6 +147,34 @@ func (dir *dir) sort() {
sort.SliceStable(dir.files, func(i, j int) bool { sort.SliceStable(dir.files, func(i, j int) bool {
return dir.files[i].ModTime().Before(dir.files[j].ModTime()) return dir.files[i].ModTime().Before(dir.files[j].ModTime())
}) })
case atimeSort:
sort.SliceStable(dir.files, func(i, j int) bool {
return dir.files[i].accessTime.Before(dir.files[j].accessTime)
})
case ctimeSort:
sort.SliceStable(dir.files, func(i, j int) bool {
return dir.files[i].changeTime.Before(dir.files[j].changeTime)
})
case extSort:
sort.SliceStable(dir.files, func(i, j int) bool {
leftExt := strings.ToLower(dir.files[i].ext)
rightExt := strings.ToLower(dir.files[j].ext)
// if the extension could not be determined (directories, files without)
// use a zero byte so that these files can be ranked higher
if leftExt == "" {
leftExt = "\x00"
}
if rightExt == "" {
rightExt = "\x00"
}
// in order to also have natural sorting with the filenames
// combine the name with the ext but have the ext at the front
left := leftExt + strings.ToLower(dir.files[i].Name())
right := rightExt + strings.ToLower(dir.files[j].Name())
return left < right
})
} }
if gOpts.sortType.option&reverseSort != 0 { if gOpts.sortType.option&reverseSort != 0 {
@@ -190,33 +241,38 @@ func (dir *dir) sel(name string, height int) {
} }
type nav struct { type nav struct {
dirs []*dir dirs []*dir
copyBytes int64 copyBytes int64
copyTotal int64 copyTotal int64
copyUpdate int copyUpdate int
moveCount int moveCount int
moveTotal int moveTotal int
moveUpdate int moveUpdate int
copyBytesChan chan int64 deleteCount int
copyTotalChan chan int64 deleteTotal int
moveCountChan chan int deleteUpdate int
moveTotalChan chan int copyBytesChan chan int64
dirChan chan *dir copyTotalChan chan int64
regChan chan *reg moveCountChan chan int
dirCache map[string]*dir moveTotalChan chan int
regCache map[string]*reg deleteCountChan chan int
saves map[string]bool deleteTotalChan chan int
marks map[string]string dirChan chan *dir
renameCache []string regChan chan *reg
selections map[string]int dirCache map[string]*dir
selectionInd int regCache map[string]*reg
height int saves map[string]bool
find string marks map[string]string
findBack bool renameCache []string
search string selections map[string]int
searchBack bool selectionInd int
searchInd int height int
searchPos int find string
findBack bool
search string
searchBack bool
searchInd int
searchPos int
} }
func (nav *nav) loadDir(path string) *dir { func (nav *nav) loadDir(path string) *dir {
@@ -284,20 +340,22 @@ func newNav(height int) *nav {
} }
nav := &nav{ nav := &nav{
copyBytesChan: make(chan int64, 1024), copyBytesChan: make(chan int64, 1024),
copyTotalChan: make(chan int64, 1024), copyTotalChan: make(chan int64, 1024),
moveCountChan: make(chan int, 1024), moveCountChan: make(chan int, 1024),
moveTotalChan: make(chan int, 1024), moveTotalChan: make(chan int, 1024),
dirChan: make(chan *dir), deleteCountChan: make(chan int, 1024),
regChan: make(chan *reg), deleteTotalChan: make(chan int, 1024),
dirCache: make(map[string]*dir), dirChan: make(chan *dir),
regCache: make(map[string]*reg), regChan: make(chan *reg),
saves: make(map[string]bool), dirCache: make(map[string]*dir),
marks: make(map[string]string), regCache: make(map[string]*reg),
renameCache: make([]string, 2), saves: make(map[string]bool),
selections: make(map[string]int), marks: make(map[string]string),
selectionInd: 0, renameCache: make([]string, 2),
height: height, selections: make(map[string]int),
selectionInd: 0,
height: height,
} }
nav.getDirs(wd) nav.getDirs(wd)
@@ -415,7 +473,7 @@ func (nav *nav) preview() {
nav.regChan <- reg nav.regChan <- reg
} }
func (nav *nav) loadReg(ui *ui, path string) *reg { func (nav *nav) loadReg(path string) *reg {
r, ok := nav.regCache[path] r, ok := nav.regCache[path]
if !ok { if !ok {
go nav.preview() go nav.preview()
@@ -724,23 +782,41 @@ func (nav *nav) paste(ui *ui) error {
return nil return nil
} }
func (nav *nav) del() error { func (nav *nav) del(ui *ui) error {
list, err := nav.currFileOrSelections() list, err := nav.currFileOrSelections()
if err != nil { if err != nil {
return err return err
} }
for _, path := range list { go func() {
if err := os.RemoveAll(path); err != nil { echo := &callExpr{"echoerr", []string{""}, 1}
return err errCount := 0
nav.deleteTotalChan <- len(list)
for _, path := range list {
nav.deleteCountChan <- 1
if err := os.RemoveAll(path); err != nil {
errCount++
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
ui.exprChan <- echo
}
} }
}
nav.deleteTotalChan <- -len(list)
if err := remote("send load"); err != nil {
errCount++
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
ui.exprChan <- echo
}
}()
return nil return nil
} }
func (nav *nav) rename(ui *ui) error { func (nav *nav) rename() error {
oldPath := nav.renameCache[0] oldPath := nav.renameCache[0]
newPath := nav.renameCache[1] newPath := nav.renameCache[1]
dir, _ := filepath.Split(newPath) dir, _ := filepath.Split(newPath)
@@ -828,7 +904,6 @@ func (nav *nav) globSel(pattern string, invert bool) error {
for i := 0; i < len(curDir.files); i++ { for i := 0; i < len(curDir.files); i++ {
match, err := filepath.Match(pattern, curDir.files[i].Name()) match, err := filepath.Match(pattern, curDir.files[i].Name())
if err != nil { if err != nil {
return fmt.Errorf("glob-select: %s", err) return fmt.Errorf("glob-select: %s", err)
} }
@@ -1007,9 +1082,8 @@ func (nav *nav) removeMark(mark string) error {
if _, ok := nav.marks[mark]; ok { if _, ok := nav.marks[mark]; ok {
delete(nav.marks, mark) delete(nav.marks, mark)
return nil return nil
} else {
return fmt.Errorf("no such mark")
} }
return fmt.Errorf("no such mark")
} }
func (nav *nav) readMarks() error { func (nav *nav) readMarks() error {
+6
View File
@@ -9,6 +9,9 @@ const (
nameSort nameSort
sizeSort sizeSort
timeSort timeSort
atimeSort
ctimeSort
extSort
) )
type sortOption byte type sortOption byte
@@ -153,6 +156,9 @@ func init() {
gOpts.keys["sn"] = &listExpr{[]expr{&setExpr{"sortby", "natural"}, &setExpr{"info", ""}}} gOpts.keys["sn"] = &listExpr{[]expr{&setExpr{"sortby", "natural"}, &setExpr{"info", ""}}}
gOpts.keys["ss"] = &listExpr{[]expr{&setExpr{"sortby", "size"}, &setExpr{"info", "size"}}} gOpts.keys["ss"] = &listExpr{[]expr{&setExpr{"sortby", "size"}, &setExpr{"info", "size"}}}
gOpts.keys["st"] = &listExpr{[]expr{&setExpr{"sortby", "time"}, &setExpr{"info", "time"}}} gOpts.keys["st"] = &listExpr{[]expr{&setExpr{"sortby", "time"}, &setExpr{"info", "time"}}}
gOpts.keys["sa"] = &listExpr{[]expr{&setExpr{"sortby", "atime"}, &setExpr{"info", "atime"}}}
gOpts.keys["sc"] = &listExpr{[]expr{&setExpr{"sortby", "ctime"}, &setExpr{"info", "ctime"}}}
gOpts.keys["se"] = &listExpr{[]expr{&setExpr{"sortby", "ext"}, &setExpr{"info", ""}}}
gOpts.keys["gh"] = &callExpr{"cd", []string{"~"}, 1} gOpts.keys["gh"] = &callExpr{"cd", []string{"~"}, 1}
gOpts.cmdkeys = make(map[string]expr) gOpts.cmdkeys = make(map[string]expr)
+1 -3
View File
@@ -18,9 +18,7 @@ var (
envShell = os.Getenv("SHELL") envShell = os.Getenv("SHELL")
) )
var ( var envPathExt = os.Getenv("PATHEXT")
envPathExt = os.Getenv("PATHEXT")
)
var ( var (
gDefaultShell = "cmd" gDefaultShell = "cmd"
+19 -21
View File
@@ -216,25 +216,24 @@ scan:
for !s.eof && s.chr != '"' { for !s.eof && s.chr != '"' {
if s.chr == '\\' { if s.chr == '\\' {
s.next() s.next()
switch s.chr { switch {
case '"', '\\': case s.chr == '"' || s.chr == '\\':
buf = append(buf, s.chr) buf = append(buf, s.chr)
case 'a': case s.chr == 'a':
buf = append(buf, '\a') buf = append(buf, '\a')
case 'b': case s.chr == 'b':
buf = append(buf, '\b') buf = append(buf, '\b')
case 'f': case s.chr == 'f':
buf = append(buf, '\f') buf = append(buf, '\f')
case 'n': case s.chr == 'n':
buf = append(buf, '\n') buf = append(buf, '\n')
case 'r': case s.chr == 'r':
buf = append(buf, '\r') buf = append(buf, '\r')
case 't': case s.chr == 't':
buf = append(buf, '\t') buf = append(buf, '\t')
case 'v': case s.chr == 'v':
buf = append(buf, '\v') buf = append(buf, '\v')
} case isDigit(s.chr):
if isDigit(s.chr) {
var oct []byte var oct []byte
for isDigit(s.chr) { for isDigit(s.chr) {
oct = append(oct, s.chr) oct = append(oct, s.chr)
@@ -245,13 +244,15 @@ scan:
log.Printf("scanning: %s", err) log.Printf("scanning: %s", err)
} }
buf = append(buf, byte(n)) buf = append(buf, byte(n))
} else { continue
s.next() default:
buf = append(buf, '\\', s.chr)
} }
} else {
buf = append(buf, s.chr)
s.next() s.next()
continue
} }
buf = append(buf, s.chr)
s.next()
} }
s.typ = tokenIdent s.typ = tokenIdent
s.tok = string(buf) s.tok = string(buf)
@@ -293,12 +294,9 @@ scan:
for !s.eof && !isSpace(s.chr) && s.chr != ';' && s.chr != '#' { for !s.eof && !isSpace(s.chr) && s.chr != ';' && s.chr != '#' {
if s.chr == '\\' { if s.chr == '\\' {
s.next() s.next()
if isSpace(s.chr) { buf = append(buf, s.chr)
buf = append(buf, s.chr) s.next()
s.next() continue
} else {
s.next()
}
} }
buf = append(buf, s.chr) buf = append(buf, s.chr)
s.next() s.next()
+3 -2
View File
@@ -58,6 +58,7 @@ func listen(l net.Listener) {
func handleConn(c net.Conn) { func handleConn(c net.Conn) {
s := bufio.NewScanner(c) s := bufio.NewScanner(c)
Loop:
for s.Scan() { for s.Scan() {
log.Printf("listen: %s", s.Text()) log.Printf("listen: %s", s.Text())
word, rest := splitWord(s.Text()) word, rest := splitWord(s.Text())
@@ -71,7 +72,7 @@ func handleConn(c net.Conn) {
gCopyFile = false gCopyFile = false
default: default:
log.Printf("unexpected option to copy file(s): %s", s.Text()) log.Printf("unexpected option to copy file(s): %s", s.Text())
break break Loop
} }
gFileList = nil gFileList = nil
for s.Scan() && s.Text() != "" { for s.Scan() && s.Text() != "" {
@@ -120,7 +121,7 @@ func handleConn(c net.Conn) {
c.Close() c.Close()
} }
gListener.Close() gListener.Close()
break break Loop
default: default:
log.Printf("listen: unexpected command: %s", word) log.Printf("listen: unexpected command: %s", word)
} }
+17 -30
View File
@@ -15,8 +15,8 @@ import (
"unicode" "unicode"
"unicode/utf8" "unicode/utf8"
"github.com/doronbehar/termbox-go"
"github.com/mattn/go-runewidth" "github.com/mattn/go-runewidth"
"github.com/nsf/termbox-go"
) )
const gEscapeCode = 27 const gEscapeCode = 27
@@ -190,8 +190,6 @@ func (win *win) printReg(reg *reg) {
for i, l := range reg.lines { for i, l := range reg.lines {
fg, bg = win.print(2, i, fg, bg, l) fg, bg = win.print(2, i, fg, bg, l)
} }
return
} }
func fileInfo(f *file, d *dir) string { func fileInfo(f *file, d *dir) string {
@@ -233,6 +231,10 @@ func fileInfo(f *file, d *dir) string {
} }
case "time": case "time":
info = fmt.Sprintf("%s %12s", info, f.ModTime().Format("Jan _2 15:04")) info = fmt.Sprintf("%s %12s", info, f.ModTime().Format("Jan _2 15:04"))
case "atime":
info = fmt.Sprintf("%s %12s", info, f.accessTime.Format("Jan _2 15:04"))
case "ctime":
info = fmt.Sprintf("%s %12s", info, f.changeTime.Format("Jan _2 15:04"))
default: default:
log.Printf("unknown info type: %s", s) log.Printf("unknown info type: %s", s)
} }
@@ -539,7 +541,7 @@ func (ui *ui) loadFile(nav *nav) {
if curr.IsDir() { if curr.IsDir() {
ui.dirPrev = nav.loadDir(curr.path) ui.dirPrev = nav.loadDir(curr.path)
} else if curr.Mode().IsRegular() { } else if curr.Mode().IsRegular() {
ui.regPrev = nav.loadReg(ui, curr.path) ui.regPrev = nav.loadReg(curr.path)
} }
} }
@@ -555,9 +557,11 @@ func (ui *ui) loadFileInfo(nav *nav) {
func (ui *ui) drawPromptLine(nav *nav) { func (ui *ui) drawPromptLine(nav *nav) {
fg, bg := termbox.ColorDefault, termbox.ColorDefault fg, bg := termbox.ColorDefault, termbox.ColorDefault
dir := nav.currDir() pwd := nav.currDir().path
nohome := strings.TrimPrefix(pwd, gUser.HomeDir)
pwd := strings.Replace(dir.path, gUser.HomeDir, "~", -1) if len(nohome) < len(pwd) {
pwd = "~/" + nohome
}
pwd = filepath.Clean(pwd) pwd = filepath.Clean(pwd)
var fname string var fname string
@@ -612,12 +616,16 @@ func (ui *ui) drawStatLine(nav *nav) {
progress += fmt.Sprintf(" [%d/%d]", nav.moveCount, nav.moveTotal) progress += fmt.Sprintf(" [%d/%d]", nav.moveCount, nav.moveTotal)
} }
if nav.deleteTotal > 0 {
progress += fmt.Sprintf(" [%d/%d]", nav.deleteCount, nav.deleteTotal)
}
ruler := fmt.Sprintf("%s%s %d/%d", acc, progress, ind, tot) ruler := fmt.Sprintf("%s%s %d/%d", acc, progress, ind, tot)
ui.msgWin.printRight(0, fg, bg, ruler) ui.msgWin.printRight(0, fg, bg, ruler)
} }
func (ui *ui) drawBox(nav *nav) { func (ui *ui) drawBox() {
fg, bg := termbox.ColorDefault, termbox.ColorDefault fg, bg := termbox.ColorDefault, termbox.ColorDefault
w, h := termbox.Size() w, h := termbox.Size()
@@ -699,7 +707,7 @@ func (ui *ui) draw(nav *nav) {
} }
if gOpts.drawbox { if gOpts.drawbox {
ui.drawBox(nav) ui.drawBox()
} }
if ui.menuBuf != nil { if ui.menuBuf != nil {
@@ -862,27 +870,6 @@ func (ui *ui) readEvent(ch chan<- expr, ev termbox.Event) {
ui.keyAcc = nil ui.keyAcc = nil
ui.keyCount = nil ui.keyCount = nil
ui.menuBuf = nil ui.menuBuf = nil
case 1:
if ok {
if len(ui.keyCount) > 0 {
c, err := strconv.Atoi(string(ui.keyCount))
if err != nil {
log.Printf("converting command count: %s", err)
}
count = c
}
expr := gOpts.keys[string(ui.keyAcc)]
if e, ok := expr.(*callExpr); ok {
e.count = count
}
ch <- expr
ui.keyAcc = nil
ui.keyCount = nil
ui.menuBuf = nil
} else {
ui.menuBuf = listBinds(binds)
ch <- draw
}
default: default:
if ok { if ok {
if len(ui.keyCount) > 0 { if len(ui.keyCount) > 0 {