Merge pull request #420 from Morganamilo/news

Only show new news when calling -Pw
This commit is contained in:
J Guerreiro 2018-05-16 18:57:35 +01:00 committed by GitHub
commit 6be6ffc7d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 13 deletions

View File

@ -425,15 +425,21 @@ type Item struct {
Creator string `xml:"dc:creator"`
}
func (item Item) Print() error {
func (item Item) Print(installTime time.Time) {
var fd string
date, err := time.Parse(time.RFC1123Z, item.PubDate)
if err != nil {
return err
fmt.Println(err)
} else {
fd = formatTime(int(date.Unix()))
if _, double, _ := cmdArgs.getArg("news", "w"); !double && !installTime.IsZero() {
if installTime.After(date) {
return
}
}
}
fd := formatTime(int(date.Unix()))
fmt.Println(bold(magenta(fd)), bold(strings.TrimSpace(item.Title)))
//fmt.Println(strings.TrimSpace(item.Link))
@ -442,7 +448,7 @@ func (item Item) Print() error {
fmt.Println(desc)
}
return nil
return
}
type Channel struct {
@ -478,19 +484,18 @@ func printNewsFeed() error {
return err
}
installTime, err := lastInstallTime()
if err != nil {
return err
}
if config.SortMode == BottomUp {
for i := len(rss.Channel.Items) - 1; i >= 0; i-- {
err := rss.Channel.Items[i].Print()
if err != nil {
return err
}
rss.Channel.Items[i].Print(installTime)
}
} else {
for i := 0; i < len(rss.Channel.Items); i++ {
err := rss.Channel.Items[i].Print()
if err != nil {
return err
}
rss.Channel.Items[i].Print(installTime)
}
}

View File

@ -5,6 +5,7 @@ import (
"sort"
"strings"
"sync"
"time"
alpm "github.com/jguer/go-alpm"
rpc "github.com/mikkeloscar/aur"
@ -407,6 +408,26 @@ func hangingPackages(removeOptional bool) (hanging []string, err error) {
return
}
func lastInstallTime() (time.Time, error) {
var time time.Time
localDb, err := alpmHandle.LocalDb()
if err != nil {
return time, err
}
localDb.PkgCache().ForEach(func(pkg alpm.Package) error {
thisTime := pkg.InstallDate()
if thisTime.After(time) {
time = thisTime
}
return nil
})
return time, nil
}
// Statistics returns statistics about packages installed in system
func statistics() (info struct {
Totaln int