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 | ||
|
|
6b235beb39 | ||
|
|
d267bc70d4 | ||
|
|
3b043752a4 | ||
|
|
a0e1d4d59a | ||
|
|
09b1daaade | ||
|
|
8eb9055622 | ||
|
|
d608eb4a56 | ||
|
|
ad4fc51805 | ||
|
|
ebd599deca | ||
|
|
5a9a829252 | ||
|
|
f92e0f53a5 | ||
|
|
54dbf5cbe4 | ||
|
|
c1fc79b6ae | ||
|
|
4d3437a198 | ||
|
|
9d14888ba2 | ||
|
|
68a23a10e1 | ||
|
|
03619c3cbb | ||
|
|
0175c1bd1b | ||
|
|
01581f902f | ||
|
|
54315ffde2 | ||
|
|
bdf20aa451 | ||
|
|
847c46421c | ||
|
|
f6c99a7d46 | ||
|
|
e55c490bf5 | ||
|
|
c63c8f63ac | ||
|
|
68232c06e3 | ||
|
|
4f05975e77 | ||
|
|
32d729eac1 |
No files matched your search
@@ -26,7 +26,7 @@ See [faq](https://github.com/gokcehan/lf/wiki/FAQ) for more information.
|
|||||||
- Single binary without any runtime dependencies (except for terminfo database)
|
- Single binary without any runtime dependencies (except for terminfo database)
|
||||||
- Fast startup and low memory footprint (due to native code and static binaries)
|
- Fast startup and low memory footprint (due to native code and static binaries)
|
||||||
- Server/client architecture to share file selection between multiple instances
|
- Server/client architecture to share file selection between multiple instances
|
||||||
- Configurable with shell commands (sync or async)
|
- Configuration with shell commands
|
||||||
- Customizable keybindings (vi and readline defaults)
|
- Customizable keybindings (vi and readline defaults)
|
||||||
- Preview filtering (for source highlight, archives, pdfs/images as text etc.)
|
- Preview filtering (for source highlight, archives, pdfs/images as text etc.)
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ See [faq](https://github.com/gokcehan/lf/wiki/FAQ) for more information.
|
|||||||
## May-Futures
|
## May-Futures
|
||||||
|
|
||||||
- Bookmarks
|
- Bookmarks
|
||||||
- Colorschemes
|
- Mouse control
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
@@ -53,6 +53,8 @@ See [packages](https://github.com/gokcehan/lf/wiki/Packages) for community maint
|
|||||||
|
|
||||||
## Usage
|
## 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.
|
After the installation `lf` command should start the application in the current directory.
|
||||||
|
|
||||||
Run `lf -help` to see command line options.
|
Run `lf -help` to see command line options.
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type cmdItem struct {
|
type cmdItem struct {
|
||||||
@@ -16,9 +20,13 @@ type cmdItem struct {
|
|||||||
type app struct {
|
type app struct {
|
||||||
ui *ui
|
ui *ui
|
||||||
nav *nav
|
nav *nav
|
||||||
|
ticker *time.Ticker
|
||||||
quitChan chan bool
|
quitChan chan bool
|
||||||
cmdHist []cmdItem
|
cmd *exec.Cmd
|
||||||
cmdHistInd int
|
cmdIn io.WriteCloser
|
||||||
|
cmdOutBuf []byte
|
||||||
|
cmdHistory []cmdItem
|
||||||
|
cmdHistoryInd int
|
||||||
}
|
}
|
||||||
|
|
||||||
func newApp() *app {
|
func newApp() *app {
|
||||||
@@ -28,6 +36,7 @@ func newApp() *app {
|
|||||||
return &app{
|
return &app{
|
||||||
ui: ui,
|
ui: ui,
|
||||||
nav: nav,
|
nav: nav,
|
||||||
|
ticker: new(time.Ticker),
|
||||||
quitChan: make(chan bool, 1),
|
quitChan: make(chan bool, 1),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -43,6 +52,7 @@ func (app *app) readFile(path string) {
|
|||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
p := newParser(f)
|
p := newParser(f)
|
||||||
|
|
||||||
for p.parse() {
|
for p.parse() {
|
||||||
p.expr.eval(app, nil)
|
p.expr.eval(app, nil)
|
||||||
}
|
}
|
||||||
@@ -52,9 +62,10 @@ func (app *app) readFile(path string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is the main event loop of the application. There are two channels to
|
// This is the main event loop of the application. Expressions are read from
|
||||||
// read expressions from client and server. Reading and evaluation are done on
|
// the client and the server on separate goroutines and sent here over channels
|
||||||
// separate goroutines.
|
// for evaluation. Similarly directories and regular files are also read in
|
||||||
|
// separate goroutines and sent here for update.
|
||||||
func (app *app) loop() {
|
func (app *app) loop() {
|
||||||
clientChan := app.ui.readExpr()
|
clientChan := app.ui.readExpr()
|
||||||
serverChan := readExpr()
|
serverChan := readExpr()
|
||||||
@@ -119,13 +130,15 @@ func (app *app) loop() {
|
|||||||
|
|
||||||
app.ui.draw(app.nav)
|
app.ui.draw(app.nav)
|
||||||
case e := <-clientChan:
|
case e := <-clientChan:
|
||||||
for i := 0; i < e.count; i++ {
|
e.eval(app, nil)
|
||||||
e.expr.eval(app, nil)
|
|
||||||
}
|
|
||||||
app.ui.draw(app.nav)
|
app.ui.draw(app.nav)
|
||||||
case e := <-serverChan:
|
case e := <-serverChan:
|
||||||
e.eval(app, nil)
|
e.eval(app, nil)
|
||||||
app.ui.draw(app.nav)
|
app.ui.draw(app.nav)
|
||||||
|
case <-app.ticker.C:
|
||||||
|
app.nav.renew()
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
|
app.ui.draw(app.nav)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -166,46 +179,91 @@ func waitKey() error {
|
|||||||
return nil
|
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
|
// Prefix Wait Async Stdin Stdout Stderr UI action
|
||||||
// $ No No Yes Pause and then resume
|
// $ No No Yes Yes Yes Pause and then resume
|
||||||
// ! Yes No Yes Pause and then resume
|
// % No No Yes Yes Yes Statline for input/output
|
||||||
// & No Yes No Do nothing
|
// ! Yes No Yes Yes Yes Pause and then resume
|
||||||
//
|
// & No Yes No No No Do nothing
|
||||||
// Waiting async commands are not used for now.
|
func (app *app) runShell(s string, args []string, prefix string) {
|
||||||
func (app *app) runShell(s string, args []string, wait bool, async bool) {
|
|
||||||
app.exportVars()
|
app.exportVars()
|
||||||
|
|
||||||
cmd := shellCommand(s, args)
|
cmd := shellCommand(s, args)
|
||||||
|
|
||||||
if !async {
|
var out io.Reader
|
||||||
|
switch prefix {
|
||||||
|
case "$", "!":
|
||||||
cmd.Stdin = os.Stdin
|
cmd.Stdin = os.Stdin
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
|
|
||||||
app.ui.pause()
|
app.ui.pause()
|
||||||
defer app.ui.resume()
|
defer app.ui.resume()
|
||||||
defer app.nav.renew(app.ui.wins[0].h)
|
defer app.nav.renew()
|
||||||
|
case "%":
|
||||||
|
stdin, err := cmd.StdinPipe()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("writing stdin: %s", err)
|
||||||
|
}
|
||||||
|
app.cmdIn = stdin
|
||||||
|
stdout, err := cmd.StdoutPipe()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("reading stdout: %s", err)
|
||||||
|
}
|
||||||
|
out = stdout
|
||||||
|
cmd.Stderr = cmd.Stdout
|
||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
if async {
|
switch prefix {
|
||||||
err = cmd.Start()
|
case "$", "!":
|
||||||
} else {
|
|
||||||
err = cmd.Run()
|
err = cmd.Run()
|
||||||
|
case "%", "&":
|
||||||
|
err = cmd.Start()
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.ui.printf("running shell: %s", err)
|
app.ui.printf("running shell: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if wait {
|
switch prefix {
|
||||||
|
case "!":
|
||||||
if err := waitKey(); err != nil {
|
if err := waitKey(); err != nil {
|
||||||
app.ui.printf("waiting shell: %s", err)
|
app.ui.printf("waiting key: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
|
|
||||||
|
switch prefix {
|
||||||
|
case "%":
|
||||||
|
go func() {
|
||||||
|
app.cmd = cmd
|
||||||
|
app.cmdOutBuf = nil
|
||||||
|
app.ui.msg = ""
|
||||||
|
app.ui.cmdPrefix = ">"
|
||||||
|
|
||||||
|
reader := bufio.NewReader(out)
|
||||||
|
for {
|
||||||
|
b, err := reader.ReadByte()
|
||||||
|
if err == io.EOF {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
app.cmdOutBuf = append(app.cmdOutBuf, b)
|
||||||
|
app.ui.exprChan <- &callExpr{"echo", []string{string(app.cmdOutBuf)}, 1}
|
||||||
|
if b == '\n' || b == '\r' {
|
||||||
|
app.cmdOutBuf = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := cmd.Wait(); err != nil {
|
||||||
|
log.Printf("running shell: %s", err)
|
||||||
|
}
|
||||||
|
app.cmd = nil
|
||||||
|
app.ui.cmdPrefix = ""
|
||||||
|
app.ui.exprChan <- &callExpr{"reload", nil, 1}
|
||||||
|
}()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -13,13 +13,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func run() {
|
func run() {
|
||||||
logFile, err := os.Create(gLogPath)
|
f, err := os.Create(gLogPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
defer os.Remove(gLogPath)
|
defer os.Remove(gLogPath)
|
||||||
defer logFile.Close()
|
defer f.Close()
|
||||||
log.SetOutput(logFile)
|
log.SetOutput(f)
|
||||||
|
|
||||||
log.Print("hi!")
|
log.Print("hi!")
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ func readExpr() <-chan expr {
|
|||||||
|
|
||||||
fmt.Fprintf(c, "conn %d\n", gClientID)
|
fmt.Fprintf(c, "conn %d\n", gClientID)
|
||||||
|
|
||||||
ch <- &callExpr{"sync", nil}
|
ch <- &callExpr{"sync", nil, 1}
|
||||||
|
|
||||||
s := bufio.NewScanner(c)
|
s := bufio.NewScanner(c)
|
||||||
for s.Scan() {
|
for s.Scan() {
|
||||||
|
|||||||
@@ -0,0 +1,241 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/nsf/termbox-go"
|
||||||
|
)
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
type colorMap map[string]colorEntry
|
||||||
|
|
||||||
|
func parseColors() colorMap {
|
||||||
|
if env := os.Getenv("LS_COLORS"); env != "" {
|
||||||
|
return parseColorsGNU(env)
|
||||||
|
}
|
||||||
|
|
||||||
|
if env := os.Getenv("LSCOLORS"); env != "" {
|
||||||
|
return parseColorsBSD(env)
|
||||||
|
}
|
||||||
|
|
||||||
|
// default values from dircolors
|
||||||
|
defaultColors := []string{
|
||||||
|
// "rs=0",
|
||||||
|
"di=01;34",
|
||||||
|
"ln=01;36",
|
||||||
|
// "mh=00",
|
||||||
|
"pi=40;33",
|
||||||
|
"so=01;35",
|
||||||
|
"do=01;35",
|
||||||
|
"bd=40;33;01",
|
||||||
|
"cd=40;33;01",
|
||||||
|
"or=40;31;01",
|
||||||
|
// "mi=00",
|
||||||
|
"su=37;41",
|
||||||
|
"sg=30;43",
|
||||||
|
"ca=30;41",
|
||||||
|
"tw=30;42",
|
||||||
|
"ow=34;42",
|
||||||
|
"st=37;44",
|
||||||
|
"ex=01;32",
|
||||||
|
}
|
||||||
|
|
||||||
|
return parseColorsGNU(strings.Join(defaultColors, ":"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func applyAnsiCodes(s string, fg, bg termbox.Attribute) (termbox.Attribute, termbox.Attribute) {
|
||||||
|
toks := strings.Split(s, ";")
|
||||||
|
|
||||||
|
var nums []int
|
||||||
|
for _, tok := range toks {
|
||||||
|
if tok == "" {
|
||||||
|
nums = append(nums, 0)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
n, err := strconv.Atoi(tok)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("converting escape code: %s", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
nums = append(nums, n)
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
attr, ok := gAnsiCodes[n]
|
||||||
|
if !ok {
|
||||||
|
log.Printf("unknown ansi code: %d", n)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
switch {
|
||||||
|
case n == 0:
|
||||||
|
fg, bg = attr, attr
|
||||||
|
case n == 1 || n == 4 || n == 7:
|
||||||
|
fg |= attr
|
||||||
|
case 30 <= n && n <= 37:
|
||||||
|
fg &= gAnsiColorResetMask
|
||||||
|
fg |= attr
|
||||||
|
case 40 <= n && n <= 47:
|
||||||
|
bg = attr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return fg, bg
|
||||||
|
}
|
||||||
|
|
||||||
|
// This function parses $LS_COLORS environment variable.
|
||||||
|
func parseColorsGNU(env string) colorMap {
|
||||||
|
colors := make(colorMap)
|
||||||
|
|
||||||
|
entries := strings.Split(env, ":")
|
||||||
|
for _, entry := range entries {
|
||||||
|
if entry == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
pair := strings.Split(entry, "=")
|
||||||
|
if len(pair) != 2 {
|
||||||
|
log.Printf("invalid $LS_COLORS entry: %s", entry)
|
||||||
|
return colors
|
||||||
|
}
|
||||||
|
key, val := pair[0], pair[1]
|
||||||
|
fg, bg := applyAnsiCodes(val, termbox.ColorDefault, termbox.ColorDefault)
|
||||||
|
colors[key] = colorEntry{fg: fg, bg: bg}
|
||||||
|
}
|
||||||
|
|
||||||
|
return colors
|
||||||
|
}
|
||||||
|
|
||||||
|
// This function parses $LSCOLORS environment variable.
|
||||||
|
func parseColorsBSD(env string) colorMap {
|
||||||
|
colors := make(colorMap)
|
||||||
|
|
||||||
|
if len(env) != 22 {
|
||||||
|
log.Printf("invalid $LSCOLORS variable: %s", env)
|
||||||
|
return colors
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
if color, ok := colorCodes[r]; ok {
|
||||||
|
return color
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("invalid $LSCOLORS entry: %c", r)
|
||||||
|
return termbox.ColorDefault
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, key := range colorNames {
|
||||||
|
colors[key] = colorEntry{fg: getColor(env[i*2]), bg: getColor(env[i*2+1])}
|
||||||
|
}
|
||||||
|
|
||||||
|
return colors
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cm colorMap) get(f *file) (termbox.Attribute, termbox.Attribute) {
|
||||||
|
var key string
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case f.IsDir() && f.Mode()&os.ModeSticky != 0 && f.Mode()&0002 != 0:
|
||||||
|
key = "tw"
|
||||||
|
case f.IsDir() && f.Mode()&os.ModeSticky != 0:
|
||||||
|
key = "st"
|
||||||
|
case f.IsDir() && f.Mode()&0002 != 0:
|
||||||
|
key = "ow"
|
||||||
|
case f.IsDir():
|
||||||
|
key = "di"
|
||||||
|
case f.linkState == working:
|
||||||
|
key = "ln"
|
||||||
|
case f.linkState == broken:
|
||||||
|
key = "or"
|
||||||
|
case f.Mode()&os.ModeNamedPipe != 0:
|
||||||
|
key = "pi"
|
||||||
|
case f.Mode()&os.ModeSocket != 0:
|
||||||
|
key = "so"
|
||||||
|
case f.Mode()&os.ModeCharDevice != 0:
|
||||||
|
key = "cd"
|
||||||
|
case f.Mode()&os.ModeDevice != 0:
|
||||||
|
key = "bd"
|
||||||
|
case f.Mode()&os.ModeSetuid != 0:
|
||||||
|
key = "su"
|
||||||
|
case f.Mode()&os.ModeSetgid != 0:
|
||||||
|
key = "sg"
|
||||||
|
case f.Mode().IsRegular() && f.Mode()&0111 != 0:
|
||||||
|
key = "ex"
|
||||||
|
default:
|
||||||
|
key = "*" + filepath.Ext(f.Name())
|
||||||
|
}
|
||||||
|
|
||||||
|
if val, ok := cm[key]; ok {
|
||||||
|
return val.fg, val.bg
|
||||||
|
}
|
||||||
|
|
||||||
|
if val, ok := cm["fi"]; ok {
|
||||||
|
return val.fg, val.bg
|
||||||
|
}
|
||||||
|
|
||||||
|
return termbox.ColorDefault, termbox.ColorDefault
|
||||||
|
}
|
||||||
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+32
-16
@@ -24,7 +24,7 @@ var (
|
|||||||
"open",
|
"open",
|
||||||
"quit",
|
"quit",
|
||||||
"top",
|
"top",
|
||||||
"bot",
|
"bottom",
|
||||||
"toggle",
|
"toggle",
|
||||||
"invert",
|
"invert",
|
||||||
"unmark",
|
"unmark",
|
||||||
@@ -32,12 +32,15 @@ var (
|
|||||||
"delete",
|
"delete",
|
||||||
"put",
|
"put",
|
||||||
"clear",
|
"clear",
|
||||||
|
"draw",
|
||||||
"redraw",
|
"redraw",
|
||||||
|
"load",
|
||||||
"reload",
|
"reload",
|
||||||
"read",
|
"read",
|
||||||
"read-shell",
|
"shell",
|
||||||
"read-shell-wait",
|
"shell-pipe",
|
||||||
"read-shell-async",
|
"shell-wait",
|
||||||
|
"shell-async",
|
||||||
"search",
|
"search",
|
||||||
"search-back",
|
"search-back",
|
||||||
"search-next",
|
"search-next",
|
||||||
@@ -45,6 +48,7 @@ var (
|
|||||||
"sync",
|
"sync",
|
||||||
"echo",
|
"echo",
|
||||||
"cd",
|
"cd",
|
||||||
|
"select",
|
||||||
"push",
|
"push",
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,6 +59,9 @@ var (
|
|||||||
"dirfirst",
|
"dirfirst",
|
||||||
"nodirfirst",
|
"nodirfirst",
|
||||||
"dirfirst!",
|
"dirfirst!",
|
||||||
|
"drawbox",
|
||||||
|
"nodrawbox",
|
||||||
|
"drawbox!",
|
||||||
"globsearch",
|
"globsearch",
|
||||||
"noglobsearch",
|
"noglobsearch",
|
||||||
"globsearch!",
|
"globsearch!",
|
||||||
@@ -76,6 +83,7 @@ var (
|
|||||||
"wrapscan",
|
"wrapscan",
|
||||||
"nowrapscan",
|
"nowrapscan",
|
||||||
"wrapscan!",
|
"wrapscan!",
|
||||||
|
"period",
|
||||||
"scrolloff",
|
"scrolloff",
|
||||||
"tabstop",
|
"tabstop",
|
||||||
"filesep",
|
"filesep",
|
||||||
@@ -102,7 +110,10 @@ func matchLongest(s1, s2 string) string {
|
|||||||
|
|
||||||
func matchWord(s string, words []string) (matches []string, longest string) {
|
func matchWord(s string, words []string) (matches []string, longest string) {
|
||||||
for _, w := range words {
|
for _, w := range words {
|
||||||
if strings.HasPrefix(w, s) {
|
if !strings.HasPrefix(w, s) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
matches = append(matches, w)
|
matches = append(matches, w)
|
||||||
if longest != "" {
|
if longest != "" {
|
||||||
longest = matchLongest(longest, w)
|
longest = matchLongest(longest, w)
|
||||||
@@ -110,7 +121,6 @@ func matchWord(s string, words []string) (matches []string, longest string) {
|
|||||||
longest = w + " "
|
longest = w + " "
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if longest == "" {
|
if longest == "" {
|
||||||
longest = s
|
longest = s
|
||||||
@@ -129,13 +139,16 @@ func matchExec(s string) (matches []string, longest string) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
fi, err := ioutil.ReadDir(p)
|
files, err := ioutil.ReadDir(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("reading path: %s", err)
|
log.Printf("reading path: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, f := range fi {
|
for _, f := range files {
|
||||||
if strings.HasPrefix(f.Name(), s) {
|
if !strings.HasPrefix(f.Name(), s) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
f, err = os.Stat(filepath.Join(p, f.Name()))
|
f, err = os.Stat(filepath.Join(p, f.Name()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("getting file information: %s", err)
|
log.Printf("getting file information: %s", err)
|
||||||
@@ -149,7 +162,6 @@ func matchExec(s string) (matches []string, longest string) {
|
|||||||
words = append(words, f.Name())
|
words = append(words, f.Name())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
sort.Strings(words)
|
sort.Strings(words)
|
||||||
|
|
||||||
@@ -179,12 +191,12 @@ func matchFile(s string) (matches []string, longest string) {
|
|||||||
|
|
||||||
dir = unescape(filepath.Dir(dir))
|
dir = unescape(filepath.Dir(dir))
|
||||||
|
|
||||||
fi, err := ioutil.ReadDir(dir)
|
files, err := ioutil.ReadDir(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("reading directory: %s", err)
|
log.Printf("reading directory: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, f := range fi {
|
for _, f := range files {
|
||||||
f, err := os.Stat(filepath.Join(dir, f.Name()))
|
f, err := os.Stat(filepath.Join(dir, f.Name()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("getting file information: %s", err)
|
log.Printf("getting file information: %s", err)
|
||||||
@@ -192,17 +204,22 @@ func matchFile(s string) (matches []string, longest string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_, last := filepath.Split(s)
|
_, last := filepath.Split(s)
|
||||||
if strings.HasPrefix(escape(f.Name()), last) {
|
if !strings.HasPrefix(escape(f.Name()), last) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
name := f.Name()
|
name := f.Name()
|
||||||
if isRoot(s) || filepath.Base(s) != s {
|
if isRoot(s) || filepath.Base(s) != s {
|
||||||
name = filepath.Join(filepath.Dir(s), f.Name())
|
name = filepath.Join(filepath.Dir(s), f.Name())
|
||||||
}
|
}
|
||||||
name = escape(name)
|
name = escape(name)
|
||||||
|
|
||||||
item := f.Name()
|
item := f.Name()
|
||||||
if f.Mode().IsDir() {
|
if f.Mode().IsDir() {
|
||||||
item += string(filepath.Separator)
|
item += string(filepath.Separator)
|
||||||
}
|
}
|
||||||
matches = append(matches, item)
|
matches = append(matches, item)
|
||||||
|
|
||||||
if longest != "" {
|
if longest != "" {
|
||||||
longest = matchLongest(longest, name)
|
longest = matchLongest(longest, name)
|
||||||
} else if s != "" {
|
} else if s != "" {
|
||||||
@@ -213,7 +230,6 @@ func matchFile(s string) (matches []string, longest string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if longest == "" {
|
if longest == "" {
|
||||||
longest = s
|
longest = s
|
||||||
@@ -222,7 +238,7 @@ func matchFile(s string) (matches []string, longest string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func compCmd(acc []rune) (matches []string, longestAcc []rune) {
|
func completeCmd(acc []rune) (matches []string, longestAcc []rune) {
|
||||||
s := string(acc)
|
s := string(acc)
|
||||||
f := tokenize(s)
|
f := tokenize(s)
|
||||||
|
|
||||||
@@ -261,7 +277,7 @@ func compCmd(acc []rune) (matches []string, longestAcc []rune) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func compShell(acc []rune) (matches []string, longestAcc []rune) {
|
func completeShell(acc []rune) (matches []string, longestAcc []rune) {
|
||||||
s := string(acc)
|
s := string(acc)
|
||||||
f := tokenize(s)
|
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>')
|
open (default 'l' and '<right>')
|
||||||
quit (default 'q')
|
quit (default 'q')
|
||||||
top (default 'gg')
|
top (default 'gg')
|
||||||
bot (default 'G')
|
bottom (default 'G')
|
||||||
toggle (default '<space>')
|
toggle (default '<space>')
|
||||||
invert (default 'v')
|
invert (default 'v')
|
||||||
unmark (default 'u')
|
unmark (default 'u')
|
||||||
@@ -33,9 +33,10 @@ The following commands are provided by lf with default keybindings:
|
|||||||
redraw (default '<c-l>')
|
redraw (default '<c-l>')
|
||||||
reload (default '<c-r>')
|
reload (default '<c-r>')
|
||||||
read (default ':')
|
read (default ':')
|
||||||
read-shell (default '$')
|
shell (default '$')
|
||||||
read-shell-wait (default '!')
|
shell-pipe (default '%')
|
||||||
read-shell-async (default '&')
|
shell-wait (default '!')
|
||||||
|
shell-async (default '&')
|
||||||
search (default '/')
|
search (default '/')
|
||||||
search-back (default '?')
|
search-back (default '?')
|
||||||
search-next (default 'n')
|
search-next (default 'n')
|
||||||
@@ -43,35 +44,47 @@ The following commands are provided by lf with default keybindings:
|
|||||||
|
|
||||||
The following commands are provided by lf without default keybindings:
|
The following commands are provided by lf without default keybindings:
|
||||||
|
|
||||||
|
draw draw the ui
|
||||||
|
load load modified files and directories
|
||||||
sync synchronizes yanked/deleted files with server
|
sync synchronizes yanked/deleted files with server
|
||||||
echo prints its arguments to the message line
|
echo prints its arguments to the message line
|
||||||
cd changes working directory to its argument
|
cd changes working directory to its argument
|
||||||
|
select changes current file selection to its argument
|
||||||
push simulate key pushes given in its argument
|
push simulate key pushes given in its argument
|
||||||
|
|
||||||
The following command line commands are provided by lf with default
|
The following command line commands are provided by lf with default
|
||||||
keybindings:
|
keybindings:
|
||||||
|
|
||||||
cmd-escape (default '<esc>')
|
cmd-escape (default '<esc>')
|
||||||
cmd-comp (default '<tab>')
|
cmd-complete (default '<tab>')
|
||||||
cmd-enter (default '<c-j>' and '<enter>')
|
cmd-enter (default '<c-j>' and '<enter>')
|
||||||
cmd-hist-next (default '<c-n>')
|
cmd-history-next (default '<c-n>')
|
||||||
cmd-hist-prev (default '<c-p>')
|
cmd-history-prev (default '<c-p>')
|
||||||
cmd-delete (default '<c-d>' and '<delete>')
|
cmd-delete (default '<c-d>' and '<delete>')
|
||||||
cmd-delete-back (default '<bs>' and '<bs2>')
|
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-beg (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-beg (default '<c-u>')
|
cmd-delete-home (default '<c-u>')
|
||||||
cmd-delete-end (default '<c-k>')
|
cmd-delete-end (default '<c-k>')
|
||||||
cmd-delete-word (default '<c-w>')
|
cmd-delete-unix-word (default '<c-w>')
|
||||||
cmd-put (default '<c-y>')
|
cmd-yank (default '<c-y>')
|
||||||
cmd-transpose (default '<c-t>')
|
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:
|
The following options can be used to customize the behavior of lf:
|
||||||
|
|
||||||
dircounts boolean (default off)
|
dircounts boolean (default off)
|
||||||
dirfirst boolean (default on)
|
dirfirst boolean (default on)
|
||||||
|
drawbox boolean (default off)
|
||||||
globsearch boolean (default off)
|
globsearch boolean (default off)
|
||||||
hidden boolean (default off)
|
hidden boolean (default off)
|
||||||
ignorecase boolean (default on)
|
ignorecase boolean (default on)
|
||||||
@@ -79,6 +92,7 @@ The following options can be used to customize the behavior of lf:
|
|||||||
reverse boolean (default off)
|
reverse boolean (default off)
|
||||||
smartcase boolean (default on)
|
smartcase boolean (default on)
|
||||||
wrapscan boolean (default on)
|
wrapscan boolean (default on)
|
||||||
|
period integer (default 0)
|
||||||
scrolloff integer (default 0)
|
scrolloff integer (default 0)
|
||||||
tabstop integer (default 8)
|
tabstop integer (default 8)
|
||||||
filesep string (default "\n")
|
filesep string (default "\n")
|
||||||
@@ -119,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:
|
The following keybindings to applications are provided by default on windows:
|
||||||
|
|
||||||
map e $notepad "%f%"
|
map e $notepad %f%
|
||||||
map i $more "%f%"
|
map i $more %f%
|
||||||
map w $cmd
|
map w $cmd
|
||||||
|
|
||||||
Configuration
|
Configuration
|
||||||
@@ -142,16 +156,18 @@ Prefixes
|
|||||||
The following command prefixes are used by lf:
|
The following command prefixes are used by lf:
|
||||||
|
|
||||||
: read (default) builtin/custom command
|
: read (default) builtin/custom command
|
||||||
$ read-shell shell command
|
$ shell shell command
|
||||||
! read-shell-wait shell command waiting for key press
|
% shell-pipe shell command running with the ui
|
||||||
& read-shell-async asynchronous shell command
|
! shell-wait shell command waiting for key press
|
||||||
|
& shell-async shell command running asynchronously
|
||||||
/ search search file in current directory
|
/ search search file in current directory
|
||||||
? search-back search file in the reverse order
|
? search-back search file in the reverse order
|
||||||
|
|
||||||
The same evaluator is used for the command line and the configuration file. The
|
The same evaluator is used for the command line and the configuration file for
|
||||||
difference is that prefixes are not necessary in the command line. Instead
|
read and shell commands. The difference is that prefixes are not necessary in
|
||||||
different modes are provided to read corresponding commands. Note that by
|
the command line. Instead, different modes are provided to read corresponding
|
||||||
default these modes are mapped to the prefix keys above.
|
commands. These modes are mapped to the prefix keys above by default. Searching
|
||||||
|
commands are only used from the command line.
|
||||||
|
|
||||||
Syntax
|
Syntax
|
||||||
|
|
||||||
@@ -178,7 +194,7 @@ command, or shell command:
|
|||||||
map gh cd ~ # builtin command
|
map gh cd ~ # builtin command
|
||||||
map D trash # custom command
|
map D trash # custom command
|
||||||
map i $less $f # shell 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
|
'cmap' is used to bind a key to a command line command which can only be one of
|
||||||
the builtin commands:
|
the builtin commands:
|
||||||
@@ -192,7 +208,7 @@ You can delete an existing binding by leaving the expression empty:
|
|||||||
|
|
||||||
'cmd' is used to define a custom command
|
'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:
|
You can delete an existing command by leaving the expression empty:
|
||||||
|
|
||||||
@@ -215,7 +231,54 @@ prefix.
|
|||||||
set info time
|
set info time
|
||||||
}}
|
}}
|
||||||
|
|
||||||
Mappings
|
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
|
The usual way to map a key sequence is to assign it to a named or unnamed
|
||||||
command. While this provides a clean way to remap builtin keys as well as other
|
command. While this provides a clean way to remap builtin keys as well as other
|
||||||
@@ -240,12 +303,11 @@ commands it is possible to accidentally create recursive bindings:
|
|||||||
|
|
||||||
These types of bindings create a deadlock when executed.
|
These types of bindings create a deadlock when executed.
|
||||||
|
|
||||||
Commands
|
Shell Commands
|
||||||
|
|
||||||
For demonstration let us write a shell command to move selected file(s) to
|
Regular shell commands are the most basic command type that is useful for many
|
||||||
trash.
|
purposes. For example, we can write a shell command to move selected file(s) to
|
||||||
|
trash. A first attempt to write such a command may look like this:
|
||||||
A first attempt to write such a command may look like this:
|
|
||||||
|
|
||||||
cmd trash ${{
|
cmd trash ${{
|
||||||
mkdir -p ~/.trash
|
mkdir -p ~/.trash
|
||||||
@@ -285,6 +347,47 @@ could use the 'ifs' option to set it for all shell commands (i.e. 'set ifs
|
|||||||
behave unexpectedly for new users. However, use of this option is highly
|
behave unexpectedly for new users. However, use of this option is highly
|
||||||
recommended and it is assumed in the rest of the documentation.
|
recommended and it is assumed in the rest of the documentation.
|
||||||
|
|
||||||
|
Piping Shell Commands
|
||||||
|
|
||||||
|
Regular shell commands have some limitations in some cases. When an output or
|
||||||
|
error message is given and the command exits afterwards, the ui is immediately
|
||||||
|
resumed and there is no way to see the message without dropping to shell again.
|
||||||
|
Also, even when there is no output or error, the ui still needs to be paused
|
||||||
|
while the command is running. This can cause flickering on the screen for short
|
||||||
|
commands and similar distractions for longer commands.
|
||||||
|
|
||||||
|
Instead of pausing the ui, piping shell commands connects stdin, stdout, and
|
||||||
|
stderr of the command to the statline in the bottom of the ui. This can be
|
||||||
|
useful for programs following the unix philosophy to give no output in the
|
||||||
|
success case, and brief error messages or prompts in other cases.
|
||||||
|
|
||||||
|
For example, following rename command prompts for overwrite in the statline if
|
||||||
|
there is an existing file with the given name:
|
||||||
|
|
||||||
|
cmd rename %mv -i $f $1
|
||||||
|
|
||||||
|
You can also output error messages in the command and it will show up in the
|
||||||
|
statline. For example, an alternative rename command may look like this:
|
||||||
|
|
||||||
|
cmd rename %[ -e $1 ] && printf "file exists" || mv $f $1
|
||||||
|
|
||||||
|
One thing to be careful is that although input is still line buffered, output
|
||||||
|
and error are byte buffered and verbose commands will be very slow to display.
|
||||||
|
|
||||||
|
Waiting Shell Commands
|
||||||
|
|
||||||
|
Waiting shell commands are similar to regular shell commands except that they
|
||||||
|
wait for a key press when the command is finished. These can be useful to see
|
||||||
|
the output of a program before the ui is resumed. Waiting shell commands are
|
||||||
|
more appropriate than piping shell commands when the command is verbose and the
|
||||||
|
output is best displayed as multiline.
|
||||||
|
|
||||||
|
Asynchronous Shell Commands
|
||||||
|
|
||||||
|
Asynchronous shell commands are used to start a command in the background and
|
||||||
|
then resume operation without waiting for the command to finish. Stdin, stdout,
|
||||||
|
and stderr of the command is neither connected to the terminal nor to the ui.
|
||||||
|
|
||||||
Remote Commands
|
Remote Commands
|
||||||
|
|
||||||
One of the more advanced features in lf is remote commands. All clients connect
|
One of the more advanced features in lf is remote commands. All clients connect
|
||||||
@@ -321,15 +424,17 @@ a shell command:
|
|||||||
lf -remote "send $id echo hello world"
|
lf -remote "send $id echo hello world"
|
||||||
|
|
||||||
Since lf does not have control flow syntax, remote commands are used for such
|
Since lf does not have control flow syntax, remote commands are used for such
|
||||||
needs. A common use is to display an error message back in the client. You can
|
needs. For example, you can configure the number of columns in the ui with
|
||||||
implement a safe rename command which does not overwrite an existing file or
|
respect to the terminal width as follows:
|
||||||
directory as such:
|
|
||||||
|
|
||||||
cmd rename ${{
|
cmd recol %{{
|
||||||
if [ -e $1 ]; then
|
w=$(tput cols)
|
||||||
lf -remote "send $id echo file exists"
|
if [ $w -le 80 ]; then
|
||||||
|
lf -remote "send $id set ratios 1:2"
|
||||||
|
elif [ $w -le 160 ]; then
|
||||||
|
lf -remote "send $id set ratios 1:2:3"
|
||||||
else
|
else
|
||||||
mv $f $1
|
lf -remote "send $id set ratios 1:2:3:5"
|
||||||
fi
|
fi
|
||||||
}}
|
}}
|
||||||
|
|
||||||
@@ -378,9 +483,9 @@ implementation. The default behavior is similar to the following command:
|
|||||||
elif [ $mode = 'move' ]; then
|
elif [ $mode = 'move' ]; then
|
||||||
mv -n $list .
|
mv -n $list .
|
||||||
fi
|
fi
|
||||||
lf -remote "send $id reload"
|
|
||||||
lf -remote "$(printf 'save\nmove\n\n')"
|
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'
|
Some useful things are to use the backup option ('--backup') with 'cp' and 'mv'
|
||||||
@@ -417,7 +522,7 @@ You may want to use either file extensions or mime types from 'file' command:
|
|||||||
|
|
||||||
Following commands are provided by default:
|
Following commands are provided by default:
|
||||||
|
|
||||||
cmd open-file &start "" "%f%" # windows
|
cmd open-file &start %f% # windows
|
||||||
cmd open-file &open "$f" # mac
|
cmd open-file &open "$f" # mac
|
||||||
cmd open-file &xdg-open "$f" # others
|
cmd open-file &xdg-open "$f" # others
|
||||||
|
|
||||||
@@ -468,5 +573,35 @@ relevant for big files. lf automatically closes the previewer script output
|
|||||||
pipe with a SIGPIPE when enough lines are read. When everything else fails, you
|
pipe with a SIGPIPE when enough lines are read. When everything else fails, you
|
||||||
can make use of the height argument to only feed the first portion of the file
|
can make use of the height argument to only feed the first portion of the file
|
||||||
to a program for preview.
|
to a program for preview.
|
||||||
|
|
||||||
|
Colorschemes
|
||||||
|
|
||||||
|
lf tries to automatically adapt its colors to the environment. On startup,
|
||||||
|
first '$LS_COLORS' environment variable is checked. This variable is used by
|
||||||
|
GNU ls to configure its colors based on file types and extensions. The value of
|
||||||
|
this variable is often set by GNU dircolors in a shell configuration file.
|
||||||
|
dircolors program itself can be configured with a configuration file. dircolors
|
||||||
|
supports 256 colors along with common attributes such as bold and underline.
|
||||||
|
|
||||||
|
If '$LS_COLORS' variable is not set, '$LSCOLORS' variable is checked instead.
|
||||||
|
This variable is used by ls programs on unix systems such as Mac and BSDs. This
|
||||||
|
variable has a simple syntax and supports 8 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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
*/
|
*/
|
||||||
package main
|
package main
|
||||||
+186
-38
@@ -26,7 +26,7 @@ The following commands are provided by lf with default keybindings:
|
|||||||
open (default 'l' and '<right>')
|
open (default 'l' and '<right>')
|
||||||
quit (default 'q')
|
quit (default 'q')
|
||||||
top (default 'gg')
|
top (default 'gg')
|
||||||
bot (default 'G')
|
bottom (default 'G')
|
||||||
toggle (default '<space>')
|
toggle (default '<space>')
|
||||||
invert (default 'v')
|
invert (default 'v')
|
||||||
unmark (default 'u')
|
unmark (default 'u')
|
||||||
@@ -37,9 +37,10 @@ The following commands are provided by lf with default keybindings:
|
|||||||
redraw (default '<c-l>')
|
redraw (default '<c-l>')
|
||||||
reload (default '<c-r>')
|
reload (default '<c-r>')
|
||||||
read (default ':')
|
read (default ':')
|
||||||
read-shell (default '$')
|
shell (default '$')
|
||||||
read-shell-wait (default '!')
|
shell-pipe (default '%')
|
||||||
read-shell-async (default '&')
|
shell-wait (default '!')
|
||||||
|
shell-async (default '&')
|
||||||
search (default '/')
|
search (default '/')
|
||||||
search-back (default '?')
|
search-back (default '?')
|
||||||
search-next (default 'n')
|
search-next (default 'n')
|
||||||
@@ -47,35 +48,47 @@ The following commands are provided by lf with default keybindings:
|
|||||||
|
|
||||||
The following commands are provided by lf without default keybindings:
|
The following commands are provided by lf without default keybindings:
|
||||||
|
|
||||||
|
draw draw the ui
|
||||||
|
load load modified files and directories
|
||||||
sync synchronizes yanked/deleted files with server
|
sync synchronizes yanked/deleted files with server
|
||||||
echo prints its arguments to the message line
|
echo prints its arguments to the message line
|
||||||
cd changes working directory to its argument
|
cd changes working directory to its argument
|
||||||
|
select changes current file selection to its argument
|
||||||
push simulate key pushes given in its argument
|
push simulate key pushes given in its argument
|
||||||
|
|
||||||
The following command line commands are provided by lf with default
|
The following command line commands are provided by lf with default
|
||||||
keybindings:
|
keybindings:
|
||||||
|
|
||||||
cmd-escape (default '<esc>')
|
cmd-escape (default '<esc>')
|
||||||
cmd-comp (default '<tab>')
|
cmd-complete (default '<tab>')
|
||||||
cmd-enter (default '<c-j>' and '<enter>')
|
cmd-enter (default '<c-j>' and '<enter>')
|
||||||
cmd-hist-next (default '<c-n>')
|
cmd-history-next (default '<c-n>')
|
||||||
cmd-hist-prev (default '<c-p>')
|
cmd-history-prev (default '<c-p>')
|
||||||
cmd-delete (default '<c-d>' and '<delete>')
|
cmd-delete (default '<c-d>' and '<delete>')
|
||||||
cmd-delete-back (default '<bs>' and '<bs2>')
|
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-beg (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-beg (default '<c-u>')
|
cmd-delete-home (default '<c-u>')
|
||||||
cmd-delete-end (default '<c-k>')
|
cmd-delete-end (default '<c-k>')
|
||||||
cmd-delete-word (default '<c-w>')
|
cmd-delete-unix-word (default '<c-w>')
|
||||||
cmd-put (default '<c-y>')
|
cmd-yank (default '<c-y>')
|
||||||
cmd-transpose (default '<c-t>')
|
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:
|
The following options can be used to customize the behavior of lf:
|
||||||
|
|
||||||
dircounts boolean (default off)
|
dircounts boolean (default off)
|
||||||
dirfirst boolean (default on)
|
dirfirst boolean (default on)
|
||||||
|
drawbox boolean (default off)
|
||||||
globsearch boolean (default off)
|
globsearch boolean (default off)
|
||||||
hidden boolean (default off)
|
hidden boolean (default off)
|
||||||
ignorecase boolean (default on)
|
ignorecase boolean (default on)
|
||||||
@@ -83,6 +96,7 @@ The following options can be used to customize the behavior of lf:
|
|||||||
reverse boolean (default off)
|
reverse boolean (default off)
|
||||||
smartcase boolean (default on)
|
smartcase boolean (default on)
|
||||||
wrapscan boolean (default on)
|
wrapscan boolean (default on)
|
||||||
|
period integer (default 0)
|
||||||
scrolloff integer (default 0)
|
scrolloff integer (default 0)
|
||||||
tabstop integer (default 8)
|
tabstop integer (default 8)
|
||||||
filesep string (default "\n")
|
filesep string (default "\n")
|
||||||
@@ -124,8 +138,8 @@ The following keybindings to applications are provided by default on unix:
|
|||||||
The following keybindings to applications are provided by default on
|
The following keybindings to applications are provided by default on
|
||||||
windows:
|
windows:
|
||||||
|
|
||||||
map e $notepad "%f%"
|
map e $notepad %f%
|
||||||
map i $more "%f%"
|
map i $more %f%
|
||||||
map w $cmd
|
map w $cmd
|
||||||
|
|
||||||
|
|
||||||
@@ -149,16 +163,18 @@ Prefixes
|
|||||||
The following command prefixes are used by lf:
|
The following command prefixes are used by lf:
|
||||||
|
|
||||||
: read (default) builtin/custom command
|
: read (default) builtin/custom command
|
||||||
$ read-shell shell command
|
$ shell shell command
|
||||||
! read-shell-wait shell command waiting for key press
|
% shell-pipe shell command running with the ui
|
||||||
& read-shell-async asynchronous shell command
|
! shell-wait shell command waiting for key press
|
||||||
|
& shell-async shell command running asynchronously
|
||||||
/ search search file in current directory
|
/ search search file in current directory
|
||||||
? search-back search file in the reverse order
|
? search-back search file in the reverse order
|
||||||
|
|
||||||
The same evaluator is used for the command line and the configuration file.
|
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.
|
for read and shell commands. The difference is that prefixes are not
|
||||||
Instead different modes are provided to read corresponding commands. Note
|
necessary in the command line. Instead, different modes are provided to read
|
||||||
that by default these modes are mapped to the prefix keys above.
|
corresponding commands. These modes are mapped to the prefix keys above by
|
||||||
|
default. Searching commands are only used from the command line.
|
||||||
|
|
||||||
|
|
||||||
Syntax
|
Syntax
|
||||||
@@ -186,7 +202,7 @@ custom command, or shell command:
|
|||||||
map gh cd ~ # builtin command
|
map gh cd ~ # builtin command
|
||||||
map D trash # custom command
|
map D trash # custom command
|
||||||
map i $less $f # shell 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
|
'cmap' is used to bind a key to a command line command which can only be one
|
||||||
of the builtin commands:
|
of the builtin commands:
|
||||||
@@ -200,7 +216,7 @@ You can delete an existing binding by leaving the expression empty:
|
|||||||
|
|
||||||
'cmd' is used to define a custom command
|
'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:
|
You can delete an existing command by leaving the expression empty:
|
||||||
|
|
||||||
@@ -224,7 +240,56 @@ proper prefix.
|
|||||||
}}
|
}}
|
||||||
|
|
||||||
|
|
||||||
Mappings
|
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
|
The usual way to map a key sequence is to assign it to a named or unnamed
|
||||||
command. While this provides a clean way to remap builtin keys as well as
|
command. While this provides a clean way to remap builtin keys as well as
|
||||||
@@ -251,12 +316,12 @@ of commands it is possible to accidentally create recursive bindings:
|
|||||||
These types of bindings create a deadlock when executed.
|
These types of bindings create a deadlock when executed.
|
||||||
|
|
||||||
|
|
||||||
Commands
|
Shell Commands
|
||||||
|
|
||||||
For demonstration let us write a shell command to move selected file(s) to
|
Regular shell commands are the most basic command type that is useful for
|
||||||
trash.
|
many purposes. For example, we can write a shell command to move selected
|
||||||
|
file(s) to trash. A first attempt to write such a command may look like
|
||||||
A first attempt to write such a command may look like this:
|
this:
|
||||||
|
|
||||||
cmd trash ${{
|
cmd trash ${{
|
||||||
mkdir -p ~/.trash
|
mkdir -p ~/.trash
|
||||||
@@ -298,6 +363,53 @@ behave unexpectedly for new users. However, use of this option is highly
|
|||||||
recommended and it is assumed in the rest of the documentation.
|
recommended and it is assumed in the rest of the documentation.
|
||||||
|
|
||||||
|
|
||||||
|
Piping Shell Commands
|
||||||
|
|
||||||
|
Regular shell commands have some limitations in some cases. When an output
|
||||||
|
or error message is given and the command exits afterwards, the ui is
|
||||||
|
immediately resumed and there is no way to see the message without dropping
|
||||||
|
to shell again. Also, even when there is no output or error, the ui still
|
||||||
|
needs to be paused while the command is running. This can cause flickering
|
||||||
|
on the screen for short commands and similar distractions for longer
|
||||||
|
commands.
|
||||||
|
|
||||||
|
Instead of pausing the ui, piping shell commands connects stdin, stdout, and
|
||||||
|
stderr of the command to the statline in the bottom of the ui. This can be
|
||||||
|
useful for programs following the unix philosophy to give no output in the
|
||||||
|
success case, and brief error messages or prompts in other cases.
|
||||||
|
|
||||||
|
For example, following rename command prompts for overwrite in the statline
|
||||||
|
if there is an existing file with the given name:
|
||||||
|
|
||||||
|
cmd rename %mv -i $f $1
|
||||||
|
|
||||||
|
You can also output error messages in the command and it will show up in the
|
||||||
|
statline. For example, an alternative rename command may look like this:
|
||||||
|
|
||||||
|
cmd rename %[ -e $1 ] && printf "file exists" || mv $f $1
|
||||||
|
|
||||||
|
One thing to be careful is that although input is still line buffered,
|
||||||
|
output and error are byte buffered and verbose commands will be very slow to
|
||||||
|
display.
|
||||||
|
|
||||||
|
|
||||||
|
Waiting Shell Commands
|
||||||
|
|
||||||
|
Waiting shell commands are similar to regular shell commands except that
|
||||||
|
they wait for a key press when the command is finished. These can be useful
|
||||||
|
to see the output of a program before the ui is resumed. Waiting shell
|
||||||
|
commands are more appropriate than piping shell commands when the command is
|
||||||
|
verbose and the output is best displayed as multiline.
|
||||||
|
|
||||||
|
|
||||||
|
Asynchronous Shell Commands
|
||||||
|
|
||||||
|
Asynchronous shell commands are used to start a command in the background
|
||||||
|
and then resume operation without waiting for the command to finish. Stdin,
|
||||||
|
stdout, and stderr of the command is neither connected to the terminal nor
|
||||||
|
to the ui.
|
||||||
|
|
||||||
|
|
||||||
Remote Commands
|
Remote Commands
|
||||||
|
|
||||||
One of the more advanced features in lf is remote commands. All clients
|
One of the more advanced features in lf is remote commands. All clients
|
||||||
@@ -335,15 +447,17 @@ calling the following in a shell command:
|
|||||||
lf -remote "send $id echo hello world"
|
lf -remote "send $id echo hello world"
|
||||||
|
|
||||||
Since lf does not have control flow syntax, remote commands are used for
|
Since lf does not have control flow syntax, remote commands are used for
|
||||||
such needs. A common use is to display an error message back in the client.
|
such needs. For example, you can configure the number of columns in the ui
|
||||||
You can implement a safe rename command which does not overwrite an existing
|
with respect to the terminal width as follows:
|
||||||
file or directory as such:
|
|
||||||
|
|
||||||
cmd rename ${{
|
cmd recol %{{
|
||||||
if [ -e $1 ]; then
|
w=$(tput cols)
|
||||||
lf -remote "send $id echo file exists"
|
if [ $w -le 80 ]; then
|
||||||
|
lf -remote "send $id set ratios 1:2"
|
||||||
|
elif [ $w -le 160 ]; then
|
||||||
|
lf -remote "send $id set ratios 1:2:3"
|
||||||
else
|
else
|
||||||
mv $f $1
|
lf -remote "send $id set ratios 1:2:3:5"
|
||||||
fi
|
fi
|
||||||
}}
|
}}
|
||||||
|
|
||||||
@@ -393,9 +507,9 @@ implementation. The default behavior is similar to the following command:
|
|||||||
elif [ $mode = 'move' ]; then
|
elif [ $mode = 'move' ]; then
|
||||||
mv -n $list .
|
mv -n $list .
|
||||||
fi
|
fi
|
||||||
lf -remote "send $id reload"
|
|
||||||
lf -remote "$(printf 'save\nmove\n\n')"
|
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
|
Some useful things are to use the backup option ('--backup') with 'cp' and
|
||||||
@@ -436,7 +550,7 @@ command:
|
|||||||
|
|
||||||
Following commands are provided by default:
|
Following commands are provided by default:
|
||||||
|
|
||||||
cmd open-file &start "" "%f%" # windows
|
cmd open-file &start %f% # windows
|
||||||
cmd open-file &open "$f" # mac
|
cmd open-file &open "$f" # mac
|
||||||
cmd open-file &xdg-open "$f" # others
|
cmd open-file &xdg-open "$f" # others
|
||||||
|
|
||||||
@@ -489,4 +603,38 @@ especially relevant for big files. lf automatically closes the previewer
|
|||||||
script output pipe with a SIGPIPE when enough lines are read. When
|
script output pipe with a SIGPIPE when enough lines are read. When
|
||||||
everything else fails, you can make use of the height argument to only feed
|
everything else fails, you can make use of the height argument to only feed
|
||||||
the first portion of the file to a program for preview.
|
the first portion of the file to a program for preview.
|
||||||
|
|
||||||
|
|
||||||
|
Colorschemes
|
||||||
|
|
||||||
|
lf tries to automatically adapt its colors to the environment. On startup,
|
||||||
|
first '$LS_COLORS' environment variable is checked. This variable is used by
|
||||||
|
GNU ls to configure its colors based on file types and extensions. The value
|
||||||
|
of this variable is often set by GNU dircolors in a shell configuration
|
||||||
|
file. dircolors program itself can be configured with a configuration file.
|
||||||
|
dircolors supports 256 colors along with common attributes such as bold and
|
||||||
|
underline.
|
||||||
|
|
||||||
|
If '$LS_COLORS' variable is not set, '$LSCOLORS' variable is checked
|
||||||
|
instead. This variable is used by ls programs on unix systems such as Mac
|
||||||
|
and BSDs. This variable has a simple syntax and supports 8 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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
`
|
`
|
||||||
+9
-20
@@ -12,7 +12,7 @@ set ifs "\n"
|
|||||||
set scrolloff 10
|
set scrolloff 10
|
||||||
|
|
||||||
# use enter for shell commands
|
# use enter for shell commands
|
||||||
map <enter> read-shell
|
map <enter> shell
|
||||||
|
|
||||||
# execute current file (must be executable)
|
# execute current file (must be executable)
|
||||||
map x $$f
|
map x $$f
|
||||||
@@ -37,24 +37,15 @@ cmd open-file ${{
|
|||||||
}}
|
}}
|
||||||
|
|
||||||
# rename current file without overwrite
|
# rename current file without overwrite
|
||||||
cmd rename ${{
|
cmd rename %[ -e $1 ] && printf "file exists" || mv $f $1
|
||||||
if [ -e $1 ]; then
|
|
||||||
lf -remote "send $id echo file exists"
|
|
||||||
else
|
|
||||||
mv $f $1
|
|
||||||
fi
|
|
||||||
}}
|
|
||||||
map r push :rename<space>
|
map r push :rename<space>
|
||||||
|
|
||||||
# show disk usage
|
|
||||||
cmd usage $du -h . | less
|
|
||||||
|
|
||||||
# make sure trash folder exists
|
# make sure trash folder exists
|
||||||
$mkdir -p ~/.trash
|
%mkdir -p ~/.trash
|
||||||
|
|
||||||
# move current file or selected files to trash folder
|
# move current file or selected files to trash folder
|
||||||
# (also see 'man mv' for backup/overwrite options)
|
# (also see 'man mv' for backup/overwrite options)
|
||||||
cmd trash $mv $fx ~/.trash
|
cmd trash %mv $fx ~/.trash
|
||||||
|
|
||||||
# remove current file or selected files (prompting)
|
# remove current file or selected files (prompting)
|
||||||
cmd remove ${{
|
cmd remove ${{
|
||||||
@@ -66,7 +57,7 @@ cmd remove ${{
|
|||||||
|
|
||||||
# extract the current file with the right command
|
# extract the current file with the right command
|
||||||
# (xkcd link: https://xkcd.com/1168/)
|
# (xkcd link: https://xkcd.com/1168/)
|
||||||
cmd extract ${{
|
cmd extract %{{
|
||||||
case $f in
|
case $f in
|
||||||
*.tar.bz|*.tar.bz2|*.tbz|*.tbz2) tar xjvf $f;;
|
*.tar.bz|*.tar.bz2|*.tbz|*.tbz2) tar xjvf $f;;
|
||||||
*.tar.gz|*.tgz) tar xzvf $f;;
|
*.tar.gz|*.tgz) tar xzvf $f;;
|
||||||
@@ -77,12 +68,10 @@ cmd extract ${{
|
|||||||
esac
|
esac
|
||||||
}}
|
}}
|
||||||
|
|
||||||
# compress marked files with tar and gunzip
|
# compress current file or selected files with tar and gunzip
|
||||||
# This command takes the output name without '.tar.gz' suffix as an argument
|
cmd compress %{{
|
||||||
# (e.g. 'compress foo' creates 'foo.tar.gz').
|
|
||||||
cmd compress ${{
|
|
||||||
mkdir $1
|
mkdir $1
|
||||||
cp $fs $1
|
cp -r $fx $1
|
||||||
tar czvf $1.tar.gz $1
|
tar czf $1.tar.gz $1
|
||||||
rm -rf $1
|
rm -rf $1
|
||||||
}}
|
}}
|
||||||
@@ -1,10 +1,13 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
"unicode"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -17,14 +20,29 @@ func (e *setExpr) eval(app *app, args []string) {
|
|||||||
case "dircounts!":
|
case "dircounts!":
|
||||||
gOpts.dircounts = !gOpts.dircounts
|
gOpts.dircounts = !gOpts.dircounts
|
||||||
case "dirfirst":
|
case "dirfirst":
|
||||||
gOpts.dirfirst = true
|
gOpts.sortType.option |= dirfirstSort
|
||||||
app.nav.sort()
|
app.nav.sort()
|
||||||
|
app.ui.sort()
|
||||||
case "nodirfirst":
|
case "nodirfirst":
|
||||||
gOpts.dirfirst = false
|
gOpts.sortType.option &= ^dirfirstSort
|
||||||
app.nav.sort()
|
app.nav.sort()
|
||||||
|
app.ui.sort()
|
||||||
case "dirfirst!":
|
case "dirfirst!":
|
||||||
gOpts.dirfirst = !gOpts.dirfirst
|
gOpts.sortType.option ^= dirfirstSort
|
||||||
app.nav.sort()
|
app.nav.sort()
|
||||||
|
app.ui.sort()
|
||||||
|
case "drawbox":
|
||||||
|
gOpts.drawbox = true
|
||||||
|
app.ui.renew()
|
||||||
|
app.nav.height = app.ui.wins[0].h
|
||||||
|
case "nodrawbox":
|
||||||
|
gOpts.drawbox = false
|
||||||
|
app.ui.renew()
|
||||||
|
app.nav.height = app.ui.wins[0].h
|
||||||
|
case "drawbox!":
|
||||||
|
gOpts.drawbox = !gOpts.drawbox
|
||||||
|
app.ui.renew()
|
||||||
|
app.nav.height = app.ui.wins[0].h
|
||||||
case "globsearch":
|
case "globsearch":
|
||||||
gOpts.globsearch = true
|
gOpts.globsearch = true
|
||||||
case "noglobsearch":
|
case "noglobsearch":
|
||||||
@@ -32,14 +50,23 @@ func (e *setExpr) eval(app *app, args []string) {
|
|||||||
case "globsearch!":
|
case "globsearch!":
|
||||||
gOpts.globsearch = !gOpts.globsearch
|
gOpts.globsearch = !gOpts.globsearch
|
||||||
case "hidden":
|
case "hidden":
|
||||||
gOpts.hidden = true
|
gOpts.sortType.option |= hiddenSort
|
||||||
app.nav.sort()
|
app.nav.sort()
|
||||||
|
app.nav.position()
|
||||||
|
app.ui.sort()
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
case "nohidden":
|
case "nohidden":
|
||||||
gOpts.hidden = false
|
gOpts.sortType.option &= ^hiddenSort
|
||||||
app.nav.sort()
|
app.nav.sort()
|
||||||
|
app.nav.position()
|
||||||
|
app.ui.sort()
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
case "hidden!":
|
case "hidden!":
|
||||||
gOpts.hidden = !gOpts.hidden
|
gOpts.sortType.option ^= hiddenSort
|
||||||
app.nav.sort()
|
app.nav.sort()
|
||||||
|
app.nav.position()
|
||||||
|
app.ui.sort()
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
case "ignorecase":
|
case "ignorecase":
|
||||||
gOpts.ignorecase = true
|
gOpts.ignorecase = true
|
||||||
case "noignorecase":
|
case "noignorecase":
|
||||||
@@ -53,14 +80,17 @@ func (e *setExpr) eval(app *app, args []string) {
|
|||||||
case "preview!":
|
case "preview!":
|
||||||
gOpts.preview = !gOpts.preview
|
gOpts.preview = !gOpts.preview
|
||||||
case "reverse":
|
case "reverse":
|
||||||
gOpts.reverse = true
|
gOpts.sortType.option |= reverseSort
|
||||||
app.nav.sort()
|
app.nav.sort()
|
||||||
|
app.ui.sort()
|
||||||
case "noreverse":
|
case "noreverse":
|
||||||
gOpts.reverse = false
|
gOpts.sortType.option &= ^reverseSort
|
||||||
app.nav.sort()
|
app.nav.sort()
|
||||||
|
app.ui.sort()
|
||||||
case "reverse!":
|
case "reverse!":
|
||||||
gOpts.reverse = !gOpts.reverse
|
gOpts.sortType.option ^= reverseSort
|
||||||
app.nav.sort()
|
app.nav.sort()
|
||||||
|
app.ui.sort()
|
||||||
case "smartcase":
|
case "smartcase":
|
||||||
gOpts.smartcase = true
|
gOpts.smartcase = true
|
||||||
case "nosmartcase":
|
case "nosmartcase":
|
||||||
@@ -73,6 +103,23 @@ func (e *setExpr) eval(app *app, args []string) {
|
|||||||
gOpts.wrapscan = false
|
gOpts.wrapscan = false
|
||||||
case "wrapscan!":
|
case "wrapscan!":
|
||||||
gOpts.wrapscan = !gOpts.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":
|
case "scrolloff":
|
||||||
n, err := strconv.Atoi(e.val)
|
n, err := strconv.Atoi(e.val)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -83,10 +130,6 @@ func (e *setExpr) eval(app *app, args []string) {
|
|||||||
app.ui.print("scrolloff: value should be a non-negative number")
|
app.ui.print("scrolloff: value should be a non-negative number")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
max := app.ui.wins[0].h / 2
|
|
||||||
if n > max {
|
|
||||||
n = max
|
|
||||||
}
|
|
||||||
gOpts.scrolloff = n
|
gOpts.scrolloff = n
|
||||||
case "tabstop":
|
case "tabstop":
|
||||||
n, err := strconv.Atoi(e.val)
|
n, err := strconv.Atoi(e.val)
|
||||||
@@ -114,8 +157,18 @@ func (e *setExpr) eval(app *app, args []string) {
|
|||||||
app.ui.print("sortby: value should either be 'natural', 'name', 'size' or 'time'")
|
app.ui.print("sortby: value should either be 'natural', 'name', 'size' or 'time'")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
gOpts.sortby = e.val
|
switch e.val {
|
||||||
|
case "natural":
|
||||||
|
gOpts.sortType.method = naturalSort
|
||||||
|
case "name":
|
||||||
|
gOpts.sortType.method = nameSort
|
||||||
|
case "size":
|
||||||
|
gOpts.sortType.method = sizeSort
|
||||||
|
case "time":
|
||||||
|
gOpts.sortType.method = timeSort
|
||||||
|
}
|
||||||
app.nav.sort()
|
app.nav.sort()
|
||||||
|
app.ui.sort()
|
||||||
case "timefmt":
|
case "timefmt":
|
||||||
gOpts.timefmt = e.val
|
gOpts.timefmt = e.val
|
||||||
case "ratios":
|
case "ratios":
|
||||||
@@ -167,7 +220,7 @@ func (e *cmapExpr) eval(app *app, args []string) {
|
|||||||
delete(gOpts.cmdkeys, e.key)
|
delete(gOpts.cmdkeys, e.key)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
gOpts.cmdkeys[e.key] = &callExpr{e.cmd, nil}
|
gOpts.cmdkeys[e.key] = &callExpr{e.cmd, nil, 1}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *cmdExpr) eval(app *app, args []string) {
|
func (e *cmdExpr) eval(app *app, args []string) {
|
||||||
@@ -180,14 +233,14 @@ func (e *cmdExpr) eval(app *app, args []string) {
|
|||||||
|
|
||||||
func splitKeys(s string) (keys []string) {
|
func splitKeys(s string) (keys []string) {
|
||||||
for i := 0; i < len(s); {
|
for i := 0; i < len(s); {
|
||||||
c, w := utf8.DecodeRuneInString(s[i:])
|
r, w := utf8.DecodeRuneInString(s[i:])
|
||||||
if c != '<' {
|
if r != '<' {
|
||||||
keys = append(keys, s[i:i+w])
|
keys = append(keys, s[i:i+w])
|
||||||
i += w
|
i += w
|
||||||
} else {
|
} else {
|
||||||
j := i + w
|
j := i + w
|
||||||
for c != '>' && j < len(s) {
|
for r != '>' && j < len(s) {
|
||||||
c, w = utf8.DecodeRuneInString(s[j:])
|
r, w = utf8.DecodeRuneInString(s[j:])
|
||||||
j += w
|
j += w
|
||||||
}
|
}
|
||||||
keys = append(keys, s[i:j])
|
keys = append(keys, s[i:j])
|
||||||
@@ -200,34 +253,36 @@ func splitKeys(s string) (keys []string) {
|
|||||||
func (e *callExpr) eval(app *app, args []string) {
|
func (e *callExpr) eval(app *app, args []string) {
|
||||||
switch e.name {
|
switch e.name {
|
||||||
case "up":
|
case "up":
|
||||||
app.nav.up(1)
|
app.nav.up(e.count)
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "half-up":
|
case "half-up":
|
||||||
app.nav.up(app.nav.height / 2)
|
app.nav.up(e.count * app.nav.height / 2)
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "page-up":
|
case "page-up":
|
||||||
app.nav.up(app.nav.height)
|
app.nav.up(e.count * app.nav.height)
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "down":
|
case "down":
|
||||||
app.nav.down(1)
|
app.nav.down(e.count)
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "half-down":
|
case "half-down":
|
||||||
app.nav.down(app.nav.height / 2)
|
app.nav.down(e.count * app.nav.height / 2)
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "page-down":
|
case "page-down":
|
||||||
app.nav.down(app.nav.height)
|
app.nav.down(e.count * app.nav.height)
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "updir":
|
case "updir":
|
||||||
|
for i := 0; i < e.count; i++ {
|
||||||
if err := app.nav.updir(); err != nil {
|
if err := app.nav.updir(); err != nil {
|
||||||
app.ui.printf("%s", err)
|
app.ui.printf("%s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "open":
|
case "open":
|
||||||
@@ -285,12 +340,14 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
app.nav.top()
|
app.nav.top()
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "bot":
|
case "bottom":
|
||||||
app.nav.bot()
|
app.nav.bottom()
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "toggle":
|
case "toggle":
|
||||||
|
for i := 0; i < e.count; i++ {
|
||||||
app.nav.toggle()
|
app.nav.toggle()
|
||||||
|
}
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "invert":
|
case "invert":
|
||||||
@@ -322,7 +379,9 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
app.ui.printf("put: %s", err)
|
app.ui.printf("put: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
app.nav.renew(app.nav.height)
|
if err := sendRemote("send load"); err != nil {
|
||||||
|
app.ui.printf("put: %s", err)
|
||||||
|
}
|
||||||
if err := sendRemote("send sync"); err != nil {
|
if err := sendRemote("send sync"); err != nil {
|
||||||
app.ui.printf("put: %s", err)
|
app.ui.printf("put: %s", err)
|
||||||
}
|
}
|
||||||
@@ -334,38 +393,45 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
if err := sendRemote("send sync"); err != nil {
|
if err := sendRemote("send sync"); err != nil {
|
||||||
app.ui.printf("clear: %s", err)
|
app.ui.printf("clear: %s", err)
|
||||||
}
|
}
|
||||||
|
case "draw":
|
||||||
case "redraw":
|
case "redraw":
|
||||||
app.ui.sync()
|
app.ui.sync()
|
||||||
app.ui.renew()
|
app.ui.renew()
|
||||||
app.ui.loadFile(app.nav)
|
app.nav.height = app.ui.wins[0].h
|
||||||
|
case "load":
|
||||||
|
app.nav.renew()
|
||||||
case "reload":
|
case "reload":
|
||||||
app.ui.sync()
|
|
||||||
app.ui.renew()
|
|
||||||
app.nav.reload()
|
app.nav.reload()
|
||||||
case "read":
|
case "read":
|
||||||
app.ui.cmdPrefix = ":"
|
app.ui.cmdPrefix = ":"
|
||||||
case "read-shell":
|
case "shell":
|
||||||
app.ui.cmdPrefix = "$"
|
app.ui.cmdPrefix = "$"
|
||||||
case "read-shell-wait":
|
case "shell-pipe":
|
||||||
|
app.ui.cmdPrefix = "%"
|
||||||
|
case "shell-wait":
|
||||||
app.ui.cmdPrefix = "!"
|
app.ui.cmdPrefix = "!"
|
||||||
case "read-shell-async":
|
case "shell-async":
|
||||||
app.ui.cmdPrefix = "&"
|
app.ui.cmdPrefix = "&"
|
||||||
case "search":
|
case "search":
|
||||||
app.ui.cmdPrefix = "/"
|
app.ui.cmdPrefix = "/"
|
||||||
case "search-back":
|
case "search-back":
|
||||||
app.ui.cmdPrefix = "?"
|
app.ui.cmdPrefix = "?"
|
||||||
case "search-next":
|
case "search-next":
|
||||||
|
for i := 0; i < e.count; i++ {
|
||||||
if err := app.nav.searchNext(); err != nil {
|
if err := app.nav.searchNext(); err != nil {
|
||||||
app.ui.printf("search: %s: %s", err, app.nav.search)
|
app.ui.printf("search: %s: %s", err, app.nav.search)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "search-prev":
|
case "search-prev":
|
||||||
|
for i := 0; i < e.count; i++ {
|
||||||
if err := app.nav.searchPrev(); err != nil {
|
if err := app.nav.searchPrev(); err != nil {
|
||||||
app.ui.printf("search: %s: %s", err, app.nav.search)
|
app.ui.printf("search: %s: %s", err, app.nav.search)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "sync":
|
case "sync":
|
||||||
@@ -385,28 +451,45 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
}
|
}
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
|
case "select":
|
||||||
|
if len(e.args) != 1 {
|
||||||
|
app.ui.print("select: requires an argument")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := app.nav.find(e.args[0]); err != nil {
|
||||||
|
app.ui.printf("%s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "push":
|
case "push":
|
||||||
if len(e.args) > 0 {
|
if len(e.args) != 1 {
|
||||||
|
app.ui.print("push: requires an argument")
|
||||||
|
return
|
||||||
|
}
|
||||||
log.Println("pushing keys", e.args[0])
|
log.Println("pushing keys", e.args[0])
|
||||||
for _, key := range splitKeys(e.args[0]) {
|
for _, key := range splitKeys(e.args[0]) {
|
||||||
app.ui.keyChan <- key
|
app.ui.keyChan <- key
|
||||||
}
|
}
|
||||||
}
|
|
||||||
case "cmd-insert":
|
case "cmd-insert":
|
||||||
if len(e.args) > 0 {
|
if len(e.args) == 0 {
|
||||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(e.args[0])...)
|
return
|
||||||
}
|
}
|
||||||
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(e.args[0])...)
|
||||||
case "cmd-escape":
|
case "cmd-escape":
|
||||||
|
if app.ui.cmdPrefix == ">" {
|
||||||
|
return
|
||||||
|
}
|
||||||
app.ui.menuBuf = nil
|
app.ui.menuBuf = nil
|
||||||
app.ui.cmdAccLeft = nil
|
app.ui.cmdAccLeft = nil
|
||||||
app.ui.cmdAccRight = nil
|
app.ui.cmdAccRight = nil
|
||||||
app.ui.cmdPrefix = ""
|
app.ui.cmdPrefix = ""
|
||||||
case "cmd-comp":
|
case "cmd-complete":
|
||||||
var matches []string
|
var matches []string
|
||||||
if app.ui.cmdPrefix == ":" {
|
if app.ui.cmdPrefix == ":" {
|
||||||
matches, app.ui.cmdAccLeft = compCmd(app.ui.cmdAccLeft)
|
matches, app.ui.cmdAccLeft = completeCmd(app.ui.cmdAccLeft)
|
||||||
} else {
|
} else {
|
||||||
matches, app.ui.cmdAccLeft = compShell(app.ui.cmdAccLeft)
|
matches, app.ui.cmdAccLeft = completeShell(app.ui.cmdAccLeft)
|
||||||
}
|
}
|
||||||
app.ui.draw(app.nav)
|
app.ui.draw(app.nav)
|
||||||
if len(matches) > 1 {
|
if len(matches) > 1 {
|
||||||
@@ -432,15 +515,30 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
if p.err != nil {
|
if p.err != nil {
|
||||||
app.ui.printf("%s", p.err)
|
app.ui.printf("%s", p.err)
|
||||||
}
|
}
|
||||||
|
app.cmdHistory = append(app.cmdHistory, cmdItem{app.ui.cmdPrefix, s})
|
||||||
|
app.ui.cmdPrefix = ""
|
||||||
case "$":
|
case "$":
|
||||||
log.Printf("shell: %s", s)
|
log.Printf("shell: %s", s)
|
||||||
app.runShell(s, nil, false, false)
|
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.cmdHistory = append(app.cmdHistory, cmdItem{app.ui.cmdPrefix, s})
|
||||||
|
case ">":
|
||||||
|
io.WriteString(app.cmdIn, s+"\n")
|
||||||
|
app.cmdOutBuf = nil
|
||||||
case "!":
|
case "!":
|
||||||
log.Printf("shell-wait: %s", s)
|
log.Printf("shell-wait: %s", s)
|
||||||
app.runShell(s, nil, true, false)
|
app.runShell(s, nil, app.ui.cmdPrefix)
|
||||||
|
app.cmdHistory = append(app.cmdHistory, cmdItem{app.ui.cmdPrefix, s})
|
||||||
|
app.ui.cmdPrefix = ""
|
||||||
case "&":
|
case "&":
|
||||||
log.Printf("shell-async: %s", s)
|
log.Printf("shell-async: %s", s)
|
||||||
app.runShell(s, nil, false, true)
|
app.runShell(s, nil, app.ui.cmdPrefix)
|
||||||
|
app.cmdHistory = append(app.cmdHistory, cmdItem{app.ui.cmdPrefix, s})
|
||||||
|
app.ui.cmdPrefix = ""
|
||||||
case "/":
|
case "/":
|
||||||
log.Printf("search: %s", s)
|
log.Printf("search: %s", s)
|
||||||
app.nav.search = s
|
app.nav.search = s
|
||||||
@@ -450,6 +548,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
}
|
}
|
||||||
|
app.ui.cmdPrefix = ""
|
||||||
case "?":
|
case "?":
|
||||||
log.Printf("search-back: %s", s)
|
log.Printf("search-back: %s", s)
|
||||||
app.nav.search = s
|
app.nav.search = s
|
||||||
@@ -459,81 +558,211 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
}
|
}
|
||||||
|
app.ui.cmdPrefix = ""
|
||||||
default:
|
default:
|
||||||
log.Printf("entering unknown execution prefix: %q", app.ui.cmdPrefix)
|
log.Printf("entering unknown execution prefix: %q", app.ui.cmdPrefix)
|
||||||
}
|
}
|
||||||
app.cmdHist = append(app.cmdHist, cmdItem{app.ui.cmdPrefix, s})
|
case "cmd-history-next":
|
||||||
app.ui.cmdPrefix = ""
|
if app.ui.cmdPrefix == "" || app.ui.cmdPrefix == ">" {
|
||||||
case "cmd-hist-next":
|
return
|
||||||
if app.cmdHistInd > 0 {
|
|
||||||
app.cmdHistInd--
|
|
||||||
}
|
}
|
||||||
if app.cmdHistInd == 0 {
|
if app.cmdHistoryInd > 0 {
|
||||||
|
app.cmdHistoryInd--
|
||||||
|
}
|
||||||
|
if app.cmdHistoryInd == 0 {
|
||||||
app.ui.menuBuf = nil
|
app.ui.menuBuf = nil
|
||||||
app.ui.cmdAccLeft = nil
|
app.ui.cmdAccLeft = nil
|
||||||
app.ui.cmdAccRight = nil
|
app.ui.cmdAccRight = nil
|
||||||
app.ui.cmdPrefix = ""
|
app.ui.cmdPrefix = ""
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
cmd := app.cmdHist[len(app.cmdHist)-app.cmdHistInd]
|
cmd := app.cmdHistory[len(app.cmdHistory)-app.cmdHistoryInd]
|
||||||
app.ui.cmdPrefix = cmd.prefix
|
app.ui.cmdPrefix = cmd.prefix
|
||||||
app.ui.cmdAccLeft = []rune(cmd.value)
|
app.ui.cmdAccLeft = []rune(cmd.value)
|
||||||
app.ui.cmdAccRight = nil
|
app.ui.cmdAccRight = nil
|
||||||
app.ui.menuBuf = nil
|
app.ui.menuBuf = nil
|
||||||
case "cmd-hist-prev":
|
case "cmd-history-prev":
|
||||||
if app.cmdHistInd == len(app.cmdHist) {
|
if app.ui.cmdPrefix == ">" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
app.cmdHistInd++
|
if app.ui.cmdPrefix == "" {
|
||||||
cmd := app.cmdHist[len(app.cmdHist)-app.cmdHistInd]
|
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.cmdPrefix = cmd.prefix
|
||||||
app.ui.cmdAccLeft = []rune(cmd.value)
|
app.ui.cmdAccLeft = []rune(cmd.value)
|
||||||
app.ui.cmdAccRight = nil
|
app.ui.cmdAccRight = nil
|
||||||
app.ui.menuBuf = nil
|
app.ui.menuBuf = nil
|
||||||
case "cmd-delete":
|
case "cmd-delete":
|
||||||
if len(app.ui.cmdAccRight) > 0 {
|
if len(app.ui.cmdAccRight) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
app.ui.cmdAccRight = app.ui.cmdAccRight[1:]
|
app.ui.cmdAccRight = app.ui.cmdAccRight[1:]
|
||||||
}
|
|
||||||
case "cmd-delete-back":
|
case "cmd-delete-back":
|
||||||
if len(app.ui.cmdAccLeft) > 0 {
|
if len(app.ui.cmdAccLeft) == 0 {
|
||||||
app.ui.cmdAccLeft = app.ui.cmdAccLeft[:len(app.ui.cmdAccLeft)-1]
|
return
|
||||||
}
|
}
|
||||||
|
app.ui.cmdAccLeft = app.ui.cmdAccLeft[:len(app.ui.cmdAccLeft)-1]
|
||||||
case "cmd-left":
|
case "cmd-left":
|
||||||
if len(app.ui.cmdAccLeft) > 0 {
|
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.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]
|
app.ui.cmdAccLeft = app.ui.cmdAccLeft[:len(app.ui.cmdAccLeft)-1]
|
||||||
}
|
|
||||||
case "cmd-right":
|
case "cmd-right":
|
||||||
if len(app.ui.cmdAccRight) > 0 {
|
if len(app.ui.cmdAccRight) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdAccRight[0])
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdAccRight[0])
|
||||||
app.ui.cmdAccRight = app.ui.cmdAccRight[1:]
|
app.ui.cmdAccRight = app.ui.cmdAccRight[1:]
|
||||||
}
|
case "cmd-home":
|
||||||
case "cmd-beg":
|
|
||||||
app.ui.cmdAccRight = append(app.ui.cmdAccLeft, app.ui.cmdAccRight...)
|
app.ui.cmdAccRight = append(app.ui.cmdAccLeft, app.ui.cmdAccRight...)
|
||||||
app.ui.cmdAccLeft = nil
|
app.ui.cmdAccLeft = nil
|
||||||
case "cmd-end":
|
case "cmd-end":
|
||||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdAccRight...)
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdAccRight...)
|
||||||
app.ui.cmdAccRight = nil
|
app.ui.cmdAccRight = nil
|
||||||
case "cmd-delete-beg":
|
case "cmd-delete-home":
|
||||||
if len(app.ui.cmdAccLeft) > 0 {
|
if len(app.ui.cmdAccLeft) == 0 {
|
||||||
app.ui.cmdBuf = app.ui.cmdAccLeft
|
return
|
||||||
|
}
|
||||||
|
app.ui.cmdYankBuf = app.ui.cmdAccLeft
|
||||||
app.ui.cmdAccLeft = nil
|
app.ui.cmdAccLeft = nil
|
||||||
}
|
|
||||||
case "cmd-delete-end":
|
case "cmd-delete-end":
|
||||||
if len(app.ui.cmdAccRight) > 0 {
|
if len(app.ui.cmdAccRight) == 0 {
|
||||||
app.ui.cmdBuf = app.ui.cmdAccRight
|
return
|
||||||
|
}
|
||||||
|
app.ui.cmdYankBuf = app.ui.cmdAccRight
|
||||||
app.ui.cmdAccRight = nil
|
app.ui.cmdAccRight = nil
|
||||||
}
|
case "cmd-delete-unix-word":
|
||||||
case "cmd-delete-word":
|
|
||||||
ind := strings.LastIndex(strings.TrimRight(string(app.ui.cmdAccLeft), " "), " ") + 1
|
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]
|
app.ui.cmdAccLeft = app.ui.cmdAccLeft[:ind]
|
||||||
case "cmd-put":
|
case "cmd-yank":
|
||||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdBuf...)
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdYankBuf...)
|
||||||
case "cmd-transpose":
|
case "cmd-transpose":
|
||||||
if len(app.ui.cmdAccLeft) > 1 {
|
if len(app.ui.cmdAccLeft) < 2 {
|
||||||
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]
|
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()
|
||||||
|
}
|
||||||
|
app.ui.menuBuf = nil
|
||||||
|
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:
|
default:
|
||||||
cmd, ok := gOpts.cmds[e.name]
|
cmd, ok := gOpts.cmds[e.name]
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -548,19 +777,16 @@ func (e *execExpr) eval(app *app, args []string) {
|
|||||||
switch e.prefix {
|
switch e.prefix {
|
||||||
case "$":
|
case "$":
|
||||||
log.Printf("shell: %s -- %s", e, args)
|
log.Printf("shell: %s -- %s", e, args)
|
||||||
app.runShell(e.value, args, false, false)
|
app.runShell(e.value, args, e.prefix)
|
||||||
|
case "%":
|
||||||
|
log.Printf("shell-pipe: %s -- %s", e, args)
|
||||||
|
app.runShell(e.value, args, e.prefix)
|
||||||
case "!":
|
case "!":
|
||||||
log.Printf("shell-wait: %s -- %s", e, args)
|
log.Printf("shell-wait: %s -- %s", e, args)
|
||||||
app.runShell(e.value, args, true, false)
|
app.runShell(e.value, args, e.prefix)
|
||||||
case "&":
|
case "&":
|
||||||
log.Printf("shell-async: %s -- %s", e, args)
|
log.Printf("shell-async: %s -- %s", e, args)
|
||||||
app.runShell(e.value, args, false, true)
|
app.runShell(e.value, args, e.prefix)
|
||||||
case "/":
|
|
||||||
log.Printf("search: %s -- %s", e, args)
|
|
||||||
// TODO: implement
|
|
||||||
case "?":
|
|
||||||
log.Printf("search-back: %s -- %s", e, args)
|
|
||||||
// TODO: implement
|
|
||||||
default:
|
default:
|
||||||
log.Printf("evaluating unknown execution prefix: %q", e.prefix)
|
log.Printf("evaluating unknown execution prefix: %q", e.prefix)
|
||||||
}
|
}
|
||||||
|
|||||||
+30
-30
@@ -26,85 +26,85 @@ var gEvalTests = []struct {
|
|||||||
{
|
{
|
||||||
"echo hello",
|
"echo hello",
|
||||||
[]string{"echo", "hello", "\n"},
|
[]string{"echo", "hello", "\n"},
|
||||||
[]expr{&callExpr{"echo", []string{"hello"}}},
|
[]expr{&callExpr{"echo", []string{"hello"}, 1}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"echo hello world",
|
"echo hello world",
|
||||||
[]string{"echo", "hello", "world", "\n"},
|
[]string{"echo", "hello", "world", "\n"},
|
||||||
[]expr{&callExpr{"echo", []string{"hello", "world"}}},
|
[]expr{&callExpr{"echo", []string{"hello", "world"}, 1}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"echo 'hello world'",
|
"echo 'hello world'",
|
||||||
[]string{"echo", "hello world", "\n"},
|
[]string{"echo", "hello world", "\n"},
|
||||||
[]expr{&callExpr{"echo", []string{"hello world"}}},
|
[]expr{&callExpr{"echo", []string{"hello world"}, 1}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
`echo "hello world"`,
|
`echo "hello world"`,
|
||||||
[]string{"echo", "hello world", "\n"},
|
[]string{"echo", "hello world", "\n"},
|
||||||
[]expr{&callExpr{"echo", []string{"hello world"}}},
|
[]expr{&callExpr{"echo", []string{"hello world"}, 1}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
`echo "hello\"world"`,
|
`echo "hello\"world"`,
|
||||||
[]string{"echo", `hello"world`, "\n"},
|
[]string{"echo", `hello"world`, "\n"},
|
||||||
[]expr{&callExpr{"echo", []string{`hello"world`}}},
|
[]expr{&callExpr{"echo", []string{`hello"world`}, 1}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
`echo "hello\tworld"`,
|
`echo "hello\tworld"`,
|
||||||
[]string{"echo", "hello\tworld", "\n"},
|
[]string{"echo", "hello\tworld", "\n"},
|
||||||
[]expr{&callExpr{"echo", []string{"hello\tworld"}}},
|
[]expr{&callExpr{"echo", []string{"hello\tworld"}, 1}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
`echo "hello\nworld"`,
|
`echo "hello\nworld"`,
|
||||||
[]string{"echo", "hello\nworld", "\n"},
|
[]string{"echo", "hello\nworld", "\n"},
|
||||||
[]expr{&callExpr{"echo", []string{"hello\nworld"}}},
|
[]expr{&callExpr{"echo", []string{"hello\nworld"}, 1}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
`echo "hello\zworld"`,
|
`echo "hello\zworld"`,
|
||||||
[]string{"echo", "helloworld", "\n"},
|
[]string{"echo", "helloworld", "\n"},
|
||||||
[]expr{&callExpr{"echo", []string{"helloworld"}}},
|
[]expr{&callExpr{"echo", []string{"helloworld"}, 1}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
`echo "hello\0world"`,
|
`echo "hello\0world"`,
|
||||||
[]string{"echo", "hello\000world", "\n"},
|
[]string{"echo", "hello\000world", "\n"},
|
||||||
[]expr{&callExpr{"echo", []string{"hello\000world"}}},
|
[]expr{&callExpr{"echo", []string{"hello\000world"}, 1}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
`echo "hello\101world"`,
|
`echo "hello\101world"`,
|
||||||
[]string{"echo", "hello\101world", "\n"},
|
[]string{"echo", "hello\101world", "\n"},
|
||||||
[]expr{&callExpr{"echo", []string{"hello\101world"}}},
|
[]expr{&callExpr{"echo", []string{"hello\101world"}, 1}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
`echo hello\ world`,
|
`echo hello\ world`,
|
||||||
[]string{"echo", "hello world", "\n"},
|
[]string{"echo", "hello world", "\n"},
|
||||||
[]expr{&callExpr{"echo", []string{"hello world"}}},
|
[]expr{&callExpr{"echo", []string{"hello world"}, 1}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
`echo hello\ world`,
|
`echo hello\ world`,
|
||||||
[]string{"echo", "hello\tworld", "\n"},
|
[]string{"echo", "hello\tworld", "\n"},
|
||||||
[]expr{&callExpr{"echo", []string{"hello\tworld"}}},
|
[]expr{&callExpr{"echo", []string{"hello\tworld"}, 1}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"echo hello\\\nworld",
|
"echo hello\\\nworld",
|
||||||
[]string{"echo", "hello\nworld", "\n"},
|
[]string{"echo", "hello\nworld", "\n"},
|
||||||
[]expr{&callExpr{"echo", []string{"hello\nworld"}}},
|
[]expr{&callExpr{"echo", []string{"hello\nworld"}, 1}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
`echo hello\zworld`,
|
`echo hello\zworld`,
|
||||||
[]string{"echo", "helloworld", "\n"},
|
[]string{"echo", "helloworld", "\n"},
|
||||||
[]expr{&callExpr{"echo", []string{"helloworld"}}},
|
[]expr{&callExpr{"echo", []string{"helloworld"}, 1}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -164,25 +164,25 @@ var gEvalTests = []struct {
|
|||||||
{
|
{
|
||||||
"map gh cd ~",
|
"map gh cd ~",
|
||||||
[]string{"map", "gh", "cd", "~", "\n"},
|
[]string{"map", "gh", "cd", "~", "\n"},
|
||||||
[]expr{&mapExpr{"gh", &callExpr{"cd", []string{"~"}}}},
|
[]expr{&mapExpr{"gh", &callExpr{"cd", []string{"~"}, 1}}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"map gh cd ~;",
|
"map gh cd ~;",
|
||||||
[]string{"map", "gh", "cd", "~", ";"},
|
[]string{"map", "gh", "cd", "~", ";"},
|
||||||
[]expr{&mapExpr{"gh", &callExpr{"cd", []string{"~"}}}},
|
[]expr{&mapExpr{"gh", &callExpr{"cd", []string{"~"}, 1}}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"map gh :cd ~",
|
"map gh :cd ~",
|
||||||
[]string{"map", "gh", ":", "cd", "~", "\n", "\n"},
|
[]string{"map", "gh", ":", "cd", "~", "\n", "\n"},
|
||||||
[]expr{&mapExpr{"gh", &listExpr{[]expr{&callExpr{"cd", []string{"~"}}}}}},
|
[]expr{&mapExpr{"gh", &listExpr{[]expr{&callExpr{"cd", []string{"~"}, 1}}}}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"map gh :cd ~;",
|
"map gh :cd ~;",
|
||||||
[]string{"map", "gh", ":", "cd", "~", ";", "\n"},
|
[]string{"map", "gh", ":", "cd", "~", ";", "\n"},
|
||||||
[]expr{&mapExpr{"gh", &listExpr{[]expr{&callExpr{"cd", []string{"~"}}}}}},
|
[]expr{&mapExpr{"gh", &listExpr{[]expr{&callExpr{"cd", []string{"~"}, 1}}}}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -206,55 +206,55 @@ var gEvalTests = []struct {
|
|||||||
{
|
{
|
||||||
"map u usage",
|
"map u usage",
|
||||||
[]string{"map", "u", "usage", "\n"},
|
[]string{"map", "u", "usage", "\n"},
|
||||||
[]expr{&mapExpr{"u", &callExpr{"usage", nil}}},
|
[]expr{&mapExpr{"u", &callExpr{"usage", nil, 1}}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"map u usage;",
|
"map u usage;",
|
||||||
[]string{"map", "u", "usage", ";"},
|
[]string{"map", "u", "usage", ";"},
|
||||||
[]expr{&mapExpr{"u", &callExpr{"usage", nil}}},
|
[]expr{&mapExpr{"u", &callExpr{"usage", nil, 1}}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"map u :usage",
|
"map u :usage",
|
||||||
[]string{"map", "u", ":", "usage", "\n", "\n"},
|
[]string{"map", "u", ":", "usage", "\n", "\n"},
|
||||||
[]expr{&mapExpr{"u", &listExpr{[]expr{&callExpr{"usage", nil}}}}},
|
[]expr{&mapExpr{"u", &listExpr{[]expr{&callExpr{"usage", nil, 1}}}}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"map u :usage;",
|
"map u :usage;",
|
||||||
[]string{"map", "u", ":", "usage", ";", "\n"},
|
[]string{"map", "u", ":", "usage", ";", "\n"},
|
||||||
[]expr{&mapExpr{"u", &listExpr{[]expr{&callExpr{"usage", nil}}}}},
|
[]expr{&mapExpr{"u", &listExpr{[]expr{&callExpr{"usage", nil, 1}}}}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"map r push :rename<space>",
|
"map r push :rename<space>",
|
||||||
[]string{"map", "r", "push", ":rename<space>", "\n"},
|
[]string{"map", "r", "push", ":rename<space>", "\n"},
|
||||||
[]expr{&mapExpr{"r", &callExpr{"push", []string{":rename<space>"}}}},
|
[]expr{&mapExpr{"r", &callExpr{"push", []string{":rename<space>"}, 1}}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"map r push :rename<space>;",
|
"map r push :rename<space>;",
|
||||||
[]string{"map", "r", "push", ":rename<space>;", "\n"},
|
[]string{"map", "r", "push", ":rename<space>;", "\n"},
|
||||||
[]expr{&mapExpr{"r", &callExpr{"push", []string{":rename<space>;"}}}},
|
[]expr{&mapExpr{"r", &callExpr{"push", []string{":rename<space>;"}, 1}}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"map r push :rename<space> # trailing comments are allowed after a space",
|
"map r push :rename<space> # trailing comments are allowed after a space",
|
||||||
[]string{"map", "r", "push", ":rename<space>", "\n"},
|
[]string{"map", "r", "push", ":rename<space>", "\n"},
|
||||||
[]expr{&mapExpr{"r", &callExpr{"push", []string{":rename<space>"}}}},
|
[]expr{&mapExpr{"r", &callExpr{"push", []string{":rename<space>"}, 1}}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"map r :push :rename<space>",
|
"map r :push :rename<space>",
|
||||||
[]string{"map", "r", ":", "push", ":rename<space>", "\n", "\n"},
|
[]string{"map", "r", ":", "push", ":rename<space>", "\n", "\n"},
|
||||||
[]expr{&mapExpr{"r", &listExpr{[]expr{&callExpr{"push", []string{":rename<space>"}}}}}},
|
[]expr{&mapExpr{"r", &listExpr{[]expr{&callExpr{"push", []string{":rename<space>"}, 1}}}}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"map r :push :rename<space> ; set hidden",
|
"map r :push :rename<space> ; set hidden",
|
||||||
[]string{"map", "r", ":", "push", ":rename<space>", ";", "set", "hidden", "\n", "\n"},
|
[]string{"map", "r", ":", "push", ":rename<space>", ";", "set", "hidden", "\n", "\n"},
|
||||||
[]expr{&mapExpr{"r", &listExpr{[]expr{&callExpr{"push", []string{":rename<space>"}}, &setExpr{"hidden", ""}}}}},
|
[]expr{&mapExpr{"r", &listExpr{[]expr{&callExpr{"push", []string{":rename<space>"}, 1}, &setExpr{"hidden", ""}}}}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -272,7 +272,7 @@ var gEvalTests = []struct {
|
|||||||
{
|
{
|
||||||
"map u usage /",
|
"map u usage /",
|
||||||
[]string{"map", "u", "usage", "/", "\n"},
|
[]string{"map", "u", "usage", "/", "\n"},
|
||||||
[]expr{&mapExpr{"u", &callExpr{"usage", []string{"/"}}}},
|
[]expr{&mapExpr{"u", &callExpr{"usage", []string{"/"}, 1}}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -297,7 +297,7 @@ var gEvalTests = []struct {
|
|||||||
"set", "hidden", "\n",
|
"set", "hidden", "\n",
|
||||||
"}}", "\n"},
|
"}}", "\n"},
|
||||||
[]expr{&cmdExpr{"gohome", &listExpr{[]expr{
|
[]expr{&cmdExpr{"gohome", &listExpr{[]expr{
|
||||||
&callExpr{"cd", []string{"~"}},
|
&callExpr{"cd", []string{"~"}, 1},
|
||||||
&setExpr{"hidden", ""}}},
|
&setExpr{"hidden", ""}}},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
@@ -312,7 +312,7 @@ var gEvalTests = []struct {
|
|||||||
"set", "hidden", "\n",
|
"set", "hidden", "\n",
|
||||||
"}}", "\n"},
|
"}}", "\n"},
|
||||||
[]expr{&mapExpr{"gh", &listExpr{[]expr{
|
[]expr{&mapExpr{"gh", &listExpr{[]expr{
|
||||||
&callExpr{"cd", []string{"~"}},
|
&callExpr{"cd", []string{"~"}, 1},
|
||||||
&setExpr{"hidden", ""}}},
|
&setExpr{"hidden", ""}}},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"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() {
|
func main() {
|
||||||
showDoc := flag.Bool(
|
showDoc := flag.Bool(
|
||||||
"doc",
|
"doc",
|
||||||
@@ -125,10 +141,7 @@ func main() {
|
|||||||
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:
|
||||||
// TODO: check if the socket is working
|
checkServer()
|
||||||
if _, err := os.Stat(gSocketPath); os.IsNotExist(err) {
|
|
||||||
startServer()
|
|
||||||
}
|
|
||||||
|
|
||||||
gClientID = 1000
|
gClientID = 1000
|
||||||
gLogPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.%d.log", gUser.Username, gClientID))
|
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)
|
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 {
|
func min(a, b int) int {
|
||||||
if a < b {
|
if a < b {
|
||||||
return a
|
return a
|
||||||
@@ -210,7 +216,7 @@ func max(a, b int) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We don't need no generic code
|
// 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
|
// No dark templates in compiler
|
||||||
// Haskell leave them kids alone
|
// Haskell leave them kids alone
|
||||||
// Hey Bjarne leave them kids alone
|
// Hey Bjarne leave them kids alone
|
||||||
|
|||||||
@@ -27,21 +27,7 @@ type file struct {
|
|||||||
os.FileInfo
|
os.FileInfo
|
||||||
linkState linkState
|
linkState linkState
|
||||||
path string
|
path string
|
||||||
count int
|
dirCount 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})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func readdir(path string) ([]*file, error) {
|
func readdir(path string) ([]*file, error) {
|
||||||
@@ -49,60 +35,59 @@ func readdir(path string) ([]*file, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
names, err := f.Readdirnames(-1)
|
names, err := f.Readdirnames(-1)
|
||||||
f.Close()
|
f.Close()
|
||||||
|
|
||||||
fi := make([]*file, 0, len(names))
|
files := make([]*file, 0, len(names))
|
||||||
for _, filename := range names {
|
for _, fname := range names {
|
||||||
fpath := filepath.Join(path, filename)
|
fpath := filepath.Join(path, fname)
|
||||||
|
|
||||||
lstat, lerr := os.Lstat(fpath)
|
lstat, err := os.Lstat(fpath)
|
||||||
if os.IsNotExist(lerr) {
|
if os.IsNotExist(err) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if lerr != nil {
|
if err != nil {
|
||||||
return fi, lerr
|
return files, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var linkState linkState
|
var linkState linkState
|
||||||
|
|
||||||
if lstat.Mode()&os.ModeSymlink != 0 {
|
if lstat.Mode()&os.ModeSymlink != 0 {
|
||||||
stat, serr := os.Stat(fpath)
|
stat, err := os.Stat(fpath)
|
||||||
if serr == nil {
|
if err == nil {
|
||||||
linkState = working
|
linkState = working
|
||||||
lstat = stat
|
lstat = stat
|
||||||
} else {
|
} else {
|
||||||
linkState = broken
|
linkState = broken
|
||||||
log.Printf("getting link destination info: %s", serr)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fi = append(fi, &file{
|
files = append(files, &file{
|
||||||
FileInfo: lstat,
|
FileInfo: lstat,
|
||||||
linkState: linkState,
|
linkState: linkState,
|
||||||
path: fpath,
|
path: fpath,
|
||||||
count: -1,
|
dirCount: -1,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return fi, err
|
return files, err
|
||||||
}
|
}
|
||||||
|
|
||||||
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 fi
|
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
|
||||||
fi []*file // displayed files in directory including or excluding hidden ones
|
files []*file // displayed files in directory including or excluding hidden ones
|
||||||
all []*file // all files in directory including hidden ones (same array as fi)
|
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 {
|
func newDir(path string) *dir {
|
||||||
time := time.Now()
|
time := time.Now()
|
||||||
|
|
||||||
fi, err := readdir(path)
|
files, err := readdir(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("reading directory: %s", err)
|
log.Printf("reading directory: %s", err)
|
||||||
}
|
}
|
||||||
@@ -110,97 +95,87 @@ func newDir(path string) *dir {
|
|||||||
return &dir{
|
return &dir{
|
||||||
loadTime: time,
|
loadTime: time,
|
||||||
path: path,
|
path: path,
|
||||||
fi: fi,
|
files: files,
|
||||||
all: fi,
|
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() {
|
func (dir *dir) sort() {
|
||||||
dir.fi = dir.all
|
dir.sortType = gOpts.sortType
|
||||||
|
|
||||||
switch gOpts.sortby {
|
dir.files = dir.allFiles
|
||||||
case "natural":
|
|
||||||
sortFilesStable(dir.fi, func(i, j int) bool {
|
switch gOpts.sortType.method {
|
||||||
return naturalLess(strings.ToLower(dir.fi[i].Name()), strings.ToLower(dir.fi[j].Name()))
|
case naturalSort:
|
||||||
|
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||||
|
return naturalLess(strings.ToLower(dir.files[i].Name()), strings.ToLower(dir.files[j].Name()))
|
||||||
})
|
})
|
||||||
case "name":
|
case nameSort:
|
||||||
sortFilesStable(dir.fi, func(i, j int) bool {
|
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||||
return strings.ToLower(dir.fi[i].Name()) < strings.ToLower(dir.fi[j].Name())
|
return strings.ToLower(dir.files[i].Name()) < strings.ToLower(dir.files[j].Name())
|
||||||
})
|
})
|
||||||
case "size":
|
case sizeSort:
|
||||||
sortFilesStable(dir.fi, func(i, j int) bool {
|
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||||
return dir.fi[i].Size() < dir.fi[j].Size()
|
return dir.files[i].Size() < dir.files[j].Size()
|
||||||
})
|
})
|
||||||
case "time":
|
case timeSort:
|
||||||
sortFilesStable(dir.fi, func(i, j int) bool {
|
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||||
return dir.fi[i].ModTime().Before(dir.fi[j].ModTime())
|
return dir.files[i].ModTime().Before(dir.files[j].ModTime())
|
||||||
})
|
})
|
||||||
default:
|
|
||||||
log.Printf("unknown sorting type: %s", gOpts.sortby)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if gOpts.reverse {
|
if gOpts.sortType.option&reverseSort != 0 {
|
||||||
for i, j := 0, len(dir.fi)-1; i < j; i, j = i+1, j-1 {
|
for i, j := 0, len(dir.files)-1; i < j; i, j = i+1, j-1 {
|
||||||
dir.fi[i], dir.fi[j] = dir.fi[j], dir.fi[i]
|
dir.files[i], dir.files[j] = dir.files[j], dir.files[i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if gOpts.dirfirst {
|
if gOpts.sortType.option&dirfirstSort != 0 {
|
||||||
sortFilesStable(dir.fi, func(i, j int) bool {
|
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||||
if dir.fi[i].IsDir() == dir.fi[j].IsDir() {
|
if dir.files[i].IsDir() == dir.files[j].IsDir() {
|
||||||
return i < j
|
return i < j
|
||||||
}
|
}
|
||||||
return dir.fi[i].IsDir()
|
return dir.files[i].IsDir()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// when hidden option is disabled, we move hidden files to the
|
// when hidden option is disabled, we move hidden files to the
|
||||||
// beginning of our file list and then set the beginning of displayed
|
// beginning of our file list and then set the beginning of displayed
|
||||||
// files to the first non-hidden file in the list
|
// files to the first non-hidden file in the list
|
||||||
if !gOpts.hidden {
|
if gOpts.sortType.option&hiddenSort == 0 {
|
||||||
sortFilesStable(dir.fi, func(i, j int) bool {
|
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||||
if dir.fi[i].Name()[0] == '.' && dir.fi[j].Name()[0] == '.' {
|
if dir.files[i].Name()[0] == '.' && dir.files[j].Name()[0] == '.' {
|
||||||
return i < j
|
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] != '.' {
|
if f.Name()[0] != '.' {
|
||||||
dir.fi = dir.fi[i:]
|
dir.files = dir.files[i:]
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dir.fi = dir.fi[len(dir.fi):]
|
dir.files = dir.files[len(dir.files):]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dir *dir) name() string {
|
func (dir *dir) name() string {
|
||||||
if len(dir.fi) == 0 {
|
if len(dir.files) == 0 {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return dir.fi[dir.ind].Name()
|
return dir.files[dir.ind].Name()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dir *dir) find(name string, height int) {
|
func (dir *dir) find(name string, height int) {
|
||||||
if len(dir.fi) == 0 {
|
if len(dir.files) == 0 {
|
||||||
dir.ind, dir.pos = 0, 0
|
dir.ind, dir.pos = 0, 0
|
||||||
return
|
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 {
|
if dir.files[dir.ind].Name() != name {
|
||||||
for i, f := range dir.fi {
|
for i, f := range dir.files {
|
||||||
if f.Name() == name {
|
if f.Name() == name {
|
||||||
dir.ind = i
|
dir.ind = i
|
||||||
break
|
break
|
||||||
@@ -208,7 +183,7 @@ func (dir *dir) find(name string, height int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
edge := min(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)
|
dir.pos = min(dir.ind, height-edge-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,6 +200,64 @@ type nav struct {
|
|||||||
search string
|
search string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
|
||||||
|
func (nav *nav) getDirs(wd string) {
|
||||||
|
var dirs []*dir
|
||||||
|
|
||||||
|
for curr, base := wd, ""; !isRoot(base); curr, base = filepath.Dir(curr), filepath.Base(curr) {
|
||||||
|
dir := nav.loadDir(curr)
|
||||||
|
dir.find(base, nav.height)
|
||||||
|
dirs = append(dirs, dir)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, j := 0, len(dirs)-1; i < j; i, j = i+1, j-1 {
|
||||||
|
dirs[i], dirs[j] = dirs[j], dirs[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
nav.dirs = dirs
|
||||||
|
}
|
||||||
|
|
||||||
func newNav(height int) *nav {
|
func newNav(height int) *nav {
|
||||||
wd, err := os.Getwd()
|
wd, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -236,8 +269,8 @@ func newNav(height int) *nav {
|
|||||||
regChan: make(chan *reg),
|
regChan: make(chan *reg),
|
||||||
dirCache: make(map[string]*dir),
|
dirCache: make(map[string]*dir),
|
||||||
regCache: make(map[string]*reg),
|
regCache: make(map[string]*reg),
|
||||||
marks: make(map[string]int),
|
|
||||||
saves: make(map[string]bool),
|
saves: make(map[string]bool),
|
||||||
|
marks: make(map[string]int),
|
||||||
markInd: 0,
|
markInd: 0,
|
||||||
height: height,
|
height: height,
|
||||||
}
|
}
|
||||||
@@ -247,36 +280,7 @@ func newNav(height int) *nav {
|
|||||||
return nav
|
return nav
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) position() {
|
func (nav *nav) renew() {
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (nav *nav) getDirs(wd string) {
|
|
||||||
var dirs []*dir
|
|
||||||
|
|
||||||
for curr, base := wd, ""; !isRoot(base); curr, base = filepath.Dir(curr), filepath.Base(curr) {
|
|
||||||
dir := nav.loadDir(curr)
|
|
||||||
dirs = append(dirs, dir)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i, j := 0, len(dirs)-1; i < j; i, j = i+1, j-1 {
|
|
||||||
dirs[i], dirs[j] = dirs[j], dirs[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
nav.dirs = dirs
|
|
||||||
}
|
|
||||||
|
|
||||||
func (nav *nav) renew(height int) {
|
|
||||||
nav.dirCache = make(map[string]*dir)
|
|
||||||
for _, d := range nav.dirs {
|
|
||||||
nav.dirCache[d.path] = d
|
|
||||||
}
|
|
||||||
|
|
||||||
nav.height = height
|
|
||||||
for _, d := range nav.dirs {
|
for _, d := range nav.dirs {
|
||||||
go func(d *dir) {
|
go func(d *dir) {
|
||||||
s, err := os.Stat(d.path)
|
s, err := os.Stat(d.path)
|
||||||
@@ -316,24 +320,16 @@ func (nav *nav) reload() {
|
|||||||
nav.getDirs(wd)
|
nav.getDirs(wd)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
last := nav.dirs[len(nav.dirs)-1]
|
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 {
|
func (nav *nav) position() {
|
||||||
d, ok := nav.dirCache[path]
|
path := nav.currDir().path
|
||||||
if !ok {
|
for i := len(nav.dirs) - 2; i >= 0; i-- {
|
||||||
go func() {
|
nav.dirs[i].find(filepath.Base(path), nav.height)
|
||||||
d := newDir(path)
|
path = filepath.Dir(path)
|
||||||
d.sort()
|
|
||||||
d.ind, d.pos = 0, 0
|
|
||||||
nav.dirChan <- d
|
|
||||||
}()
|
|
||||||
d := &dir{loading: true, path: path}
|
|
||||||
nav.dirCache[path] = d
|
|
||||||
return d
|
|
||||||
}
|
}
|
||||||
return d
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) preview() {
|
func (nav *nav) preview() {
|
||||||
@@ -369,7 +365,7 @@ func (nav *nav) preview() {
|
|||||||
reader = f
|
reader = f
|
||||||
}
|
}
|
||||||
|
|
||||||
reg := ®{path: curr.path}
|
reg := ®{loadTime: time.Now(), path: curr.path}
|
||||||
|
|
||||||
buf := bufio.NewScanner(reader)
|
buf := bufio.NewScanner(reader)
|
||||||
|
|
||||||
@@ -395,10 +391,21 @@ func (nav *nav) loadReg(ui *ui, path string) *reg {
|
|||||||
r, ok := nav.regCache[path]
|
r, ok := nav.regCache[path]
|
||||||
if !ok {
|
if !ok {
|
||||||
go nav.preview()
|
go nav.preview()
|
||||||
r := ®{path: path, lines: []string{"\033[1mloading...\033[0m"}}
|
r := ®{loading: true, path: path}
|
||||||
nav.regCache[path] = r
|
nav.regCache[path] = r
|
||||||
return 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
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -421,14 +428,14 @@ func (nav *nav) up(dist int) {
|
|||||||
dir.ind = max(0, dir.ind)
|
dir.ind = max(0, dir.ind)
|
||||||
|
|
||||||
dir.pos -= dist
|
dir.pos -= dist
|
||||||
edge := min(gOpts.scrolloff, dir.ind)
|
edge := min(min(nav.height/2, gOpts.scrolloff), dir.ind)
|
||||||
dir.pos = max(dir.pos, edge)
|
dir.pos = max(dir.pos, edge)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) down(dist int) {
|
func (nav *nav) down(dist int) {
|
||||||
dir := nav.currDir()
|
dir := nav.currDir()
|
||||||
|
|
||||||
maxind := len(dir.fi) - 1
|
maxind := len(dir.files) - 1
|
||||||
|
|
||||||
if dir.ind >= maxind {
|
if dir.ind >= maxind {
|
||||||
return
|
return
|
||||||
@@ -438,7 +445,7 @@ func (nav *nav) down(dist int) {
|
|||||||
dir.ind = min(maxind, dir.ind)
|
dir.ind = min(maxind, dir.ind)
|
||||||
|
|
||||||
dir.pos += dist
|
dir.pos += dist
|
||||||
edge := min(gOpts.scrolloff, maxind-dir.ind)
|
edge := min(min(nav.height/2, gOpts.scrolloff), maxind-dir.ind)
|
||||||
|
|
||||||
// use a smaller value when the height is even and scrolloff is maxed
|
// use a smaller value when the height is even and scrolloff is maxed
|
||||||
// in order to stay at the same row as much as possible while up/down
|
// in order to stay at the same row as much as possible while up/down
|
||||||
@@ -490,10 +497,10 @@ func (nav *nav) top() {
|
|||||||
dir.pos = 0
|
dir.pos = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) bot() {
|
func (nav *nav) bottom() {
|
||||||
dir := nav.currDir()
|
dir := nav.currDir()
|
||||||
|
|
||||||
dir.ind = len(dir.fi) - 1
|
dir.ind = len(dir.files) - 1
|
||||||
dir.pos = min(dir.ind, nav.height-1)
|
dir.pos = min(dir.ind, nav.height-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -522,7 +529,7 @@ func (nav *nav) toggle() {
|
|||||||
|
|
||||||
func (nav *nav) invert() {
|
func (nav *nav) invert() {
|
||||||
last := nav.currDir()
|
last := nav.currDir()
|
||||||
for _, f := range last.fi {
|
for _, f := range last.files {
|
||||||
path := filepath.Join(last.path, f.Name())
|
path := filepath.Join(last.path, f.Name())
|
||||||
nav.toggleMark(path)
|
nav.toggleMark(path)
|
||||||
}
|
}
|
||||||
@@ -618,6 +625,30 @@ func (nav *nav) cd(wd string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (nav *nav) find(path string) error {
|
||||||
|
lstat, err := os.Stat(path)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("select: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
dir := filepath.Dir(path)
|
||||||
|
|
||||||
|
if err := nav.cd(dir); err != nil {
|
||||||
|
return fmt.Errorf("select: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
base := filepath.Base(path)
|
||||||
|
|
||||||
|
last := nav.dirs[len(nav.dirs)-1]
|
||||||
|
if last.loading {
|
||||||
|
last.files = append(last.files, &file{FileInfo: lstat})
|
||||||
|
} else {
|
||||||
|
last.find(base, nav.height)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func match(pattern, name string) (matched bool, err error) {
|
func match(pattern, name string) (matched bool, err error) {
|
||||||
if gOpts.ignorecase {
|
if gOpts.ignorecase {
|
||||||
lpattern := strings.ToLower(pattern)
|
lpattern := strings.ToLower(pattern)
|
||||||
@@ -634,8 +665,8 @@ func match(pattern, name string) (matched bool, err error) {
|
|||||||
|
|
||||||
func (nav *nav) searchNext() error {
|
func (nav *nav) searchNext() error {
|
||||||
last := nav.currDir()
|
last := nav.currDir()
|
||||||
for i := last.ind + 1; i < len(last.fi); i++ {
|
for i := last.ind + 1; i < len(last.files); i++ {
|
||||||
matched, err := match(nav.search, last.fi[i].Name())
|
matched, err := match(nav.search, last.files[i].Name())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -646,7 +677,7 @@ func (nav *nav) searchNext() error {
|
|||||||
}
|
}
|
||||||
if gOpts.wrapscan {
|
if gOpts.wrapscan {
|
||||||
for i := 0; i < last.ind; i++ {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -662,7 +693,7 @@ func (nav *nav) searchNext() error {
|
|||||||
func (nav *nav) searchPrev() error {
|
func (nav *nav) searchPrev() error {
|
||||||
last := nav.currDir()
|
last := nav.currDir()
|
||||||
for i := last.ind - 1; i >= 0; i-- {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -672,8 +703,8 @@ func (nav *nav) searchPrev() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if gOpts.wrapscan {
|
if gOpts.wrapscan {
|
||||||
for i := len(last.fi) - 1; i > last.ind; i-- {
|
for i := len(last.files) - 1; 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -693,10 +724,10 @@ func (nav *nav) currDir() *dir {
|
|||||||
func (nav *nav) currFile() (*file, error) {
|
func (nav *nav) currFile() (*file, error) {
|
||||||
last := nav.dirs[len(nav.dirs)-1]
|
last := nav.dirs[len(nav.dirs)-1]
|
||||||
|
|
||||||
if len(last.fi) == 0 {
|
if len(last.files) == 0 {
|
||||||
return nil, fmt.Errorf("empty directory")
|
return nil, fmt.Errorf("empty directory")
|
||||||
}
|
}
|
||||||
return last.fi[last.ind], nil
|
return last.files[last.ind], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type indexedMarks struct {
|
type indexedMarks struct {
|
||||||
|
|||||||
@@ -2,16 +2,37 @@ package main
|
|||||||
|
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
|
type sortMethod byte
|
||||||
|
|
||||||
|
const (
|
||||||
|
naturalSort sortMethod = iota
|
||||||
|
nameSort
|
||||||
|
sizeSort
|
||||||
|
timeSort
|
||||||
|
)
|
||||||
|
|
||||||
|
type sortOption byte
|
||||||
|
|
||||||
|
const (
|
||||||
|
dirfirstSort sortOption = 1 << iota
|
||||||
|
hiddenSort
|
||||||
|
reverseSort
|
||||||
|
)
|
||||||
|
|
||||||
|
type sortType struct {
|
||||||
|
method sortMethod
|
||||||
|
option sortOption
|
||||||
|
}
|
||||||
|
|
||||||
var gOpts struct {
|
var gOpts struct {
|
||||||
dircounts bool
|
dircounts bool
|
||||||
dirfirst bool
|
drawbox bool
|
||||||
globsearch bool
|
globsearch bool
|
||||||
hidden bool
|
|
||||||
ignorecase bool
|
ignorecase bool
|
||||||
preview bool
|
preview bool
|
||||||
reverse bool
|
|
||||||
smartcase bool
|
smartcase bool
|
||||||
wrapscan bool
|
wrapscan bool
|
||||||
|
period int
|
||||||
scrolloff int
|
scrolloff int
|
||||||
tabstop int
|
tabstop int
|
||||||
filesep string
|
filesep string
|
||||||
@@ -19,71 +40,71 @@ var gOpts struct {
|
|||||||
previewer string
|
previewer string
|
||||||
promptfmt string
|
promptfmt string
|
||||||
shell string
|
shell string
|
||||||
sortby string
|
|
||||||
timefmt string
|
timefmt string
|
||||||
ratios []int
|
ratios []int
|
||||||
info []string
|
info []string
|
||||||
keys map[string]expr
|
keys map[string]expr
|
||||||
cmdkeys map[string]expr
|
cmdkeys map[string]expr
|
||||||
cmds map[string]expr
|
cmds map[string]expr
|
||||||
|
sortType sortType
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
gOpts.dircounts = false
|
gOpts.dircounts = false
|
||||||
gOpts.dirfirst = true
|
gOpts.drawbox = false
|
||||||
gOpts.globsearch = false
|
gOpts.globsearch = false
|
||||||
gOpts.hidden = false
|
|
||||||
gOpts.ignorecase = true
|
gOpts.ignorecase = true
|
||||||
gOpts.preview = true
|
gOpts.preview = true
|
||||||
gOpts.reverse = false
|
|
||||||
gOpts.smartcase = true
|
gOpts.smartcase = true
|
||||||
gOpts.wrapscan = true
|
gOpts.wrapscan = true
|
||||||
|
gOpts.period = 0
|
||||||
gOpts.scrolloff = 0
|
gOpts.scrolloff = 0
|
||||||
gOpts.tabstop = 8
|
gOpts.tabstop = 8
|
||||||
gOpts.filesep = "\n"
|
gOpts.filesep = "\n"
|
||||||
gOpts.promptfmt = "\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f\033[0m"
|
gOpts.promptfmt = "\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f\033[0m"
|
||||||
gOpts.shell = gDefaultShell
|
gOpts.shell = gDefaultShell
|
||||||
gOpts.sortby = "natural"
|
|
||||||
gOpts.timefmt = time.ANSIC
|
gOpts.timefmt = time.ANSIC
|
||||||
gOpts.ratios = []int{1, 2, 3}
|
gOpts.ratios = []int{1, 2, 3}
|
||||||
gOpts.info = nil
|
gOpts.info = nil
|
||||||
|
gOpts.sortType = sortType{naturalSort, dirfirstSort}
|
||||||
|
|
||||||
gOpts.keys = make(map[string]expr)
|
gOpts.keys = make(map[string]expr)
|
||||||
|
|
||||||
gOpts.keys["k"] = &callExpr{"up", nil}
|
gOpts.keys["k"] = &callExpr{"up", nil, 1}
|
||||||
gOpts.keys["<up>"] = &callExpr{"up", nil}
|
gOpts.keys["<up>"] = &callExpr{"up", nil, 1}
|
||||||
gOpts.keys["<c-u>"] = &callExpr{"half-up", nil}
|
gOpts.keys["<c-u>"] = &callExpr{"half-up", nil, 1}
|
||||||
gOpts.keys["<c-b>"] = &callExpr{"page-up", nil}
|
gOpts.keys["<c-b>"] = &callExpr{"page-up", nil, 1}
|
||||||
gOpts.keys["j"] = &callExpr{"down", nil}
|
gOpts.keys["j"] = &callExpr{"down", nil, 1}
|
||||||
gOpts.keys["<down>"] = &callExpr{"down", nil}
|
gOpts.keys["<down>"] = &callExpr{"down", nil, 1}
|
||||||
gOpts.keys["<c-d>"] = &callExpr{"half-down", nil}
|
gOpts.keys["<c-d>"] = &callExpr{"half-down", nil, 1}
|
||||||
gOpts.keys["<c-f>"] = &callExpr{"page-down", nil}
|
gOpts.keys["<c-f>"] = &callExpr{"page-down", nil, 1}
|
||||||
gOpts.keys["h"] = &callExpr{"updir", nil}
|
gOpts.keys["h"] = &callExpr{"updir", nil, 1}
|
||||||
gOpts.keys["<left>"] = &callExpr{"updir", nil}
|
gOpts.keys["<left>"] = &callExpr{"updir", nil, 1}
|
||||||
gOpts.keys["l"] = &callExpr{"open", nil}
|
gOpts.keys["l"] = &callExpr{"open", nil, 1}
|
||||||
gOpts.keys["<right>"] = &callExpr{"open", nil}
|
gOpts.keys["<right>"] = &callExpr{"open", nil, 1}
|
||||||
gOpts.keys["q"] = &callExpr{"quit", nil}
|
gOpts.keys["q"] = &callExpr{"quit", nil, 1}
|
||||||
gOpts.keys["gg"] = &callExpr{"top", nil}
|
gOpts.keys["gg"] = &callExpr{"top", nil, 1}
|
||||||
gOpts.keys["G"] = &callExpr{"bot", nil}
|
gOpts.keys["G"] = &callExpr{"bottom", nil, 1}
|
||||||
gOpts.keys["<space>"] = &callExpr{"toggle", nil}
|
gOpts.keys["<space>"] = &callExpr{"toggle", nil, 1}
|
||||||
gOpts.keys["v"] = &callExpr{"invert", nil}
|
gOpts.keys["v"] = &callExpr{"invert", nil, 1}
|
||||||
gOpts.keys["u"] = &callExpr{"unmark", nil}
|
gOpts.keys["u"] = &callExpr{"unmark", nil, 1}
|
||||||
gOpts.keys["y"] = &callExpr{"yank", nil}
|
gOpts.keys["y"] = &callExpr{"yank", nil, 1}
|
||||||
gOpts.keys["d"] = &callExpr{"delete", nil}
|
gOpts.keys["d"] = &callExpr{"delete", nil, 1}
|
||||||
gOpts.keys["c"] = &callExpr{"clear", nil}
|
gOpts.keys["c"] = &callExpr{"clear", nil, 1}
|
||||||
gOpts.keys["p"] = &callExpr{"put", nil}
|
gOpts.keys["p"] = &callExpr{"put", nil, 1}
|
||||||
gOpts.keys["<c-l>"] = &callExpr{"redraw", nil}
|
gOpts.keys["<c-l>"] = &callExpr{"redraw", nil, 1}
|
||||||
gOpts.keys["<c-r>"] = &callExpr{"reload", nil}
|
gOpts.keys["<c-r>"] = &callExpr{"reload", nil, 1}
|
||||||
gOpts.keys[":"] = &callExpr{"read", nil}
|
gOpts.keys[":"] = &callExpr{"read", nil, 1}
|
||||||
gOpts.keys["$"] = &callExpr{"read-shell", nil}
|
gOpts.keys["$"] = &callExpr{"shell", nil, 1}
|
||||||
gOpts.keys["!"] = &callExpr{"read-shell-wait", nil}
|
gOpts.keys["%"] = &callExpr{"shell-pipe", nil, 1}
|
||||||
gOpts.keys["&"] = &callExpr{"read-shell-async", nil}
|
gOpts.keys["!"] = &callExpr{"shell-wait", nil, 1}
|
||||||
gOpts.keys["/"] = &callExpr{"search", nil}
|
gOpts.keys["&"] = &callExpr{"shell-async", nil, 1}
|
||||||
gOpts.keys["?"] = &callExpr{"search-back", nil}
|
gOpts.keys["/"] = &callExpr{"search", nil, 1}
|
||||||
gOpts.keys["n"] = &callExpr{"search-next", nil}
|
gOpts.keys["?"] = &callExpr{"search-back", nil, 1}
|
||||||
gOpts.keys["N"] = &callExpr{"search-prev", nil}
|
gOpts.keys["n"] = &callExpr{"search-next", nil, 1}
|
||||||
gOpts.keys["<c-n>"] = &callExpr{"cmd-hist-next", nil}
|
gOpts.keys["N"] = &callExpr{"search-prev", nil, 1}
|
||||||
gOpts.keys["<c-p>"] = &callExpr{"cmd-hist-prev", nil}
|
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["zh"] = &setExpr{"hidden!", ""}
|
||||||
gOpts.keys["zr"] = &setExpr{"reverse!", ""}
|
gOpts.keys["zr"] = &setExpr{"reverse!", ""}
|
||||||
@@ -94,35 +115,42 @@ func init() {
|
|||||||
gOpts.keys["sn"] = &listExpr{[]expr{&setExpr{"sortby", "natural"}, &setExpr{"info", ""}}}
|
gOpts.keys["sn"] = &listExpr{[]expr{&setExpr{"sortby", "natural"}, &setExpr{"info", ""}}}
|
||||||
gOpts.keys["ss"] = &listExpr{[]expr{&setExpr{"sortby", "size"}, &setExpr{"info", "size"}}}
|
gOpts.keys["ss"] = &listExpr{[]expr{&setExpr{"sortby", "size"}, &setExpr{"info", "size"}}}
|
||||||
gOpts.keys["st"] = &listExpr{[]expr{&setExpr{"sortby", "time"}, &setExpr{"info", "time"}}}
|
gOpts.keys["st"] = &listExpr{[]expr{&setExpr{"sortby", "time"}, &setExpr{"info", "time"}}}
|
||||||
gOpts.keys["gh"] = &callExpr{"cd", []string{"~"}}
|
gOpts.keys["gh"] = &callExpr{"cd", []string{"~"}, 1}
|
||||||
|
|
||||||
gOpts.cmdkeys = make(map[string]expr)
|
gOpts.cmdkeys = make(map[string]expr)
|
||||||
|
|
||||||
// TODO: rest of the keys
|
gOpts.cmdkeys["<space>"] = &callExpr{"cmd-insert", []string{" "}, 1}
|
||||||
gOpts.cmdkeys["<space>"] = &callExpr{"cmd-insert", []string{" "}}
|
gOpts.cmdkeys["<esc>"] = &callExpr{"cmd-escape", nil, 1}
|
||||||
gOpts.cmdkeys["<esc>"] = &callExpr{"cmd-escape", nil}
|
gOpts.cmdkeys["<tab>"] = &callExpr{"cmd-complete", nil, 1}
|
||||||
gOpts.cmdkeys["<tab>"] = &callExpr{"cmd-comp", nil}
|
gOpts.cmdkeys["<enter>"] = &callExpr{"cmd-enter", nil, 1}
|
||||||
gOpts.cmdkeys["<enter>"] = &callExpr{"cmd-enter", nil}
|
gOpts.cmdkeys["<c-j>"] = &callExpr{"cmd-enter", nil, 1}
|
||||||
gOpts.cmdkeys["<c-j>"] = &callExpr{"cmd-enter", nil}
|
gOpts.cmdkeys["<c-n>"] = &callExpr{"cmd-history-next", nil, 1}
|
||||||
gOpts.cmdkeys["<c-n>"] = &callExpr{"cmd-hist-next", nil}
|
gOpts.cmdkeys["<c-p>"] = &callExpr{"cmd-history-prev", nil, 1}
|
||||||
gOpts.cmdkeys["<c-p>"] = &callExpr{"cmd-hist-prev", nil}
|
gOpts.cmdkeys["<delete>"] = &callExpr{"cmd-delete", nil, 1}
|
||||||
gOpts.cmdkeys["<delete>"] = &callExpr{"cmd-delete", nil}
|
gOpts.cmdkeys["<c-d>"] = &callExpr{"cmd-delete", nil, 1}
|
||||||
gOpts.cmdkeys["<c-d>"] = &callExpr{"cmd-delete", nil}
|
gOpts.cmdkeys["<bs>"] = &callExpr{"cmd-delete-back", nil, 1}
|
||||||
gOpts.cmdkeys["<bs>"] = &callExpr{"cmd-delete-back", nil}
|
gOpts.cmdkeys["<bs2>"] = &callExpr{"cmd-delete-back", nil, 1}
|
||||||
gOpts.cmdkeys["<bs2>"] = &callExpr{"cmd-delete-back", nil}
|
gOpts.cmdkeys["<left>"] = &callExpr{"cmd-left", nil, 1}
|
||||||
gOpts.cmdkeys["<left>"] = &callExpr{"cmd-left", nil}
|
gOpts.cmdkeys["<c-b>"] = &callExpr{"cmd-left", nil, 1}
|
||||||
gOpts.cmdkeys["<c-b>"] = &callExpr{"cmd-left", nil}
|
gOpts.cmdkeys["<right>"] = &callExpr{"cmd-right", nil, 1}
|
||||||
gOpts.cmdkeys["<right>"] = &callExpr{"cmd-right", nil}
|
gOpts.cmdkeys["<c-f>"] = &callExpr{"cmd-right", nil, 1}
|
||||||
gOpts.cmdkeys["<c-f>"] = &callExpr{"cmd-right", nil}
|
gOpts.cmdkeys["<home>"] = &callExpr{"cmd-home", nil, 1}
|
||||||
gOpts.cmdkeys["<home>"] = &callExpr{"cmd-beg", nil}
|
gOpts.cmdkeys["<c-a>"] = &callExpr{"cmd-home", nil, 1}
|
||||||
gOpts.cmdkeys["<c-a>"] = &callExpr{"cmd-beg", nil}
|
gOpts.cmdkeys["<end>"] = &callExpr{"cmd-end", nil, 1}
|
||||||
gOpts.cmdkeys["<end>"] = &callExpr{"cmd-end", nil}
|
gOpts.cmdkeys["<c-e>"] = &callExpr{"cmd-end", nil, 1}
|
||||||
gOpts.cmdkeys["<c-e>"] = &callExpr{"cmd-end", nil}
|
gOpts.cmdkeys["<c-u>"] = &callExpr{"cmd-delete-home", nil, 1}
|
||||||
gOpts.cmdkeys["<c-u>"] = &callExpr{"cmd-delete-beg", nil}
|
gOpts.cmdkeys["<c-k>"] = &callExpr{"cmd-delete-end", nil, 1}
|
||||||
gOpts.cmdkeys["<c-k>"] = &callExpr{"cmd-delete-end", nil}
|
gOpts.cmdkeys["<c-w>"] = &callExpr{"cmd-delete-unix-word", nil, 1}
|
||||||
gOpts.cmdkeys["<c-w>"] = &callExpr{"cmd-delete-word", nil}
|
gOpts.cmdkeys["<c-y>"] = &callExpr{"cmd-yank", nil, 1}
|
||||||
gOpts.cmdkeys["<c-y>"] = &callExpr{"cmd-put", nil}
|
gOpts.cmdkeys["<c-t>"] = &callExpr{"cmd-transpose", nil, 1}
|
||||||
gOpts.cmdkeys["<c-t>"] = &callExpr{"cmd-transpose", nil}
|
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)
|
gOpts.cmds = make(map[string]expr)
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func pauseCommand() *exec.Cmd {
|
func pauseCommand() *exec.Cmd {
|
||||||
c := `echo
|
cmd := `echo
|
||||||
echo -n 'Press any key to continue'
|
echo -n 'Press any key to continue'
|
||||||
old=$(stty -g)
|
old=$(stty -g)
|
||||||
stty raw -echo
|
stty raw -echo
|
||||||
@@ -55,7 +55,7 @@ func pauseCommand() *exec.Cmd {
|
|||||||
stty $old
|
stty $old
|
||||||
echo`
|
echo`
|
||||||
|
|
||||||
return exec.Command(gOpts.shell, "-c", c)
|
return exec.Command(gOpts.shell, "-c", cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func shellCommand(s string, args []string) *exec.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
|
// 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,
|
// response is not affirmative. Since this command is run with a nil
|
||||||
// it should not give an affirmative answer and in return this command
|
// stdin, it should not give an affirmative answer and in return this
|
||||||
// should not overwrite existing files. Our intention here is to use the
|
// command should not overwrite existing files. Our intention here is
|
||||||
// standard -i flag in place of non-standard -n flag to avoid overwrites.
|
// to use the standard -i flag in place of non-standard -n flag to
|
||||||
|
// avoid overwrites.
|
||||||
args = append(args, "-i")
|
args = append(args, "-i")
|
||||||
|
|
||||||
args = append(args, list...)
|
args = append(args, list...)
|
||||||
|
|||||||
+3
-3
@@ -70,10 +70,10 @@ func putCommand(list []string, dir *dir, copy bool) *exec.Cmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func setDefaults() {
|
func setDefaults() {
|
||||||
gOpts.keys["e"] = &execExpr{"$", `notepad "%f%"`}
|
gOpts.keys["e"] = &execExpr{"$", `notepad %f%`}
|
||||||
gOpts.keys["i"] = &execExpr{"$", `more "%f%"`}
|
gOpts.keys["i"] = &execExpr{"$", `more %f%`}
|
||||||
gOpts.keys["w"] = &execExpr{"$", "cmd"}
|
gOpts.keys["w"] = &execExpr{"$", "cmd"}
|
||||||
gOpts.cmds["open-file"] = &execExpr{"&", `start "" "%f%"`}
|
gOpts.cmds["open-file"] = &execExpr{"&", `start %f%`}
|
||||||
}
|
}
|
||||||
|
|
||||||
func moveCursor(y, x int) {
|
func moveCursor(y, x int) {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ package main
|
|||||||
// ExecExpr = Prefix <value> '\n'
|
// ExecExpr = Prefix <value> '\n'
|
||||||
// | Prefix '{{' <value> '}}' ';'
|
// | Prefix '{{' <value> '}}' ';'
|
||||||
//
|
//
|
||||||
// Prefix = '$' | '!' | '&' | '/' | '?'
|
// Prefix = '$' | '%' | '!' | '&'
|
||||||
//
|
//
|
||||||
// ListExpr = ':' Expr ListRest '\n'
|
// ListExpr = ':' Expr ListRest '\n'
|
||||||
// | ':' '{{' Expr ListRest '}}' ';'
|
// | ':' '{{' Expr ListRest '}}' ';'
|
||||||
@@ -74,6 +74,7 @@ func (e *cmdExpr) String() string { return fmt.Sprintf("cmd %s %s", e.name, e.ex
|
|||||||
type callExpr struct {
|
type callExpr struct {
|
||||||
name string
|
name string
|
||||||
args []string
|
args []string
|
||||||
|
count int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *callExpr) String() string { return fmt.Sprintf("%s -- %s", e.name, e.args) }
|
func (e *callExpr) String() string { return fmt.Sprintf("%s -- %s", e.name, e.args) }
|
||||||
@@ -230,7 +231,7 @@ func (p *parser) parseExpr() expr {
|
|||||||
|
|
||||||
s.scan()
|
s.scan()
|
||||||
|
|
||||||
result = &callExpr{name, args}
|
result = &callExpr{name, args, 1}
|
||||||
}
|
}
|
||||||
case tokenColon:
|
case tokenColon:
|
||||||
s.scan()
|
s.scan()
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ const (
|
|||||||
// no explicit keyword type
|
// no explicit keyword type
|
||||||
tokenIdent // e.g. set, ratios, 1:2:3
|
tokenIdent // e.g. set, ratios, 1:2:3
|
||||||
tokenColon // :
|
tokenColon // :
|
||||||
tokenPrefix // $, !, &, / or ?
|
tokenPrefix // $, %, !, &
|
||||||
tokenLBraces // {{
|
tokenLBraces // {{
|
||||||
tokenRBraces // }}
|
tokenRBraces // }}
|
||||||
tokenCommand // in between a prefix to \n or between {{ and }}
|
tokenCommand // in between a prefix to \n or between {{ and }}
|
||||||
@@ -90,8 +90,7 @@ func isDigit(b byte) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func isPrefix(b byte) bool {
|
func isPrefix(b byte) bool {
|
||||||
// TODO: how to differentiate slash in path vs search?
|
return b == '$' || b == '%' || b == '!' || b == '&'
|
||||||
return b == '$' || b == '!' || b == '&' // || b == '/' || b == '?'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *scanner) scan() bool {
|
func (s *scanner) scan() bool {
|
||||||
|
|||||||
@@ -16,12 +16,12 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func serve() {
|
func serve() {
|
||||||
logFile, err := os.Create(gServerLogPath)
|
f, err := os.Create(gServerLogPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
defer logFile.Close()
|
defer f.Close()
|
||||||
log.SetOutput(logFile)
|
log.SetOutput(f)
|
||||||
|
|
||||||
log.Print("hi!")
|
log.Print("hi!")
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
"time"
|
||||||
"unicode"
|
"unicode"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
@@ -18,91 +19,65 @@ import (
|
|||||||
"github.com/nsf/termbox-go"
|
"github.com/nsf/termbox-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const gEscapeCode = 27
|
||||||
gEscapeCode = 27
|
|
||||||
gAnsiColorResetMask = termbox.AttrBold | termbox.AttrUnderline | termbox.AttrReverse
|
|
||||||
)
|
|
||||||
|
|
||||||
var gAnsiCodes = map[int]termbox.Attribute{
|
var gKeyVal = map[termbox.Key]string{
|
||||||
0: termbox.ColorDefault,
|
termbox.KeyF1: "<f-1>",
|
||||||
1: termbox.AttrBold,
|
termbox.KeyF2: "<f-2>",
|
||||||
4: termbox.AttrUnderline,
|
termbox.KeyF3: "<f-3>",
|
||||||
7: termbox.AttrReverse,
|
termbox.KeyF4: "<f-4>",
|
||||||
30: termbox.ColorBlack,
|
termbox.KeyF5: "<f-5>",
|
||||||
31: termbox.ColorRed,
|
termbox.KeyF6: "<f-6>",
|
||||||
32: termbox.ColorGreen,
|
termbox.KeyF7: "<f-7>",
|
||||||
33: termbox.ColorYellow,
|
termbox.KeyF8: "<f-8>",
|
||||||
34: termbox.ColorBlue,
|
termbox.KeyF9: "<f-9>",
|
||||||
35: termbox.ColorMagenta,
|
termbox.KeyF10: "<f-10>",
|
||||||
36: termbox.ColorCyan,
|
termbox.KeyF11: "<f-11>",
|
||||||
37: termbox.ColorWhite,
|
termbox.KeyF12: "<f-12>",
|
||||||
40: termbox.ColorBlack,
|
termbox.KeyInsert: "<insert>",
|
||||||
41: termbox.ColorRed,
|
termbox.KeyDelete: "<delete>",
|
||||||
42: termbox.ColorGreen,
|
termbox.KeyHome: "<home>",
|
||||||
43: termbox.ColorYellow,
|
termbox.KeyEnd: "<end>",
|
||||||
44: termbox.ColorBlue,
|
termbox.KeyPgup: "<pgup>",
|
||||||
45: termbox.ColorMagenta,
|
termbox.KeyPgdn: "<pgdn>",
|
||||||
46: termbox.ColorCyan,
|
termbox.KeyArrowUp: "<up>",
|
||||||
47: termbox.ColorWhite,
|
termbox.KeyArrowDown: "<down>",
|
||||||
}
|
termbox.KeyArrowLeft: "<left>",
|
||||||
|
termbox.KeyArrowRight: "<right>",
|
||||||
var gKeyVal = map[termbox.Key][]rune{
|
termbox.KeyCtrlSpace: "<c-space>",
|
||||||
termbox.KeyF1: {'<', 'f', '-', '1', '>'},
|
termbox.KeyCtrlA: "<c-a>",
|
||||||
termbox.KeyF2: {'<', 'f', '-', '2', '>'},
|
termbox.KeyCtrlB: "<c-b>",
|
||||||
termbox.KeyF3: {'<', 'f', '-', '3', '>'},
|
termbox.KeyCtrlC: "<c-c>",
|
||||||
termbox.KeyF4: {'<', 'f', '-', '4', '>'},
|
termbox.KeyCtrlD: "<c-d>",
|
||||||
termbox.KeyF5: {'<', 'f', '-', '5', '>'},
|
termbox.KeyCtrlE: "<c-e>",
|
||||||
termbox.KeyF6: {'<', 'f', '-', '6', '>'},
|
termbox.KeyCtrlF: "<c-f>",
|
||||||
termbox.KeyF7: {'<', 'f', '-', '7', '>'},
|
termbox.KeyCtrlG: "<c-g>",
|
||||||
termbox.KeyF8: {'<', 'f', '-', '8', '>'},
|
termbox.KeyBackspace: "<bs>",
|
||||||
termbox.KeyF9: {'<', 'f', '-', '9', '>'},
|
termbox.KeyTab: "<tab>",
|
||||||
termbox.KeyF10: {'<', 'f', '-', '1', '0', '>'},
|
termbox.KeyCtrlJ: "<c-j>",
|
||||||
termbox.KeyF11: {'<', 'f', '-', '1', '1', '>'},
|
termbox.KeyCtrlK: "<c-k>",
|
||||||
termbox.KeyF12: {'<', 'f', '-', '1', '2', '>'},
|
termbox.KeyCtrlL: "<c-l>",
|
||||||
termbox.KeyInsert: {'<', 'i', 'n', 's', 'e', 'r', 't', '>'},
|
termbox.KeyEnter: "<enter>",
|
||||||
termbox.KeyDelete: {'<', 'd', 'e', 'l', 'e', 't', 'e', '>'},
|
termbox.KeyCtrlN: "<c-n>",
|
||||||
termbox.KeyHome: {'<', 'h', 'o', 'm', 'e', '>'},
|
termbox.KeyCtrlO: "<c-o>",
|
||||||
termbox.KeyEnd: {'<', 'e', 'n', 'd', '>'},
|
termbox.KeyCtrlP: "<c-p>",
|
||||||
termbox.KeyPgup: {'<', 'p', 'g', 'u', 'p', '>'},
|
termbox.KeyCtrlQ: "<c-q>",
|
||||||
termbox.KeyPgdn: {'<', 'p', 'g', 'd', 'n', '>'},
|
termbox.KeyCtrlR: "<c-r>",
|
||||||
termbox.KeyArrowUp: {'<', 'u', 'p', '>'},
|
termbox.KeyCtrlS: "<c-s>",
|
||||||
termbox.KeyArrowDown: {'<', 'd', 'o', 'w', 'n', '>'},
|
termbox.KeyCtrlT: "<c-t>",
|
||||||
termbox.KeyArrowLeft: {'<', 'l', 'e', 'f', 't', '>'},
|
termbox.KeyCtrlU: "<c-u>",
|
||||||
termbox.KeyArrowRight: {'<', 'r', 'i', 'g', 'h', 't', '>'},
|
termbox.KeyCtrlV: "<c-v>",
|
||||||
termbox.KeyCtrlSpace: {'<', 'c', '-', 's', 'p', 'a', 'c', 'e', '>'},
|
termbox.KeyCtrlW: "<c-w>",
|
||||||
termbox.KeyCtrlA: {'<', 'c', '-', 'a', '>'},
|
termbox.KeyCtrlX: "<c-x>",
|
||||||
termbox.KeyCtrlB: {'<', 'c', '-', 'b', '>'},
|
termbox.KeyCtrlY: "<c-y>",
|
||||||
termbox.KeyCtrlC: {'<', 'c', '-', 'c', '>'},
|
termbox.KeyCtrlZ: "<c-z>",
|
||||||
termbox.KeyCtrlD: {'<', 'c', '-', 'd', '>'},
|
termbox.KeyEsc: "<esc>",
|
||||||
termbox.KeyCtrlE: {'<', 'c', '-', 'e', '>'},
|
termbox.KeyCtrlBackslash: "<c-\\>",
|
||||||
termbox.KeyCtrlF: {'<', 'c', '-', 'f', '>'},
|
termbox.KeyCtrlRsqBracket: "<c-]>",
|
||||||
termbox.KeyCtrlG: {'<', 'c', '-', 'g', '>'},
|
termbox.KeyCtrl6: "<c-6>",
|
||||||
termbox.KeyBackspace: {'<', 'b', 's', '>'},
|
termbox.KeyCtrlSlash: "<c-/>",
|
||||||
termbox.KeyTab: {'<', 't', 'a', 'b', '>'},
|
termbox.KeySpace: "<space>",
|
||||||
termbox.KeyCtrlJ: {'<', 'c', '-', 'j', '>'},
|
termbox.KeyBackspace2: "<bs2>",
|
||||||
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 gValKey map[string]termbox.Key
|
var gValKey map[string]termbox.Key
|
||||||
@@ -110,7 +85,7 @@ var gValKey map[string]termbox.Key
|
|||||||
func init() {
|
func init() {
|
||||||
gValKey = make(map[string]termbox.Key)
|
gValKey = make(map[string]termbox.Key)
|
||||||
for k, v := range gKeyVal {
|
for k, v := range gKeyVal {
|
||||||
gValKey[string(v)] = k
|
gValKey[v] = k
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,60 +101,6 @@ func (win *win) renew(w, h, x, y int) {
|
|||||||
win.w, win.h, win.x, win.y = w, h, x, y
|
win.w, win.h, win.x, win.y = w, h, x, y
|
||||||
}
|
}
|
||||||
|
|
||||||
func applyAnsiCodes(s string, fg, bg termbox.Attribute) (termbox.Attribute, termbox.Attribute) {
|
|
||||||
toks := strings.Split(s, ";")
|
|
||||||
|
|
||||||
var nums []int
|
|
||||||
for _, t := range toks {
|
|
||||||
if t == "" {
|
|
||||||
fg = termbox.ColorDefault
|
|
||||||
bg = termbox.ColorDefault
|
|
||||||
break
|
|
||||||
}
|
|
||||||
n, err := strconv.Atoi(t)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("converting escape code: %s", err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
nums = append(nums, n)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse 256 color terminal ansi codes
|
|
||||||
// termbox-go has a color offset of one, because of attributes
|
|
||||||
if len(nums) == 3 {
|
|
||||||
if nums[0] == 48 && nums[1] == 5 {
|
|
||||||
bg = termbox.Attribute(nums[2])
|
|
||||||
bg++
|
|
||||||
}
|
|
||||||
if nums[0] == 38 && nums[1] == 5 {
|
|
||||||
fg = termbox.Attribute(nums[2])
|
|
||||||
fg++
|
|
||||||
}
|
|
||||||
return fg, bg
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, n := range nums {
|
|
||||||
attr, ok := gAnsiCodes[n]
|
|
||||||
if !ok {
|
|
||||||
log.Printf("unknown ansi code: %d", n)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
switch {
|
|
||||||
case n == 0:
|
|
||||||
fg, bg = attr, attr
|
|
||||||
case n == 1 || n == 4 || n == 7:
|
|
||||||
fg |= attr
|
|
||||||
case 30 <= n && n <= 37:
|
|
||||||
fg &= gAnsiColorResetMask
|
|
||||||
fg |= attr
|
|
||||||
case 40 <= n && n <= 47:
|
|
||||||
bg = attr
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return fg, bg
|
|
||||||
}
|
|
||||||
|
|
||||||
func printLength(s string) int {
|
func printLength(s string) int {
|
||||||
ind := 0
|
ind := 0
|
||||||
off := 0
|
off := 0
|
||||||
@@ -260,6 +181,12 @@ func (win *win) printReg(reg *reg) {
|
|||||||
|
|
||||||
fg, bg := termbox.ColorDefault, termbox.ColorDefault
|
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 {
|
for i, l := range reg.lines {
|
||||||
fg, bg = win.print(2, i, fg, bg, l)
|
fg, bg = win.print(2, i, fg, bg, l)
|
||||||
}
|
}
|
||||||
@@ -267,12 +194,55 @@ func (win *win) printReg(reg *reg) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (win *win) printDir(dir *dir, marks map[string]int, saves map[string]bool) {
|
func fileInfo(f *file, d *dir) string {
|
||||||
if win.w < 3 {
|
var info string
|
||||||
return
|
|
||||||
|
path := filepath.Join(d.path, f.Name())
|
||||||
|
|
||||||
|
for _, s := range gOpts.info {
|
||||||
|
switch s {
|
||||||
|
case "size":
|
||||||
|
if !(gOpts.dircounts && f.IsDir()) {
|
||||||
|
info = fmt.Sprintf("%s %4s", info, humanize(f.Size()))
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if dir == nil {
|
if f.dirCount == -1 {
|
||||||
|
d, err := os.Open(path)
|
||||||
|
if err != nil {
|
||||||
|
f.dirCount = -2
|
||||||
|
}
|
||||||
|
|
||||||
|
names, err := d.Readdirnames(1000)
|
||||||
|
d.Close()
|
||||||
|
|
||||||
|
if names == nil && err != io.EOF {
|
||||||
|
f.dirCount = -2
|
||||||
|
} else {
|
||||||
|
f.dirCount = len(names)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case f.dirCount < 0:
|
||||||
|
info = fmt.Sprintf("%s ?", info)
|
||||||
|
case f.dirCount < 1000:
|
||||||
|
info = fmt.Sprintf("%s %4d", info, f.dirCount)
|
||||||
|
default:
|
||||||
|
info = fmt.Sprintf("%s 999+", info)
|
||||||
|
}
|
||||||
|
case "time":
|
||||||
|
info = fmt.Sprintf("%s %12s", info, f.ModTime().Format("Jan _2 15:04"))
|
||||||
|
default:
|
||||||
|
log.Printf("unknown info type: %s", s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return info
|
||||||
|
}
|
||||||
|
|
||||||
|
func (win *win) printDir(dir *dir, marks map[string]int, saves map[string]bool, colors colorMap) {
|
||||||
|
if win.w < 5 || dir == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -284,42 +254,22 @@ func (win *win) printDir(dir *dir, marks map[string]int, saves map[string]bool)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(dir.fi) == 0 {
|
if len(dir.files) == 0 {
|
||||||
fg = termbox.AttrBold
|
fg = termbox.AttrBold
|
||||||
win.print(2, 0, fg, bg, "empty")
|
win.print(2, 0, fg, bg, "empty")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
maxind := len(dir.fi) - 1
|
|
||||||
|
|
||||||
beg := max(dir.ind-dir.pos, 0)
|
beg := max(dir.ind-dir.pos, 0)
|
||||||
end := min(beg+win.h, maxind+1)
|
end := min(beg+win.h, len(dir.files))
|
||||||
|
|
||||||
for i, f := range dir.fi[beg:end] {
|
if beg > end {
|
||||||
switch {
|
return
|
||||||
case f.linkState == working:
|
|
||||||
fg = termbox.ColorCyan
|
|
||||||
if f.Mode().IsDir() {
|
|
||||||
fg |= termbox.AttrBold
|
|
||||||
}
|
|
||||||
case f.linkState == broken:
|
|
||||||
fg = termbox.ColorMagenta
|
|
||||||
case f.Mode().IsRegular():
|
|
||||||
if f.Mode()&0111 != 0 {
|
|
||||||
fg = termbox.AttrBold | termbox.ColorGreen
|
|
||||||
} else {
|
|
||||||
fg = termbox.ColorDefault
|
|
||||||
}
|
|
||||||
case f.Mode().IsDir():
|
|
||||||
fg = termbox.AttrBold | termbox.ColorBlue
|
|
||||||
case f.Mode()&os.ModeNamedPipe != 0:
|
|
||||||
fg = termbox.ColorRed
|
|
||||||
case f.Mode()&os.ModeSocket != 0:
|
|
||||||
fg = termbox.ColorYellow
|
|
||||||
case f.Mode()&os.ModeDevice != 0:
|
|
||||||
fg = termbox.ColorWhite
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for i, f := range dir.files[beg:end] {
|
||||||
|
fg, bg = colors.get(f)
|
||||||
|
|
||||||
path := filepath.Join(dir.path, f.Name())
|
path := filepath.Join(dir.path, f.Name())
|
||||||
|
|
||||||
if _, ok := marks[path]; ok {
|
if _, ok := marks[path]; ok {
|
||||||
@@ -345,63 +295,31 @@ func (win *win) printDir(dir *dir, marks map[string]int, saves map[string]bool)
|
|||||||
}
|
}
|
||||||
|
|
||||||
w := runeSliceWidth(s)
|
w := runeSliceWidth(s)
|
||||||
if w > win.w-2 {
|
|
||||||
s = runeSliceWidthRange(s, 0, win.w-2)
|
if w > win.w-3 {
|
||||||
|
s = runeSliceWidthRange(s, 0, win.w-4)
|
||||||
|
s = append(s, '~')
|
||||||
} else {
|
} else {
|
||||||
for i := 0; i < win.w-2-w; i++ {
|
for i := 0; i < win.w-3-w; i++ {
|
||||||
s = append(s, ' ')
|
s = append(s, ' ')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var info string
|
info := fileInfo(f, dir)
|
||||||
|
|
||||||
for _, s := range gOpts.info {
|
if len(info) > 0 && win.w-2 > 2*len(info) {
|
||||||
switch s {
|
if win.w-2 > w+len(info) {
|
||||||
case "size":
|
s = runeSliceWidthRange(s, 0, win.w-3-len(info))
|
||||||
if !(gOpts.dircounts && f.IsDir()) {
|
|
||||||
info = fmt.Sprintf("%s %4s", info, humanize(f.Size()))
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if f.count == -1 {
|
|
||||||
d, err := os.Open(path)
|
|
||||||
if err != nil {
|
|
||||||
f.count = -2
|
|
||||||
}
|
|
||||||
|
|
||||||
names, err := d.Readdirnames(1000)
|
|
||||||
d.Close()
|
|
||||||
|
|
||||||
if names == nil && err != io.EOF {
|
|
||||||
f.count = -2
|
|
||||||
} else {
|
} else {
|
||||||
f.count = len(names)
|
s = runeSliceWidthRange(s, 0, win.w-4-len(info))
|
||||||
|
s = append(s, '~')
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
switch {
|
|
||||||
case f.count < 0:
|
|
||||||
info = fmt.Sprintf("%s ?", info)
|
|
||||||
case f.count < 1000:
|
|
||||||
info = fmt.Sprintf("%s %4d", info, f.count)
|
|
||||||
default:
|
|
||||||
info = fmt.Sprintf("%s 999+", info)
|
|
||||||
}
|
|
||||||
case "time":
|
|
||||||
info = fmt.Sprintf("%s %12s", info, f.ModTime().Format("Jan _2 15:04"))
|
|
||||||
default:
|
|
||||||
log.Printf("unknown info type: %s", s)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(info) > 0 && win.w > 2*len(info) {
|
|
||||||
s = runeSliceWidthRange(s, 0, win.w-2-len(info))
|
|
||||||
for _, r := range info {
|
for _, r := range info {
|
||||||
s = append(s, r)
|
s = append(s, r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: add a trailing '~' to the name if cut
|
s = append(s, ' ')
|
||||||
|
|
||||||
win.print(1, i, fg, bg, string(s))
|
win.print(1, i, fg, bg, string(s))
|
||||||
}
|
}
|
||||||
@@ -415,21 +333,23 @@ type ui struct {
|
|||||||
msg string
|
msg string
|
||||||
regPrev *reg
|
regPrev *reg
|
||||||
dirPrev *dir
|
dirPrev *dir
|
||||||
|
exprChan chan expr
|
||||||
keyChan chan string
|
keyChan chan string
|
||||||
evChan chan termbox.Event
|
evChan chan termbox.Event
|
||||||
menuBuf *bytes.Buffer
|
menuBuf *bytes.Buffer
|
||||||
cmdPrefix string
|
cmdPrefix string
|
||||||
cmdAccLeft []rune
|
cmdAccLeft []rune
|
||||||
cmdAccRight []rune
|
cmdAccRight []rune
|
||||||
cmdBuf []rune
|
cmdYankBuf []rune
|
||||||
keyAcc []rune
|
keyAcc []rune
|
||||||
keyCount []rune
|
keyCount []rune
|
||||||
|
colors colorMap
|
||||||
}
|
}
|
||||||
|
|
||||||
func getWidths(wtot int) []int {
|
func getWidths(wtot int) []int {
|
||||||
rsum := 0
|
rsum := 0
|
||||||
for _, rat := range gOpts.ratios {
|
for _, r := range gOpts.ratios {
|
||||||
rsum += rat
|
rsum += r
|
||||||
}
|
}
|
||||||
|
|
||||||
wlen := len(gOpts.ratios)
|
wlen := len(gOpts.ratios)
|
||||||
@@ -442,6 +362,10 @@ func getWidths(wtot int) []int {
|
|||||||
}
|
}
|
||||||
widths[wlen-1] = wtot - wsum
|
widths[wlen-1] = wtot - wsum
|
||||||
|
|
||||||
|
if gOpts.drawbox {
|
||||||
|
widths[wlen-1]--
|
||||||
|
}
|
||||||
|
|
||||||
return widths
|
return widths
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -455,7 +379,11 @@ func getWins() []*win {
|
|||||||
wacc := 0
|
wacc := 0
|
||||||
wlen := len(widths)
|
wlen := len(widths)
|
||||||
for i := 0; i < wlen; i++ {
|
for i := 0; i < wlen; i++ {
|
||||||
|
if gOpts.drawbox {
|
||||||
|
wins = append(wins, newWin(widths[i], htot-4, wacc+1, 2))
|
||||||
|
} else {
|
||||||
wins = append(wins, newWin(widths[i], htot-2, wacc, 1))
|
wins = append(wins, newWin(widths[i], htot-2, wacc, 1))
|
||||||
|
}
|
||||||
wacc += widths[i]
|
wacc += widths[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -465,11 +393,27 @@ func getWins() []*win {
|
|||||||
func newUI() *ui {
|
func newUI() *ui {
|
||||||
wtot, htot := termbox.Size()
|
wtot, htot := termbox.Size()
|
||||||
|
|
||||||
evChan := make(chan termbox.Event)
|
evQueue := make(chan termbox.Event)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
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
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@@ -480,6 +424,7 @@ func newUI() *ui {
|
|||||||
menuWin: newWin(wtot, 1, 0, htot-2),
|
menuWin: newWin(wtot, 1, 0, htot-2),
|
||||||
keyChan: make(chan string, 1000),
|
keyChan: make(chan string, 1000),
|
||||||
evChan: evChan,
|
evChan: evChan,
|
||||||
|
colors: parseColors(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -491,11 +436,26 @@ func (ui *ui) renew() {
|
|||||||
wacc := 0
|
wacc := 0
|
||||||
wlen := len(widths)
|
wlen := len(widths)
|
||||||
for i := 0; i < wlen; i++ {
|
for i := 0; i < wlen; i++ {
|
||||||
|
if gOpts.drawbox {
|
||||||
|
ui.wins[i].renew(widths[i], htot-4, wacc+1, 2)
|
||||||
|
} else {
|
||||||
ui.wins[i].renew(widths[i], htot-2, wacc, 1)
|
ui.wins[i].renew(widths[i], htot-2, wacc, 1)
|
||||||
|
}
|
||||||
wacc += widths[i]
|
wacc += widths[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ui.promptWin.renew(wtot, 1, 0, 0)
|
||||||
ui.msgWin.renew(wtot, 1, 0, htot-1)
|
ui.msgWin.renew(wtot, 1, 0, htot-1)
|
||||||
|
ui.menuWin.renew(wtot, 1, 0, htot-2)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ui *ui) sort() {
|
||||||
|
if ui.dirPrev == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
name := ui.dirPrev.name()
|
||||||
|
ui.dirPrev.sort()
|
||||||
|
ui.dirPrev.find(name, ui.wins[0].h)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ui *ui) print(msg string) {
|
func (ui *ui) print(msg string) {
|
||||||
@@ -508,6 +468,8 @@ func (ui *ui) printf(format string, a ...interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type reg struct {
|
type reg struct {
|
||||||
|
loading bool
|
||||||
|
loadTime time.Time
|
||||||
path string
|
path string
|
||||||
lines []string
|
lines []string
|
||||||
}
|
}
|
||||||
@@ -583,14 +545,46 @@ func (ui *ui) drawStatLine(nav *nav) {
|
|||||||
|
|
||||||
ui.msgWin.print(0, 0, fg, bg, ui.msg)
|
ui.msgWin.print(0, 0, fg, bg, ui.msg)
|
||||||
|
|
||||||
tot := len(currDir.fi)
|
tot := len(currDir.files)
|
||||||
ind := min(currDir.ind+1, tot)
|
ind := min(currDir.ind+1, tot)
|
||||||
|
acc := string(ui.keyCount) + string(ui.keyAcc)
|
||||||
|
|
||||||
ruler := fmt.Sprintf("%d/%d", ind, tot)
|
ruler := fmt.Sprintf("%s %d/%d", acc, ind, tot)
|
||||||
|
|
||||||
ui.msgWin.printRight(0, fg, bg, ruler)
|
ui.msgWin.printRight(0, fg, bg, ruler)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ui *ui) drawBox(nav *nav) {
|
||||||
|
fg, bg := termbox.ColorDefault, termbox.ColorDefault
|
||||||
|
|
||||||
|
w, h := termbox.Size()
|
||||||
|
|
||||||
|
for i := 1; i < w-1; i++ {
|
||||||
|
termbox.SetCell(i, 1, '─', fg, bg)
|
||||||
|
termbox.SetCell(i, h-2, '─', fg, bg)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 2; i < h-2; i++ {
|
||||||
|
termbox.SetCell(0, i, '│', fg, bg)
|
||||||
|
termbox.SetCell(w-1, i, '│', fg, bg)
|
||||||
|
}
|
||||||
|
|
||||||
|
termbox.SetCell(0, 1, '┌', fg, bg)
|
||||||
|
termbox.SetCell(w-1, 1, '┐', fg, bg)
|
||||||
|
termbox.SetCell(0, h-2, '└', fg, bg)
|
||||||
|
termbox.SetCell(w-1, h-2, '┘', fg, bg)
|
||||||
|
|
||||||
|
wacc := 0
|
||||||
|
for wind := 0; wind < len(ui.wins)-1; wind++ {
|
||||||
|
wacc += ui.wins[wind].w
|
||||||
|
termbox.SetCell(wacc, 1, '┬', fg, bg)
|
||||||
|
for i := 2; i < h-2; i++ {
|
||||||
|
termbox.SetCell(wacc, i, '│', fg, bg)
|
||||||
|
}
|
||||||
|
termbox.SetCell(wacc, h-2, '┴', fg, bg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (ui *ui) draw(nav *nav) {
|
func (ui *ui) draw(nav *nav) {
|
||||||
fg, bg := termbox.ColorDefault, termbox.ColorDefault
|
fg, bg := termbox.ColorDefault, termbox.ColorDefault
|
||||||
|
|
||||||
@@ -608,17 +602,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.marks, nav.saves)
|
ui.wins[woff+i].printDir(nav.dirs[doff+i], nav.marks, nav.saves, ui.colors)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ui.cmdPrefix != "" {
|
switch ui.cmdPrefix {
|
||||||
|
case "":
|
||||||
|
ui.drawStatLine(nav)
|
||||||
|
termbox.HideCursor()
|
||||||
|
case ">":
|
||||||
|
ui.msgWin.printLine(0, 0, fg, bg, ui.cmdPrefix)
|
||||||
|
ui.msgWin.print(len(ui.cmdPrefix), 0, fg, bg, ui.msg)
|
||||||
|
ui.msgWin.print(len(ui.cmdPrefix)+len(ui.msg), 0, fg, bg, string(ui.cmdAccLeft))
|
||||||
|
ui.msgWin.print(len(ui.cmdPrefix)+len(ui.msg)+runeSliceWidth(ui.cmdAccLeft), 0, fg, bg, string(ui.cmdAccRight))
|
||||||
|
termbox.SetCursor(ui.msgWin.x+len(ui.cmdPrefix)+len(ui.msg)+runeSliceWidth(ui.cmdAccLeft), ui.msgWin.y)
|
||||||
|
default:
|
||||||
ui.msgWin.printLine(0, 0, fg, bg, ui.cmdPrefix)
|
ui.msgWin.printLine(0, 0, fg, bg, ui.cmdPrefix)
|
||||||
ui.msgWin.print(len(ui.cmdPrefix), 0, fg, bg, string(ui.cmdAccLeft))
|
ui.msgWin.print(len(ui.cmdPrefix), 0, fg, bg, string(ui.cmdAccLeft))
|
||||||
ui.msgWin.print(len(ui.cmdPrefix)+runeSliceWidth(ui.cmdAccLeft), 0, fg, bg, string(ui.cmdAccRight))
|
ui.msgWin.print(len(ui.cmdPrefix)+runeSliceWidth(ui.cmdAccLeft), 0, fg, bg, string(ui.cmdAccRight))
|
||||||
termbox.SetCursor(ui.msgWin.x+len(ui.cmdPrefix)+runeSliceWidth(ui.cmdAccLeft), ui.msgWin.y)
|
termbox.SetCursor(ui.msgWin.x+len(ui.cmdPrefix)+runeSliceWidth(ui.cmdAccLeft), ui.msgWin.y)
|
||||||
} else {
|
|
||||||
ui.drawStatLine(nav)
|
|
||||||
termbox.HideCursor()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if gOpts.preview {
|
if gOpts.preview {
|
||||||
@@ -627,13 +628,17 @@ func (ui *ui) draw(nav *nav) {
|
|||||||
preview := ui.wins[len(ui.wins)-1]
|
preview := ui.wins[len(ui.wins)-1]
|
||||||
|
|
||||||
if f.IsDir() {
|
if f.IsDir() {
|
||||||
preview.printDir(ui.dirPrev, nav.marks, nav.saves)
|
preview.printDir(ui.dirPrev, nav.marks, nav.saves, ui.colors)
|
||||||
} else if f.Mode().IsRegular() {
|
} else if f.Mode().IsRegular() {
|
||||||
preview.printReg(ui.regPrev)
|
preview.printReg(ui.regPrev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if gOpts.drawbox {
|
||||||
|
ui.drawBox(nav)
|
||||||
|
}
|
||||||
|
|
||||||
if ui.menuBuf != nil {
|
if ui.menuBuf != nil {
|
||||||
lines := strings.Split(ui.menuBuf.String(), "\n")
|
lines := strings.Split(ui.menuBuf.String(), "\n")
|
||||||
|
|
||||||
@@ -642,6 +647,10 @@ func (ui *ui) draw(nav *nav) {
|
|||||||
ui.menuWin.h = len(lines) - 1
|
ui.menuWin.h = len(lines) - 1
|
||||||
ui.menuWin.y = ui.wins[0].h - ui.menuWin.h
|
ui.menuWin.y = ui.wins[0].h - ui.menuWin.h
|
||||||
|
|
||||||
|
if gOpts.drawbox {
|
||||||
|
ui.menuWin.y += 2
|
||||||
|
}
|
||||||
|
|
||||||
ui.menuWin.printLine(0, 0, termbox.AttrBold, termbox.AttrBold, lines[0])
|
ui.menuWin.printLine(0, 0, termbox.AttrBold, termbox.AttrBold, 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(0, i+1, fg, bg, "")
|
||||||
@@ -660,13 +669,14 @@ func (ui *ui) draw(nav *nav) {
|
|||||||
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) {
|
||||||
binds = make(map[string]expr)
|
binds = make(map[string]expr)
|
||||||
for key, expr := range keys {
|
for key, expr := range keys {
|
||||||
if strings.HasPrefix(key, prefix) {
|
if !strings.HasPrefix(key, prefix) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
binds[key] = expr
|
binds[key] = expr
|
||||||
if key == prefix {
|
if key == prefix {
|
||||||
ok = true
|
ok = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -698,11 +708,15 @@ func (ui *ui) pollEvent() termbox.Event {
|
|||||||
if len(key) == 1 {
|
if len(key) == 1 {
|
||||||
ev.Ch, _ = utf8.DecodeRuneInString(key)
|
ev.Ch, _ = utf8.DecodeRuneInString(key)
|
||||||
} else {
|
} else {
|
||||||
switch key {
|
switch {
|
||||||
case "<lt>":
|
case key == "<lt>":
|
||||||
ev.Ch = '<'
|
ev.Ch = '<'
|
||||||
case "<gt>":
|
case key == "<gt>":
|
||||||
ev.Ch = '>'
|
ev.Ch = '>'
|
||||||
|
case reAltKey.MatchString(key):
|
||||||
|
match := reAltKey.FindStringSubmatch(key)[1]
|
||||||
|
ev.Ch, _ = utf8.DecodeRuneInString(match)
|
||||||
|
ev.Mod = termbox.ModAlt
|
||||||
default:
|
default:
|
||||||
if val, ok := gValKey[key]; ok {
|
if val, ok := gValKey[key]; ok {
|
||||||
ev.Key = val
|
ev.Key = val
|
||||||
@@ -719,24 +733,11 @@ func (ui *ui) pollEvent() termbox.Event {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type multiExpr struct {
|
// This function is used to read a normal event on the client side. For keys,
|
||||||
expr expr
|
// digits are interpreted as command counts but this is only done for digits
|
||||||
count int
|
// 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}
|
||||||
func readCmdEvent(ch chan<- multiExpr, ev termbox.Event) {
|
|
||||||
if ev.Ch != 0 {
|
|
||||||
ch <- multiExpr{&callExpr{"cmd-insert", []string{string(ev.Ch)}}, 1}
|
|
||||||
} else {
|
|
||||||
val := gKeyVal[ev.Key]
|
|
||||||
if expr, ok := gOpts.cmdkeys[string(val)]; ok {
|
|
||||||
ch <- multiExpr{expr, 1}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ui *ui) readEvent(ch chan<- multiExpr, ev termbox.Event) {
|
|
||||||
redraw := &callExpr{"redraw", nil}
|
|
||||||
count := 1
|
count := 1
|
||||||
|
|
||||||
switch ev.Type {
|
switch ev.Type {
|
||||||
@@ -744,9 +745,11 @@ func (ui *ui) readEvent(ch chan<- multiExpr, ev termbox.Event) {
|
|||||||
if ev.Ch != 0 {
|
if ev.Ch != 0 {
|
||||||
switch {
|
switch {
|
||||||
case ev.Ch == '<':
|
case ev.Ch == '<':
|
||||||
ui.keyAcc = append(ui.keyAcc, '<', 'l', 't', '>')
|
ui.keyAcc = append(ui.keyAcc, []rune("<lt>")...)
|
||||||
case ev.Ch == '>':
|
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:
|
case unicode.IsDigit(ev.Ch) && len(ui.keyAcc) == 0:
|
||||||
ui.keyCount = append(ui.keyCount, ev.Ch)
|
ui.keyCount = append(ui.keyCount, ev.Ch)
|
||||||
default:
|
default:
|
||||||
@@ -754,12 +757,17 @@ func (ui *ui) readEvent(ch chan<- multiExpr, ev termbox.Event) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val := gKeyVal[ev.Key]
|
val := gKeyVal[ev.Key]
|
||||||
if string(val) == "<esc>" {
|
if val == "<esc>" {
|
||||||
ch <- multiExpr{redraw, 1}
|
ch <- draw
|
||||||
ui.keyAcc = nil
|
ui.keyAcc = nil
|
||||||
ui.keyCount = nil
|
ui.keyCount = nil
|
||||||
}
|
}
|
||||||
ui.keyAcc = append(ui.keyAcc, val...)
|
ui.keyAcc = append(ui.keyAcc, []rune(val)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(ui.keyAcc) == 0 {
|
||||||
|
ch <- draw
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
binds, ok := findBinds(gOpts.keys, string(ui.keyAcc))
|
binds, ok := findBinds(gOpts.keys, string(ui.keyAcc))
|
||||||
@@ -767,7 +775,7 @@ func (ui *ui) readEvent(ch chan<- multiExpr, ev termbox.Event) {
|
|||||||
switch len(binds) {
|
switch len(binds) {
|
||||||
case 0:
|
case 0:
|
||||||
ui.printf("unknown mapping: %s", string(ui.keyAcc))
|
ui.printf("unknown mapping: %s", string(ui.keyAcc))
|
||||||
ch <- multiExpr{redraw, 1}
|
ch <- draw
|
||||||
ui.keyAcc = nil
|
ui.keyAcc = nil
|
||||||
ui.keyCount = nil
|
ui.keyCount = nil
|
||||||
ui.menuBuf = nil
|
ui.menuBuf = nil
|
||||||
@@ -783,19 +791,19 @@ func (ui *ui) readEvent(ch chan<- multiExpr, ev termbox.Event) {
|
|||||||
count = 1
|
count = 1
|
||||||
}
|
}
|
||||||
expr := gOpts.keys[string(ui.keyAcc)]
|
expr := gOpts.keys[string(ui.keyAcc)]
|
||||||
ch <- multiExpr{expr, count}
|
if e, ok := expr.(*callExpr); ok {
|
||||||
|
e.count = count
|
||||||
|
}
|
||||||
|
ch <- expr
|
||||||
ui.keyAcc = nil
|
ui.keyAcc = nil
|
||||||
ui.keyCount = nil
|
ui.keyCount = nil
|
||||||
}
|
|
||||||
if len(ui.keyAcc) > 0 {
|
|
||||||
ui.menuBuf = listBinds(binds)
|
|
||||||
ch <- multiExpr{redraw, 1}
|
|
||||||
} else if ui.menuBuf != nil {
|
|
||||||
ui.menuBuf = nil
|
ui.menuBuf = nil
|
||||||
|
} else {
|
||||||
|
ui.menuBuf = listBinds(binds)
|
||||||
|
ch <- draw
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
if ok {
|
if ok {
|
||||||
// TODO: use a delay
|
|
||||||
if len(ui.keyCount) > 0 {
|
if len(ui.keyCount) > 0 {
|
||||||
c, err := strconv.Atoi(string(ui.keyCount))
|
c, err := strconv.Atoi(string(ui.keyCount))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -806,32 +814,48 @@ func (ui *ui) readEvent(ch chan<- multiExpr, ev termbox.Event) {
|
|||||||
count = 1
|
count = 1
|
||||||
}
|
}
|
||||||
expr := gOpts.keys[string(ui.keyAcc)]
|
expr := gOpts.keys[string(ui.keyAcc)]
|
||||||
ch <- multiExpr{expr, count}
|
if e, ok := expr.(*callExpr); ok {
|
||||||
|
e.count = count
|
||||||
|
}
|
||||||
|
ch <- expr
|
||||||
ui.keyAcc = nil
|
ui.keyAcc = nil
|
||||||
ui.keyCount = nil
|
ui.keyCount = nil
|
||||||
}
|
|
||||||
if len(ui.keyAcc) > 0 {
|
|
||||||
ui.menuBuf = listBinds(binds)
|
|
||||||
ch <- multiExpr{redraw, 1}
|
|
||||||
} else {
|
|
||||||
ui.menuBuf = nil
|
ui.menuBuf = nil
|
||||||
|
} else {
|
||||||
|
ui.menuBuf = listBinds(binds)
|
||||||
|
ch <- draw
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case termbox.EventResize:
|
case termbox.EventResize:
|
||||||
ch <- multiExpr{redraw, 1}
|
ch <- &callExpr{"redraw", nil, 1}
|
||||||
default:
|
|
||||||
// TODO: handle other events
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function is used to read expressions on the client side. Digits are
|
func readCmdEvent(ch chan<- expr, ev termbox.Event) {
|
||||||
// interpreted as command counts but this is only done for digits preceding any
|
if ev.Ch != 0 {
|
||||||
// non-digit characters (e.g. "42y2k" as 42 times "y2k").
|
if ev.Mod == termbox.ModAlt {
|
||||||
func (ui *ui) readExpr() <-chan multiExpr {
|
val := string([]rune{'<', 'a', '-', ev.Ch, '>'})
|
||||||
ch := make(chan multiExpr)
|
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)
|
||||||
|
|
||||||
|
ui.exprChan = ch
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
ch <- multiExpr{&callExpr{"redraw", nil}, 1}
|
ch <- &callExpr{"draw", nil, 1}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
ev := ui.pollEvent()
|
ev := ui.pollEvent()
|
||||||
|
|||||||
Reference in new issue
Block a user