Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6b235beb39 | ||
|
|
d267bc70d4 | ||
|
|
3b043752a4 | ||
|
|
a0e1d4d59a | ||
|
|
09b1daaade | ||
|
|
8eb9055622 | ||
|
|
d608eb4a56 | ||
|
|
ad4fc51805 | ||
|
|
ebd599deca | ||
|
|
5a9a829252 | ||
|
|
f92e0f53a5 | ||
|
|
54dbf5cbe4 | ||
|
|
c1fc79b6ae | ||
|
|
4d3437a198 | ||
|
|
9d14888ba2 | ||
|
|
68a23a10e1 | ||
|
|
03619c3cbb |
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,6 @@ See [faq](https://github.com/gokcehan/lf/wiki/FAQ) for more information.
|
|||||||
## May-Futures
|
## May-Futures
|
||||||
|
|
||||||
- Bookmarks
|
- Bookmarks
|
||||||
- Colorschemes
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
|||||||
@@ -125,9 +125,7 @@ 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)
|
||||||
@@ -193,7 +191,7 @@ func (app *app) runShell(s string, args []string, prefix string) {
|
|||||||
|
|
||||||
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 "%":
|
case "%":
|
||||||
stdin, err := cmd.StdinPipe()
|
stdin, err := cmd.StdinPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -245,7 +243,7 @@ func (app *app) runShell(s string, args []string, prefix string) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
app.cmdOutBuf = append(app.cmdOutBuf, b)
|
app.cmdOutBuf = append(app.cmdOutBuf, b)
|
||||||
app.ui.exprChan <- multiExpr{&callExpr{"echo", []string{string(app.cmdOutBuf)}}, 1}
|
app.ui.exprChan <- &callExpr{"echo", []string{string(app.cmdOutBuf)}, 1}
|
||||||
if b == '\n' || b == '\r' {
|
if b == '\n' || b == '\r' {
|
||||||
app.cmdOutBuf = nil
|
app.cmdOutBuf = nil
|
||||||
}
|
}
|
||||||
@@ -256,7 +254,7 @@ func (app *app) runShell(s string, args []string, prefix string) {
|
|||||||
}
|
}
|
||||||
app.cmd = nil
|
app.cmd = nil
|
||||||
app.ui.cmdPrefix = ""
|
app.ui.cmdPrefix = ""
|
||||||
app.ui.exprChan <- multiExpr{&callExpr{"reload", nil}, 1}
|
app.ui.exprChan <- &callExpr{"reload", nil, 1}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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,217 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/nsf/termbox-go"
|
||||||
|
)
|
||||||
|
|
||||||
|
const gAnsiColorResetMask = termbox.AttrBold | termbox.AttrUnderline | termbox.AttrReverse
|
||||||
|
|
||||||
|
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 _, 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
|
||||||
|
if len(nums) == 3 {
|
||||||
|
if nums[0] == 48 && nums[1] == 5 {
|
||||||
|
bg = termbox.Attribute(nums[2] + 1)
|
||||||
|
}
|
||||||
|
if nums[0] == 38 && nums[1] == 5 {
|
||||||
|
fg = termbox.Attribute(nums[2] + 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, n := range nums {
|
||||||
|
attr, ok := gAnsiCodes[n]
|
||||||
|
if !ok {
|
||||||
|
log.Printf("unknown ansi code: %d", n)
|
||||||
|
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
|
||||||
|
}
|
||||||
@@ -32,6 +32,7 @@ var (
|
|||||||
"delete",
|
"delete",
|
||||||
"put",
|
"put",
|
||||||
"clear",
|
"clear",
|
||||||
|
"draw",
|
||||||
"redraw",
|
"redraw",
|
||||||
"reload",
|
"reload",
|
||||||
"read",
|
"read",
|
||||||
@@ -57,6 +58,9 @@ var (
|
|||||||
"dirfirst",
|
"dirfirst",
|
||||||
"nodirfirst",
|
"nodirfirst",
|
||||||
"dirfirst!",
|
"dirfirst!",
|
||||||
|
"drawbox",
|
||||||
|
"nodrawbox",
|
||||||
|
"drawbox!",
|
||||||
"globsearch",
|
"globsearch",
|
||||||
"noglobsearch",
|
"noglobsearch",
|
||||||
"globsearch!",
|
"globsearch!",
|
||||||
|
|||||||
@@ -44,6 +44,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
|
||||||
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
|
||||||
@@ -75,6 +76,7 @@ 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)
|
||||||
@@ -514,5 +516,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
|
||||||
@@ -48,6 +48,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
|
||||||
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
|
||||||
@@ -79,6 +80,7 @@ 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)
|
||||||
@@ -542,4 +544,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.
|
||||||
`
|
`
|
||||||
@@ -18,14 +18,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":
|
||||||
@@ -33,14 +48,17 @@ 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.ui.sort()
|
||||||
case "nohidden":
|
case "nohidden":
|
||||||
gOpts.hidden = false
|
gOpts.sortType.option &= ^hiddenSort
|
||||||
app.nav.sort()
|
app.nav.sort()
|
||||||
|
app.ui.sort()
|
||||||
case "hidden!":
|
case "hidden!":
|
||||||
gOpts.hidden = !gOpts.hidden
|
gOpts.sortType.option ^= hiddenSort
|
||||||
app.nav.sort()
|
app.nav.sort()
|
||||||
|
app.ui.sort()
|
||||||
case "ignorecase":
|
case "ignorecase":
|
||||||
gOpts.ignorecase = true
|
gOpts.ignorecase = true
|
||||||
case "noignorecase":
|
case "noignorecase":
|
||||||
@@ -54,14 +72,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":
|
||||||
@@ -84,10 +105,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)
|
||||||
@@ -115,8 +132,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":
|
||||||
@@ -168,7 +195,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) {
|
||||||
@@ -201,34 +228,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":
|
||||||
@@ -291,7 +320,9 @@ 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 "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":
|
||||||
@@ -323,7 +354,7 @@ 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)
|
app.nav.renew()
|
||||||
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)
|
||||||
}
|
}
|
||||||
@@ -335,10 +366,11 @@ 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 "reload":
|
case "reload":
|
||||||
app.ui.sync()
|
app.ui.sync()
|
||||||
app.ui.renew()
|
app.ui.renew()
|
||||||
@@ -358,17 +390,21 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
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":
|
||||||
|
|||||||
+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", ""}}},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -97,6 +97,7 @@ type dir struct {
|
|||||||
path string // full path of directory
|
path string // full path of directory
|
||||||
fi []*file // displayed files in directory including or excluding hidden ones
|
fi []*file // displayed files in directory including or excluding hidden ones
|
||||||
all []*file // all files in directory including hidden ones (same array as fi)
|
all []*file // all files in directory including hidden ones (same array as fi)
|
||||||
|
sortType sortType // sort method and options from last sort
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDir(path string) *dir {
|
func newDir(path string) *dir {
|
||||||
@@ -126,36 +127,36 @@ func (dir *dir) renew() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (dir *dir) sort() {
|
func (dir *dir) sort() {
|
||||||
|
dir.sortType = gOpts.sortType
|
||||||
|
|
||||||
dir.fi = dir.all
|
dir.fi = dir.all
|
||||||
|
|
||||||
switch gOpts.sortby {
|
switch gOpts.sortType.method {
|
||||||
case "natural":
|
case naturalSort:
|
||||||
sortFilesStable(dir.fi, func(i, j int) bool {
|
sortFilesStable(dir.fi, func(i, j int) bool {
|
||||||
return naturalLess(strings.ToLower(dir.fi[i].Name()), strings.ToLower(dir.fi[j].Name()))
|
return naturalLess(strings.ToLower(dir.fi[i].Name()), strings.ToLower(dir.fi[j].Name()))
|
||||||
})
|
})
|
||||||
case "name":
|
case nameSort:
|
||||||
sortFilesStable(dir.fi, func(i, j int) bool {
|
sortFilesStable(dir.fi, func(i, j int) bool {
|
||||||
return strings.ToLower(dir.fi[i].Name()) < strings.ToLower(dir.fi[j].Name())
|
return strings.ToLower(dir.fi[i].Name()) < strings.ToLower(dir.fi[j].Name())
|
||||||
})
|
})
|
||||||
case "size":
|
case sizeSort:
|
||||||
sortFilesStable(dir.fi, func(i, j int) bool {
|
sortFilesStable(dir.fi, func(i, j int) bool {
|
||||||
return dir.fi[i].Size() < dir.fi[j].Size()
|
return dir.fi[i].Size() < dir.fi[j].Size()
|
||||||
})
|
})
|
||||||
case "time":
|
case timeSort:
|
||||||
sortFilesStable(dir.fi, func(i, j int) bool {
|
sortFilesStable(dir.fi, func(i, j int) bool {
|
||||||
return dir.fi[i].ModTime().Before(dir.fi[j].ModTime())
|
return dir.fi[i].ModTime().Before(dir.fi[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.fi)-1; i < j; i, j = i+1, j-1 {
|
||||||
dir.fi[i], dir.fi[j] = dir.fi[j], dir.fi[i]
|
dir.fi[i], dir.fi[j] = dir.fi[j], dir.fi[i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if gOpts.dirfirst {
|
if gOpts.sortType.option&dirfirstSort != 0 {
|
||||||
sortFilesStable(dir.fi, func(i, j int) bool {
|
sortFilesStable(dir.fi, func(i, j int) bool {
|
||||||
if dir.fi[i].IsDir() == dir.fi[j].IsDir() {
|
if dir.fi[i].IsDir() == dir.fi[j].IsDir() {
|
||||||
return i < j
|
return i < j
|
||||||
@@ -167,7 +168,7 @@ func (dir *dir) sort() {
|
|||||||
// 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 {
|
sortFilesStable(dir.fi, func(i, j int) bool {
|
||||||
if dir.fi[i].Name()[0] == '.' && dir.fi[j].Name()[0] == '.' {
|
if dir.fi[i].Name()[0] == '.' && dir.fi[j].Name()[0] == '.' {
|
||||||
return i < j
|
return i < j
|
||||||
@@ -208,7 +209,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.fi)-dir.ind-1)
|
||||||
dir.pos = min(dir.ind, height-edge-1)
|
dir.pos = min(dir.ind, height-edge-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,13 +272,12 @@ func (nav *nav) getDirs(wd string) {
|
|||||||
nav.dirs = dirs
|
nav.dirs = dirs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) renew(height int) {
|
func (nav *nav) renew() {
|
||||||
nav.dirCache = make(map[string]*dir)
|
nav.dirCache = make(map[string]*dir)
|
||||||
for _, d := range nav.dirs {
|
for _, d := range nav.dirs {
|
||||||
nav.dirCache[d.path] = d
|
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)
|
||||||
@@ -330,10 +330,22 @@ func (nav *nav) loadDir(path string) *dir {
|
|||||||
d.ind, d.pos = 0, 0
|
d.ind, d.pos = 0, 0
|
||||||
nav.dirChan <- d
|
nav.dirChan <- d
|
||||||
}()
|
}()
|
||||||
d := &dir{loading: true, path: path}
|
d := &dir{loading: true, path: path, sortType: gOpts.sortType}
|
||||||
nav.dirCache[path] = d
|
nav.dirCache[path] = d
|
||||||
return d
|
return d
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if d.sortType != gOpts.sortType {
|
||||||
|
go func() {
|
||||||
|
d.loading = true
|
||||||
|
name := d.name()
|
||||||
|
d.sort()
|
||||||
|
d.find(name, nav.height)
|
||||||
|
d.loading = false
|
||||||
|
nav.dirChan <- d
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
return d
|
return d
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -422,7 +434,7 @@ 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -439,7 +451,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
|
||||||
|
|||||||
@@ -2,14 +2,34 @@ 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
|
||||||
scrolloff int
|
scrolloff int
|
||||||
@@ -19,23 +39,21 @@ 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.scrolloff = 0
|
gOpts.scrolloff = 0
|
||||||
@@ -43,48 +61,48 @@ func init() {
|
|||||||
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{"bot", 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{"shell", nil}
|
gOpts.keys["$"] = &callExpr{"shell", nil, 1}
|
||||||
gOpts.keys["%"] = &callExpr{"shell-pipe", nil}
|
gOpts.keys["%"] = &callExpr{"shell-pipe", nil, 1}
|
||||||
gOpts.keys["!"] = &callExpr{"shell-wait", nil}
|
gOpts.keys["!"] = &callExpr{"shell-wait", nil, 1}
|
||||||
gOpts.keys["&"] = &callExpr{"shell-async", nil}
|
gOpts.keys["&"] = &callExpr{"shell-async", nil, 1}
|
||||||
gOpts.keys["/"] = &callExpr{"search", nil}
|
gOpts.keys["/"] = &callExpr{"search", nil, 1}
|
||||||
gOpts.keys["?"] = &callExpr{"search-back", nil}
|
gOpts.keys["?"] = &callExpr{"search-back", nil, 1}
|
||||||
gOpts.keys["n"] = &callExpr{"search-next", nil}
|
gOpts.keys["n"] = &callExpr{"search-next", nil, 1}
|
||||||
gOpts.keys["N"] = &callExpr{"search-prev", nil}
|
gOpts.keys["N"] = &callExpr{"search-prev", nil, 1}
|
||||||
gOpts.keys["<c-n>"] = &callExpr{"cmd-hist-next", nil}
|
gOpts.keys["<c-n>"] = &callExpr{"cmd-hist-next", nil, 1}
|
||||||
gOpts.keys["<c-p>"] = &callExpr{"cmd-hist-prev", nil}
|
gOpts.keys["<c-p>"] = &callExpr{"cmd-hist-prev", nil, 1}
|
||||||
|
|
||||||
gOpts.keys["zh"] = &setExpr{"hidden!", ""}
|
gOpts.keys["zh"] = &setExpr{"hidden!", ""}
|
||||||
gOpts.keys["zr"] = &setExpr{"reverse!", ""}
|
gOpts.keys["zr"] = &setExpr{"reverse!", ""}
|
||||||
@@ -95,36 +113,36 @@ 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
|
// TODO: rest of the keys
|
||||||
gOpts.cmdkeys["<space>"] = &callExpr{"cmd-insert", []string{" "}}
|
gOpts.cmdkeys["<space>"] = &callExpr{"cmd-insert", []string{" "}, 1}
|
||||||
gOpts.cmdkeys["<esc>"] = &callExpr{"cmd-escape", nil}
|
gOpts.cmdkeys["<esc>"] = &callExpr{"cmd-escape", nil, 1}
|
||||||
gOpts.cmdkeys["<tab>"] = &callExpr{"cmd-comp", nil}
|
gOpts.cmdkeys["<tab>"] = &callExpr{"cmd-comp", nil, 1}
|
||||||
gOpts.cmdkeys["<enter>"] = &callExpr{"cmd-enter", nil}
|
gOpts.cmdkeys["<enter>"] = &callExpr{"cmd-enter", nil, 1}
|
||||||
gOpts.cmdkeys["<c-j>"] = &callExpr{"cmd-enter", nil}
|
gOpts.cmdkeys["<c-j>"] = &callExpr{"cmd-enter", nil, 1}
|
||||||
gOpts.cmdkeys["<c-n>"] = &callExpr{"cmd-hist-next", nil}
|
gOpts.cmdkeys["<c-n>"] = &callExpr{"cmd-hist-next", nil, 1}
|
||||||
gOpts.cmdkeys["<c-p>"] = &callExpr{"cmd-hist-prev", nil}
|
gOpts.cmdkeys["<c-p>"] = &callExpr{"cmd-hist-prev", nil, 1}
|
||||||
gOpts.cmdkeys["<delete>"] = &callExpr{"cmd-delete", nil}
|
gOpts.cmdkeys["<delete>"] = &callExpr{"cmd-delete", nil, 1}
|
||||||
gOpts.cmdkeys["<c-d>"] = &callExpr{"cmd-delete", nil}
|
gOpts.cmdkeys["<c-d>"] = &callExpr{"cmd-delete", nil, 1}
|
||||||
gOpts.cmdkeys["<bs>"] = &callExpr{"cmd-delete-back", nil}
|
gOpts.cmdkeys["<bs>"] = &callExpr{"cmd-delete-back", nil, 1}
|
||||||
gOpts.cmdkeys["<bs2>"] = &callExpr{"cmd-delete-back", nil}
|
gOpts.cmdkeys["<bs2>"] = &callExpr{"cmd-delete-back", nil, 1}
|
||||||
gOpts.cmdkeys["<left>"] = &callExpr{"cmd-left", nil}
|
gOpts.cmdkeys["<left>"] = &callExpr{"cmd-left", nil, 1}
|
||||||
gOpts.cmdkeys["<c-b>"] = &callExpr{"cmd-left", nil}
|
gOpts.cmdkeys["<c-b>"] = &callExpr{"cmd-left", nil, 1}
|
||||||
gOpts.cmdkeys["<right>"] = &callExpr{"cmd-right", nil}
|
gOpts.cmdkeys["<right>"] = &callExpr{"cmd-right", nil, 1}
|
||||||
gOpts.cmdkeys["<c-f>"] = &callExpr{"cmd-right", nil}
|
gOpts.cmdkeys["<c-f>"] = &callExpr{"cmd-right", nil, 1}
|
||||||
gOpts.cmdkeys["<home>"] = &callExpr{"cmd-beg", nil}
|
gOpts.cmdkeys["<home>"] = &callExpr{"cmd-beg", nil, 1}
|
||||||
gOpts.cmdkeys["<c-a>"] = &callExpr{"cmd-beg", nil}
|
gOpts.cmdkeys["<c-a>"] = &callExpr{"cmd-beg", nil, 1}
|
||||||
gOpts.cmdkeys["<end>"] = &callExpr{"cmd-end", nil}
|
gOpts.cmdkeys["<end>"] = &callExpr{"cmd-end", nil, 1}
|
||||||
gOpts.cmdkeys["<c-e>"] = &callExpr{"cmd-end", nil}
|
gOpts.cmdkeys["<c-e>"] = &callExpr{"cmd-end", nil, 1}
|
||||||
gOpts.cmdkeys["<c-u>"] = &callExpr{"cmd-delete-beg", nil}
|
gOpts.cmdkeys["<c-u>"] = &callExpr{"cmd-delete-beg", nil, 1}
|
||||||
gOpts.cmdkeys["<c-k>"] = &callExpr{"cmd-delete-end", nil}
|
gOpts.cmdkeys["<c-k>"] = &callExpr{"cmd-delete-end", nil, 1}
|
||||||
gOpts.cmdkeys["<c-w>"] = &callExpr{"cmd-delete-word", nil}
|
gOpts.cmdkeys["<c-w>"] = &callExpr{"cmd-delete-word", nil, 1}
|
||||||
gOpts.cmdkeys["<c-y>"] = &callExpr{"cmd-put", nil}
|
gOpts.cmdkeys["<c-y>"] = &callExpr{"cmd-put", nil, 1}
|
||||||
gOpts.cmdkeys["<c-t>"] = &callExpr{"cmd-transpose", nil}
|
gOpts.cmdkeys["<c-t>"] = &callExpr{"cmd-transpose", nil, 1}
|
||||||
gOpts.cmdkeys["<c-c>"] = &callExpr{"cmd-interrupt", nil}
|
gOpts.cmdkeys["<c-c>"] = &callExpr{"cmd-interrupt", nil, 1}
|
||||||
|
|
||||||
gOpts.cmds = make(map[string]expr)
|
gOpts.cmds = make(map[string]expr)
|
||||||
|
|
||||||
|
|||||||
@@ -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()
|
||||||
|
|||||||
@@ -18,10 +18,7 @@ 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 gAnsiCodes = map[int]termbox.Attribute{
|
||||||
0: termbox.ColorDefault,
|
0: termbox.ColorDefault,
|
||||||
@@ -126,60 +123,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
|
||||||
@@ -267,94 +210,11 @@ 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 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if dir == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
fg, bg := termbox.ColorDefault, termbox.ColorDefault
|
|
||||||
|
|
||||||
if dir.loading {
|
|
||||||
fg = termbox.AttrBold
|
|
||||||
win.print(2, 0, fg, bg, "loading...")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(dir.fi) == 0 {
|
|
||||||
fg = termbox.AttrBold
|
|
||||||
win.print(2, 0, fg, bg, "empty")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
maxind := len(dir.fi) - 1
|
|
||||||
|
|
||||||
beg := max(dir.ind-dir.pos, 0)
|
|
||||||
end := min(beg+win.h, maxind+1)
|
|
||||||
|
|
||||||
for i, f := range dir.fi[beg:end] {
|
|
||||||
switch {
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
path := filepath.Join(dir.path, f.Name())
|
|
||||||
|
|
||||||
if _, ok := marks[path]; ok {
|
|
||||||
win.print(0, i, fg, termbox.ColorMagenta, " ")
|
|
||||||
} else if copy, ok := saves[path]; ok {
|
|
||||||
if copy {
|
|
||||||
win.print(0, i, fg, termbox.ColorYellow, " ")
|
|
||||||
} else {
|
|
||||||
win.print(0, i, fg, termbox.ColorRed, " ")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if i == dir.pos {
|
|
||||||
fg |= termbox.AttrReverse
|
|
||||||
}
|
|
||||||
|
|
||||||
var s []rune
|
|
||||||
|
|
||||||
s = append(s, ' ')
|
|
||||||
|
|
||||||
for _, r := range f.Name() {
|
|
||||||
s = append(s, r)
|
|
||||||
}
|
|
||||||
|
|
||||||
w := runeSliceWidth(s)
|
|
||||||
if w > win.w-2 {
|
|
||||||
s = runeSliceWidthRange(s, 0, win.w-2)
|
|
||||||
} else {
|
|
||||||
for i := 0; i < win.w-2-w; i++ {
|
|
||||||
s = append(s, ' ')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var info string
|
var info string
|
||||||
|
|
||||||
|
path := filepath.Join(d.path, f.Name())
|
||||||
|
|
||||||
for _, s := range gOpts.info {
|
for _, s := range gOpts.info {
|
||||||
switch s {
|
switch s {
|
||||||
case "size":
|
case "size":
|
||||||
@@ -394,14 +254,88 @@ func (win *win) printDir(dir *dir, marks map[string]int, saves map[string]bool)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(info) > 0 && win.w > 2*len(info) {
|
return info
|
||||||
s = runeSliceWidthRange(s, 0, win.w-2-len(info))
|
}
|
||||||
|
|
||||||
|
func (win *win) printDir(dir *dir, marks map[string]int, saves map[string]bool, colors colorMap) {
|
||||||
|
if win.w < 5 || dir == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
fg, bg := termbox.ColorDefault, termbox.ColorDefault
|
||||||
|
|
||||||
|
if dir.loading {
|
||||||
|
fg = termbox.AttrBold
|
||||||
|
win.print(2, 0, fg, bg, "loading...")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(dir.fi) == 0 {
|
||||||
|
fg = termbox.AttrBold
|
||||||
|
win.print(2, 0, fg, bg, "empty")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
beg := max(dir.ind-dir.pos, 0)
|
||||||
|
end := min(beg+win.h, len(dir.fi))
|
||||||
|
|
||||||
|
if beg > end {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, f := range dir.fi[beg:end] {
|
||||||
|
fg, bg = colors.get(f)
|
||||||
|
|
||||||
|
path := filepath.Join(dir.path, f.Name())
|
||||||
|
|
||||||
|
if _, ok := marks[path]; ok {
|
||||||
|
win.print(0, i, fg, termbox.ColorMagenta, " ")
|
||||||
|
} else if copy, ok := saves[path]; ok {
|
||||||
|
if copy {
|
||||||
|
win.print(0, i, fg, termbox.ColorYellow, " ")
|
||||||
|
} else {
|
||||||
|
win.print(0, i, fg, termbox.ColorRed, " ")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if i == dir.pos {
|
||||||
|
fg |= termbox.AttrReverse
|
||||||
|
}
|
||||||
|
|
||||||
|
var s []rune
|
||||||
|
|
||||||
|
s = append(s, ' ')
|
||||||
|
|
||||||
|
for _, r := range f.Name() {
|
||||||
|
s = append(s, r)
|
||||||
|
}
|
||||||
|
|
||||||
|
w := runeSliceWidth(s)
|
||||||
|
|
||||||
|
if w > win.w-3 {
|
||||||
|
s = runeSliceWidthRange(s, 0, win.w-4)
|
||||||
|
s = append(s, '~')
|
||||||
|
} else {
|
||||||
|
for i := 0; i < win.w-3-w; i++ {
|
||||||
|
s = append(s, ' ')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
info := fileInfo(f, dir)
|
||||||
|
|
||||||
|
if len(info) > 0 && win.w-2 > 2*len(info) {
|
||||||
|
if win.w-2 > w+len(info) {
|
||||||
|
s = runeSliceWidthRange(s, 0, win.w-3-len(info))
|
||||||
|
} else {
|
||||||
|
s = runeSliceWidthRange(s, 0, win.w-4-len(info))
|
||||||
|
s = append(s, '~')
|
||||||
|
}
|
||||||
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,7 +349,7 @@ type ui struct {
|
|||||||
msg string
|
msg string
|
||||||
regPrev *reg
|
regPrev *reg
|
||||||
dirPrev *dir
|
dirPrev *dir
|
||||||
exprChan chan multiExpr
|
exprChan chan expr
|
||||||
keyChan chan string
|
keyChan chan string
|
||||||
evChan chan termbox.Event
|
evChan chan termbox.Event
|
||||||
menuBuf *bytes.Buffer
|
menuBuf *bytes.Buffer
|
||||||
@@ -425,6 +359,7 @@ type ui struct {
|
|||||||
cmdBuf []rune
|
cmdBuf []rune
|
||||||
keyAcc []rune
|
keyAcc []rune
|
||||||
keyCount []rune
|
keyCount []rune
|
||||||
|
colors colorMap
|
||||||
}
|
}
|
||||||
|
|
||||||
func getWidths(wtot int) []int {
|
func getWidths(wtot int) []int {
|
||||||
@@ -443,6 +378,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -456,7 +395,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]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -481,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(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -492,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) {
|
||||||
@@ -586,12 +545,44 @@ func (ui *ui) drawStatLine(nav *nav) {
|
|||||||
|
|
||||||
tot := len(currDir.fi)
|
tot := len(currDir.fi)
|
||||||
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
|
||||||
|
|
||||||
@@ -609,7 +600,7 @@ 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ui.cmdPrefix {
|
switch ui.cmdPrefix {
|
||||||
@@ -635,13 +626,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")
|
||||||
|
|
||||||
@@ -650,6 +645,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, "")
|
||||||
@@ -727,24 +726,19 @@ func (ui *ui) pollEvent() termbox.Event {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type multiExpr struct {
|
func readCmdEvent(ch chan<- expr, ev termbox.Event) {
|
||||||
expr expr
|
|
||||||
count int
|
|
||||||
}
|
|
||||||
|
|
||||||
func readCmdEvent(ch chan<- multiExpr, ev termbox.Event) {
|
|
||||||
if ev.Ch != 0 {
|
if ev.Ch != 0 {
|
||||||
ch <- multiExpr{&callExpr{"cmd-insert", []string{string(ev.Ch)}}, 1}
|
ch <- &callExpr{"cmd-insert", []string{string(ev.Ch)}, 1}
|
||||||
} else {
|
} else {
|
||||||
val := gKeyVal[ev.Key]
|
val := gKeyVal[ev.Key]
|
||||||
if expr, ok := gOpts.cmdkeys[string(val)]; ok {
|
if expr, ok := gOpts.cmdkeys[string(val)]; ok {
|
||||||
ch <- multiExpr{expr, 1}
|
ch <- expr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ui *ui) readEvent(ch chan<- multiExpr, ev termbox.Event) {
|
func (ui *ui) readEvent(ch chan<- expr, ev termbox.Event) {
|
||||||
redraw := &callExpr{"redraw", nil}
|
draw := &callExpr{"draw", nil, 1}
|
||||||
count := 1
|
count := 1
|
||||||
|
|
||||||
switch ev.Type {
|
switch ev.Type {
|
||||||
@@ -763,19 +757,24 @@ 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 string(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, 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))
|
||||||
|
|
||||||
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
|
||||||
@@ -791,15 +790,16 @@ 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 {
|
||||||
@@ -814,19 +814,20 @@ 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:
|
default:
|
||||||
// TODO: handle other events
|
// TODO: handle other events
|
||||||
}
|
}
|
||||||
@@ -835,13 +836,13 @@ func (ui *ui) readEvent(ch chan<- multiExpr, ev termbox.Event) {
|
|||||||
// This function is used to read expressions on the client side. Digits are
|
// This function is used to read expressions on the client side. Digits are
|
||||||
// interpreted as command counts but this is only done for digits preceding any
|
// interpreted as command counts but this is only done for digits preceding any
|
||||||
// non-digit characters (e.g. "42y2k" as 42 times "y2k").
|
// non-digit characters (e.g. "42y2k" as 42 times "y2k").
|
||||||
func (ui *ui) readExpr() <-chan multiExpr {
|
func (ui *ui) readExpr() <-chan expr {
|
||||||
ch := make(chan multiExpr)
|
ch := make(chan expr)
|
||||||
|
|
||||||
ui.exprChan = ch
|
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