Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
da126a3959 | ||
|
|
6d20887b16 | ||
|
|
078dc47e34 | ||
|
|
8070cd82b7 | ||
|
|
52974615f2 | ||
|
|
76a725eaf2 | ||
|
|
2e014b3c0a | ||
|
|
51101f7020 | ||
|
|
ba01f85340 | ||
|
|
723357fe3d | ||
|
|
e025c68130 | ||
|
|
7acc85f81c | ||
|
|
4846a74320 | ||
|
|
9177ddd406 | ||
|
|
9d21a4f359 | ||
|
|
20720c832d | ||
|
|
448f2a3cb2 | ||
|
|
397d5e0fac | ||
|
|
9400f07e45 | ||
|
|
a85e0da9b0 | ||
|
|
03b9fe0c5e | ||
|
|
42d57121f7 | ||
|
|
ed8137a79c | ||
|
|
d9761d2dc8 | ||
|
|
04f1d68d1e | ||
|
|
3deea69c4d | ||
|
|
980a89c908 | ||
|
|
de39594a46 | ||
|
|
6e6cca33b8 | ||
|
|
18f6d954a7 | ||
|
|
1a95df7b64 | ||
|
|
afefc30a67 | ||
|
|
0c672fef6f | ||
|
|
bc67283f2a | ||
|
|
f672a71f3d | ||
|
|
ef709b5611 | ||
|
|
7543b2256c | ||
|
|
0855507298 |
No files matched your search
@@ -39,6 +39,7 @@ See [faq](https://github.com/gokcehan/lf/wiki/FAQ) for more information.
|
||||
## May-Futures
|
||||
|
||||
- Bookmarks
|
||||
- Mouse control
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -52,6 +53,8 @@ See [packages](https://github.com/gokcehan/lf/wiki/Packages) for community maint
|
||||
|
||||
## Usage
|
||||
|
||||
See [tutorial](https://github.com/gokcehan/lf/wiki/Tutorial) for a gentle introduction with screencasts.
|
||||
|
||||
After the installation `lf` command should start the application in the current directory.
|
||||
|
||||
Run `lf -help` to see command line options.
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type cmdItem struct {
|
||||
@@ -17,14 +18,15 @@ type cmdItem struct {
|
||||
}
|
||||
|
||||
type app struct {
|
||||
ui *ui
|
||||
nav *nav
|
||||
quitChan chan bool
|
||||
cmd *exec.Cmd
|
||||
cmdIn io.WriteCloser
|
||||
cmdOutBuf []byte
|
||||
cmdHist []cmdItem
|
||||
cmdHistInd int
|
||||
ui *ui
|
||||
nav *nav
|
||||
ticker *time.Ticker
|
||||
quitChan chan bool
|
||||
cmd *exec.Cmd
|
||||
cmdIn io.WriteCloser
|
||||
cmdOutBuf []byte
|
||||
cmdHistory []cmdItem
|
||||
cmdHistoryInd int
|
||||
}
|
||||
|
||||
func newApp() *app {
|
||||
@@ -34,6 +36,7 @@ func newApp() *app {
|
||||
return &app{
|
||||
ui: ui,
|
||||
nav: nav,
|
||||
ticker: new(time.Ticker),
|
||||
quitChan: make(chan bool, 1),
|
||||
}
|
||||
}
|
||||
@@ -49,6 +52,7 @@ func (app *app) readFile(path string) {
|
||||
defer f.Close()
|
||||
|
||||
p := newParser(f)
|
||||
|
||||
for p.parse() {
|
||||
p.expr.eval(app, nil)
|
||||
}
|
||||
@@ -58,9 +62,10 @@ func (app *app) readFile(path string) {
|
||||
}
|
||||
}
|
||||
|
||||
// This is the main event loop of the application. There are two channels to
|
||||
// read expressions from client and server. Reading and evaluation are done on
|
||||
// separate goroutines.
|
||||
// This is the main event loop of the application. Expressions are read from
|
||||
// the client and the server on separate goroutines and sent here over channels
|
||||
// for evaluation. Similarly directories and regular files are also read in
|
||||
// separate goroutines and sent here for update.
|
||||
func (app *app) loop() {
|
||||
clientChan := app.ui.readExpr()
|
||||
serverChan := readExpr()
|
||||
@@ -130,6 +135,10 @@ func (app *app) loop() {
|
||||
case e := <-serverChan:
|
||||
e.eval(app, nil)
|
||||
app.ui.draw(app.nav)
|
||||
case <-app.ticker.C:
|
||||
app.nav.renew()
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.draw(app.nav)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -170,13 +179,13 @@ func waitKey() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// This function is used to run a command in shell. Following modes are used:
|
||||
// This function is used to run a shell command. Modes are as follows:
|
||||
//
|
||||
// Prefix Wait Async Stdin Stdout Stderr UI action
|
||||
// $ No No Yes Yes Yes Pause and then resume
|
||||
// % No No Yes Yes Yes Use statline for input/output
|
||||
// ! Yes No Yes Yes Yes Pause and then resume
|
||||
// & No Yes No No No Do nothing
|
||||
// Prefix Wait Async Stdin Stdout Stderr UI action
|
||||
// $ No No Yes Yes Yes Pause and then resume
|
||||
// % No No Yes Yes Yes Statline for input/output
|
||||
// ! Yes No Yes Yes Yes Pause and then resume
|
||||
// & No Yes No No No Do nothing
|
||||
func (app *app) runShell(s string, args []string, prefix string) {
|
||||
app.exportVars()
|
||||
|
||||
|
||||
@@ -13,13 +13,13 @@ import (
|
||||
)
|
||||
|
||||
func run() {
|
||||
logFile, err := os.Create(gLogPath)
|
||||
f, err := os.Create(gLogPath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer os.Remove(gLogPath)
|
||||
defer logFile.Close()
|
||||
log.SetOutput(logFile)
|
||||
defer f.Close()
|
||||
log.SetOutput(f)
|
||||
|
||||
log.Print("hi!")
|
||||
|
||||
|
||||
@@ -12,6 +12,29 @@ import (
|
||||
|
||||
const gAnsiColorResetMask = termbox.AttrBold | termbox.AttrUnderline | termbox.AttrReverse
|
||||
|
||||
var gAnsiCodes = map[int]termbox.Attribute{
|
||||
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
|
||||
@@ -57,13 +80,12 @@ func applyAnsiCodes(s string, fg, bg termbox.Attribute) (termbox.Attribute, term
|
||||
toks := strings.Split(s, ";")
|
||||
|
||||
var nums []int
|
||||
for _, t := range toks {
|
||||
if t == "" {
|
||||
fg = termbox.ColorDefault
|
||||
bg = termbox.ColorDefault
|
||||
break
|
||||
for _, tok := range toks {
|
||||
if tok == "" {
|
||||
nums = append(nums, 0)
|
||||
continue
|
||||
}
|
||||
n, err := strconv.Atoi(t)
|
||||
n, err := strconv.Atoi(tok)
|
||||
if err != nil {
|
||||
log.Printf("converting escape code: %s", err)
|
||||
continue
|
||||
@@ -71,17 +93,19 @@ func applyAnsiCodes(s string, fg, bg termbox.Attribute) (termbox.Attribute, term
|
||||
nums = append(nums, n)
|
||||
}
|
||||
|
||||
// parse 256 color terminal ansi codes
|
||||
if len(nums) == 3 {
|
||||
if nums[0] == 48 && nums[1] == 5 {
|
||||
bg = termbox.Attribute(nums[2] + 1)
|
||||
for i := 0; i < len(nums); i++ {
|
||||
n := nums[i]
|
||||
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
|
||||
}
|
||||
if nums[0] == 38 && nums[1] == 5 {
|
||||
fg = termbox.Attribute(nums[2] + 1)
|
||||
}
|
||||
}
|
||||
|
||||
for _, n := range nums {
|
||||
attr, ok := gAnsiCodes[n]
|
||||
if !ok {
|
||||
log.Printf("unknown ansi code: %d", n)
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/nsf/termbox-go"
|
||||
)
|
||||
|
||||
func TestApplyAnsiCodes(t *testing.T) {
|
||||
none := termbox.ColorDefault
|
||||
|
||||
tests := []struct {
|
||||
s string
|
||||
fg termbox.Attribute
|
||||
bg termbox.Attribute
|
||||
fgExp termbox.Attribute
|
||||
bgExp termbox.Attribute
|
||||
}{
|
||||
{"", none, none, none, none},
|
||||
{"", termbox.ColorRed, termbox.ColorRed, none, none},
|
||||
{"", termbox.AttrBold, none, none, none},
|
||||
{"", termbox.ColorRed | termbox.AttrBold, none, none, none},
|
||||
|
||||
{"0", none, none, none, none},
|
||||
{"0", termbox.ColorRed, termbox.ColorRed, none, none},
|
||||
{"0", termbox.AttrBold, none, none, none},
|
||||
{"0", termbox.ColorRed | termbox.AttrBold, none, none, none},
|
||||
|
||||
{"1", none, none, termbox.AttrBold, none},
|
||||
{"4", none, none, termbox.AttrUnderline, none},
|
||||
{"7", none, none, termbox.AttrReverse, none},
|
||||
|
||||
{"1", termbox.ColorRed, none, termbox.ColorRed | termbox.AttrBold, none},
|
||||
{"4", termbox.ColorRed, none, termbox.ColorRed | termbox.AttrUnderline, none},
|
||||
{"7", termbox.ColorRed, none, termbox.ColorRed | termbox.AttrReverse, none},
|
||||
|
||||
{"4", termbox.AttrBold, none, termbox.AttrBold | termbox.AttrUnderline, none},
|
||||
{"4", termbox.ColorRed | termbox.AttrBold, none, termbox.ColorRed | termbox.AttrBold | termbox.AttrUnderline, none},
|
||||
|
||||
{"31", none, none, termbox.ColorRed, none},
|
||||
{"31", termbox.ColorGreen, none, termbox.ColorRed, none},
|
||||
{"31", termbox.ColorGreen | termbox.AttrBold, none, termbox.ColorRed | termbox.AttrBold, none},
|
||||
|
||||
{"41", none, none, none, termbox.ColorRed},
|
||||
{"41", none, termbox.ColorGreen, none, termbox.ColorRed},
|
||||
|
||||
{"1;31", none, none, termbox.ColorRed | termbox.AttrBold, none},
|
||||
{"1;31", termbox.ColorGreen, none, termbox.ColorRed | termbox.AttrBold, none},
|
||||
|
||||
{"38;5;0", none, none, termbox.ColorBlack, none},
|
||||
{"38;5;1", none, none, termbox.ColorRed, none},
|
||||
{"38;5;8", none, none, termbox.Attribute(9), none},
|
||||
{"38;5;16", none, none, termbox.Attribute(17), none},
|
||||
{"38;5;232", none, none, termbox.Attribute(233), none},
|
||||
|
||||
{"38;5;1", termbox.ColorGreen, none, termbox.ColorRed, none},
|
||||
{"38;5;1", termbox.ColorGreen | termbox.AttrBold, none, termbox.ColorRed | termbox.AttrBold, none},
|
||||
|
||||
{"48;5;0", none, none, none, termbox.ColorBlack},
|
||||
{"48;5;1", none, none, none, termbox.ColorRed},
|
||||
{"48;5;8", none, none, none, termbox.Attribute(9)},
|
||||
{"48;5;16", none, none, none, termbox.Attribute(17)},
|
||||
{"48;5;232", none, none, none, termbox.Attribute(233)},
|
||||
|
||||
{"48;5;1", none, termbox.ColorGreen, none, termbox.ColorRed},
|
||||
|
||||
{"1;38;5;1", none, none, termbox.ColorRed | termbox.AttrBold, none},
|
||||
{"1;38;5;1", termbox.ColorGreen, none, termbox.ColorRed | termbox.AttrBold, none},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
if fgGot, bgGot := applyAnsiCodes(test.s, test.fg, test.bg); fgGot != test.fgExp || bgGot != test.bgExp {
|
||||
t.Errorf("at input '%s' with '%d' and '%d' expected '%d' and '%d' but got '%d' and '%d'",
|
||||
test.s, test.fg, test.bg, test.fgExp, test.bgExp, fgGot, bgGot)
|
||||
}
|
||||
}
|
||||
}
|
||||
+55
-45
@@ -24,7 +24,7 @@ var (
|
||||
"open",
|
||||
"quit",
|
||||
"top",
|
||||
"bot",
|
||||
"bottom",
|
||||
"toggle",
|
||||
"invert",
|
||||
"unmark",
|
||||
@@ -34,6 +34,7 @@ var (
|
||||
"clear",
|
||||
"draw",
|
||||
"redraw",
|
||||
"load",
|
||||
"reload",
|
||||
"read",
|
||||
"shell",
|
||||
@@ -82,6 +83,7 @@ var (
|
||||
"wrapscan",
|
||||
"nowrapscan",
|
||||
"wrapscan!",
|
||||
"period",
|
||||
"scrolloff",
|
||||
"tabstop",
|
||||
"filesep",
|
||||
@@ -108,13 +110,15 @@ func matchLongest(s1, s2 string) string {
|
||||
|
||||
func matchWord(s string, words []string) (matches []string, longest string) {
|
||||
for _, w := range words {
|
||||
if strings.HasPrefix(w, s) {
|
||||
matches = append(matches, w)
|
||||
if longest != "" {
|
||||
longest = matchLongest(longest, w)
|
||||
} else if s != "" {
|
||||
longest = w + " "
|
||||
}
|
||||
if !strings.HasPrefix(w, s) {
|
||||
continue
|
||||
}
|
||||
|
||||
matches = append(matches, w)
|
||||
if longest != "" {
|
||||
longest = matchLongest(longest, w)
|
||||
} else if s != "" {
|
||||
longest = w + " "
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,25 +139,27 @@ func matchExec(s string) (matches []string, longest string) {
|
||||
continue
|
||||
}
|
||||
|
||||
fi, err := ioutil.ReadDir(p)
|
||||
files, err := ioutil.ReadDir(p)
|
||||
if err != nil {
|
||||
log.Printf("reading path: %s", err)
|
||||
}
|
||||
|
||||
for _, f := range fi {
|
||||
if strings.HasPrefix(f.Name(), s) {
|
||||
f, err = os.Stat(filepath.Join(p, f.Name()))
|
||||
if err != nil {
|
||||
log.Printf("getting file information: %s", err)
|
||||
continue
|
||||
}
|
||||
|
||||
if !f.Mode().IsRegular() || f.Mode()&0111 == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
words = append(words, f.Name())
|
||||
for _, f := range files {
|
||||
if !strings.HasPrefix(f.Name(), s) {
|
||||
continue
|
||||
}
|
||||
|
||||
f, err = os.Stat(filepath.Join(p, f.Name()))
|
||||
if err != nil {
|
||||
log.Printf("getting file information: %s", err)
|
||||
continue
|
||||
}
|
||||
|
||||
if !f.Mode().IsRegular() || f.Mode()&0111 == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
words = append(words, f.Name())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,12 +191,12 @@ func matchFile(s string) (matches []string, longest string) {
|
||||
|
||||
dir = unescape(filepath.Dir(dir))
|
||||
|
||||
fi, err := ioutil.ReadDir(dir)
|
||||
files, err := ioutil.ReadDir(dir)
|
||||
if err != nil {
|
||||
log.Printf("reading directory: %s", err)
|
||||
}
|
||||
|
||||
for _, f := range fi {
|
||||
for _, f := range files {
|
||||
f, err := os.Stat(filepath.Join(dir, f.Name()))
|
||||
if err != nil {
|
||||
log.Printf("getting file information: %s", err)
|
||||
@@ -198,25 +204,29 @@ func matchFile(s string) (matches []string, longest string) {
|
||||
}
|
||||
|
||||
_, last := filepath.Split(s)
|
||||
if strings.HasPrefix(escape(f.Name()), last) {
|
||||
name := f.Name()
|
||||
if isRoot(s) || filepath.Base(s) != s {
|
||||
name = filepath.Join(filepath.Dir(s), f.Name())
|
||||
}
|
||||
name = escape(name)
|
||||
item := f.Name()
|
||||
if f.Mode().IsDir() {
|
||||
item += string(filepath.Separator)
|
||||
}
|
||||
matches = append(matches, item)
|
||||
if longest != "" {
|
||||
longest = matchLongest(longest, name)
|
||||
} else if s != "" {
|
||||
if f.Mode().IsRegular() {
|
||||
longest = name + " "
|
||||
} else {
|
||||
longest = name + string(filepath.Separator)
|
||||
}
|
||||
if !strings.HasPrefix(escape(f.Name()), last) {
|
||||
continue
|
||||
}
|
||||
|
||||
name := f.Name()
|
||||
if isRoot(s) || filepath.Base(s) != s {
|
||||
name = filepath.Join(filepath.Dir(s), f.Name())
|
||||
}
|
||||
name = escape(name)
|
||||
|
||||
item := f.Name()
|
||||
if f.Mode().IsDir() {
|
||||
item += string(filepath.Separator)
|
||||
}
|
||||
matches = append(matches, item)
|
||||
|
||||
if longest != "" {
|
||||
longest = matchLongest(longest, name)
|
||||
} else if s != "" {
|
||||
if f.Mode().IsRegular() {
|
||||
longest = name + " "
|
||||
} else {
|
||||
longest = name + string(filepath.Separator)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -228,7 +238,7 @@ func matchFile(s string) (matches []string, longest string) {
|
||||
return
|
||||
}
|
||||
|
||||
func compCmd(acc []rune) (matches []string, longestAcc []rune) {
|
||||
func completeCmd(acc []rune) (matches []string, longestAcc []rune) {
|
||||
s := string(acc)
|
||||
f := tokenize(s)
|
||||
|
||||
@@ -267,7 +277,7 @@ func compCmd(acc []rune) (matches []string, longestAcc []rune) {
|
||||
return
|
||||
}
|
||||
|
||||
func compShell(acc []rune) (matches []string, longestAcc []rune) {
|
||||
func completeShell(acc []rune) (matches []string, longestAcc []rune) {
|
||||
s := string(acc)
|
||||
f := tokenize(s)
|
||||
|
||||
File renamed without changes.
@@ -22,7 +22,7 @@ The following commands are provided by lf with default keybindings:
|
||||
open (default 'l' and '<right>')
|
||||
quit (default 'q')
|
||||
top (default 'gg')
|
||||
bot (default 'G')
|
||||
bottom (default 'G')
|
||||
toggle (default '<space>')
|
||||
invert (default 'v')
|
||||
unmark (default 'u')
|
||||
@@ -45,6 +45,7 @@ The following commands are provided by lf with default keybindings:
|
||||
The following commands are provided by lf without default keybindings:
|
||||
|
||||
draw draw the ui
|
||||
load load modified files and directories
|
||||
sync synchronizes yanked/deleted files with server
|
||||
echo prints its arguments to the message line
|
||||
cd changes working directory to its argument
|
||||
@@ -54,23 +55,30 @@ The following commands are provided by lf without default keybindings:
|
||||
The following command line commands are provided by lf with default
|
||||
keybindings:
|
||||
|
||||
cmd-escape (default '<esc>')
|
||||
cmd-comp (default '<tab>')
|
||||
cmd-enter (default '<c-j>' and '<enter>')
|
||||
cmd-hist-next (default '<c-n>')
|
||||
cmd-hist-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-right (default '<c-f>' and '<right>')
|
||||
cmd-beg (default '<c-a>' and '<home>')
|
||||
cmd-end (default '<c-e>' and '<end>')
|
||||
cmd-delete-beg (default '<c-u>')
|
||||
cmd-delete-end (default '<c-k>')
|
||||
cmd-delete-word (default '<c-w>')
|
||||
cmd-put (default '<c-y>')
|
||||
cmd-transpose (default '<c-t>')
|
||||
cmd-interrupt (default '<c-c>')
|
||||
cmd-escape (default '<esc>')
|
||||
cmd-complete (default '<tab>')
|
||||
cmd-enter (default '<c-j>' and '<enter>')
|
||||
cmd-history-next (default '<c-n>')
|
||||
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-right (default '<c-f>' and '<right>')
|
||||
cmd-home (default '<c-a>' and '<home>')
|
||||
cmd-end (default '<c-e>' and '<end>')
|
||||
cmd-delete-home (default '<c-u>')
|
||||
cmd-delete-end (default '<c-k>')
|
||||
cmd-delete-unix-word (default '<c-w>')
|
||||
cmd-yank (default '<c-y>')
|
||||
cmd-transpose (default '<c-t>')
|
||||
cmd-interrupt (default '<c-c>')
|
||||
cmd-word (default '<a-f>')
|
||||
cmd-word-back (default '<a-b>')
|
||||
cmd-capitalize-word (default '<a-c>')
|
||||
cmd-delete-word (default '<a-d>')
|
||||
cmd-uppercase-word (default '<a-u>')
|
||||
cmd-lowercase-word (default '<a-l>')
|
||||
cmd-transpose-word (default '<a-t>')
|
||||
|
||||
The following options can be used to customize the behavior of lf:
|
||||
|
||||
@@ -84,6 +92,7 @@ The following options can be used to customize the behavior of lf:
|
||||
reverse boolean (default off)
|
||||
smartcase boolean (default on)
|
||||
wrapscan boolean (default on)
|
||||
period integer (default 0)
|
||||
scrolloff integer (default 0)
|
||||
tabstop integer (default 8)
|
||||
filesep string (default "\n")
|
||||
@@ -124,8 +133,8 @@ The following keybindings to applications are provided by default on unix:
|
||||
|
||||
The following keybindings to applications are provided by default on windows:
|
||||
|
||||
map e $notepad "%f%"
|
||||
map i $more "%f%"
|
||||
map e $notepad %f%
|
||||
map i $more %f%
|
||||
map w $cmd
|
||||
|
||||
Configuration
|
||||
@@ -154,10 +163,11 @@ The following command prefixes are used by lf:
|
||||
/ search search file in current directory
|
||||
? search-back search file in the reverse order
|
||||
|
||||
The same evaluator is used for the command line and the configuration file. The
|
||||
difference is that prefixes are not necessary in the command line. Instead
|
||||
different modes are provided to read corresponding commands. Note that by
|
||||
default these modes are mapped to the prefix keys above.
|
||||
The same evaluator is used for the command line and the configuration file for
|
||||
read and shell commands. The difference is that prefixes are not necessary in
|
||||
the command line. Instead, different modes are provided to read corresponding
|
||||
commands. These modes are mapped to the prefix keys above by default. Searching
|
||||
commands are only used from the command line.
|
||||
|
||||
Syntax
|
||||
|
||||
@@ -184,7 +194,7 @@ command, or shell command:
|
||||
map gh cd ~ # builtin command
|
||||
map D trash # custom command
|
||||
map i $less $f # shell command
|
||||
map u !du -h . # waiting shell command
|
||||
map U !du -sh # waiting shell command
|
||||
|
||||
'cmap' is used to bind a key to a command line command which can only be one of
|
||||
the builtin commands:
|
||||
@@ -198,7 +208,7 @@ You can delete an existing binding by leaving the expression empty:
|
||||
|
||||
'cmd' is used to define a custom command
|
||||
|
||||
cmd usage $du -h . | less
|
||||
cmd usage $du -h -d1 | less
|
||||
|
||||
You can delete an existing command by leaving the expression empty:
|
||||
|
||||
@@ -221,6 +231,53 @@ prefix.
|
||||
set info time
|
||||
}}
|
||||
|
||||
Key Mappings
|
||||
|
||||
Regular keys are assigned to a command with the usual syntax:
|
||||
|
||||
map a down
|
||||
|
||||
Keys combined with the shift key simply use the uppercase letter:
|
||||
|
||||
map A down
|
||||
|
||||
Special keys are written in between '<' and '>' characters and always use
|
||||
lowercase letters:
|
||||
|
||||
map <enter> down
|
||||
|
||||
Angle brackets can be assigned with their special names:
|
||||
|
||||
map <lt> down
|
||||
map <gt> down
|
||||
|
||||
Function keys are prefixed with 'f' character:
|
||||
|
||||
map <f-1> down
|
||||
|
||||
Keys combined with the control key are prefixed with 'c' character:
|
||||
|
||||
map <c-a> down
|
||||
|
||||
Keys combined with the alt key are assigned in two different ways depending on
|
||||
the behavior of your terminal. Older terminals (e.g. xterm) may set the 8th bit
|
||||
of a character when the alt key is pressed. On these terminals, you can use the
|
||||
corresponding byte for the mapping:
|
||||
|
||||
map á down
|
||||
|
||||
Newer terminals (e.g. gnome-terminal) may prefix the key with an escape key
|
||||
when the alt key is pressed. lf uses the escape delaying mechanism to recognize
|
||||
alt keys in these terminals (delay is 100ms). On these terminals, keys combined
|
||||
with the alt key are prefixed with 'a' character:
|
||||
|
||||
map <a-a> down
|
||||
|
||||
Please note that, some key combinations are not possible due to the way
|
||||
terminals work (e.g. control and h combination sends a backspace key instead).
|
||||
The easiest way to find the name of a key combination is to press the key while
|
||||
lf is running and read the name of the key from the unknown mapping error.
|
||||
|
||||
Push Mappings
|
||||
|
||||
The usual way to map a key sequence is to assign it to a named or unnamed
|
||||
@@ -370,7 +427,7 @@ Since lf does not have control flow syntax, remote commands are used for such
|
||||
needs. For example, you can configure the number of columns in the ui with
|
||||
respect to the terminal width as follows:
|
||||
|
||||
cmd recol ${{
|
||||
cmd recol %{{
|
||||
w=$(tput cols)
|
||||
if [ $w -le 80 ]; then
|
||||
lf -remote "send $id set ratios 1:2"
|
||||
@@ -426,9 +483,9 @@ implementation. The default behavior is similar to the following command:
|
||||
elif [ $mode = 'move' ]; then
|
||||
mv -n $list .
|
||||
fi
|
||||
lf -remote "send $id reload"
|
||||
lf -remote "$(printf 'save\nmove\n\n')"
|
||||
lf -remote "send sync"
|
||||
lf -remote 'send load'
|
||||
lf -remote 'send sync'
|
||||
}}
|
||||
|
||||
Some useful things are to use the backup option ('--backup') with 'cp' and 'mv'
|
||||
@@ -465,9 +522,9 @@ You may want to use either file extensions or mime types from 'file' command:
|
||||
|
||||
Following commands are provided by default:
|
||||
|
||||
cmd open-file &start "" "%f%" # windows
|
||||
cmd open-file &open "$f" # mac
|
||||
cmd open-file &xdg-open "$f" # others
|
||||
cmd open-file &start %f% # windows
|
||||
cmd open-file &open "$f" # mac
|
||||
cmd open-file &xdg-open "$f" # others
|
||||
|
||||
You may also use any other existing file openers as you like. Possible options
|
||||
are 'libfile-mimeinfo-perl' (executable name is 'mimeopen'), 'rifle' (ranger's
|
||||
|
||||
+91
-32
@@ -26,7 +26,7 @@ The following commands are provided by lf with default keybindings:
|
||||
open (default 'l' and '<right>')
|
||||
quit (default 'q')
|
||||
top (default 'gg')
|
||||
bot (default 'G')
|
||||
bottom (default 'G')
|
||||
toggle (default '<space>')
|
||||
invert (default 'v')
|
||||
unmark (default 'u')
|
||||
@@ -49,6 +49,7 @@ The following commands are provided by lf with default keybindings:
|
||||
The following commands are provided by lf without default keybindings:
|
||||
|
||||
draw draw the ui
|
||||
load load modified files and directories
|
||||
sync synchronizes yanked/deleted files with server
|
||||
echo prints its arguments to the message line
|
||||
cd changes working directory to its argument
|
||||
@@ -58,23 +59,30 @@ The following commands are provided by lf without default keybindings:
|
||||
The following command line commands are provided by lf with default
|
||||
keybindings:
|
||||
|
||||
cmd-escape (default '<esc>')
|
||||
cmd-comp (default '<tab>')
|
||||
cmd-enter (default '<c-j>' and '<enter>')
|
||||
cmd-hist-next (default '<c-n>')
|
||||
cmd-hist-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-right (default '<c-f>' and '<right>')
|
||||
cmd-beg (default '<c-a>' and '<home>')
|
||||
cmd-end (default '<c-e>' and '<end>')
|
||||
cmd-delete-beg (default '<c-u>')
|
||||
cmd-delete-end (default '<c-k>')
|
||||
cmd-delete-word (default '<c-w>')
|
||||
cmd-put (default '<c-y>')
|
||||
cmd-transpose (default '<c-t>')
|
||||
cmd-interrupt (default '<c-c>')
|
||||
cmd-escape (default '<esc>')
|
||||
cmd-complete (default '<tab>')
|
||||
cmd-enter (default '<c-j>' and '<enter>')
|
||||
cmd-history-next (default '<c-n>')
|
||||
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-right (default '<c-f>' and '<right>')
|
||||
cmd-home (default '<c-a>' and '<home>')
|
||||
cmd-end (default '<c-e>' and '<end>')
|
||||
cmd-delete-home (default '<c-u>')
|
||||
cmd-delete-end (default '<c-k>')
|
||||
cmd-delete-unix-word (default '<c-w>')
|
||||
cmd-yank (default '<c-y>')
|
||||
cmd-transpose (default '<c-t>')
|
||||
cmd-interrupt (default '<c-c>')
|
||||
cmd-word (default '<a-f>')
|
||||
cmd-word-back (default '<a-b>')
|
||||
cmd-capitalize-word (default '<a-c>')
|
||||
cmd-delete-word (default '<a-d>')
|
||||
cmd-uppercase-word (default '<a-u>')
|
||||
cmd-lowercase-word (default '<a-l>')
|
||||
cmd-transpose-word (default '<a-t>')
|
||||
|
||||
The following options can be used to customize the behavior of lf:
|
||||
|
||||
@@ -88,6 +96,7 @@ The following options can be used to customize the behavior of lf:
|
||||
reverse boolean (default off)
|
||||
smartcase boolean (default on)
|
||||
wrapscan boolean (default on)
|
||||
period integer (default 0)
|
||||
scrolloff integer (default 0)
|
||||
tabstop integer (default 8)
|
||||
filesep string (default "\n")
|
||||
@@ -129,8 +138,8 @@ The following keybindings to applications are provided by default on unix:
|
||||
The following keybindings to applications are provided by default on
|
||||
windows:
|
||||
|
||||
map e $notepad "%f%"
|
||||
map i $more "%f%"
|
||||
map e $notepad %f%
|
||||
map i $more %f%
|
||||
map w $cmd
|
||||
|
||||
|
||||
@@ -161,10 +170,11 @@ The following command prefixes are used by lf:
|
||||
/ search search file in current directory
|
||||
? search-back search file in the reverse order
|
||||
|
||||
The same evaluator is used for the command line and the configuration file.
|
||||
The difference is that prefixes are not necessary in the command line.
|
||||
Instead different modes are provided to read corresponding commands. Note
|
||||
that by default these modes are mapped to the prefix keys above.
|
||||
The same evaluator is used for the command line and the configuration file
|
||||
for read and shell commands. The difference is that prefixes are not
|
||||
necessary in the command line. Instead, different modes are provided to read
|
||||
corresponding commands. These modes are mapped to the prefix keys above by
|
||||
default. Searching commands are only used from the command line.
|
||||
|
||||
|
||||
Syntax
|
||||
@@ -192,7 +202,7 @@ custom command, or shell command:
|
||||
map gh cd ~ # builtin command
|
||||
map D trash # custom command
|
||||
map i $less $f # shell command
|
||||
map u !du -h . # waiting shell command
|
||||
map U !du -sh # waiting shell command
|
||||
|
||||
'cmap' is used to bind a key to a command line command which can only be one
|
||||
of the builtin commands:
|
||||
@@ -206,7 +216,7 @@ You can delete an existing binding by leaving the expression empty:
|
||||
|
||||
'cmd' is used to define a custom command
|
||||
|
||||
cmd usage $du -h . | less
|
||||
cmd usage $du -h -d1 | less
|
||||
|
||||
You can delete an existing command by leaving the expression empty:
|
||||
|
||||
@@ -230,6 +240,55 @@ proper prefix.
|
||||
}}
|
||||
|
||||
|
||||
Key Mappings
|
||||
|
||||
Regular keys are assigned to a command with the usual syntax:
|
||||
|
||||
map a down
|
||||
|
||||
Keys combined with the shift key simply use the uppercase letter:
|
||||
|
||||
map A down
|
||||
|
||||
Special keys are written in between '<' and '>' characters and always use
|
||||
lowercase letters:
|
||||
|
||||
map <enter> down
|
||||
|
||||
Angle brackets can be assigned with their special names:
|
||||
|
||||
map <lt> down
|
||||
map <gt> down
|
||||
|
||||
Function keys are prefixed with 'f' character:
|
||||
|
||||
map <f-1> down
|
||||
|
||||
Keys combined with the control key are prefixed with 'c' character:
|
||||
|
||||
map <c-a> down
|
||||
|
||||
Keys combined with the alt key are assigned in two different ways depending
|
||||
on the behavior of your terminal. Older terminals (e.g. xterm) may set the
|
||||
8th bit of a character when the alt key is pressed. On these terminals, you
|
||||
can use the corresponding byte for the mapping:
|
||||
|
||||
map á down
|
||||
|
||||
Newer terminals (e.g. gnome-terminal) may prefix the key with an escape key
|
||||
when the alt key is pressed. lf uses the escape delaying mechanism to
|
||||
recognize alt keys in these terminals (delay is 100ms). On these terminals,
|
||||
keys combined with the alt key are prefixed with 'a' character:
|
||||
|
||||
map <a-a> down
|
||||
|
||||
Please note that, some key combinations are not possible due to the way
|
||||
terminals work (e.g. control and h combination sends a backspace key
|
||||
instead). The easiest way to find the name of a key combination is to press
|
||||
the key while lf is running and read the name of the key from the unknown
|
||||
mapping error.
|
||||
|
||||
|
||||
Push Mappings
|
||||
|
||||
The usual way to map a key sequence is to assign it to a named or unnamed
|
||||
@@ -391,7 +450,7 @@ Since lf does not have control flow syntax, remote commands are used for
|
||||
such needs. For example, you can configure the number of columns in the ui
|
||||
with respect to the terminal width as follows:
|
||||
|
||||
cmd recol ${{
|
||||
cmd recol %{{
|
||||
w=$(tput cols)
|
||||
if [ $w -le 80 ]; then
|
||||
lf -remote "send $id set ratios 1:2"
|
||||
@@ -448,9 +507,9 @@ implementation. The default behavior is similar to the following command:
|
||||
elif [ $mode = 'move' ]; then
|
||||
mv -n $list .
|
||||
fi
|
||||
lf -remote "send $id reload"
|
||||
lf -remote "$(printf 'save\nmove\n\n')"
|
||||
lf -remote "send sync"
|
||||
lf -remote 'send load'
|
||||
lf -remote 'send sync'
|
||||
}}
|
||||
|
||||
Some useful things are to use the backup option ('--backup') with 'cp' and
|
||||
@@ -491,9 +550,9 @@ command:
|
||||
|
||||
Following commands are provided by default:
|
||||
|
||||
cmd open-file &start "" "%f%" # windows
|
||||
cmd open-file &open "$f" # mac
|
||||
cmd open-file &xdg-open "$f" # others
|
||||
cmd open-file &start %f% # windows
|
||||
cmd open-file &open "$f" # mac
|
||||
cmd open-file &xdg-open "$f" # others
|
||||
|
||||
You may also use any other existing file openers as you like. Possible
|
||||
options are 'libfile-mimeinfo-perl' (executable name is 'mimeopen'), 'rifle'
|
||||
|
||||
@@ -6,6 +6,8 @@ import (
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
@@ -50,15 +52,21 @@ func (e *setExpr) eval(app *app, args []string) {
|
||||
case "hidden":
|
||||
gOpts.sortType.option |= hiddenSort
|
||||
app.nav.sort()
|
||||
app.nav.position()
|
||||
app.ui.sort()
|
||||
app.ui.loadFile(app.nav)
|
||||
case "nohidden":
|
||||
gOpts.sortType.option &= ^hiddenSort
|
||||
app.nav.sort()
|
||||
app.nav.position()
|
||||
app.ui.sort()
|
||||
app.ui.loadFile(app.nav)
|
||||
case "hidden!":
|
||||
gOpts.sortType.option ^= hiddenSort
|
||||
app.nav.sort()
|
||||
app.nav.position()
|
||||
app.ui.sort()
|
||||
app.ui.loadFile(app.nav)
|
||||
case "ignorecase":
|
||||
gOpts.ignorecase = true
|
||||
case "noignorecase":
|
||||
@@ -95,6 +103,23 @@ func (e *setExpr) eval(app *app, args []string) {
|
||||
gOpts.wrapscan = false
|
||||
case "wrapscan!":
|
||||
gOpts.wrapscan = !gOpts.wrapscan
|
||||
case "period":
|
||||
n, err := strconv.Atoi(e.val)
|
||||
if err != nil {
|
||||
app.ui.printf("period: %s", err)
|
||||
return
|
||||
}
|
||||
if n < 0 {
|
||||
app.ui.print("period: value should be a non-negative number")
|
||||
return
|
||||
}
|
||||
gOpts.period = n
|
||||
if n == 0 {
|
||||
app.ticker.Stop()
|
||||
} else {
|
||||
app.ticker.Stop()
|
||||
app.ticker = time.NewTicker(time.Duration(gOpts.period) * time.Second)
|
||||
}
|
||||
case "scrolloff":
|
||||
n, err := strconv.Atoi(e.val)
|
||||
if err != nil {
|
||||
@@ -208,14 +233,14 @@ func (e *cmdExpr) eval(app *app, args []string) {
|
||||
|
||||
func splitKeys(s string) (keys []string) {
|
||||
for i := 0; i < len(s); {
|
||||
c, w := utf8.DecodeRuneInString(s[i:])
|
||||
if c != '<' {
|
||||
r, w := utf8.DecodeRuneInString(s[i:])
|
||||
if r != '<' {
|
||||
keys = append(keys, s[i:i+w])
|
||||
i += w
|
||||
} else {
|
||||
j := i + w
|
||||
for c != '>' && j < len(s) {
|
||||
c, w = utf8.DecodeRuneInString(s[j:])
|
||||
for r != '>' && j < len(s) {
|
||||
r, w = utf8.DecodeRuneInString(s[j:])
|
||||
j += w
|
||||
}
|
||||
keys = append(keys, s[i:j])
|
||||
@@ -315,8 +340,8 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
app.nav.top()
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "bot":
|
||||
app.nav.bot()
|
||||
case "bottom":
|
||||
app.nav.bottom()
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "toggle":
|
||||
@@ -354,7 +379,9 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
app.ui.printf("put: %s", err)
|
||||
return
|
||||
}
|
||||
app.nav.renew()
|
||||
if err := sendRemote("send load"); err != nil {
|
||||
app.ui.printf("put: %s", err)
|
||||
}
|
||||
if err := sendRemote("send sync"); err != nil {
|
||||
app.ui.printf("put: %s", err)
|
||||
}
|
||||
@@ -371,9 +398,9 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
app.ui.sync()
|
||||
app.ui.renew()
|
||||
app.nav.height = app.ui.wins[0].h
|
||||
case "load":
|
||||
app.nav.renew()
|
||||
case "reload":
|
||||
app.ui.sync()
|
||||
app.ui.renew()
|
||||
app.nav.reload()
|
||||
case "read":
|
||||
app.ui.cmdPrefix = ":"
|
||||
@@ -436,16 +463,19 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "push":
|
||||
if len(e.args) > 0 {
|
||||
log.Println("pushing keys", e.args[0])
|
||||
for _, key := range splitKeys(e.args[0]) {
|
||||
app.ui.keyChan <- key
|
||||
}
|
||||
if len(e.args) != 1 {
|
||||
app.ui.print("push: requires an argument")
|
||||
return
|
||||
}
|
||||
log.Println("pushing keys", e.args[0])
|
||||
for _, key := range splitKeys(e.args[0]) {
|
||||
app.ui.keyChan <- key
|
||||
}
|
||||
case "cmd-insert":
|
||||
if len(e.args) > 0 {
|
||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(e.args[0])...)
|
||||
if len(e.args) == 0 {
|
||||
return
|
||||
}
|
||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(e.args[0])...)
|
||||
case "cmd-escape":
|
||||
if app.ui.cmdPrefix == ">" {
|
||||
return
|
||||
@@ -454,12 +484,12 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
app.ui.cmdAccLeft = nil
|
||||
app.ui.cmdAccRight = nil
|
||||
app.ui.cmdPrefix = ""
|
||||
case "cmd-comp":
|
||||
case "cmd-complete":
|
||||
var matches []string
|
||||
if app.ui.cmdPrefix == ":" {
|
||||
matches, app.ui.cmdAccLeft = compCmd(app.ui.cmdAccLeft)
|
||||
matches, app.ui.cmdAccLeft = completeCmd(app.ui.cmdAccLeft)
|
||||
} else {
|
||||
matches, app.ui.cmdAccLeft = compShell(app.ui.cmdAccLeft)
|
||||
matches, app.ui.cmdAccLeft = completeShell(app.ui.cmdAccLeft)
|
||||
}
|
||||
app.ui.draw(app.nav)
|
||||
if len(matches) > 1 {
|
||||
@@ -485,24 +515,30 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
if p.err != nil {
|
||||
app.ui.printf("%s", p.err)
|
||||
}
|
||||
app.cmdHistory = append(app.cmdHistory, cmdItem{app.ui.cmdPrefix, s})
|
||||
app.ui.cmdPrefix = ""
|
||||
case "$":
|
||||
log.Printf("shell: %s", s)
|
||||
app.runShell(s, nil, app.ui.cmdPrefix)
|
||||
app.cmdHistory = append(app.cmdHistory, cmdItem{app.ui.cmdPrefix, s})
|
||||
app.ui.cmdPrefix = ""
|
||||
case "%":
|
||||
log.Printf("shell-pipe: %s", s)
|
||||
app.runShell(s, nil, app.ui.cmdPrefix)
|
||||
app.cmdHist = append(app.cmdHist, cmdItem{"%", s})
|
||||
return
|
||||
app.cmdHistory = append(app.cmdHistory, cmdItem{app.ui.cmdPrefix, s})
|
||||
case ">":
|
||||
io.WriteString(app.cmdIn, s+"\n")
|
||||
app.cmdOutBuf = nil
|
||||
return
|
||||
case "!":
|
||||
log.Printf("shell-wait: %s", s)
|
||||
app.runShell(s, nil, app.ui.cmdPrefix)
|
||||
app.cmdHistory = append(app.cmdHistory, cmdItem{app.ui.cmdPrefix, s})
|
||||
app.ui.cmdPrefix = ""
|
||||
case "&":
|
||||
log.Printf("shell-async: %s", s)
|
||||
app.runShell(s, nil, app.ui.cmdPrefix)
|
||||
app.cmdHistory = append(app.cmdHistory, cmdItem{app.ui.cmdPrefix, s})
|
||||
app.ui.cmdPrefix = ""
|
||||
case "/":
|
||||
log.Printf("search: %s", s)
|
||||
app.nav.search = s
|
||||
@@ -512,6 +548,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
}
|
||||
app.ui.cmdPrefix = ""
|
||||
case "?":
|
||||
log.Printf("search-back: %s", s)
|
||||
app.nav.search = s
|
||||
@@ -521,87 +558,96 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
}
|
||||
app.ui.cmdPrefix = ""
|
||||
default:
|
||||
log.Printf("entering unknown execution prefix: %q", app.ui.cmdPrefix)
|
||||
}
|
||||
app.cmdHist = append(app.cmdHist, cmdItem{app.ui.cmdPrefix, s})
|
||||
app.ui.cmdPrefix = ""
|
||||
case "cmd-hist-next":
|
||||
if app.ui.cmdPrefix == "" {
|
||||
case "cmd-history-next":
|
||||
if app.ui.cmdPrefix == "" || app.ui.cmdPrefix == ">" {
|
||||
return
|
||||
}
|
||||
if app.cmdHistInd > 0 {
|
||||
app.cmdHistInd--
|
||||
if app.cmdHistoryInd > 0 {
|
||||
app.cmdHistoryInd--
|
||||
}
|
||||
if app.cmdHistInd == 0 {
|
||||
if app.cmdHistoryInd == 0 {
|
||||
app.ui.menuBuf = nil
|
||||
app.ui.cmdAccLeft = nil
|
||||
app.ui.cmdAccRight = nil
|
||||
app.ui.cmdPrefix = ""
|
||||
return
|
||||
}
|
||||
cmd := app.cmdHist[len(app.cmdHist)-app.cmdHistInd]
|
||||
cmd := app.cmdHistory[len(app.cmdHistory)-app.cmdHistoryInd]
|
||||
app.ui.cmdPrefix = cmd.prefix
|
||||
app.ui.cmdAccLeft = []rune(cmd.value)
|
||||
app.ui.cmdAccRight = nil
|
||||
app.ui.menuBuf = nil
|
||||
case "cmd-hist-prev":
|
||||
if app.ui.cmdPrefix == "" {
|
||||
app.cmdHistInd = 0
|
||||
}
|
||||
if app.cmdHistInd == len(app.cmdHist) {
|
||||
case "cmd-history-prev":
|
||||
if app.ui.cmdPrefix == ">" {
|
||||
return
|
||||
}
|
||||
app.cmdHistInd++
|
||||
cmd := app.cmdHist[len(app.cmdHist)-app.cmdHistInd]
|
||||
if app.ui.cmdPrefix == "" {
|
||||
app.cmdHistoryInd = 0
|
||||
}
|
||||
if app.cmdHistoryInd == len(app.cmdHistory) {
|
||||
return
|
||||
}
|
||||
app.cmdHistoryInd++
|
||||
cmd := app.cmdHistory[len(app.cmdHistory)-app.cmdHistoryInd]
|
||||
app.ui.cmdPrefix = cmd.prefix
|
||||
app.ui.cmdAccLeft = []rune(cmd.value)
|
||||
app.ui.cmdAccRight = nil
|
||||
app.ui.menuBuf = nil
|
||||
case "cmd-delete":
|
||||
if len(app.ui.cmdAccRight) > 0 {
|
||||
app.ui.cmdAccRight = app.ui.cmdAccRight[1:]
|
||||
if len(app.ui.cmdAccRight) == 0 {
|
||||
return
|
||||
}
|
||||
app.ui.cmdAccRight = app.ui.cmdAccRight[1:]
|
||||
case "cmd-delete-back":
|
||||
if len(app.ui.cmdAccLeft) > 0 {
|
||||
app.ui.cmdAccLeft = app.ui.cmdAccLeft[:len(app.ui.cmdAccLeft)-1]
|
||||
if len(app.ui.cmdAccLeft) == 0 {
|
||||
return
|
||||
}
|
||||
app.ui.cmdAccLeft = app.ui.cmdAccLeft[:len(app.ui.cmdAccLeft)-1]
|
||||
case "cmd-left":
|
||||
if len(app.ui.cmdAccLeft) > 0 {
|
||||
app.ui.cmdAccRight = append([]rune{app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-1]}, app.ui.cmdAccRight...)
|
||||
app.ui.cmdAccLeft = app.ui.cmdAccLeft[:len(app.ui.cmdAccLeft)-1]
|
||||
if len(app.ui.cmdAccLeft) == 0 {
|
||||
return
|
||||
}
|
||||
app.ui.cmdAccRight = append([]rune{app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-1]}, app.ui.cmdAccRight...)
|
||||
app.ui.cmdAccLeft = app.ui.cmdAccLeft[:len(app.ui.cmdAccLeft)-1]
|
||||
case "cmd-right":
|
||||
if len(app.ui.cmdAccRight) > 0 {
|
||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdAccRight[0])
|
||||
app.ui.cmdAccRight = app.ui.cmdAccRight[1:]
|
||||
if len(app.ui.cmdAccRight) == 0 {
|
||||
return
|
||||
}
|
||||
case "cmd-beg":
|
||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdAccRight[0])
|
||||
app.ui.cmdAccRight = app.ui.cmdAccRight[1:]
|
||||
case "cmd-home":
|
||||
app.ui.cmdAccRight = append(app.ui.cmdAccLeft, app.ui.cmdAccRight...)
|
||||
app.ui.cmdAccLeft = nil
|
||||
case "cmd-end":
|
||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdAccRight...)
|
||||
app.ui.cmdAccRight = nil
|
||||
case "cmd-delete-beg":
|
||||
if len(app.ui.cmdAccLeft) > 0 {
|
||||
app.ui.cmdBuf = app.ui.cmdAccLeft
|
||||
app.ui.cmdAccLeft = nil
|
||||
case "cmd-delete-home":
|
||||
if len(app.ui.cmdAccLeft) == 0 {
|
||||
return
|
||||
}
|
||||
app.ui.cmdYankBuf = app.ui.cmdAccLeft
|
||||
app.ui.cmdAccLeft = nil
|
||||
case "cmd-delete-end":
|
||||
if len(app.ui.cmdAccRight) > 0 {
|
||||
app.ui.cmdBuf = app.ui.cmdAccRight
|
||||
app.ui.cmdAccRight = nil
|
||||
if len(app.ui.cmdAccRight) == 0 {
|
||||
return
|
||||
}
|
||||
case "cmd-delete-word":
|
||||
app.ui.cmdYankBuf = app.ui.cmdAccRight
|
||||
app.ui.cmdAccRight = nil
|
||||
case "cmd-delete-unix-word":
|
||||
ind := strings.LastIndex(strings.TrimRight(string(app.ui.cmdAccLeft), " "), " ") + 1
|
||||
app.ui.cmdBuf = app.ui.cmdAccLeft[ind:]
|
||||
app.ui.cmdYankBuf = app.ui.cmdAccLeft[ind:]
|
||||
app.ui.cmdAccLeft = app.ui.cmdAccLeft[:ind]
|
||||
case "cmd-put":
|
||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdBuf...)
|
||||
case "cmd-yank":
|
||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdYankBuf...)
|
||||
case "cmd-transpose":
|
||||
if len(app.ui.cmdAccLeft) > 1 {
|
||||
app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-1], app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-2] = app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-2], app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-1]
|
||||
if len(app.ui.cmdAccLeft) < 2 {
|
||||
return
|
||||
}
|
||||
app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-1], app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-2] = app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-2], app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-1]
|
||||
case "cmd-interrupt":
|
||||
if app.cmd != nil {
|
||||
app.cmd.Process.Kill()
|
||||
@@ -610,6 +656,113 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
app.ui.cmdAccLeft = nil
|
||||
app.ui.cmdAccRight = nil
|
||||
app.ui.cmdPrefix = ""
|
||||
case "cmd-word":
|
||||
if len(app.ui.cmdAccRight) == 0 {
|
||||
return
|
||||
}
|
||||
loc := reWordEnd.FindStringIndex(string(app.ui.cmdAccRight))
|
||||
if loc == nil {
|
||||
return
|
||||
}
|
||||
ind := loc[0] + 1
|
||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdAccRight[:ind]...)
|
||||
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:]
|
||||
case "cmd-word-back":
|
||||
if len(app.ui.cmdAccLeft) == 0 {
|
||||
return
|
||||
}
|
||||
locs := reWordBeg.FindAllStringIndex(string(app.ui.cmdAccLeft), -1)
|
||||
if locs == nil {
|
||||
return
|
||||
}
|
||||
ind := locs[len(locs)-1][1] - 1
|
||||
old := app.ui.cmdAccRight
|
||||
app.ui.cmdAccRight = append([]rune{}, app.ui.cmdAccLeft[ind:]...)
|
||||
app.ui.cmdAccRight = append(app.ui.cmdAccRight, old...)
|
||||
app.ui.cmdAccLeft = app.ui.cmdAccLeft[:ind]
|
||||
case "cmd-capitalize-word":
|
||||
if len(app.ui.cmdAccRight) == 0 {
|
||||
return
|
||||
}
|
||||
ind := 0
|
||||
for ; ind < len(app.ui.cmdAccRight) && unicode.IsSpace(app.ui.cmdAccRight[ind]); ind++ {
|
||||
}
|
||||
if ind >= len(app.ui.cmdAccRight) {
|
||||
return
|
||||
}
|
||||
app.ui.cmdAccRight[ind] = unicode.ToUpper(app.ui.cmdAccRight[ind])
|
||||
loc := reWordEnd.FindStringIndex(string(app.ui.cmdAccRight))
|
||||
if loc == nil {
|
||||
return
|
||||
}
|
||||
ind = loc[0] + 1
|
||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdAccRight[:ind]...)
|
||||
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:]
|
||||
case "cmd-delete-word":
|
||||
if len(app.ui.cmdAccRight) == 0 {
|
||||
return
|
||||
}
|
||||
loc := reWordEnd.FindStringIndex(string(app.ui.cmdAccRight))
|
||||
if loc == nil {
|
||||
return
|
||||
}
|
||||
ind := loc[0] + 1
|
||||
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:]
|
||||
case "cmd-uppercase-word":
|
||||
if len(app.ui.cmdAccRight) == 0 {
|
||||
return
|
||||
}
|
||||
loc := reWordEnd.FindStringIndex(string(app.ui.cmdAccRight))
|
||||
if loc == nil {
|
||||
return
|
||||
}
|
||||
ind := loc[0] + 1
|
||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(strings.ToUpper(string(app.ui.cmdAccRight[:ind])))...)
|
||||
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:]
|
||||
case "cmd-lowercase-word":
|
||||
if len(app.ui.cmdAccRight) == 0 {
|
||||
return
|
||||
}
|
||||
loc := reWordEnd.FindStringIndex(string(app.ui.cmdAccRight))
|
||||
if loc == nil {
|
||||
return
|
||||
}
|
||||
ind := loc[0] + 1
|
||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(strings.ToLower(string(app.ui.cmdAccRight[:ind])))...)
|
||||
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:]
|
||||
case "cmd-transpose-word":
|
||||
if len(app.ui.cmdAccLeft) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
locs := reWord.FindAllStringIndex(string(app.ui.cmdAccLeft), -1)
|
||||
if len(locs) < 2 {
|
||||
return
|
||||
}
|
||||
|
||||
if len(app.ui.cmdAccRight) > 0 {
|
||||
loc := reWordEnd.FindStringIndex(string(app.ui.cmdAccRight))
|
||||
if loc != nil {
|
||||
ind := loc[0] + 1
|
||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdAccRight[:ind]...)
|
||||
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:]
|
||||
}
|
||||
}
|
||||
|
||||
locs = reWord.FindAllStringIndex(string(app.ui.cmdAccLeft), -1)
|
||||
|
||||
beg1, end1 := locs[len(locs)-2][0], locs[len(locs)-2][1]
|
||||
beg2, end2 := locs[len(locs)-1][0], locs[len(locs)-1][1]
|
||||
|
||||
var acc []rune
|
||||
|
||||
acc = append(acc, app.ui.cmdAccLeft[:beg1]...)
|
||||
acc = append(acc, app.ui.cmdAccLeft[beg2:end2]...)
|
||||
acc = append(acc, app.ui.cmdAccLeft[end1:beg2]...)
|
||||
acc = append(acc, app.ui.cmdAccLeft[beg1:end1]...)
|
||||
acc = append(acc, app.ui.cmdAccLeft[end2:]...)
|
||||
|
||||
app.ui.cmdAccLeft = acc
|
||||
default:
|
||||
cmd, ok := gOpts.cmds[e.name]
|
||||
if !ok {
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
@@ -42,6 +43,21 @@ func startServer() {
|
||||
}
|
||||
}
|
||||
|
||||
func checkServer() {
|
||||
if gSocketProt == "unix" {
|
||||
if _, err := os.Stat(gSocketPath); os.IsNotExist(err) {
|
||||
startServer()
|
||||
} else if _, err := net.Dial(gSocketProt, gSocketPath); err != nil {
|
||||
os.Remove(gSocketPath)
|
||||
startServer()
|
||||
}
|
||||
} else {
|
||||
if _, err := net.Dial(gSocketProt, gSocketPath); err != nil {
|
||||
startServer()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
showDoc := flag.Bool(
|
||||
"doc",
|
||||
@@ -125,10 +141,7 @@ func main() {
|
||||
gServerLogPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.server.log", gUser.Username))
|
||||
serve()
|
||||
default:
|
||||
// TODO: check if the socket is working
|
||||
if _, err := os.Stat(gSocketPath); os.IsNotExist(err) {
|
||||
startServer()
|
||||
}
|
||||
checkServer()
|
||||
|
||||
gClientID = 1000
|
||||
gLogPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.%d.log", gUser.Username, gClientID))
|
||||
|
||||
@@ -195,6 +195,12 @@ func naturalLess(s1, s2 string) bool {
|
||||
return len(parts1) < len(parts2)
|
||||
}
|
||||
|
||||
var reAltKey = regexp.MustCompile(`<a-(.)>`)
|
||||
|
||||
var reWord = regexp.MustCompile(`(\pL|\pN)+`)
|
||||
var reWordBeg = regexp.MustCompile(`([^\pL\pN]|^)(\pL|\pN)`)
|
||||
var reWordEnd = regexp.MustCompile(`(\pL|\pN)([^\pL\pN]|$)`)
|
||||
|
||||
func min(a, b int) int {
|
||||
if a < b {
|
||||
return a
|
||||
@@ -210,7 +216,7 @@ func max(a, b int) int {
|
||||
}
|
||||
|
||||
// We don't need no generic code
|
||||
// We don't need no thought control
|
||||
// We don't need no type control
|
||||
// No dark templates in compiler
|
||||
// Haskell leave them kids alone
|
||||
// Hey Bjarne leave them kids alone
|
||||
|
||||
@@ -27,21 +27,7 @@ type file struct {
|
||||
os.FileInfo
|
||||
linkState linkState
|
||||
path string
|
||||
count int
|
||||
}
|
||||
|
||||
type filesSortable struct {
|
||||
files []*file
|
||||
less func(i, j int) bool
|
||||
}
|
||||
|
||||
func (f filesSortable) Len() int { return len(f.files) }
|
||||
func (f filesSortable) Swap(i, j int) { f.files[i], f.files[j] = f.files[j], f.files[i] }
|
||||
func (f filesSortable) Less(i, j int) bool { return f.less(i, j) }
|
||||
|
||||
// TODO: Replace with `sort.SliceStable` once available
|
||||
func sortFilesStable(files []*file, less func(i, j int) bool) {
|
||||
sort.Stable(filesSortable{files: files, less: less})
|
||||
dirCount int
|
||||
}
|
||||
|
||||
func readdir(path string) ([]*file, error) {
|
||||
@@ -49,61 +35,59 @@ func readdir(path string) ([]*file, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
names, err := f.Readdirnames(-1)
|
||||
f.Close()
|
||||
|
||||
fi := make([]*file, 0, len(names))
|
||||
for _, filename := range names {
|
||||
fpath := filepath.Join(path, filename)
|
||||
files := make([]*file, 0, len(names))
|
||||
for _, fname := range names {
|
||||
fpath := filepath.Join(path, fname)
|
||||
|
||||
lstat, lerr := os.Lstat(fpath)
|
||||
if os.IsNotExist(lerr) {
|
||||
lstat, err := os.Lstat(fpath)
|
||||
if os.IsNotExist(err) {
|
||||
continue
|
||||
}
|
||||
if lerr != nil {
|
||||
return fi, lerr
|
||||
if err != nil {
|
||||
return files, err
|
||||
}
|
||||
|
||||
var linkState linkState
|
||||
|
||||
if lstat.Mode()&os.ModeSymlink != 0 {
|
||||
stat, serr := os.Stat(fpath)
|
||||
if serr == nil {
|
||||
stat, err := os.Stat(fpath)
|
||||
if err == nil {
|
||||
linkState = working
|
||||
lstat = stat
|
||||
} else {
|
||||
linkState = broken
|
||||
log.Printf("getting link destination info: %s", serr)
|
||||
}
|
||||
}
|
||||
|
||||
fi = append(fi, &file{
|
||||
files = append(files, &file{
|
||||
FileInfo: lstat,
|
||||
linkState: linkState,
|
||||
path: fpath,
|
||||
count: -1,
|
||||
dirCount: -1,
|
||||
})
|
||||
}
|
||||
|
||||
return fi, err
|
||||
return files, err
|
||||
}
|
||||
|
||||
type dir struct {
|
||||
loading bool // directory is loading from disk
|
||||
loadTime time.Time // current loading or last load time
|
||||
ind int // index of current entry in fi
|
||||
ind int // index of current entry in files
|
||||
pos int // position of current entry in ui
|
||||
path string // full path of directory
|
||||
fi []*file // displayed files in directory including or excluding hidden ones
|
||||
all []*file // all files in directory including hidden ones (same array as fi)
|
||||
files []*file // displayed files in directory including or excluding hidden ones
|
||||
allFiles []*file // all files in directory including hidden ones (same array as files)
|
||||
sortType sortType // sort method and options from last sort
|
||||
}
|
||||
|
||||
func newDir(path string) *dir {
|
||||
time := time.Now()
|
||||
|
||||
fi, err := readdir(path)
|
||||
files, err := readdir(path)
|
||||
if err != nil {
|
||||
log.Printf("reading directory: %s", err)
|
||||
}
|
||||
@@ -111,57 +95,47 @@ func newDir(path string) *dir {
|
||||
return &dir{
|
||||
loadTime: time,
|
||||
path: path,
|
||||
fi: fi,
|
||||
all: fi,
|
||||
files: files,
|
||||
allFiles: files,
|
||||
}
|
||||
}
|
||||
|
||||
func (dir *dir) renew() {
|
||||
fi, err := readdir(dir.path)
|
||||
if err != nil {
|
||||
log.Printf("reading directory: %s", err)
|
||||
}
|
||||
|
||||
dir.fi = fi
|
||||
dir.all = fi
|
||||
}
|
||||
|
||||
func (dir *dir) sort() {
|
||||
dir.sortType = gOpts.sortType
|
||||
|
||||
dir.fi = dir.all
|
||||
dir.files = dir.allFiles
|
||||
|
||||
switch gOpts.sortType.method {
|
||||
case naturalSort:
|
||||
sortFilesStable(dir.fi, func(i, j int) bool {
|
||||
return naturalLess(strings.ToLower(dir.fi[i].Name()), strings.ToLower(dir.fi[j].Name()))
|
||||
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||
return naturalLess(strings.ToLower(dir.files[i].Name()), strings.ToLower(dir.files[j].Name()))
|
||||
})
|
||||
case nameSort:
|
||||
sortFilesStable(dir.fi, func(i, j int) bool {
|
||||
return strings.ToLower(dir.fi[i].Name()) < strings.ToLower(dir.fi[j].Name())
|
||||
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||
return strings.ToLower(dir.files[i].Name()) < strings.ToLower(dir.files[j].Name())
|
||||
})
|
||||
case sizeSort:
|
||||
sortFilesStable(dir.fi, func(i, j int) bool {
|
||||
return dir.fi[i].Size() < dir.fi[j].Size()
|
||||
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||
return dir.files[i].Size() < dir.files[j].Size()
|
||||
})
|
||||
case timeSort:
|
||||
sortFilesStable(dir.fi, func(i, j int) bool {
|
||||
return dir.fi[i].ModTime().Before(dir.fi[j].ModTime())
|
||||
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||
return dir.files[i].ModTime().Before(dir.files[j].ModTime())
|
||||
})
|
||||
}
|
||||
|
||||
if gOpts.sortType.option&reverseSort != 0 {
|
||||
for i, j := 0, len(dir.fi)-1; i < j; i, j = i+1, j-1 {
|
||||
dir.fi[i], dir.fi[j] = dir.fi[j], dir.fi[i]
|
||||
for i, j := 0, len(dir.files)-1; i < j; i, j = i+1, j-1 {
|
||||
dir.files[i], dir.files[j] = dir.files[j], dir.files[i]
|
||||
}
|
||||
}
|
||||
|
||||
if gOpts.sortType.option&dirfirstSort != 0 {
|
||||
sortFilesStable(dir.fi, func(i, j int) bool {
|
||||
if dir.fi[i].IsDir() == dir.fi[j].IsDir() {
|
||||
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||
if dir.files[i].IsDir() == dir.files[j].IsDir() {
|
||||
return i < j
|
||||
}
|
||||
return dir.fi[i].IsDir()
|
||||
return dir.files[i].IsDir()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -169,39 +143,39 @@ func (dir *dir) sort() {
|
||||
// beginning of our file list and then set the beginning of displayed
|
||||
// files to the first non-hidden file in the list
|
||||
if gOpts.sortType.option&hiddenSort == 0 {
|
||||
sortFilesStable(dir.fi, func(i, j int) bool {
|
||||
if dir.fi[i].Name()[0] == '.' && dir.fi[j].Name()[0] == '.' {
|
||||
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||
if dir.files[i].Name()[0] == '.' && dir.files[j].Name()[0] == '.' {
|
||||
return i < j
|
||||
}
|
||||
return dir.fi[i].Name()[0] == '.'
|
||||
return dir.files[i].Name()[0] == '.'
|
||||
})
|
||||
for i, f := range dir.fi {
|
||||
for i, f := range dir.files {
|
||||
if f.Name()[0] != '.' {
|
||||
dir.fi = dir.fi[i:]
|
||||
dir.files = dir.files[i:]
|
||||
return
|
||||
}
|
||||
}
|
||||
dir.fi = dir.fi[len(dir.fi):]
|
||||
dir.files = dir.files[len(dir.files):]
|
||||
}
|
||||
}
|
||||
|
||||
func (dir *dir) name() string {
|
||||
if len(dir.fi) == 0 {
|
||||
if len(dir.files) == 0 {
|
||||
return ""
|
||||
}
|
||||
return dir.fi[dir.ind].Name()
|
||||
return dir.files[dir.ind].Name()
|
||||
}
|
||||
|
||||
func (dir *dir) find(name string, height int) {
|
||||
if len(dir.fi) == 0 {
|
||||
if len(dir.files) == 0 {
|
||||
dir.ind, dir.pos = 0, 0
|
||||
return
|
||||
}
|
||||
|
||||
dir.ind = min(dir.ind, len(dir.fi)-1)
|
||||
dir.ind = min(dir.ind, len(dir.files)-1)
|
||||
|
||||
if dir.fi[dir.ind].Name() != name {
|
||||
for i, f := range dir.fi {
|
||||
if dir.files[dir.ind].Name() != name {
|
||||
for i, f := range dir.files {
|
||||
if f.Name() == name {
|
||||
dir.ind = i
|
||||
break
|
||||
@@ -209,7 +183,7 @@ func (dir *dir) find(name string, height int) {
|
||||
}
|
||||
}
|
||||
|
||||
edge := min(min(height/2, gOpts.scrolloff), len(dir.fi)-dir.ind-1)
|
||||
edge := min(min(height/2, gOpts.scrolloff), len(dir.files)-dir.ind-1)
|
||||
dir.pos = min(dir.ind, height-edge-1)
|
||||
}
|
||||
|
||||
@@ -226,34 +200,46 @@ type nav struct {
|
||||
search string
|
||||
}
|
||||
|
||||
func newNav(height int) *nav {
|
||||
wd, err := os.Getwd()
|
||||
func (nav *nav) loadDir(path string) *dir {
|
||||
d, ok := nav.dirCache[path]
|
||||
if !ok {
|
||||
go func() {
|
||||
d := newDir(path)
|
||||
d.sort()
|
||||
d.ind, d.pos = 0, 0
|
||||
nav.dirChan <- d
|
||||
}()
|
||||
d := &dir{loading: true, path: path, sortType: gOpts.sortType}
|
||||
nav.dirCache[path] = d
|
||||
return d
|
||||
}
|
||||
|
||||
s, err := os.Stat(d.path)
|
||||
if err != nil {
|
||||
log.Printf("getting current directory: %s", err)
|
||||
return d
|
||||
}
|
||||
|
||||
nav := &nav{
|
||||
dirChan: make(chan *dir),
|
||||
regChan: make(chan *reg),
|
||||
dirCache: make(map[string]*dir),
|
||||
regCache: make(map[string]*reg),
|
||||
marks: make(map[string]int),
|
||||
saves: make(map[string]bool),
|
||||
markInd: 0,
|
||||
height: height,
|
||||
switch {
|
||||
case s.ModTime().After(d.loadTime):
|
||||
go func() {
|
||||
d.loadTime = time.Now()
|
||||
nd := newDir(path)
|
||||
nd.sort()
|
||||
nd.find(d.name(), nav.height)
|
||||
nav.dirChan <- nd
|
||||
}()
|
||||
case d.sortType != gOpts.sortType:
|
||||
go func() {
|
||||
d.loading = true
|
||||
name := d.name()
|
||||
d.sort()
|
||||
d.find(name, nav.height)
|
||||
d.loading = false
|
||||
nav.dirChan <- d
|
||||
}()
|
||||
}
|
||||
|
||||
nav.getDirs(wd)
|
||||
|
||||
return nav
|
||||
}
|
||||
|
||||
func (nav *nav) position() {
|
||||
path := nav.currDir().path
|
||||
for i := len(nav.dirs) - 2; i >= 0; i-- {
|
||||
nav.dirs[i].find(filepath.Base(path), nav.height)
|
||||
path = filepath.Dir(path)
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
func (nav *nav) getDirs(wd string) {
|
||||
@@ -272,12 +258,29 @@ func (nav *nav) getDirs(wd string) {
|
||||
nav.dirs = dirs
|
||||
}
|
||||
|
||||
func (nav *nav) renew() {
|
||||
nav.dirCache = make(map[string]*dir)
|
||||
for _, d := range nav.dirs {
|
||||
nav.dirCache[d.path] = d
|
||||
func newNav(height int) *nav {
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
log.Printf("getting current directory: %s", err)
|
||||
}
|
||||
|
||||
nav := &nav{
|
||||
dirChan: make(chan *dir),
|
||||
regChan: make(chan *reg),
|
||||
dirCache: make(map[string]*dir),
|
||||
regCache: make(map[string]*reg),
|
||||
saves: make(map[string]bool),
|
||||
marks: make(map[string]int),
|
||||
markInd: 0,
|
||||
height: height,
|
||||
}
|
||||
|
||||
nav.getDirs(wd)
|
||||
|
||||
return nav
|
||||
}
|
||||
|
||||
func (nav *nav) renew() {
|
||||
for _, d := range nav.dirs {
|
||||
go func(d *dir) {
|
||||
s, err := os.Stat(d.path)
|
||||
@@ -317,36 +320,16 @@ func (nav *nav) reload() {
|
||||
nav.getDirs(wd)
|
||||
if err == nil {
|
||||
last := nav.dirs[len(nav.dirs)-1]
|
||||
last.fi = append(last.fi, curr)
|
||||
last.files = append(last.files, curr)
|
||||
}
|
||||
}
|
||||
|
||||
func (nav *nav) loadDir(path string) *dir {
|
||||
d, ok := nav.dirCache[path]
|
||||
if !ok {
|
||||
go func() {
|
||||
d := newDir(path)
|
||||
d.sort()
|
||||
d.ind, d.pos = 0, 0
|
||||
nav.dirChan <- d
|
||||
}()
|
||||
d := &dir{loading: true, path: path, sortType: gOpts.sortType}
|
||||
nav.dirCache[path] = d
|
||||
return d
|
||||
func (nav *nav) position() {
|
||||
path := nav.currDir().path
|
||||
for i := len(nav.dirs) - 2; i >= 0; i-- {
|
||||
nav.dirs[i].find(filepath.Base(path), nav.height)
|
||||
path = filepath.Dir(path)
|
||||
}
|
||||
|
||||
if d.sortType != gOpts.sortType {
|
||||
go func() {
|
||||
d.loading = true
|
||||
name := d.name()
|
||||
d.sort()
|
||||
d.find(name, nav.height)
|
||||
d.loading = false
|
||||
nav.dirChan <- d
|
||||
}()
|
||||
}
|
||||
|
||||
return d
|
||||
}
|
||||
|
||||
func (nav *nav) preview() {
|
||||
@@ -382,7 +365,7 @@ func (nav *nav) preview() {
|
||||
reader = f
|
||||
}
|
||||
|
||||
reg := ®{path: curr.path}
|
||||
reg := ®{loadTime: time.Now(), path: curr.path}
|
||||
|
||||
buf := bufio.NewScanner(reader)
|
||||
|
||||
@@ -408,10 +391,21 @@ func (nav *nav) loadReg(ui *ui, path string) *reg {
|
||||
r, ok := nav.regCache[path]
|
||||
if !ok {
|
||||
go nav.preview()
|
||||
r := ®{path: path, lines: []string{"\033[1mloading...\033[0m"}}
|
||||
r := ®{loading: true, path: path}
|
||||
nav.regCache[path] = r
|
||||
return r
|
||||
}
|
||||
|
||||
s, err := os.Stat(r.path)
|
||||
if err != nil {
|
||||
return r
|
||||
}
|
||||
|
||||
if s.ModTime().After(r.loadTime) {
|
||||
r.loadTime = time.Now()
|
||||
go nav.preview()
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
@@ -441,7 +435,7 @@ func (nav *nav) up(dist int) {
|
||||
func (nav *nav) down(dist int) {
|
||||
dir := nav.currDir()
|
||||
|
||||
maxind := len(dir.fi) - 1
|
||||
maxind := len(dir.files) - 1
|
||||
|
||||
if dir.ind >= maxind {
|
||||
return
|
||||
@@ -503,10 +497,10 @@ func (nav *nav) top() {
|
||||
dir.pos = 0
|
||||
}
|
||||
|
||||
func (nav *nav) bot() {
|
||||
func (nav *nav) bottom() {
|
||||
dir := nav.currDir()
|
||||
|
||||
dir.ind = len(dir.fi) - 1
|
||||
dir.ind = len(dir.files) - 1
|
||||
dir.pos = min(dir.ind, nav.height-1)
|
||||
}
|
||||
|
||||
@@ -535,7 +529,7 @@ func (nav *nav) toggle() {
|
||||
|
||||
func (nav *nav) invert() {
|
||||
last := nav.currDir()
|
||||
for _, f := range last.fi {
|
||||
for _, f := range last.files {
|
||||
path := filepath.Join(last.path, f.Name())
|
||||
nav.toggleMark(path)
|
||||
}
|
||||
@@ -647,7 +641,7 @@ func (nav *nav) find(path string) error {
|
||||
|
||||
last := nav.dirs[len(nav.dirs)-1]
|
||||
if last.loading {
|
||||
last.fi = append(last.fi, &file{FileInfo: lstat})
|
||||
last.files = append(last.files, &file{FileInfo: lstat})
|
||||
} else {
|
||||
last.find(base, nav.height)
|
||||
}
|
||||
@@ -671,8 +665,8 @@ func match(pattern, name string) (matched bool, err error) {
|
||||
|
||||
func (nav *nav) searchNext() error {
|
||||
last := nav.currDir()
|
||||
for i := last.ind + 1; i < len(last.fi); i++ {
|
||||
matched, err := match(nav.search, last.fi[i].Name())
|
||||
for i := last.ind + 1; i < len(last.files); i++ {
|
||||
matched, err := match(nav.search, last.files[i].Name())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -683,7 +677,7 @@ func (nav *nav) searchNext() error {
|
||||
}
|
||||
if gOpts.wrapscan {
|
||||
for i := 0; i < last.ind; i++ {
|
||||
matched, err := match(nav.search, last.fi[i].Name())
|
||||
matched, err := match(nav.search, last.files[i].Name())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -699,7 +693,7 @@ func (nav *nav) searchNext() error {
|
||||
func (nav *nav) searchPrev() error {
|
||||
last := nav.currDir()
|
||||
for i := last.ind - 1; i >= 0; i-- {
|
||||
matched, err := match(nav.search, last.fi[i].Name())
|
||||
matched, err := match(nav.search, last.files[i].Name())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -709,8 +703,8 @@ func (nav *nav) searchPrev() error {
|
||||
}
|
||||
}
|
||||
if gOpts.wrapscan {
|
||||
for i := len(last.fi) - 1; i > last.ind; i-- {
|
||||
matched, err := match(nav.search, last.fi[i].Name())
|
||||
for i := len(last.files) - 1; i > last.ind; i-- {
|
||||
matched, err := match(nav.search, last.files[i].Name())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -730,10 +724,10 @@ func (nav *nav) currDir() *dir {
|
||||
func (nav *nav) currFile() (*file, error) {
|
||||
last := nav.dirs[len(nav.dirs)-1]
|
||||
|
||||
if len(last.fi) == 0 {
|
||||
if len(last.files) == 0 {
|
||||
return nil, fmt.Errorf("empty directory")
|
||||
}
|
||||
return last.fi[last.ind], nil
|
||||
return last.files[last.ind], nil
|
||||
}
|
||||
|
||||
type indexedMarks struct {
|
||||
|
||||
@@ -32,6 +32,7 @@ var gOpts struct {
|
||||
preview bool
|
||||
smartcase bool
|
||||
wrapscan bool
|
||||
period int
|
||||
scrolloff int
|
||||
tabstop int
|
||||
filesep string
|
||||
@@ -56,6 +57,7 @@ func init() {
|
||||
gOpts.preview = true
|
||||
gOpts.smartcase = true
|
||||
gOpts.wrapscan = true
|
||||
gOpts.period = 0
|
||||
gOpts.scrolloff = 0
|
||||
gOpts.tabstop = 8
|
||||
gOpts.filesep = "\n"
|
||||
@@ -82,7 +84,7 @@ func init() {
|
||||
gOpts.keys["<right>"] = &callExpr{"open", nil, 1}
|
||||
gOpts.keys["q"] = &callExpr{"quit", nil, 1}
|
||||
gOpts.keys["gg"] = &callExpr{"top", nil, 1}
|
||||
gOpts.keys["G"] = &callExpr{"bot", nil, 1}
|
||||
gOpts.keys["G"] = &callExpr{"bottom", nil, 1}
|
||||
gOpts.keys["<space>"] = &callExpr{"toggle", nil, 1}
|
||||
gOpts.keys["v"] = &callExpr{"invert", nil, 1}
|
||||
gOpts.keys["u"] = &callExpr{"unmark", nil, 1}
|
||||
@@ -101,8 +103,8 @@ func init() {
|
||||
gOpts.keys["?"] = &callExpr{"search-back", nil, 1}
|
||||
gOpts.keys["n"] = &callExpr{"search-next", nil, 1}
|
||||
gOpts.keys["N"] = &callExpr{"search-prev", nil, 1}
|
||||
gOpts.keys["<c-n>"] = &callExpr{"cmd-hist-next", nil, 1}
|
||||
gOpts.keys["<c-p>"] = &callExpr{"cmd-hist-prev", nil, 1}
|
||||
gOpts.keys["<c-n>"] = &callExpr{"cmd-history-next", nil, 1}
|
||||
gOpts.keys["<c-p>"] = &callExpr{"cmd-history-prev", nil, 1}
|
||||
|
||||
gOpts.keys["zh"] = &setExpr{"hidden!", ""}
|
||||
gOpts.keys["zr"] = &setExpr{"reverse!", ""}
|
||||
@@ -117,14 +119,13 @@ func init() {
|
||||
|
||||
gOpts.cmdkeys = make(map[string]expr)
|
||||
|
||||
// TODO: rest of the keys
|
||||
gOpts.cmdkeys["<space>"] = &callExpr{"cmd-insert", []string{" "}, 1}
|
||||
gOpts.cmdkeys["<esc>"] = &callExpr{"cmd-escape", nil, 1}
|
||||
gOpts.cmdkeys["<tab>"] = &callExpr{"cmd-comp", nil, 1}
|
||||
gOpts.cmdkeys["<tab>"] = &callExpr{"cmd-complete", nil, 1}
|
||||
gOpts.cmdkeys["<enter>"] = &callExpr{"cmd-enter", nil, 1}
|
||||
gOpts.cmdkeys["<c-j>"] = &callExpr{"cmd-enter", nil, 1}
|
||||
gOpts.cmdkeys["<c-n>"] = &callExpr{"cmd-hist-next", nil, 1}
|
||||
gOpts.cmdkeys["<c-p>"] = &callExpr{"cmd-hist-prev", nil, 1}
|
||||
gOpts.cmdkeys["<c-n>"] = &callExpr{"cmd-history-next", nil, 1}
|
||||
gOpts.cmdkeys["<c-p>"] = &callExpr{"cmd-history-prev", nil, 1}
|
||||
gOpts.cmdkeys["<delete>"] = &callExpr{"cmd-delete", nil, 1}
|
||||
gOpts.cmdkeys["<c-d>"] = &callExpr{"cmd-delete", nil, 1}
|
||||
gOpts.cmdkeys["<bs>"] = &callExpr{"cmd-delete-back", nil, 1}
|
||||
@@ -133,16 +134,23 @@ func init() {
|
||||
gOpts.cmdkeys["<c-b>"] = &callExpr{"cmd-left", nil, 1}
|
||||
gOpts.cmdkeys["<right>"] = &callExpr{"cmd-right", nil, 1}
|
||||
gOpts.cmdkeys["<c-f>"] = &callExpr{"cmd-right", nil, 1}
|
||||
gOpts.cmdkeys["<home>"] = &callExpr{"cmd-beg", nil, 1}
|
||||
gOpts.cmdkeys["<c-a>"] = &callExpr{"cmd-beg", nil, 1}
|
||||
gOpts.cmdkeys["<home>"] = &callExpr{"cmd-home", nil, 1}
|
||||
gOpts.cmdkeys["<c-a>"] = &callExpr{"cmd-home", nil, 1}
|
||||
gOpts.cmdkeys["<end>"] = &callExpr{"cmd-end", nil, 1}
|
||||
gOpts.cmdkeys["<c-e>"] = &callExpr{"cmd-end", nil, 1}
|
||||
gOpts.cmdkeys["<c-u>"] = &callExpr{"cmd-delete-beg", nil, 1}
|
||||
gOpts.cmdkeys["<c-u>"] = &callExpr{"cmd-delete-home", nil, 1}
|
||||
gOpts.cmdkeys["<c-k>"] = &callExpr{"cmd-delete-end", nil, 1}
|
||||
gOpts.cmdkeys["<c-w>"] = &callExpr{"cmd-delete-word", nil, 1}
|
||||
gOpts.cmdkeys["<c-y>"] = &callExpr{"cmd-put", nil, 1}
|
||||
gOpts.cmdkeys["<c-w>"] = &callExpr{"cmd-delete-unix-word", nil, 1}
|
||||
gOpts.cmdkeys["<c-y>"] = &callExpr{"cmd-yank", nil, 1}
|
||||
gOpts.cmdkeys["<c-t>"] = &callExpr{"cmd-transpose", nil, 1}
|
||||
gOpts.cmdkeys["<c-c>"] = &callExpr{"cmd-interrupt", nil, 1}
|
||||
gOpts.cmdkeys["<a-f>"] = &callExpr{"cmd-word", nil, 1}
|
||||
gOpts.cmdkeys["<a-b>"] = &callExpr{"cmd-word-back", nil, 1}
|
||||
gOpts.cmdkeys["<a-c>"] = &callExpr{"cmd-capitalize-word", nil, 1}
|
||||
gOpts.cmdkeys["<a-d>"] = &callExpr{"cmd-delete-word", nil, 1}
|
||||
gOpts.cmdkeys["<a-u>"] = &callExpr{"cmd-uppercase-word", nil, 1}
|
||||
gOpts.cmdkeys["<a-l>"] = &callExpr{"cmd-lowercase-word", nil, 1}
|
||||
gOpts.cmdkeys["<a-t>"] = &callExpr{"cmd-transpose-word", nil, 1}
|
||||
|
||||
gOpts.cmds = make(map[string]expr)
|
||||
|
||||
|
||||
@@ -47,15 +47,15 @@ func init() {
|
||||
}
|
||||
|
||||
func pauseCommand() *exec.Cmd {
|
||||
c := `echo
|
||||
echo -n 'Press any key to continue'
|
||||
old=$(stty -g)
|
||||
stty raw -echo
|
||||
eval "ignore=\$(dd bs=1 count=1 2> /dev/null)"
|
||||
stty $old
|
||||
echo`
|
||||
cmd := `echo
|
||||
echo -n 'Press any key to continue'
|
||||
old=$(stty -g)
|
||||
stty raw -echo
|
||||
eval "ignore=\$(dd bs=1 count=1 2> /dev/null)"
|
||||
stty $old
|
||||
echo`
|
||||
|
||||
return exec.Command(gOpts.shell, "-c", c)
|
||||
return exec.Command(gOpts.shell, "-c", cmd)
|
||||
}
|
||||
|
||||
func shellCommand(s string, args []string) *exec.Cmd {
|
||||
@@ -80,10 +80,11 @@ func putCommand(list []string, dir *dir, copy bool) *exec.Cmd {
|
||||
}
|
||||
|
||||
// XXX: POSIX standard states that -i flag shall do nothing when the
|
||||
// response is not affirmative. Since this command is run with a nil stdin,
|
||||
// it should not give an affirmative answer and in return this command
|
||||
// should not overwrite existing files. Our intention here is to use the
|
||||
// standard -i flag in place of non-standard -n flag to avoid overwrites.
|
||||
// response is not affirmative. Since this command is run with a nil
|
||||
// stdin, it should not give an affirmative answer and in return this
|
||||
// command should not overwrite existing files. Our intention here is
|
||||
// to use the standard -i flag in place of non-standard -n flag to
|
||||
// avoid overwrites.
|
||||
args = append(args, "-i")
|
||||
|
||||
args = append(args, list...)
|
||||
|
||||
+3
-3
@@ -70,10 +70,10 @@ func putCommand(list []string, dir *dir, copy bool) *exec.Cmd {
|
||||
}
|
||||
|
||||
func setDefaults() {
|
||||
gOpts.keys["e"] = &execExpr{"$", `notepad "%f%"`}
|
||||
gOpts.keys["i"] = &execExpr{"$", `more "%f%"`}
|
||||
gOpts.keys["e"] = &execExpr{"$", `notepad %f%`}
|
||||
gOpts.keys["i"] = &execExpr{"$", `more %f%`}
|
||||
gOpts.keys["w"] = &execExpr{"$", "cmd"}
|
||||
gOpts.cmds["open-file"] = &execExpr{"&", `start "" "%f%"`}
|
||||
gOpts.cmds["open-file"] = &execExpr{"&", `start %f%`}
|
||||
}
|
||||
|
||||
func moveCursor(y, x int) {
|
||||
|
||||
@@ -23,7 +23,7 @@ package main
|
||||
// ExecExpr = Prefix <value> '\n'
|
||||
// | Prefix '{{' <value> '}}' ';'
|
||||
//
|
||||
// Prefix = '$' | '!' | '&' | '/' | '?'
|
||||
// Prefix = '$' | '%' | '!' | '&'
|
||||
//
|
||||
// ListExpr = ':' Expr ListRest '\n'
|
||||
// | ':' '{{' Expr ListRest '}}' ';'
|
||||
|
||||
@@ -16,12 +16,12 @@ var (
|
||||
)
|
||||
|
||||
func serve() {
|
||||
logFile, err := os.Create(gServerLogPath)
|
||||
f, err := os.Create(gServerLogPath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer logFile.Close()
|
||||
log.SetOutput(logFile)
|
||||
defer f.Close()
|
||||
log.SetOutput(f)
|
||||
|
||||
log.Print("hi!")
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
"time"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
|
||||
@@ -20,86 +21,63 @@ import (
|
||||
|
||||
const gEscapeCode = 27
|
||||
|
||||
var gAnsiCodes = map[int]termbox.Attribute{
|
||||
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,
|
||||
}
|
||||
|
||||
var gKeyVal = map[termbox.Key][]rune{
|
||||
termbox.KeyF1: {'<', 'f', '-', '1', '>'},
|
||||
termbox.KeyF2: {'<', 'f', '-', '2', '>'},
|
||||
termbox.KeyF3: {'<', 'f', '-', '3', '>'},
|
||||
termbox.KeyF4: {'<', 'f', '-', '4', '>'},
|
||||
termbox.KeyF5: {'<', 'f', '-', '5', '>'},
|
||||
termbox.KeyF6: {'<', 'f', '-', '6', '>'},
|
||||
termbox.KeyF7: {'<', 'f', '-', '7', '>'},
|
||||
termbox.KeyF8: {'<', 'f', '-', '8', '>'},
|
||||
termbox.KeyF9: {'<', 'f', '-', '9', '>'},
|
||||
termbox.KeyF10: {'<', 'f', '-', '1', '0', '>'},
|
||||
termbox.KeyF11: {'<', 'f', '-', '1', '1', '>'},
|
||||
termbox.KeyF12: {'<', 'f', '-', '1', '2', '>'},
|
||||
termbox.KeyInsert: {'<', 'i', 'n', 's', 'e', 'r', 't', '>'},
|
||||
termbox.KeyDelete: {'<', 'd', 'e', 'l', 'e', 't', 'e', '>'},
|
||||
termbox.KeyHome: {'<', 'h', 'o', 'm', 'e', '>'},
|
||||
termbox.KeyEnd: {'<', 'e', 'n', 'd', '>'},
|
||||
termbox.KeyPgup: {'<', 'p', 'g', 'u', 'p', '>'},
|
||||
termbox.KeyPgdn: {'<', 'p', 'g', 'd', 'n', '>'},
|
||||
termbox.KeyArrowUp: {'<', 'u', 'p', '>'},
|
||||
termbox.KeyArrowDown: {'<', 'd', 'o', 'w', 'n', '>'},
|
||||
termbox.KeyArrowLeft: {'<', 'l', 'e', 'f', 't', '>'},
|
||||
termbox.KeyArrowRight: {'<', 'r', 'i', 'g', 'h', 't', '>'},
|
||||
termbox.KeyCtrlSpace: {'<', 'c', '-', 's', 'p', 'a', 'c', 'e', '>'},
|
||||
termbox.KeyCtrlA: {'<', 'c', '-', 'a', '>'},
|
||||
termbox.KeyCtrlB: {'<', 'c', '-', 'b', '>'},
|
||||
termbox.KeyCtrlC: {'<', 'c', '-', 'c', '>'},
|
||||
termbox.KeyCtrlD: {'<', 'c', '-', 'd', '>'},
|
||||
termbox.KeyCtrlE: {'<', 'c', '-', 'e', '>'},
|
||||
termbox.KeyCtrlF: {'<', 'c', '-', 'f', '>'},
|
||||
termbox.KeyCtrlG: {'<', 'c', '-', 'g', '>'},
|
||||
termbox.KeyBackspace: {'<', 'b', 's', '>'},
|
||||
termbox.KeyTab: {'<', 't', 'a', 'b', '>'},
|
||||
termbox.KeyCtrlJ: {'<', 'c', '-', 'j', '>'},
|
||||
termbox.KeyCtrlK: {'<', 'c', '-', 'k', '>'},
|
||||
termbox.KeyCtrlL: {'<', 'c', '-', 'l', '>'},
|
||||
termbox.KeyEnter: {'<', 'e', 'n', 't', 'e', 'r', '>'},
|
||||
termbox.KeyCtrlN: {'<', 'c', '-', 'n', '>'},
|
||||
termbox.KeyCtrlO: {'<', 'c', '-', 'o', '>'},
|
||||
termbox.KeyCtrlP: {'<', 'c', '-', 'p', '>'},
|
||||
termbox.KeyCtrlQ: {'<', 'c', '-', 'q', '>'},
|
||||
termbox.KeyCtrlR: {'<', 'c', '-', 'r', '>'},
|
||||
termbox.KeyCtrlS: {'<', 'c', '-', 's', '>'},
|
||||
termbox.KeyCtrlT: {'<', 'c', '-', 't', '>'},
|
||||
termbox.KeyCtrlU: {'<', 'c', '-', 'u', '>'},
|
||||
termbox.KeyCtrlV: {'<', 'c', '-', 'v', '>'},
|
||||
termbox.KeyCtrlW: {'<', 'c', '-', 'w', '>'},
|
||||
termbox.KeyCtrlX: {'<', 'c', '-', 'x', '>'},
|
||||
termbox.KeyCtrlY: {'<', 'c', '-', 'y', '>'},
|
||||
termbox.KeyCtrlZ: {'<', 'c', '-', 'z', '>'},
|
||||
termbox.KeyEsc: {'<', 'e', 's', 'c', '>'},
|
||||
termbox.KeyCtrlBackslash: {'<', 'c', '-', '\\', '>'},
|
||||
termbox.KeyCtrlRsqBracket: {'<', 'c', '-', ']', '>'},
|
||||
termbox.KeyCtrl6: {'<', 'c', '-', '6', '>'},
|
||||
termbox.KeyCtrlSlash: {'<', 'c', '-', '/', '>'},
|
||||
termbox.KeySpace: {'<', 's', 'p', 'a', 'c', 'e', '>'},
|
||||
termbox.KeyBackspace2: {'<', 'b', 's', '2', '>'},
|
||||
var gKeyVal = map[termbox.Key]string{
|
||||
termbox.KeyF1: "<f-1>",
|
||||
termbox.KeyF2: "<f-2>",
|
||||
termbox.KeyF3: "<f-3>",
|
||||
termbox.KeyF4: "<f-4>",
|
||||
termbox.KeyF5: "<f-5>",
|
||||
termbox.KeyF6: "<f-6>",
|
||||
termbox.KeyF7: "<f-7>",
|
||||
termbox.KeyF8: "<f-8>",
|
||||
termbox.KeyF9: "<f-9>",
|
||||
termbox.KeyF10: "<f-10>",
|
||||
termbox.KeyF11: "<f-11>",
|
||||
termbox.KeyF12: "<f-12>",
|
||||
termbox.KeyInsert: "<insert>",
|
||||
termbox.KeyDelete: "<delete>",
|
||||
termbox.KeyHome: "<home>",
|
||||
termbox.KeyEnd: "<end>",
|
||||
termbox.KeyPgup: "<pgup>",
|
||||
termbox.KeyPgdn: "<pgdn>",
|
||||
termbox.KeyArrowUp: "<up>",
|
||||
termbox.KeyArrowDown: "<down>",
|
||||
termbox.KeyArrowLeft: "<left>",
|
||||
termbox.KeyArrowRight: "<right>",
|
||||
termbox.KeyCtrlSpace: "<c-space>",
|
||||
termbox.KeyCtrlA: "<c-a>",
|
||||
termbox.KeyCtrlB: "<c-b>",
|
||||
termbox.KeyCtrlC: "<c-c>",
|
||||
termbox.KeyCtrlD: "<c-d>",
|
||||
termbox.KeyCtrlE: "<c-e>",
|
||||
termbox.KeyCtrlF: "<c-f>",
|
||||
termbox.KeyCtrlG: "<c-g>",
|
||||
termbox.KeyBackspace: "<bs>",
|
||||
termbox.KeyTab: "<tab>",
|
||||
termbox.KeyCtrlJ: "<c-j>",
|
||||
termbox.KeyCtrlK: "<c-k>",
|
||||
termbox.KeyCtrlL: "<c-l>",
|
||||
termbox.KeyEnter: "<enter>",
|
||||
termbox.KeyCtrlN: "<c-n>",
|
||||
termbox.KeyCtrlO: "<c-o>",
|
||||
termbox.KeyCtrlP: "<c-p>",
|
||||
termbox.KeyCtrlQ: "<c-q>",
|
||||
termbox.KeyCtrlR: "<c-r>",
|
||||
termbox.KeyCtrlS: "<c-s>",
|
||||
termbox.KeyCtrlT: "<c-t>",
|
||||
termbox.KeyCtrlU: "<c-u>",
|
||||
termbox.KeyCtrlV: "<c-v>",
|
||||
termbox.KeyCtrlW: "<c-w>",
|
||||
termbox.KeyCtrlX: "<c-x>",
|
||||
termbox.KeyCtrlY: "<c-y>",
|
||||
termbox.KeyCtrlZ: "<c-z>",
|
||||
termbox.KeyEsc: "<esc>",
|
||||
termbox.KeyCtrlBackslash: "<c-\\>",
|
||||
termbox.KeyCtrlRsqBracket: "<c-]>",
|
||||
termbox.KeyCtrl6: "<c-6>",
|
||||
termbox.KeyCtrlSlash: "<c-/>",
|
||||
termbox.KeySpace: "<space>",
|
||||
termbox.KeyBackspace2: "<bs2>",
|
||||
}
|
||||
|
||||
var gValKey map[string]termbox.Key
|
||||
@@ -107,7 +85,7 @@ var gValKey map[string]termbox.Key
|
||||
func init() {
|
||||
gValKey = make(map[string]termbox.Key)
|
||||
for k, v := range gKeyVal {
|
||||
gValKey[string(v)] = k
|
||||
gValKey[v] = k
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,6 +181,12 @@ func (win *win) printReg(reg *reg) {
|
||||
|
||||
fg, bg := termbox.ColorDefault, termbox.ColorDefault
|
||||
|
||||
if reg.loading {
|
||||
fg = termbox.AttrBold
|
||||
win.print(2, 0, fg, bg, "loading...")
|
||||
return
|
||||
}
|
||||
|
||||
for i, l := range reg.lines {
|
||||
fg, bg = win.print(2, i, fg, bg, l)
|
||||
}
|
||||
@@ -223,27 +207,27 @@ func fileInfo(f *file, d *dir) string {
|
||||
continue
|
||||
}
|
||||
|
||||
if f.count == -1 {
|
||||
if f.dirCount == -1 {
|
||||
d, err := os.Open(path)
|
||||
if err != nil {
|
||||
f.count = -2
|
||||
f.dirCount = -2
|
||||
}
|
||||
|
||||
names, err := d.Readdirnames(1000)
|
||||
d.Close()
|
||||
|
||||
if names == nil && err != io.EOF {
|
||||
f.count = -2
|
||||
f.dirCount = -2
|
||||
} else {
|
||||
f.count = len(names)
|
||||
f.dirCount = len(names)
|
||||
}
|
||||
}
|
||||
|
||||
switch {
|
||||
case f.count < 0:
|
||||
case f.dirCount < 0:
|
||||
info = fmt.Sprintf("%s ?", info)
|
||||
case f.count < 1000:
|
||||
info = fmt.Sprintf("%s %4d", info, f.count)
|
||||
case f.dirCount < 1000:
|
||||
info = fmt.Sprintf("%s %4d", info, f.dirCount)
|
||||
default:
|
||||
info = fmt.Sprintf("%s 999+", info)
|
||||
}
|
||||
@@ -270,20 +254,20 @@ func (win *win) printDir(dir *dir, marks map[string]int, saves map[string]bool,
|
||||
return
|
||||
}
|
||||
|
||||
if len(dir.fi) == 0 {
|
||||
if len(dir.files) == 0 {
|
||||
fg = termbox.AttrBold
|
||||
win.print(2, 0, fg, bg, "empty")
|
||||
return
|
||||
}
|
||||
|
||||
beg := max(dir.ind-dir.pos, 0)
|
||||
end := min(beg+win.h, len(dir.fi))
|
||||
end := min(beg+win.h, len(dir.files))
|
||||
|
||||
if beg > end {
|
||||
return
|
||||
}
|
||||
|
||||
for i, f := range dir.fi[beg:end] {
|
||||
for i, f := range dir.files[beg:end] {
|
||||
fg, bg = colors.get(f)
|
||||
|
||||
path := filepath.Join(dir.path, f.Name())
|
||||
@@ -356,7 +340,7 @@ type ui struct {
|
||||
cmdPrefix string
|
||||
cmdAccLeft []rune
|
||||
cmdAccRight []rune
|
||||
cmdBuf []rune
|
||||
cmdYankBuf []rune
|
||||
keyAcc []rune
|
||||
keyCount []rune
|
||||
colors colorMap
|
||||
@@ -364,8 +348,8 @@ type ui struct {
|
||||
|
||||
func getWidths(wtot int) []int {
|
||||
rsum := 0
|
||||
for _, rat := range gOpts.ratios {
|
||||
rsum += rat
|
||||
for _, r := range gOpts.ratios {
|
||||
rsum += r
|
||||
}
|
||||
|
||||
wlen := len(gOpts.ratios)
|
||||
@@ -409,11 +393,27 @@ func getWins() []*win {
|
||||
func newUI() *ui {
|
||||
wtot, htot := termbox.Size()
|
||||
|
||||
evChan := make(chan termbox.Event)
|
||||
|
||||
evQueue := make(chan termbox.Event)
|
||||
go func() {
|
||||
for {
|
||||
evChan <- termbox.PollEvent()
|
||||
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
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -468,8 +468,10 @@ func (ui *ui) printf(format string, a ...interface{}) {
|
||||
}
|
||||
|
||||
type reg struct {
|
||||
path string
|
||||
lines []string
|
||||
loading bool
|
||||
loadTime time.Time
|
||||
path string
|
||||
lines []string
|
||||
}
|
||||
|
||||
func (ui *ui) loadFile(nav *nav) {
|
||||
@@ -543,7 +545,7 @@ func (ui *ui) drawStatLine(nav *nav) {
|
||||
|
||||
ui.msgWin.print(0, 0, fg, bg, ui.msg)
|
||||
|
||||
tot := len(currDir.fi)
|
||||
tot := len(currDir.files)
|
||||
ind := min(currDir.ind+1, tot)
|
||||
acc := string(ui.keyCount) + string(ui.keyAcc)
|
||||
|
||||
@@ -667,11 +669,12 @@ func (ui *ui) draw(nav *nav) {
|
||||
func findBinds(keys map[string]expr, prefix string) (binds map[string]expr, ok bool) {
|
||||
binds = make(map[string]expr)
|
||||
for key, expr := range keys {
|
||||
if strings.HasPrefix(key, prefix) {
|
||||
binds[key] = expr
|
||||
if key == prefix {
|
||||
ok = true
|
||||
}
|
||||
if !strings.HasPrefix(key, prefix) {
|
||||
continue
|
||||
}
|
||||
binds[key] = expr
|
||||
if key == prefix {
|
||||
ok = true
|
||||
}
|
||||
}
|
||||
return
|
||||
@@ -705,11 +708,15 @@ func (ui *ui) pollEvent() termbox.Event {
|
||||
if len(key) == 1 {
|
||||
ev.Ch, _ = utf8.DecodeRuneInString(key)
|
||||
} else {
|
||||
switch key {
|
||||
case "<lt>":
|
||||
switch {
|
||||
case key == "<lt>":
|
||||
ev.Ch = '<'
|
||||
case "<gt>":
|
||||
case key == "<gt>":
|
||||
ev.Ch = '>'
|
||||
case reAltKey.MatchString(key):
|
||||
match := reAltKey.FindStringSubmatch(key)[1]
|
||||
ev.Ch, _ = utf8.DecodeRuneInString(match)
|
||||
ev.Mod = termbox.ModAlt
|
||||
default:
|
||||
if val, ok := gValKey[key]; ok {
|
||||
ev.Key = val
|
||||
@@ -726,17 +733,9 @@ func (ui *ui) pollEvent() termbox.Event {
|
||||
}
|
||||
}
|
||||
|
||||
func readCmdEvent(ch chan<- expr, ev termbox.Event) {
|
||||
if ev.Ch != 0 {
|
||||
ch <- &callExpr{"cmd-insert", []string{string(ev.Ch)}, 1}
|
||||
} else {
|
||||
val := gKeyVal[ev.Key]
|
||||
if expr, ok := gOpts.cmdkeys[string(val)]; ok {
|
||||
ch <- expr
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
// preceding any non-digit characters (e.g. "42y2k" as 42 times "y2k").
|
||||
func (ui *ui) readEvent(ch chan<- expr, ev termbox.Event) {
|
||||
draw := &callExpr{"draw", nil, 1}
|
||||
count := 1
|
||||
@@ -746,9 +745,11 @@ func (ui *ui) readEvent(ch chan<- expr, ev termbox.Event) {
|
||||
if ev.Ch != 0 {
|
||||
switch {
|
||||
case ev.Ch == '<':
|
||||
ui.keyAcc = append(ui.keyAcc, '<', 'l', 't', '>')
|
||||
ui.keyAcc = append(ui.keyAcc, []rune("<lt>")...)
|
||||
case ev.Ch == '>':
|
||||
ui.keyAcc = append(ui.keyAcc, '<', 'g', 't', '>')
|
||||
ui.keyAcc = append(ui.keyAcc, []rune("<gt>")...)
|
||||
case ev.Mod == termbox.ModAlt:
|
||||
ui.keyAcc = append(ui.keyAcc, '<', 'a', '-', ev.Ch, '>')
|
||||
case unicode.IsDigit(ev.Ch) && len(ui.keyAcc) == 0:
|
||||
ui.keyCount = append(ui.keyCount, ev.Ch)
|
||||
default:
|
||||
@@ -756,12 +757,12 @@ func (ui *ui) readEvent(ch chan<- expr, ev termbox.Event) {
|
||||
}
|
||||
} else {
|
||||
val := gKeyVal[ev.Key]
|
||||
if string(val) == "<esc>" {
|
||||
if val == "<esc>" {
|
||||
ch <- draw
|
||||
ui.keyAcc = nil
|
||||
ui.keyCount = nil
|
||||
}
|
||||
ui.keyAcc = append(ui.keyAcc, val...)
|
||||
ui.keyAcc = append(ui.keyAcc, []rune(val)...)
|
||||
}
|
||||
|
||||
if len(ui.keyAcc) == 0 {
|
||||
@@ -803,7 +804,6 @@ func (ui *ui) readEvent(ch chan<- expr, ev termbox.Event) {
|
||||
}
|
||||
default:
|
||||
if ok {
|
||||
// TODO: use a delay
|
||||
if len(ui.keyCount) > 0 {
|
||||
c, err := strconv.Atoi(string(ui.keyCount))
|
||||
if err != nil {
|
||||
@@ -828,14 +828,27 @@ func (ui *ui) readEvent(ch chan<- expr, ev termbox.Event) {
|
||||
}
|
||||
case termbox.EventResize:
|
||||
ch <- &callExpr{"redraw", nil, 1}
|
||||
default:
|
||||
// TODO: handle other events
|
||||
}
|
||||
}
|
||||
|
||||
// This function is used to read expressions on the client side. 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").
|
||||
func readCmdEvent(ch chan<- expr, ev termbox.Event) {
|
||||
if ev.Ch != 0 {
|
||||
if ev.Mod == termbox.ModAlt {
|
||||
val := string([]rune{'<', 'a', '-', ev.Ch, '>'})
|
||||
if expr, ok := gOpts.cmdkeys[val]; ok {
|
||||
ch <- expr
|
||||
}
|
||||
} else {
|
||||
ch <- &callExpr{"cmd-insert", []string{string(ev.Ch)}, 1}
|
||||
}
|
||||
} else {
|
||||
val := gKeyVal[ev.Key]
|
||||
if expr, ok := gOpts.cmdkeys[val]; ok {
|
||||
ch <- expr
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (ui *ui) readExpr() <-chan expr {
|
||||
ch := make(chan expr)
|
||||
|
||||
|
||||
Reference in new issue
Block a user