Compare commits

31 Commits
Author SHA1 Message Date
Gokcehan 228a20ffd1 rename bs to backspace 2020-10-10 17:34:29 +03:00
Gokcehan 8979e2b260 update cross build script 2020-10-10 16:53:52 +03:00
Gokcehan 6a286673ce initialize hiddenfiles for loading directories
Related #478
2020-10-06 22:24:55 +03:00
Gokcehan 4c89535e18 add descriptions of variables to the documentation 2020-10-02 23:37:39 +03:00
Gokcehan 88749a3da1 check hiddenfiles option for dir updates
Related #476
2020-10-02 21:50:55 +03:00
Alexey Yerin cf79726d21 feat: add ability to map lone <esc> (#475)
Since d2414f7580 <esc> resets key buffer
but this feature prevents binding lone <esc>
2020-10-02 21:30:31 +03:00
Gokcehan 50dd374f77 fix race in previews with lazy drawing
Related #445
2020-09-25 23:08:29 +03:00
Gokcehan 1460f49b3e update readme 2020-09-24 23:38:09 +03:00
Gokcehan 969dee3621 add descriptions of options to the documentation
Related #321
2020-09-24 02:00:36 +03:00
Gokcehan 36798b4c24 update doc
Related #469
2020-09-22 04:22:08 +03:00
gotroyb127 7a3bd15903 always export lf_options before previewing (#468)
* always export lf_options before previewing

related functions were moved to `os.go`
and now exportOpts isn't called through
an app, so it can be called independently

* move related functions to main.go

so they get compiled on windows too
2020-09-18 00:50:45 +03:00
Gokcehan 76c85d9459 add descriptions of cmds to the documentation
Related #321
2020-09-13 18:14:25 +03:00
Gokcehan 355075cf75 cleanup 2020-09-13 14:55:17 +03:00
Himujjal Upadhyaya 1186bf6382 [Minor Fix]: Doc update for Windows Users (#465)
A minor change was fixed in `doc.go:142` for Windows Users. Clear instructions for using `$f`, `$fs`, `$fx` and `$id` in Windows as `%f%`, `%fs%`, `%fx%` and `%id%`.
2020-09-10 19:17:09 +03:00
Provessor 61442f8880 A more robust server starting mechanism (#463)
now lf will start the server in the current directory (which will then
Chdir to the user's home directory) to ensure it is always starting as
the user intended.
2020-09-09 14:08:52 +03:00
Gokcehan ec512dfe31 read events in the main loop
Related #445
2020-09-07 18:40:57 +03:00
gotroyb127 f248ce77a1 fixes 'numbers are bold when the filename is bold' (#462)
* fixes 'numbers are bold when the filename is bold'

* do it correctly
2020-09-06 17:52:11 +03:00
Gokcehan 3c8b5a5630 avoid overwriting messages after shell commands
Related #441
2020-09-05 17:41:17 +03:00
Gokcehan b608682580 load modified previews after shell-pipe commands 2020-09-05 14:09:52 +03:00
Gokcehan ab6549679b rename backspace/backspace2 to bs/bs2 again
Related #445
2020-09-05 12:56:12 +03:00
Gokcehan 5e9580500c show loading directories with previous file list
Related #414
2020-09-05 12:55:27 +03:00
Gokcehan ebf3bcc76b resume with a new goroutine instead of busy wait
Related #461
2020-09-05 12:36:31 +03:00
Gokcehan f1f28018a6 add missing keys for push command
Related #445
2020-09-04 23:59:20 +03:00
Gokcehan b40ebdcb33 fix regular keys in push commands
Related #445
2020-09-04 21:25:19 +03:00
Gokcehan 4f5b4e6dbf remove manual escape delaying mechanism
Related #459
2020-09-04 18:25:40 +03:00
Gokcehan 4f02cf47c7 use the same input goroutine when ui is resumed
Related #459
2020-09-04 18:07:50 +03:00
Gokcehan eab7b61846 only listen 127.0.0.1 in the server
Related #456
2020-09-02 00:43:55 +03:00
Gokcehan 658af50006 do not crash with corrupted history entries
Related #455
2020-09-01 23:57:40 +03:00
Gokcehan bc0000f274 go mod tidy
Related #439
2020-09-01 23:10:16 +03:00
Provessor 24f01f4988 Replace termbox-go with tcell (#439)
Fix colour construction issue

This also has a test to mitigate it in the future

Remove `colormode` option

The original issue it was trying to solve is no longer present with
tcell (it being a holdover from `color256` on termbox) so it is not
needed.

retire gitter channel in favor of irc/matrix

Export options as environment variables (#448)

* Export options as environment variables

Any options from gOpts are available via lf_OPTION environment
variables. For now it works only on booleans, integers and strings (no
array support)

* Do not export some of the options

* Add support for arrays and fix numbers

* Fix comments

* Replace 1 and 0 with true and false

* Export hidden,reverse,dirfirst and sortby options

* Fix comments

* Little fix

* Simplify boolean conversion

log readlink errors instead of fail

Related #447 and #374
2020-09-01 15:42:44 +03:00
Gokcehan d25faf7186 add descriptions of commands to the documentation
Related #321
2020-09-01 00:00:38 +03:00
19 changed files with 2666 additions and 910 deletions

No files matched your search

+15 -3
View File
@@ -41,13 +41,25 @@ See [faq](https://github.com/gokcehan/lf/wiki/FAQ) for more information and [tut
## Installation ## Installation
See [packages](https://github.com/gokcehan/lf/wiki/Packages) for community maintained packages.
See [releases](https://github.com/gokcehan/lf/releases) for pre-built binaries. See [releases](https://github.com/gokcehan/lf/releases) for pre-built binaries.
If you like to build from the source: If you like to build from the source on unix:
go get -u github.com/gokcehan/lf env CGO_ENABLED=0 GO111MODULE=on go get -u -ldflags="-s -w" github.com/gokcehan/lf
See [packages](https://github.com/gokcehan/lf/wiki/Packages) for community maintained packages. On windows `cmd`:
set CGO_ENABLED=0
set GO111MODULE=on
go get -u -ldflags="-s -w" github.com/gokcehan/lf
On windows `powershell`:
$env:CGO_ENABLED = '0'
$env:GO111MODULE = 'on'
go get -u -ldflags="-s -w" github.com/gokcehan/lf
## Usage ## Usage
+34 -87
View File
@@ -9,11 +9,11 @@ import (
"os/exec" "os/exec"
"os/signal" "os/signal"
"path/filepath" "path/filepath"
"reflect"
"strconv"
"strings" "strings"
"syscall" "syscall"
"time" "time"
"github.com/gdamore/tcell"
) )
type cmdItem struct { type cmdItem struct {
@@ -34,8 +34,8 @@ type app struct {
cmdHistoryInd int cmdHistoryInd int
} }
func newApp() *app { func newApp(screen tcell.Screen) *app {
ui := newUI() ui := newUI(screen)
nav := newNav(ui.wins[0].h) nav := newNav(ui.wins[0].h)
quitChan := make(chan bool, 1) quitChan := make(chan bool, 1)
@@ -93,6 +93,12 @@ func (app *app) readHistory() error {
scanner := bufio.NewScanner(f) scanner := bufio.NewScanner(f)
for scanner.Scan() { for scanner.Scan() {
toks := strings.SplitN(scanner.Text(), " ", 2) toks := strings.SplitN(scanner.Text(), " ", 2)
if toks[0] != ":" && toks[0] != "$" && toks[0] != "%" && toks[0] != "!" && toks[0] != "&" {
continue
}
if len(toks) < 2 {
continue
}
app.cmdHistory = append(app.cmdHistory, cmdItem{toks[0], toks[1]}) app.cmdHistory = append(app.cmdHistory, cmdItem{toks[0], toks[1]})
} }
@@ -149,9 +155,10 @@ func (app *app) writeHistory() error {
// for evaluation. Similarly directories and regular files are also read in // for evaluation. Similarly directories and regular files are also read in
// separate goroutines and sent here for update. // separate goroutines and sent here for update.
func (app *app) loop() { func (app *app) loop() {
clientChan := app.ui.readExpr()
serverChan := readExpr() serverChan := readExpr()
app.ui.readExpr()
if gSelect != "" { if gSelect != "" {
go func() { go func() {
lstat, err := os.Lstat(gSelect) lstat, err := os.Lstat(gSelect)
@@ -310,7 +317,27 @@ func (app *app) loop() {
} }
app.ui.draw(app.nav) app.ui.draw(app.nav)
case e := <-clientChan: case ev := <-app.ui.evChan:
e := app.ui.readEvent(ev)
if e == nil {
continue
}
e.eval(app, nil)
loop:
for {
select {
case ev := <-app.ui.evChan:
e = app.ui.readEvent(ev)
if e == nil {
continue
}
e.eval(app, nil)
default:
break loop
}
}
app.ui.draw(app.nav)
case e := <-app.ui.exprChan:
e.eval(app, nil) e.eval(app, nil)
app.ui.draw(app.nav) app.ui.draw(app.nav)
case e := <-serverChan: case e := <-serverChan:
@@ -335,85 +362,6 @@ func (app *app) exportFiles() {
exportFiles(currFile, currSelections) exportFiles(currFile, currSelections)
} }
func fieldToString(field reflect.Value) string {
kind := field.Kind()
var value string
switch kind {
case reflect.Int:
value = strconv.Itoa(int(field.Int()))
case reflect.Bool:
value = strconv.FormatBool(field.Bool())
case reflect.Slice:
for i := 0; i < field.Len(); i++ {
element := field.Index(i)
if i == 0 {
value = fieldToString(element)
} else {
value += ":" + fieldToString(element)
}
}
default:
value = field.String()
}
return value
}
func (app *app) exportOpts() {
e := reflect.ValueOf(&gOpts).Elem()
for i := 0; i < e.NumField(); i++ {
// Get name and prefix it with lf_
name := e.Type().Field(i).Name
name = fmt.Sprintf("lf_%s", name)
// Skip maps
if name == "lf_keys" || name == "lf_cmdkeys" || name == "lf_cmds" {
continue
}
// Get string representation of the value
if name == "lf_sortType" {
var sortby string
switch gOpts.sortType.method {
case naturalSort:
sortby = "natural"
case nameSort:
sortby = "name"
case sizeSort:
sortby = "size"
case timeSort:
sortby = "time"
case ctimeSort:
sortby = "ctime"
case atimeSort:
sortby = "atime"
case extSort:
sortby = "ext"
}
os.Setenv("lf_sortby", sortby)
reverse := strconv.FormatBool(gOpts.sortType.option&reverseSort != 0)
os.Setenv("lf_reverse", reverse)
hidden := strconv.FormatBool(gOpts.sortType.option&hiddenSort != 0)
os.Setenv("lf_hidden", hidden)
dirfirst := strconv.FormatBool(gOpts.sortType.option&dirfirstSort != 0)
os.Setenv("lf_dirfirst", dirfirst)
} else {
field := e.Field(i)
value := fieldToString(field)
os.Setenv(name, value)
}
}
}
func waitKey() error { func waitKey() error {
cmd := pauseCommand() cmd := pauseCommand()
@@ -437,7 +385,7 @@ func waitKey() error {
// & No Yes No No No Do nothing // & No Yes No No No Do nothing
func (app *app) runShell(s string, args []string, prefix string) { func (app *app) runShell(s string, args []string, prefix string) {
app.exportFiles() app.exportFiles()
app.exportOpts() exportOpts()
cmd := shellCommand(s, args) cmd := shellCommand(s, args)
@@ -483,7 +431,6 @@ func (app *app) runShell(s string, args []string, prefix string) {
} }
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav)
app.ui.loadFileInfo(app.nav)
switch prefix { switch prefix {
case "%": case "%":
+9 -7
View File
@@ -10,16 +10,17 @@ import (
"strings" "strings"
"time" "time"
"github.com/doronbehar/termbox-go" "github.com/gdamore/tcell"
) )
func run() { func run() {
if err := termbox.Init(); err != nil { var screen tcell.Screen
log.Fatalf("initializing termbox: %s", err) var err error
if screen, err = tcell.NewScreen(); err != nil {
log.Fatalf("creating screen: %s", err)
} else if err = screen.Init(); err != nil {
log.Fatalf("initializing screen: %s", err)
} }
defer termbox.Close()
setColorMode()
f, err := os.Create(gLogPath) f, err := os.Create(gLogPath)
if err != nil { if err != nil {
@@ -31,7 +32,7 @@ func run() {
log.Print("hi!") log.Print("hi!")
app := newApp() app := newApp(screen)
if err := app.nav.readMarks(); err != nil { if err := app.nav.readMarks(); err != nil {
app.ui.echoerrf("reading marks file: %s", err) app.ui.echoerrf("reading marks file: %s", err)
@@ -42,6 +43,7 @@ func run() {
} }
app.loop() app.loop()
app.ui.screen.Fini()
} }
func readExpr() <-chan expr { func readExpr() <-chan expr {
+90 -101
View File
@@ -7,48 +7,18 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/doronbehar/termbox-go" "github.com/gdamore/tcell"
) )
const gAnsiColorResetMask = termbox.AttrBold | termbox.AttrUnderline | termbox.AttrReverse type styleMap map[string]tcell.Style
var gAnsiCodes = map[int]termbox.Attribute{ func parseStyles() styleMap {
0: termbox.ColorDefault,
1: termbox.AttrBold,
4: termbox.AttrUnderline,
7: termbox.AttrReverse,
30: termbox.ColorBlack,
31: termbox.ColorRed,
32: termbox.ColorGreen,
33: termbox.ColorYellow,
34: termbox.ColorBlue,
35: termbox.ColorMagenta,
36: termbox.ColorCyan,
37: termbox.ColorWhite,
40: termbox.ColorBlack,
41: termbox.ColorRed,
42: termbox.ColorGreen,
43: termbox.ColorYellow,
44: termbox.ColorBlue,
45: termbox.ColorMagenta,
46: termbox.ColorCyan,
47: termbox.ColorWhite,
}
type colorEntry struct {
fg termbox.Attribute
bg termbox.Attribute
}
type colorMap map[string]colorEntry
func parseColors() colorMap {
if env := os.Getenv("LS_COLORS"); env != "" { if env := os.Getenv("LS_COLORS"); env != "" {
return parseColorsGNU(env) return parseStylesGNU(env)
} }
if env := os.Getenv("LSCOLORS"); env != "" { if env := os.Getenv("LSCOLORS"); env != "" {
return parseColorsBSD(env) return parseStylesBSD(env)
} }
// default values from dircolors with removed background colors // default values from dircolors with removed background colors
@@ -73,10 +43,10 @@ func parseColors() colorMap {
"ex=01;32", "ex=01;32",
} }
return parseColorsGNU(strings.Join(defaultColors, ":")) return parseStylesGNU(strings.Join(defaultColors, ":"))
} }
func applyAnsiCodes(s string, fg, bg termbox.Attribute) (termbox.Attribute, termbox.Attribute) { func applyAnsiCodes(s string, st tcell.Style) tcell.Style {
toks := strings.Split(s, ";") toks := strings.Split(s, ";")
var nums []int var nums []int
@@ -93,43 +63,63 @@ func applyAnsiCodes(s string, fg, bg termbox.Attribute) (termbox.Attribute, term
nums = append(nums, n) nums = append(nums, n)
} }
// ECMA-48 details the standard
for i := 0; i < len(nums); i++ { for i := 0; i < len(nums); i++ {
n := nums[i] n := nums[i]
switch { switch {
case n == 38 && i+2 < len(nums) && nums[i+1] == 5:
fg &= gAnsiColorResetMask
fg |= termbox.Attribute(nums[i+2] + 1)
i += 2
continue
case n == 48 && i+2 < len(nums) && nums[i+1] == 5:
bg = termbox.Attribute(nums[i+2] + 1)
i += 2
continue
}
attr, ok := gAnsiCodes[n]
if !ok {
log.Printf("unknown ansi code: %d", n)
continue
}
switch {
case n == 0: case n == 0:
fg, bg = attr, attr st = tcell.StyleDefault
case n == 1 || n == 4 || n == 7: case n == 1:
fg |= attr st = st.Bold(true)
case 30 <= n && n <= 37: case n == 2:
fg &= gAnsiColorResetMask st = st.Dim(true)
fg |= attr case n == 4:
case 40 <= n && n <= 47: st = st.Underline(true)
bg = attr case n == 5 || n == 6:
st = st.Blink(true)
case n == 7:
st = st.Reverse(true)
case n >= 30 && n <= 37:
st = st.Foreground(tcell.Color(n - 30))
case n == 38:
if i+3 <= len(nums) && nums[i+1] == 5 {
st = st.Foreground(tcell.Color(nums[i+2]))
i += 2
} else if i+5 <= len(nums) && nums[i+1] == 2 {
st = st.Foreground(tcell.NewRGBColor(
int32(nums[i+2]),
int32(nums[i+3]),
int32(nums[i+4])))
i += 4
} else {
log.Printf("unknown ansi code or incorrect form: %d", n)
}
case n >= 40 && n <= 47:
st = st.Background(tcell.Color(n - 40))
case n == 48:
if i+3 <= len(nums) && nums[i+1] == 5 {
st = st.Background(tcell.Color(nums[i+2]))
i += 2
} else if i+5 <= len(nums) && nums[i+1] == 2 {
st = st.Background(tcell.NewRGBColor(
int32(nums[i+2]),
int32(nums[i+3]),
int32(nums[i+4])))
i += 4
} else {
log.Printf("unknown ansi code or incorrect form: %d", n)
}
default:
log.Printf("unknown ansi code: %d", n)
} }
} }
return fg, bg return st
} }
// This function parses $LS_COLORS environment variable. // This function parses $LS_COLORS environment variable.
func parseColorsGNU(env string) colorMap { func parseStylesGNU(env string) styleMap {
colors := make(colorMap) styles := make(styleMap)
entries := strings.Split(env, ":") entries := strings.Split(env, ":")
for _, entry := range entries { for _, entry := range entries {
@@ -139,63 +129,62 @@ func parseColorsGNU(env string) colorMap {
pair := strings.Split(entry, "=") pair := strings.Split(entry, "=")
if len(pair) != 2 { if len(pair) != 2 {
log.Printf("invalid $LS_COLORS entry: %s", entry) log.Printf("invalid $LS_COLORS entry: %s", entry)
return colors return styles
} }
key, val := pair[0], pair[1] key, val := pair[0], pair[1]
fg, bg := applyAnsiCodes(val, termbox.ColorDefault, termbox.ColorDefault) styles[key] = applyAnsiCodes(val, tcell.StyleDefault)
colors[key] = colorEntry{fg: fg, bg: bg}
} }
return colors return styles
} }
// This function parses $LSCOLORS environment variable. // This function parses $LSCOLORS environment variable.
func parseColorsBSD(env string) colorMap { func parseStylesBSD(env string) styleMap {
colors := make(colorMap) styles := make(styleMap)
if len(env) != 22 { if len(env) != 22 {
log.Printf("invalid $LSCOLORS variable: %s", env) log.Printf("invalid $LSCOLORS variable: %s", env)
return colors return styles
} }
colorNames := []string{"di", "ln", "so", "pi", "ex", "bd", "cd", "su", "sg", "tw", "ow"} colorNames := []string{"di", "ln", "so", "pi", "ex", "bd", "cd", "su", "sg", "tw", "ow"}
colorCodes := map[byte]termbox.Attribute{
'a': termbox.ColorBlack,
'b': termbox.ColorRed,
'c': termbox.ColorGreen,
'd': termbox.ColorYellow, // brown
'e': termbox.ColorBlue,
'f': termbox.ColorMagenta,
'g': termbox.ColorCyan,
'h': termbox.ColorWhite, // light grey
'A': termbox.AttrBold | termbox.ColorBlack,
'B': termbox.AttrBold | termbox.ColorRed,
'C': termbox.AttrBold | termbox.ColorGreen,
'D': termbox.AttrBold | termbox.ColorYellow, // brown
'E': termbox.AttrBold | termbox.ColorBlue,
'F': termbox.AttrBold | termbox.ColorMagenta,
'G': termbox.AttrBold | termbox.ColorCyan,
'H': termbox.AttrBold | termbox.ColorWhite, // light grey
'x': termbox.ColorDefault,
}
getColor := func(r byte) termbox.Attribute { getStyle := func(r1, r2 byte) tcell.Style {
if color, ok := colorCodes[r]; ok { st := tcell.StyleDefault
return color
switch {
case r1 == 'x':
st = st.Foreground(tcell.ColorDefault)
case 'A' <= r1 && r1 <= 'H':
st = st.Foreground(tcell.Color(r1 - 'A')).Bold(true)
case 'a' <= r1 && r1 <= 'h':
st = st.Foreground(tcell.Color(r1 - 'a'))
default:
log.Printf("invalid $LSCOLORS entry: %c", r1)
return tcell.StyleDefault
} }
log.Printf("invalid $LSCOLORS entry: %c", r) switch {
return termbox.ColorDefault case r2 == 'x':
st = st.Background(tcell.ColorDefault)
case 'a' <= r2 && r2 <= 'h':
st = st.Background(tcell.Color(r2 - 'a'))
default:
log.Printf("invalid $LSCOLORS entry: %c", r2)
return tcell.StyleDefault
}
return st
} }
for i, key := range colorNames { for i, key := range colorNames {
colors[key] = colorEntry{fg: getColor(env[i*2]), bg: getColor(env[i*2+1])} styles[key] = getStyle(env[i*2], env[i*2+1])
} }
return colors return styles
} }
func (cm colorMap) get(f *file) (termbox.Attribute, termbox.Attribute) { func (cm styleMap) get(f *file) tcell.Style {
var key string var key string
switch { switch {
@@ -230,12 +219,12 @@ func (cm colorMap) get(f *file) (termbox.Attribute, termbox.Attribute) {
} }
if val, ok := cm[key]; ok { if val, ok := cm[key]; ok {
return val.fg, val.bg return val
} }
if val, ok := cm["fi"]; ok { if val, ok := cm["fi"]; ok {
return val.fg, val.bg return val
} }
return termbox.ColorDefault, termbox.ColorDefault return tcell.StyleDefault
} }
+51 -47
View File
@@ -3,75 +3,79 @@ package main
import ( import (
"testing" "testing"
"github.com/doronbehar/termbox-go" "github.com/gdamore/tcell"
) )
func TestApplyAnsiCodes(t *testing.T) { func TestApplyAnsiCodes(t *testing.T) {
none := termbox.ColorDefault none := tcell.StyleDefault
tests := []struct { tests := []struct {
s string s string
fg termbox.Attribute st tcell.Style
bg termbox.Attribute stExp tcell.Style
fgExp termbox.Attribute
bgExp termbox.Attribute
}{ }{
{"", none, none, none, none}, {"", none, none},
{"", termbox.ColorRed, termbox.ColorRed, none, none}, {"", none.Foreground(tcell.ColorMaroon).Background(tcell.ColorMaroon), none},
{"", termbox.AttrBold, none, none, none}, {"", none.Bold(true), none},
{"", termbox.ColorRed | termbox.AttrBold, none, none, none}, {"", none.Foreground(tcell.ColorMaroon).Bold(true), none},
{"0", none, none, none, none}, {"0", none, none},
{"0", termbox.ColorRed, termbox.ColorRed, none, none}, {"0", none.Foreground(tcell.ColorMaroon).Background(tcell.ColorMaroon), none},
{"0", termbox.AttrBold, none, none, none}, {"0", none.Bold(true), none},
{"0", termbox.ColorRed | termbox.AttrBold, none, none, none}, {"0", none.Foreground(tcell.ColorMaroon).Bold(true), none},
{"1", none, none, termbox.AttrBold, none}, {"1", none, none.Bold(true)},
{"4", none, none, termbox.AttrUnderline, none}, {"4", none, none.Underline(true)},
{"7", none, none, termbox.AttrReverse, none}, {"7", none, none.Reverse(true)},
{"1", termbox.ColorRed, none, termbox.ColorRed | termbox.AttrBold, none}, {"1", none.Foreground(tcell.ColorMaroon), none.Foreground(tcell.ColorMaroon).Bold(true)},
{"4", termbox.ColorRed, none, termbox.ColorRed | termbox.AttrUnderline, none}, {"4", none.Foreground(tcell.ColorMaroon), none.Foreground(tcell.ColorMaroon).Underline(true)},
{"7", termbox.ColorRed, none, termbox.ColorRed | termbox.AttrReverse, none}, {"7", none.Foreground(tcell.ColorMaroon), none.Foreground(tcell.ColorMaroon).Reverse(true)},
{"4", termbox.AttrBold, none, termbox.AttrBold | termbox.AttrUnderline, none}, {"4", none.Bold(true), none.Bold(true).Underline(true)},
{"4", termbox.ColorRed | termbox.AttrBold, none, termbox.ColorRed | termbox.AttrBold | termbox.AttrUnderline, none}, {"4", none.Foreground(tcell.ColorMaroon).Bold(true), none.Foreground(tcell.ColorMaroon).Bold(true).Underline(true)},
{"31", none, none, termbox.ColorRed, none}, {"31", none, none.Foreground(tcell.ColorMaroon)},
{"31", termbox.ColorGreen, none, termbox.ColorRed, none}, {"31", none.Foreground(tcell.ColorGreen), none.Foreground(tcell.ColorMaroon)},
{"31", termbox.ColorGreen | termbox.AttrBold, none, termbox.ColorRed | termbox.AttrBold, none}, {"31", none.Foreground(tcell.ColorGreen).Bold(true), none.Foreground(tcell.ColorMaroon).Bold(true)},
{"41", none, none, none, termbox.ColorRed}, {"41", none, none.Background(tcell.ColorMaroon)},
{"41", none, termbox.ColorGreen, none, termbox.ColorRed}, {"41", none.Background(tcell.ColorGreen), none.Background(tcell.ColorMaroon)},
{"1;31", none, none, termbox.ColorRed | termbox.AttrBold, none}, {"1;31", none, none.Foreground(tcell.ColorMaroon).Bold(true)},
{"1;31", termbox.ColorGreen, none, termbox.ColorRed | termbox.AttrBold, none}, {"1;31", none.Foreground(tcell.ColorGreen), none.Foreground(tcell.ColorMaroon).Bold(true)},
{"38;5;0", none, none, termbox.ColorBlack, none}, {"38;5;0", none, none.Foreground(tcell.ColorBlack)},
{"38;5;1", none, none, termbox.ColorRed, none}, {"38;5;1", none, none.Foreground(tcell.ColorMaroon)},
{"38;5;8", none, none, termbox.Attribute(9), none}, {"38;5;8", none, none.Foreground(tcell.Color(8))},
{"38;5;16", none, none, termbox.Attribute(17), none}, {"38;5;16", none, none.Foreground(tcell.Color(16))},
{"38;5;232", none, none, termbox.Attribute(233), none}, {"38;5;232", none, none.Foreground(tcell.Color(232))},
{"38;5;1", termbox.ColorGreen, none, termbox.ColorRed, none}, {"38;5;1", none.Foreground(tcell.ColorGreen), none.Foreground(tcell.ColorMaroon)},
{"38;5;1", termbox.ColorGreen | termbox.AttrBold, none, termbox.ColorRed | termbox.AttrBold, none}, {"38;5;1", none.Foreground(tcell.ColorGreen).Bold(true), none.Foreground(tcell.ColorMaroon).Bold(true)},
{"48;5;0", none, none, none, termbox.ColorBlack}, {"48;5;0", none, none.Background(tcell.ColorBlack)},
{"48;5;1", none, none, none, termbox.ColorRed}, {"48;5;1", none, none.Background(tcell.ColorMaroon)},
{"48;5;8", none, none, none, termbox.Attribute(9)}, {"48;5;8", none, none.Background(tcell.Color(8))},
{"48;5;16", none, none, none, termbox.Attribute(17)}, {"48;5;16", none, none.Background(tcell.Color(16))},
{"48;5;232", none, none, none, termbox.Attribute(233)}, {"48;5;232", none, none.Background(tcell.Color(232))},
{"48;5;1", none, termbox.ColorGreen, none, termbox.ColorRed}, {"48;5;1", none.Background(tcell.ColorGreen), none.Background(tcell.ColorMaroon)},
{"1;38;5;1", none, none, termbox.ColorRed | termbox.AttrBold, none}, {"1;38;5;1", none, none.Foreground(tcell.ColorMaroon).Bold(true)},
{"1;38;5;1", termbox.ColorGreen, none, termbox.ColorRed | termbox.AttrBold, none}, {"1;38;5;1", none.Foreground(tcell.ColorGreen), none.Foreground(tcell.ColorMaroon).Bold(true)},
{"38;2;5;102;8", none, none.Foreground(tcell.NewRGBColor(5, 102, 8))},
{"48;2;0;48;143", none, none.Background(tcell.NewRGBColor(0, 48, 143))},
// Fixes color construction issue: https://github.com/gokcehan/lf/pull/439#issuecomment-674409446
{"38;5;34;1", none, none.Foreground(tcell.Color(34)).Bold(true)},
} }
for _, test := range tests { for _, test := range tests {
if fgGot, bgGot := applyAnsiCodes(test.s, test.fg, test.bg); fgGot != test.fgExp || bgGot != test.bgExp { if stGot := applyAnsiCodes(test.s, test.st); stGot != test.stExp {
t.Errorf("at input '%s' with '%d' and '%d' expected '%d' and '%d' but got '%d' and '%d'", t.Errorf("at input '%s' with '%d' expected '%d' but got '%d'",
test.s, test.fg, test.bg, test.fgExp, test.bgExp, fgGot, bgGot) test.s, test.st, test.stExp, stGot)
} }
} }
} }
-3
View File
@@ -70,9 +70,6 @@ var (
"anchorfind", "anchorfind",
"noanchorfind", "noanchorfind",
"anchorfind!", "anchorfind!",
"color256",
"nocolor256",
"color256!",
"dircounts", "dircounts",
"nodircounts", "nodircounts",
"dircounts!", "dircounts!",
+607 -121
View File
@@ -12,10 +12,11 @@ at https://godoc.org/github.com/gokcehan/lf. You can also use 'doc' command
You can run 'lf -help' to see descriptions of command line options. You can run 'lf -help' to see descriptions of command line options.
Reference Quick Reference
The following commands are provided by lf with default keybindings: The following commands are provided by lf:
quit (default 'q')
up (default 'k' and '<up>') up (default 'k' and '<up>')
half-up (default '<c-u>') half-up (default '<c-u>')
page-up (default '<c-b>' and '<pgup>') page-up (default '<c-b>' and '<pgup>')
@@ -24,146 +25,132 @@ The following commands are provided by lf with default keybindings:
page-down (default '<c-f>' and '<pgdn>') page-down (default '<c-f>' and '<pgdn>')
updir (default 'h' and '<left>') updir (default 'h' and '<left>')
open (default 'l' and '<right>') open (default 'l' and '<right>')
quit (default 'q')
top (default 'gg' and '<home>') top (default 'gg' and '<home>')
bottom (default 'G' and '<end>') bottom (default 'G' and '<end>')
toggle
invert (default 'v') invert (default 'v')
unselect (default 'u') unselect (default 'u')
glob-select
glob-unselect
copy (default 'y') copy (default 'y')
cut (default 'd') cut (default 'd')
paste (default 'p') paste (default 'p')
clear (default 'c') clear (default 'c')
sync
draw
redraw (default '<c-l>') redraw (default '<c-l>')
load
reload (default '<c-r>') reload (default '<c-r>')
read (default ':') echo
rename (default 'r') echomsg
shell (default '$') echoerr
shell-pipe (default '%') cd
shell-wait (default '!') select
shell-async (default '&') delete (modal)
find (default 'f') rename (modal) (default 'r')
find-back (default 'F') source
push
read (modal) (default ':')
shell (modal) (default '$')
shell-pipe (modal) (default '%')
shell-wait (modal) (default '!')
shell-async (modal) (default '&')
find (modal) (default 'f')
find-back (modal) (default 'F')
find-next (default ';') find-next (default ';')
find-prev (default ',') find-prev (default ',')
search (default '/') search (modal) (default '/')
search-back (default '?') search-back (modal) (default '?')
search-next (default 'n') search-next (default 'n')
search-prev (default 'N') search-prev (default 'N')
mark-save (default 'm') mark-save (modal) (default 'm')
mark-load (default "'") mark-load (modal) (default "'")
mark-remove (default `"`) mark-remove (modal) (default `"`)
The following commands are provided by lf without default keybindings: The following command line commands are provided by lf:
draw draw the ui
load load modified files and directories
sync synchronize copied/cut files with server
echo print arguments to the message line
echomsg same as echo but logging
echoerr same as echomsg but red color
cd change working directory to the argument
select change current file selection to the argument
toggle toggle the selection of the current file or its arguments
glob-select select files that match the given glob
glob-unselect unselect files that match the given glob
source read the configuration file in the argument
push simulate key pushes given in the argument
delete remove the current file or selected file(s)
The following command line commands are provided by lf with default
keybindings:
cmd-escape (default '<esc>') cmd-escape (default '<esc>')
cmd-complete (default '<tab>') cmd-complete (default '<tab>')
cmd-enter (default '<c-j>' and '<enter>') cmd-enter (default '<c-j>' and '<enter>')
cmd-interrupt (default '<c-c>')
cmd-history-next (default '<c-n>') cmd-history-next (default '<c-n>')
cmd-history-prev (default '<c-p>') cmd-history-prev (default '<c-p>')
cmd-delete (default '<c-d>' and '<delete>')
cmd-delete-back (default '<bs>' and '<bs2>')
cmd-left (default '<c-b>' and '<left>') cmd-left (default '<c-b>' and '<left>')
cmd-right (default '<c-f>' and '<right>') cmd-right (default '<c-f>' and '<right>')
cmd-home (default '<c-a>' and '<home>') cmd-home (default '<c-a>' and '<home>')
cmd-end (default '<c-e>' and '<end>') cmd-end (default '<c-e>' and '<end>')
cmd-delete (default '<c-d>' and '<delete>')
cmd-delete-back (default '<backspace>' and '<backspace2>')
cmd-delete-home (default '<c-u>') cmd-delete-home (default '<c-u>')
cmd-delete-end (default '<c-k>') cmd-delete-end (default '<c-k>')
cmd-delete-unix-word (default '<c-w>') cmd-delete-unix-word (default '<c-w>')
cmd-yank (default '<c-y>') cmd-yank (default '<c-y>')
cmd-transpose (default '<c-t>') cmd-transpose (default '<c-t>')
cmd-interrupt (default '<c-c>') cmd-transpose-word (default '<a-t>')
cmd-word (default '<a-f>') cmd-word (default '<a-f>')
cmd-word-back (default '<a-b>') cmd-word-back (default '<a-b>')
cmd-capitalize-word (default '<a-c>')
cmd-delete-word (default '<a-d>') cmd-delete-word (default '<a-d>')
cmd-capitalize-word (default '<a-c>')
cmd-uppercase-word (default '<a-u>') cmd-uppercase-word (default '<a-u>')
cmd-lowercase-word (default '<a-l>') cmd-lowercase-word (default '<a-l>')
cmd-transpose-word (default '<a-t>')
The following options can be used to customize the behavior of lf: The following options can be used to customize the behavior of lf:
anchorfind boolean (default on) anchorfind bool (default on)
color256 boolean (default off) dircounts bool (default off)
dircounts boolean (default off) dirfirst bool (default on)
dirfirst boolean (default on) drawbox bool (default off)
drawbox boolean (default off) errorfmt string (default "\033[7;31;47m%s\033[0m")
globsearch boolean (default off) filesep string (default "\n")
hidden boolean (default off) findlen int (default 1)
icons boolean (default off) globsearch bool (default off)
ignorecase boolean (default on) hidden bool (default off)
ignoredia boolean (default off) hiddenfiles []string (default '.*')
incsearch boolean (default off) icons bool (default off)
number boolean (default off) ifs string (default '')
preview boolean (default on) ignorecase bool (default on)
relativenumber boolean (default off) ignoredia bool (default off)
reverse boolean (default off) incsearch bool (default off)
smartcase boolean (default on) info []string (default '')
smartdia boolean (default off) number bool (default off)
wrapscan boolean (default on) period int (default 0)
wrapscroll boolean (default off) preview bool (default on)
findlen integer (default 1) (zero to prompt until single match) previewer string (default '')
period integer (default 0) (zero to disable periodic loading) promptfmt string (default "\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f\033[0m")
scrolloff integer (default 0) ratios []int (default '1:2:3')
tabstop integer (default 8) relativenumber bool (default off)
errorfmt string (default "\033[7;31;47m%s\033[0m") reverse bool (default off)
filesep string (default "\n") scrolloff int (default 0)
hiddenfiles string (default '.*') shell string (default 'sh' for unix and 'cmd' for windows)
ifs string (default '') (not exported if empty) shellopts []string (default '')
info string (default '') smartcase bool (default on)
previewer string (default '') (not filtered if empty) smartdia bool (default off)
promptfmt string (default "\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f\033[0m") sortby string (default 'natural')
ratios string (default '1:2:3') tabstop int (default 8)
shell string (default 'sh') timefmt string (default 'Mon Jan _2 15:04:05 2006')
shellopts string (default '') truncatechar string (default '~')
sortby string (default 'natural') wrapscan bool (default on)
timefmt string (default 'Mon Jan _2 15:04:05 2006') wrapscroll bool (default off)
truncatechar string (default '~')
The following variables are exported for shell commands: The following environment variables are exported for shell commands:
$f current file f
$fs selected file(s) separated with 'filesep' fs
$fx current file or selected file(s) if any fx
$id id number of the client id
LF_LEVEL
OPENER
EDITOR
PAGER
SHELL
The following variables are set to the corresponding values: The following commands/keybindings are provided by default:
$LF_LEVEL current nesting level unix windows
cmd open &$OPENER "$f" cmd open &%OPENER% %f%
The following default values are set to the environmental variables on unix map e $$EDITOR "$f" map e $%EDITOR% %f%
when they are not set or empty: map i $$PAGER "$f" map i !%PAGER% %f%
map w $$SHELL map w $%SHELL%
$OPENER open # macos
$OPENER xdg-open # others
$EDITOR vi
$PAGER less
$SHELL sh
The following default values are set to the environmental variables on windows
when they are not set or empty:
%OPENER% start
%EDITOR% notepad
%PAGER% more
%SHELL% cmd
The following additional keybindings are provided by default: The following additional keybindings are provided by default:
@@ -182,12 +169,6 @@ The following additional keybindings are provided by default:
map gh cd ~ map gh cd ~
map <space> :toggle; down map <space> :toggle; down
The following keybindings to applications are provided by default:
map e $$EDITOR $f
map i $$PAGER $f
map w $$SHELL
Configuration Configuration
Configuration files should be located at: Configuration files should be located at:
@@ -217,6 +198,507 @@ locations:
A sample configuration file can be found at A sample configuration file can be found at
https://github.com/gokcehan/lf/blob/master/etc/lfrc.example. https://github.com/gokcehan/lf/blob/master/etc/lfrc.example.
Commands
This section shows information about builtin commands.
Modal commands do not take any arguments, but instead change the operation mode to read their input conveniently, and so they are meant to be assigned to keybindings.
quit (default 'q')
Quit lf and return to the shell.
up (default 'k' and '<up>')
half-up (default '<c-u>')
page-up (default '<c-b>' and '<pgup>')
down (default 'j' and '<down>')
half-down (default '<c-d>')
page-down (default '<c-f>' and '<pgdn>')
Move the current file selection upwards/downwards by one/half a page/full page.
updir (default 'h' and '<left>')
Change the current working directory to the parent directory.
open (default 'l' and '<right>')
If the current file is a directory, then change the current directory to it, otherwise, execute the 'open' command.
A default 'open' command is provided to call the default system opener asynchronously with the current file as the argument.
A custom 'open' command can be defined to override this default.
(See also 'OPENER' variable and 'Opening Files' section)
top (default 'gg' and '<home>')
bottom (default 'G' and '<end>')
Move the current file selection to the top/bottom of the directory.
toggle
Toggle the selection of the current file or files given as arguments.
invert (default 'v')
Reverse the selection of all files in the current directory (i.e. 'toggle' all files).
Selections in other directories are not effected by this command.
You can define a new command to select all files in the directory by combining 'invert' with 'unselect' (i.e. `cmd select-all :unselect; invert`), though this will also remove selections in other directories.
unselect (default 'u')
Remove the selection of all files in all directories.
glob-select
Select files that match the given glob.
glob-unselect
Unselect files that match the given glob.
copy (default 'y')
If there are no selections, save the path of the current file to the copy buffer, otherwise, copy the paths of selected files.
cut (default 'd')
If there are no selections, save the path of the current file to the cut buffer, otherwise, copy the paths of selected files.
paste (default 'p')
Copy/Move files in copy/cut buffer to the current working directory.
clear (default 'c')
Clear file paths in copy/cut buffer.
sync
Synchronize copied/cut files with server.
This command is automatically called when required.
draw
Draw the screen.
This command is automatically called when required.
redraw (default '<c-l>')
Synchronize the terminal and redraw the screen.
load
Load modified files and directories.
This command is automatically called when required.
reload (default '<c-r>')
Flush the cache and reload all files and directories.
echo
Print given arguments to the message line at the bottom.
echomsg
Print given arguments to the message line at the bottom and also to the log file.
echoerr
Print given arguments to the message line at the bottom in red color and also to the log file.
cd
Change the working directory to the given argument.
select
Change the current file selection to the given argument.
delete (modal)
Remove the current file or selected file(s).
rename (modal) (default 'r')
Rename the current file using the builtin method.
A custom 'rename' command can be defined to override this default.
source
Read the configuration file given in the argument.
push
Simulate key pushes given in the argument.
read (modal) (default ':')
Read a command to evaluate.
shell (modal) (default '$')
Read a shell command to execute.
(See also 'Prefixes' and 'Shell Commands' sections)
shell-pipe (modal) (default '%')
Read a shell command to execute piping its standard I/O to the bottom statline.
(See also 'Prefixes' and 'Piping Shell Commands' sections)
shell-wait (modal) (default '!')
Read a shell command to execute and wait for a key press in the end.
(See also 'Prefixes' and 'Waiting Shell Commands' sections)
shell-async (modal) (default '&')
Read a shell command to execute synchronously without standard I/O.
find (modal) (default 'f')
find-back (modal) (default 'F')
find-next (default ';')
find-prev (default ',')
Read key(s) to find the appropriate file name match in the forward/backward direction and jump to the next/previous match.
(See also 'anchorfind', 'findlen', 'wrapscan', 'ignorecase', 'smartcase', 'ignoredia', and 'smartdia' options and 'Searching Files' section)
search (default '/')
search-back (default '?')
search-next (default 'n')
search-prev (default 'N')
Read a pattern to search for a file name match in the forward/backward direction and jump to the next/previous match.
(See also 'globsearch', 'incsearch', 'wrapscan', 'ignorecase', 'smartcase', 'ignoredia', and 'smartdia' options and 'Searching Files' section)
mark-save (modal) (default 'm')
Save the current directory as a bookmark assigned to the given key.
mark-load (modal) (default "'")
Change the current directory to the bookmark assigned to the given key.
A special bookmark "'" holds the previous directory after a 'mark-load', 'cd', or 'select' command.
mark-remove (modal) (default `"`)
Remove a bookmark assigned to the given key.
Command Line Commands
This section shows information about command line commands.
These should be mostly compatible with readline keybindings.
A character refers to a unicode code point, a word consists of letters and digits, and a unix word consists of any non-blank characters.
cmd-escape (default '<esc>')
Quit command line mode and return to normal mode.
cmd-complete (default '<tab>')
Autocomplete the current word.
cmd-enter (default '<c-j>' and '<enter>')
Execute the current line.
cmd-interrupt (default '<c-c>')
Interrupt the current shell-pipe command and return to the normal mode.
cmd-history-next (default '<c-n>')
cmd-history-prev (default '<c-p>')
Go to next/previous item in the history.
cmd-left (default '<c-b>' and '<left>')
cmd-right (default '<c-f>' and '<right>')
Move the cursor to the left/right.
cmd-home (default '<c-a>' and '<home>')
cmd-end (default '<c-e>' and '<end>')
Move the cursor to the beginning/end of line.
cmd-delete (default '<c-d>' and '<delete>')
cmd-delete-back (default '<backspace>' and '<backspace2>')
Delete the next character in forward/backward direction.
cmd-delete-home (default '<c-u>')
cmd-delete-end (default '<c-k>')
Delete everything up to the beginning/end of line.
cmd-delete-unix-word (default '<c-w>')
Delete the previous unix word.
cmd-yank (default '<c-y>')
Paste the buffer content containing the last deleted item.
cmd-transpose (default '<c-t>')
cmd-transpose-word (default '<a-t>')
Transpose the positions of last two characters/words.
cmd-word (default '<a-f>')
cmd-word-back (default '<a-b>')
Move the cursor by one word in forward/backward direction.
cmd-delete-word (default '<a-d>')
Delete the next word in forward direction.
cmd-capitalize-word (default '<a-c>')
cmd-uppercase-word (default '<a-u>')
cmd-lowercase-word (default '<a-l>')
Capitalize/uppercase/lowercase the current word and jump to the next word.
Options
This section shows information about options to customize the behavior.
Character ':' is used as the separator for list options '[]int' and '[]string'.
anchorfind bool (default on)
When this option is enabled, find command starts matching patterns from the beginning of file names, otherwise, it can match at an arbitrary position.
dircounts bool (default off)
When this option is enabled, directory sizes show the number of items inside instead of the size of directory file.
The former needs to be calculated by reading the directory and counting the items inside.
The latter is directly provided by the operating system and it does not require any calculation, though it is non-intuitive and it can often be misleading.
This option is disabled by default for performance reasons.
This option only has an effect when 'info' has a 'size' field and the pane is wide enough to show the information.
A thousand items are counted per directory at most, and bigger directories are shown as '999+'.
dirfirst bool (default on)
Show directories first above regular files.
drawbox bool (default off)
Draw boxes around panes with box drawing characters.
errorfmt string (default "\033[7;31;47m%s\033[0m")
Format string of error messages shown in the bottom message line.
filesep string (default "\n")
File separator used in environment variables 'fs' and 'fx'.
findlen int (default 1)
Number of characters prompted for the find command.
When this value is set to 0, find command prompts until there is only a single match left.
globsearch bool (default off)
When this option is enabled, search command patterns are considered as globs, otherwise they are literals.
With globbing, '*' matches any sequence, '?' matches any character, and '[...]' or '[^...] matches character sets or ranges.
Otherwise, these characters are interpreted as they are.
hidden bool (default off)
Show hidden files.
On unix systems, hidden files are determined by the value of 'hiddenfiles'.
On windows, only files with hidden attributes are considered hidden files.
hiddenfiles []string (default '.*')
List of hidden file glob patterns.
Patterns can be given as relative or absolute paths.
Globbing supports the usual special characters, '*' to match any sequence, '?' to match any character, and '[...]' or '[^...] to match character sets or ranges.
In addition, if a pattern starts with '!', then its matches are excluded from hidden files.
icons bool (default off)
Show icons before each item in the list.
By default, only two icons, 🗀 (U+1F5C0) and 🗎 (U+1F5CE), are used for directories and files respectively, as they are supported in the unicode standard.
Icons can be configured with an environment variable named 'LF_ICONS'.
The syntax of this variable is similar to 'LS_COLORS'.
See the wiki page for an example icon configuration.
ifs string (default '')
Sets 'IFS' variable in shell commands.
It works by adding the assignment to the beginning of the command string as 'IFS='...'; ...'.
The reason is that 'IFS' variable is not inherited by the shell for security reasons.
This method assumes a POSIX shell syntax and so it can fail for non-POSIX shells.
This option has no effect when the value is left empty.
This option does not have any effect on windows.
ignorecase bool (default on)
Ignore case in search patterns.
ignoredia bool (default off)
Ignore diacritics in search patterns.
incsearch bool (default off)
Jump to the first match after each keystroke during searching.
info []string (default '')
List of information shown for directory items at the right side of pane.
Currently supported information types are 'size', 'time', 'atime', and 'ctime'.
Information is only shown when the pane width is more than twice the width of information.
number bool (default off)
Show the position number for directory items at the left side of pane.
When 'relativenumber' is enabled, only the current line shows the absolute position and relative positions are shown for the rest.
period int (default 0)
Set the interval in seconds for periodic checks of directory updates.
This works by periodically calling the 'load' command.
Note that directories are already updated automatically in many cases.
This option can be useful when there is an external process changing the displayed directory and you are not doing anything in lf.
Periodic checks are disabled when the value of this option is set to zero.
preview bool (default on)
Show previews of files and directories at the right most pane.
If the file has more lines than the preview pane, rest of the lines are not read.
Files containing the null character (U+0000) in the read portion are considered binary files and displayed as 'binary'.
previewer string (default '') (not filtered if empty)
Set the path of a previewer file to filter the content of regular files for previewing.
The file should be executable.
Two arguments are passed to the file, first is the current file name, and second is the height of preview pane.
SIGPIPE signal is sent when enough lines are read.
Preview filtering is disabled and files are displayed as they are when the value of this option is left empty.
promptfmt string (default "\033[32;1m%u@%h\033[0m:\033[34;1m%w/\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, 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.
ratios []int (default '1:2:3')
List of ratios of pane widths.
Number of items in the list determines the number of panes in the ui.
When 'preview' option is enabled, the right most number is used for the width of preview pane.
relativenumber bool (default off)
Show the position number relative to the current line.
When 'number' is enabled, current line shows the absolute position, otherwise nothing is shown.
reverse bool (default off)
Reverse the direction of sort.
scrolloff int (default 0)
Minimum number of offset lines shown at all times in the top and the bottom of the screen when scrolling.
The current line is kept in the middle when this option is set to a large value that is bigger than the half of number of lines.
A smaller offset can be used when the current file is close to the beginning or end of the list to show the maximum number of items.
shell string (default 'sh' for unix and 'cmd' for windows)
Shell executable to use for shell commands.
Shell commands are executed as 'shell shellopts -c command -- arguments'.
On windows, '/c' is used instead of '-c' which should work in 'cmd' and 'powershell'.
shellopts []string (default '')
List of shell options to pass to the shell executable.
smartcase bool (default on)
Override 'ignorecase' option when the pattern contains an uppercase character.
This option has no effect when 'ignorecase' is disabled.
smartdia bool (default off)
Override 'ignoredia' option when the pattern contains a character with diacritic.
This option has no effect when 'ignoredia' is disabled.
sortby string (default 'natural')
Sort type for directories.
Currently supported sort types are 'natural', 'name', 'size', 'time', 'ctime', 'atime', and 'ext'.
tabstop int (default 8)
Number of space characters to show for horizontal tabulation (U+0009) character.
timefmt string (default 'Mon Jan _2 15:04:05 2006')
Format string of the file modification time shown in the bottom line.
truncatechar string (default '~')
Truncate character shown at the end when the file name does not fit to the pane.
wrapscan bool (default on)
Searching can wrap around the file list.
wrapscroll bool (default off)
Scrolling can wrap around the file list.
Environment Variables
The following variables are exported for shell commands:
These are referred with a '$' prefix on POSIX shells (e.g. '$f'), between '%' characters on Windows cmd (e.g. '%f%'), and with a '$env:' prefix on Windows powershell (e.g. '$env:f').
f
Current file selection as a full path.
fs
Selected file(s) separated with the value of 'filesep' option as full path(s).
fx
Selected file(s) (i.e. 'fs') if there are any selected files, otherwise current file selection (i.e. 'f').
id
Id of the running client.
LF_LEVEL
The value of this variable is set to the current nesting level when you run lf from a shell spawned inside lf.
You can add the value of this variable to your shell prompt to make it clear that your shell runs inside lf.
For example, with POSIX shells, you can use '[ -n "$LF_LEVEL" ] && PS1="$PS1""(lf level: $LF_LEVEL) "' in your shell configuration file (e.g. '~/.bashrc').
OPENER
If this variable is set in the environment, use the same value, otherwise set the value to 'start' in Windows, 'open' in MacOS, 'xdg-open' in others.
EDITOR
If this variable is set in the environment, use the same value, otherwise set the value to 'vi' on unix, 'notepad' in Windows.
PAGER
If this variable is set in the environment, use the same value, otherwise set the value to 'less' on unix, 'more' in Windows.
SHELL
If this variable is set in the environment, use the same value, otherwise set the value to 'sh' on unix, 'cmd' in Windows.
Prefixes Prefixes
The following command prefixes are used by lf: The following command prefixes are used by lf:
@@ -745,25 +1227,29 @@ If both of these environment variables are not set, then lf fallbacks to its
default colorscheme. Default lf colors are taken from GNU dircolors defaults. default colorscheme. Default lf colors are taken from GNU dircolors defaults.
These defaults use 8 basic colors and bold attribute. These defaults use 8 basic colors and bold attribute.
You should also note that lf uses 8 color mode by default which uses sgr 3-bit It is worth noting that lf uses as many colors are advertised by your terminal's
color escapes (e.g. '\033[34m'). If you want to use 256 colors, you need to entry in your systems terminfo or infocmp database, if this is not present lf
enable 'color256' option which then makes lf use sgr 8-bit color escapes (e.g. will default to an internal database. For terminals supporting 24-bit (or
'\033[38;5;4m'). This option is intended to eliminate differences between "true") color that do not have a database entry (or one that does not advertise
default colors used by ls and lf since terminals may render 3-bit and 8-bit all capabilities), support can be enabled by either setting the '$COLORTERM'
escapes differently even for the same color. variable to "truecolor" or ensuring '$TERM' is set to a value that ends with
"-truecolor".
Keeping this mechanism in mind, you can configure lf colors in two different Keeping this in mind, you can configure lf colors in two different ways. First,
ways. First, you can configure 8 basic colors used by your terminal and lf you can configure 8 basic colors used by your terminal and lf should pick up
should pick up those colors automatically. Depending on your terminal, you those colors automatically. Depending on your terminal, you should be able to
should be able to select your colors from a 24-bit palette. This is the select your colors from a 24-bit palette. This is the recommended approach as
recommended approach as colors used by other programs will also match each colors used by other programs will also match each other.
other.
Second, you can set the values of environmental variables mentioned above for Second, you can set the values of environmental variables mentioned above for
fine grained customization. This is useful to change colors used for different fine grained customization. This is useful to change colors used for different
file types and extensions. '$LS_COLORS' is more powerful than '$LSCOLORS' and file types and extensions. '$LS_COLORS' is more powerful than '$LSCOLORS' and it
it can be used even when GNU programs are not installed on the system. You can can be used even when GNU programs are not installed on the system. You can
combine this second method with the first method for best results. combine this second method with the first method for best results. lf can also
be configured to ignore your terminal theme and output colors "as they were
intended" by translating all numbered colors into a 24-bit output that matches
the description; this can be enabled by setting the environment variable
'$TCELL_TRUECOLOR' to "on" (or any text except ""/nothing or "disable").
Lastly, you may also want to configure the colors of the prompt line to match Lastly, you may also want to configure the colors of the prompt line to match
the rest of the colors. Colors of the prompt line can be configured using the the rest of the colors. Colors of the prompt line can be configured using the
+655 -119
View File
@@ -15,10 +15,11 @@ command (default '<f-1>') inside lf to view the documentation in a pager.
You can run 'lf -help' to see descriptions of command line options. You can run 'lf -help' to see descriptions of command line options.
Reference Quick Reference
The following commands are provided by lf with default keybindings: The following commands are provided by lf:
quit (default 'q')
up (default 'k' and '<up>') up (default 'k' and '<up>')
half-up (default '<c-u>') half-up (default '<c-u>')
page-up (default '<c-b>' and '<pgup>') page-up (default '<c-b>' and '<pgup>')
@@ -27,146 +28,132 @@ The following commands are provided by lf with default keybindings:
page-down (default '<c-f>' and '<pgdn>') page-down (default '<c-f>' and '<pgdn>')
updir (default 'h' and '<left>') updir (default 'h' and '<left>')
open (default 'l' and '<right>') open (default 'l' and '<right>')
quit (default 'q')
top (default 'gg' and '<home>') top (default 'gg' and '<home>')
bottom (default 'G' and '<end>') bottom (default 'G' and '<end>')
toggle
invert (default 'v') invert (default 'v')
unselect (default 'u') unselect (default 'u')
glob-select
glob-unselect
copy (default 'y') copy (default 'y')
cut (default 'd') cut (default 'd')
paste (default 'p') paste (default 'p')
clear (default 'c') clear (default 'c')
sync
draw
redraw (default '<c-l>') redraw (default '<c-l>')
load
reload (default '<c-r>') reload (default '<c-r>')
read (default ':') echo
rename (default 'r') echomsg
shell (default '$') echoerr
shell-pipe (default '%') cd
shell-wait (default '!') select
shell-async (default '&') delete (modal)
find (default 'f') rename (modal) (default 'r')
find-back (default 'F') source
push
read (modal) (default ':')
shell (modal) (default '$')
shell-pipe (modal) (default '%')
shell-wait (modal) (default '!')
shell-async (modal) (default '&')
find (modal) (default 'f')
find-back (modal) (default 'F')
find-next (default ';') find-next (default ';')
find-prev (default ',') find-prev (default ',')
search (default '/') search (modal) (default '/')
search-back (default '?') search-back (modal) (default '?')
search-next (default 'n') search-next (default 'n')
search-prev (default 'N') search-prev (default 'N')
mark-save (default 'm') mark-save (modal) (default 'm')
mark-load (default "'") mark-load (modal) (default "'")
mark-remove (default '"') mark-remove (modal) (default '"')
The following commands are provided by lf without default keybindings: The following command line commands are provided by lf:
draw draw the ui
load load modified files and directories
sync synchronize copied/cut files with server
echo print arguments to the message line
echomsg same as echo but logging
echoerr same as echomsg but red color
cd change working directory to the argument
select change current file selection to the argument
toggle toggle the selection of the current file or its arguments
glob-select select files that match the given glob
glob-unselect unselect files that match the given glob
source read the configuration file in the argument
push simulate key pushes given in the argument
delete remove the current file or selected file(s)
The following command line commands are provided by lf with default
keybindings:
cmd-escape (default '<esc>') cmd-escape (default '<esc>')
cmd-complete (default '<tab>') cmd-complete (default '<tab>')
cmd-enter (default '<c-j>' and '<enter>') cmd-enter (default '<c-j>' and '<enter>')
cmd-interrupt (default '<c-c>')
cmd-history-next (default '<c-n>') cmd-history-next (default '<c-n>')
cmd-history-prev (default '<c-p>') cmd-history-prev (default '<c-p>')
cmd-delete (default '<c-d>' and '<delete>')
cmd-delete-back (default '<bs>' and '<bs2>')
cmd-left (default '<c-b>' and '<left>') cmd-left (default '<c-b>' and '<left>')
cmd-right (default '<c-f>' and '<right>') cmd-right (default '<c-f>' and '<right>')
cmd-home (default '<c-a>' and '<home>') cmd-home (default '<c-a>' and '<home>')
cmd-end (default '<c-e>' and '<end>') cmd-end (default '<c-e>' and '<end>')
cmd-delete (default '<c-d>' and '<delete>')
cmd-delete-back (default '<backspace>' and '<backspace2>')
cmd-delete-home (default '<c-u>') cmd-delete-home (default '<c-u>')
cmd-delete-end (default '<c-k>') cmd-delete-end (default '<c-k>')
cmd-delete-unix-word (default '<c-w>') cmd-delete-unix-word (default '<c-w>')
cmd-yank (default '<c-y>') cmd-yank (default '<c-y>')
cmd-transpose (default '<c-t>') cmd-transpose (default '<c-t>')
cmd-interrupt (default '<c-c>') cmd-transpose-word (default '<a-t>')
cmd-word (default '<a-f>') cmd-word (default '<a-f>')
cmd-word-back (default '<a-b>') cmd-word-back (default '<a-b>')
cmd-capitalize-word (default '<a-c>')
cmd-delete-word (default '<a-d>') cmd-delete-word (default '<a-d>')
cmd-capitalize-word (default '<a-c>')
cmd-uppercase-word (default '<a-u>') cmd-uppercase-word (default '<a-u>')
cmd-lowercase-word (default '<a-l>') cmd-lowercase-word (default '<a-l>')
cmd-transpose-word (default '<a-t>')
The following options can be used to customize the behavior of lf: The following options can be used to customize the behavior of lf:
anchorfind boolean (default on) anchorfind bool (default on)
color256 boolean (default off) dircounts bool (default off)
dircounts boolean (default off) dirfirst bool (default on)
dirfirst boolean (default on) drawbox bool (default off)
drawbox boolean (default off) errorfmt string (default "\033[7;31;47m%s\033[0m")
globsearch boolean (default off) filesep string (default "\n")
hidden boolean (default off) findlen int (default 1)
icons boolean (default off) globsearch bool (default off)
ignorecase boolean (default on) hidden bool (default off)
ignoredia boolean (default off) hiddenfiles []string (default '.*')
incsearch boolean (default off) icons bool (default off)
number boolean (default off) ifs string (default '')
preview boolean (default on) ignorecase bool (default on)
relativenumber boolean (default off) ignoredia bool (default off)
reverse boolean (default off) incsearch bool (default off)
smartcase boolean (default on) info []string (default '')
smartdia boolean (default off) number bool (default off)
wrapscan boolean (default on) period int (default 0)
wrapscroll boolean (default off) preview bool (default on)
findlen integer (default 1) (zero to prompt until single match) previewer string (default '')
period integer (default 0) (zero to disable periodic loading) promptfmt string (default "\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f\033[0m")
scrolloff integer (default 0) ratios []int (default '1:2:3')
tabstop integer (default 8) relativenumber bool (default off)
errorfmt string (default "\033[7;31;47m%s\033[0m") reverse bool (default off)
filesep string (default "\n") scrolloff int (default 0)
hiddenfiles string (default '.*') shell string (default 'sh' for unix and 'cmd' for windows)
ifs string (default '') (not exported if empty) shellopts []string (default '')
info string (default '') smartcase bool (default on)
previewer string (default '') (not filtered if empty) smartdia bool (default off)
promptfmt string (default "\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f\033[0m") sortby string (default 'natural')
ratios string (default '1:2:3') tabstop int (default 8)
shell string (default 'sh') timefmt string (default 'Mon Jan _2 15:04:05 2006')
shellopts string (default '') truncatechar string (default '~')
sortby string (default 'natural') wrapscan bool (default on)
timefmt string (default 'Mon Jan _2 15:04:05 2006') wrapscroll bool (default off)
truncatechar string (default '~')
The following variables are exported for shell commands: The following environment variables are exported for shell commands:
$f current file f
$fs selected file(s) separated with 'filesep' fs
$fx current file or selected file(s) if any fx
$id id number of the client id
LF_LEVEL
OPENER
EDITOR
PAGER
SHELL
The following variables are set to the corresponding values: The following commands/keybindings are provided by default:
$LF_LEVEL current nesting level unix windows
cmd open &$OPENER "$f" cmd open &%OPENER% %f%
The following default values are set to the environmental variables on unix map e $$EDITOR "$f" map e $%EDITOR% %f%
when they are not set or empty: map i $$PAGER "$f" map i !%PAGER% %f%
map w $$SHELL map w $%SHELL%
$OPENER open # macos
$OPENER xdg-open # others
$EDITOR vi
$PAGER less
$SHELL sh
The following default values are set to the environmental variables on
windows when they are not set or empty:
%OPENER% start
%EDITOR% notepad
%PAGER% more
%SHELL% cmd
The following additional keybindings are provided by default: The following additional keybindings are provided by default:
@@ -185,12 +172,6 @@ The following additional keybindings are provided by default:
map gh cd ~ map gh cd ~
map <space> :toggle; down map <space> :toggle; down
The following keybindings to applications are provided by default:
map e $$EDITOR $f
map i $$PAGER $f
map w $$SHELL
Configuration Configuration
@@ -222,6 +203,557 @@ A sample configuration file can be found at
https://github.com/gokcehan/lf/blob/master/etc/lfrc.example. https://github.com/gokcehan/lf/blob/master/etc/lfrc.example.
Commands
This section shows information about builtin commands. Modal commands do not
take any arguments, but instead change the operation mode to read their
input conveniently, and so they are meant to be assigned to keybindings.
quit (default 'q')
Quit lf and return to the shell.
up (default 'k' and '<up>')
half-up (default '<c-u>')
page-up (default '<c-b>' and '<pgup>')
down (default 'j' and '<down>')
half-down (default '<c-d>')
page-down (default '<c-f>' and '<pgdn>')
Move the current file selection upwards/downwards by one/half a page/full
page.
updir (default 'h' and '<left>')
Change the current working directory to the parent directory.
open (default 'l' and '<right>')
If the current file is a directory, then change the current directory to it,
otherwise, execute the 'open' command. A default 'open' command is provided
to call the default system opener asynchronously with the current file as
the argument. A custom 'open' command can be defined to override this
default.
(See also 'OPENER' variable and 'Opening Files' section)
top (default 'gg' and '<home>')
bottom (default 'G' and '<end>')
Move the current file selection to the top/bottom of the directory.
toggle
Toggle the selection of the current file or files given as arguments.
invert (default 'v')
Reverse the selection of all files in the current directory (i.e. 'toggle'
all files). Selections in other directories are not effected by this
command. You can define a new command to select all files in the directory
by combining 'invert' with 'unselect' (i.e. 'cmd select-all :unselect;
invert'), though this will also remove selections in other directories.
unselect (default 'u')
Remove the selection of all files in all directories.
glob-select
Select files that match the given glob.
glob-unselect
Unselect files that match the given glob.
copy (default 'y')
If there are no selections, save the path of the current file to the copy
buffer, otherwise, copy the paths of selected files.
cut (default 'd')
If there are no selections, save the path of the current file to the cut
buffer, otherwise, copy the paths of selected files.
paste (default 'p')
Copy/Move files in copy/cut buffer to the current working directory.
clear (default 'c')
Clear file paths in copy/cut buffer.
sync
Synchronize copied/cut files with server. This command is automatically
called when required.
draw
Draw the screen. This command is automatically called when required.
redraw (default '<c-l>')
Synchronize the terminal and redraw the screen.
load
Load modified files and directories. This command is automatically called
when required.
reload (default '<c-r>')
Flush the cache and reload all files and directories.
echo
Print given arguments to the message line at the bottom.
echomsg
Print given arguments to the message line at the bottom and also to the log
file.
echoerr
Print given arguments to the message line at the bottom in red color and
also to the log file.
cd
Change the working directory to the given argument.
select
Change the current file selection to the given argument.
delete (modal)
Remove the current file or selected file(s).
rename (modal) (default 'r')
Rename the current file using the builtin method. A custom 'rename' command
can be defined to override this default.
source
Read the configuration file given in the argument.
push
Simulate key pushes given in the argument.
read (modal) (default ':')
Read a command to evaluate.
shell (modal) (default '$')
Read a shell command to execute.
(See also 'Prefixes' and 'Shell Commands' sections)
shell-pipe (modal) (default '%')
Read a shell command to execute piping its standard I/O to the bottom
statline.
(See also 'Prefixes' and 'Piping Shell Commands' sections)
shell-wait (modal) (default '!')
Read a shell command to execute and wait for a key press in the end.
(See also 'Prefixes' and 'Waiting Shell Commands' sections)
shell-async (modal) (default '&')
Read a shell command to execute synchronously without standard I/O.
find (modal) (default 'f')
find-back (modal) (default 'F')
find-next (default ';')
find-prev (default ',')
Read key(s) to find the appropriate file name match in the forward/backward
direction and jump to the next/previous match.
(See also 'anchorfind', 'findlen', 'wrapscan', 'ignorecase', 'smartcase',
'ignoredia', and 'smartdia' options and 'Searching Files' section)
search (default '/')
search-back (default '?')
search-next (default 'n')
search-prev (default 'N')
Read a pattern to search for a file name match in the forward/backward
direction and jump to the next/previous match.
(See also 'globsearch', 'incsearch', 'wrapscan', 'ignorecase', 'smartcase',
'ignoredia', and 'smartdia' options and 'Searching Files' section)
mark-save (modal) (default 'm')
Save the current directory as a bookmark assigned to the given key.
mark-load (modal) (default "'")
Change the current directory to the bookmark assigned to the given key. A
special bookmark "'" holds the previous directory after a 'mark-load', 'cd',
or 'select' command.
mark-remove (modal) (default '"')
Remove a bookmark assigned to the given key.
Command Line Commands
This section shows information about command line commands. These should be
mostly compatible with readline keybindings. A character refers to a unicode
code point, a word consists of letters and digits, and a unix word consists
of any non-blank characters.
cmd-escape (default '<esc>')
Quit command line mode and return to normal mode.
cmd-complete (default '<tab>')
Autocomplete the current word.
cmd-enter (default '<c-j>' and '<enter>')
Execute the current line.
cmd-interrupt (default '<c-c>')
Interrupt the current shell-pipe command and return to the normal mode.
cmd-history-next (default '<c-n>')
cmd-history-prev (default '<c-p>')
Go to next/previous item in the history.
cmd-left (default '<c-b>' and '<left>')
cmd-right (default '<c-f>' and '<right>')
Move the cursor to the left/right.
cmd-home (default '<c-a>' and '<home>')
cmd-end (default '<c-e>' and '<end>')
Move the cursor to the beginning/end of line.
cmd-delete (default '<c-d>' and '<delete>')
cmd-delete-back (default '<backspace>' and '<backspace2>')
Delete the next character in forward/backward direction.
cmd-delete-home (default '<c-u>')
cmd-delete-end (default '<c-k>')
Delete everything up to the beginning/end of line.
cmd-delete-unix-word (default '<c-w>')
Delete the previous unix word.
cmd-yank (default '<c-y>')
Paste the buffer content containing the last deleted item.
cmd-transpose (default '<c-t>')
cmd-transpose-word (default '<a-t>')
Transpose the positions of last two characters/words.
cmd-word (default '<a-f>')
cmd-word-back (default '<a-b>')
Move the cursor by one word in forward/backward direction.
cmd-delete-word (default '<a-d>')
Delete the next word in forward direction.
cmd-capitalize-word (default '<a-c>')
cmd-uppercase-word (default '<a-u>')
cmd-lowercase-word (default '<a-l>')
Capitalize/uppercase/lowercase the current word and jump to the next word.
Options
This section shows information about options to customize the behavior.
Character ':' is used as the separator for list options '[]int' and
'[]string'.
anchorfind bool (default on)
When this option is enabled, find command starts matching patterns from the
beginning of file names, otherwise, it can match at an arbitrary position.
dircounts bool (default off)
When this option is enabled, directory sizes show the number of items inside
instead of the size of directory file. The former needs to be calculated by
reading the directory and counting the items inside. The latter is directly
provided by the operating system and it does not require any calculation,
though it is non-intuitive and it can often be misleading. This option is
disabled by default for performance reasons. This option only has an effect
when 'info' has a 'size' field and the pane is wide enough to show the
information. A thousand items are counted per directory at most, and bigger
directories are shown as '999+'.
dirfirst bool (default on)
Show directories first above regular files.
drawbox bool (default off)
Draw boxes around panes with box drawing characters.
errorfmt string (default "\033[7;31;47m%s\033[0m")
Format string of error messages shown in the bottom message line.
filesep string (default "\n")
File separator used in environment variables 'fs' and 'fx'.
findlen int (default 1)
Number of characters prompted for the find command. When this value is set
to 0, find command prompts until there is only a single match left.
globsearch bool (default off)
When this option is enabled, search command patterns are considered as
globs, otherwise they are literals. With globbing, '*' matches any sequence,
'?' matches any character, and '[...]' or '[^...] matches character sets or
ranges. Otherwise, these characters are interpreted as they are.
hidden bool (default off)
Show hidden files. On unix systems, hidden files are determined by the value
of 'hiddenfiles'. On windows, only files with hidden attributes are
considered hidden files.
hiddenfiles []string (default '.*')
List of hidden file glob patterns. Patterns can be given as relative or
absolute paths. Globbing supports the usual special characters, '*' to match
any sequence, '?' to match any character, and '[...]' or '[^...] to match
character sets or ranges. In addition, if a pattern starts with '!', then
its matches are excluded from hidden files.
icons bool (default off)
Show icons before each item in the list. By default, only two icons, 🗀
(U+1F5C0) and 🗎 (U+1F5CE), are used for directories and files respectively,
as they are supported in the unicode standard. Icons can be configured with
an environment variable named 'LF_ICONS'. The syntax of this variable is
similar to 'LS_COLORS'. See the wiki page for an example icon configuration.
ifs string (default '')
Sets 'IFS' variable in shell commands. It works by adding the assignment to
the beginning of the command string as 'IFS='...'; ...'. The reason is that
'IFS' variable is not inherited by the shell for security reasons. This
method assumes a POSIX shell syntax and so it can fail for non-POSIX shells.
This option has no effect when the value is left empty. This option does not
have any effect on windows.
ignorecase bool (default on)
Ignore case in search patterns.
ignoredia bool (default off)
Ignore diacritics in search patterns.
incsearch bool (default off)
Jump to the first match after each keystroke during searching.
info []string (default '')
List of information shown for directory items at the right side of pane.
Currently supported information types are 'size', 'time', 'atime', and
'ctime'. Information is only shown when the pane width is more than twice
the width of information.
number bool (default off)
Show the position number for directory items at the left side of pane. When
'relativenumber' is enabled, only the current line shows the absolute
position and relative positions are shown for the rest.
period int (default 0)
Set the interval in seconds for periodic checks of directory updates. This
works by periodically calling the 'load' command. Note that directories are
already updated automatically in many cases. This option can be useful when
there is an external process changing the displayed directory and you are
not doing anything in lf. Periodic checks are disabled when the value of
this option is set to zero.
preview bool (default on)
Show previews of files and directories at the right most pane. If the file
has more lines than the preview pane, rest of the lines are not read. Files
containing the null character (U+0000) in the read portion are considered
binary files and displayed as 'binary'.
previewer string (default '') (not filtered if empty)
Set the path of a previewer file to filter the content of regular files for
previewing. The file should be executable. Two arguments are passed to the
file, first is the current file name, and second is the height of preview
pane. SIGPIPE signal is sent when enough lines are read. Preview filtering
is disabled and files are displayed as they are when the value of this
option is left empty.
promptfmt string (default "\033[32;1m%u@%h\033[0m:\033[34;1m%w/\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, 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.
ratios []int (default '1:2:3')
List of ratios of pane widths. Number of items in the list determines the
number of panes in the ui. When 'preview' option is enabled, the right most
number is used for the width of preview pane.
relativenumber bool (default off)
Show the position number relative to the current line. When 'number' is
enabled, current line shows the absolute position, otherwise nothing is
shown.
reverse bool (default off)
Reverse the direction of sort.
scrolloff int (default 0)
Minimum number of offset lines shown at all times in the top and the bottom
of the screen when scrolling. The current line is kept in the middle when
this option is set to a large value that is bigger than the half of number
of lines. A smaller offset can be used when the current file is close to the
beginning or end of the list to show the maximum number of items.
shell string (default 'sh' for unix and 'cmd' for windows)
Shell executable to use for shell commands. Shell commands are executed as
'shell shellopts -c command -- arguments'. On windows, '/c' is used instead
of '-c' which should work in 'cmd' and 'powershell'.
shellopts []string (default '')
List of shell options to pass to the shell executable.
smartcase bool (default on)
Override 'ignorecase' option when the pattern contains an uppercase
character. This option has no effect when 'ignorecase' is disabled.
smartdia bool (default off)
Override 'ignoredia' option when the pattern contains a character with
diacritic. This option has no effect when 'ignoredia' is disabled.
sortby string (default 'natural')
Sort type for directories. Currently supported sort types are 'natural',
'name', 'size', 'time', 'ctime', 'atime', and 'ext'.
tabstop int (default 8)
Number of space characters to show for horizontal tabulation (U+0009)
character.
timefmt string (default 'Mon Jan _2 15:04:05 2006')
Format string of the file modification time shown in the bottom line.
truncatechar string (default '~')
Truncate character shown at the end when the file name does not fit to the
pane.
wrapscan bool (default on)
Searching can wrap around the file list.
wrapscroll bool (default off)
Scrolling can wrap around the file list.
Environment Variables
The following variables are exported for shell commands: These are referred
with a '$' prefix on POSIX shells (e.g. '$f'), between '%' characters on
Windows cmd (e.g. '%f%'), and with a '$env:' prefix on Windows powershell
(e.g. '$env:f').
f
Current file selection as a full path.
fs
Selected file(s) separated with the value of 'filesep' option as full
path(s).
fx
Selected file(s) (i.e. 'fs') if there are any selected files, otherwise
current file selection (i.e. 'f').
id
Id of the running client.
LF_LEVEL
The value of this variable is set to the current nesting level when you run
lf from a shell spawned inside lf. You can add the value of this variable to
your shell prompt to make it clear that your shell runs inside lf. For
example, with POSIX shells, you can use '[ -n "$LF_LEVEL" ] &&
PS1="$PS1""(lf level: $LF_LEVEL) "' in your shell configuration file (e.g.
'~/.bashrc').
OPENER
If this variable is set in the environment, use the same value, otherwise
set the value to 'start' in Windows, 'open' in MacOS, 'xdg-open' in others.
EDITOR
If this variable is set in the environment, use the same value, otherwise
set the value to 'vi' on unix, 'notepad' in Windows.
PAGER
If this variable is set in the environment, use the same value, otherwise
set the value to 'less' on unix, 'more' in Windows.
SHELL
If this variable is set in the environment, use the same value, otherwise
set the value to 'sh' on unix, 'cmd' in Windows.
Prefixes Prefixes
The following command prefixes are used by lf: The following command prefixes are used by lf:
@@ -780,26 +1312,30 @@ If both of these environment variables are not set, then lf fallbacks to its
default colorscheme. Default lf colors are taken from GNU dircolors default colorscheme. Default lf colors are taken from GNU dircolors
defaults. These defaults use 8 basic colors and bold attribute. defaults. These defaults use 8 basic colors and bold attribute.
You should also note that lf uses 8 color mode by default which uses sgr It is worth noting that lf uses as many colors are advertised by your
3-bit color escapes (e.g. '\033[34m'). If you want to use 256 colors, you terminal's entry in your systems terminfo or infocmp database, if this is
need to enable 'color256' option which then makes lf use sgr 8-bit color not present lf will default to an internal database. For terminals
escapes (e.g. '\033[38;5;4m'). This option is intended to eliminate supporting 24-bit (or "true") color that do not have a database entry (or
differences between default colors used by ls and lf since terminals may one that does not advertise all capabilities), support can be enabled by
render 3-bit and 8-bit escapes differently even for the same color. either setting the '$COLORTERM' variable to "truecolor" or ensuring '$TERM'
is set to a value that ends with "-truecolor".
Keeping this mechanism in mind, you can configure lf colors in two different Keeping this in mind, you can configure lf colors in two different ways.
ways. First, you can configure 8 basic colors used by your terminal and lf First, you can configure 8 basic colors used by your terminal and lf should
should pick up those colors automatically. Depending on your terminal, you pick up those colors automatically. Depending on your terminal, you should
should be able to select your colors from a 24-bit palette. This is the be able to select your colors from a 24-bit palette. This is the recommended
recommended approach as colors used by other programs will also match each approach as colors used by other programs will also match each other.
other.
Second, you can set the values of environmental variables mentioned above Second, you can set the values of environmental variables mentioned above
for fine grained customization. This is useful to change colors used for for fine grained customization. This is useful to change colors used for
different file types and extensions. '$LS_COLORS' is more powerful than different file types and extensions. '$LS_COLORS' is more powerful than
'$LSCOLORS' and it can be used even when GNU programs are not installed on '$LSCOLORS' and it can be used even when GNU programs are not installed on
the system. You can combine this second method with the first method for the system. You can combine this second method with the first method for
best results. best results. lf can also be configured to ignore your terminal theme and
output colors "as they were intended" by translating all numbered colors
into a 24-bit output that matches the description; this can be enabled by
setting the environment variable '$TCELL_TRUECOLOR' to "on" (or any text
except ""/nothing or "disable").
Lastly, you may also want to configure the colors of the prompt line to Lastly, you may also want to configure the colors of the prompt line to
match the rest of the colors. Colors of the prompt line can be configured match the rest of the colors. Colors of the prompt line can be configured
+9 -18
View File
@@ -21,20 +21,11 @@ func (e *setExpr) eval(app *app, args []string) {
case "anchorfind!": case "anchorfind!":
gOpts.anchorfind = !gOpts.anchorfind gOpts.anchorfind = !gOpts.anchorfind
case "color256": case "color256":
gOpts.color256 = true app.ui.echoerr("option color256 is depreciated")
setColorMode()
app.ui.pause()
app.ui.resume()
case "nocolor256": case "nocolor256":
gOpts.color256 = false app.ui.echoerr("option nocolor256 is depreciated")
setColorMode()
app.ui.pause()
app.ui.resume()
case "color256!": case "color256!":
gOpts.color256 = !gOpts.color256 app.ui.echoerr("option color256! is depreciated")
setColorMode()
app.ui.pause()
app.ui.resume()
case "dircounts": case "dircounts":
gOpts.dircounts = true gOpts.dircounts = true
case "nodircounts": case "nodircounts":
@@ -284,7 +275,7 @@ func (e *setExpr) eval(app *app, args []string) {
return return
} }
gOpts.ratios = rats gOpts.ratios = rats
app.ui.wins = getWins() app.ui.wins = getWins(app.ui.screen)
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav)
case "shell": case "shell":
gOpts.shell = e.val gOpts.shell = e.val
@@ -793,13 +784,13 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "draw": case "draw":
case "redraw": case "redraw":
app.ui.sync()
app.ui.renew() app.ui.renew()
app.ui.screen.Sync()
app.nav.height = app.ui.wins[0].h app.nav.height = app.ui.wins[0].h
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav)
app.ui.loadFileInfo(app.nav)
case "load": case "load":
app.nav.renew() app.nav.renew()
app.ui.loadFile(app.nav)
case "reload": case "reload":
if err := app.nav.reload(); err != nil { if err := app.nav.reload(); err != nil {
app.ui.echoerrf("reload: %s", err) app.ui.echoerrf("reload: %s", err)
@@ -1021,8 +1012,8 @@ func (e *callExpr) eval(app *app, args []string) {
return return
} }
log.Println("pushing keys", e.args[0]) log.Println("pushing keys", e.args[0])
for _, key := range splitKeys(e.args[0]) { for _, val := range splitKeys(e.args[0]) {
app.ui.keyChan <- key app.ui.keyChan <- val
} }
case "cmd-insert": case "cmd-insert":
if len(e.args) == 0 { if len(e.args) == 0 {
@@ -1056,7 +1047,7 @@ func (e *callExpr) eval(app *app, args []string) {
} }
app.ui.draw(app.nav) app.ui.draw(app.nav)
if len(matches) > 1 { if len(matches) > 1 {
app.ui.menuBuf = listMatches(matches) app.ui.menuBuf = listMatches(app.ui.screen, matches)
} else { } else {
app.ui.menuBuf = nil app.ui.menuBuf = nil
} }
+18 -1
View File
@@ -14,12 +14,15 @@ set -o verbose
mkdir -p dist mkdir -p dist
CGO_ENABLED=0 GOOS=darwin GOARCH=386 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-darwin-386.tar.gz lf --remove-files # https://golang.org/doc/install/source#environment
CGO_ENABLED=0 GOOS=android GOARCH=arm64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-android-arm64.tar.gz lf --remove-files
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-darwin-amd64.tar.gz lf --remove-files CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-darwin-amd64.tar.gz lf --remove-files
CGO_ENABLED=0 GOOS=dragonfly GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-dragonfly-amd64.tar.gz lf --remove-files CGO_ENABLED=0 GOOS=dragonfly GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-dragonfly-amd64.tar.gz lf --remove-files
CGO_ENABLED=0 GOOS=freebsd GOARCH=386 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-freebsd-386.tar.gz lf --remove-files CGO_ENABLED=0 GOOS=freebsd GOARCH=386 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-freebsd-386.tar.gz lf --remove-files
CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-freebsd-amd64.tar.gz lf --remove-files CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-freebsd-amd64.tar.gz lf --remove-files
CGO_ENABLED=0 GOOS=freebsd GOARCH=arm go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-freebsd-arm.tar.gz lf --remove-files CGO_ENABLED=0 GOOS=freebsd GOARCH=arm go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-freebsd-arm.tar.gz lf --remove-files
CGO_ENABLED=0 GOOS=illumos GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-illumos-amd64.tar.gz lf --remove-files
CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-linux-386.tar.gz lf --remove-files CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-linux-386.tar.gz lf --remove-files
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-linux-amd64.tar.gz lf --remove-files CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-linux-amd64.tar.gz lf --remove-files
CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-linux-arm.tar.gz lf --remove-files CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-linux-arm.tar.gz lf --remove-files
@@ -30,12 +33,26 @@ CGO_ENABLED=0 GOOS=linux GOARCH=mips go build -ldflags="-s -w -X main.gV
CGO_ENABLED=0 GOOS=linux GOARCH=mipsle go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-linux-mipsle.tar.gz lf --remove-files CGO_ENABLED=0 GOOS=linux GOARCH=mipsle go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-linux-mipsle.tar.gz lf --remove-files
CGO_ENABLED=0 GOOS=linux GOARCH=mips64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-linux-mips64.tar.gz lf --remove-files CGO_ENABLED=0 GOOS=linux GOARCH=mips64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-linux-mips64.tar.gz lf --remove-files
CGO_ENABLED=0 GOOS=linux GOARCH=mips64le go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-linux-mips64le.tar.gz lf --remove-files CGO_ENABLED=0 GOOS=linux GOARCH=mips64le go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-linux-mips64le.tar.gz lf --remove-files
CGO_ENABLED=0 GOOS=linux GOARCH=s390x go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-linux-s390x.tar.gz lf --remove-files
CGO_ENABLED=0 GOOS=netbsd GOARCH=386 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-netbsd-386.tar.gz lf --remove-files CGO_ENABLED=0 GOOS=netbsd GOARCH=386 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-netbsd-386.tar.gz lf --remove-files
CGO_ENABLED=0 GOOS=netbsd GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-netbsd-amd64.tar.gz lf --remove-files CGO_ENABLED=0 GOOS=netbsd GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-netbsd-amd64.tar.gz lf --remove-files
CGO_ENABLED=0 GOOS=netbsd GOARCH=arm go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-netbsd-arm.tar.gz lf --remove-files CGO_ENABLED=0 GOOS=netbsd GOARCH=arm go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-netbsd-arm.tar.gz lf --remove-files
CGO_ENABLED=0 GOOS=openbsd GOARCH=386 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-openbsd-386.tar.gz lf --remove-files CGO_ENABLED=0 GOOS=openbsd GOARCH=386 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-openbsd-386.tar.gz lf --remove-files
CGO_ENABLED=0 GOOS=openbsd GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-openbsd-amd64.tar.gz lf --remove-files CGO_ENABLED=0 GOOS=openbsd GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-openbsd-amd64.tar.gz lf --remove-files
CGO_ENABLED=0 GOOS=openbsd GOARCH=arm go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-openbsd-arm.tar.gz lf --remove-files CGO_ENABLED=0 GOOS=openbsd GOARCH=arm go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-openbsd-arm.tar.gz lf --remove-files
CGO_ENABLED=0 GOOS=openbsd GOARCH=arm64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-openbsd-arm64.tar.gz lf --remove-files
CGO_ENABLED=0 GOOS=solaris GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-solaris-amd64.tar.gz lf --remove-files
CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -ldflags="-s -w -X main.gVersion=$version" && zip dist/lf-windows-386.zip lf.exe --move CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -ldflags="-s -w -X main.gVersion=$version" && zip dist/lf-windows-386.zip lf.exe --move
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && zip dist/lf-windows-amd64.zip lf.exe --move CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && zip dist/lf-windows-amd64.zip lf.exe --move
# not supported
# CGO_ENABLED=0 GOOS=aix GOARCH=ppc64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-aix-ppc64.tar.gz lf --remove-files
# CGO_ENABLED=0 GOOS=android GOARCH=386 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-android-386.tar.gz lf --remove-files
# CGO_ENABLED=0 GOOS=android GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-android-amd64.tar.gz lf --remove-files
# CGO_ENABLED=0 GOOS=android GOARCH=arm go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-android-arm.tar.gz lf --remove-files
# CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-darwin-arm64.tar.gz lf --remove-files
# CGO_ENABLED=0 GOOS=js GOARCH=wasm go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-js-wasm.tar.gz lf --remove-files
# CGO_ENABLED=0 GOOS=plan9 GOARCH=386 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-plan9-386.tar.gz lf --remove-files
# CGO_ENABLED=0 GOOS=plan9 GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-plan9-amd64.tar.gz lf --remove-files
# CGO_ENABLED=0 GOOS=plan9 GOARCH=arm go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-plan9-arm.tar.gz lf --remove-files
+1 -1
View File
@@ -3,7 +3,7 @@ module github.com/gokcehan/lf
go 1.12 go 1.12
require ( require (
github.com/doronbehar/termbox-go v0.0.0-20200711071547-71407e3bfa14 github.com/gdamore/tcell v1.3.0
github.com/mattn/go-runewidth v0.0.9 github.com/mattn/go-runewidth v0.0.9
gopkg.in/djherbis/times.v1 v1.2.0 gopkg.in/djherbis/times.v1 v1.2.0
) )
+13 -2
View File
@@ -1,6 +1,17 @@
github.com/doronbehar/termbox-go v0.0.0-20200711071547-71407e3bfa14 h1:KKPl27Vj3HRF384G7jW7K8uCRv0Ks+GuAOkGsz4qWAs= github.com/DATA-DOG/go-sqlmock v1.3.3 h1:CWUqKXe0s8A2z6qCgkP4Kru7wC11YoAnoupUKFDnH08=
github.com/doronbehar/termbox-go v0.0.0-20200711071547-71407e3bfa14/go.mod h1:cHYbFQiZNC8LPG6clYoLMKAl0xx7KR75RPsHtG/f1Hk= github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
github.com/gdamore/tcell v1.3.0 h1:r35w0JBADPZCVQijYebl6YMWWtHRqVEGt7kL2eBADRM=
github.com/gdamore/tcell v1.3.0/go.mod h1:Hjvr+Ofd+gLglo7RYKxxnzCBmev3BzsS67MebKS4zMM=
github.com/lucasb-eyer/go-colorful v1.0.2 h1:mCMFu6PgSozg9tDNMMK3g18oJBX7oYGrC09mS6CXfO4=
github.com/lucasb-eyer/go-colorful v1.0.2/go.mod h1:0MS4r+7BZKSJ5mw4/S5MPN+qHFF1fYclkSPilDOKW0s=
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756 h1:9nuHUbU8dRnRRfj9KjWUVrJeoexdbeMjttk6Oh1rD10=
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/djherbis/times.v1 v1.2.0 h1:UCvDKl1L/fmBygl2Y7hubXCnY7t4Yj46ZrBFNUipFbM= gopkg.in/djherbis/times.v1 v1.2.0 h1:UCvDKl1L/fmBygl2Y7hubXCnY7t4Yj46ZrBFNUipFbM=
gopkg.in/djherbis/times.v1 v1.2.0/go.mod h1:AQlg6unIsrsCEdQYhTzERy542dz6SFdQFZFv6mUY0P8= gopkg.in/djherbis/times.v1 v1.2.0/go.mod h1:AQlg6unIsrsCEdQYhTzERy542dz6SFdQFZFv6mUY0P8=
+713 -114
View File
@@ -22,10 +22,11 @@ Source code can be found in the repository at https://github.com/gokcehan/lf.
This documentation can either be read from terminal using 'lf -doc' or online at https://godoc.org/github.com/gokcehan/lf. You can also use 'doc' command (default '<f-1>') inside lf to view the documentation in a pager. This documentation can either be read from terminal using 'lf -doc' or online at https://godoc.org/github.com/gokcehan/lf. You can also use 'doc' command (default '<f-1>') inside lf to view the documentation in a pager.
.PP .PP
You can run 'lf -help' to see descriptions of command line options. You can run 'lf -help' to see descriptions of command line options.
.SH REFERENCE .SH QUICK REFERENCE
The following commands are provided by lf with default keybindings: The following commands are provided by lf:
.PP .PP
.EX .EX
quit (default 'q')
up (default 'k' and '<up>') up (default 'k' and '<up>')
half-up (default '<c-u>') half-up (default '<c-u>')
page-up (default '<c-b>' and '<pgup>') page-up (default '<c-b>' and '<pgup>')
@@ -34,157 +35,140 @@ The following commands are provided by lf with default keybindings:
page-down (default '<c-f>' and '<pgdn>') page-down (default '<c-f>' and '<pgdn>')
updir (default 'h' and '<left>') updir (default 'h' and '<left>')
open (default 'l' and '<right>') open (default 'l' and '<right>')
quit (default 'q')
top (default 'gg' and '<home>') top (default 'gg' and '<home>')
bottom (default 'G' and '<end>') bottom (default 'G' and '<end>')
toggle
invert (default 'v') invert (default 'v')
unselect (default 'u') unselect (default 'u')
glob-select
glob-unselect
copy (default 'y') copy (default 'y')
cut (default 'd') cut (default 'd')
paste (default 'p') paste (default 'p')
clear (default 'c') clear (default 'c')
sync
draw
redraw (default '<c-l>') redraw (default '<c-l>')
load
reload (default '<c-r>') reload (default '<c-r>')
read (default ':') echo
rename (default 'r') echomsg
shell (default '$') echoerr
shell-pipe (default '%') cd
shell-wait (default '!') select
shell-async (default '&') delete (modal)
find (default 'f') rename (modal) (default 'r')
find-back (default 'F') source
push
read (modal) (default ':')
shell (modal) (default '$')
shell-pipe (modal) (default '%')
shell-wait (modal) (default '!')
shell-async (modal) (default '&')
find (modal) (default 'f')
find-back (modal) (default 'F')
find-next (default ';') find-next (default ';')
find-prev (default ',') find-prev (default ',')
search (default '/') search (modal) (default '/')
search-back (default '?') search-back (modal) (default '?')
search-next (default 'n') search-next (default 'n')
search-prev (default 'N') search-prev (default 'N')
mark-save (default 'm') mark-save (modal) (default 'm')
mark-load (default "'") mark-load (modal) (default "'")
mark-remove (default `"`) mark-remove (modal) (default `"`)
.EE .EE
.PP .PP
The following commands are provided by lf without default keybindings: The following command line commands are provided by lf:
.PP
.EX
draw draw the ui
load load modified files and directories
sync synchronize copied/cut files with server
echo print arguments to the message line
echomsg same as echo but logging
echoerr same as echomsg but red color
cd change working directory to the argument
select change current file selection to the argument
toggle toggle the selection of the current file or its arguments
glob-select select files that match the given glob
glob-unselect unselect files that match the given glob
source read the configuration file in the argument
push simulate key pushes given in the argument
delete remove the current file or selected file(s)
.EE
.PP
The following command line commands are provided by lf with default keybindings:
.PP .PP
.EX .EX
cmd-escape (default '<esc>') cmd-escape (default '<esc>')
cmd-complete (default '<tab>') cmd-complete (default '<tab>')
cmd-enter (default '<c-j>' and '<enter>') cmd-enter (default '<c-j>' and '<enter>')
cmd-interrupt (default '<c-c>')
cmd-history-next (default '<c-n>') cmd-history-next (default '<c-n>')
cmd-history-prev (default '<c-p>') cmd-history-prev (default '<c-p>')
cmd-delete (default '<c-d>' and '<delete>')
cmd-delete-back (default '<bs>' and '<bs2>')
cmd-left (default '<c-b>' and '<left>') cmd-left (default '<c-b>' and '<left>')
cmd-right (default '<c-f>' and '<right>') cmd-right (default '<c-f>' and '<right>')
cmd-home (default '<c-a>' and '<home>') cmd-home (default '<c-a>' and '<home>')
cmd-end (default '<c-e>' and '<end>') cmd-end (default '<c-e>' and '<end>')
cmd-delete (default '<c-d>' and '<delete>')
cmd-delete-back (default '<backspace>' and '<backspace2>')
cmd-delete-home (default '<c-u>') cmd-delete-home (default '<c-u>')
cmd-delete-end (default '<c-k>') cmd-delete-end (default '<c-k>')
cmd-delete-unix-word (default '<c-w>') cmd-delete-unix-word (default '<c-w>')
cmd-yank (default '<c-y>') cmd-yank (default '<c-y>')
cmd-transpose (default '<c-t>') cmd-transpose (default '<c-t>')
cmd-interrupt (default '<c-c>') cmd-transpose-word (default '<a-t>')
cmd-word (default '<a-f>') cmd-word (default '<a-f>')
cmd-word-back (default '<a-b>') cmd-word-back (default '<a-b>')
cmd-capitalize-word (default '<a-c>')
cmd-delete-word (default '<a-d>') cmd-delete-word (default '<a-d>')
cmd-capitalize-word (default '<a-c>')
cmd-uppercase-word (default '<a-u>') cmd-uppercase-word (default '<a-u>')
cmd-lowercase-word (default '<a-l>') cmd-lowercase-word (default '<a-l>')
cmd-transpose-word (default '<a-t>')
.EE .EE
.PP .PP
The following options can be used to customize the behavior of lf: The following options can be used to customize the behavior of lf:
.PP .PP
.EX .EX
anchorfind boolean (default on) anchorfind bool (default on)
color256 boolean (default off) dircounts bool (default off)
dircounts boolean (default off) dirfirst bool (default on)
dirfirst boolean (default on) drawbox bool (default off)
drawbox boolean (default off) errorfmt string (default "\e033[7;31;47m%s\e033[0m")
globsearch boolean (default off) filesep string (default "\en")
hidden boolean (default off) findlen int (default 1)
icons boolean (default off) globsearch bool (default off)
ignorecase boolean (default on) hidden bool (default off)
ignoredia boolean (default off) hiddenfiles []string (default '.*')
incsearch boolean (default off) icons bool (default off)
number boolean (default off) ifs string (default '')
preview boolean (default on) ignorecase bool (default on)
relativenumber boolean (default off) ignoredia bool (default off)
reverse boolean (default off) incsearch bool (default off)
smartcase boolean (default on) info []string (default '')
smartdia boolean (default off) number bool (default off)
wrapscan boolean (default on) period int (default 0)
wrapscroll boolean (default off) preview bool (default on)
findlen integer (default 1) (zero to prompt until single match) previewer string (default '')
period integer (default 0) (zero to disable periodic loading) promptfmt string (default "\e033[32;1m%u@%h\e033[0m:\e033[34;1m%w/\e033[0m\e033[1m%f\e033[0m")
scrolloff integer (default 0) ratios []int (default '1:2:3')
tabstop integer (default 8) relativenumber bool (default off)
errorfmt string (default "\e033[7;31;47m%s\e033[0m") reverse bool (default off)
filesep string (default "\en") scrolloff int (default 0)
hiddenfiles string (default '.*') shell string (default 'sh' for unix and 'cmd' for windows)
ifs string (default '') (not exported if empty) shellopts []string (default '')
info string (default '') smartcase bool (default on)
previewer string (default '') (not filtered if empty) smartdia bool (default off)
promptfmt string (default "\e033[32;1m%u@%h\e033[0m:\e033[34;1m%w/\e033[0m\e033[1m%f\e033[0m") sortby string (default 'natural')
ratios string (default '1:2:3') tabstop int (default 8)
shell string (default 'sh') timefmt string (default 'Mon Jan _2 15:04:05 2006')
shellopts string (default '') truncatechar string (default '~')
sortby string (default 'natural') wrapscan bool (default on)
timefmt string (default 'Mon Jan _2 15:04:05 2006') wrapscroll bool (default off)
truncatechar string (default '~')
.EE .EE
.PP .PP
The following variables are exported for shell commands: The following environment variables are exported for shell commands:
.PP .PP
.EX .EX
$f current file f
$fs selected file(s) separated with 'filesep' fs
$fx current file or selected file(s) if any fx
$id id number of the client id
LF_LEVEL
OPENER
EDITOR
PAGER
SHELL
.EE .EE
.PP .PP
The following variables are set to the corresponding values: The following commands/keybindings are provided by default:
.PP .PP
.EX .EX
$LF_LEVEL current nesting level unix windows
.EE cmd open &$OPENER "$f" cmd open &%OPENER% %f%
.PP map e $$EDITOR "$f" map e $%EDITOR% %f%
The following default values are set to the environmental variables on unix when they are not set or empty: map i $$PAGER "$f" map i !%PAGER% %f%
.PP map w $$SHELL map w $%SHELL%
.EX
$OPENER open # macos
$OPENER xdg-open # others
$EDITOR vi
$PAGER less
$SHELL sh
.EE
.PP
The following default values are set to the environmental variables on windows when they are not set or empty:
.PP
.EX
%OPENER% start
%EDITOR% notepad
%PAGER% more
%SHELL% cmd
.EE .EE
.PP .PP
The following additional keybindings are provided by default: The following additional keybindings are provided by default:
@@ -205,14 +189,6 @@ The following additional keybindings are provided by default:
map gh cd ~ map gh cd ~
map <space> :toggle; down map <space> :toggle; down
.EE .EE
.PP
The following keybindings to applications are provided by default:
.PP
.EX
map e $$EDITOR $f
map i $$PAGER $f
map w $$SHELL
.EE
.SH CONFIGURATION .SH CONFIGURATION
Configuration files should be located at: Configuration files should be located at:
.PP .PP
@@ -246,6 +222,629 @@ You can configure the default values of following variables to change these loca
.EE .EE
.PP .PP
A sample configuration file can be found at https://github.com/gokcehan/lf/blob/master/etc/lfrc.example. A sample configuration file can be found at https://github.com/gokcehan/lf/blob/master/etc/lfrc.example.
.SH COMMANDS
This section shows information about builtin commands. Modal commands do not take any arguments, but instead change the operation mode to read their input conveniently, and so they are meant to be assigned to keybindings.
.PP
.EX
quit (default 'q')
.EE
.PP
Quit lf and return to the shell.
.PP
.EX
up (default 'k' and '<up>')
half-up (default '<c-u>')
page-up (default '<c-b>' and '<pgup>')
down (default 'j' and '<down>')
half-down (default '<c-d>')
page-down (default '<c-f>' and '<pgdn>')
.EE
.PP
Move the current file selection upwards/downwards by one/half a page/full page.
.PP
.EX
updir (default 'h' and '<left>')
.EE
.PP
Change the current working directory to the parent directory.
.PP
.EX
open (default 'l' and '<right>')
.EE
.PP
If the current file is a directory, then change the current directory to it, otherwise, execute the 'open' command. A default 'open' command is provided to call the default system opener asynchronously with the current file as the argument. A custom 'open' command can be defined to override this default.
.PP
(See also 'OPENER' variable and 'Opening Files' section)
.PP
.EX
top (default 'gg' and '<home>')
bottom (default 'G' and '<end>')
.EE
.PP
Move the current file selection to the top/bottom of the directory.
.PP
.EX
toggle
.EE
.PP
Toggle the selection of the current file or files given as arguments.
.PP
.EX
invert (default 'v')
.EE
.PP
Reverse the selection of all files in the current directory (i.e. 'toggle' all files). Selections in other directories are not effected by this command. You can define a new command to select all files in the directory by combining 'invert' with 'unselect' (i.e. `cmd select-all :unselect; invert`), though this will also remove selections in other directories.
.PP
.EX
unselect (default 'u')
.EE
.PP
Remove the selection of all files in all directories.
.PP
.EX
glob-select
.EE
.PP
Select files that match the given glob.
.PP
.EX
glob-unselect
.EE
.PP
Unselect files that match the given glob.
.PP
.EX
copy (default 'y')
.EE
.PP
If there are no selections, save the path of the current file to the copy buffer, otherwise, copy the paths of selected files.
.PP
.EX
cut (default 'd')
.EE
.PP
If there are no selections, save the path of the current file to the cut buffer, otherwise, copy the paths of selected files.
.PP
.EX
paste (default 'p')
.EE
.PP
Copy/Move files in copy/cut buffer to the current working directory.
.PP
.EX
clear (default 'c')
.EE
.PP
Clear file paths in copy/cut buffer.
.PP
.EX
sync
.EE
.PP
Synchronize copied/cut files with server. This command is automatically called when required.
.PP
.EX
draw
.EE
.PP
Draw the screen. This command is automatically called when required.
.PP
.EX
redraw (default '<c-l>')
.EE
.PP
Synchronize the terminal and redraw the screen.
.PP
.EX
load
.EE
.PP
Load modified files and directories. This command is automatically called when required.
.PP
.EX
reload (default '<c-r>')
.EE
.PP
Flush the cache and reload all files and directories.
.PP
.EX
echo
.EE
.PP
Print given arguments to the message line at the bottom.
.PP
.EX
echomsg
.EE
.PP
Print given arguments to the message line at the bottom and also to the log file.
.PP
.EX
echoerr
.EE
.PP
Print given arguments to the message line at the bottom in red color and also to the log file.
.PP
.EX
cd
.EE
.PP
Change the working directory to the given argument.
.PP
.EX
select
.EE
.PP
Change the current file selection to the given argument.
.PP
.EX
delete (modal)
.EE
.PP
Remove the current file or selected file(s).
.PP
.EX
rename (modal) (default 'r')
.EE
.PP
Rename the current file using the builtin method. A custom 'rename' command can be defined to override this default.
.PP
.EX
source
.EE
.PP
Read the configuration file given in the argument.
.PP
.EX
push
.EE
.PP
Simulate key pushes given in the argument.
.PP
.EX
read (modal) (default ':')
.EE
.PP
Read a command to evaluate.
.PP
.EX
shell (modal) (default '$')
.EE
.PP
Read a shell command to execute.
.PP
(See also 'Prefixes' and 'Shell Commands' sections)
.PP
.EX
shell-pipe (modal) (default '%')
.EE
.PP
Read a shell command to execute piping its standard I/O to the bottom statline.
.PP
(See also 'Prefixes' and 'Piping Shell Commands' sections)
.PP
.EX
shell-wait (modal) (default '!')
.EE
.PP
Read a shell command to execute and wait for a key press in the end.
.PP
(See also 'Prefixes' and 'Waiting Shell Commands' sections)
.PP
.EX
shell-async (modal) (default '&')
.EE
.PP
Read a shell command to execute synchronously without standard I/O.
.PP
.EX
find (modal) (default 'f')
find-back (modal) (default 'F')
find-next (default ';')
find-prev (default ',')
.EE
.PP
Read key(s) to find the appropriate file name match in the forward/backward direction and jump to the next/previous match.
.PP
(See also 'anchorfind', 'findlen', 'wrapscan', 'ignorecase', 'smartcase', 'ignoredia', and 'smartdia' options and 'Searching Files' section)
.PP
.EX
search (default '/')
search-back (default '?')
search-next (default 'n')
search-prev (default 'N')
.EE
.PP
Read a pattern to search for a file name match in the forward/backward direction and jump to the next/previous match.
.PP
(See also 'globsearch', 'incsearch', 'wrapscan', 'ignorecase', 'smartcase', 'ignoredia', and 'smartdia' options and 'Searching Files' section)
.PP
.EX
mark-save (modal) (default 'm')
.EE
.PP
Save the current directory as a bookmark assigned to the given key.
.PP
.EX
mark-load (modal) (default "'")
.EE
.PP
Change the current directory to the bookmark assigned to the given key. A special bookmark "'" holds the previous directory after a 'mark-load', 'cd', or 'select' command.
.PP
.EX
mark-remove (modal) (default `"`)
.EE
.PP
Remove a bookmark assigned to the given key.
.SH COMMAND LINE COMMANDS
This section shows information about command line commands. These should be mostly compatible with readline keybindings. A character refers to a unicode code point, a word consists of letters and digits, and a unix word consists of any non-blank characters.
.PP
.EX
cmd-escape (default '<esc>')
.EE
.PP
Quit command line mode and return to normal mode.
.PP
.EX
cmd-complete (default '<tab>')
.EE
.PP
Autocomplete the current word.
.PP
.EX
cmd-enter (default '<c-j>' and '<enter>')
.EE
.PP
Execute the current line.
.PP
.EX
cmd-interrupt (default '<c-c>')
.EE
.PP
Interrupt the current shell-pipe command and return to the normal mode.
.PP
.EX
cmd-history-next (default '<c-n>')
cmd-history-prev (default '<c-p>')
.EE
.PP
Go to next/previous item in the history.
.PP
.EX
cmd-left (default '<c-b>' and '<left>')
cmd-right (default '<c-f>' and '<right>')
.EE
.PP
Move the cursor to the left/right.
.PP
.EX
cmd-home (default '<c-a>' and '<home>')
cmd-end (default '<c-e>' and '<end>')
.EE
.PP
Move the cursor to the beginning/end of line.
.PP
.EX
cmd-delete (default '<c-d>' and '<delete>')
cmd-delete-back (default '<backspace>' and '<backspace2>')
.EE
.PP
Delete the next character in forward/backward direction.
.PP
.EX
cmd-delete-home (default '<c-u>')
cmd-delete-end (default '<c-k>')
.EE
.PP
Delete everything up to the beginning/end of line.
.PP
.EX
cmd-delete-unix-word (default '<c-w>')
.EE
.PP
Delete the previous unix word.
.PP
.EX
cmd-yank (default '<c-y>')
.EE
.PP
Paste the buffer content containing the last deleted item.
.PP
.EX
cmd-transpose (default '<c-t>')
cmd-transpose-word (default '<a-t>')
.EE
.PP
Transpose the positions of last two characters/words.
.PP
.EX
cmd-word (default '<a-f>')
cmd-word-back (default '<a-b>')
.EE
.PP
Move the cursor by one word in forward/backward direction.
.PP
.EX
cmd-delete-word (default '<a-d>')
.EE
.PP
Delete the next word in forward direction.
.PP
.EX
cmd-capitalize-word (default '<a-c>')
cmd-uppercase-word (default '<a-u>')
cmd-lowercase-word (default '<a-l>')
.EE
.PP
Capitalize/uppercase/lowercase the current word and jump to the next word.
.SH OPTIONS
This section shows information about options to customize the behavior. Character ':' is used as the separator for list options '[]int' and '[]string'.
.PP
.EX
anchorfind bool (default on)
.EE
.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
dircounts bool (default off)
.EE
.PP
When this option is enabled, directory sizes show the number of items inside instead of the size of directory file. The former needs to be calculated by reading the directory and counting the items inside. The latter is directly provided by the operating system and it does not require any calculation, though it is non-intuitive and it can often be misleading. This option is disabled by default for performance reasons. This option only has an effect when 'info' has a 'size' field and the pane is wide enough to show the information. A thousand items are counted per directory at most, and bigger directories are shown as '999+'.
.PP
.EX
dirfirst bool (default on)
.EE
.PP
Show directories first above regular files.
.PP
.EX
drawbox bool (default off)
.EE
.PP
Draw boxes around panes with box drawing characters.
.PP
.EX
errorfmt string (default "\e033[7;31;47m%s\e033[0m")
.EE
.PP
Format string of error messages shown in the bottom message line.
.PP
.EX
filesep string (default "\en")
.EE
.PP
File separator used in environment variables 'fs' and 'fx'.
.PP
.EX
findlen int (default 1)
.EE
.PP
Number of characters prompted for the find command. When this value is set to 0, find command prompts until there is only a single match left.
.PP
.EX
globsearch bool (default off)
.EE
.PP
When this option is enabled, search command patterns are considered as globs, otherwise they are literals. With globbing, '*' matches any sequence, '?' matches any character, and '[...]' or '[^...] matches character sets or ranges. Otherwise, these characters are interpreted as they are.
.PP
.EX
hidden bool (default off)
.EE
.PP
Show hidden files. On unix systems, hidden files are determined by the value of 'hiddenfiles'. On windows, only files with hidden attributes are considered hidden files.
.PP
.EX
hiddenfiles []string (default '.*')
.EE
.PP
List of hidden file glob patterns. Patterns can be given as relative or absolute paths. Globbing supports the usual special characters, '*' to match any sequence, '?' to match any character, and '[...]' or '[^...] to match character sets or ranges. In addition, if a pattern starts with '!', then its matches are excluded from hidden files.
.PP
.EX
icons bool (default off)
.EE
.PP
Show icons before each item in the list. By default, only two icons, 🗀 (U+1F5C0) and 🗎 (U+1F5CE), are used for directories and files respectively, as they are supported in the unicode standard. Icons can be configured with an environment variable named 'LF_ICONS'. The syntax of this variable is similar to 'LS_COLORS'. See the wiki page for an example icon configuration.
.PP
.EX
ifs string (default '')
.EE
.PP
Sets 'IFS' variable in shell commands. It works by adding the assignment to the beginning of the command string as 'IFS='...'; ...'. The reason is that 'IFS' variable is not inherited by the shell for security reasons. This method assumes a POSIX shell syntax and so it can fail for non-POSIX shells. This option has no effect when the value is left empty. This option does not have any effect on windows.
.PP
.EX
ignorecase bool (default on)
.EE
.PP
Ignore case in search patterns.
.PP
.EX
ignoredia bool (default off)
.EE
.PP
Ignore diacritics in search patterns.
.PP
.EX
incsearch bool (default off)
.EE
.PP
Jump to the first match after each keystroke during searching.
.PP
.EX
info []string (default '')
.EE
.PP
List of information shown for directory items at the right side of pane. Currently supported information types are 'size', 'time', 'atime', and 'ctime'. Information is only shown when the pane width is more than twice the width of information.
.PP
.EX
number bool (default off)
.EE
.PP
Show the position number for directory items at the left side of pane. When 'relativenumber' is enabled, only the current line shows the absolute position and relative positions are shown for the rest.
.PP
.EX
period int (default 0)
.EE
.PP
Set the interval in seconds for periodic checks of directory updates. This works by periodically calling the 'load' command. Note that directories are already updated automatically in many cases. This option can be useful when there is an external process changing the displayed directory and you are not doing anything in lf. Periodic checks are disabled when the value of this option is set to zero.
.PP
.EX
preview bool (default on)
.EE
.PP
Show previews of files and directories at the right most pane. If the file has more lines than the preview pane, rest of the lines are not read. Files containing the null character (U+0000) in the read portion are considered binary files and displayed as 'binary'.
.PP
.EX
previewer string (default '') (not filtered if empty)
.EE
.PP
Set the path of a previewer file to filter the content of regular files for previewing. The file should be executable. Two arguments are passed to the file, first is the current file name, and second is the height of preview pane. SIGPIPE signal is sent when enough lines are read. Preview filtering is disabled and files are displayed as they are when the value of this option is left empty.
.PP
.EX
promptfmt string (default "\e033[32;1m%u@%h\e033[0m:\e033[34;1m%w/\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, 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.
.PP
.EX
ratios []int (default '1:2:3')
.EE
.PP
List of ratios of pane widths. Number of items in the list determines the number of panes in the ui. When 'preview' option is enabled, the right most number is used for the width of preview pane.
.PP
.EX
relativenumber bool (default off)
.EE
.PP
Show the position number relative to the current line. When 'number' is enabled, current line shows the absolute position, otherwise nothing is shown.
.PP
.EX
reverse bool (default off)
.EE
.PP
Reverse the direction of sort.
.PP
.EX
scrolloff int (default 0)
.EE
.PP
Minimum number of offset lines shown at all times in the top and the bottom of the screen when scrolling. The current line is kept in the middle when this option is set to a large value that is bigger than the half of number of lines. A smaller offset can be used when the current file is close to the beginning or end of the list to show the maximum number of items.
.PP
.EX
shell string (default 'sh' for unix and 'cmd' for windows)
.EE
.PP
Shell executable to use for shell commands. Shell commands are executed as 'shell shellopts -c command -- arguments'. On windows, '/c' is used instead of '-c' which should work in 'cmd' and 'powershell'.
.PP
.EX
shellopts []string (default '')
.EE
.PP
List of shell options to pass to the shell executable.
.PP
.EX
smartcase bool (default on)
.EE
.PP
Override 'ignorecase' option when the pattern contains an uppercase character. This option has no effect when 'ignorecase' is disabled.
.PP
.EX
smartdia bool (default off)
.EE
.PP
Override 'ignoredia' option when the pattern contains a character with diacritic. This option has no effect when 'ignoredia' is disabled.
.PP
.EX
sortby string (default 'natural')
.EE
.PP
Sort type for directories. Currently supported sort types are 'natural', 'name', 'size', 'time', 'ctime', 'atime', and 'ext'.
.PP
.EX
tabstop int (default 8)
.EE
.PP
Number of space characters to show for horizontal tabulation (U+0009) character.
.PP
.EX
timefmt string (default 'Mon Jan _2 15:04:05 2006')
.EE
.PP
Format string of the file modification time shown in the bottom line.
.PP
.EX
truncatechar string (default '~')
.EE
.PP
Truncate character shown at the end when the file name does not fit to the pane.
.PP
.EX
wrapscan bool (default on)
.EE
.PP
Searching can wrap around the file list.
.PP
.EX
wrapscroll bool (default off)
.EE
.PP
Scrolling can wrap around the file list.
.SH ENVIRONMENT VARIABLES
The following variables are exported for shell commands: These are referred with a '$' prefix on POSIX shells (e.g. '$f'), between '%' characters on Windows cmd (e.g. '%f%'), and with a '$env:' prefix on Windows powershell (e.g. '$env:f').
.PP
.EX
f
.EE
.PP
Current file selection as a full path.
.PP
.EX
fs
.EE
.PP
Selected file(s) separated with the value of 'filesep' option as full path(s).
.PP
.EX
fx
.EE
.PP
Selected file(s) (i.e. 'fs') if there are any selected files, otherwise current file selection (i.e. 'f').
.PP
.EX
id
.EE
.PP
Id of the running client.
.PP
.EX
LF_LEVEL
.EE
.PP
The value of this variable is set to the current nesting level when you run lf from a shell spawned inside lf. You can add the value of this variable to your shell prompt to make it clear that your shell runs inside lf. For example, with POSIX shells, you can use '[ -n "$LF_LEVEL" ] && PS1="$PS1""(lf level: $LF_LEVEL) "' in your shell configuration file (e.g. '~/.bashrc').
.PP
.EX
OPENER
.EE
.PP
If this variable is set in the environment, use the same value, otherwise set the value to 'start' in Windows, 'open' in MacOS, 'xdg-open' in others.
.PP
.EX
EDITOR
.EE
.PP
If this variable is set in the environment, use the same value, otherwise set the value to 'vi' on unix, 'notepad' in Windows.
.PP
.EX
PAGER
.EE
.PP
If this variable is set in the environment, use the same value, otherwise set the value to 'less' on unix, 'more' in Windows.
.PP
.EX
SHELL
.EE
.PP
If this variable is set in the environment, use the same value, otherwise set the value to 'sh' on unix, 'cmd' in Windows.
.SH PREFIXES .SH PREFIXES
The following command prefixes are used by lf: The following command prefixes are used by lf:
.PP .PP
@@ -675,10 +1274,10 @@ If '$LS_COLORS' variable is not set, '$LSCOLORS' variable is checked instead. Th
.PP .PP
If both of these environment variables are not set, then lf fallbacks to its default colorscheme. Default lf colors are taken from GNU dircolors defaults. These defaults use 8 basic colors and bold attribute. If both of these environment variables are not set, then lf fallbacks to its default colorscheme. Default lf colors are taken from GNU dircolors defaults. These defaults use 8 basic colors and bold attribute.
.PP .PP
You should also note that lf uses 8 color mode by default which uses sgr 3-bit color escapes (e.g. '\e033[34m'). If you want to use 256 colors, you need to enable 'color256' option which then makes lf use sgr 8-bit color escapes (e.g. '\e033[38;5;4m'). This option is intended to eliminate differences between default colors used by ls and lf since terminals may render 3-bit and 8-bit escapes differently even for the same color. It is worth noting that lf uses as many colors are advertised by your terminal's entry in your systems terminfo or infocmp database, if this is not present lf will default to an internal database. For terminals supporting 24-bit (or "true") color that do not have a database entry (or one that does not advertise all capabilities), support can be enabled by either setting the '$COLORTERM' variable to "truecolor" or ensuring '$TERM' is set to a value that ends with "-truecolor".
.PP .PP
Keeping this mechanism in mind, you can configure lf colors in two different ways. First, you can configure 8 basic colors used by your terminal and lf should pick up those colors automatically. Depending on your terminal, you should be able to select your colors from a 24-bit palette. This is the recommended approach as colors used by other programs will also match each other. Keeping this in mind, you can configure lf colors in two different ways. First, you can configure 8 basic colors used by your terminal and lf should pick up those colors automatically. Depending on your terminal, you should be able to select your colors from a 24-bit palette. This is the recommended approach as colors used by other programs will also match each other.
.PP .PP
Second, you can set the values of environmental variables mentioned above for fine grained customization. This is useful to change colors used for different file types and extensions. '$LS_COLORS' is more powerful than '$LSCOLORS' and it can be used even when GNU programs are not installed on the system. You can combine this second method with the first method for best results. Second, you can set the values of environmental variables mentioned above for fine grained customization. This is useful to change colors used for different file types and extensions. '$LS_COLORS' is more powerful than '$LSCOLORS' and it can be used even when GNU programs are not installed on the system. You can combine this second method with the first method for best results. lf can also be configured to ignore your terminal theme and output colors "as they were intended" by translating all numbered colors into a 24-bit output that matches the description; this can be enabled by setting the environment variable '$TCELL_TRUECOLOR' to "on" (or any text except ""/nothing or "disable").
.PP .PP
Lastly, you may also want to configure the colors of the prompt line to match the rest of the colors. Colors of the prompt line can be configured using the 'promptfmt' option which can include hardcoded colors as ansi escapes. See the default value of this option to have an idea about how to color this line. Lastly, you may also want to configure the colors of the prompt line to match the rest of the colors. Colors of the prompt line can be configured using the 'promptfmt' option which can include hardcoded colors as ansi escapes. See the default value of this option to have an idea about how to color this line.
+83 -1
View File
@@ -7,6 +7,7 @@ import (
"net" "net"
"os" "os"
"path/filepath" "path/filepath"
"reflect"
"runtime" "runtime"
"runtime/pprof" "runtime/pprof"
"strconv" "strconv"
@@ -50,6 +51,7 @@ func exportEnvVars() {
os.Setenv("EDITOR", envEditor) os.Setenv("EDITOR", envEditor)
os.Setenv("PAGER", envPager) os.Setenv("PAGER", envPager)
os.Setenv("SHELL", envShell) os.Setenv("SHELL", envShell)
os.Setenv("TCELL_TRUECOLOR", envTcellTruecolor)
level, err := strconv.Atoi(envLevel) level, err := strconv.Atoi(envLevel)
if err != nil { if err != nil {
@@ -61,9 +63,88 @@ func exportEnvVars() {
os.Setenv("LF_LEVEL", strconv.Itoa(level)) os.Setenv("LF_LEVEL", strconv.Itoa(level))
} }
// used by exportOpts below
func fieldToString(field reflect.Value) string {
kind := field.Kind()
var value string
switch kind {
case reflect.Int:
value = strconv.Itoa(int(field.Int()))
case reflect.Bool:
value = strconv.FormatBool(field.Bool())
case reflect.Slice:
for i := 0; i < field.Len(); i++ {
element := field.Index(i)
if i == 0 {
value = fieldToString(element)
} else {
value += ":" + fieldToString(element)
}
}
default:
value = field.String()
}
return value
}
func exportOpts() {
e := reflect.ValueOf(&gOpts).Elem()
for i := 0; i < e.NumField(); i++ {
// Get name and prefix it with lf_
name := e.Type().Field(i).Name
name = fmt.Sprintf("lf_%s", name)
// Skip maps
if name == "lf_keys" || name == "lf_cmdkeys" || name == "lf_cmds" {
continue
}
// Get string representation of the value
if name == "lf_sortType" {
var sortby string
switch gOpts.sortType.method {
case naturalSort:
sortby = "natural"
case nameSort:
sortby = "name"
case sizeSort:
sortby = "size"
case timeSort:
sortby = "time"
case ctimeSort:
sortby = "ctime"
case atimeSort:
sortby = "atime"
case extSort:
sortby = "ext"
}
os.Setenv("lf_sortby", sortby)
reverse := strconv.FormatBool(gOpts.sortType.option&reverseSort != 0)
os.Setenv("lf_reverse", reverse)
hidden := strconv.FormatBool(gOpts.sortType.option&hiddenSort != 0)
os.Setenv("lf_hidden", hidden)
dirfirst := strconv.FormatBool(gOpts.sortType.option&dirfirstSort != 0)
os.Setenv("lf_dirfirst", dirfirst)
} else {
field := e.Field(i)
value := fieldToString(field)
os.Setenv(name, value)
}
}
}
func startServer() { func startServer() {
cmd := detachedCommand(os.Args[0], "-server") cmd := detachedCommand(os.Args[0], "-server")
cmd.Dir = gUser.HomeDir
if err := cmd.Start(); err != nil { if err := cmd.Start(); err != nil {
log.Printf("starting server: %s", err) log.Printf("starting server: %s", err)
} }
@@ -156,6 +237,7 @@ func main() {
log.Fatalf("remote command: %s", err) log.Fatalf("remote command: %s", err)
} }
case *serverMode: case *serverMode:
os.Chdir(gUser.HomeDir)
gServerLogPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.server.log", gUser.Username)) gServerLogPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.server.log", gUser.Username))
serve() serve()
default: default:
+21 -22
View File
@@ -9,6 +9,7 @@ import (
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"reflect"
"sort" "sort"
"strconv" "strconv"
"strings" "strings"
@@ -104,15 +105,16 @@ func readdir(path string) ([]*file, error) {
} }
type dir struct { type dir struct {
loading bool // directory is loading from disk loading bool // directory is loading from disk
loadTime time.Time // current loading or last load time loadTime time.Time // current loading or last load time
ind int // index of current entry in files ind int // index of current entry in files
pos int // position of current entry in ui pos int // position of current entry in ui
path string // full path of directory path string // full path of directory
files []*file // displayed files in directory including or excluding hidden ones files []*file // displayed files in directory including or excluding hidden ones
allFiles []*file // all files in directory including hidden ones (same array as files) allFiles []*file // all files in directory including hidden ones (same array as files)
sortType sortType // sort method and options from last sort sortType sortType // sort method and options from last sort
noPerm bool // whether lf has no permission to open the directory hiddenfiles []string // hiddenfiles value from last sort
noPerm bool // whether lf has no permission to open the directory
} }
func newDir(path string) *dir { func newDir(path string) *dir {
@@ -134,6 +136,7 @@ func newDir(path string) *dir {
func (dir *dir) sort() { func (dir *dir) sort() {
dir.sortType = gOpts.sortType dir.sortType = gOpts.sortType
dir.hiddenfiles = gOpts.hiddenfiles
dir.files = dir.allFiles dir.files = dir.allFiles
@@ -286,7 +289,7 @@ type nav struct {
func (nav *nav) loadDir(path string) *dir { func (nav *nav) loadDir(path string) *dir {
d, ok := nav.dirCache[path] d, ok := nav.dirCache[path]
if !ok { if !ok {
d := &dir{loading: true, loadTime: time.Now(), path: path, sortType: gOpts.sortType} d := &dir{loading: true, loadTime: time.Now(), path: path, sortType: gOpts.sortType, hiddenfiles: gOpts.hiddenfiles}
nav.dirCache[path] = d nav.dirCache[path] = d
go func() { go func() {
d := newDir(path) d := newDir(path)
@@ -318,7 +321,7 @@ func (nav *nav) checkDir(dir *dir) {
nd.sort() nd.sort()
nav.dirChan <- nd nav.dirChan <- nd
}() }()
case dir.sortType != gOpts.sortType: case dir.sortType != gOpts.sortType || !reflect.DeepEqual(dir.hiddenfiles, gOpts.hiddenfiles):
dir.loading = true dir.loading = true
go func() { go func() {
dir.sort() dir.sort()
@@ -416,18 +419,14 @@ func (nav *nav) position() {
} }
} }
func (nav *nav) preview() { func (nav *nav) preview(path string) {
curr, err := nav.currFile() reg := &reg{loadTime: time.Now(), path: path}
if err != nil {
return
}
reg := &reg{loadTime: time.Now(), path: curr.path}
var reader io.Reader var reader io.Reader
if len(gOpts.previewer) != 0 { if len(gOpts.previewer) != 0 {
cmd := exec.Command(gOpts.previewer, curr.path, strconv.Itoa(nav.height)) exportOpts()
cmd := exec.Command(gOpts.previewer, path, strconv.Itoa(nav.height))
out, err := cmd.StdoutPipe() out, err := cmd.StdoutPipe()
if err != nil { if err != nil {
@@ -442,7 +441,7 @@ func (nav *nav) preview() {
defer out.Close() defer out.Close()
reader = out reader = out
} else { } else {
f, err := os.Open(curr.path) f, err := os.Open(path)
if err != nil { if err != nil {
log.Printf("opening file: %s", err) log.Printf("opening file: %s", err)
} }
@@ -476,7 +475,7 @@ func (nav *nav) loadReg(path string) *reg {
if !ok { if !ok {
r := &reg{loading: true, loadTime: time.Now(), path: path} r := &reg{loading: true, loadTime: time.Now(), path: path}
nav.regCache[path] = r nav.regCache[path] = r
go nav.preview() go nav.preview(path)
return r return r
} }
@@ -493,7 +492,7 @@ func (nav *nav) checkReg(reg *reg) {
if s.ModTime().After(reg.loadTime) { if s.ModTime().After(reg.loadTime) {
reg.loadTime = time.Now() reg.loadTime = time.Now()
go nav.preview() go nav.preview(reg.path)
} }
} }
+2 -4
View File
@@ -29,7 +29,6 @@ type sortType struct {
var gOpts struct { var gOpts struct {
anchorfind bool anchorfind bool
color256 bool
dircounts bool dircounts bool
drawbox bool drawbox bool
globsearch bool globsearch bool
@@ -68,7 +67,6 @@ var gOpts struct {
func init() { func init() {
gOpts.anchorfind = true gOpts.anchorfind = true
gOpts.color256 = false
gOpts.dircounts = false gOpts.dircounts = false
gOpts.drawbox = false gOpts.drawbox = false
gOpts.globsearch = false gOpts.globsearch = false
@@ -176,8 +174,8 @@ func init() {
gOpts.cmdkeys["<c-p>"] = &callExpr{"cmd-history-prev", nil, 1} gOpts.cmdkeys["<c-p>"] = &callExpr{"cmd-history-prev", nil, 1}
gOpts.cmdkeys["<delete>"] = &callExpr{"cmd-delete", nil, 1} gOpts.cmdkeys["<delete>"] = &callExpr{"cmd-delete", nil, 1}
gOpts.cmdkeys["<c-d>"] = &callExpr{"cmd-delete", nil, 1} gOpts.cmdkeys["<c-d>"] = &callExpr{"cmd-delete", nil, 1}
gOpts.cmdkeys["<bs>"] = &callExpr{"cmd-delete-back", nil, 1} gOpts.cmdkeys["<backspace>"] = &callExpr{"cmd-delete-back", nil, 1}
gOpts.cmdkeys["<bs2>"] = &callExpr{"cmd-delete-back", nil, 1} gOpts.cmdkeys["<backspace2>"] = &callExpr{"cmd-delete-back", nil, 1}
gOpts.cmdkeys["<left>"] = &callExpr{"cmd-left", nil, 1} gOpts.cmdkeys["<left>"] = &callExpr{"cmd-left", nil, 1}
gOpts.cmdkeys["<c-b>"] = &callExpr{"cmd-left", nil, 1} gOpts.cmdkeys["<c-b>"] = &callExpr{"cmd-left", nil, 1}
gOpts.cmdkeys["<right>"] = &callExpr{"cmd-right", nil, 1} gOpts.cmdkeys["<right>"] = &callExpr{"cmd-right", nil, 1}
+9 -4
View File
@@ -15,10 +15,11 @@ import (
) )
var ( var (
envOpener = os.Getenv("OPENER") envOpener = os.Getenv("OPENER")
envEditor = os.Getenv("EDITOR") envEditor = os.Getenv("EDITOR")
envPager = os.Getenv("PAGER") envPager = os.Getenv("PAGER")
envShell = os.Getenv("SHELL") envShell = os.Getenv("SHELL")
envTcellTruecolor = os.Getenv("TCELL_TRUECOLOR")
) )
var ( var (
@@ -55,6 +56,10 @@ func init() {
envShell = "sh" envShell = "sh"
} }
if envTcellTruecolor == "" {
envTcellTruecolor = "disable"
}
u, err := user.Current() u, err := user.Current()
if err != nil { if err != nil {
log.Printf("user: %s", err) log.Printf("user: %s", err)
+10 -5
View File
@@ -12,10 +12,11 @@ import (
) )
var ( var (
envOpener = os.Getenv("OPENER") envOpener = os.Getenv("OPENER")
envEditor = os.Getenv("EDITOR") envEditor = os.Getenv("EDITOR")
envPager = os.Getenv("PAGER") envPager = os.Getenv("PAGER")
envShell = os.Getenv("SHELL") envShell = os.Getenv("SHELL")
envTcellTruecolor = os.Getenv("TCELL_TRUECOLOR")
) )
var envPathExt = os.Getenv("PATHEXT") var envPathExt = os.Getenv("PATHEXT")
@@ -23,7 +24,7 @@ var envPathExt = os.Getenv("PATHEXT")
var ( var (
gDefaultShell = "cmd" gDefaultShell = "cmd"
gDefaultSocketProt = "tcp" gDefaultSocketProt = "tcp"
gDefaultSocketPath = ":12345" gDefaultSocketPath = "127.0.0.1:12345"
) )
var ( var (
@@ -50,6 +51,10 @@ func init() {
envShell = "cmd" envShell = "cmd"
} }
if envTcellTruecolor == "" {
envTcellTruecolor = "disable"
}
u, err := user.Current() u, err := user.Current()
if err != nil { if err != nil {
log.Printf("user: %s", err) log.Printf("user: %s", err)
+326 -250
View File
@@ -15,75 +15,137 @@ import (
"unicode" "unicode"
"unicode/utf8" "unicode/utf8"
"github.com/doronbehar/termbox-go" "github.com/gdamore/tcell"
"github.com/mattn/go-runewidth" "github.com/mattn/go-runewidth"
) )
const gEscapeCode = 27 const gEscapeCode = 27
var gKeyVal = map[termbox.Key]string{ var gKeyVal = map[tcell.Key]string{
termbox.KeyF1: "<f-1>", tcell.KeyEnter: "<enter>",
termbox.KeyF2: "<f-2>", tcell.KeyBackspace: "<backspace>",
termbox.KeyF3: "<f-3>", tcell.KeyTab: "<tab>",
termbox.KeyF4: "<f-4>", tcell.KeyBacktab: "<backtab>",
termbox.KeyF5: "<f-5>", tcell.KeyEsc: "<esc>",
termbox.KeyF6: "<f-6>", tcell.KeyBackspace2: "<backspace2>",
termbox.KeyF7: "<f-7>", tcell.KeyDelete: "<delete>",
termbox.KeyF8: "<f-8>", tcell.KeyInsert: "<insert>",
termbox.KeyF9: "<f-9>", tcell.KeyUp: "<up>",
termbox.KeyF10: "<f-10>", tcell.KeyDown: "<down>",
termbox.KeyF11: "<f-11>", tcell.KeyLeft: "<left>",
termbox.KeyF12: "<f-12>", tcell.KeyRight: "<right>",
termbox.KeyInsert: "<insert>", tcell.KeyHome: "<home>",
termbox.KeyDelete: "<delete>", tcell.KeyEnd: "<end>",
termbox.KeyHome: "<home>", tcell.KeyUpLeft: "<upleft>",
termbox.KeyEnd: "<end>", tcell.KeyUpRight: "<upright>",
termbox.KeyPgup: "<pgup>", tcell.KeyDownLeft: "<downleft>",
termbox.KeyPgdn: "<pgdn>", tcell.KeyDownRight: "<downright>",
termbox.KeyArrowUp: "<up>", tcell.KeyCenter: "<center>",
termbox.KeyArrowDown: "<down>", tcell.KeyPgDn: "<pgdn>",
termbox.KeyArrowLeft: "<left>", tcell.KeyPgUp: "<pgup>",
termbox.KeyArrowRight: "<right>", tcell.KeyClear: "<clear>",
termbox.KeyCtrlSpace: "<c-space>", tcell.KeyExit: "<exit>",
termbox.KeyCtrlA: "<c-a>", tcell.KeyCancel: "<cancel>",
termbox.KeyCtrlB: "<c-b>", tcell.KeyPause: "<pause>",
termbox.KeyCtrlC: "<c-c>", tcell.KeyPrint: "<print>",
termbox.KeyCtrlD: "<c-d>", tcell.KeyF1: "<f-1>",
termbox.KeyCtrlE: "<c-e>", tcell.KeyF2: "<f-2>",
termbox.KeyCtrlF: "<c-f>", tcell.KeyF3: "<f-3>",
termbox.KeyCtrlG: "<c-g>", tcell.KeyF4: "<f-4>",
termbox.KeyBackspace: "<bs>", tcell.KeyF5: "<f-5>",
termbox.KeyTab: "<tab>", tcell.KeyF6: "<f-6>",
termbox.KeyCtrlJ: "<c-j>", tcell.KeyF7: "<f-7>",
termbox.KeyCtrlK: "<c-k>", tcell.KeyF8: "<f-8>",
termbox.KeyCtrlL: "<c-l>", tcell.KeyF9: "<f-9>",
termbox.KeyEnter: "<enter>", tcell.KeyF10: "<f-10>",
termbox.KeyCtrlN: "<c-n>", tcell.KeyF11: "<f-11>",
termbox.KeyCtrlO: "<c-o>", tcell.KeyF12: "<f-12>",
termbox.KeyCtrlP: "<c-p>", tcell.KeyF13: "<f-13>",
termbox.KeyCtrlQ: "<c-q>", tcell.KeyF14: "<f-14>",
termbox.KeyCtrlR: "<c-r>", tcell.KeyF15: "<f-15>",
termbox.KeyCtrlS: "<c-s>", tcell.KeyF16: "<f-16>",
termbox.KeyCtrlT: "<c-t>", tcell.KeyF17: "<f-17>",
termbox.KeyCtrlU: "<c-u>", tcell.KeyF18: "<f-18>",
termbox.KeyCtrlV: "<c-v>", tcell.KeyF19: "<f-19>",
termbox.KeyCtrlW: "<c-w>", tcell.KeyF20: "<f-20>",
termbox.KeyCtrlX: "<c-x>", tcell.KeyF21: "<f-21>",
termbox.KeyCtrlY: "<c-y>", tcell.KeyF22: "<f-22>",
termbox.KeyCtrlZ: "<c-z>", tcell.KeyF23: "<f-23>",
termbox.KeyEsc: "<esc>", tcell.KeyF24: "<f-24>",
termbox.KeyCtrlBackslash: "<c-\\>", tcell.KeyF25: "<f-25>",
termbox.KeyCtrlRsqBracket: "<c-]>", tcell.KeyF26: "<f-26>",
termbox.KeyCtrl6: "<c-6>", tcell.KeyF27: "<f-27>",
termbox.KeyCtrlSlash: "<c-/>", tcell.KeyF28: "<f-28>",
termbox.KeySpace: "<space>", tcell.KeyF29: "<f-29>",
termbox.KeyBackspace2: "<bs2>", tcell.KeyF30: "<f-30>",
tcell.KeyF31: "<f-31>",
tcell.KeyF32: "<f-32>",
tcell.KeyF33: "<f-33>",
tcell.KeyF34: "<f-34>",
tcell.KeyF35: "<f-35>",
tcell.KeyF36: "<f-36>",
tcell.KeyF37: "<f-37>",
tcell.KeyF38: "<f-38>",
tcell.KeyF39: "<f-39>",
tcell.KeyF40: "<f-40>",
tcell.KeyF41: "<f-41>",
tcell.KeyF42: "<f-42>",
tcell.KeyF43: "<f-43>",
tcell.KeyF44: "<f-44>",
tcell.KeyF45: "<f-45>",
tcell.KeyF46: "<f-46>",
tcell.KeyF47: "<f-47>",
tcell.KeyF48: "<f-48>",
tcell.KeyF49: "<f-49>",
tcell.KeyF50: "<f-50>",
tcell.KeyF51: "<f-51>",
tcell.KeyF52: "<f-52>",
tcell.KeyF53: "<f-53>",
tcell.KeyF54: "<f-54>",
tcell.KeyF55: "<f-55>",
tcell.KeyF56: "<f-56>",
tcell.KeyF57: "<f-57>",
tcell.KeyF58: "<f-58>",
tcell.KeyF59: "<f-59>",
tcell.KeyF60: "<f-60>",
tcell.KeyF61: "<f-61>",
tcell.KeyF62: "<f-62>",
tcell.KeyF63: "<f-63>",
tcell.KeyF64: "<f-64>",
tcell.KeyCtrlA: "<c-a>",
tcell.KeyCtrlB: "<c-b>",
tcell.KeyCtrlC: "<c-c>",
tcell.KeyCtrlD: "<c-d>",
tcell.KeyCtrlE: "<c-e>",
tcell.KeyCtrlF: "<c-f>",
tcell.KeyCtrlG: "<c-g>",
tcell.KeyCtrlJ: "<c-j>",
tcell.KeyCtrlK: "<c-k>",
tcell.KeyCtrlL: "<c-l>",
tcell.KeyCtrlN: "<c-n>",
tcell.KeyCtrlO: "<c-o>",
tcell.KeyCtrlP: "<c-p>",
tcell.KeyCtrlQ: "<c-q>",
tcell.KeyCtrlR: "<c-r>",
tcell.KeyCtrlS: "<c-s>",
tcell.KeyCtrlT: "<c-t>",
tcell.KeyCtrlU: "<c-u>",
tcell.KeyCtrlV: "<c-v>",
tcell.KeyCtrlW: "<c-w>",
tcell.KeyCtrlX: "<c-x>",
tcell.KeyCtrlY: "<c-y>",
tcell.KeyCtrlZ: "<c-z>",
tcell.KeyCtrlSpace: "<c-space>",
tcell.KeyCtrlUnderscore: "<c-_>",
tcell.KeyCtrlRightSq: "<c-]>",
tcell.KeyCtrlBackslash: "<c-\\>",
tcell.KeyCtrlCarat: "<c-^>",
} }
var gValKey map[string]termbox.Key var gValKey map[string]tcell.Key
func init() { func init() {
gValKey = make(map[string]termbox.Key) gValKey = make(map[string]tcell.Key)
for k, v := range gKeyVal { for k, v := range gKeyVal {
gValKey[v] = k gValKey[v] = k
} }
@@ -129,7 +191,7 @@ func printLength(s string) int {
return ind return ind
} }
func (win *win) print(x, y int, fg, bg termbox.Attribute, s string) (termbox.Attribute, termbox.Attribute) { func (win *win) print(screen tcell.Screen, x, y int, st tcell.Style, s string) tcell.Style {
off := x off := x
for i := 0; i < len(s); i++ { for i := 0; i < len(s); i++ {
r, w := utf8.DecodeRuneInString(s[i:]) r, w := utf8.DecodeRuneInString(s[i:])
@@ -140,14 +202,14 @@ func (win *win) print(x, y int, fg, bg termbox.Attribute, s string) (termbox.Att
continue continue
} }
fg, bg = applyAnsiCodes(s[i+2:i+j], fg, bg) st = applyAnsiCodes(s[i+2:i+j], st)
i += j i += j
continue continue
} }
if x < win.w { if x < win.w {
termbox.SetCell(win.x+x, win.y+y, r, fg, bg) screen.SetContent(win.x+x, win.y+y, r, nil, st)
} }
i += w - 1 i += w - 1
@@ -155,7 +217,7 @@ func (win *win) print(x, y int, fg, bg termbox.Attribute, s string) (termbox.Att
if r == '\t' { if r == '\t' {
s := gOpts.tabstop - (x-off)%gOpts.tabstop s := gOpts.tabstop - (x-off)%gOpts.tabstop
for i := 0; i < s && x+i < win.w; i++ { for i := 0; i < s && x+i < win.w; i++ {
termbox.SetCell(win.x+x+i, win.y+y, ' ', fg, bg) screen.SetContent(win.x+x+i, win.y+y, ' ', nil, st)
} }
x += s x += s
} else { } else {
@@ -163,36 +225,40 @@ func (win *win) print(x, y int, fg, bg termbox.Attribute, s string) (termbox.Att
} }
} }
return fg, bg return st
} }
func (win *win) printf(x, y int, fg, bg termbox.Attribute, format string, a ...interface{}) { func (win *win) printf(screen tcell.Screen, x, y int, st tcell.Style, format string, a ...interface{}) {
win.print(x, y, fg, bg, fmt.Sprintf(format, a...)) win.print(screen, x, y, st, fmt.Sprintf(format, a...))
} }
func (win *win) printLine(x, y int, fg, bg termbox.Attribute, s string) { func (win *win) printLine(screen tcell.Screen, x, y int, st tcell.Style, s string) {
win.printf(x, y, fg, bg, "%s%*s", s, win.w-len(s), "") win.printf(screen, x, y, st, "%s%*s", s, win.w-len(s), "")
} }
func (win *win) printRight(y int, fg, bg termbox.Attribute, s string) { func (win *win) printRight(screen tcell.Screen, y int, st tcell.Style, s string) {
win.print(win.w-len(s), y, fg, bg, s) win.print(screen, win.w-len(s), y, st, s)
} }
func (win *win) printReg(reg *reg) { func (win *win) printReg(screen tcell.Screen, reg *reg) {
if reg == nil { if reg == nil {
return return
} }
fg, bg := termbox.ColorDefault, termbox.ColorDefault st := tcell.StyleDefault
if reg.loading { if reg.loading {
fg = termbox.AttrReverse st = st.Reverse(true)
win.print(2, 0, fg, bg, "loading...") win.print(screen, 2, 0, st, "loading...")
return return
} }
for i, l := range reg.lines { for i, l := range reg.lines {
fg, bg = win.print(2, i, fg, bg, l) if i > win.h-1 {
break
}
st = win.print(screen, 2, i, st, l)
} }
} }
@@ -247,23 +313,23 @@ func fileInfo(f *file, d *dir) string {
return info return info
} }
func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]bool, colors colorMap, icons iconMap) { func (win *win) printDir(screen tcell.Screen, dir *dir, selections map[string]int, saves map[string]bool, colors styleMap, icons iconMap) {
if win.w < 5 || dir == nil { if win.w < 5 || dir == nil {
return return
} }
if dir.loading { if dir.noPerm {
win.print(2, 0, termbox.AttrReverse, termbox.ColorDefault, "loading...") win.print(screen, 2, 0, tcell.StyleDefault.Reverse(true), "permission denied")
return return
} }
if dir.noPerm { if dir.loading && len(dir.files) == 0 {
win.print(2, 0, termbox.AttrReverse, termbox.ColorDefault, "permission denied") win.print(screen, 2, 0, tcell.StyleDefault.Reverse(true), "loading...")
return return
} }
if len(dir.files) == 0 { if len(dir.files) == 0 {
win.print(2, 0, termbox.AttrReverse, termbox.ColorDefault, "empty") win.print(screen, 2, 0, tcell.StyleDefault.Reverse(true), "empty")
return return
} }
@@ -289,7 +355,7 @@ func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]b
} }
for i, f := range dir.files[beg:end] { for i, f := range dir.files[beg:end] {
fg, bg := colors.get(f) st := colors.get(f)
if lnwidth > 0 { if lnwidth > 0 {
var ln string var ln string
@@ -309,23 +375,23 @@ func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]b
} }
} }
win.print(0, i, termbox.ColorYellow, bg, ln) win.print(screen, 0, i, tcell.StyleDefault.Foreground(tcell.ColorOlive), ln)
} }
path := filepath.Join(dir.path, f.Name()) path := filepath.Join(dir.path, f.Name())
if _, ok := selections[path]; ok { if _, ok := selections[path]; ok {
win.print(lnwidth, i, fg, termbox.ColorMagenta, " ") win.print(screen, lnwidth, i, st.Background(tcell.ColorPurple), " ")
} else if cp, ok := saves[path]; ok { } else if cp, ok := saves[path]; ok {
if cp { if cp {
win.print(lnwidth, i, fg, termbox.ColorYellow, " ") win.print(screen, lnwidth, i, st.Background(tcell.ColorOlive), " ")
} else { } else {
win.print(lnwidth, i, fg, termbox.ColorRed, " ") win.print(screen, lnwidth, i, st.Background(tcell.ColorMaroon), " ")
} }
} }
if i == dir.pos { if i == dir.pos {
fg |= termbox.AttrReverse st = st.Reverse(true)
} }
var s []rune var s []rune
@@ -368,11 +434,12 @@ func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]b
s = append(s, ' ') s = append(s, ' ')
win.print(lnwidth+1, i, fg, bg, string(s)) win.print(screen, lnwidth+1, i, st, string(s))
} }
} }
type ui struct { type ui struct {
screen tcell.Screen
wins []*win wins []*win
promptWin *win promptWin *win
msgWin *win msgWin *win
@@ -382,7 +449,8 @@ type ui struct {
dirPrev *dir dirPrev *dir
exprChan chan expr exprChan chan expr
keyChan chan string keyChan chan string
evChan chan termbox.Event tevChan chan tcell.Event
evChan chan tcell.Event
menuBuf *bytes.Buffer menuBuf *bytes.Buffer
cmdPrefix string cmdPrefix string
cmdAccLeft []rune cmdAccLeft []rune
@@ -390,7 +458,7 @@ type ui struct {
cmdYankBuf []rune cmdYankBuf []rune
keyAcc []rune keyAcc []rune
keyCount []rune keyCount []rune
colors colorMap styles styleMap
icons iconMap icons iconMap
} }
@@ -417,8 +485,8 @@ func getWidths(wtot int) []int {
return widths return widths
} }
func getWins() []*win { func getWins(screen tcell.Screen) []*win {
wtot, htot := termbox.Size() wtot, htot := screen.Size()
var wins []*win var wins []*win
@@ -438,47 +506,41 @@ func getWins() []*win {
return wins return wins
} }
func newUI() *ui { func newUI(screen tcell.Screen) *ui {
wtot, htot := termbox.Size() wtot, htot := screen.Size()
evQueue := make(chan termbox.Event) ui := &ui{
go func() { screen: screen,
for { wins: getWins(screen),
evQueue <- termbox.PollEvent()
}
}()
evChan := make(chan termbox.Event)
go func() {
for {
ev := <-evQueue
if ev.Type == termbox.EventKey && ev.Key == termbox.KeyEsc {
select {
case ev2 := <-evQueue:
ev2.Mod = termbox.ModAlt
evChan <- ev2
continue
case <-time.After(100 * time.Millisecond):
}
}
evChan <- ev
}
}()
return &ui{
wins: getWins(),
promptWin: newWin(wtot, 1, 0, 0), promptWin: newWin(wtot, 1, 0, 0),
msgWin: newWin(wtot, 1, 0, htot-1), msgWin: newWin(wtot, 1, 0, htot-1),
menuWin: newWin(wtot, 1, 0, htot-2), menuWin: newWin(wtot, 1, 0, htot-2),
exprChan: make(chan expr, 1000),
keyChan: make(chan string, 1000), keyChan: make(chan string, 1000),
evChan: evChan, tevChan: make(chan tcell.Event, 1000),
colors: parseColors(), evChan: make(chan tcell.Event, 1000),
styles: parseStyles(),
icons: parseIcons(), icons: parseIcons(),
} }
go ui.pollEvents()
return ui
}
func (ui *ui) pollEvents() {
var ev tcell.Event
for {
ev = ui.screen.PollEvent()
if ev == nil {
return
}
ui.tevChan <- ev
}
} }
func (ui *ui) renew() { func (ui *ui) renew() {
wtot, htot := termbox.Size() wtot, htot := ui.screen.Size()
widths := getWidths(wtot) widths := getWidths(wtot)
@@ -571,7 +633,7 @@ func (ui *ui) loadFileInfo(nav *nav) {
} }
func (ui *ui) drawPromptLine(nav *nav) { func (ui *ui) drawPromptLine(nav *nav) {
fg, bg := termbox.ColorDefault, termbox.ColorDefault st := tcell.StyleDefault
pwd := nav.currDir().path pwd := nav.currDir().path
@@ -614,15 +676,15 @@ func (ui *ui) drawPromptLine(nav *nav) {
prompt = strings.Replace(prompt, "%w", pwd, -1) prompt = strings.Replace(prompt, "%w", pwd, -1)
ui.promptWin.print(0, 0, fg, bg, prompt) ui.promptWin.print(ui.screen, 0, 0, st, prompt)
} }
func (ui *ui) drawStatLine(nav *nav) { func (ui *ui) drawStatLine(nav *nav) {
fg, bg := termbox.ColorDefault, termbox.ColorDefault st := tcell.StyleDefault
dir := nav.currDir() dir := nav.currDir()
ui.msgWin.print(0, 0, fg, bg, ui.msg) ui.msgWin.print(ui.screen, 0, 0, st, ui.msg)
tot := len(dir.files) tot := len(dir.files)
ind := min(dir.ind+1, tot) ind := min(dir.ind+1, tot)
@@ -645,44 +707,49 @@ func (ui *ui) drawStatLine(nav *nav) {
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(ui.screen, 0, st, ruler)
} }
func (ui *ui) drawBox() { func (ui *ui) drawBox() {
fg, bg := termbox.ColorDefault, termbox.ColorDefault st := tcell.StyleDefault
w, h := termbox.Size() w, h := ui.screen.Size()
for i := 1; i < w-1; i++ { for i := 1; i < w-1; i++ {
termbox.SetCell(i, 1, '─', fg, bg) ui.screen.SetContent(i, 1, '─', nil, st)
termbox.SetCell(i, h-2, '─', fg, bg) ui.screen.SetContent(i, h-2, '─', nil, st)
} }
for i := 2; i < h-2; i++ { for i := 2; i < h-2; i++ {
termbox.SetCell(0, i, '│', fg, bg) ui.screen.SetContent(0, i, '│', nil, st)
termbox.SetCell(w-1, i, '│', fg, bg) ui.screen.SetContent(w-1, i, '│', nil, st)
} }
termbox.SetCell(0, 1, '┌', fg, bg) ui.screen.SetContent(0, 1, '┌', nil, st)
termbox.SetCell(w-1, 1, '┐', fg, bg) ui.screen.SetContent(w-1, 1, '┐', nil, st)
termbox.SetCell(0, h-2, '└', fg, bg) ui.screen.SetContent(0, h-2, '└', nil, st)
termbox.SetCell(w-1, h-2, '┘', fg, bg) ui.screen.SetContent(w-1, h-2, '┘', nil, st)
wacc := 0 wacc := 0
for wind := 0; wind < len(ui.wins)-1; wind++ { for wind := 0; wind < len(ui.wins)-1; wind++ {
wacc += ui.wins[wind].w wacc += ui.wins[wind].w
termbox.SetCell(wacc, 1, '┬', fg, bg) ui.screen.SetContent(wacc, 1, '┬', nil, st)
for i := 2; i < h-2; i++ { for i := 2; i < h-2; i++ {
termbox.SetCell(wacc, i, '│', fg, bg) ui.screen.SetContent(wacc, i, '│', nil, st)
} }
termbox.SetCell(wacc, h-2, '┴', fg, bg) ui.screen.SetContent(wacc, h-2, '┴', nil, st)
} }
} }
func (ui *ui) draw(nav *nav) { func (ui *ui) draw(nav *nav) {
fg, bg := termbox.ColorDefault, termbox.ColorDefault st := tcell.StyleDefault
termbox.Clear(fg, bg) wtot, htot := ui.screen.Size()
for i := 0; i < wtot; i++ {
for j := 0; j < htot; j++ {
ui.screen.SetContent(i, j, ' ', nil, st)
}
}
ui.drawPromptLine(nav) ui.drawPromptLine(nav)
@@ -696,24 +763,24 @@ func (ui *ui) draw(nav *nav) {
doff := len(nav.dirs) - length doff := len(nav.dirs) - length
for i := 0; i < length; i++ { for i := 0; i < length; i++ {
ui.wins[woff+i].printDir(nav.dirs[doff+i], nav.selections, nav.saves, ui.colors, ui.icons) ui.wins[woff+i].printDir(ui.screen, nav.dirs[doff+i], nav.selections, nav.saves, ui.styles, ui.icons)
} }
switch ui.cmdPrefix { switch ui.cmdPrefix {
case "": case "":
ui.drawStatLine(nav) ui.drawStatLine(nav)
termbox.HideCursor() ui.screen.HideCursor()
case ">": case ">":
ui.msgWin.printLine(0, 0, fg, bg, ui.cmdPrefix) ui.msgWin.printLine(ui.screen, 0, 0, st, ui.cmdPrefix)
ui.msgWin.print(len(ui.cmdPrefix), 0, fg, bg, ui.msg) ui.msgWin.print(ui.screen, len(ui.cmdPrefix), 0, st, ui.msg)
ui.msgWin.print(len(ui.cmdPrefix)+len(ui.msg), 0, fg, bg, string(ui.cmdAccLeft)) ui.msgWin.print(ui.screen, len(ui.cmdPrefix)+len(ui.msg), 0, st, string(ui.cmdAccLeft))
ui.msgWin.print(len(ui.cmdPrefix)+len(ui.msg)+runeSliceWidth(ui.cmdAccLeft), 0, fg, bg, string(ui.cmdAccRight)) ui.msgWin.print(ui.screen, len(ui.cmdPrefix)+len(ui.msg)+runeSliceWidth(ui.cmdAccLeft), 0, st, string(ui.cmdAccRight))
termbox.SetCursor(ui.msgWin.x+len(ui.cmdPrefix)+len(ui.msg)+runeSliceWidth(ui.cmdAccLeft), ui.msgWin.y) ui.screen.ShowCursor(ui.msgWin.x+len(ui.cmdPrefix)+len(ui.msg)+runeSliceWidth(ui.cmdAccLeft), ui.msgWin.y)
default: default:
ui.msgWin.printLine(0, 0, fg, bg, ui.cmdPrefix) ui.msgWin.printLine(ui.screen, 0, 0, st, ui.cmdPrefix)
ui.msgWin.print(len(ui.cmdPrefix), 0, fg, bg, string(ui.cmdAccLeft)) ui.msgWin.print(ui.screen, len(ui.cmdPrefix), 0, st, string(ui.cmdAccLeft))
ui.msgWin.print(len(ui.cmdPrefix)+runeSliceWidth(ui.cmdAccLeft), 0, fg, bg, string(ui.cmdAccRight)) ui.msgWin.print(ui.screen, len(ui.cmdPrefix)+runeSliceWidth(ui.cmdAccLeft), 0, st, string(ui.cmdAccRight))
termbox.SetCursor(ui.msgWin.x+len(ui.cmdPrefix)+runeSliceWidth(ui.cmdAccLeft), ui.msgWin.y) ui.screen.ShowCursor(ui.msgWin.x+len(ui.cmdPrefix)+runeSliceWidth(ui.cmdAccLeft), ui.msgWin.y)
} }
if gOpts.preview { if gOpts.preview {
@@ -722,9 +789,9 @@ func (ui *ui) draw(nav *nav) {
preview := ui.wins[len(ui.wins)-1] preview := ui.wins[len(ui.wins)-1]
if curr.IsDir() { if curr.IsDir() {
preview.printDir(ui.dirPrev, nav.selections, nav.saves, ui.colors, ui.icons) preview.printDir(ui.screen, ui.dirPrev, nav.selections, nav.saves, ui.styles, ui.icons)
} else if curr.Mode().IsRegular() { } else if curr.Mode().IsRegular() {
preview.printReg(ui.regPrev) preview.printReg(ui.screen, ui.regPrev)
} }
} }
} }
@@ -745,14 +812,14 @@ func (ui *ui) draw(nav *nav) {
ui.menuWin.y += 2 ui.menuWin.y += 2
} }
ui.menuWin.printLine(0, 0, termbox.AttrBold, termbox.AttrBold, lines[0]) ui.menuWin.printLine(ui.screen, 0, 0, st.Bold(true), lines[0])
for i, line := range lines[1:] { for i, line := range lines[1:] {
ui.menuWin.printLine(0, i+1, fg, bg, "") ui.menuWin.printLine(ui.screen, 0, i+1, st, "")
ui.menuWin.print(0, i+1, fg, bg, line) ui.menuWin.print(ui.screen, 0, i+1, st, line)
} }
} }
termbox.Flush() ui.screen.Show()
} }
func findBinds(keys map[string]expr, prefix string) (binds map[string]expr, ok bool) { func findBinds(keys map[string]expr, prefix string) (binds map[string]expr, ok bool) {
@@ -809,35 +876,40 @@ func listMarks(marks map[string]string) *bytes.Buffer {
return b return b
} }
func (ui *ui) pollEvent() termbox.Event { func (ui *ui) pollEvent() tcell.Event {
select { select {
case key := <-ui.keyChan: case val := <-ui.keyChan:
ev := termbox.Event{Type: termbox.EventKey} var ch rune
var mod tcell.ModMask
if utf8.RuneCountInString(key) == 1 { k := tcell.KeyRune
ev.Ch, _ = utf8.DecodeRuneInString(key)
if utf8.RuneCountInString(val) == 1 {
ch, _ = utf8.DecodeRuneInString(val)
} else { } else {
switch { switch {
case key == "<lt>": case val == "<lt>":
ev.Ch = '<' ch = '<'
case key == "<gt>": case val == "<gt>":
ev.Ch = '>' ch = '>'
case reAltKey.MatchString(key): case val == "<space>":
match := reAltKey.FindStringSubmatch(key)[1] ch = ' '
ev.Ch, _ = utf8.DecodeRuneInString(match) case reAltKey.MatchString(val):
ev.Mod = termbox.ModAlt match := reAltKey.FindStringSubmatch(val)[1]
ch, _ = utf8.DecodeRuneInString(match)
mod = tcell.ModMask(tcell.ModAlt)
default: default:
if val, ok := gValKey[key]; ok { if key, ok := gValKey[val]; ok {
ev.Key = val k = key
} else { } else {
ev.Key = termbox.KeyEsc k = tcell.KeyESC
ui.echoerrf("unknown key: %s", key) ui.echoerrf("unknown key: %s", val)
} }
} }
} }
return ev return tcell.NewEventKey(k, ch, mod)
case ev := <-ui.evChan: case ev := <-ui.tevChan:
return ev return ev
} }
} }
@@ -845,40 +917,41 @@ func (ui *ui) pollEvent() termbox.Event {
// This function is used to read a normal event on the client side. For keys, // This function is used to read a normal event on the client side. For keys,
// digits are interpreted as command counts but this is only done for digits // digits are interpreted as command counts but this is only done for digits
// preceding any non-digit characters (e.g. "42y2k" as 42 times "y2k"). // preceding any non-digit characters (e.g. "42y2k" as 42 times "y2k").
func (ui *ui) readEvent(ch chan<- expr, ev termbox.Event) { func (ui *ui) readNormalEvent(ev tcell.Event) expr {
draw := &callExpr{"draw", nil, 1} draw := &callExpr{"draw", nil, 1}
count := 1 count := 1
switch ev.Type { switch tev := ev.(type) {
case termbox.EventKey: case *tcell.EventKey:
if ev.Ch != 0 { // KeyRune is a regular character
if tev.Key() == tcell.KeyRune {
switch { switch {
case ev.Ch == '<': case tev.Rune() == '<':
ui.keyAcc = append(ui.keyAcc, []rune("<lt>")...) ui.keyAcc = append(ui.keyAcc, []rune("<lt>")...)
case ev.Ch == '>': case tev.Rune() == '>':
ui.keyAcc = append(ui.keyAcc, []rune("<gt>")...) ui.keyAcc = append(ui.keyAcc, []rune("<gt>")...)
case ev.Mod == termbox.ModAlt: case tev.Rune() == ' ':
ui.keyAcc = append(ui.keyAcc, '<', 'a', '-', ev.Ch, '>') ui.keyAcc = append(ui.keyAcc, []rune("<space>")...)
case unicode.IsDigit(ev.Ch) && len(ui.keyAcc) == 0: case tev.Modifiers() == tcell.ModAlt:
ui.keyCount = append(ui.keyCount, ev.Ch) ui.keyAcc = append(ui.keyAcc, '<', 'a', '-', tev.Rune(), '>')
case unicode.IsDigit(tev.Rune()) && len(ui.keyAcc) == 0:
ui.keyCount = append(ui.keyCount, tev.Rune())
default: default:
ui.keyAcc = append(ui.keyAcc, ev.Ch) ui.keyAcc = append(ui.keyAcc, tev.Rune())
} }
} else { } else {
val := gKeyVal[ev.Key] val := gKeyVal[tev.Key()]
if val == "<esc>" { if val == "<esc>" && string(ui.keyAcc) != "" {
ch <- draw
ui.keyAcc = nil ui.keyAcc = nil
ui.keyCount = nil ui.keyCount = nil
ui.menuBuf = nil ui.menuBuf = nil
return return draw
} }
ui.keyAcc = append(ui.keyAcc, []rune(val)...) ui.keyAcc = append(ui.keyAcc, []rune(val)...)
} }
if len(ui.keyAcc) == 0 { if len(ui.keyAcc) == 0 {
ch <- draw return draw
break
} }
binds, ok := findBinds(gOpts.keys, string(ui.keyAcc)) binds, ok := findBinds(gOpts.keys, string(ui.keyAcc))
@@ -886,10 +959,10 @@ func (ui *ui) readEvent(ch chan<- expr, ev termbox.Event) {
switch len(binds) { switch len(binds) {
case 0: case 0:
ui.echoerrf("unknown mapping: %s", string(ui.keyAcc)) ui.echoerrf("unknown mapping: %s", string(ui.keyAcc))
ch <- draw
ui.keyAcc = nil ui.keyAcc = nil
ui.keyCount = nil ui.keyCount = nil
ui.menuBuf = nil ui.menuBuf = nil
return draw
default: default:
if ok { if ok {
if len(ui.keyCount) > 0 { if len(ui.keyCount) > 0 {
@@ -905,89 +978,92 @@ func (ui *ui) readEvent(ch chan<- expr, ev termbox.Event) {
} else if e, ok := expr.(*listExpr); ok { } else if e, ok := expr.(*listExpr); ok {
e.count = count e.count = count
} }
ch <- expr
ui.keyAcc = nil ui.keyAcc = nil
ui.keyCount = nil ui.keyCount = nil
ui.menuBuf = nil ui.menuBuf = nil
} else { return expr
ui.menuBuf = listBinds(binds)
ch <- draw
} }
ui.menuBuf = listBinds(binds)
return draw
} }
case termbox.EventResize: case *tcell.EventResize:
ch <- &callExpr{"redraw", nil, 1} return &callExpr{"redraw", nil, 1}
case *tcell.EventError:
log.Printf("Got EventError: '%s' at %s", tev.Error(), tev.When())
return nil
case *tcell.EventInterrupt:
log.Printf("Got EventInterrupt: at %s", tev.When())
return nil
} }
return nil
} }
func readCmdEvent(ch chan<- expr, ev termbox.Event) { func readCmdEvent(ev tcell.Event) expr {
if ev.Ch != 0 { switch tev := ev.(type) {
if ev.Mod == termbox.ModAlt { case *tcell.EventKey:
val := string([]rune{'<', 'a', '-', ev.Ch, '>'}) if tev.Key() == tcell.KeyRune {
if expr, ok := gOpts.cmdkeys[val]; ok { if tev.Modifiers() == tcell.ModMask(tcell.ModAlt) {
ch <- expr val := string([]rune{'<', 'a', '-', tev.Rune(), '>'})
if expr, ok := gOpts.cmdkeys[val]; ok {
return expr
}
} else {
return &callExpr{"cmd-insert", []string{string(tev.Rune())}, 1}
} }
} else { } else {
ch <- &callExpr{"cmd-insert", []string{string(ev.Ch)}, 1} val := gKeyVal[tev.Key()]
} if expr, ok := gOpts.cmdkeys[val]; ok {
} else { return expr
val := gKeyVal[ev.Key] }
if expr, ok := gOpts.cmdkeys[val]; ok {
ch <- expr
} }
} }
return nil
} }
func (ui *ui) readExpr() <-chan expr { func (ui *ui) readEvent(ev tcell.Event) expr {
ch := make(chan expr) if ev == nil {
return nil
}
ui.exprChan = ch if _, ok := ev.(*tcell.EventKey); ok && ui.cmdPrefix != "" {
return readCmdEvent(ev)
}
return ui.readNormalEvent(ev)
}
func (ui *ui) readExpr() {
go func() { go func() {
ch <- &callExpr{"draw", nil, 1}
for { for {
ev := ui.pollEvent() ui.evChan <- ui.pollEvent()
if ui.cmdPrefix != "" && ev.Type == termbox.EventKey {
readCmdEvent(ch, ev)
continue
}
ui.readEvent(ch, ev)
} }
}() }()
return ch
}
func setColorMode() {
if gOpts.color256 {
termbox.SetOutputMode(termbox.Output256)
} else {
termbox.SetOutputMode(termbox.OutputNormal)
}
} }
func (ui *ui) pause() { func (ui *ui) pause() {
termbox.Close() ui.screen.Fini()
} }
func (ui *ui) resume() { func (ui *ui) resume() {
if err := termbox.Init(); err != nil { var screen tcell.Screen
log.Fatalf("initializing termbox: %s", err) var err error
if screen, err = tcell.NewScreen(); err != nil {
log.Fatalf("creating screen: %s", err)
} else if err = screen.Init(); err != nil {
log.Fatalf("initializing screen: %s", err)
} }
ui.screen = screen
go ui.pollEvents()
ui.renew()
} }
func (ui *ui) sync() { func listMatches(screen tcell.Screen, matches []string) *bytes.Buffer {
if err := termbox.Sync(); err != nil {
log.Printf("syncing termbox: %s", err)
}
}
func listMatches(matches []string) *bytes.Buffer {
b := new(bytes.Buffer) b := new(bytes.Buffer)
wtot, _ := termbox.Size() wtot, _ := screen.Size()
wcol := 0 wcol := 0
for _, m := range matches { for _, m := range matches {