Compare commits

17 Commits
r4 ... r5
Author SHA1 Message Date
Gokcehan da126a3959 update readme 2018-06-16 16:59:41 +03:00
Gokcehan 6d20887b16 update preview when 'hidden' is changed 2018-06-16 16:34:14 +03:00
Gokcehan 078dc47e34 find hidden parents when 'hidden' is changed 2018-06-16 16:27:39 +03:00
Gokcehan 8070cd82b7 cleanup 2018-06-16 00:59:16 +03:00
Gokcehan 52974615f2 handle command properly with 'cmd-word'back' 2018-06-16 00:13:33 +03:00
Gokcehan 76a725eaf2 replace 'reload' with 'load' in documentaiton 2018-06-15 22:52:17 +03:00
Gokcehan 2e014b3c0a add tutorial link to readme
Related #94
2018-06-15 21:05:55 +03:00
Gokcehan 51101f7020 load all clients after running 'put' command 2018-06-15 16:34:44 +03:00
Gokcehan ba01f85340 add 'load' command to load modified dirs and files 2018-06-15 16:33:54 +03:00
Gokcehan 723357fe3d add 'period' option for periodic refresh
Related #73
2018-06-09 22:02:09 +03:00
Gokcehan e025c68130 keep cache when navigation is renewed 2018-06-08 21:47:28 +03:00
Gokcehan 7acc85f81c reload modified files when loading cache
Related #92
2018-06-07 22:49:53 +03:00
Gokcehan 4846a74320 reload modified directories when loading cache
Related #92
2018-06-07 22:19:55 +03:00
Gokcehan 9177ddd406 cleanup 2018-06-06 21:50:15 +03:00
Gokcehan 9d21a4f359 add key mappings to the doc 2018-06-06 21:39:44 +03:00
Gokcehan 20720c832d cleanup 2018-06-06 20:55:13 +03:00
Gokcehan 448f2a3cb2 restart server when crashed
Related #65
2018-06-05 22:11:20 +03:00
10 changed files with 211 additions and 31 deletions

No files matched your search

