Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
295dae27fd | ||
|
a13d212968 | ||
|
69139ee7f6 | ||
|
073db44b81 | ||
|
49ea48976d |
52
.github/workflows/reviewdog.yml
vendored
Normal file
52
.github/workflows/reviewdog.yml
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
name: reviewdog
|
||||
on: [pull_request]
|
||||
jobs:
|
||||
# NOTE: golangci-lint doesn't report multiple errors on the same line from
|
||||
# different linters and just report one of the errors?
|
||||
|
||||
golangci-lint:
|
||||
name: runner / golangci-lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out code into the Go module directory
|
||||
uses: actions/checkout@v1
|
||||
- name: golangci-lint
|
||||
uses: docker://reviewdog/action-golangci-lint:v1 # Pre-built image
|
||||
# uses: reviewdog/action-golangci-lint@v1 # Build with Dockerfile
|
||||
# uses: docker://reviewdog/action-golangci-lint:v1.0.2 # Can use specific version.
|
||||
# uses: reviewdog/action-golangci-lint@v1.0.2 # Can use specific version.
|
||||
with:
|
||||
github_token: ${{ secrets.github_token }}
|
||||
# Can pass --config flag to change golangci-lint behavior and target
|
||||
# directory.
|
||||
golangci_lint_flags: "--config=.github/.golangci.yml ./testdata"
|
||||
|
||||
# Use golint via golangci-lint binary with "warning" level.
|
||||
golint:
|
||||
name: runner / golint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out code into the Go module directory
|
||||
uses: actions/checkout@v1
|
||||
- name: golint
|
||||
uses: reviewdog/action-golangci-lint@v1
|
||||
with:
|
||||
github_token: ${{ secrets.github_token }}
|
||||
golangci_lint_flags: "--disable-all -E golint"
|
||||
tool_name: golint # Change reporter name.
|
||||
level: warning # GitHub Status Check won't become failure with this level.
|
||||
|
||||
# You can add more and more supported linters with different config.
|
||||
errcheck:
|
||||
name: runner / errcheck
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out code into the Go module directory
|
||||
uses: actions/checkout@v1
|
||||
- name: errcheck
|
||||
uses: reviewdog/action-golangci-lint@v1
|
||||
with:
|
||||
github_token: ${{ secrets.github_token }}
|
||||
golangci_lint_flags: "--disable-all -E errcheck"
|
||||
tool_name: errcheck
|
||||
level: info
|
@@ -2,7 +2,7 @@
|
||||
|
||||
View RSS feeds from the terminal.
|
||||
|
||||

|
||||

