nopub per post
parent
77783a3405
commit
6b5bc6b0ef
|
@ -25,9 +25,9 @@ func NewManagement() *Management {
|
|||
title,
|
||||
ui.NewList([]string{
|
||||
"read over feels",
|
||||
"modify feels publishing", // TODO
|
||||
"backup your feels", // TODO
|
||||
"import a feels backup", // TODO
|
||||
"modify feels publishing",
|
||||
"backup your feels", // TODO
|
||||
"import a feels backup", // TODO
|
||||
"bury some feels",
|
||||
"delete feels by day",
|
||||
"purge all feels",
|
||||
|
@ -60,7 +60,8 @@ func (management *Management) Event(state *ui.State, event vaxis.Event) (process
|
|||
case 0:
|
||||
user, _ := user.Current()
|
||||
ui.ViewChange <- NewUserPage(user.Username, true)
|
||||
// case 1:
|
||||
case 1:
|
||||
ui.ViewChange <- NewPublishing()
|
||||
case 2:
|
||||
management.SaveBackup(state)
|
||||
// case 3:
|
||||
|
|
|
@ -147,7 +147,7 @@ func newFeels(state *ui.State) {
|
|||
state.HideCursor()
|
||||
state.Window().Clear()
|
||||
ttbp.NewNopub(now)
|
||||
ttbp.Publish(now)
|
||||
ttbp.Publish()
|
||||
ui.ViewChange <- NewPosted()
|
||||
return
|
||||
case vaxis.Redraw:
|
||||
|
|
|
@ -0,0 +1,92 @@
|
|||
package app
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/user"
|
||||
"strconv"
|
||||
|
||||
"git.sr.ht/~rockorager/vaxis"
|
||||
"git.tilde.town/nbsp/neofeels/ttbp"
|
||||
"git.tilde.town/nbsp/neofeels/ui"
|
||||
)
|
||||
|
||||
type Publishing struct {
|
||||
title string
|
||||
list ui.List
|
||||
help string
|
||||
posts []ttbp.Post
|
||||
}
|
||||
|
||||
func NewPublishing() *Publishing {
|
||||
user, _ := user.Current()
|
||||
posts := ttbp.GetPostsForUser(user.Username)
|
||||
list := []string{}
|
||||
for _, post := range posts {
|
||||
list = append(list, formatPublishing(post))
|
||||
}
|
||||
|
||||
return &Publishing{
|
||||
title,
|
||||
ui.NewList(list),
|
||||
"↑↓/kj move ↵ enter q return",
|
||||
posts,
|
||||
}
|
||||
}
|
||||
|
||||
func formatPublishing(post ttbp.Post) string {
|
||||
nopub := ""
|
||||
if post.Nopub {
|
||||
nopub = "(nopub)"
|
||||
}
|
||||
return fmt.Sprintf(
|
||||
"%s %s",
|
||||
post.Date.Format("2006-01-02"),
|
||||
nopub,
|
||||
)
|
||||
}
|
||||
|
||||
func (publishing *Publishing) Event(state *ui.State, event vaxis.Event) (processed bool) {
|
||||
if key, ok := event.(vaxis.Key); ok && key.EventType == vaxis.EventPress {
|
||||
switch key.String() {
|
||||
case "Ctrl+c", "Ctrl+d":
|
||||
close(ui.Quit)
|
||||
case "Down", "j", "Ctrl+n":
|
||||
publishing.list.Down()
|
||||
case "Up", "k", "Ctrl+p":
|
||||
publishing.list.Up()
|
||||
case "End", "Shift+g":
|
||||
publishing.list.End()
|
||||
case "Home", "g":
|
||||
publishing.list.Home()
|
||||
case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9":
|
||||
i, _ := strconv.Atoi(key.String())
|
||||
publishing.list.SetIndex(i)
|
||||
case "q", "h", "Left":
|
||||
ttbp.Publish()
|
||||
ui.ViewChange <- NewManagement()
|
||||
case "Enter", "l", "Right":
|
||||
if len(publishing.list.Items()) > 0 {
|
||||
publishing.posts[publishing.list.Index()].Nopub = !publishing.posts[publishing.list.Index()].Nopub
|
||||
ttbp.ToggleNopub(publishing.posts[publishing.list.Index()].Date)
|
||||
publishing.list.SetItem(publishing.list.Index(), formatPublishing(publishing.posts[publishing.list.Index()]))
|
||||
}
|
||||
}
|
||||
processed = true
|
||||
}
|
||||
publishing.Draw(state)
|
||||
return
|
||||
}
|
||||
|
||||
func (publishing *Publishing) Draw(state *ui.State) {
|
||||
win := state.Window()
|
||||
win.New(win.Width/2-10, win.Height/2-8, 20, 5).Print(vaxis.Segment{Text: publishing.title})
|
||||
publishing.list.Draw(vaxis.Window{
|
||||
Vx: win.Vx,
|
||||
Parent: nil,
|
||||
Column: win.Width/2 - 14,
|
||||
Row: win.Height/2 - 2,
|
||||
Width: 28,
|
||||
Height: 10,
|
||||
})
|
||||
win.New(win.Width/2-15, win.Height/2+9, 30, 1).Print(vaxis.Segment{Text: publishing.help})
|
||||
}
|
|
@ -14,6 +14,4 @@
|
|||
<!---put your custom html here-->
|
||||
|
||||
<!---don't put anything after this line-->
|
||||
<div id="tlogs"></div>
|
||||
</body>
|
||||
</html>
|
||||
<div id="tlogs">
|
||||
|
|
43
ttbp/ttbp.go
43
ttbp/ttbp.go
|
@ -261,7 +261,48 @@ func NewNopub(t time.Time) {
|
|||
writer.Flush()
|
||||
}
|
||||
|
||||
func Publish(t time.Time) {
|
||||
func ToggleNopub(t time.Time) {
|
||||
dateString := t.Format("20060102.txt")
|
||||
nopubs, err := os.ReadFile(PathUserNopub)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
lines := strings.Split(strings.TrimSpace(string(nopubs)), "\n")
|
||||
|
||||
newLines := []string{}
|
||||
exists := false
|
||||
for _, line := range lines {
|
||||
if line == dateString {
|
||||
exists = true
|
||||
} else {
|
||||
newLines = append(newLines, line)
|
||||
}
|
||||
}
|
||||
if !exists {
|
||||
newLines = append(newLines, dateString)
|
||||
}
|
||||
|
||||
file, err := os.Create(PathUserNopub)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
writer := bufio.NewWriter(file)
|
||||
for _, line := range newLines {
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
_, err := writer.WriteString(line + "\n")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
writer.Flush()
|
||||
}
|
||||
|
||||
func Publish() {
|
||||
cfg, err := config.Read()
|
||||
if err != nil {
|
||||
return // TODO: expose this error to the user
|
||||
|
|
Loading…
Reference in New Issue