Skip to content

Commit

Permalink
can now adjust headers in the config
Browse files Browse the repository at this point in the history
  • Loading branch information
Gianni Young committed Apr 26, 2023
1 parent 014f458 commit 2c6756e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/charmbracelet/lipgloss v0.6.0
github.com/hekmon/transmissionrpc/v2 v2.0.1
github.com/kelseyhightower/envconfig v1.4.0
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
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.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
17 changes: 12 additions & 5 deletions transmission.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import (
"fmt"
"os"

"github.com/kelseyhightower/envconfig"
"gopkg.in/yaml.v2"

trans "github.com/hekmon/transmissionrpc/v2"
"github.com/kelseyhightower/envconfig"
"gopkg.in/yaml.v3"
)

type Config struct {
Expand Down Expand Up @@ -46,8 +45,16 @@ func readConfig(cfg *Config) {
func readEnvironmentalVariables(cfg *Config) {
err := envconfig.Process("", cfg)
if err != nil {
fmt.Println(err)
fmt.Printf("Error Reading Environmental Variables: %s", err)
}

fmt.Println(Cfg.UI.Columns)
fmt.Println(Cfg.Bookmarks)
fmt.Println(Cfg.Server.IP)
for _, value := range Cfg.UI.Columns {
fmt.Println(value)
}

}

var Cfg Config
Expand All @@ -58,7 +65,7 @@ func transmissionClientInit() {
}

func setupCheck() *trans.Client {
// readConfig(&Cfg)
readConfig(&Cfg)
readEnvironmentalVariables(&Cfg)
transmissionPassword := Cfg.Server.Password
transmissionUserName := Cfg.Server.Username
Expand Down
12 changes: 5 additions & 7 deletions tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,14 @@ func buildRow(torrent trans.Torrent, columns map[string]bool) table.Row {
return row
}

func SetColumns(t TorrentTable, columns map[string]bool) []table.Column {
func SetColumns(t TorrentTable) []table.Column {
var visibleColumns []table.Column
// totalColumns := len(columns)
// maxColumnSize := width / totalColumns

for key := range columns {
if columns[key] {
column := table.Column{Title: key, Width: t.width - t.width + 6}
visibleColumns = append(visibleColumns, column)
}
for _, c := range Cfg.UI.Columns {
column := table.Column{Title: c, Width: t.width - t.width + 6}
visibleColumns = append(visibleColumns, column)
}

return visibleColumns
Expand All @@ -129,7 +127,7 @@ func (m *TorrentTable) updateTable(height, width int) {
"Uploaded Ever": false,
}

visibleColumns := SetColumns(*m, headers)
visibleColumns := SetColumns(*m)
var rows []table.Row
for _, torrent := range allTorrents {
rows = append(rows, buildRow(torrent, headers))
Expand Down

0 comments on commit 2c6756e

Please sign in to comment.