|
||||
|
||||
## configure
|
||||
|
||||
|
218
cmd/start.go
218
cmd/start.go
@@ -1,218 +0,0 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os/exec"
|
||||
"os/user"
|
||||
|
||||
"github.com/davegallant/srv/internal"
|
||||
"github.com/jroimartin/gocui"
|
||||
)
|
||||
|
||||
// Controller can access Feeds and Config
|
||||
var Controller *internal.Controller
|
||||
|
||||
var (
|
||||
viewArr = []string{"feeds", "Items"}
|
||||
active = 0
|
||||
currentFeed = 0 // TODO: move to Controller
|
||||
)
|
||||
|
||||
func cursorDown(g *gocui.Gui, v *gocui.View) error {
|
||||
if v != nil {
|
||||
cx, cy := v.Cursor()
|
||||
if err := v.SetCursor(cx, cy+1); err != nil {
|
||||
v.SetCursor(cx, cy-1)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func cursorUp(g *gocui.Gui, v *gocui.View) error {
|
||||
if v != nil {
|
||||
ox, oy := v.Origin()
|
||||
cx, cy := v.Cursor()
|
||||
if err := v.SetCursor(cx, cy-1); err != nil && oy > 0 {
|
||||
if err := v.SetOrigin(ox, oy-1); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// openFeed opens all items in the feed
|
||||
func openFeed(g *gocui.Gui, v *gocui.View) error {
|
||||
_, cy := v.Cursor()
|
||||
currentFeed = cy
|
||||
feed := Controller.Rss.Feeds[currentFeed]
|
||||
ov, _ := g.View("Items")
|
||||
|
||||
ov.Clear()
|
||||
for _, item := range feed.Items {
|
||||
fmt.Fprintln(ov, "-", item.Title)
|
||||
}
|
||||
nextView(g, ov)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// openItem opens the feed in an external browser
|
||||
func openItem(g *gocui.Gui, v *gocui.View) error {
|
||||
_, cy := v.Cursor()
|
||||
item := Controller.Rss.Feeds[currentFeed].Items[cy]
|
||||
viewer := Controller.Config.ExternalViewer
|
||||
err := exec.Command(viewer, item.Link).Start()
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func showLoading(g *gocui.Gui) error {
|
||||
maxX, maxY := g.Size()
|
||||
if v, err := g.SetView("loading", maxX/2-4, maxY/2-1, maxX/2+4, maxY/2+1); err != nil {
|
||||
if err != gocui.ErrUnknownView {
|
||||
return err
|
||||
}
|
||||
fmt.Fprintln(v, "Loading")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func hideLoading(g *gocui.Gui) error {
|
||||
if err := g.DeleteView("loading"); err != nil {
|
||||
if err != gocui.ErrUnknownView {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func refreshFeeds(g *gocui.Gui, v *gocui.View) error {
|
||||
showLoading(g)
|
||||
Controller.Rss.Update()
|
||||
//hideLoading(g)
|
||||
return nil
|
||||
}
|
||||
|
||||
// statically map all of the keys
|
||||
func keybindings(g *gocui.Gui) error {
|
||||
if err := g.SetKeybinding("", gocui.KeyTab, gocui.ModNone, nextView); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := g.SetKeybinding("", gocui.KeyArrowDown, gocui.ModNone, cursorDown); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := g.SetKeybinding("", gocui.KeyArrowUp, gocui.ModNone, cursorUp); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := g.SetKeybinding("feeds", gocui.KeyEnter, gocui.ModNone, openFeed); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := g.SetKeybinding("Items", gocui.KeyEnter, gocui.ModNone, openItem); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := g.SetKeybinding("", gocui.KeyF5, gocui.ModNone, refreshFeeds); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func setCurrentViewOnTop(g *gocui.Gui, name string) (*gocui.View, error) {
|
||||
if _, err := g.SetCurrentView(name); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return g.SetViewOnTop(name)
|
||||
}
|
||||
|
||||
func nextView(g *gocui.Gui, v *gocui.View) error {
|
||||
nextIndex := (active + 1) % len(viewArr)
|
||||
name := viewArr[nextIndex]
|
||||
|
||||
_, err := g.View("Items")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := setCurrentViewOnTop(g, name); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if nextIndex == 0 || nextIndex == 3 {
|
||||
g.Cursor = true
|
||||
} else {
|
||||
g.Cursor = false
|
||||
}
|
||||
|
||||
active = nextIndex
|
||||
return nil
|
||||
}
|
||||
|
||||
func layout(g *gocui.Gui) error {
|
||||
maxX, maxY := g.Size()
|
||||
if v, err := g.SetView("feeds", 0, 0, maxX-1, maxY/4-1); err != nil {
|
||||
if err != gocui.ErrUnknownView {
|
||||
return err
|
||||
}
|
||||
v.Title = "Feeds"
|
||||
v.Highlight = true
|
||||
v.SelBgColor = gocui.ColorGreen
|
||||
v.SelFgColor = gocui.ColorBlack
|
||||
|
||||
if _, err = setCurrentViewOnTop(g, "feeds"); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, f := range Controller.Rss.Feeds {
|
||||
fmt.Fprintln(v, "-", f.Title)
|
||||
}
|
||||
}
|
||||
if v, err := g.SetView("Items", 0, maxY/4, maxX-1, maxY-1); err != nil {
|
||||
if err != gocui.ErrUnknownView {
|
||||
return err
|
||||
}
|
||||
v.Title = "Items"
|
||||
v.Highlight = true
|
||||
v.SelBgColor = gocui.ColorGreen
|
||||
v.SelFgColor = gocui.ColorBlack
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func quit(g *gocui.Gui, v *gocui.View) error {
|
||||
return gocui.ErrQuit
|
||||
}
|
||||
|
||||
// Start initializes the application
|
||||
func Start() {
|
||||
usr, err := user.Current()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
configPath := usr.HomeDir + "/.config/srv/config.yaml"
|
||||
|
||||
Controller = &internal.Controller{}
|
||||
Controller.Init(configPath)
|
||||
|
||||
g, err := gocui.NewGui(gocui.OutputNormal)
|
||||
if err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
defer g.Close()
|
||||
|
||||
g.SetManagerFunc(layout)
|
||||
|
||||
if err := keybindings(g); err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
|
||||
if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {
|
||||
log.Panicln(err)
|
||||
}
|
||||
}
|
@@ -4,8 +4,9 @@ feeds:
|
||||
- https://www.reddit.com/r/golang/.rss
|
||||
- https://www.reddit.com/r/linux/.rss
|
||||
- https://www.zdnet.com/topic/security/rss.xml
|
||||
- https://aws.amazon.com/blogs/security/feed/
|
||||
- https://www.archlinux.org/feeds/news/
|
||||
|
||||
# Optionally define an an external application viewer
|
||||
# Optionally define an application to view the feeds
|
||||
#externalViewer: firefox
|
||||
# Optionally define args for the external viewer
|
||||
#externalViewerArgs:
|
||||
#- --new-window
|
||||
|
@@ -1,4 +1,4 @@
|
||||
package internal
|
||||
package config
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@@ -7,13 +7,15 @@ import (
|
||||
"os"
|
||||
"runtime"
|
||||
|
||||
"github.com/davegallant/srv/file"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
// Configuration stores the global config
|
||||
type Configuration struct {
|
||||
Feeds []string `yaml:"feeds"`
|
||||
ExternalViewer string `yaml:"externalViewer,omitempty"`
|
||||
Feeds []string `yaml:"feeds"`
|
||||
ExternalViewer string `yaml:"externalViewer,omitempty"`
|
||||
ExternalViewerArgs []string `yaml:"externalViewerArgs,omitempty"`
|
||||
}
|
||||
|
||||
// DefaultConfiguration can be used if a config is missing
|
||||
@@ -21,11 +23,12 @@ var DefaultConfiguration = Configuration{
|
||||
Feeds: []string{
|
||||
"https://news.ycombinator.com/rss",
|
||||
"https://www.reddit.com/r/golang/.rss",
|
||||
"https://www.reddit.com/r/linux/.rss",
|
||||
"https://www.zdnet.com/topic/security/rss.xml",
|
||||
},
|
||||
}
|
||||
|
||||
// Determines the default viewer
|
||||
// DetermineExternalViewer checks the OS to decide the default viewer
|
||||
func DetermineExternalViewer() (string, error) {
|
||||
switch os := runtime.GOOS; os {
|
||||
case "linux":
|
||||
@@ -38,17 +41,14 @@ func DetermineExternalViewer() (string, error) {
|
||||
}
|
||||
|
||||
// LoadConfiguration takes a filename (configuration) and loads it.
|
||||
func LoadConfiguration(file string) Configuration {
|
||||
func LoadConfiguration(f string) Configuration {
|
||||
var config Configuration
|
||||
|
||||
// If the configuration file does not exist,
|
||||
// write a default config
|
||||
_, err := os.Stat(file)
|
||||
if os.IsNotExist(err) {
|
||||
WriteConfig(DefaultConfiguration, file)
|
||||
if !file.Exists(f) {
|
||||
WriteConfig(DefaultConfiguration, f)
|
||||
}
|
||||
|
||||
data, err := ioutil.ReadFile(file)
|
||||
data, err := ioutil.ReadFile(f)
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
@@ -77,7 +77,7 @@ func WriteConfig(config Configuration, file string) error {
|
||||
log.Fatalf("Unable to marshal default config: %v", err)
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(file, c, 0644)
|
||||
err = ioutil.WriteFile(file, c, 0600)
|
||||
if err != nil {
|
||||
log.Fatalf("Unable to write default config: %v", err)
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
package internal
|
||||
package config
|
||||
|
||||
import (
|
||||
"testing"
|
||||
@@ -15,8 +15,6 @@ func TestLoadConfiguration(t *testing.T) {
|
||||
"https://www.reddit.com/r/golang/.rss",
|
||||
"https://www.reddit.com/r/linux/.rss",
|
||||
"https://www.zdnet.com/topic/security/rss.xml",
|
||||
"https://aws.amazon.com/blogs/security/feed/",
|
||||
"https://www.archlinux.org/feeds/news/",
|
||||
}
|
||||
|
||||
assert.Equal(
|
21
controller/controller.go
Normal file
21
controller/controller.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
config "github.com/davegallant/srv/config"
|
||||
feeds "github.com/davegallant/srv/feeds"
|
||||
)
|
||||
|
||||
// Controller keeps everything together
|
||||
type Controller struct {
|
||||
Config config.Configuration
|
||||
Rss *feeds.RSS
|
||||
CurrentFeed int
|
||||
}
|
||||
|
||||
// Init initiates the controller with config
|
||||
func (c *Controller) Init(conf string) {
|
||||
c.Config = config.LoadConfiguration(conf)
|
||||
c.Rss = &feeds.RSS{}
|
||||
c.Rss.Update(c.Config.Feeds)
|
||||
c.CurrentFeed = 0
|
||||
}
|
8
cui/colours.go
Normal file
8
cui/colours.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package cui
|
||||
|
||||
import "github.com/jroimartin/gocui"
|
||||
|
||||
const (
|
||||
selectionBgColor = gocui.ColorWhite
|
||||
selectionFgColor = gocui.ColorBlack
|
||||
)
|
29
cui/keybindings.go
Normal file
29
cui/keybindings.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package cui
|
||||
|
||||
import "github.com/jroimartin/gocui"
|
||||
|
||||
// Map keys to actions
|
||||
func keybindings(g *gocui.Gui) error {
|
||||
if err := g.SetKeybinding("", gocui.KeyTab, gocui.ModNone, nextView); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := g.SetKeybinding("", gocui.KeyArrowDown, gocui.ModNone, cursorDown); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := g.SetKeybinding("", gocui.KeyArrowUp, gocui.ModNone, cursorUp); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := g.SetKeybinding("feeds", gocui.KeyEnter, gocui.ModNone, openFeed); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := g.SetKeybinding("Items", gocui.KeyEnter, gocui.ModNone, openItem); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := g.SetKeybinding("", gocui.KeyF5, gocui.ModNone, refreshFeeds); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
153
cui/main.go
Normal file
153
cui/main.go
Normal file
@@ -0,0 +1,153 @@
|
||||
package cui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os/exec"
|
||||
"os/user"
|
||||
"path"
|
||||
|
||||
"github.com/davegallant/srv/controller"
|
||||
"github.com/jroimartin/gocui"
|
||||
)
|
||||
|
||||
// Controller can access internal state
|
||||
var Controller *controller.Controller
|
||||
|
||||
var (
|
||||
viewArr = []string{"feeds", "Items"}
|
||||
active = 0
|
||||
)
|
||||
|
||||
// openFeed opens all items in the feed
|
||||
func openFeed(g *gocui.Gui, v *gocui.View) error {
|
||||
_, oy := v.Origin()
|
||||
feed := Controller.Rss.Feeds[oy]
|
||||
Controller.CurrentFeed = oy
|
||||
ov, _ := g.View("Items")
|
||||
|
||||
ov.Clear()
|
||||
|
||||
if err := ov.SetOrigin(0, 0); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
for _, item := range feed.Items {
|
||||
fmt.Fprintln(ov, "-", item.Title)
|
||||
}
|
||||
nextView(g, ov)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// openItem opens the feed in an external browser
|
||||
func openItem(g *gocui.Gui, v *gocui.View) error {
|
||||
_, oy := v.Origin()
|
||||
item := Controller.Rss.Feeds[Controller.CurrentFeed].Items[oy]
|
||||
err := exec.Command(
|
||||
Controller.Config.ExternalViewer,
|
||||
append(Controller.Config.ExternalViewerArgs, item.Link)...).Start()
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func refreshFeeds(g *gocui.Gui, v *gocui.View) error {
|
||||
Controller.Rss.Update(Controller.Config.Feeds)
|
||||
return nil
|
||||
}
|
||||
|
||||
func setCurrentViewOnTop(g *gocui.Gui, name string) (*gocui.View, error) {
|
||||
if _, err := g.SetCurrentView(name); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return g.SetViewOnTop(name)
|
||||
}
|
||||
|
||||
func nextView(g *gocui.Gui, v *gocui.View) error {
|
||||
nextIndex := (active + 1) % len(viewArr)
|
||||
name := viewArr[nextIndex]
|
||||
|
||||
_, err := g.View("Items")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := setCurrentViewOnTop(g, name); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if nextIndex == 0 || nextIndex == 3 {
|
||||
g.Cursor = true
|
||||
} else {
|
||||
g.Cursor = false
|
||||
}
|
||||
|
||||
active = nextIndex
|
||||
return nil
|
||||
}
|
||||
|
||||
func layout(g *gocui.Gui) error {
|
||||
maxX, maxY := g.Size()
|
||||
if v, err := g.SetView("feeds", 0, 0, maxX-1, maxY/4-1); err != nil {
|
||||
if err != gocui.ErrUnknownView {
|
||||
return err
|
||||
}
|
||||
v.Highlight = true
|
||||
v.SelBgColor = selectionBgColor
|
||||
v.SelFgColor = selectionFgColor
|
||||
v.Title = "Feeds"
|
||||
|
||||
if _, err = setCurrentViewOnTop(g, "feeds"); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, f := range Controller.Rss.Feeds {
|
||||
fmt.Fprintln(v, "-", f.Title)
|
||||
}
|
||||
}
|
||||
if v, err := g.SetView("Items", 0, maxY/4, maxX-1, maxY-1); err != nil {
|
||||
if err != gocui.ErrUnknownView {
|
||||
return err
|
||||
}
|
||||
v.Highlight = true
|
||||
v.SelBgColor = selectionBgColor
|
||||
v.SelFgColor = selectionFgColor
|
||||
v.Title = "Items"
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func quit(g *gocui.Gui, v *gocui.View) error {
|
||||
return gocui.ErrQuit
|
||||
}
|
||||
|
||||
// Start initializes the application
|
||||
func Start() {
|
||||
usr, err := user.Current()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
configPath := path.Join(usr.HomeDir, ".config", "srv", "config.yaml")
|
||||
|
||||
Controller = &controller.Controller{}
|
||||
Controller.Init(configPath)
|
||||
|
||||
g, err := gocui.NewGui(gocui.OutputNormal)
|
||||
if err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
defer g.Close()
|
||||
|
||||
g.SetManagerFunc(layout)
|
||||
|
||||
if err := keybindings(g); err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
|
||||
if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {
|
||||
log.Panicln(err)
|
||||
}
|
||||
}
|
38
cui/scroll.go
Normal file
38
cui/scroll.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package cui
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/jroimartin/gocui"
|
||||
)
|
||||
|
||||
func scroll(g *gocui.Gui, v *gocui.View, direction int) error {
|
||||
if v != nil {
|
||||
_, y := v.Size()
|
||||
ox, oy := v.Origin()
|
||||
cx, cy := v.Cursor()
|
||||
|
||||
if err := v.SetCursor(cx, cy-1); err != nil && oy > 0 {
|
||||
if err := v.SetOrigin(ox, oy-1); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// If we're nearing a boundary
|
||||
if oy+direction > strings.Count(v.ViewBuffer(), "\n")+y-direction {
|
||||
v.Autoscroll = true
|
||||
} else {
|
||||
v.Autoscroll = false
|
||||
v.SetOrigin(ox, oy+direction)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func cursorDown(g *gocui.Gui, v *gocui.View) error {
|
||||
return scroll(g, v, 1)
|
||||
}
|
||||
|
||||
func cursorUp(g *gocui.Gui, v *gocui.View) error {
|
||||
return scroll(g, v, -1)
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
package internal
|
||||
package feeds
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -12,20 +12,15 @@ import (
|
||||
|
||||
type RSS struct {
|
||||
Feeds []*gofeed.Feed
|
||||
c *Controller
|
||||
}
|
||||
|
||||
func (r *RSS) New(c *Controller) {
|
||||
r.c = c
|
||||
}
|
||||
|
||||
// Update fetches all articles for all feeds
|
||||
func (r *RSS) Update() {
|
||||
func (r *RSS) Update(feeds []string) {
|
||||
fp := gofeed.NewParser()
|
||||
var wg sync.WaitGroup
|
||||
var mux sync.Mutex
|
||||
r.Feeds = []*gofeed.Feed{}
|
||||
for _, f := range r.c.Config.Feeds {
|
||||
for _, f := range feeds {
|
||||
f := f
|
||||
wg.Add(1)
|
||||
go func() {
|
15
file/file.go
Normal file
15
file/file.go
Normal file
@@ -0,0 +1,15 @@
|
||||
// Package file contains filesystem functions
|
||||
package file
|
||||
|
||||
import (
|
||||
"os"
|
||||
)
|
||||
|
||||
// Exists returns true if a file exists
|
||||
func Exists(filename string) bool {
|
||||
info, err := os.Stat(filename)
|
||||
if os.IsNotExist(err) {
|
||||
return false
|
||||
}
|
||||
return !info.IsDir()
|
||||
}
|
@@ -1,18 +0,0 @@
|
||||
package internal
|
||||
|
||||
import "time"
|
||||
|
||||
// Controller keeps everything together
|
||||
type Controller struct {
|
||||
Config Configuration
|
||||
lastUpdate time.Time
|
||||
Rss *RSS
|
||||
}
|
||||
|
||||
// Init initiates the controller with config
|
||||
func (c *Controller) Init(config string) {
|
||||
c.Config = LoadConfiguration(config)
|
||||
c.Rss = &RSS{}
|
||||
c.Rss.New(c)
|
||||
c.Rss.Update()
|
||||
}
|
Reference in New Issue
Block a user