Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
da126a3959 | ||
|
|
6d20887b16 | ||
|
|
078dc47e34 | ||
|
|
8070cd82b7 | ||
|
|
52974615f2 | ||
|
|
76a725eaf2 | ||
|
|
2e014b3c0a | ||
|
|
51101f7020 | ||
|
|
ba01f85340 | ||
|
|
723357fe3d | ||
|
|
e025c68130 | ||
|
|
7acc85f81c | ||
|
|
4846a74320 | ||
|
|
9177ddd406 | ||
|
|
9d21a4f359 | ||
|
|
20720c832d | ||
|
|
448f2a3cb2 |
No files matched your search
@@ -39,6 +39,7 @@ See [faq](https://github.com/gokcehan/lf/wiki/FAQ) for more information.
|
|||||||
## May-Futures
|
## May-Futures
|
||||||
|
|
||||||
- Bookmarks
|
- Bookmarks
|
||||||
|
- Mouse control
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
@@ -52,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.
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type cmdItem struct {
|
type cmdItem struct {
|
||||||
@@ -19,6 +20,7 @@ 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
|
||||||
cmd *exec.Cmd
|
cmd *exec.Cmd
|
||||||
cmdIn io.WriteCloser
|
cmdIn io.WriteCloser
|
||||||
@@ -34,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),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -132,6 +135,10 @@ func (app *app) loop() {
|
|||||||
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ var (
|
|||||||
"clear",
|
"clear",
|
||||||
"draw",
|
"draw",
|
||||||
"redraw",
|
"redraw",
|
||||||
|
"load",
|
||||||
"reload",
|
"reload",
|
||||||
"read",
|
"read",
|
||||||
"shell",
|
"shell",
|
||||||
@@ -82,6 +83,7 @@ var (
|
|||||||
"wrapscan",
|
"wrapscan",
|
||||||
"nowrapscan",
|
"nowrapscan",
|
||||||
"wrapscan!",
|
"wrapscan!",
|
||||||
|
"period",
|
||||||
"scrolloff",
|
"scrolloff",
|
||||||
"tabstop",
|
"tabstop",
|
||||||
"filesep",
|
"filesep",
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ The following commands are provided by lf with default keybindings:
|
|||||||
The following commands are provided by lf without default keybindings:
|
The following commands are provided by lf without default keybindings:
|
||||||
|
|
||||||
draw draw the ui
|
draw draw the ui
|
||||||
|
load load modified files and directories
|
||||||
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
|
||||||
@@ -91,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")
|
||||||
@@ -192,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:
|
||||||
@@ -206,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:
|
||||||
|
|
||||||
@@ -229,6 +231,53 @@ prefix.
|
|||||||
set info time
|
set info time
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
Key Mappings
|
||||||
|
|
||||||
|
Regular keys are assigned to a command with the usual syntax:
|
||||||
|
|
||||||
|
map a down
|
||||||
|
|
||||||
|
Keys combined with the shift key simply use the uppercase letter:
|
||||||
|
|
||||||
|
map A down
|
||||||
|
|
||||||
|
Special keys are written in between '<' and '>' characters and always use
|
||||||
|
lowercase letters:
|
||||||
|
|
||||||
|
map <enter> down
|
||||||
|
|
||||||
|
Angle brackets can be assigned with their special names:
|
||||||
|
|
||||||
|
map <lt> down
|
||||||
|
map <gt> down
|
||||||
|
|
||||||
|
Function keys are prefixed with 'f' character:
|
||||||
|
|
||||||
|
map <f-1> down
|
||||||
|
|
||||||
|
Keys combined with the control key are prefixed with 'c' character:
|
||||||
|
|
||||||
|
map <c-a> down
|
||||||
|
|
||||||
|
Keys combined with the alt key are assigned in two different ways depending on
|
||||||
|
the behavior of your terminal. Older terminals (e.g. xterm) may set the 8th bit
|
||||||
|
of a character when the alt key is pressed. On these terminals, you can use the
|
||||||
|
corresponding byte for the mapping:
|
||||||
|
|
||||||
|
map á down
|
||||||
|
|
||||||
|
Newer terminals (e.g. gnome-terminal) may prefix the key with an escape key
|
||||||
|
when the alt key is pressed. lf uses the escape delaying mechanism to recognize
|
||||||
|
alt keys in these terminals (delay is 100ms). On these terminals, keys combined
|
||||||
|
with the alt key are prefixed with 'a' character:
|
||||||
|
|
||||||
|
map <a-a> down
|
||||||
|
|
||||||
|
Please note that, some key combinations are not possible due to the way
|
||||||
|
terminals work (e.g. control and h combination sends a backspace key instead).
|
||||||
|
The easiest way to find the name of a key combination is to press the key while
|
||||||
|
lf is running and read the name of the key from the unknown mapping error.
|
||||||
|
|
||||||
Push Mappings
|
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
|
||||||
@@ -378,7 +427,7 @@ Since lf does not have control flow syntax, remote commands are used for such
|
|||||||
needs. For example, you can configure the number of columns in the ui with
|
needs. For example, you can configure the number of columns in the ui with
|
||||||
respect to the terminal width as follows:
|
respect to the terminal width as follows:
|
||||||
|
|
||||||
cmd recol ${{
|
cmd recol %{{
|
||||||
w=$(tput cols)
|
w=$(tput cols)
|
||||||
if [ $w -le 80 ]; then
|
if [ $w -le 80 ]; then
|
||||||
lf -remote "send $id set ratios 1:2"
|
lf -remote "send $id set ratios 1:2"
|
||||||
@@ -434,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'
|
||||||
|
|||||||
+56
-5
@@ -49,6 +49,7 @@ The following commands are provided by lf with default keybindings:
|
|||||||
The following commands are provided by lf without default keybindings:
|
The following commands are provided by lf without default keybindings:
|
||||||
|
|
||||||
draw draw the ui
|
draw draw the ui
|
||||||
|
load load modified files and directories
|
||||||
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
|
||||||
@@ -95,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")
|
||||||
@@ -200,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:
|
||||||
@@ -214,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:
|
||||||
|
|
||||||
@@ -238,6 +240,55 @@ proper prefix.
|
|||||||
}}
|
}}
|
||||||
|
|
||||||
|
|
||||||
|
Key Mappings
|
||||||
|
|
||||||
|
Regular keys are assigned to a command with the usual syntax:
|
||||||
|
|
||||||
|
map a down
|
||||||
|
|
||||||
|
Keys combined with the shift key simply use the uppercase letter:
|
||||||
|
|
||||||
|
map A down
|
||||||
|
|
||||||
|
Special keys are written in between '<' and '>' characters and always use
|
||||||
|
lowercase letters:
|
||||||
|
|
||||||
|
map <enter> down
|
||||||
|
|
||||||
|
Angle brackets can be assigned with their special names:
|
||||||
|
|
||||||
|
map <lt> down
|
||||||
|
map <gt> down
|
||||||
|
|
||||||
|
Function keys are prefixed with 'f' character:
|
||||||
|
|
||||||
|
map <f-1> down
|
||||||
|
|
||||||
|
Keys combined with the control key are prefixed with 'c' character:
|
||||||
|
|
||||||
|
map <c-a> down
|
||||||
|
|
||||||
|
Keys combined with the alt key are assigned in two different ways depending
|
||||||
|
on the behavior of your terminal. Older terminals (e.g. xterm) may set the
|
||||||
|
8th bit of a character when the alt key is pressed. On these terminals, you
|
||||||
|
can use the corresponding byte for the mapping:
|
||||||
|
|
||||||
|
map á down
|
||||||
|
|
||||||
|
Newer terminals (e.g. gnome-terminal) may prefix the key with an escape key
|
||||||
|
when the alt key is pressed. lf uses the escape delaying mechanism to
|
||||||
|
recognize alt keys in these terminals (delay is 100ms). On these terminals,
|
||||||
|
keys combined with the alt key are prefixed with 'a' character:
|
||||||
|
|
||||||
|
map <a-a> down
|
||||||
|
|
||||||
|
Please note that, some key combinations are not possible due to the way
|
||||||
|
terminals work (e.g. control and h combination sends a backspace key
|
||||||
|
instead). The easiest way to find the name of a key combination is to press
|
||||||
|
the key while lf is running and read the name of the key from the unknown
|
||||||
|
mapping error.
|
||||||
|
|
||||||
|
|
||||||
Push Mappings
|
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
|
||||||
@@ -399,7 +450,7 @@ Since lf does not have control flow syntax, remote commands are used for
|
|||||||
such needs. For example, you can configure the number of columns in the ui
|
such needs. For example, you can configure the number of columns in the ui
|
||||||
with respect to the terminal width as follows:
|
with respect to the terminal width as follows:
|
||||||
|
|
||||||
cmd recol ${{
|
cmd recol %{{
|
||||||
w=$(tput cols)
|
w=$(tput cols)
|
||||||
if [ $w -le 80 ]; then
|
if [ $w -le 80 ]; then
|
||||||
lf -remote "send $id set ratios 1:2"
|
lf -remote "send $id set ratios 1:2"
|
||||||
@@ -456,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
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
"unicode"
|
"unicode"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
)
|
)
|
||||||
@@ -51,15 +52,21 @@ func (e *setExpr) eval(app *app, args []string) {
|
|||||||
case "hidden":
|
case "hidden":
|
||||||
gOpts.sortType.option |= hiddenSort
|
gOpts.sortType.option |= hiddenSort
|
||||||
app.nav.sort()
|
app.nav.sort()
|
||||||
|
app.nav.position()
|
||||||
app.ui.sort()
|
app.ui.sort()
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
case "nohidden":
|
case "nohidden":
|
||||||
gOpts.sortType.option &= ^hiddenSort
|
gOpts.sortType.option &= ^hiddenSort
|
||||||
app.nav.sort()
|
app.nav.sort()
|
||||||
|
app.nav.position()
|
||||||
app.ui.sort()
|
app.ui.sort()
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
case "hidden!":
|
case "hidden!":
|
||||||
gOpts.sortType.option ^= hiddenSort
|
gOpts.sortType.option ^= hiddenSort
|
||||||
app.nav.sort()
|
app.nav.sort()
|
||||||
|
app.nav.position()
|
||||||
app.ui.sort()
|
app.ui.sort()
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
case "ignorecase":
|
case "ignorecase":
|
||||||
gOpts.ignorecase = true
|
gOpts.ignorecase = true
|
||||||
case "noignorecase":
|
case "noignorecase":
|
||||||
@@ -96,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 {
|
||||||
@@ -355,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()
|
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)
|
||||||
}
|
}
|
||||||
@@ -372,9 +398,9 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
app.ui.sync()
|
app.ui.sync()
|
||||||
app.ui.renew()
|
app.ui.renew()
|
||||||
app.nav.height = app.ui.wins[0].h
|
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 = ":"
|
||||||
@@ -650,7 +676,9 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
ind := locs[len(locs)-1][1] - 1
|
ind := locs[len(locs)-1][1] - 1
|
||||||
app.ui.cmdAccRight = append(app.ui.cmdAccLeft[ind:], app.ui.cmdAccRight...)
|
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]
|
app.ui.cmdAccLeft = app.ui.cmdAccLeft[:ind]
|
||||||
case "cmd-capitalize-word":
|
case "cmd-capitalize-word":
|
||||||
if len(app.ui.cmdAccRight) == 0 {
|
if len(app.ui.cmdAccRight) == 0 {
|
||||||
|
|||||||
@@ -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))
|
||||||
|
|||||||
@@ -214,7 +214,21 @@ func (nav *nav) loadDir(path string) *dir {
|
|||||||
return d
|
return d
|
||||||
}
|
}
|
||||||
|
|
||||||
if d.sortType != gOpts.sortType {
|
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() {
|
go func() {
|
||||||
d.loading = true
|
d.loading = true
|
||||||
name := d.name()
|
name := d.name()
|
||||||
@@ -267,11 +281,6 @@ func newNav(height int) *nav {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) renew() {
|
func (nav *nav) renew() {
|
||||||
nav.dirCache = make(map[string]*dir)
|
|
||||||
for _, d := range nav.dirs {
|
|
||||||
nav.dirCache[d.path] = d
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
||||||
@@ -356,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)
|
||||||
|
|
||||||
@@ -382,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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ var gOpts struct {
|
|||||||
preview bool
|
preview bool
|
||||||
smartcase bool
|
smartcase bool
|
||||||
wrapscan bool
|
wrapscan bool
|
||||||
|
period int
|
||||||
scrolloff int
|
scrolloff int
|
||||||
tabstop int
|
tabstop int
|
||||||
filesep string
|
filesep string
|
||||||
@@ -56,6 +57,7 @@ func init() {
|
|||||||
gOpts.preview = true
|
gOpts.preview = true
|
||||||
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"
|
||||||
|
|||||||
@@ -181,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)
|
||||||
}
|
}
|
||||||
@@ -462,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
|
||||||
}
|
}
|
||||||
@@ -796,7 +804,6 @@ func (ui *ui) readEvent(ch chan<- expr, ev termbox.Event) {
|
|||||||
}
|
}
|
||||||
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 {
|
||||||
@@ -821,8 +828,6 @@ func (ui *ui) readEvent(ch chan<- expr, ev termbox.Event) {
|
|||||||
}
|
}
|
||||||
case termbox.EventResize:
|
case termbox.EventResize:
|
||||||
ch <- &callExpr{"redraw", nil, 1}
|
ch <- &callExpr{"redraw", nil, 1}
|
||||||
default:
|
|
||||||
// TODO: handle other events
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user