mirror of
https://github.com/Jguer/yay.git
synced 2024-11-06 09:07:21 +01:00
Merge pull request #420 from Morganamilo/news
Only show new news when calling -Pw
This commit is contained in:
commit
6be6ffc7d2
31
print.go
31
print.go
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
21
query.go
21
query.go
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user