Compare commits

44 Commits
Author SHA1 Message Date
Gokcehan 7872455021 restart event polling after ui resume on windows
cc #677
2021-10-19 22:51:25 +03:00
Gokcehan 1b71c33afd update doc 2021-10-10 00:01:01 +03:00
Gokcehan f01fab6257 fix crash when hidden is changed
cc #615 #657
2021-10-09 22:49:12 +03:00
SPFab 85aa3b9dc6 Cmap fixes (#691)
* fixed bug when switching commands

* filter and searches are now reset, whenever prompt is reset

* don't interrupt %-shell commands

* filter and search are now correctly started and stoped on cd

* movement commands now don't stop prompts

* forgot shell-pipe check in delete command
2021-08-29 18:28:29 +03:00
SPFabGerman 5566f82596 fixed bug, where ~ is not a absolute directory (#690) 2021-08-25 19:36:14 +03:00
SPFab 0edf0823b7 cmap now accepts all expressions (#686) 2021-08-25 18:28:47 +03:00
SPFab 05a48ea315 added pre-cd command (#685)
* added special pre-cd command

* added documentation
2021-08-23 17:11:56 +03:00
SPFab ff0933ca03 Added filter command (#667)
* added first version of interactive filter

* small fix when loading new file

* don't reset filter when directory is reloaded automatically

* reapply filter when options for searching change

* current filter or arguments now prefilled in the prompt

* empty filter can now be supplied

* added new setfilter command for use in scripts

* added incfilter option

* added very basic documentation

* added filter indication in statusbar

* added option to display filter to prompt
2021-08-21 16:40:24 +03:00
Gokcehan 6c46b217af add completion for dircache option 2021-08-01 17:06:04 +03:00
Gokcehan bdd1747e43 update doc 2021-08-01 17:04:37 +03:00
Yegor Bychin ee5b3f4813 add an option to disable directory cache (#673)
* add an option to disable directory cache

* change option name to `dircache`

* change 4 whitespaces to tab
2021-08-01 17:00:10 +03:00
Matthew Tooheyandmtoohey31 75eba115d2 implement dironly option (#669)
Co-authored-by: mtoohey31 <mtoohey31@users.noreply.github.com>
2021-07-31 16:10:25 +03:00
SeerLite 8adbd2b9ef Don't use the absolute path when saving bookmarks (#659)
The absolute path of symlinks were getting saved, so bookmarking a symlink
directory would cause the absolute path to be saved and loaded instead.
What's saved now is the current path string as understood by lf instead, so
path to symlinks can be saved too and they won't get dereferenced when
loading.
2021-07-09 16:34:45 +03:00
Gokcehan 55b9189713 build release only on tags 2021-06-20 01:43:45 +03:00
Gokcehan b763c30cc5 deprecate travis in favor of github actions 2021-06-20 01:38:53 +03:00
gokcehan 61489ad00b Create release.yml 2021-06-20 01:37:44 +03:00
gokcehan 1ff3910c70 Create go.yml 2021-06-20 01:12:57 +03:00
Gokcehan 1966a30deb bump go version 2021-06-20 01:01:06 +03:00
ratijas 50e3a6856e PowerShell: use native Camel-Case style for commands (#650)
In PowerShell land it is preferred to use Camel Case for command names,
options and parameters, so lets respect that.
2021-06-19 23:41:14 +03:00
Gokcehan 9885c4be7a trim command prefix when it is longer than width
cc #648
2021-06-13 01:09:19 +03:00
Gokcehan 29aa77aa27 update doc 2021-06-13 00:36:48 +03:00
István Donkó 6e9f53f4bb Fix minor typo (#647)
* Fix minor typo

lf.1 will need to be regenerated as well.

* Fix minor typo
2021-06-13 00:36:16 +03:00
Gokcehan 099cccdcb5 show remote error when client id does not exists
cc #495
2021-06-13 00:27:43 +03:00
Gokcehan 4220868cc7 create data directory first before selection file
cc #645
2021-06-12 23:29:54 +03:00
Gokcehan eaaf08e425 ignore erase line escape code
cc #440
2021-05-30 20:43:17 +03:00
Gokcehan f885af55f2 add support for bright fg/bg ansi escape codes
cc #307
2021-05-30 19:26:08 +03:00
Gokcehan 599e42c12b calculate rune widths properly in shell outputs 2021-05-30 17:35:44 +03:00
Gokcehan 5d439419ea scroll when the prompt is longer than the width
cc #269
2021-05-30 17:24:19 +03:00
Gokcehan 5d02b557d3 follow links in 'open' examples
cc #634
2021-05-22 01:46:13 +03:00
Gokcehan 7acb69c40a echo logged server errors back to client as well 2021-05-21 16:54:01 +03:00
Gokcehan 7cdb7495ea add a command line parameter for single use
cc #177
2021-05-19 23:38:05 +03:00
Gokcehan d6acf4a6ec update doc 2021-05-19 22:25:26 +03:00
Gokcehan 06a30eda19 add 'autoquit' option to auto quit server on quit
cc #177
2021-05-19 21:55:19 +03:00
Gokcehan 7bf895e301 add server quit command to quit without clients
cc #177
2021-05-19 21:47:53 +03:00
Gokcehan 1841bba3e6 rename server quit command to quit!
cc #177
2021-05-19 21:47:08 +03:00
Gokcehan 6ca07b1bfc drop client connections on quit
cc #177
2021-05-19 21:45:27 +03:00
Gokcehan ec330c1bc5 use a local file instead of server load and save
cc #177
2021-05-19 19:54:50 +03:00
Gokcehan d31cd98b58 bump tcell to v2.3.1
cc #616 #621
2021-05-16 22:52:15 +03:00
Marius 0cd634e9a8 Preserve ' bookmark on sync (#624) 2021-05-13 21:31:25 +03:00
Marius 843afdfe4f Make ratios behave like ratios (#622)
Integer division causes miscalculation of pane widths. With `set ratios 100:200:300` the first two panes have width 0, the third pane will take up all space (unless you happen to have a huge terminal). I noticed this when fine tuning ratios, e.g. going from `1:2:3` to something like `10:21:30`.
2021-05-13 21:25:04 +03:00
Gokcehan 1bd78220e2 avoid crash with dir preview when hidden changes
cc #615
2021-04-28 18:50:24 +03:00
Gokcehan 202a998731 invalidate reg cache when drawbox option changes
cc #602
2021-04-25 16:51:40 +03:00
Gokcehan 8739087fe1 increase lookahead length for color escapes
cc #609
2021-04-15 17:23:25 +03:00
Gokcehan 628bf408b4 invalidate reg cache when height changes in resize
cc #610
2021-04-14 14:49:41 +03:00
31 changed files with 1014 additions and 422 deletions

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
name: Go
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.15
- name: Build
run: go build -v ./...
- name: Test
run: go test -v ./...
+28
View File
@@ -0,0 +1,28 @@
name: Release
on:
push:
tags:
- '*'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.15
- name: Build
run: gen/xbuild.sh
- name: Release
uses: softprops/action-gh-release@v1
with:
files: dist/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-19
View File
@@ -1,19 +0,0 @@
language: go
go:
- 1.15.x
before_deploy:
- gen/xbuild.sh
deploy:
provider: releases
api_key:
secure: RdZAOPWooYq73iFQIjqe9+Awr7oA8m0j0tn1tUUfLjP+PGYpuz2lf1SHW/UjPcxySFkkBxnNPC1xgqmxekmvZadBaQbApqko4e47zCF0Pe91QG9OcDFaiJUWb7wcg+UDLoS0lJq8mcKYoi6bV76syOk0gBunLUmuYYpz/hR4lbalfq5//fD6sOOJ9cJPjeuG7LwYqbyw/8VwQWpiWgK9Sb5gu7+ZBgXkLG+/5OSHW8yNHGmtkw5sjMr4jQnNt2ixXVe5OdQ14mvRx0n4vlnzjNjmY6cPjEeqAc9eniOJ5o99k1OnR3H5kmNgI749q+VAkdu/uJfHiLXL1zerReb4SSTU+tTw9c7JYTcjBHlCT11CHlksVu55hHAbFvPkIpLfoRvdqrcjUyEHiCI/HbWiHhsQ+Gve+tpIcgu/aAC2TEsQ+vmmaXbOFcUsG77XP8gn1y+Spkyzou7tUvypIXduDSKFIvI51HYK2F5t5ttG6zJw9lpmmuoUWvCvbGvdAW893O6ef+iZvBoZYRjdeWvIqh/no2gWi1CRa4ZPSZWkn9NoE/2koaCQkrx9RHmEeLIukZVAT6ZViwvhMAOrvXQdKTDwbQ3ovMdtDvGcvjGz9k5xwnWrIcF7MV7nf7sj/JlcX2tulevcSLsYeBvcuTUFzy90erMy70MS01wp0I/IgpY=
skip_cleanup: true
file_glob: true
file: dist/*
name: $TRAVIS_TAG
on:
tags: true
repo: gokcehan/lf
-1
View File
@@ -5,7 +5,6 @@
| [#lf](https://webchat.freenode.net/?channels=lf) (on Freenode)
| [#lf:matrix.org](https://matrix.to/#/#lf:matrix.org) (with IRC bridge)
[![Build Status](https://travis-ci.org/gokcehan/lf.svg?branch=master)](https://travis-ci.org/gokcehan/lf)
[![Go Report Card](https://goreportcard.com/badge/github.com/gokcehan/lf)](https://goreportcard.com/report/github.com/gokcehan/lf)
[![Go Reference](https://pkg.go.dev/badge/github.com/gokcehan/lf.svg)](https://pkg.go.dev/github.com/gokcehan/lf)
+103 -15
View File
@@ -49,8 +49,7 @@ func newApp(ui *ui, nav *nav) *app {
case os.Interrupt:
return
case syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM:
app.writeHistory()
os.Remove(gLogPath)
app.quit()
os.Exit(3)
return
}
@@ -59,6 +58,23 @@ func newApp(ui *ui, nav *nav) *app {
return app
}
func (app *app) quit() {
if err := app.writeHistory(); err != nil {
log.Printf("writing history file: %s", err)
}
if !gSingleMode {
if err := remote(fmt.Sprintf("drop %d", gClientID)); err != nil {
log.Printf("dropping connection: %s", err)
}
if gOpts.autoquit {
if err := remote("quit"); err != nil {
log.Printf("auto quitting server: %s", err)
}
}
}
os.Remove(gLogPath)
}
func (app *app) readFile(path string) {
log.Printf("reading file: %s", path)
@@ -80,6 +96,72 @@ func (app *app) readFile(path string) {
}
}
func loadFiles() (list []string, cp bool, err error) {
files, err := os.Open(gFilesPath)
if os.IsNotExist(err) {
err = nil
return
}
if err != nil {
err = fmt.Errorf("opening file selections file: %s", err)
return
}
defer files.Close()
s := bufio.NewScanner(files)
s.Scan()
switch s.Text() {
case "copy":
cp = true
case "move":
cp = false
default:
err = fmt.Errorf("unexpected option to copy file(s): %s", s.Text())
return
}
for s.Scan() && s.Text() != "" {
list = append(list, s.Text())
}
if s.Err() != nil {
err = fmt.Errorf("scanning file list: %s", s.Err())
return
}
log.Printf("loading files: %v", list)
return
}
func saveFiles(list []string, cp bool) error {
if err := os.MkdirAll(filepath.Dir(gFilesPath), os.ModePerm); err != nil {
return fmt.Errorf("creating data directory: %s", err)
}
files, err := os.Create(gFilesPath)
if err != nil {
return fmt.Errorf("opening file selections file: %s", err)
}
defer files.Close()
log.Printf("saving files: %v", list)
if cp {
fmt.Fprintln(files, "copy")
} else {
fmt.Fprintln(files, "move")
}
for _, f := range list {
fmt.Fprintln(files, f)
}
return nil
}
func (app *app) readHistory() error {
f, err := os.Open(gHistoryPath)
if os.IsNotExist(err) {
@@ -157,7 +239,10 @@ func (app *app) writeHistory() error {
func (app *app) loop() {
go app.nav.previewLoop(app.ui)
serverChan := readExpr()
var serverChan <-chan expr
if !gSingleMode {
serverChan = readExpr()
}
app.ui.readExpr()
@@ -218,14 +303,12 @@ func (app *app) loop() {
continue
}
app.quit()
app.nav.previewChan <- ""
log.Print("bye!")
if err := app.writeHistory(); err != nil {
log.Printf("writing history file: %s", err)
}
if gLastDirPath != "" {
f, err := os.Create(gLastDirPath)
if err != nil {
@@ -289,13 +372,15 @@ func (app *app) loop() {
case d := <-app.nav.dirChan:
app.nav.checkDir(d)
prev, ok := app.nav.dirCache[d.path]
if ok {
d.ind = prev.ind
d.sel(prev.name(), app.nav.height)
}
if gOpts.dircache {
prev, ok := app.nav.dirCache[d.path]
if ok {
d.ind = prev.ind
d.sel(prev.name(), app.nav.height)
}
app.nav.dirCache[d.path] = d
app.nav.dirCache[d.path] = d
}
for i := range app.nav.dirs {
if app.nav.dirs[i].path == d.path {
@@ -401,8 +486,7 @@ func (app *app) runShell(s string, args []string, prefix string) {
}
defer func() {
if err := app.ui.resume(); err != nil {
app.writeHistory()
os.Remove(gLogPath)
app.quit()
os.Exit(3)
return
}
@@ -411,6 +495,9 @@ func (app *app) runShell(s string, args []string, prefix string) {
err = cmd.Run()
case "%":
if app.ui.cmdPrefix == ">" {
return
}
stdin, err := cmd.StdinPipe()
if err != nil {
log.Printf("writing stdin: %s", err)
@@ -440,6 +527,7 @@ func (app *app) runShell(s string, args []string, prefix string) {
switch prefix {
case "%":
normal(app)
app.cmd = cmd
app.cmdOutBuf = nil
app.ui.msg = ""
+4 -64
View File
@@ -29,7 +29,6 @@ func run() {
if err != nil {
panic(err)
}
defer os.Remove(gLogPath)
defer f.Close()
log.SetOutput(f)
@@ -39,6 +38,10 @@ func run() {
nav := newNav(ui.wins[0].h)
app := newApp(ui, nav)
if err := nav.sync(); err != nil {
app.ui.echoerrf("sync: %s", err)
}
if err := app.nav.readMarks(); err != nil {
app.ui.echoerrf("reading marks file: %s", err)
}
@@ -85,69 +88,6 @@ func readExpr() <-chan expr {
return ch
}
func saveFiles(list []string, cp bool) error {
c, err := net.Dial(gSocketProt, gSocketPath)
if err != nil {
return fmt.Errorf("dialing to save files: %s", err)
}
defer c.Close()
log.Printf("saving files: %v", list)
fmt.Fprintln(c, "save")
if cp {
fmt.Fprintln(c, "copy")
} else {
fmt.Fprintln(c, "move")
}
for _, f := range list {
fmt.Fprintln(c, f)
}
fmt.Fprintln(c)
return nil
}
func loadFiles() (list []string, cp bool, err error) {
c, e := net.Dial(gSocketProt, gSocketPath)
if e != nil {
err = fmt.Errorf("dialing to load files: %s", e)
return
}
defer c.Close()
fmt.Fprintln(c, "load")
s := bufio.NewScanner(c)
s.Scan()
switch s.Text() {
case "copy":
cp = true
case "move":
cp = false
default:
err = fmt.Errorf("unexpected option to copy file(s): %s", s.Text())
return
}
for s.Scan() && s.Text() != "" {
list = append(list, s.Text())
}
if s.Err() != nil {
err = fmt.Errorf("scanning file list: %s", s.Err())
return
}
log.Printf("loading files: %v", list)
return
}
func remote(cmd string) error {
c, err := net.Dial(gSocketProt, gSocketPath)
if err != nil {
+4
View File
@@ -118,6 +118,8 @@ func applyAnsiCodes(s string, st tcell.Style) tcell.Style {
st = st.StrikeThrough(true)
case n >= 30 && n <= 37:
st = st.Foreground(tcell.PaletteColor(n - 30))
case n >= 90 && n <= 97:
st = st.Foreground(tcell.PaletteColor(n - 82))
case n == 38:
if i+3 <= len(nums) && nums[i+1] == 5 {
st = st.Foreground(tcell.PaletteColor(nums[i+2]))
@@ -133,6 +135,8 @@ func applyAnsiCodes(s string, st tcell.Style) tcell.Style {
}
case n >= 40 && n <= 47:
st = st.Background(tcell.PaletteColor(n - 40))
case n >= 100 && n <= 107:
st = st.Background(tcell.PaletteColor(n - 92))
case n == 48:
if i+3 <= len(nums) && nums[i+1] == 5 {
st = st.Background(tcell.PaletteColor(nums[i+2]))
+14
View File
@@ -48,6 +48,8 @@ var (
"search-back",
"search-next",
"search-prev",
"filter",
"setfilter",
"mark-save",
"mark-remove",
"mark-load",
@@ -70,12 +72,21 @@ var (
"anchorfind",
"noanchorfind",
"anchorfind!",
"autoquit",
"noautoquit",
"autoquit!",
"dircache",
"nodircache",
"dircache!",
"dircounts",
"nodircounts",
"dircounts!",
"dirfirst",
"nodirfirst",
"dirfirst!",
"dironly",
"nodironly",
"dironly!",
"drawbox",
"nodrawbox",
"drawbox!",
@@ -97,6 +108,9 @@ var (
"incsearch",
"noincsearch",
"incsearch!",
"incfilter",
"noincfilter",
"incfilter!",
"mouse",
"nomouse",
"mouse!",
+50 -26
View File
@@ -62,6 +62,8 @@ The following commands are provided by lf:
search-back (modal) (default '?')
search-next (default 'n')
search-prev (default 'N')
filter (modal)
setfilter
mark-save (modal) (default 'm')
mark-load (modal) (default "'")
mark-remove (modal) (default `"`)
@@ -98,8 +100,11 @@ The following command line commands are provided by lf:
The following options can be used to customize the behavior of lf:
anchorfind bool (default on)
autoquit bool (default off)
dircache bool (default on)
dircounts bool (default off)
dirfirst bool (default on)
dironly bool (default off)
drawbox bool (default off)
errorfmt string (default "\033[7;31;47m%s\033[0m")
filesep string (default "\n")
@@ -111,6 +116,7 @@ The following options can be used to customize the behavior of lf:
ifs string (default '')
ignorecase bool (default on)
ignoredia bool (default on)
incfilter bool (default off)
incsearch bool (default off)
info []string (default '')
mouse bool (default off)
@@ -184,6 +190,11 @@ Configuration files should be located at:
unix /etc/lf/lfrc ~/.config/lf/lfrc
windows C:\ProgramData\lf\lfrc C:\Users\<user>\AppData\Local\lf\lfrc
Selection file should be located at:
unix ~/.local/share/lf/files
windows C:\Users\<user>\AppData\Local\lf\files
Marks file should be located at:
unix ~/.local/share/lf/marks
@@ -362,7 +373,7 @@ Read a shell command to execute and wait for a key press in the end.
shell-async (modal) (default '&')
Read a shell command to execute synchronously without standard I/O.
Read a shell command to execute asynchronously without standard I/O.
find (modal) (default 'f')
find-back (modal) (default 'F')
@@ -382,6 +393,15 @@ Read a pattern to search for a file name match in the forward/backward direction
(See also 'globsearch', 'incsearch', 'wrapscan', 'ignorecase', 'smartcase', 'ignoredia', and 'smartdia' options and 'Searching Files' section)
filter (modal)
setfilter
Read a pattern to filter out and only view files matching the pattern.
setfilter does the same but uses an argument to set the filter immediatly.
You can supply an argument to filter, in order to use that as the starting prompt.
(See also 'globsearch', 'incfilter', 'ignorecase', 'smartcase', 'ignoredia', and 'smartdia' options)
mark-save (modal) (default 'm')
Save the current directory as a bookmark assigned to the given key.
@@ -489,6 +509,14 @@ Character ':' is used as the separator for list options '[]int' and '[]string'.
When this option is enabled, find command starts matching patterns from the beginning of file names, otherwise, it can match at an arbitrary position.
autoquit bool (default off)
Automatically quit server when there are no clients left connected.
dircache bool (default on)
Cache directory contents.
dircounts bool (default off)
When this option is enabled, directory sizes show the number of items inside instead of the size of directory file.
@@ -502,6 +530,10 @@ A thousand items are counted per directory at most, and bigger directories are s
Show directories first above regular files.
dironly bool (default off)
Show only directories.
drawbox bool (default off)
Draw boxes around panes with box drawing characters.
@@ -567,6 +599,10 @@ Ignore diacritics in sorting and search patterns.
Jump to the first match after each keystroke during searching.
incfilter bool (default off)
Apply filter pattern after each keystroke during filtering.
info []string (default '')
List of information shown for directory items at the right side of pane.
@@ -615,7 +651,7 @@ Preview clearing is disabled when the value of this option is left empty.
promptfmt string (default "\033[32;1m%u@%h\033[0m:\033[34;1m%d\033[0m\033[1m%f\033[0m")
Format string of the prompt shown in the top line.
Special expansions are provided, '%u' as the user name, '%h' as the host name, '%w' as the working directory, '%d' as the working directory with a trailing path separator, and '%f' as the file name.
Special expansions are provided, '%u' as the user name, '%h' as the host name, '%w' as the working directory, '%d' as the working directory with a trailing path separator, '%f' as the file name, and '%F' as the current filter.
Home folder is shown as '~' in the working directory expansion.
Directory names are automatically shortened to a single character starting from the left most parent when the prompt does not fit to the screen.
@@ -781,7 +817,7 @@ Command 'map' is used to bind a key to a command which can be builtin command, c
map gh cd ~ # builtin command
map D trash # custom command
map i $less $f # shell command
map U !du -sh # waiting shell command
map U !du -csh * # waiting shell command
Command 'cmap' is used to bind a key to a command line command which can only be one of the builtin commands:
@@ -996,10 +1032,11 @@ This is the recommended way of using remote commands since it is shorter and imm
In this command 'send' is used to send the rest of the string as a command to all connected clients.
You can optionally give it an id number to send a command to a single client:
lf -remote 'send 1000 echo hello world'
lf -remote 'send 1234 echo hello world'
All clients have a unique id number but you may not be aware of the id number when you are writing a command.
For this purpose, an '$id' variable is exported to the environment for shell commands.
The value of this variable is set to the process id of the client.
You can use it to send a remote command from a client to the server which in return sends a command back to itself.
So now you can display a message in the current client by calling the following in a shell command:
@@ -1019,27 +1056,10 @@ For example, you can configure the number of columns in the ui with respect to t
fi
}}
Besides 'send' command, there are also two commands to get or set the current file selection.
Two possible modes 'copy' and 'move' specify whether selected files are to be copied or moved.
File names are separated by newline character.
Setting the file selection is done with 'save' command:
lf -remote "$(printf 'save\ncopy\nfoo.txt\nbar.txt\nbaz.txt\n')"
Getting the file selection is similarly done with 'load' command:
load=$(lf -remote 'load')
mode=$(echo "$load" | sed -n '1p')
list=$(echo "$load" | sed '1d')
if [ $mode = 'copy' ]; then
# do something with $list
elif [ $mode = 'move' ]; then
# do something else with $list
fi
There is a 'quit' command to close client connections and quit the server:
Besides 'send' command, there is a 'quit' command to quit the server when there are no connected clients left, and a 'quit!' command to force quit the server by closing client connections first:
lf -remote 'quit'
lf -remote 'quit!'
Lastly, there is a 'conn' command to connect the server as a client.
This should not be needed for users.
@@ -1057,7 +1077,7 @@ For cross-device moving, lf falls back to copying and then deletes the original
Operation errors are shown in the message line as well as the log file and they do not preemptively finish the corresponding file operation.
File operations can be performed on the current selected file or alternatively on multiple files by selecting them first.
When you 'copy' a file, lf doesn't actually copy the file on the disk, but only records its name to memory.
When you 'copy' a file, lf doesn't actually copy the file on the disk, but only records its name to a file.
The actual file copying takes place when you 'paste'.
Similarly 'paste' after a 'cut' operation moves the file.
@@ -1066,7 +1086,7 @@ This is a special command that is called when it is defined instead of the built
You can use the following example as a starting point:
cmd paste %{{
load=$(lf -remote 'load')
load=$(cat ~/.local/share/lf/files)
mode=$(echo "$load" | sed -n '1p')
list=$(echo "$load" | sed '1d')
if [ $mode = 'copy' ]; then
@@ -1074,7 +1094,7 @@ You can use the following example as a starting point:
elif [ $mode = 'move' ]; then
mv $list .
fi
lf -remote 'send load'
rm ~/.local/share/lf/files
lf -remote 'send clear'
}}
@@ -1133,6 +1153,7 @@ It is possible to use different command types:
You may want to use either file extensions or mime types from 'file' command:
cmd open ${{
test -L $f && f=$(readlink -f $f)
case $(file --mime-type $f -b) in
text/*) vi $fx;;
*) for f in $fx; do xdg-open $f > /dev/null 2> /dev/null & done;;
@@ -1235,6 +1256,9 @@ You can add an extra call to make it run on startup as well:
Note that all shell commands are possible but `%` and `&` are usually more appropriate as `$` and `!` causes flickers and pauses respectively.
There is also a 'pre-cd' command, that works like 'on-cd', but is run before the directory is actually changed.
It is generally a bad idea, to put movement commands (like 'up' / 'top' etc.) here.
Colors
lf tries to automatically adapt its colors to the environment.
+70 -41
View File
@@ -66,6 +66,8 @@ The following commands are provided by lf:
search-back (modal) (default '?')
search-next (default 'n')
search-prev (default 'N')
filter (modal)
setfilter
mark-save (modal) (default 'm')
mark-load (modal) (default "'")
mark-remove (modal) (default '"')
@@ -102,8 +104,11 @@ The following command line commands are provided by lf:
The following options can be used to customize the behavior of lf:
anchorfind bool (default on)
autoquit bool (default off)
dircache bool (default on)
dircounts bool (default off)
dirfirst bool (default on)
dironly bool (default off)
drawbox bool (default off)
errorfmt string (default "\033[7;31;47m%s\033[0m")
filesep string (default "\n")
@@ -115,6 +120,7 @@ The following options can be used to customize the behavior of lf:
ifs string (default '')
ignorecase bool (default on)
ignoredia bool (default on)
incfilter bool (default off)
incsearch bool (default off)
info []string (default '')
mouse bool (default off)
@@ -189,6 +195,11 @@ Configuration files should be located at:
unix /etc/lf/lfrc ~/.config/lf/lfrc
windows C:\ProgramData\lf\lfrc C:\Users\<user>\AppData\Local\lf\lfrc
Selection file should be located at:
unix ~/.local/share/lf/files
windows C:\Users\<user>\AppData\Local\lf\files
Marks file should be located at:
unix ~/.local/share/lf/marks
@@ -378,7 +389,7 @@ Read a shell command to execute and wait for a key press in the end.
shell-async (modal) (default '&')
Read a shell command to execute synchronously without standard I/O.
Read a shell command to execute asynchronously without standard I/O.
find (modal) (default 'f')
find-back (modal) (default 'F')
@@ -402,6 +413,17 @@ direction and jump to the next/previous match.
(See also 'globsearch', 'incsearch', 'wrapscan', 'ignorecase', 'smartcase',
'ignoredia', and 'smartdia' options and 'Searching Files' section)
filter (modal)
setfilter
Read a pattern to filter out and only view files matching the pattern.
setfilter does the same but uses an argument to set the filter immediatly.
You can supply an argument to filter, in order to use that as the starting
prompt.
(See also 'globsearch', 'incfilter', 'ignorecase', 'smartcase', 'ignoredia',
and 'smartdia' options)
mark-save (modal) (default 'm')
Save the current directory as a bookmark assigned to the given key.
@@ -515,6 +537,14 @@ Character ':' is used as the separator for list options '[]int' and
When this option is enabled, find command starts matching patterns from the
beginning of file names, otherwise, it can match at an arbitrary position.
autoquit bool (default off)
Automatically quit server when there are no clients left connected.
dircache bool (default on)
Cache directory contents.
dircounts bool (default off)
When this option is enabled, directory sizes show the number of items inside
@@ -531,6 +561,10 @@ directories are shown as '999+'.
Show directories first above regular files.
dironly bool (default off)
Show only directories.
drawbox bool (default off)
Draw boxes around panes with box drawing characters.
@@ -598,6 +632,10 @@ Ignore diacritics in sorting and search patterns.
Jump to the first match after each keystroke during searching.
incfilter bool (default off)
Apply filter pattern after each keystroke during filtering.
info []string (default '')
List of information shown for directory items at the right side of pane.
@@ -655,11 +693,11 @@ Preview clearing is disabled when the value of this option is left empty.
Format string of the prompt shown in the top line. Special expansions are
provided, '%u' as the user name, '%h' as the host name, '%w' as the working
directory, '%d' as the working directory with a trailing path separator, and
'%f' as the file name. Home folder is shown as '~' in the working directory
expansion. Directory names are automatically shortened to a single character
starting from the left most parent when the prompt does not fit to the
screen.
directory, '%d' as the working directory with a trailing path separator,
'%f' as the file name, and '%F' as the current filter. Home folder is shown
as '~' in the working directory expansion. Directory names are automatically
shortened to a single character starting from the left most parent when the
prompt does not fit to the screen.
ratios []int (default '1:2:3')
@@ -846,7 +884,7 @@ command, custom command, or shell command:
map gh cd ~ # builtin command
map D trash # custom command
map i $less $f # shell command
map U !du -sh # waiting shell command
map U !du -csh * # waiting shell command
Command 'cmap' is used to bind a key to a command line command which can
only be one of the builtin commands:
@@ -1095,11 +1133,12 @@ In this command 'send' is used to send the rest of the string as a command
to all connected clients. You can optionally give it an id number to send a
command to a single client:
lf -remote 'send 1000 echo hello world'
lf -remote 'send 1234 echo hello world'
All clients have a unique id number but you may not be aware of the id
number when you are writing a command. For this purpose, an '$id' variable
is exported to the environment for shell commands. You can use it to send a
is exported to the environment for shell commands. The value of this
variable is set to the process id of the client. You can use it to send a
remote command from a client to the server which in return sends a command
back to itself. So now you can display a message in the current client by
calling the following in a shell command:
@@ -1121,27 +1160,12 @@ with respect to the terminal width as follows:
fi
}}
Besides 'send' command, there are also two commands to get or set the
current file selection. Two possible modes 'copy' and 'move' specify whether
selected files are to be copied or moved. File names are separated by
newline character. Setting the file selection is done with 'save' command:
lf -remote "$(printf 'save\ncopy\nfoo.txt\nbar.txt\nbaz.txt\n')"
Getting the file selection is similarly done with 'load' command:
load=$(lf -remote 'load')
mode=$(echo "$load" | sed -n '1p')
list=$(echo "$load" | sed '1d')
if [ $mode = 'copy' ]; then
# do something with $list
elif [ $mode = 'move' ]; then
# do something else with $list
fi
There is a 'quit' command to close client connections and quit the server:
Besides 'send' command, there is a 'quit' command to quit the server when
there are no connected clients left, and a 'quit!' command to force quit the
server by closing client connections first:
lf -remote 'quit'
lf -remote 'quit!'
Lastly, there is a 'conn' command to connect the server as a client. This
should not be needed for users.
@@ -1166,7 +1190,7 @@ corresponding file operation.
File operations can be performed on the current selected file or
alternatively on multiple files by selecting them first. When you 'copy' a
file, lf doesn't actually copy the file on the disk, but only records its
name to memory. The actual file copying takes place when you 'paste'.
name to a file. The actual file copying takes place when you 'paste'.
Similarly 'paste' after a 'cut' operation moves the file.
You can customize copy and move operations by defining a 'paste' command.
@@ -1174,18 +1198,18 @@ This is a special command that is called when it is defined instead of the
builtin implementation. You can use the following example as a starting
point:
cmd paste %{{
load=$(lf -remote 'load')
mode=$(echo "$load" | sed -n '1p')
list=$(echo "$load" | sed '1d')
if [ $mode = 'copy' ]; then
cp -R $list .
elif [ $mode = 'move' ]; then
mv $list .
fi
lf -remote 'send load'
lf -remote 'send clear'
}}
cmd paste %{{
load=$(cat ~/.local/share/lf/files)
mode=$(echo "$load" | sed -n '1p')
list=$(echo "$load" | sed '1d')
if [ $mode = 'copy' ]; then
cp -R $list .
elif [ $mode = 'move' ]; then
mv $list .
fi
rm ~/.local/share/lf/files
lf -remote 'send clear'
}}
Some useful things to be considered are to use the backup ('--backup')
and/or preserve attributes ('-a') options with 'cp' and 'mv' commands if
@@ -1259,6 +1283,7 @@ You may want to use either file extensions or mime types from 'file'
command:
cmd open ${{
test -L $f && f=$(readlink -f $f)
case $(file --mime-type $f -b) in
text/*) vi $fx;;
*) for f in $fx; do xdg-open $f > /dev/null 2> /dev/null & done;;
@@ -1382,6 +1407,10 @@ add an extra call to make it run on startup as well:
Note that all shell commands are possible but '%' and '&' are usually more
appropriate as '$' and '!' causes flickers and pauses respectively.
There is also a 'pre-cd' command, that works like 'on-cd', but is run before
the directory is actually changed. It is generally a bad idea, to put
movement commands (like 'up' / 'top' etc.) here.
Colors
+1
View File
@@ -17,6 +17,7 @@ _lf () {
-remote
-selection-path
-server
-single
-version
-help
)
+1 -1
View File
@@ -9,7 +9,7 @@
# endif
#
set LF_ARGS = "-command -config -cpuprofile -doc -last-dir-path -memprofile -remote -selection-path -server -version -help "
set LF_ARGS = "-command -config -cpuprofile -doc -last-dir-path -memprofile -remote -selection-path -server -single -version -help "
complete lf "C/-*/(${LF_ARGS})/"
complete lfcd "C/-*/(${LF_ARGS})/"
+1
View File
@@ -15,5 +15,6 @@ complete -c lf -o memprofile -r -d 'path to the file to write the memory profile
complete -c lf -o remote -x -d 'send remote command to server'
complete -c lf -o selection-path -r -d 'path to the file to write selected files on open (to use as open file dialog)'
complete -c lf -o server -d 'start server (automatic)'
complete -c lf -o single -d 'start a client without server'
complete -c lf -o version -d 'show version'
complete -c lf -o help -d 'show help'
+1
View File
@@ -18,6 +18,7 @@ Register-ArgumentCompleter -Native -CommandName 'lf' -ScriptBlock {
[CompletionResult]::new('-remote ', '-remote', [CompletionResultType]::ParameterName, 'send remote command to server')
[CompletionResult]::new('-selection-path ', '-selection-path', [CompletionResultType]::ParameterName, 'path to the file to write selected files on open (to use as open file dialog)')
[CompletionResult]::new('-server', '-server', [CompletionResultType]::ParameterName, 'start server (automatic)')
[CompletionResult]::new('-single', '-single', [CompletionResultType]::ParameterName, 'start a client without server')
[CompletionResult]::new('-version', '-version', [CompletionResultType]::ParameterName, 'show version')
[CompletionResult]::new('-help', '-help', [CompletionResultType]::ParameterName, 'show help')
)
+1
View File
@@ -22,6 +22,7 @@ arguments=(
'-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)]'
'-single[start a client without server]'
'-version[show version]'
'-help[show help]'
'*:filename:_files'
+4 -4
View File
@@ -15,10 +15,10 @@
$tmp = [System.IO.Path]::GetTempFileName()
lf -last-dir-path="$tmp" $args
if (test-path -pathtype leaf "$tmp") {
$dir = type "$tmp"
remove-item -force "$tmp"
if (test-path -pathtype container "$dir") {
if (Test-Path -PathType Leaf "$tmp") {
$dir = Get-Content "$tmp"
Remove-Item -Force "$tmp"
if (Test-Path -PathType Container "$dir") {
if ("$dir" -ne "$pwd") {
cd "$dir"
}
+1
View File
@@ -36,6 +36,7 @@ map O $mimeopen --ask $f
# use either file extensions and/or mime types here. Below uses an editor for
# text files and a file opener for the rest.
cmd open ${{
test -L $f && f=$(readlink -f $f)
case $(file --mime-type $f -b) in
text/*) $EDITOR $fx;;
*) for f in $fx; do setsid $OPENER $f > /dev/null 2> /dev/null & done;;
+357 -105
View File
@@ -20,12 +20,42 @@ func (e *setExpr) eval(app *app, args []string) {
gOpts.anchorfind = false
case "anchorfind!":
gOpts.anchorfind = !gOpts.anchorfind
case "autoquit":
gOpts.autoquit = true
case "noautoquit":
gOpts.autoquit = false
case "autoquit!":
gOpts.autoquit = !gOpts.autoquit
case "dircache":
gOpts.dircache = true
case "nodircache":
gOpts.dircache = false
case "dircache!":
gOpts.dircache = !gOpts.dircache
case "dircounts":
gOpts.dircounts = true
case "nodircounts":
gOpts.dircounts = false
case "dircounts!":
gOpts.dircounts = !gOpts.dircounts
case "dironly":
gOpts.dironly = true
app.nav.sort()
app.nav.position()
app.ui.sort()
app.ui.loadFile(app.nav, true)
case "nodironly":
gOpts.dironly = false
app.nav.sort()
app.nav.position()
app.ui.sort()
app.ui.loadFile(app.nav, true)
case "dironly!":
gOpts.dironly = !gOpts.dironly
app.nav.sort()
app.nav.position()
app.ui.sort()
app.ui.loadFile(app.nav, true)
case "dirfirst":
gOpts.sortType.option |= dirfirstSort
app.nav.sort()
@@ -41,21 +71,42 @@ func (e *setExpr) eval(app *app, args []string) {
case "drawbox":
gOpts.drawbox = true
app.ui.renew()
app.nav.height = app.ui.wins[0].h
if app.nav.height != app.ui.wins[0].h {
app.nav.height = app.ui.wins[0].h
app.nav.regCache = make(map[string]*reg)
}
app.ui.loadFile(app.nav, true)
case "nodrawbox":
gOpts.drawbox = false
app.ui.renew()
app.nav.height = app.ui.wins[0].h
if app.nav.height != app.ui.wins[0].h {
app.nav.height = app.ui.wins[0].h
app.nav.regCache = make(map[string]*reg)
}
app.ui.loadFile(app.nav, true)
case "drawbox!":
gOpts.drawbox = !gOpts.drawbox
app.ui.renew()
app.nav.height = app.ui.wins[0].h
if app.nav.height != app.ui.wins[0].h {
app.nav.height = app.ui.wins[0].h
app.nav.regCache = make(map[string]*reg)
}
app.ui.loadFile(app.nav, true)
case "globsearch":
gOpts.globsearch = true
app.nav.sort()
app.ui.sort()
app.ui.loadFile(app.nav, true)
case "noglobsearch":
gOpts.globsearch = false
app.nav.sort()
app.ui.sort()
app.ui.loadFile(app.nav, true)
case "globsearch!":
gOpts.globsearch = !gOpts.globsearch
app.nav.sort()
app.ui.sort()
app.ui.loadFile(app.nav, true)
case "hidden":
gOpts.sortType.option |= hiddenSort
app.nav.sort()
@@ -84,14 +135,17 @@ func (e *setExpr) eval(app *app, args []string) {
gOpts.ignorecase = true
app.nav.sort()
app.ui.sort()
app.ui.loadFile(app.nav, true)
case "noignorecase":
gOpts.ignorecase = false
app.nav.sort()
app.ui.sort()
app.ui.loadFile(app.nav, true)
case "ignorecase!":
gOpts.ignorecase = !gOpts.ignorecase
app.nav.sort()
app.ui.sort()
app.ui.loadFile(app.nav, true)
case "ignoredia":
gOpts.ignoredia = true
app.nav.sort()
@@ -104,6 +158,12 @@ func (e *setExpr) eval(app *app, args []string) {
gOpts.ignoredia = !gOpts.ignoredia
app.nav.sort()
app.ui.sort()
case "incfilter":
gOpts.incfilter = true
case "noincfilter":
gOpts.incfilter = false
case "incfilter!":
gOpts.incfilter = !gOpts.incfilter
case "incsearch":
gOpts.incsearch = true
case "noincsearch":
@@ -168,10 +228,19 @@ func (e *setExpr) eval(app *app, args []string) {
app.ui.sort()
case "smartcase":
gOpts.smartcase = true
app.nav.sort()
app.ui.sort()
app.ui.loadFile(app.nav, true)
case "nosmartcase":
gOpts.smartcase = false
app.nav.sort()
app.ui.sort()
app.ui.loadFile(app.nav, true)
case "smartcase!":
gOpts.smartcase = !gOpts.smartcase
app.nav.sort()
app.ui.sort()
app.ui.loadFile(app.nav, true)
case "smartdia":
gOpts.smartdia = true
case "nosmartdia":
@@ -367,10 +436,10 @@ func (e *mapExpr) eval(app *app, args []string) {
}
func (e *cmapExpr) eval(app *app, args []string) {
if e.cmd == "" {
if e.expr == nil {
delete(gOpts.cmdkeys, e.key)
} else {
gOpts.cmdkeys[e.key] = &callExpr{e.cmd, nil, 1}
gOpts.cmdkeys[e.key] = e.expr
}
app.ui.loadFileInfo(app.nav)
}
@@ -384,6 +453,12 @@ func (e *cmdExpr) eval(app *app, args []string) {
app.ui.loadFileInfo(app.nav)
}
func preChdir(app *app) {
if cmd, ok := gOpts.cmds["pre-cd"]; ok {
cmd.eval(app, nil)
}
}
func onChdir(app *app) {
if cmd, ok := gOpts.cmds["on-cd"]; ok {
cmd.eval(app, nil)
@@ -443,10 +518,56 @@ func update(app *app) {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
case gOpts.incfilter && app.ui.cmdPrefix == "filter: ":
filter := string(app.ui.cmdAccLeft) + string(app.ui.cmdAccRight)
dir := app.nav.currDir()
old := dir.ind
if err := app.nav.setFilter(strings.Split(filter, " ")); err != nil {
app.ui.echoerrf("filter: %s", err)
} else if old != dir.ind {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
}
}
func restartIncCmd(app *app) {
if gOpts.incsearch && (app.ui.cmdPrefix == "/" || app.ui.cmdPrefix == "?") {
dir := app.nav.currDir()
app.nav.searchInd = dir.ind
app.nav.searchPos = dir.pos
update(app)
} else if gOpts.incfilter && app.ui.cmdPrefix == "filter: " {
dir := app.nav.currDir()
app.nav.prevFilter = dir.filter
update(app)
}
}
func resetIncCmd(app *app) {
if gOpts.incsearch && (app.ui.cmdPrefix == "/" || app.ui.cmdPrefix == "?") {
dir := app.nav.currDir()
dir.pos = app.nav.searchPos
if dir.ind != app.nav.searchInd {
dir.ind = app.nav.searchInd
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
} else if gOpts.incfilter && app.ui.cmdPrefix == "filter: " {
dir := app.nav.currDir()
old := dir.ind
app.nav.setFilter(app.nav.prevFilter)
if old != dir.ind {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
}
}
func normal(app *app) {
resetIncCmd(app)
app.ui.menuBuf = nil
app.ui.menuSelected = -2
@@ -461,6 +582,9 @@ func insert(app *app, arg string) {
case gOpts.incsearch && (app.ui.cmdPrefix == "/" || app.ui.cmdPrefix == "?"):
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
update(app)
case gOpts.incfilter && app.ui.cmdPrefix == "filter: ":
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
update(app)
case app.ui.cmdPrefix == "find: ":
app.nav.find = string(app.ui.cmdAccLeft) + arg + string(app.ui.cmdAccRight)
@@ -528,9 +652,14 @@ func insert(app *app, arg string) {
return
}
app.nav.unselect()
if err := remote("send load"); err != nil {
app.ui.echoerrf("delete: %s", err)
return
if gSingleMode {
app.nav.renew()
app.ui.loadFile(app.nav, true)
} else {
if err := remote("send load"); err != nil {
app.ui.echoerrf("delete: %s", err)
return
}
}
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
@@ -543,9 +672,14 @@ func insert(app *app, arg string) {
app.ui.echoerrf("rename: %s", err)
return
}
if err := remote("send load"); err != nil {
app.ui.echoerrf("rename: %s", err)
return
if gSingleMode {
app.nav.renew()
app.ui.loadFile(app.nav, true)
} else {
if err := remote("send load"); err != nil {
app.ui.echoerrf("rename: %s", err)
return
}
}
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
@@ -562,9 +696,14 @@ func insert(app *app, arg string) {
app.ui.echoerrf("rename: %s", err)
return
}
if err := remote("send load"); err != nil {
app.ui.echoerrf("rename: %s", err)
return
if gSingleMode {
app.nav.renew()
app.ui.loadFile(app.nav, true)
} else {
if err := remote("send load"); err != nil {
app.ui.echoerrf("rename: %s", err)
return
}
}
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
@@ -572,17 +711,18 @@ func insert(app *app, arg string) {
case app.ui.cmdPrefix == "mark-save: ":
normal(app)
wd, err := os.Getwd()
if err != nil {
log.Printf("getting current directory: %s", err)
return
}
app.nav.marks[arg] = wd
app.nav.marks[arg] = app.nav.currDir().path
if err := app.nav.writeMarks(); err != nil {
app.ui.echoerrf("mark-save: %s", err)
}
if err := remote("send sync"); err != nil {
app.ui.echoerrf("mark-save: %s", err)
if gSingleMode {
if err := app.nav.sync(); err != nil {
app.ui.echoerrf("mark-save: %s", err)
}
} else {
if err := remote("send sync"); err != nil {
app.ui.echoerrf("mark-save: %s", err)
}
}
case app.ui.cmdPrefix == "mark-load: ":
normal(app)
@@ -597,6 +737,12 @@ func insert(app *app, arg string) {
app.ui.echoerr("mark-load: no such mark")
return
}
if wd != path {
resetIncCmd(app)
preChdir(app)
}
if err := app.nav.cd(path); err != nil {
app.ui.echoerrf("%s", err)
return
@@ -606,6 +752,7 @@ func insert(app *app, arg string) {
if wd != path {
app.nav.marks["'"] = wd
restartIncCmd(app)
onChdir(app)
}
case app.ui.cmdPrefix == "mark-remove: ":
@@ -618,8 +765,14 @@ func insert(app *app, arg string) {
app.ui.echoerrf("mark-remove: %s", err)
return
}
if err := remote("send sync"); err != nil {
app.ui.echoerrf("mark-remove: %s", err)
if gSingleMode {
if err := app.nav.sync(); err != nil {
app.ui.echoerrf("mark-remove: %s", err)
}
} else {
if err := remote("send sync"); err != nil {
app.ui.echoerrf("mark-remove: %s", err)
}
}
default:
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
@@ -629,57 +782,38 @@ func insert(app *app, arg string) {
func (e *callExpr) eval(app *app, args []string) {
switch e.name {
case "up":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
if app.nav.up(e.count) {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
case "half-up":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
if app.nav.up(e.count * app.nav.height / 2) {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
case "page-up":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
if app.nav.up(e.count * app.nav.height) {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
case "down":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
if app.nav.down(e.count) {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
case "half-down":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
if app.nav.down(e.count * app.nav.height / 2) {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
case "page-down":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
if app.nav.down(e.count * app.nav.height) {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
case "updir":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
resetIncCmd(app)
preChdir(app)
for i := 0; i < e.count; i++ {
if err := app.nav.updir(); err != nil {
app.ui.echoerrf("%s", err)
@@ -688,11 +822,9 @@ func (e *callExpr) eval(app *app, args []string) {
}
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
restartIncCmd(app)
onChdir(app)
case "open":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
curr, err := app.nav.currFile()
if err != nil {
app.ui.echoerrf("opening: %s", err)
@@ -700,6 +832,8 @@ func (e *callExpr) eval(app *app, args []string) {
}
if curr.IsDir() {
resetIncCmd(app)
preChdir(app)
err := app.nav.open()
if err != nil {
app.ui.echoerrf("opening directory: %s", err)
@@ -707,6 +841,7 @@ func (e *callExpr) eval(app *app, args []string) {
}
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
restartIncCmd(app)
onChdir(app)
return
}
@@ -742,17 +877,11 @@ func (e *callExpr) eval(app *app, args []string) {
case "quit":
app.quitChan <- struct{}{}
case "top":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
if app.nav.top() {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
case "bottom":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
if app.nav.bottom() {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
@@ -763,6 +892,7 @@ func (e *callExpr) eval(app *app, args []string) {
} else {
dir := app.nav.currDir()
for _, path := range e.args {
path = replaceTilde(path)
if !filepath.IsAbs(path) {
path = filepath.Join(dir.path, path)
}
@@ -783,9 +913,16 @@ func (e *callExpr) eval(app *app, args []string) {
return
}
app.nav.unselect()
if err := remote("send sync"); err != nil {
app.ui.echoerrf("copy: %s", err)
return
if gSingleMode {
if err := app.nav.sync(); err != nil {
app.ui.echoerrf("copy: %s", err)
return
}
} else {
if err := remote("send sync"); err != nil {
app.ui.echoerrf("copy: %s", err)
return
}
}
app.ui.loadFileInfo(app.nav)
case "cut":
@@ -794,9 +931,16 @@ func (e *callExpr) eval(app *app, args []string) {
return
}
app.nav.unselect()
if err := remote("send sync"); err != nil {
app.ui.echoerrf("cut: %s", err)
return
if gSingleMode {
if err := app.nav.sync(); err != nil {
app.ui.echoerrf("cut: %s", err)
return
}
} else {
if err := remote("send sync"); err != nil {
app.ui.echoerrf("cut: %s", err)
return
}
}
app.ui.loadFileInfo(app.nav)
case "paste":
@@ -812,9 +956,14 @@ func (e *callExpr) eval(app *app, args []string) {
if cmd, ok := gOpts.cmds["delete"]; ok {
cmd.eval(app, e.args)
app.nav.unselect()
if err := remote("send load"); err != nil {
app.ui.echoerrf("delete: %s", err)
return
if gSingleMode {
app.nav.renew()
app.ui.loadFile(app.nav, true)
} else {
if err := remote("send load"); err != nil {
app.ui.echoerrf("delete: %s", err)
return
}
}
} else {
list, err := app.nav.currFileOrSelections()
@@ -823,6 +972,10 @@ func (e *callExpr) eval(app *app, args []string) {
return
}
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
if len(list) == 1 {
app.ui.cmdPrefix = "delete '" + list[0] + "' ? [y/N] "
} else {
@@ -836,16 +989,26 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.echoerrf("clear: %s", err)
return
}
if err := remote("send sync"); err != nil {
app.ui.echoerrf("clear: %s", err)
return
if gSingleMode {
if err := app.nav.sync(); err != nil {
app.ui.echoerrf("clear: %s", err)
return
}
} else {
if err := remote("send sync"); err != nil {
app.ui.echoerrf("clear: %s", err)
return
}
}
app.ui.loadFileInfo(app.nav)
case "draw":
case "redraw":
app.ui.renew()
app.ui.screen.Sync()
app.nav.height = app.ui.wins[0].h
if app.nav.height != app.ui.wins[0].h {
app.nav.height = app.ui.wins[0].h
app.nav.regCache = make(map[string]*reg)
}
app.ui.loadFile(app.nav, true)
case "load":
app.nav.renew()
@@ -857,25 +1020,53 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
case "read":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = ":"
app.ui.loadFileInfo(app.nav)
case "shell":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "$"
app.ui.loadFileInfo(app.nav)
case "shell-pipe":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "%"
app.ui.loadFileInfo(app.nav)
case "shell-wait":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "!"
app.ui.loadFileInfo(app.nav)
case "shell-async":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "&"
app.ui.loadFileInfo(app.nav)
case "find":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "find: "
app.nav.findBack = false
app.ui.loadFileInfo(app.nav)
case "find-back":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "find-back: "
app.nav.findBack = true
app.ui.loadFileInfo(app.nav)
@@ -908,6 +1099,10 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFileInfo(app.nav)
}
case "search":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "/"
dir := app.nav.currDir()
app.nav.searchInd = dir.ind
@@ -915,6 +1110,10 @@ func (e *callExpr) eval(app *app, args []string) {
app.nav.searchBack = false
app.ui.loadFileInfo(app.nav)
case "search-back":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "?"
dir := app.nav.currDir()
app.nav.searchInd = dir.ind
@@ -957,20 +1156,58 @@ func (e *callExpr) eval(app *app, args []string) {
}
}
}
case "filter":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "filter: "
dir := app.nav.currDir()
app.nav.prevFilter = dir.filter
if len(e.args) == 0 {
app.ui.cmdAccLeft = []rune(strings.Join(dir.filter, " "))
} else {
app.ui.cmdAccLeft = []rune(strings.Join(e.args, " "))
}
app.ui.loadFileInfo(app.nav)
case "setfilter":
log.Printf("filter: %s", e.args)
if err := app.nav.setFilter(e.args); err != nil {
app.ui.echoerrf("filter: %s", err)
}
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
case "mark-save":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "mark-save: "
case "mark-load":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.menuBuf = listMarks(app.nav.marks)
app.ui.cmdPrefix = "mark-load: "
case "mark-remove":
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.menuBuf = listMarks(app.nav.marks)
app.ui.cmdPrefix = "mark-remove: "
case "rename":
if cmd, ok := gOpts.cmds["rename"]; ok {
cmd.eval(app, e.args)
if err := remote("send load"); err != nil {
app.ui.echoerrf("rename: %s", err)
return
if gSingleMode {
app.nav.renew()
app.ui.loadFile(app.nav, true)
} else {
if err := remote("send load"); err != nil {
app.ui.echoerrf("rename: %s", err)
return
}
}
} else {
curr, err := app.nav.currFile()
@@ -978,6 +1215,10 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.echoerrf("rename: %s:", err)
return
}
if app.ui.cmdPrefix == ">" {
return
}
normal(app)
app.ui.cmdPrefix = "rename: "
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(curr.Name())...)
}
@@ -1004,6 +1245,18 @@ func (e *callExpr) eval(app *app, args []string) {
log.Printf("getting current directory: %s", err)
}
path = replaceTilde(path)
if !filepath.IsAbs(path) {
path = filepath.Join(wd, path)
} else {
path = filepath.Clean(path)
}
if wd != path {
resetIncCmd(app)
preChdir(app)
}
if err := app.nav.cd(path); err != nil {
app.ui.echoerrf("%s", err)
return
@@ -1012,14 +1265,9 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
if !filepath.IsAbs(path) {
path = filepath.Join(wd, path)
} else {
path = filepath.Clean(path)
}
if wd != path {
app.nav.marks["'"] = wd
restartIncCmd(app)
onChdir(app)
}
case "select":
@@ -1033,6 +1281,18 @@ func (e *callExpr) eval(app *app, args []string) {
log.Printf("getting current directory: %s", err)
}
path := filepath.Dir(replaceTilde(e.args[0]))
if !filepath.IsAbs(path) {
path = filepath.Join(wd, path)
} else {
path = filepath.Clean(path)
}
if wd != path {
resetIncCmd(app)
preChdir(app)
}
if err := app.nav.sel(e.args[0]); err != nil {
app.ui.echoerrf("%s", err)
return
@@ -1041,15 +1301,9 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
path := filepath.Dir(e.args[0])
if !filepath.IsAbs(path) {
path = filepath.Join(wd, path)
} else {
path = filepath.Clean(path)
}
if wd != path {
app.nav.marks["'"] = wd
restartIncCmd(app)
onChdir(app)
}
case "glob-select":
@@ -1103,15 +1357,6 @@ func (e *callExpr) eval(app *app, args []string) {
if app.ui.cmdPrefix == ">" {
return
}
if gOpts.incsearch && (app.ui.cmdPrefix == "/" || app.ui.cmdPrefix == "?") {
dir := app.nav.currDir()
dir.pos = app.nav.searchPos
if dir.ind != app.nav.searchInd {
dir.ind = app.nav.searchInd
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
}
normal(app)
case "cmd-complete":
var matches []string
@@ -1228,7 +1473,7 @@ func (e *callExpr) eval(app *app, args []string) {
}
case "cmd-enter":
s := string(append(app.ui.cmdAccLeft, app.ui.cmdAccRight...))
if len(s) == 0 {
if len(s) == 0 && app.ui.cmdPrefix != "filter: " {
return
}
@@ -1305,6 +1550,14 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
case "filter: ":
log.Printf("filter: %s", s)
app.ui.cmdPrefix = ""
if err := app.nav.setFilter(strings.Split(s, " ")); err != nil {
app.ui.echoerrf("filter: %s", err)
}
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
case "find: ":
app.ui.cmdPrefix = ""
if moved, found := app.nav.findNext(); !found {
@@ -1334,7 +1587,7 @@ func (e *callExpr) eval(app *app, args []string) {
oldPath := filepath.Join(wd, curr.Name())
newPath := filepath.Clean(s)
newPath := filepath.Clean(replaceTilde(s))
if !filepath.IsAbs(newPath) {
newPath = filepath.Join(wd, newPath)
}
@@ -1368,9 +1621,14 @@ func (e *callExpr) eval(app *app, args []string) {
return
}
if err := remote("send load"); err != nil {
app.ui.echoerrf("rename: %s", err)
return
if gSingleMode {
app.nav.renew()
app.ui.loadFile(app.nav, true)
} else {
if err := remote("send load"); err != nil {
app.ui.echoerrf("rename: %s", err)
return
}
}
app.ui.loadFile(app.nav, true)
@@ -1396,12 +1654,9 @@ func (e *callExpr) eval(app *app, args []string) {
return
}
cmd := app.cmdHistory[len(app.cmdHistory)-app.cmdHistoryInd]
normal(app)
app.ui.cmdPrefix = cmd.prefix
app.ui.cmdAccLeft = []rune(cmd.value)
app.ui.cmdAccRight = nil
app.ui.cmdTmp = nil
app.ui.menuBuf = nil
app.ui.menuSelected = -2
case "cmd-history-prev":
if app.ui.cmdPrefix == ">" {
return
@@ -1414,12 +1669,9 @@ func (e *callExpr) eval(app *app, args []string) {
}
app.cmdHistoryInd++
cmd := app.cmdHistory[len(app.cmdHistory)-app.cmdHistoryInd]
normal(app)
app.ui.cmdPrefix = cmd.prefix
app.ui.cmdAccLeft = []rune(cmd.value)
app.ui.cmdAccRight = nil
app.ui.cmdTmp = nil
app.ui.menuBuf = nil
app.ui.menuSelected = -2
case "cmd-delete":
if len(app.ui.cmdAccRight) == 0 {
return
+1 -1
View File
@@ -218,7 +218,7 @@ var gEvalTests = []struct {
{
"cmap <c-g> cmd-escape",
[]string{"cmap", "<c-g>", "cmd-escape", "\n"},
[]expr{&cmapExpr{"<c-g>", "cmd-escape"}},
[]expr{&cmapExpr{"<c-g>", &callExpr{"cmd-escape", nil, 1}}},
},
{
+1
View File
@@ -32,6 +32,7 @@ lf \- terminal file manager
.OP \-remote command
.OP \-selection-path path
.OP \-server
.OP \-single
.OP \-version
.OP \-help
.RI [ directory ]
+1 -3
View File
@@ -3,10 +3,8 @@ module github.com/gokcehan/lf
go 1.12
require (
github.com/gdamore/tcell/v2 v2.2.0
github.com/gdamore/tcell/v2 v2.3.1
github.com/mattn/go-runewidth v0.0.10
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d
gopkg.in/djherbis/times.v1 v1.2.0
)
replace github.com/gdamore/tcell/v2 => github.com/gokcehan/tcell/v2 v2.2.1-0.20210329222449-4dd2d52e83ef
+2 -2
View File
@@ -1,7 +1,7 @@
github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
github.com/gokcehan/tcell/v2 v2.2.1-0.20210329222449-4dd2d52e83ef h1:I2KyR549rTlwGBHe2uwZHGNNeAIHUpwIs6V522yK+SE=
github.com/gokcehan/tcell/v2 v2.2.1-0.20210329222449-4dd2d52e83ef/go.mod h1:cTTuF84Dlj/RqmaCIV5p4w8uG1zWdk0SF6oBpwHp4fU=
github.com/gdamore/tcell/v2 v2.3.1 h1:htEXmKMzurgcnNH3VqQA7GYlCpdl9LCSNpzFpZOKhJE=
github.com/gdamore/tcell/v2 v2.3.1/go.mod h1:cTTuF84Dlj/RqmaCIV5p4w8uG1zWdk0SF6oBpwHp4fU=
github.com/lucasb-eyer/go-colorful v1.0.3 h1:QIbQXiugsb+q10B+MI+7DI1oQLdmnep86tWFlaaUAac=
github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-runewidth v0.0.10 h1:CoZ3S2P7pvtP45xOtBw+/mDL2z0RKI576gSkzRRpdGg=
+70 -38
View File
@@ -13,6 +13,7 @@ lf \- terminal file manager
.OP \-remote command
.OP \-selection-path path
.OP \-server
.OP \-single
.OP \-version
.OP \-help
.RI [ directory ]
@@ -76,6 +77,8 @@ The following commands are provided by lf:
search-back (modal) (default '?')
search-next (default 'n')
search-prev (default 'N')
filter (modal)
setfilter
mark-save (modal) (default 'm')
mark-load (modal) (default "'")
mark-remove (modal) (default `"`)
@@ -116,8 +119,11 @@ The following options can be used to customize the behavior of lf:
.PP
.EX
anchorfind bool (default on)
autoquit bool (default off)
dircache bool (default on)
dircounts bool (default off)
dirfirst bool (default on)
dironly bool (default off)
drawbox bool (default off)
errorfmt string (default "\e033[7;31;47m%s\e033[0m")
filesep string (default "\en")
@@ -129,6 +135,7 @@ The following options can be used to customize the behavior of lf:
ifs string (default '')
ignorecase bool (default on)
ignoredia bool (default on)
incfilter bool (default off)
incsearch bool (default off)
info []string (default '')
mouse bool (default off)
@@ -209,6 +216,13 @@ Configuration files should be located at:
windows C:\eProgramData\elf\elfrc C:\eUsers\e<user>\eAppData\eLocal\elf\elfrc
.EE
.PP
Selection file should be located at:
.PP
.EX
unix ~/.local/share/lf/files
windows C:\eUsers\e<user>\eAppData\eLocal\elf\efiles
.EE
.PP
Marks file should be located at:
.PP
.EX
@@ -446,7 +460,7 @@ Read a shell command to execute and wait for a key press in the end.
shell-async (modal) (default '&')
.EE
.PP
Read a shell command to execute synchronously without standard I/O.
Read a shell command to execute asynchronously without standard I/O.
.PP
.EX
find (modal) (default 'f')
@@ -470,6 +484,15 @@ Read a pattern to search for a file name match in the forward/backward direction
.PP
(See also 'globsearch', 'incsearch', 'wrapscan', 'ignorecase', 'smartcase', 'ignoredia', and 'smartdia' options and 'Searching Files' section)
.PP
.EX
filter (modal)
setfilter
.EE
.PP
Read a pattern to filter out and only view files matching the pattern. setfilter does the same but uses an argument to set the filter immediatly. You can supply an argument to filter, in order to use that as the starting prompt.
.PP
(See also 'globsearch', 'incfilter', 'ignorecase', 'smartcase', 'ignoredia', and 'smartdia' options)
.PP
.EX
mark-save (modal) (default 'm')
.EE
@@ -609,6 +632,18 @@ This section shows information about options to customize the behavior. Characte
.PP
When this option is enabled, find command starts matching patterns from the beginning of file names, otherwise, it can match at an arbitrary position.
.PP
.EX
autoquit bool (default off)
.EE
.PP
Automatically quit server when there are no clients left connected.
.PP
.EX
dircache bool (default on)
.EE
.PP
Cache directory contents.
.PP
.EX
dircounts bool (default off)
.EE
@@ -621,6 +656,12 @@ When this option is enabled, directory sizes show the number of items inside ins
.PP
Show directories first above regular files.
.PP
.EX
dironly bool (default off)
.EE
.PP
Show only directories.
.PP
.EX
drawbox bool (default off)
.EE
@@ -693,6 +734,12 @@ Ignore diacritics in sorting and search patterns.
.PP
Jump to the first match after each keystroke during searching.
.PP
.EX
incfilter bool (default off)
.EE
.PP
Apply filter pattern after each keystroke during filtering.
.PP
.EX
info []string (default '')
.EE
@@ -739,7 +786,7 @@ Set the path of a cleaner file. This file will be called if previewing is enable
promptfmt string (default "\e033[32;1m%u@%h\e033[0m:\e033[34;1m%d\e033[0m\e033[1m%f\e033[0m")
.EE
.PP
Format string of the prompt shown in the top line. Special expansions are provided, '%u' as the user name, '%h' as the host name, '%w' as the working directory, '%d' as the working directory with a trailing path separator, and '%f' as the file name. Home folder is shown as '~' in the working directory expansion. Directory names are automatically shortened to a single character starting from the left most parent when the prompt does not fit to the screen.
Format string of the prompt shown in the top line. Special expansions are provided, '%u' as the user name, '%h' as the host name, '%w' as the working directory, '%d' as the working directory with a trailing path separator, '%f' as the file name, and '%F' as the current filter. Home folder is shown as '~' in the working directory expansion. Directory names are automatically shortened to a single character starting from the left most parent when the prompt does not fit to the screen.
.PP
.EX
ratios []int (default '1:2:3')
@@ -943,7 +990,7 @@ Command 'map' is used to bind a key to a command which can be builtin command, c
map gh cd ~ # builtin command
map D trash # custom command
map i $less $f # shell command
map U !du -sh # waiting shell command
map U !du -csh * # waiting shell command
.EE
.PP
Command 'cmap' is used to bind a key to a command line command which can only be one of the builtin commands:
@@ -1170,10 +1217,10 @@ Since such a client may not be available everywhere, lf comes bundled with a com
In this command 'send' is used to send the rest of the string as a command to all connected clients. You can optionally give it an id number to send a command to a single client:
.PP
.EX
lf -remote 'send 1000 echo hello world'
lf -remote 'send 1234 echo hello world'
.EE
.PP
All clients have a unique id number but you may not be aware of the id number when you are writing a command. For this purpose, an '$id' variable is exported to the environment for shell commands. You can use it to send a remote command from a client to the server which in return sends a command back to itself. So now you can display a message in the current client by calling the following in a shell command:
All clients have a unique id number but you may not be aware of the id number when you are writing a command. For this purpose, an '$id' variable is exported to the environment for shell commands. The value of this variable is set to the process id of the client. You can use it to send a remote command from a client to the server which in return sends a command back to itself. So now you can display a message in the current client by calling the following in a shell command:
.PP
.EX
lf -remote "send $id echo hello world"
@@ -1194,52 +1241,34 @@ Since lf does not have control flow syntax, remote commands are used for such ne
}}
.EE
.PP
Besides 'send' command, there are also two commands to get or set the current file selection. Two possible modes 'copy' and 'move' specify whether selected files are to be copied or moved. File names are separated by newline character. Setting the file selection is done with 'save' command:
.PP
.EX
lf -remote "$(printf 'save\encopy\enfoo.txt\enbar.txt\enbaz.txt\en')"
.EE
.PP
Getting the file selection is similarly done with 'load' command:
.PP
.EX
load=$(lf -remote 'load')
mode=$(echo "$load" | sed -n '1p')
list=$(echo "$load" | sed '1d')
if [ $mode = 'copy' ]; then
# do something with $list
elif [ $mode = 'move' ]; then
# do something else with $list
fi
.EE
.PP
There is a 'quit' command to close client connections and quit the server:
Besides 'send' command, there is a 'quit' command to quit the server when there are no connected clients left, and a 'quit!' command to force quit the server by closing client connections first:
.PP
.EX
lf -remote 'quit'
lf -remote 'quit!'
.EE
.PP
Lastly, there is a 'conn' command to connect the server as a client. This should not be needed for users.
.SH FILE OPERATIONS
lf uses its own builtin copy and move operations by default. These are implemented as asynchronous operations and progress is shown in the bottom ruler. These commands do not overwrite existing files or directories with the same name. Instead, a suffix that is compatible with '--backup=numbered' option in GNU cp is added to the new files or directories. Only file modes are preserved and all other attributes are ignored including ownership, timestamps, context, and xattr. Special files such as character and block devices, named pipes, and sockets are skipped and links are not followed. Moving is performed using the rename operation of the underlying OS. For cross-device moving, lf falls back to copying and then deletes the original files if there are no errors. Operation errors are shown in the message line as well as the log file and they do not preemptively finish the corresponding file operation.
.PP
File operations can be performed on the current selected file or alternatively on multiple files by selecting them first. When you 'copy' a file, lf doesn't actually copy the file on the disk, but only records its name to memory. The actual file copying takes place when you 'paste'. Similarly 'paste' after a 'cut' operation moves the file.
File operations can be performed on the current selected file or alternatively on multiple files by selecting them first. When you 'copy' a file, lf doesn't actually copy the file on the disk, but only records its name to a file. The actual file copying takes place when you 'paste'. Similarly 'paste' after a 'cut' operation moves the file.
.PP
You can customize copy and move operations by defining a 'paste' command. This is a special command that is called when it is defined instead of the builtin implementation. You can use the following example as a starting point:
.PP
.EX
cmd paste %{{
load=$(lf -remote 'load')
mode=$(echo "$load" | sed -n '1p')
list=$(echo "$load" | sed '1d')
if [ $mode = 'copy' ]; then
cp -R $list .
elif [ $mode = 'move' ]; then
mv $list .
fi
lf -remote 'send load'
lf -remote 'send clear'
}}
cmd paste %{{
load=$(cat ~/.local/share/lf/files)
mode=$(echo "$load" | sed -n '1p')
list=$(echo "$load" | sed '1d')
if [ $mode = 'copy' ]; then
cp -R $list .
elif [ $mode = 'move' ]; then
mv $list .
fi
rm ~/.local/share/lf/files
lf -remote 'send clear'
}}
.EE
.PP
Some useful things to be considered are to use the backup ('--backup') and/or preserve attributes ('-a') options with 'cp' and 'mv' commands if they support it (i.e. GNU implementation), change the command type to asynchronous, or use 'rsync' command with progress bar option for copying and feed the progress to the client periodically with remote 'echo' calls.
@@ -1277,6 +1306,7 @@ You may want to use either file extensions or mime types from 'file' command:
.PP
.EX
cmd open ${{
test -L $f && f=$(readlink -f $f)
case $(file --mime-type $f -b) in
text/*) vi $fx;;
*) for f in $fx; do xdg-open $f > /dev/null 2> /dev/null & done;;
@@ -1369,6 +1399,8 @@ This command runs whenever you change directory but not on startup. You can add
.EE
.PP
Note that all shell commands are possible but `%` and `&` are usually more appropriate as `$` and `!` causes flickers and pauses respectively.
.PP
There is also a 'pre-cd' command, that works like 'on-cd', but is run before the directory is actually changed. It is generally a bad idea, to put movement commands (like 'up' / 'top' etc.) here.
.SH COLORS
lf tries to automatically adapt its colors to the environment. It starts with a default colorscheme and updates colors using values of existing environment variables possibly by overwriting its previous values. Colors are set in the following order:
.PP
+11 -1
View File
@@ -22,6 +22,7 @@ var (
type arrayFlag []string
var (
gSingleMode bool
gClientID int
gHostname string
gLastDirPath string
@@ -199,6 +200,11 @@ func main() {
false,
"start server (automatic)")
singleMode := flag.Bool(
"single",
false,
"start a client without server")
remoteCmd := flag.String(
"remote",
"",
@@ -263,7 +269,11 @@ func main() {
gServerLogPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.server.log", gUser.Username))
serve()
default:
checkServer()
gSingleMode = *singleMode
if !gSingleMode {
checkServer()
}
gClientID = os.Getpid()
gLogPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.%d.log", gUser.Username, gClientID))
+164 -40
View File
@@ -113,7 +113,9 @@ type dir struct {
files []*file // displayed files in directory including or excluding hidden ones
allFiles []*file // all files in directory including hidden ones (same array as files)
sortType sortType // sort method and options from last sort
dironly bool // dironly value from last sort
hiddenfiles []string // hiddenfiles value from last sort
filter []string // last filter for this directory
ignorecase bool // ignorecase value from last sort
ignoredia bool // ignoredia value from last sort
noPerm bool // whether lf has no permission to open the directory
@@ -150,6 +152,7 @@ func normalize(s1, s2 string, ignorecase, ignoredia bool) (string, string) {
func (dir *dir) sort() {
dir.sortType = gOpts.sortType
dir.dironly = gOpts.dironly
dir.hiddenfiles = gOpts.hiddenfiles
dir.ignorecase = gOpts.ignorecase
dir.ignoredia = gOpts.ignoredia
@@ -219,6 +222,26 @@ func (dir *dir) sort() {
})
}
// when dironly option is enabled, we move files to the beginning of our file
// list and then set the beginning of displayed files to the first directory
// in the list
if dir.dironly {
sort.SliceStable(dir.files, func(i, j int) bool {
if !dir.files[i].IsDir() && !dir.files[j].IsDir() {
return i < j
}
return !dir.files[i].IsDir()
})
dir.files = func() []*file {
for i, f := range dir.files {
if f.IsDir() {
return dir.files[i:]
}
}
return dir.files[len(dir.files):]
}()
}
// when hidden option is disabled, we move hidden files to the
// beginning of our file list and then set the beginning of displayed
// files to the first non-hidden file in the list
@@ -232,17 +255,41 @@ func (dir *dir) sort() {
for i, f := range dir.files {
if !isHidden(f, dir.path, dir.hiddenfiles) {
dir.files = dir.files[i:]
return
break
}
}
dir.files = dir.files[len(dir.files):]
if len(dir.files) > 0 && isHidden(dir.files[len(dir.files)-1], dir.path, dir.hiddenfiles) {
dir.files = dir.files[len(dir.files):]
}
}
if len(dir.filter) != 0 {
sort.SliceStable(dir.files, func(i, j int) bool {
if isFiltered(dir.files[i], dir.filter) && isFiltered(dir.files[j], dir.filter) {
return i < j
}
return isFiltered(dir.files[i], dir.filter)
})
for i, f := range dir.files {
if !isFiltered(f, dir.filter) {
dir.files = dir.files[i:]
break
}
}
if len(dir.files) > 0 && isFiltered(dir.files[len(dir.files)-1], dir.filter) {
dir.files = dir.files[len(dir.files):]
}
}
dir.ind = max(dir.ind, 0)
dir.ind = min(dir.ind, len(dir.files)-1)
}
func (dir *dir) name() string {
if len(dir.files) == 0 {
return ""
}
return dir.files[dir.ind].Name()
}
@@ -303,36 +350,46 @@ type nav struct {
searchBack bool
searchInd int
searchPos int
prevFilter []string
volatilePreview bool
}
func (nav *nav) loadDir(path string) *dir {
d, ok := nav.dirCache[path]
if !ok {
d := &dir{
loading: true,
loadTime: time.Now(),
path: path,
sortType: gOpts.sortType,
hiddenfiles: gOpts.hiddenfiles,
ignorecase: gOpts.ignorecase,
ignoredia: gOpts.ignoredia,
}
nav.dirCache[path] = d
go func() {
d := newDir(path)
d.sort()
d.ind, d.pos = 0, 0
nav.dirChan <- d
}()
return d
func (nav *nav) loadDirInternal(path string) *dir {
d := &dir{
loading: true,
loadTime: time.Now(),
path: path,
sortType: gOpts.sortType,
hiddenfiles: gOpts.hiddenfiles,
ignorecase: gOpts.ignorecase,
ignoredia: gOpts.ignoredia,
}
nav.checkDir(d)
go func() {
d := newDir(path)
d.sort()
d.ind, d.pos = 0, 0
nav.dirChan <- d
}()
return d
}
func (nav *nav) loadDir(path string) *dir {
if gOpts.dircache {
d, ok := nav.dirCache[path]
if !ok {
d = nav.loadDirInternal(path)
nav.dirCache[path] = d
return d
}
nav.checkDir(d)
return d
} else {
return nav.loadDirInternal(path)
}
}
func (nav *nav) checkDir(dir *dir) {
s, err := os.Stat(dir.path)
if err != nil {
@@ -354,10 +411,12 @@ func (nav *nav) checkDir(dir *dir) {
dir.loadTime = now
go func() {
nd := newDir(dir.path)
nd.filter = dir.filter
nd.sort()
nav.dirChan <- nd
}()
case dir.sortType != gOpts.sortType ||
dir.dironly != gOpts.dironly ||
!reflect.DeepEqual(dir.hiddenfiles, gOpts.hiddenfiles) ||
dir.ignorecase != gOpts.ignorecase ||
dir.ignoredia != gOpts.ignoredia:
@@ -597,6 +656,27 @@ func (nav *nav) sort() {
}
}
func (nav *nav) setFilter(filter []string) error {
newfilter := []string{}
for _, tok := range filter {
_, err := filepath.Match(tok, "a")
if err != nil {
return err
}
if tok != "" {
newfilter = append(newfilter, tok)
}
}
dir := nav.currDir()
dir.filter = newfilter
// Apply filter, by sorting current dir (see nav.sort())
name := dir.name()
dir.sort()
dir.sel(name, nav.height)
return nil
}
func (nav *nav) up(dist int) bool {
dir := nav.currDir()
@@ -797,10 +877,15 @@ loop:
nav.copyTotalChan <- -total
if err := remote("send load"); err != nil {
errCount++
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
ui.exprChan <- echo
if gSingleMode {
nav.renew()
ui.loadFile(nav, true)
} else {
if err := remote("send load"); err != nil {
errCount++
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
ui.exprChan <- echo
}
}
if errCount == 0 {
@@ -897,10 +982,15 @@ func (nav *nav) moveAsync(ui *ui, srcs []string, dstDir string) {
nav.moveTotalChan <- -len(srcs)
if err := remote("send load"); err != nil {
errCount++
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
ui.exprChan <- echo
if gSingleMode {
nav.renew()
ui.loadFile(nav, true)
} else {
if err := remote("send load"); err != nil {
errCount++
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
ui.exprChan <- echo
}
}
if errCount == 0 {
@@ -930,8 +1020,14 @@ func (nav *nav) paste(ui *ui) error {
return fmt.Errorf("clearing copy/cut buffer: %s", err)
}
if err := remote("send sync"); err != nil {
return fmt.Errorf("paste: %s", err)
if gSingleMode {
if err := nav.sync(); err != nil {
return fmt.Errorf("paste: %s", err)
}
} else {
if err := remote("send sync"); err != nil {
return fmt.Errorf("paste: %s", err)
}
}
return nil
@@ -961,10 +1057,15 @@ func (nav *nav) del(ui *ui) error {
nav.deleteTotalChan <- -len(list)
if err := remote("send load"); err != nil {
errCount++
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
ui.exprChan <- echo
if gSingleMode {
nav.renew()
ui.loadFile(nav, true)
} else {
if err := remote("send load"); err != nil {
errCount++
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
ui.exprChan <- echo
}
}
}()
@@ -1006,7 +1107,13 @@ func (nav *nav) sync() error {
nav.saves[f] = cp
}
return nav.readMarks()
path, ok := nav.marks["'"]
err = nav.readMarks()
if ok {
nav.marks["'"] = path
}
return err
}
func (nav *nav) cd(wd string) error {
@@ -1220,6 +1327,22 @@ func (nav *nav) searchPrev() (bool, error) {
return false, nil
}
func isFiltered(f os.FileInfo, filter []string) bool {
for _, pattern := range filter {
matched, err := searchMatch(f.Name(), strings.TrimPrefix(pattern, "!"))
if err != nil {
log.Printf("Filter Error: %s", err)
return false
}
if strings.HasPrefix(pattern, "!") && matched {
return true
} else if !strings.HasPrefix(pattern, "!") && !matched {
return true
}
}
return false
}
func (nav *nav) removeMark(mark string) error {
if _, ok := nav.marks[mark]; ok {
delete(nav.marks, mark)
@@ -1291,6 +1414,7 @@ func (nav *nav) currFile() (*file, error) {
if len(dir.files) == 0 {
return nil, fmt.Errorf("empty directory")
}
return dir.files[dir.ind], nil
}
+8
View File
@@ -29,12 +29,16 @@ type sortType struct {
var gOpts struct {
anchorfind bool
autoquit bool
dircache bool
dircounts bool
dironly bool
drawbox bool
globsearch bool
icons bool
ignorecase bool
ignoredia bool
incfilter bool
incsearch bool
mouse bool
number bool
@@ -71,12 +75,16 @@ var gOpts struct {
func init() {
gOpts.anchorfind = true
gOpts.autoquit = false
gOpts.dircache = true
gOpts.dircounts = false
gOpts.dironly = false
gOpts.drawbox = false
gOpts.globsearch = false
gOpts.icons = false
gOpts.ignorecase = true
gOpts.ignoredia = true
gOpts.incfilter = false
gOpts.incsearch = false
gOpts.mouse = false
gOpts.number = false
+2
View File
@@ -31,6 +31,7 @@ var (
var (
gUser *user.User
gConfigPaths []string
gFilesPath string
gMarksPath string
gHistoryPath string
)
@@ -83,6 +84,7 @@ func init() {
data = filepath.Join(gUser.HomeDir, ".local", "share")
}
gFilesPath = filepath.Join(data, "lf", "files")
gMarksPath = filepath.Join(data, "lf", "marks")
gHistoryPath = filepath.Join(data, "lf", "history")
+2
View File
@@ -30,6 +30,7 @@ var (
var (
gUser *user.User
gConfigPaths []string
gFilesPath string
gMarksPath string
gHistoryPath string
)
@@ -67,6 +68,7 @@ func init() {
filepath.Join(data, "lf", "lfrc"),
}
gFilesPath = filepath.Join(data, "lf", "files")
gMarksPath = filepath.Join(data, "lf", "marks")
gHistoryPath = filepath.Join(data, "lf", "history")
}
+8 -12
View File
@@ -14,7 +14,7 @@ package main
//
// MapExpr = 'map' <keys> Expr
//
// CMapExpr = 'cmap' <key> <cmd> ';'
// CMapExpr = 'cmap' <key> Expr
//
// CmdExpr = 'cmd' <name> Expr
//
@@ -58,11 +58,11 @@ type mapExpr struct {
func (e *mapExpr) String() string { return fmt.Sprintf("map %s %s", e.keys, e.expr) }
type cmapExpr struct {
key string
cmd string
key string
expr expr
}
func (e *cmapExpr) String() string { return fmt.Sprintf("cmap %s %s", e.key, e.cmd) }
func (e *cmapExpr) String() string { return fmt.Sprintf("cmap %s %s", e.key, e.expr) }
type cmdExpr struct {
name string
@@ -191,23 +191,19 @@ func (p *parser) parseExpr() expr {
result = &mapExpr{keys, expr}
case "cmap":
var cmd string
var expr expr
s.scan()
key := s.tok
s.scan()
if s.typ != tokenSemicolon {
if s.typ != tokenIdent {
p.err = fmt.Errorf("expected command: %s", s.tok)
}
cmd = s.tok
expr = p.parseExpr()
} else {
s.scan()
}
s.scan()
result = &cmapExpr{key, cmd}
result = &cmapExpr{key, expr}
case "cmd":
var expr expr
+35 -33
View File
@@ -10,8 +10,6 @@ import (
)
var (
gCopyFile bool
gFileList []string
gConnList = make(map[int]net.Conn)
gQuitChan = make(chan struct{}, 1)
gListener net.Listener
@@ -55,6 +53,15 @@ func listen(l net.Listener) {
}
}
func echoerr(c net.Conn, msg string) {
fmt.Fprintln(c, msg)
log.Printf(msg)
}
func echoerrf(c net.Conn, format string, a ...interface{}) {
echoerr(c, fmt.Sprintf(format, a...))
}
func handleConn(c net.Conn) {
s := bufio.NewScanner(c)
@@ -63,42 +70,29 @@ Loop:
log.Printf("listen: %s", s.Text())
word, rest := splitWord(s.Text())
switch word {
case "save":
s.Scan()
switch s.Text() {
case "copy":
gCopyFile = true
case "move":
gCopyFile = false
default:
log.Printf("unexpected option to copy file(s): %s", s.Text())
break Loop
}
gFileList = nil
for s.Scan() && s.Text() != "" {
gFileList = append(gFileList, s.Text())
}
case "load":
if gCopyFile {
fmt.Fprintln(c, "copy")
} else {
fmt.Fprintln(c, "move")
}
for _, f := range gFileList {
fmt.Fprintln(c, f)
}
fmt.Fprintln(c)
case "conn":
if rest != "" {
word2, _ := splitWord(rest)
id, err := strconv.Atoi(word2)
if err != nil {
log.Print("listen: conn: client id should be a number")
echoerr(c, "listen: conn: client id should be a number")
} else {
gConnList[id] = c
}
} else {
log.Print("listen: conn: requires a client id")
echoerr(c, "listen: conn: requires a client id")
}
case "drop":
if rest != "" {
word2, _ := splitWord(rest)
id, err := strconv.Atoi(word2)
if err != nil {
echoerr(c, "listen: drop: client id should be a number")
} else {
delete(gConnList, id)
}
} else {
echoerr(c, "listen: drop: requires a client id")
}
case "send":
if rest != "" {
@@ -109,12 +103,20 @@ Loop:
fmt.Fprintln(c, rest)
}
} else {
if c, ok := gConnList[id]; ok {
fmt.Fprintln(c, rest2)
if c2, ok := gConnList[id]; ok {
fmt.Fprintln(c2, rest2)
} else {
echoerr(c, "listen: send: no such client id is connected")
}
}
}
case "quit":
if len(gConnList) == 0 {
gQuitChan <- struct{}{}
gListener.Close()
break Loop
}
case "quit!":
gQuitChan <- struct{}{}
for _, c := range gConnList {
fmt.Fprintln(c, "echo server is quitting...")
@@ -123,12 +125,12 @@ Loop:
gListener.Close()
break Loop
default:
log.Printf("listen: unexpected command: %s", word)
echoerrf(c, "listen: unexpected command: %s", word)
}
}
if s.Err() != nil {
log.Printf("listening: %s", s.Err())
echoerrf(c, "listening: %s", s.Err())
}
c.Close()
+44 -16
View File
@@ -171,7 +171,7 @@ func printLength(s string) int {
r, w := utf8.DecodeRuneInString(s[i:])
if r == gEscapeCode && i+1 < len(s) && s[i+1] == '[' {
j := strings.IndexByte(s[i:min(len(s), i+32)], 'm')
j := strings.IndexAny(s[i:min(len(s), i+64)], "mK")
if j == -1 {
continue
}
@@ -199,12 +199,13 @@ func (win *win) print(screen tcell.Screen, x, y int, st tcell.Style, s string) t
r, w := utf8.DecodeRuneInString(s[i:])
if r == gEscapeCode && i+1 < len(s) && s[i+1] == '[' {
j := strings.IndexByte(s[i:min(len(s), i+32)], 'm')
j := strings.IndexAny(s[i:min(len(s), i+64)], "mK")
if j == -1 {
continue
}
st = applyAnsiCodes(s[i+2:i+j], st)
if s[i+j] == 'm' {
st = applyAnsiCodes(s[i+2:i+j], st)
}
i += j
continue
@@ -464,6 +465,7 @@ func (win *win) printDir(screen tcell.Screen, dir *dir, selections map[string]in
type ui struct {
screen tcell.Screen
polling bool
wins []*win
promptWin *win
msgWin *win
@@ -499,7 +501,7 @@ func getWidths(wtot int) []int {
wsum := 0
for i := 0; i < wlen-1; i++ {
widths[i] = gOpts.ratios[i] * (wtot / rsum)
widths[i] = gOpts.ratios[i] * wtot / rsum
wsum += widths[i]
}
widths[wlen-1] = wtot - wsum
@@ -537,6 +539,7 @@ func newUI(screen tcell.Screen) *ui {
ui := &ui{
screen: screen,
polling: true,
wins: getWins(screen),
promptWin: newWin(wtot, 1, 0, 0),
msgWin: newWin(wtot, 1, 0, htot-1),
@@ -560,6 +563,7 @@ func (ui *ui) pollEvents() {
for {
ev = ui.screen.PollEvent()
if ev == nil {
ui.polling = false
return
}
ui.tevChan <- ev
@@ -675,7 +679,8 @@ func (ui *ui) loadFileInfo(nav *nav) {
func (ui *ui) drawPromptLine(nav *nav) {
st := tcell.StyleDefault
pwd := nav.currDir().path
dir := nav.currDir()
pwd := dir.path
if strings.HasPrefix(pwd, gUser.HomeDir) {
pwd = filepath.Join("~", strings.TrimPrefix(pwd, gUser.HomeDir))
@@ -716,6 +721,12 @@ func (ui *ui) drawPromptLine(nav *nav) {
}
prompt = strings.Replace(prompt, "%d", pwd, -1)
if len(dir.filter) != 0 {
prompt = strings.Replace(prompt, "%F", fmt.Sprint(dir.filter), -1)
} else {
prompt = strings.Replace(prompt, "%F", "", -1)
}
ui.promptWin.print(ui.screen, 0, 0, st, prompt)
}
@@ -754,6 +765,10 @@ func (ui *ui) drawStatLine(nav *nav) {
selection += fmt.Sprintf(" \033[35;7m %d \033[0m", len(nav.selections))
}
if len(dir.filter) != 0 {
selection += " \033[34;7m F \033[0m"
}
var progress string
if nav.copyTotal > 0 {
@@ -835,16 +850,24 @@ func (ui *ui) draw(nav *nav) {
ui.drawStatLine(nav)
ui.screen.HideCursor()
case ">":
ui.msgWin.printLine(ui.screen, 0, 0, st, ui.cmdPrefix)
ui.msgWin.print(ui.screen, len(ui.cmdPrefix), 0, st, ui.msg)
ui.msgWin.print(ui.screen, len(ui.cmdPrefix)+len(ui.msg), 0, st, string(ui.cmdAccLeft))
ui.msgWin.print(ui.screen, len(ui.cmdPrefix)+len(ui.msg)+runeSliceWidth(ui.cmdAccLeft), 0, st, string(ui.cmdAccRight))
ui.screen.ShowCursor(ui.msgWin.x+len(ui.cmdPrefix)+len(ui.msg)+runeSliceWidth(ui.cmdAccLeft), ui.msgWin.y)
prefix := ui.cmdPrefix[:min(ui.msgWin.w-1, len(ui.cmdPrefix))]
pos := min(runeSliceWidth(ui.cmdAccLeft), ui.msgWin.w-len(prefix)-1)
left := ui.cmdAccLeft[runeSliceWidth(ui.cmdAccLeft)-pos:]
right := ui.cmdAccRight
ui.msgWin.printLine(ui.screen, 0, 0, st, prefix)
ui.msgWin.print(ui.screen, len(prefix), 0, st, ui.msg)
ui.msgWin.print(ui.screen, len(prefix)+printLength(ui.msg), 0, st, string(left))
ui.msgWin.print(ui.screen, len(prefix)+printLength(ui.msg)+runeSliceWidth(left), 0, st, string(right))
ui.screen.ShowCursor(ui.msgWin.x+len(prefix)+printLength(ui.msg)+runeSliceWidth(left), ui.msgWin.y)
default:
ui.msgWin.printLine(ui.screen, 0, 0, st, ui.cmdPrefix)
ui.msgWin.print(ui.screen, len(ui.cmdPrefix), 0, st, string(ui.cmdAccLeft))
ui.msgWin.print(ui.screen, len(ui.cmdPrefix)+runeSliceWidth(ui.cmdAccLeft), 0, st, string(ui.cmdAccRight))
ui.screen.ShowCursor(ui.msgWin.x+len(ui.cmdPrefix)+runeSliceWidth(ui.cmdAccLeft), ui.msgWin.y)
prefix := ui.cmdPrefix[:min(ui.msgWin.w-1, len(ui.cmdPrefix))]
pos := min(runeSliceWidth(ui.cmdAccLeft), ui.msgWin.w-len(prefix)-1)
left := ui.cmdAccLeft[runeSliceWidth(ui.cmdAccLeft)-pos:]
right := ui.cmdAccRight
ui.msgWin.printLine(ui.screen, 0, 0, st, prefix)
ui.msgWin.print(ui.screen, len(prefix), 0, st, string(left))
ui.msgWin.print(ui.screen, len(prefix)+runeSliceWidth(left), 0, st, string(right))
ui.screen.ShowCursor(ui.msgWin.x+len(prefix)+runeSliceWidth(left), ui.msgWin.y)
}
if gOpts.preview {
@@ -1149,7 +1172,12 @@ func (ui *ui) suspend() error {
}
func (ui *ui) resume() error {
return ui.screen.Resume()
err := ui.screen.Resume()
if !ui.polling {
go ui.pollEvents()
ui.polling = true
}
return err
}
func anyKey() {