Compare commits

5 Commits
Author SHA1 Message Date
Gokcehan 9d451ffd19 use ascii space/digits in scanner
cc #572
2021-01-30 18:29:32 +03:00
Gokcehan 2aa50aecaf show unknown mapping error for unbind mouse events
cc #268 #570
2021-01-29 19:47:28 +03:00
Gokcehan 13d19d84f9 add 'mouse' option to enable/disable mouse events
cc #268 #570
2021-01-29 19:36:27 +03:00
neeshy 1163efb7aa Avoid redundantly loading previews for search/find (#569)
* Avoid redundantly loading previews for find

* Avoid redundantly loading previews for search
2021-01-29 18:27:27 +03:00
Gokcehan c6cf0e61ba only combine non-spacing mark characters
cc #565
2021-01-27 02:22:40 +03:00
10 changed files with 145 additions and 94 deletions

No files matched your search

+3 -1
View File
@@ -21,7 +21,9 @@ func run() {
} else if err = screen.Init(); err != nil {
log.Fatalf("initializing screen: %s", err)
}
screen.EnableMouse()
if gOpts.mouse {
screen.EnableMouse()
}
f, err := os.Create(gLogPath)
if err != nil {
+3
View File
@@ -97,6 +97,9 @@ var (
"incsearch",
"noincsearch",
"incsearch!",
"mouse",
"nomouse",
"mouse!",
"number",
"nonumber",
"number!",
+5
View File
@@ -114,6 +114,7 @@ The following options can be used to customize the behavior of lf:
ignoredia bool (default on)
incsearch bool (default off)
info []string (default '')
mouse bool (default off)
number bool (default off)
period int (default 0)
preview bool (default on)
@@ -569,6 +570,10 @@ List of information shown for directory items at the right side of pane.
Currently supported information types are 'size', 'time', 'atime', and 'ctime'.
Information is only shown when the pane width is more than twice the width of information.
mouse bool (default off)
Send mouse events as input.
number bool (default off)
Show the position number for directory items at the left side of pane.
+5
View File
@@ -117,6 +117,7 @@ The following options can be used to customize the behavior of lf:
ignoredia bool (default on)
incsearch bool (default off)
info []string (default '')
mouse bool (default off)
number bool (default off)
period int (default 0)
preview bool (default on)
@@ -600,6 +601,10 @@ Currently supported information types are 'size', 'time', 'atime', and
'ctime'. Information is only shown when the pane width is more than twice
the width of information.
mouse bool (default off)
Send mouse events as input.
number bool (default off)
Show the position number for directory items at the left side of pane. When
+73 -40
View File
@@ -110,6 +110,24 @@ func (e *setExpr) eval(app *app, args []string) {
gOpts.incsearch = false
case "incsearch!":
gOpts.incsearch = !gOpts.incsearch
case "mouse":
if !gOpts.mouse {
gOpts.mouse = true
app.ui.screen.EnableMouse()
}
case "nomouse":
if gOpts.mouse {
gOpts.mouse = false
app.ui.screen.DisableMouse()
}
case "mouse!":
if gOpts.mouse {
gOpts.mouse = false
app.ui.screen.DisableMouse()
} else {
gOpts.mouse = true
app.ui.screen.EnableMouse()
}
case "number":
gOpts.number = true
case "nonumber":
@@ -393,30 +411,30 @@ func update(app *app) {
app.nav.search = string(app.ui.cmdAccLeft) + string(app.ui.cmdAccRight)
dir := app.nav.currDir()
old := dir.ind
dir.ind = app.nav.searchInd
dir.pos = app.nav.searchPos
if err := app.nav.searchNext(); err != nil {
if _, err := app.nav.searchNext(); err != nil {
app.ui.echoerrf("search: %s: %s", err, app.nav.search)
return
} else if old != dir.ind {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
case gOpts.incsearch && app.ui.cmdPrefix == "?":
app.nav.search = string(app.ui.cmdAccLeft) + string(app.ui.cmdAccRight)
dir := app.nav.currDir()
old := dir.ind
dir.ind = app.nav.searchInd
dir.pos = app.nav.searchPos
if err := app.nav.searchPrev(); err != nil {
if _, err := app.nav.searchPrev(); err != nil {
app.ui.echoerrf("search: %s: %s", err, app.nav.search)
return
} else if old != dir.ind {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
}
@@ -455,9 +473,9 @@ func insert(app *app, arg string) {
return
}
if !app.nav.findNext() {
if moved, found := app.nav.findNext(); !found {
app.ui.echoerrf("find: pattern not found: %s", app.nav.find)
} else {
} else if moved {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
@@ -484,9 +502,9 @@ func insert(app *app, arg string) {
return
}
if !app.nav.findPrev() {
if moved, found := app.nav.findPrev(); !found {
app.ui.echoerrf("find-back: pattern not found: %s", app.nav.find)
} else {
} else if moved {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
@@ -854,6 +872,8 @@ func (e *callExpr) eval(app *app, args []string) {
app.nav.findBack = true
app.ui.loadFileInfo(app.nav)
case "find-next":
dir := app.nav.currDir()
old := dir.ind
for i := 0; i < e.count; i++ {
if app.nav.findBack {
app.nav.findPrev()
@@ -861,9 +881,13 @@ func (e *callExpr) eval(app *app, args []string) {
app.nav.findNext()
}
}
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
if old != dir.ind {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
case "find-prev":
dir := app.nav.currDir()
old := dir.ind
for i := 0; i < e.count; i++ {
if app.nav.findBack {
app.nav.findNext()
@@ -871,8 +895,10 @@ func (e *callExpr) eval(app *app, args []string) {
app.nav.findPrev()
}
}
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
if old != dir.ind {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
case "search":
app.ui.cmdPrefix = "/"
dir := app.nav.currDir()
@@ -890,35 +916,39 @@ func (e *callExpr) eval(app *app, args []string) {
case "search-next":
for i := 0; i < e.count; i++ {
if app.nav.searchBack {
if err := app.nav.searchPrev(); err != nil {
if moved, err := app.nav.searchPrev(); err != nil {
app.ui.echoerrf("search-back: %s: %s", err, app.nav.search)
return
} else if moved {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
} else {
if err := app.nav.searchNext(); err != nil {
if moved, err := app.nav.searchNext(); err != nil {
app.ui.echoerrf("search: %s: %s", err, app.nav.search)
return
} else if moved {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
}
}
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
case "search-prev":
for i := 0; i < e.count; i++ {
if app.nav.searchBack {
if err := app.nav.searchNext(); err != nil {
if moved, err := app.nav.searchNext(); err != nil {
app.ui.echoerrf("search-back: %s: %s", err, app.nav.search)
return
} else if moved {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
} else {
if err := app.nav.searchPrev(); err != nil {
if moved, err := app.nav.searchPrev(); err != nil {
app.ui.echoerrf("search: %s: %s", err, app.nav.search)
return
} else if moved {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
}
}
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
case "mark-save":
app.ui.cmdPrefix = "mark-save: "
case "mark-load":
@@ -1067,11 +1097,12 @@ func (e *callExpr) eval(app *app, args []string) {
}
if gOpts.incsearch && (app.ui.cmdPrefix == "/" || app.ui.cmdPrefix == "?") {
dir := app.nav.currDir()
dir.ind = app.nav.searchInd
dir.pos = app.nav.searchPos
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
if dir.ind != app.nav.searchInd {
dir.ind = app.nav.searchInd
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
}
normal(app)
case "cmd-complete":
@@ -1235,32 +1266,34 @@ func (e *callExpr) eval(app *app, args []string) {
app.cmdHistory = append(app.cmdHistory, cmdItem{"&", s})
app.runShell(s, nil, "&")
case "/":
dir := app.nav.currDir()
old := dir.ind
if gOpts.incsearch {
dir := app.nav.currDir()
dir.ind = app.nav.searchInd
dir.pos = app.nav.searchPos
}
log.Printf("search: %s", s)
app.ui.cmdPrefix = ""
app.nav.search = s
if err := app.nav.searchNext(); err != nil {
if _, err := app.nav.searchNext(); err != nil {
app.ui.echoerrf("search: %s: %s", err, app.nav.search)
} else {
} else if old != dir.ind {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
case "?":
dir := app.nav.currDir()
old := dir.ind
if gOpts.incsearch {
dir := app.nav.currDir()
dir.ind = app.nav.searchInd
dir.pos = app.nav.searchPos
}
log.Printf("search-back: %s", s)
app.ui.cmdPrefix = ""
app.nav.search = s
if err := app.nav.searchPrev(); err != nil {
if _, err := app.nav.searchPrev(); err != nil {
app.ui.echoerrf("search-back: %s: %s", err, app.nav.search)
} else {
} else if old != dir.ind {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
+7
View File
@@ -128,6 +128,7 @@ The following options can be used to customize the behavior of lf:
ignoredia bool (default on)
incsearch bool (default off)
info []string (default '')
mouse bool (default off)
number bool (default off)
period int (default 0)
preview bool (default on)
@@ -691,6 +692,12 @@ Jump to the first match after each keystroke during searching.
.PP
List of information shown for directory items at the right side of pane. Currently supported information types are 'size', 'time', 'atime', and 'ctime'. Information is only shown when the pane width is more than twice the width of information.
.PP
.EX
mouse bool (default off)
.EE
.PP
Send mouse events as input.
.PP
.EX
number bool (default off)
.EE
+28 -44
View File
@@ -1123,42 +1123,38 @@ func (nav *nav) findSingle() int {
return count
}
func (nav *nav) findNext() bool {
func (nav *nav) findNext() (bool, bool) {
dir := nav.currDir()
for i := dir.ind + 1; i < len(dir.files); i++ {
if findMatch(dir.files[i].Name(), nav.find) {
nav.down(i - dir.ind)
return true
return nav.down(i - dir.ind), true
}
}
if gOpts.wrapscan {
for i := 0; i < dir.ind; i++ {
if findMatch(dir.files[i].Name(), nav.find) {
nav.up(dir.ind - i)
return true
return nav.up(dir.ind - i), true
}
}
}
return false
return false, false
}
func (nav *nav) findPrev() bool {
func (nav *nav) findPrev() (bool, bool) {
dir := nav.currDir()
for i := dir.ind - 1; i >= 0; i-- {
if findMatch(dir.files[i].Name(), nav.find) {
nav.up(dir.ind - i)
return true
return nav.up(dir.ind - i), true
}
}
if gOpts.wrapscan {
for i := len(dir.files) - 1; i > dir.ind; i-- {
if findMatch(dir.files[i].Name(), nav.find) {
nav.down(i - dir.ind)
return true
return nav.down(i - dir.ind), true
}
}
}
return false
return false, false
}
func searchMatch(name, pattern string) (matched bool, err error) {
@@ -1182,58 +1178,46 @@ func searchMatch(name, pattern string) (matched bool, err error) {
return strings.Contains(name, pattern), nil
}
func (nav *nav) searchNext() error {
func (nav *nav) searchNext() (bool, error) {
dir := nav.currDir()
for i := dir.ind + 1; i < len(dir.files); i++ {
matched, err := searchMatch(dir.files[i].Name(), nav.search)
if err != nil {
return err
}
if matched {
nav.down(i - dir.ind)
return nil
if matched, err := searchMatch(dir.files[i].Name(), nav.search); err != nil {
return false, err
} else if matched {
return nav.down(i - dir.ind), nil
}
}
if gOpts.wrapscan {
for i := 0; i < dir.ind; i++ {
matched, err := searchMatch(dir.files[i].Name(), nav.search)
if err != nil {
return err
}
if matched {
nav.up(dir.ind - i)
return nil
if matched, err := searchMatch(dir.files[i].Name(), nav.search); err != nil {
return false, err
} else if matched {
return nav.up(dir.ind - i), nil
}
}
}
return nil
return false, nil
}
func (nav *nav) searchPrev() error {
func (nav *nav) searchPrev() (bool, error) {
dir := nav.currDir()
for i := dir.ind - 1; i >= 0; i-- {
matched, err := searchMatch(dir.files[i].Name(), nav.search)
if err != nil {
return err
}
if matched {
nav.up(dir.ind - i)
return nil
if matched, err := searchMatch(dir.files[i].Name(), nav.search); err != nil {
return false, err
} else if matched {
return nav.up(dir.ind - i), nil
}
}
if gOpts.wrapscan {
for i := len(dir.files) - 1; i > dir.ind; i-- {
matched, err := searchMatch(dir.files[i].Name(), nav.search)
if err != nil {
return err
}
if matched {
nav.down(i - dir.ind)
return nil
if matched, err := searchMatch(dir.files[i].Name(), nav.search); err != nil {
return false, err
} else if matched {
return nav.down(i - dir.ind), nil
}
}
}
return nil
return false, nil
}
func (nav *nav) removeMark(mark string) error {
+2
View File
@@ -36,6 +36,7 @@ var gOpts struct {
ignorecase bool
ignoredia bool
incsearch bool
mouse bool
number bool
preview bool
relativenumber bool
@@ -75,6 +76,7 @@ func init() {
gOpts.ignorecase = true
gOpts.ignoredia = true
gOpts.incsearch = false
gOpts.mouse = false
gOpts.number = false
gOpts.preview = true
gOpts.relativenumber = false
+11 -4
View File
@@ -5,7 +5,6 @@ import (
"io/ioutil"
"log"
"strconv"
"unicode"
)
type tokenType byte
@@ -82,15 +81,23 @@ func (s *scanner) peek() byte {
}
func isSpace(b byte) bool {
return unicode.IsSpace(rune(b))
switch b {
case '\t', '\n', '\v', '\f', '\r', ' ':
return true
}
return false
}
func isDigit(b byte) bool {
return unicode.IsDigit(rune(b))
return '0' <= b && b <= '9'
}
func isPrefix(b byte) bool {
return b == '$' || b == '%' || b == '!' || b == '&'
switch b {
case '$', '%', '!', '&':
return true
}
return false
}
func (s *scanner) scan() bool {
+8 -5
View File
@@ -211,7 +211,7 @@ func (win *win) print(screen tcell.Screen, x, y int, st tcell.Style, s string) t
for {
rc, wc := utf8.DecodeRuneInString(s[i+w:])
if rc == gEscapeCode || rc == '\t' || runewidth.RuneWidth(rc) != 0 {
if !unicode.Is(unicode.Mn, rc) {
break
}
comb = append(comb, rc)
@@ -1051,11 +1051,12 @@ func (ui *ui) readNormalEvent(ev tcell.Event) expr {
}
expr, ok := gOpts.keys[button]
if ok {
return expr
if !ok {
ui.echoerrf("unknown mapping: %s", button)
return draw
}
return nil
return expr
case *tcell.EventResize:
return &callExpr{"redraw", nil, 1}
case *tcell.EventError:
@@ -1122,7 +1123,9 @@ func (ui *ui) resume() {
} else if err = screen.Init(); err != nil {
log.Fatalf("initializing screen: %s", err)
}
screen.EnableMouse()
if gOpts.mouse {
screen.EnableMouse()
}
ui.screen = screen