+3
View File
@@ -39,6 +39,7 @@ See [faq](https://github.com/gokcehan/lf/wiki/FAQ) for more information.
## May-Futures
- Bookmarks
- Mouse control
## Installation
@@ -52,6 +53,8 @@ See [packages](https://github.com/gokcehan/lf/wiki/Packages) for community maint
## Usage
See [tutorial](https://github.com/gokcehan/lf/wiki/Tutorial) for a gentle introduction with screencasts.
After the installation `lf` command should start the application in the current directory.
Run `lf -help` to see command line options.
+7
View File
@@ -9,6 +9,7 @@ import (
"os/exec"
"strconv"
"strings"
"time"
)
type cmdItem struct {
@@ -19,6 +20,7 @@ type cmdItem struct {
type app struct {
ui *ui
nav *nav
ticker *time.Ticker
quitChan chan bool
cmd *exec.Cmd
cmdIn io.WriteCloser
@@ -34,6 +36,7 @@ func newApp() *app {
return &app{
ui: ui,
nav: nav,
ticker: new(time.Ticker),
quitChan: make(chan bool, 1),
}
}
@@ -132,6 +135,10 @@ func (app *app) loop() {
case e := <-serverChan:
e.eval(app, nil)
app.ui.draw(app.nav)
case <-app.ticker.C:
app.nav.renew()
app.ui.loadFile(app.nav)
app.ui.draw(app.nav)
}
}
}
+2
View File
@@ -34,6 +34,7 @@ var (
"clear",
"draw",
"redraw",
"load",
"reload",
"read",
"shell",
@@ -82,6 +83,7 @@ var (
"wrapscan",
"nowrapscan",
"wrapscan!",
"period",
"scrolloff",
"tabstop",
"filesep",
+54 -5
View File
@@ -45,6 +45,7 @@ The following commands are provided by lf with default keybindings:
The following commands are provided by lf without default keybindings:
draw draw the ui
load load modified files and directories
sync synchronizes yanked/deleted files with server
echo prints its arguments to the message line
cd changes working directory to its argument
@@ -91,6 +92,7 @@ The following options can be used to customize the behavior of lf:
reverse boolean (default off)
smartcase boolean (default on)
wrapscan boolean (default on)
period integer (default 0)
scrolloff integer (default 0)
tabstop integer (default 8)
filesep string (default "\n")
@@ -192,7 +194,7 @@ command, or shell command:
map gh cd ~ # builtin command
map D trash # custom command
map i $less $f # shell command
map u !du -h . # waiting shell command
map U !du -sh # waiting shell command
'cmap' is used to bind a key to a command line command which can only be one of
the builtin commands:
@@ -206,7 +208,7 @@ You can delete an existing binding by leaving the expression empty:
'cmd' is used to define a custom command
cmd usage $du -h . | less
cmd usage $du -h -d1 | less
You can delete an existing command by leaving the expression empty:
@@ -229,6 +231,53 @@ prefix.
set info time
}}
Key Mappings
Regular keys are assigned to a command with the usual syntax:
map a down
Keys combined with the shift key simply use the uppercase letter:
map A down
Special keys are written in between '<' and '>' characters and always use
lowercase letters:
map <enter> down
Angle brackets can be assigned with their special names:
map <lt> down
map <gt> down
Function keys are prefixed with 'f' character:
map <f-1> down
Keys combined with the control key are prefixed with 'c' character:
map <c-a> down
Keys combined with the alt key are assigned in two different ways depending on
the behavior of your terminal. Older terminals (e.g. xterm) may set the 8th bit
of a character when the alt key is pressed. On these terminals, you can use the
corresponding byte for the mapping:
map á down
Newer terminals (e.g. gnome-terminal) may prefix the key with an escape key
when the alt key is pressed. lf uses the escape delaying mechanism to recognize
alt keys in these terminals (delay is 100ms). On these terminals, keys combined
with the alt key are prefixed with 'a' character:
map <a-a> down
Please note that, some key combinations are not possible due to the way
terminals work (e.g. control and h combination sends a backspace key instead).
The easiest way to find the name of a key combination is to press the key while
lf is running and read the name of the key from the unknown mapping error.
Push Mappings
The usual way to map a key sequence is to assign it to a named or unnamed
@@ -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
respect to the terminal width as follows:
cmd recol ${{
cmd recol %{{
w=$(tput cols)
if [ $w -le 80 ]; then
lf -remote "send $id set ratios 1:2"
@@ -434,9 +483,9 @@ implementation. The default behavior is similar to the following command:
elif [ $mode = 'move' ]; then
mv -n $list .
fi
lf -remote "send $id reload"
lf -remote "$(printf 'save\nmove\n\n')"
lf -remote "send sync"
lf -remote 'send load'
lf -remote 'send sync'
}}
Some useful things are to use the backup option ('--backup') with 'cp' and 'mv'
+56 -5
View File
@@ -49,6 +49,7 @@ The following commands are provided by lf with default keybindings:
The following commands are provided by lf without default keybindings:
draw draw the ui
load load modified files and directories
sync synchronizes yanked/deleted files with server
echo prints its arguments to the message line
cd changes working directory to its argument
@@ -95,6 +96,7 @@ The following options can be used to customize the behavior of lf:
reverse boolean (default off)
smartcase boolean (default on)
wrapscan boolean (default on)
period integer (default 0)
scrolloff integer (default 0)
tabstop integer (default 8)
filesep string (default "\n")
@@ -200,7 +202,7 @@ custom command, or shell command:
map gh cd ~ # builtin command
map D trash # custom command
map i $less $f # shell command
map u !du -h . # waiting shell command
map U !du -sh # waiting shell command
'cmap' is used to bind a key to a command line command which can only be one
of the builtin commands:
@@ -214,7 +216,7 @@ You can delete an existing binding by leaving the expression empty:
'cmd' is used to define a custom command
cmd usage $du -h . | less
cmd usage $du -h -d1 | less
You can delete an existing command by leaving the expression empty:
@@ -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
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
with respect to the terminal width as follows:
cmd recol ${{
cmd recol %{{
w=$(tput cols)
if [ $w -le 80 ]; then
lf -remote "send $id set ratios 1:2"
@@ -456,9 +507,9 @@ implementation. The default behavior is similar to the following command:
elif [ $mode = 'move' ]; then
mv -n $list .
fi
lf -remote "send $id reload"
lf -remote "$(printf 'save\nmove\n\n')"
lf -remote "send sync"
lf -remote 'send load'
lf -remote 'send sync'
}}
Some useful things are to use the backup option ('--backup') with 'cp' and
+32 -4
View File
@@ -6,6 +6,7 @@ import (
"os"
"strconv"
"strings"
"time"
"unicode"
"unicode/utf8"
)
@@ -51,15 +52,21 @@ func (e *setExpr) eval(app *app, args []string) {
case "hidden":
gOpts.sortType.option |= hiddenSort
app.nav.sort()
app.nav.position()
app.ui.sort()
app.ui.loadFile(app.nav)
case "nohidden":
gOpts.sortType.option &= ^hiddenSort
app.nav.sort()
app.nav.position()
app.ui.sort()
app.ui.loadFile(app.nav)
case "hidden!":
gOpts.sortType.option ^= hiddenSort
app.nav.sort()
app.nav.position()
app.ui.sort()
app.ui.loadFile(app.nav)
case "ignorecase":
gOpts.ignorecase = true
case "noignorecase":
@@ -96,6 +103,23 @@ func (e *setExpr) eval(app *app, args []string) {
gOpts.wrapscan = false
case "wrapscan!":
gOpts.wrapscan = !gOpts.wrapscan
case "period":
n, err := strconv.Atoi(e.val)
if err != nil {
app.ui.printf("period: %s", err)
return
}
if n < 0 {
app.ui.print("period: value should be a non-negative number")
return
}
gOpts.period = n
if n == 0 {
app.ticker.Stop()
} else {
app.ticker.Stop()
app.ticker = time.NewTicker(time.Duration(gOpts.period) * time.Second)
}
case "scrolloff":
n, err := strconv.Atoi(e.val)
if err != nil {
@@ -355,7 +379,9 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.printf("put: %s", err)
return
}
app.nav.renew()
if err := sendRemote("send load"); err != nil {
app.ui.printf("put: %s", err)
}
if err := sendRemote("send sync"); err != nil {
app.ui.printf("put: %s", err)
}
@@ -372,9 +398,9 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.sync()
app.ui.renew()
app.nav.height = app.ui.wins[0].h
case "load":
app.nav.renew()
case "reload":
app.ui.sync()
app.ui.renew()
app.nav.reload()
case "read":
app.ui.cmdPrefix = ":"
@@ -650,7 +676,9 @@ func (e *callExpr) eval(app *app, args []string) {
return
}
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]
case "cmd-capitalize-word":
if len(app.ui.cmdAccRight) == 0 {
+17 -4
View File
@@ -4,6 +4,7 @@ import (
"flag"
"fmt"
"log"
"net"
"os"
"os/exec"
"path/filepath"
@@ -42,6 +43,21 @@ func startServer() {
}
}
func checkServer() {
if gSocketProt == "unix" {
if _, err := os.Stat(gSocketPath); os.IsNotExist(err) {
startServer()
} else if _, err := net.Dial(gSocketProt, gSocketPath); err != nil {
os.Remove(gSocketPath)
startServer()
}
} else {
if _, err := net.Dial(gSocketProt, gSocketPath); err != nil {
startServer()
}
}
}
func main() {
showDoc := flag.Bool(
"doc",
@@ -125,10 +141,7 @@ func main() {
gServerLogPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.server.log", gUser.Username))
serve()
default:
// TODO: check if the socket is working
if _, err := os.Stat(gSocketPath); os.IsNotExist(err) {
startServer()
}
checkServer()
gClientID = 1000
gLogPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.%d.log", gUser.Username, gClientID))
+28 -8
View File
@@ -214,7 +214,21 @@ func (nav *nav) loadDir(path string) *dir {
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() {
d.loading = true
name := d.name()
@@ -267,11 +281,6 @@ func newNav(height int) *nav {
}
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 {
go func(d *dir) {
s, err := os.Stat(d.path)
@@ -356,7 +365,7 @@ func (nav *nav) preview() {
reader = f
}
reg := &reg{path: curr.path}
reg := &reg{loadTime: time.Now(), path: curr.path}
buf := bufio.NewScanner(reader)
@@ -382,10 +391,21 @@ func (nav *nav) loadReg(ui *ui, path string) *reg {
r, ok := nav.regCache[path]
if !ok {
go nav.preview()
r := &reg{path: path, lines: []string{"\033[1mloading...\033[0m"}}
r := &reg{loading: true, path: path}
nav.regCache[path] = r
return r
}
s, err := os.Stat(r.path)
if err != nil {
return r
}
if s.ModTime().After(r.loadTime) {
r.loadTime = time.Now()
go nav.preview()
}
return r
}
+2
View File
@@ -32,6 +32,7 @@ var gOpts struct {
preview bool
smartcase bool
wrapscan bool
period int
scrolloff int
tabstop int
filesep string
@@ -56,6 +57,7 @@ func init() {
gOpts.preview = true
gOpts.smartcase = true
gOpts.wrapscan = true
gOpts.period = 0
gOpts.scrolloff = 0
gOpts.tabstop = 8
gOpts.filesep = "\n"
+10 -5
View File
@@ -181,6 +181,12 @@ func (win *win) printReg(reg *reg) {
fg, bg := termbox.ColorDefault, termbox.ColorDefault
if reg.loading {
fg = termbox.AttrBold
win.print(2, 0, fg, bg, "loading...")
return
}
for i, l := range reg.lines {
fg, bg = win.print(2, i, fg, bg, l)
}
@@ -462,8 +468,10 @@ func (ui *ui) printf(format string, a ...interface{}) {
}
type reg struct {
path string
lines []string
loading bool
loadTime time.Time
path string
lines []string
}
func (ui *ui) loadFile(nav *nav) {
@@ -796,7 +804,6 @@ func (ui *ui) readEvent(ch chan<- expr, ev termbox.Event) {
}
default:
if ok {
// TODO: use a delay
if len(ui.keyCount) > 0 {
c, err := strconv.Atoi(string(ui.keyCount))
if err != nil {
@@ -821,8 +828,6 @@ func (ui *ui) readEvent(ch chan<- expr, ev termbox.Event) {
}
case termbox.EventResize:
ch <- &callExpr{"redraw", nil, 1}
default:
// TODO: handle other events
}
}