Skip to content

Commit

Permalink
Rebase on current version of Viddy
Browse files Browse the repository at this point in the history
  • Loading branch information
anvial committed Aug 29, 2022
1 parent 0ab3347 commit 4b5886c
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 13 deletions.
8 changes: 4 additions & 4 deletions config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package viddy

import (
"errors"
Expand All @@ -24,7 +24,7 @@ var (
type config struct {
runtime runtimeConfig
general general
theme theme
Theme theme
keymap keymapping
}

Expand Down Expand Up @@ -69,7 +69,7 @@ type keymapping struct {
}

//nolint:funlen,cyclop
func newConfig(v *viper.Viper, args []string) (*config, error) {
func NewConfig(v *viper.Viper, args []string) (*config, error) {
flagSet := pflag.NewFlagSet("", pflag.ExitOnError)

defaultInterval := os.Getenv("WATCH_INTERVAL")
Expand Down Expand Up @@ -172,7 +172,7 @@ func newConfig(v *viper.Viper, args []string) (*config, error) {
v.SetDefault("color.border", "gray")
v.SetDefault("color.title", "gray")

conf.theme.Theme = tview.Theme{
conf.Theme.Theme = tview.Theme{
PrimitiveBackgroundColor: tcell.GetColor(v.GetString("color.background")),
ContrastBackgroundColor: tcell.GetColor(v.GetString("color.contrast_background")),
MoreContrastBackgroundColor: tcell.GetColor(v.GetString("color.more_contrast_background")),
Expand Down
2 changes: 1 addition & 1 deletion config_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package viddy

import (
"bytes"
Expand Down
2 changes: 1 addition & 1 deletion generator.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package viddy

import "time"

Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package viddy

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion run.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//go:build !windows

package main
package viddy

import (
"bytes"
Expand Down
2 changes: 1 addition & 1 deletion run_windows.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//go:build windows

package main
package viddy

import (
"bytes"
Expand Down
5 changes: 3 additions & 2 deletions snapshot.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package viddy

import (
"bytes"
Expand Down Expand Up @@ -47,8 +47,9 @@ type Snapshot struct {
finish chan<- struct{}
}

//nolint:lll
// NewSnapshot returns Snapshot object.
//
//nolint:lll
func NewSnapshot(id int64, command string, args []string, shell string, shellOpts string, before *Snapshot, finish chan<- struct{}) *Snapshot {
return &Snapshot{
id: id,
Expand Down
26 changes: 24 additions & 2 deletions viddy.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package main
package viddy

import (
"bytes"
"errors"
"fmt"
"github.com/adrg/xdg"
"github.com/spf13/viper"
"html/template"
"io"
"os"
Expand Down Expand Up @@ -141,6 +143,26 @@ func NewViddy(conf *config) *Viddy {
}
}

func NewPreconfigedViddy(args []string) *Viddy {
v := viper.New()
v.SetConfigType("toml")
v.SetConfigName("viddy")
v.AddConfigPath(xdg.ConfigHome)

_ = v.ReadInConfig()

conf, err := NewConfig(v, args)

if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}

tview.Styles = conf.Theme.Theme
preConfigedViddy := NewViddy(conf)
return preConfigedViddy
}

func (v *Viddy) ShowLogView(b bool) {
v.showLogView = b
v.arrange()
Expand Down Expand Up @@ -412,7 +434,7 @@ func (v *Viddy) arrange() {
}

// Run is entry point to run viddy.
//nolint: funlen,gocognit,cyclop
// nolint: funlen,gocognit,cyclop
func (v *Viddy) Run() error {
b := tview.NewTextView()
b.SetDynamicColors(true)
Expand Down

0 comments on commit 4b5886c

Please sign in to comment.