Use new slices/cmp standard lib (#1834)
This commit is contained in:
1 parent
d9a6ca5766
commit
0b51987044
3 files changed
+25
-41
No files matched your search
@@ -7,6 +7,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -2111,8 +2112,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
}
|
||||
ind := locs[len(locs)-1][3]
|
||||
old := app.ui.cmdAccRight
|
||||
app.ui.cmdAccRight = append([]rune{}, []rune(string(app.ui.cmdAccLeft)[ind:])...)
|
||||
app.ui.cmdAccRight = append(app.ui.cmdAccRight, old...)
|
||||
app.ui.cmdAccRight = append([]rune(string(app.ui.cmdAccLeft)[ind:]), old...)
|
||||
app.ui.cmdAccLeft = []rune(string(app.ui.cmdAccLeft)[:ind])
|
||||
case "cmd-capitalize-word":
|
||||
if len(app.ui.cmdAccRight) == 0 {
|
||||
@@ -2205,15 +2205,13 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
beg1, end1 := locs[len(locs)-2][0], locs[len(locs)-2][1]
|
||||
beg2, end2 := locs[len(locs)-1][0], locs[len(locs)-1][1]
|
||||
|
||||
var acc []rune
|
||||
|
||||
acc = append(acc, []rune(string(app.ui.cmdAccLeft)[:beg1])...)
|
||||
acc = append(acc, []rune(string(app.ui.cmdAccLeft)[beg2:end2])...)
|
||||
acc = append(acc, []rune(string(app.ui.cmdAccLeft)[end1:beg2])...)
|
||||
acc = append(acc, []rune(string(app.ui.cmdAccLeft)[beg1:end1])...)
|
||||
acc = append(acc, []rune(string(app.ui.cmdAccLeft)[end2:])...)
|
||||
|
||||
app.ui.cmdAccLeft = acc
|
||||
app.ui.cmdAccLeft = slices.Concat(
|
||||
[]rune(string(app.ui.cmdAccLeft)[:beg1]),
|
||||
[]rune(string(app.ui.cmdAccLeft)[beg2:end2]),
|
||||
[]rune(string(app.ui.cmdAccLeft)[end1:beg2]),
|
||||
[]rune(string(app.ui.cmdAccLeft)[beg1:end1]),
|
||||
[]rune(string(app.ui.cmdAccLeft)[end2:]),
|
||||
)
|
||||
update(app)
|
||||
default:
|
||||
cmd, ok := gOpts.cmds[e.name]
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
@@ -53,10 +54,7 @@ func init() {
|
||||
}
|
||||
|
||||
if envEditor == "" {
|
||||
envEditor = os.Getenv("EDITOR")
|
||||
if envEditor == "" {
|
||||
envEditor = "vi"
|
||||
}
|
||||
envEditor = cmp.Or(os.Getenv("EDITOR"), "vi")
|
||||
}
|
||||
|
||||
if envPager == "" {
|
||||
@@ -86,13 +84,11 @@ func init() {
|
||||
}
|
||||
gUser = u
|
||||
|
||||
config := os.Getenv("LF_CONFIG_HOME")
|
||||
if config == "" {
|
||||
config = os.Getenv("XDG_CONFIG_HOME")
|
||||
}
|
||||
if config == "" {
|
||||
config = filepath.Join(gUser.HomeDir, ".config")
|
||||
}
|
||||
config := cmp.Or(
|
||||
os.Getenv("LF_CONFIG_HOME"),
|
||||
os.Getenv("XDG_CONFIG_HOME"),
|
||||
filepath.Join(gUser.HomeDir, ".config"),
|
||||
)
|
||||
|
||||
gConfigPaths = []string{
|
||||
filepath.Join("/etc", "lf", "lfrc"),
|
||||
@@ -109,23 +105,18 @@ func init() {
|
||||
filepath.Join(config, "lf", "icons"),
|
||||
}
|
||||
|
||||
data := os.Getenv("LF_DATA_HOME")
|
||||
if data == "" {
|
||||
data = os.Getenv("XDG_DATA_HOME")
|
||||
}
|
||||
if data == "" {
|
||||
data = filepath.Join(gUser.HomeDir, ".local", "share")
|
||||
}
|
||||
data := cmp.Or(
|
||||
os.Getenv("LF_DATA_HOME"),
|
||||
os.Getenv("XDG_DATA_HOME"),
|
||||
filepath.Join(gUser.HomeDir, ".local", "share"),
|
||||
)
|
||||
|
||||
gFilesPath = filepath.Join(data, "lf", "files")
|
||||
gMarksPath = filepath.Join(data, "lf", "marks")
|
||||
gTagsPath = filepath.Join(data, "lf", "tags")
|
||||
gHistoryPath = filepath.Join(data, "lf", "history")
|
||||
|
||||
runtime := os.Getenv("XDG_RUNTIME_DIR")
|
||||
if runtime == "" {
|
||||
runtime = os.TempDir()
|
||||
}
|
||||
runtime := cmp.Or(os.Getenv("XDG_RUNTIME_DIR"), os.TempDir())
|
||||
|
||||
gDefaultSocketPath = filepath.Join(runtime, fmt.Sprintf("lf.%s.sock", gUser.Username))
|
||||
}
|
||||
|
||||
+3
-8
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
@@ -47,10 +48,7 @@ func init() {
|
||||
}
|
||||
|
||||
if envEditor == "" {
|
||||
envEditor = os.Getenv("EDITOR")
|
||||
if envEditor == "" {
|
||||
envEditor = "notepad"
|
||||
}
|
||||
envEditor = cmp.Or(os.Getenv("EDITOR"), "notepad")
|
||||
}
|
||||
|
||||
if envPager == "" {
|
||||
@@ -76,10 +74,7 @@ func init() {
|
||||
Username: username,
|
||||
}
|
||||
|
||||
data := os.Getenv("LF_CONFIG_HOME")
|
||||
if data == "" {
|
||||
data = os.Getenv("LOCALAPPDATA")
|
||||
}
|
||||
data := cmp.Or(os.Getenv("LF_CONFIG_HOME"), os.Getenv("LOCALAPPDATA"))
|
||||
|
||||
gConfigPaths = []string{
|
||||
filepath.Join(os.Getenv("ProgramData"), "lf", "lfrc"),
|
||||
|
||||
Reference in new issue
Block a user