Compare commits
No commits in common. "77783a3405423638100664612e7cf3957736e57b" and "f2804c1fc9c4ea81d9554b17da1439aa9a1bc817" have entirely different histories.
77783a3405
...
f2804c1fc9
154
app/bury.go
154
app/bury.go
|
@ -1,154 +0,0 @@
|
||||||
package app
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"os/user"
|
|
||||||
"path"
|
|
||||||
"strconv"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"git.sr.ht/~rockorager/vaxis"
|
|
||||||
"git.tilde.town/nbsp/neofeels/ttbp"
|
|
||||||
"git.tilde.town/nbsp/neofeels/ui"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Bury struct {
|
|
||||||
title string
|
|
||||||
list ui.List
|
|
||||||
help string
|
|
||||||
posts []ttbp.Post
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewBury() *Bury {
|
|
||||||
user, _ := user.Current()
|
|
||||||
posts := ttbp.GetPostsForUser(user.Username)
|
|
||||||
list := []string{}
|
|
||||||
for _, post := range posts {
|
|
||||||
list = append(list, fmt.Sprintf(
|
|
||||||
"%s (%d words)",
|
|
||||||
post.Date.Format("2006-01-02"),
|
|
||||||
post.Words,
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
return &Bury{
|
|
||||||
title,
|
|
||||||
ui.NewList(list),
|
|
||||||
"↑↓/kj move ↵ enter q return",
|
|
||||||
posts,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (bury *Bury) 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":
|
|
||||||
bury.list.Down()
|
|
||||||
case "Up", "k", "Ctrl+p":
|
|
||||||
bury.list.Up()
|
|
||||||
case "End", "Shift+g":
|
|
||||||
bury.list.End()
|
|
||||||
case "Home", "g":
|
|
||||||
bury.list.Home()
|
|
||||||
case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9":
|
|
||||||
i, _ := strconv.Atoi(key.String())
|
|
||||||
bury.list.SetIndex(i)
|
|
||||||
case "q", "h", "Left":
|
|
||||||
ui.ViewChange <- NewManagement()
|
|
||||||
case "Enter", "l", "Right":
|
|
||||||
if len(bury.list.Items()) > 0 {
|
|
||||||
bury.Confirmation(state, func() {
|
|
||||||
os.MkdirAll(ttbp.PathUserBuried, 0700)
|
|
||||||
newPath := path.Join(ttbp.PathUserBuried, bury.posts[bury.list.Index()].Date.Format("20060102-")+strconv.FormatInt(time.Now().Unix(), 10)+".txt")
|
|
||||||
os.Rename(
|
|
||||||
path.Join(ttbp.PathUserEntries, bury.posts[bury.list.Index()].Date.Format("20060102.txt")),
|
|
||||||
newPath,
|
|
||||||
)
|
|
||||||
os.Chmod(newPath, 600)
|
|
||||||
}, "feels buried")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
processed = true
|
|
||||||
}
|
|
||||||
bury.Draw(state)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (bury *Bury) Draw(state *ui.State) {
|
|
||||||
win := state.Window()
|
|
||||||
win.New(win.Width/2-10, win.Height/2-8, 20, 5).Print(vaxis.Segment{Text: bury.title})
|
|
||||||
bury.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: bury.help})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (delete *Bury) Confirmation(state *ui.State, action func(), message string) {
|
|
||||||
delete.Draw(state)
|
|
||||||
win := state.Window()
|
|
||||||
win.New(win.Width/2-14, win.Height/2-2+delete.list.Index(), 28, 1).Print(vaxis.Segment{
|
|
||||||
Text: " are you sure? ",
|
|
||||||
Style: vaxis.Style{
|
|
||||||
Foreground: vaxis.IndexColor(1),
|
|
||||||
Attribute: vaxis.AttrReverse,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
state.Render()
|
|
||||||
loop:
|
|
||||||
for ev := range state.Events() {
|
|
||||||
switch ev.(type) {
|
|
||||||
case vaxis.Resize, vaxis.Redraw:
|
|
||||||
delete.Draw(state)
|
|
||||||
win.New(win.Width/2-14, win.Height/2-2+delete.list.Index(), 28, 1).Print(vaxis.Segment{
|
|
||||||
Text: " are you sure? ",
|
|
||||||
Style: vaxis.Style{
|
|
||||||
Foreground: vaxis.IndexColor(1),
|
|
||||||
Attribute: vaxis.AttrReverse,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
state.Render()
|
|
||||||
case vaxis.Key:
|
|
||||||
switch ev.(vaxis.Key).String() {
|
|
||||||
case "Enter", "l", "Right":
|
|
||||||
action()
|
|
||||||
delete.Draw(state)
|
|
||||||
win.New(win.Width/2-14, win.Height/2-2+delete.list.Index(), 28, 1).Print(vaxis.Segment{
|
|
||||||
Text: fmt.Sprintf(" %-26s", message),
|
|
||||||
Style: vaxis.Style{
|
|
||||||
Foreground: vaxis.IndexColor(1),
|
|
||||||
Attribute: vaxis.AttrReverse,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
state.Render()
|
|
||||||
for ev := range state.Events() {
|
|
||||||
switch ev.(type) {
|
|
||||||
case vaxis.Resize, vaxis.Redraw:
|
|
||||||
delete.Draw(state)
|
|
||||||
win.New(win.Width/2-14, win.Height/2-2+delete.list.Index(), 28, 1).Print(vaxis.Segment{
|
|
||||||
Text: fmt.Sprintf(" %26s", message),
|
|
||||||
Style: vaxis.Style{
|
|
||||||
Foreground: vaxis.IndexColor(1),
|
|
||||||
Attribute: vaxis.AttrReverse,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
state.Render()
|
|
||||||
case vaxis.Key:
|
|
||||||
if ev.(vaxis.Key).EventType == vaxis.EventPress {
|
|
||||||
ui.ViewChange <- NewBury()
|
|
||||||
break loop
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break loop
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
147
app/delete.go
147
app/delete.go
|
@ -1,147 +0,0 @@
|
||||||
package app
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"os/user"
|
|
||||||
"path"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"git.sr.ht/~rockorager/vaxis"
|
|
||||||
"git.tilde.town/nbsp/neofeels/ttbp"
|
|
||||||
"git.tilde.town/nbsp/neofeels/ui"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Delete struct {
|
|
||||||
title string
|
|
||||||
list ui.List
|
|
||||||
help string
|
|
||||||
posts []ttbp.Post
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewDelete() *Delete {
|
|
||||||
user, _ := user.Current()
|
|
||||||
posts := ttbp.GetPostsForUser(user.Username)
|
|
||||||
list := []string{}
|
|
||||||
for _, post := range posts {
|
|
||||||
list = append(list, fmt.Sprintf(
|
|
||||||
"%s (%d words)",
|
|
||||||
post.Date.Format("2006-01-02"),
|
|
||||||
post.Words,
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
return &Delete{
|
|
||||||
title,
|
|
||||||
ui.NewList(list),
|
|
||||||
"↑↓/kj move ↵ enter q return",
|
|
||||||
posts,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (delete *Delete) 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":
|
|
||||||
delete.list.Down()
|
|
||||||
case "Up", "k", "Ctrl+p":
|
|
||||||
delete.list.Up()
|
|
||||||
case "End", "Shift+g":
|
|
||||||
delete.list.End()
|
|
||||||
case "Home", "g":
|
|
||||||
delete.list.Home()
|
|
||||||
case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9":
|
|
||||||
i, _ := strconv.Atoi(key.String())
|
|
||||||
delete.list.SetIndex(i)
|
|
||||||
case "q", "h", "Left":
|
|
||||||
ui.ViewChange <- NewManagement()
|
|
||||||
case "Enter", "l", "Right":
|
|
||||||
if len(delete.list.Items()) > 0 {
|
|
||||||
delete.Confirmation(state, func() {
|
|
||||||
os.Remove(path.Join(ttbp.PathUserEntries, delete.posts[delete.list.Index()].Date.Format("20060102.txt")))
|
|
||||||
}, "feels deleted")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
processed = true
|
|
||||||
}
|
|
||||||
delete.Draw(state)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (delete *Delete) Draw(state *ui.State) {
|
|
||||||
win := state.Window()
|
|
||||||
win.New(win.Width/2-10, win.Height/2-8, 20, 5).Print(vaxis.Segment{Text: delete.title})
|
|
||||||
delete.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: delete.help})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (delete *Delete) Confirmation(state *ui.State, action func(), message string) {
|
|
||||||
delete.Draw(state)
|
|
||||||
win := state.Window()
|
|
||||||
win.New(win.Width/2-14, win.Height/2-2+delete.list.Index(), 28, 1).Print(vaxis.Segment{
|
|
||||||
Text: " are you sure? ",
|
|
||||||
Style: vaxis.Style{
|
|
||||||
Foreground: vaxis.IndexColor(1),
|
|
||||||
Attribute: vaxis.AttrReverse,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
state.Render()
|
|
||||||
loop:
|
|
||||||
for ev := range state.Events() {
|
|
||||||
switch ev.(type) {
|
|
||||||
case vaxis.Resize, vaxis.Redraw:
|
|
||||||
delete.Draw(state)
|
|
||||||
win.New(win.Width/2-14, win.Height/2-2+delete.list.Index(), 28, 1).Print(vaxis.Segment{
|
|
||||||
Text: " are you sure? ",
|
|
||||||
Style: vaxis.Style{
|
|
||||||
Foreground: vaxis.IndexColor(1),
|
|
||||||
Attribute: vaxis.AttrReverse,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
state.Render()
|
|
||||||
case vaxis.Key:
|
|
||||||
switch ev.(vaxis.Key).String() {
|
|
||||||
case "Enter", "l", "Right":
|
|
||||||
action()
|
|
||||||
delete.Draw(state)
|
|
||||||
win.New(win.Width/2-14, win.Height/2-2+delete.list.Index(), 28, 1).Print(vaxis.Segment{
|
|
||||||
Text: fmt.Sprintf(" %-26s", message),
|
|
||||||
Style: vaxis.Style{
|
|
||||||
Foreground: vaxis.IndexColor(1),
|
|
||||||
Attribute: vaxis.AttrReverse,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
state.Render()
|
|
||||||
for ev := range state.Events() {
|
|
||||||
switch ev.(type) {
|
|
||||||
case vaxis.Resize, vaxis.Redraw:
|
|
||||||
delete.Draw(state)
|
|
||||||
win.New(win.Width/2-14, win.Height/2-2+delete.list.Index(), 28, 1).Print(vaxis.Segment{
|
|
||||||
Text: fmt.Sprintf(" %26s", message),
|
|
||||||
Style: vaxis.Style{
|
|
||||||
Foreground: vaxis.IndexColor(1),
|
|
||||||
Attribute: vaxis.AttrReverse,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
state.Render()
|
|
||||||
case vaxis.Key:
|
|
||||||
if ev.(vaxis.Key).EventType == vaxis.EventPress {
|
|
||||||
ui.ViewChange <- NewDelete()
|
|
||||||
break loop
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break loop
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -3,11 +3,8 @@ package app
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
|
||||||
"os/user"
|
"os/user"
|
||||||
"path"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
|
||||||
|
|
||||||
"git.sr.ht/~rockorager/vaxis"
|
"git.sr.ht/~rockorager/vaxis"
|
||||||
"git.tilde.town/nbsp/neofeels/ttbp"
|
"git.tilde.town/nbsp/neofeels/ttbp"
|
||||||
|
@ -28,8 +25,8 @@ func NewManagement() *Management {
|
||||||
"modify feels publishing", // TODO
|
"modify feels publishing", // TODO
|
||||||
"backup your feels", // TODO
|
"backup your feels", // TODO
|
||||||
"import a feels backup", // TODO
|
"import a feels backup", // TODO
|
||||||
"bury some feels",
|
"bury some feels", // TODO
|
||||||
"delete feels by day",
|
"delete feels by day", // TODO
|
||||||
"purge all feels",
|
"purge all feels",
|
||||||
"wipe feels account",
|
"wipe feels account",
|
||||||
}),
|
}),
|
||||||
|
@ -60,14 +57,6 @@ func (management *Management) Event(state *ui.State, event vaxis.Event) (process
|
||||||
case 0:
|
case 0:
|
||||||
user, _ := user.Current()
|
user, _ := user.Current()
|
||||||
ui.ViewChange <- NewUserPage(user.Username, true)
|
ui.ViewChange <- NewUserPage(user.Username, true)
|
||||||
// case 1:
|
|
||||||
case 2:
|
|
||||||
management.SaveBackup(state)
|
|
||||||
// case 3:
|
|
||||||
case 4:
|
|
||||||
ui.ViewChange <- NewBury()
|
|
||||||
case 5:
|
|
||||||
ui.ViewChange <- NewDelete()
|
|
||||||
case 6:
|
case 6:
|
||||||
management.Confirmation(state, purgeFeels, "feels purged")
|
management.Confirmation(state, purgeFeels, "feels purged")
|
||||||
case 7:
|
case 7:
|
||||||
|
@ -107,44 +96,6 @@ func wipeAccount() {
|
||||||
close(ui.Quit)
|
close(ui.Quit)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (management *Management) SaveBackup(state *ui.State) {
|
|
||||||
os.MkdirAll(ttbp.PathUserBackups, 0700)
|
|
||||||
filename := time.Now().Format("feels-backup-20060102-150405.tar.gz")
|
|
||||||
|
|
||||||
exec.Command("tar", "-C", ttbp.PathUserFeels, "-czf", filename, "entries").Run()
|
|
||||||
exec.Command("tar", "-C", ttbp.PathUserFeels, "-czf", path.Join(ttbp.PathUserBackups, filename), "entries").Run()
|
|
||||||
|
|
||||||
management.Draw(state)
|
|
||||||
win := state.Window()
|
|
||||||
win.New(win.Width/2-14, win.Height/2-2+management.list.Index(), 28, 1).Print(vaxis.Segment{
|
|
||||||
Text: " backup saved ",
|
|
||||||
Style: vaxis.Style{
|
|
||||||
Foreground: vaxis.IndexColor(2),
|
|
||||||
Attribute: vaxis.AttrReverse,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
state.Render()
|
|
||||||
loop:
|
|
||||||
for ev := range state.Events() {
|
|
||||||
switch ev.(type) {
|
|
||||||
case vaxis.Resize, vaxis.Redraw:
|
|
||||||
management.Draw(state)
|
|
||||||
win.New(win.Width/2-14, win.Height/2-2+management.list.Index(), 28, 1).Print(vaxis.Segment{
|
|
||||||
Text: " backup saved ",
|
|
||||||
Style: vaxis.Style{
|
|
||||||
Foreground: vaxis.IndexColor(2),
|
|
||||||
Attribute: vaxis.AttrReverse,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
state.Render()
|
|
||||||
case vaxis.Key:
|
|
||||||
if ev.(vaxis.Key).EventType == vaxis.EventPress {
|
|
||||||
break loop
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: abstract this to our own List type
|
// TODO: abstract this to our own List type
|
||||||
// TODO: figure out a less janky way instead of nesting event channels
|
// TODO: figure out a less janky way instead of nesting event channels
|
||||||
func (management *Management) Confirmation(state *ui.State, action func(), message string) {
|
func (management *Management) Confirmation(state *ui.State, action func(), message string) {
|
||||||
|
|
|
@ -29,8 +29,6 @@ var (
|
||||||
PathUserHTML = path.Join(PathUser, "public_html")
|
PathUserHTML = path.Join(PathUser, "public_html")
|
||||||
PathUserConfig = path.Join(PathUserFeels, "config")
|
PathUserConfig = path.Join(PathUserFeels, "config")
|
||||||
PathUserEntries = path.Join(PathUserFeels, "entries")
|
PathUserEntries = path.Join(PathUserFeels, "entries")
|
||||||
PathUserBuried = path.Join(PathUserFeels, "buried")
|
|
||||||
PathUserBackups = path.Join(PathUserFeels, "backups")
|
|
||||||
PathUserWWW = path.Join(PathUserFeels, "www")
|
PathUserWWW = path.Join(PathUserFeels, "www")
|
||||||
PathUserRc = path.Join(PathUserConfig, "ttbprc")
|
PathUserRc = path.Join(PathUserConfig, "ttbprc")
|
||||||
PathUserNopub = path.Join(PathUserConfig, "nopub")
|
PathUserNopub = path.Join(PathUserConfig, "nopub")
|
||||||
|
|
Loading…
Reference in New Issue