-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
481 additions
and
164 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package config | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"os/user" | ||
"path/filepath" | ||
|
||
"encoding/json" | ||
"github.com/tarrsalah/pkt" | ||
"io/ioutil" | ||
) | ||
|
||
// GetAuth returns the saved pocket credentials | ||
func GetAuth() *pkt.Auth { | ||
auth := &pkt.Auth{} | ||
configFile, err := ioutil.ReadFile(Path()) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
err = json.Unmarshal(configFile, auth) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
return auth | ||
} | ||
|
||
// PutAuth saves the pocket credentials into a file | ||
func PutAuth(auth *pkt.Auth) { | ||
content, err := json.MarshalIndent(auth, " ", " ") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
err = ioutil.WriteFile(Path(), content, 0644) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
// Dir returns the path of the confi directory | ||
func Dir() string { | ||
user, err := user.Current() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
configDir := filepath.Join(user.HomeDir, ".config", "pkt") | ||
err = os.MkdirAll(configDir, 0777) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
return configDir | ||
} | ||
|
||
// Path returns the Path of the config file | ||
func Path() string { | ||
return filepath.Join(Dir(), "config.json") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package ui | ||
|
||
import ( | ||
"fmt" | ||
"github.com/rivo/tview" | ||
"github.com/tarrsalah/pkt" | ||
) | ||
|
||
type itemsTable struct { | ||
*tview.Table | ||
items pkt.Items | ||
handleSelect func(int, int) | ||
} | ||
|
||
func newItemsTable() *itemsTable { | ||
t := &itemsTable{ | ||
Table: tview.NewTable(), | ||
} | ||
|
||
t.SetBorder(true) | ||
t.SetSelectable(true, false) | ||
|
||
return t | ||
} | ||
|
||
func (t *itemsTable) Render() { | ||
t.Clear() | ||
for i, item := range t.items { | ||
tags := fmt.Sprintf("[yellow] %s", item.Tags()) | ||
title := fmt.Sprintf("%d. %s [green](%s)", | ||
i+1, item.Title(), | ||
item.Host()) | ||
|
||
t.SetCell(i, 0, tview.NewTableCell(title). | ||
SetMaxWidth(1). | ||
SetExpansion(3)) | ||
|
||
t.SetCell(i, 1, tview.NewTableCell(tags). | ||
SetMaxWidth(1). | ||
SetExpansion(2)) | ||
} | ||
|
||
t.SetSelectedFunc(t.handleSelect) | ||
t.SetTitle(t.title()) | ||
} | ||
|
||
func (t *itemsTable) title() string { | ||
count := len(t.items) | ||
if count > 0 { | ||
return fmt.Sprintf("Pocket items (%d)", count) | ||
} | ||
return "Pocket items" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package ui | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/gdamore/tcell/v2" | ||
"github.com/rivo/tview" | ||
"github.com/tarrsalah/pkt" | ||
) | ||
|
||
type tagsTable struct { | ||
*tview.Table | ||
tags pkt.Tags | ||
selectedTags map[int]struct{} | ||
handleSelect func(int, int) | ||
} | ||
|
||
func newTagsTable() *tagsTable { | ||
t := &tagsTable{ | ||
Table: tview.NewTable(), | ||
} | ||
|
||
t.SetBorder(true) | ||
t.SetSelectable(true, false) | ||
|
||
return t | ||
} | ||
|
||
func (t *tagsTable) Render() { | ||
t.Clear() | ||
for i, tag := range t.tags { | ||
cell := tview.NewTableCell(tag.Label) | ||
|
||
if _, ok := t.selectedTags[i]; ok { | ||
cell.SetTextColor(tcell.ColorYellow) | ||
cell.SetAttributes(tcell.AttrUnderline | tcell.AttrBold) | ||
} | ||
t.Table.SetCell(i, 0, cell) | ||
|
||
} | ||
t.SetSelectedFunc(t.handleSelect) | ||
t.SetTitle(t.title()) | ||
} | ||
|
||
func (t *tagsTable) title() string { | ||
l := len(t.tags) | ||
if l > 0 { | ||
return fmt.Sprintf("Tags (%d)", len(t.tags)) | ||
} | ||
|
||
return "Tags" | ||
} |
Oops, something went wrong.