Compare commits
No commits in common. "db53b2100529c4cb9984b9919aab865aa2093b9c" and "6b5bc6b0efb7c36b1440db969131eb81e148526e" have entirely different histories.
db53b21005
...
6b5bc6b0ef
|
@ -21,7 +21,7 @@ make
|
|||
- [x] plaintext
|
||||
- [x] html
|
||||
- [ ] gopher
|
||||
- [x] graffiti
|
||||
- [ ] graffiti
|
||||
- [x] documentation with manpages
|
||||
|
||||
## contributing
|
||||
|
|
121
app/backups.go
121
app/backups.go
|
@ -1,121 +0,0 @@
|
|||
package app
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"git.sr.ht/~rockorager/vaxis"
|
||||
"git.tilde.town/nbsp/neofeels/ttbp"
|
||||
"git.tilde.town/nbsp/neofeels/ui"
|
||||
"github.com/dustin/go-humanize"
|
||||
)
|
||||
|
||||
type Backups struct {
|
||||
title string
|
||||
list ui.List
|
||||
help string
|
||||
description string
|
||||
backups []fs.DirEntry
|
||||
}
|
||||
|
||||
func NewBackups() *Backups {
|
||||
os.MkdirAll(ttbp.PathUserBackups, 0700)
|
||||
backups, _ := os.ReadDir(ttbp.PathUserBackups)
|
||||
list := []string{}
|
||||
for _, backup := range backups {
|
||||
timestamp, err := time.Parse("feels-backup-20060102-150405.tar.gz", backup.Name())
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
list = append(list, humanize.Time(timestamp.Local()))
|
||||
}
|
||||
|
||||
return &Backups{
|
||||
title,
|
||||
ui.NewList(list),
|
||||
"↑↓/kj move ↵ enter q return",
|
||||
"choose a backup to restore",
|
||||
backups,
|
||||
}
|
||||
}
|
||||
|
||||
func (backups *Backups) 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":
|
||||
backups.list.Down()
|
||||
case "Up", "k", "Ctrl+p":
|
||||
backups.list.Up()
|
||||
case "End", "Shift+g":
|
||||
backups.list.End()
|
||||
case "Home", "g":
|
||||
backups.list.Home()
|
||||
case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9":
|
||||
i, _ := strconv.Atoi(key.String())
|
||||
backups.list.SetIndex(i)
|
||||
case "q", "h", "Left":
|
||||
ui.ViewChange <- NewManagement()
|
||||
case "Enter", "l", "Right":
|
||||
if len(backups.list.Items()) > 0 {
|
||||
backups.LoadBackup(state)
|
||||
}
|
||||
}
|
||||
processed = true
|
||||
}
|
||||
backups.Draw(state)
|
||||
return
|
||||
}
|
||||
|
||||
func (backups *Backups) Draw(state *ui.State) {
|
||||
win := state.Window()
|
||||
win.New(win.Width/2-10, win.Height/2-8, 20, 5).Print(vaxis.Segment{Text: backups.title})
|
||||
win.New(win.Width/2-13, win.Height/2-2, 26, 1).Print(vaxis.Segment{Text: backups.description})
|
||||
backups.list.Draw(vaxis.Window{
|
||||
Vx: win.Vx,
|
||||
Parent: nil,
|
||||
Column: win.Width/2 - 14,
|
||||
Row: win.Height / 2,
|
||||
Width: 28,
|
||||
Height: 10,
|
||||
})
|
||||
if len(backups.list.Items()) == 0 {
|
||||
win.New(win.Width/2-8, win.Height/2+1, 16, 1).Print(vaxis.Segment{Text: "no backups found"})
|
||||
}
|
||||
win.New(win.Width/2-14, win.Height/2+11, 28, 1).Print(vaxis.Segment{Text: backups.help})
|
||||
}
|
||||
|
||||
func (backups *Backups) LoadBackup(state *ui.State) {
|
||||
backups.Draw(state)
|
||||
win := state.Window()
|
||||
win.New(win.Width/2-14, win.Height/2+backups.list.Index(), 28, 1).Print(vaxis.Segment{
|
||||
Text: " backup restored ",
|
||||
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:
|
||||
backups.Draw(state)
|
||||
win.New(win.Width/2-14, win.Height/2+backups.list.Index(), 28, 1).Print(vaxis.Segment{
|
||||
Text: " backup restored ",
|
||||
Style: vaxis.Style{
|
||||
Foreground: vaxis.IndexColor(2),
|
||||
Attribute: vaxis.AttrReverse,
|
||||
},
|
||||
})
|
||||
state.Render()
|
||||
case vaxis.Key:
|
||||
if ev.(vaxis.Key).EventType == vaxis.EventPress {
|
||||
break loop
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -26,8 +26,8 @@ func NewManagement() *Management {
|
|||
ui.NewList([]string{
|
||||
"read over feels",
|
||||
"modify feels publishing",
|
||||
"backup your feels",
|
||||
"import a feels backup",
|
||||
"backup your feels", // TODO
|
||||
"import a feels backup", // TODO
|
||||
"bury some feels",
|
||||
"delete feels by day",
|
||||
"purge all feels",
|
||||
|
@ -64,8 +64,7 @@ func (management *Management) Event(state *ui.State, event vaxis.Event) (process
|
|||
ui.ViewChange <- NewPublishing()
|
||||
case 2:
|
||||
management.SaveBackup(state)
|
||||
case 3:
|
||||
ui.ViewChange <- NewBackups()
|
||||
// case 3:
|
||||
case 4:
|
||||
ui.ViewChange <- NewBury()
|
||||
case 5:
|
||||
|
|
Loading…
Reference in New Issue