Skip to content

Commit

Permalink
Replace termbox-go with tcell
Browse files Browse the repository at this point in the history
Fix colour construction issue

This also has a test to mitigate it in the future

Remove `colormode` option

The original issue it was trying to solve is no longer present with
tcell (it being a holdover from `color256` on termbox) so it is not
needed.

retire gitter channel in favor of irc/matrix

Export options as environment variables (#448)

* Export options as environment variables

Any options from gOpts are available via lf_OPTION environment
variables. For now it works only on booleans, integers and strings (no
array support)

* Do not export some of the options

* Add support for arrays and fix numbers

* Fix comments

* Replace 1 and 0 with true and false

* Export hidden,reverse,dirfirst and sortby options

* Fix comments

* Little fix

* Simplify boolean conversion

log readlink errors instead of fail

Related #447 and #374
  • Loading branch information
Provessor committed Sep 1, 2020
1 parent 2b445aa commit bca10c3
Show file tree
Hide file tree
Showing 20 changed files with 1,291 additions and 527 deletions.
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
language: go
install:
- go get github.com/doronbehar/termbox-go
- go get gopkg.in/djherbis/times.v1

go:
- 1.15.x

before_deploy:
- gen/xbuild.sh

deploy:
provider: releases
api_key:
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
[![Build Status](https://travis-ci.org/gokcehan/lf.svg?branch=master)](https://travis-ci.org/gokcehan/lf)
[![Go Report Card](https://goreportcard.com/badge/github.com/gokcehan/lf)](https://goreportcard.com/report/github.com/gokcehan/lf)
[![GoDoc](https://godoc.org/github.com/gokcehan/lf?status.svg)](https://godoc.org/github.com/gokcehan/lf)
[![Join the chat at https://gitter.im/lf-fm/Lobby](https://badges.gitter.im/lf-fm/Lobby.svg)](https://gitter.im/lf-fm/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

> This is a work in progress. Use at your own risk.
Expand Down
88 changes: 86 additions & 2 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ import (
"os/exec"
"os/signal"
"path/filepath"
"reflect"
"strconv"
"strings"
"syscall"
"time"

"github.com/gdamore/tcell"
)

type cmdItem struct {
Expand All @@ -32,8 +36,8 @@ type app struct {
cmdHistoryInd int
}

func newApp() *app {
ui := newUI()
func newApp(screen tcell.Screen) *app {
ui := newUI(screen)
nav := newNav(ui.wins[0].h)

quitChan := make(chan bool, 1)
Expand Down Expand Up @@ -333,6 +337,85 @@ func (app *app) exportFiles() {
exportFiles(currFile, currSelections)
}

func fieldToString(field reflect.Value) string {
kind := field.Kind()
var value string

switch kind {
case reflect.Int:
value = strconv.Itoa(int(field.Int()))
case reflect.Bool:
value = strconv.FormatBool(field.Bool())
case reflect.Slice:
for i := 0; i < field.Len(); i++ {
element := field.Index(i)

if i == 0 {
value = fieldToString(element)
} else {
value += ":" + fieldToString(element)
}
}
default:
value = field.String()
}

return value
}

func (app *app) exportOpts() {
e := reflect.ValueOf(&gOpts).Elem()

for i := 0; i < e.NumField(); i++ {
// Get name and prefix it with lf_
name := e.Type().Field(i).Name
name = fmt.Sprintf("lf_%s", name)

// Skip maps
if name == "lf_keys" || name == "lf_cmdkeys" || name == "lf_cmds" {
continue
}

// Get string representation of the value
if name == "lf_sortType" {
var sortby string

switch gOpts.sortType.method {
case naturalSort:
sortby = "natural"
case nameSort:
sortby = "name"
case sizeSort:
sortby = "size"
case timeSort:
sortby = "time"
case ctimeSort:
sortby = "ctime"
case atimeSort:
sortby = "atime"
case extSort:
sortby = "ext"
}

os.Setenv("lf_sortby", sortby)

reverse := strconv.FormatBool(gOpts.sortType.option&reverseSort != 0)
os.Setenv("lf_reverse", reverse)

hidden := strconv.FormatBool(gOpts.sortType.option&hiddenSort != 0)
os.Setenv("lf_hidden", hidden)

dirfirst := strconv.FormatBool(gOpts.sortType.option&dirfirstSort != 0)
os.Setenv("lf_dirfirst", dirfirst)
} else {
field := e.Field(i)
value := fieldToString(field)

os.Setenv(name, value)
}
}
}

func waitKey() error {
cmd := pauseCommand()

Expand All @@ -356,6 +439,7 @@ func waitKey() error {
// & No Yes No No No Do nothing
func (app *app) runShell(s string, args []string, prefix string) {
app.exportFiles()
app.exportOpts()

cmd := shellCommand(s, args)

Expand Down
16 changes: 9 additions & 7 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ import (
"strings"
"time"

"github.com/doronbehar/termbox-go"
"github.com/gdamore/tcell"
)

func run() {
if err := termbox.Init(); err != nil {
log.Fatalf("initializing termbox: %s", err)
var screen tcell.Screen
var err error
if screen, err = tcell.NewScreen(); err != nil {
log.Fatalf("creating screen: %s", err)
} else if err = screen.Init(); err != nil {
log.Fatalf("initializing screen: %s", err)
}
defer termbox.Close()

setColorMode()

f, err := os.Create(gLogPath)
if err != nil {
Expand All @@ -31,7 +32,7 @@ func run() {

log.Print("hi!")

app := newApp()
app := newApp(screen)

if err := app.nav.readMarks(); err != nil {
app.ui.echoerrf("reading marks file: %s", err)
Expand All @@ -42,6 +43,7 @@ func run() {
}

app.loop()
app.ui.screen.Fini()
}

func readExpr() <-chan expr {
Expand Down
Loading

0 comments on commit bca10c3

Please sign in to comment.