Browse user home dir by default

This commit is contained in:
Trevor Slocum 2020-02-24 08:33:03 -08:00
parent cef0c8414c
commit 4c22c8edea
6 changed files with 84 additions and 94 deletions

View File

@ -1,5 +1,4 @@
# adbfm
[![GoDoc](https://godoc.org/gitlab.com/tslocum/adbfm?status.svg)](https://godoc.org/gitlab.com/tslocum/adbfm)
[![CI status](https://gitlab.com/tslocum/adbfm/badges/master/pipeline.svg)](https://gitlab.com/tslocum/adbfm/commits/master)
[![Donate](https://img.shields.io/liberapay/receives/rocketnine.space.svg?logo=liberapay)](https://liberapay.com/rocketnine.space)
@ -9,10 +8,6 @@ ADB file manager
* [zach-klippenstein/goadb](https://github.com/zach-klippenstein/goadb)
## Documentation
Documentation is available via [gdooc](https://godoc.org/gitlab.com/tslocum/adbfm).
## Support
Please share issues/suggestions [here](https://gitlab.com/tslocum/adbfm/issues).

View File

@ -1,7 +1,6 @@
package main
import (
"fmt"
"log"
"os"
"path/filepath"
@ -17,8 +16,8 @@ var (
inputConfig = cbind.NewConfiguration()
devicesDropDown *cview.DropDown
localBuffer *cview.TextView
remoteBuffer *cview.TextView
localBuffer *cview.List
remoteBuffer *cview.List
currentFocus = 0
)
@ -30,13 +29,13 @@ func initTUI() error {
}
if len(devices) == 0 {
log.Fatal("no devices")
log.Fatal("connect to a device via ADB before launching")
}
cview.Styles.TitleColor = tcell.ColorDefault
/*cview.Styles.TitleColor = tcell.ColorDefault
cview.Styles.BorderColor = tcell.ColorDefault
cview.Styles.PrimaryTextColor = tcell.ColorDefault
cview.Styles.PrimitiveBackgroundColor = tcell.ColorDefault
cview.Styles.PrimitiveBackgroundColor = tcell.ColorDefault*/
app = cview.NewApplication().
SetInputCapture(inputConfig.Capture)
@ -46,10 +45,10 @@ func initTUI() error {
devicesDropDown.AddOption(device.Serial, setDeviceFunc(adb, device))
}
localBuffer = cview.NewTextView().SetWrap(true).SetWordWrap(false)
localBuffer = cview.NewList().ShowSecondaryText(false).SetScrollBarVisibility(cview.ScrollBarAlways)
localBuffer.SetTitleAlign(cview.AlignLeft).SetBorder(true)
remoteBuffer = cview.NewTextView().SetWrap(true).SetWordWrap(false)
remoteBuffer = cview.NewList().ShowSecondaryText(false).SetScrollBarVisibility(cview.ScrollBarAlways)
remoteBuffer.SetTitleAlign(cview.AlignLeft).SetBorder(true)
// Select first device
@ -84,18 +83,23 @@ func focusUpdated() {
}
}
func listLocalDir(p string) {
func browseLocal(p string) {
var entries []string
var skippedFirst bool
err := filepath.Walk(p, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() {
} else if !skippedFirst {
skippedFirst = true
return nil
}
// TODO Store entries with more info
entries = append(entries, info.Name())
if info.IsDir() {
return filepath.SkipDir
}
return nil
})
if err != nil {
@ -106,6 +110,21 @@ func listLocalDir(p string) {
localBuffer.Clear()
for _, entry := range entries {
fmt.Fprintf(localBuffer, entry+"\n")
localBuffer.AddItem(entry, "", 0, nil)
}
}
func browseRemote(p string) {
entries, err := adb.DirectoryEntries(p)
if err != nil {
log.Fatalf("failed to list files: %s", err)
}
go app.QueueUpdateDraw(func() {
remoteBuffer.Clear()
remoteBuffer.SetTitle(" " + p + " ")
for _, entry := range entries {
remoteBuffer.AddItem(entry.Name, "", 0, nil)
}
})
}

View File

@ -11,42 +11,6 @@ func selectItem(ev *tcell.EventKey) *tcell.EventKey {
}
func previousItem(ev *tcell.EventKey) *tcell.EventKey {
if currentFocus == 0 {
return ev
}
return nil
}
func nextItem(ev *tcell.EventKey) *tcell.EventKey {
if currentFocus == 0 {
return ev
}
return nil
}
func previousPage(ev *tcell.EventKey) *tcell.EventKey {
if currentFocus == 0 {
return ev
}
return nil
}
func nextPage(ev *tcell.EventKey) *tcell.EventKey {
if currentFocus == 0 {
return ev
}
return nil
}
func previousField(_ *tcell.EventKey) *tcell.EventKey {
if currentFocus > 0 {
currentFocus--

View File

@ -1,8 +1,10 @@
package main
import (
"flag"
"fmt"
"log"
"os"
"strings"
"github.com/gdamore/tcell"
@ -11,6 +13,8 @@ import (
"gitlab.com/tslocum/cbind"
)
const defaultRemotePath = "/storage/emulated/0/Android/data"
type appConfig struct {
Input map[string][]string // Keybinds
}
@ -18,6 +22,9 @@ type appConfig struct {
var config = &appConfig{}
var (
localPath string
remotePath string
adb *android.ADB
done = make(chan bool)
@ -25,10 +32,6 @@ var (
const (
actionSelect = "select"
actionPreviousItem = "previous-item"
actionNextItem = "next-item"
actionPreviousPage = "previous-page"
actionNextPage = "next-page"
actionPreviousField = "previous-field"
actionNextField = "next-field"
actionExit = "exit"
@ -36,10 +39,6 @@ const (
var actionHandlers = map[string]func(*tcell.EventKey) *tcell.EventKey{
actionSelect: selectItem,
actionPreviousItem: previousItem,
actionNextItem: nextItem,
actionPreviousPage: previousPage,
actionNextPage: nextPage,
actionPreviousField: previousField,
actionNextField: nextField,
actionExit: exit,
@ -77,10 +76,6 @@ func setKeyBinds() error {
func setDefaultKeyBinds() {
config.Input = map[string][]string{
actionSelect: {"Enter"},
actionPreviousItem: {"Up", "k"},
actionNextItem: {"Down", "j"},
actionPreviousPage: {"PageUp"},
actionNextPage: {"PageDown"},
actionPreviousField: {"Backtab"},
actionNextField: {"Tab"},
actionExit: {"Alt+q"},
@ -94,24 +89,29 @@ func setDeviceFunc(adb *android.ADB, device *goadb.DeviceInfo) func() {
log.Fatal(err)
}
remoteBuffer.Clear()
p := "/storage/emulated/0"
remoteBuffer.SetTitle(" " + p + " ")
entries, err := adb.DirectoryEntries(p)
if err != nil {
log.Fatalf("failed to list files: %s", err)
}
for _, entry := range entries {
fmt.Fprintf(remoteBuffer, entry.Name+"\n")
}
browseRemote(remotePath)
}
}
func main() {
flag.StringVar(&localPath, "local", "", "local starting directory")
flag.StringVar(&remotePath, "remote", "", "remote starting directory")
flag.Parse()
if localPath == "" {
homeDir, err := os.UserHomeDir()
if err == nil && homeDir != "" {
localPath = homeDir
}
}
if localPath == "" {
log.Fatalf("failed to start adbfm: local path must be specified with --local")
}
if remotePath == "" {
remotePath = defaultRemotePath
}
var err error
adb, err = android.NewADB("", 0, "")
if err != nil {
@ -128,7 +128,7 @@ func main() {
log.Fatalf("failed to initialize user interface: %s", err)
}
listLocalDir("/home/trevor/Downloads")
browseLocal(localPath)
go func() {
if err := app.Run(); err != nil {

7
go.mod
View File

@ -4,8 +4,9 @@ go 1.13
require (
github.com/gdamore/tcell v1.3.0
github.com/stretchr/testify v1.4.0 // indirect
github.com/zach-klippenstein/goadb v0.0.0-20170530005145-029cc6bee481
gitlab.com/tslocum/cbind v0.1.0
gitlab.com/tslocum/cview v1.4.2-0.20200128151041-339db80f666d
golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9 // indirect
gitlab.com/tslocum/cbind v0.1.1
gitlab.com/tslocum/cview v1.4.4-0.20200224155434-eb2600c8573d
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae // indirect
)

31
go.sum
View File

@ -1,4 +1,6 @@
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
github.com/gdamore/tcell v1.3.0 h1:r35w0JBADPZCVQijYebl6YMWWtHRqVEGt7kL2eBADRM=
@ -7,24 +9,33 @@ github.com/lucasb-eyer/go-colorful v1.0.2/go.mod h1:0MS4r+7BZKSJ5mw4/S5MPN+qHFF1
github.com/lucasb-eyer/go-colorful v1.0.3 h1:QIbQXiugsb+q10B+MI+7DI1oQLdmnep86tWFlaaUAac=
github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54=
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.8 h1:3tS41NlGYSmhhe/8fhGRzc+z3AYCw1Fe1WAyLuujKs0=
github.com/mattn/go-runewidth v0.0.8/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/zach-klippenstein/goadb v0.0.0-20170530005145-029cc6bee481 h1:yVrbGOZZHihWLaa3xpaTKoO5FbYg/vG5hUufn429HAo=
github.com/zach-klippenstein/goadb v0.0.0-20170530005145-029cc6bee481/go.mod h1:Drd+klC4FSDx0vKNEQDsSpWX5so04NA7l0vzHqkH8AQ=
gitlab.com/tslocum/cbind v0.1.0 h1:Ot6y7K6mwp7Qp/MWOH5cuhf/VC5HKpJaWFvgzMC8nnM=
gitlab.com/tslocum/cbind v0.1.0/go.mod h1:xxuB0UqPYytWTkjI0l2VzOJJzqvIUf18r6YahPXYDd8=
gitlab.com/tslocum/cview v1.4.2-0.20200128151041-339db80f666d h1:5rPwwmNYGLcOsyawvAw7m/Jtwp5rAuvLoqVW5k09AP0=
gitlab.com/tslocum/cview v1.4.2-0.20200128151041-339db80f666d/go.mod h1:QbxliYQa2I32UJH2boP54jq6tnWlgm6yViaFXKGDfuM=
gitlab.com/tslocum/cbind v0.1.1 h1:JXXtxMWHgWLvoF+QkrvcNvOQ59juy7OE1RhT7hZfdt0=
gitlab.com/tslocum/cbind v0.1.1/go.mod h1:rX7vkl0pUSg/yy427MmD1FZAf99S7WwpUlxF/qTpPqk=
gitlab.com/tslocum/cview v1.4.4-0.20200224155434-eb2600c8573d h1:C66lgr32Vig6TRcO31aCmNX+QiG6qNnp4Lu4z/ho6/M=
gitlab.com/tslocum/cview v1.4.4-0.20200224155434-eb2600c8573d/go.mod h1:+bEf1cg6IoWvL16YHJAKwGGpQf5s/nxXAA7YJr+WOHE=
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200103143344-a1369afcdac7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9 h1:1/DFK4b7JH8DmkqhUk48onnSfrPzImPoVxuomtbT2nk=
golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5 h1:LfCXLvNmTYH9kEmVgqbnsWfruoXZIrh4YBgqVHtDvw0=
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4 h1:sfkvUWPNGwSV+8/fNqctR5lS2AqCSqYwXdrjCxp/dXo=
golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=