From 50cb60cdc4b305ab5675e43eb4b4fba1f770efda Mon Sep 17 00:00:00 2001 From: nbsp Date: Sun, 12 Jan 2025 14:25:31 +0200 Subject: [PATCH] add configurable pager --- app/config.go | 70 +++++++++++++++++++++++++++++++++++++++--------- app/graffiti.go | 2 +- app/user.go | 13 +++++++-- config/config.go | 2 ++ 4 files changed, 72 insertions(+), 15 deletions(-) diff --git a/app/config.go b/app/config.go index 9530ee7..23776bc 100644 --- a/app/config.go +++ b/app/config.go @@ -19,6 +19,7 @@ type Config struct { } var configList = []string{ + "pager", "publish to html", "publish to gopher", "default to nopub", @@ -36,6 +37,10 @@ func NewConfig() *Config { "↑↓/kj move ↵ enter q return", cfg, []string{ + `which pager do you want to use to display feels? + +here you can add additional pre-processing to your pager. leaving this option +unset defaults to $PAGER, and if that isn't set, neofeels falls back to less.`, `do you want to publish your feels online? if yes, your feels will be published to a directory of your choice in your @@ -85,14 +90,16 @@ func (config *Config) Event(state *ui.State, event vaxis.Event) (processed bool) case "Enter", "l", "Right", "Space": switch config.list.Index() { case 0: - config.config.Publishing = !config.config.Publishing + config.config.Pager = config.changePager(state) case 1: - config.config.Gopher = !config.config.Gopher + config.config.Publishing = !config.config.Publishing case 2: - config.config.Nopub = !config.config.Nopub + config.config.Gopher = !config.config.Gopher case 3: - config.config.HTML = !config.config.HTML + config.config.Nopub = !config.config.Nopub case 4: + config.config.HTML = !config.config.HTML + case 5: config.config.PublishDir = config.changePublishDir(state) } config.config.Write() @@ -117,18 +124,19 @@ func (config *Config) Draw(state *ui.State) { Column: win.Width/2 - 21, Row: win.Height/2 - 2, Width: 28, - Height: 5, + Height: 6, }) - win.New(win.Width/2-40, win.Height/2+4, 80, 10).Print(vaxis.Segment{Text: config.descriptions[config.list.Index()]}) - win.New(win.Width/2-15, win.Height/2+14, 30, 1).Print(vaxis.Segment{Text: config.help}) + win.New(win.Width/2-40, win.Height/2+5, 80, 10).Print(vaxis.Segment{Text: config.descriptions[config.list.Index()]}) + win.New(win.Width/2-15, win.Height/2+15, 30, 1).Print(vaxis.Segment{Text: config.help}) // drawing the current selected options - win.New(win.Width/2+7, win.Height/2-2, 14, 1).Print(vaxis.Segment{Text: fmt.Sprintf(" %-12v", config.config.Publishing)}) - win.New(win.Width/2+7, win.Height/2-1, 14, 1).Print(vaxis.Segment{Text: fmt.Sprintf(" %-12v", config.config.Gopher)}) - win.New(win.Width/2+7, win.Height/2, 14, 1).Print(vaxis.Segment{Text: fmt.Sprintf(" %-12v", config.config.Nopub)}) - win.New(win.Width/2+7, win.Height/2+1, 14, 1).Print(vaxis.Segment{Text: fmt.Sprintf(" %-12v", config.config.HTML)}) + win.New(win.Width/2+7, win.Height/2-2, 40, 1).Print(vaxis.Segment{Text: fmt.Sprintf(" %-12v", config.config.Pager)}) + win.New(win.Width/2+7, win.Height/2-1, 14, 1).Print(vaxis.Segment{Text: fmt.Sprintf(" %-12v", config.config.Publishing)}) + win.New(win.Width/2+7, win.Height/2, 14, 1).Print(vaxis.Segment{Text: fmt.Sprintf(" %-12v", config.config.Gopher)}) + win.New(win.Width/2+7, win.Height/2+1, 14, 1).Print(vaxis.Segment{Text: fmt.Sprintf(" %-12v", config.config.Nopub)}) + win.New(win.Width/2+7, win.Height/2+2, 14, 1).Print(vaxis.Segment{Text: fmt.Sprintf(" %-12v", config.config.HTML)}) if config.config.Publishing { - win.New(win.Width/2+7, win.Height/2+2, 14, 1).Print(vaxis.Segment{Text: fmt.Sprintf(" %-12v", config.config.PublishDir)}) + win.New(win.Width/2+7, win.Height/2+3, 14, 1).Print(vaxis.Segment{Text: fmt.Sprintf(" %-12v", config.config.PublishDir)}) } } @@ -169,3 +177,41 @@ func (config *Config) changePublishDir(state *ui.State) string { return "" } + +func (config *Config) changePager(state *ui.State) string { + ti := textinput.New() + ti.SetContent(config.config.Pager) + config.Draw(state) + win := state.Window() + ti.Draw(vaxis.Window{ + Vx: win.Vx, + Parent: &win, + Column: win.Width/2 + 9, + Row: win.Height/2 - 2, + Width: 40, + Height: 1, + }) + for ev := range win.Vx.Events() { + switch ev := ev.(type) { + case vaxis.Key: + switch ev.String() { + case "Ctrl+c", "Esc", "Enter": + state.HideCursor() + return ti.String() + } + } + ti.Update(ev) + config.Draw(state) + ti.Draw(vaxis.Window{ + Vx: win.Vx, + Parent: nil, + Column: win.Width/2 + 9, + Row: win.Height/2 - 2, + Width: 40, + Height: 1, + }) + state.Render() + } + + return "" +} diff --git a/app/graffiti.go b/app/graffiti.go index 8e4ae82..f1b34c7 100644 --- a/app/graffiti.go +++ b/app/graffiti.go @@ -57,7 +57,7 @@ func (graffiti *Graffiti) Event(state *ui.State, event vaxis.Event) (processed b } win := state.Window() win.New(win.Width/2-10, win.Height/2-8, 20, 5).Print(vaxis.Segment{Text: graffiti.title}) - win.New(win.Width/2-40, win.Height/2-2, 80, 9).Print(vaxis.Segment{Text: graffiti.content}) + win.New(win.Width/2-40, win.Height/2-2, 81, 9).Print(vaxis.Segment{Text: graffiti.content}) win.New(win.Width/2-9, win.Height/2+8, 18, 1).Print(vaxis.Segment{Text: graffiti.help}) return } diff --git a/app/user.go b/app/user.go index 2fc40c6..c082855 100644 --- a/app/user.go +++ b/app/user.go @@ -9,6 +9,7 @@ import ( "git.sr.ht/~rockorager/vaxis" "git.sr.ht/~rockorager/vaxis/widgets/term" + "git.tilde.town/nbsp/neofeels/config" "git.tilde.town/nbsp/neofeels/ttbp" "git.tilde.town/nbsp/neofeels/ui" ) @@ -95,7 +96,15 @@ func showPost(state *ui.State, post ttbp.Post) { vt.Attach(state.PostEvent()) vt.Focus() - pager := os.ExpandEnv(os.Getenv("PAGER")) + cfg, err := config.Read() + if err != nil { + panic(err) + } + pager := os.ExpandEnv(cfg.Pager) + if cfg.Pager == "" { + + pager = os.ExpandEnv(os.Getenv("PAGER")) + } if pager == "" { pager = "less" } @@ -106,7 +115,7 @@ func showPost(state *ui.State, post ttbp.Post) { } cmd := fmt.Sprintf("%s %s | %s", prepro, path.Join("/home", post.Author, ".ttbp/entries", post.Date.Format("20060102")+".txt"), pager) - err := vt.Start(exec.Command("sh", "-c", cmd)) + err = vt.Start(exec.Command("sh", "-c", cmd)) if err != nil { panic(err) } diff --git a/config/config.go b/config/config.go index eaf65ca..e36f722 100644 --- a/config/config.go +++ b/config/config.go @@ -14,6 +14,7 @@ type Config struct { Publishing bool `json:"publishing"` Rainbows bool `json:"rainbows"` // we don't care about this HTML bool `json:"html"` + Pager string `json:"pager"` } var Default = &Config{ @@ -24,6 +25,7 @@ var Default = &Config{ Publishing: false, Rainbows: false, HTML: false, + Pager: "less", } func Read() (config *Config, err error) {