add configurable pager
parent
7e4456450c
commit
50cb60cdc4
|
@ -19,6 +19,7 @@ type Config struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
var configList = []string{
|
var configList = []string{
|
||||||
|
"pager",
|
||||||
"publish to html",
|
"publish to html",
|
||||||
"publish to gopher",
|
"publish to gopher",
|
||||||
"default to nopub",
|
"default to nopub",
|
||||||
|
@ -36,6 +37,10 @@ func NewConfig() *Config {
|
||||||
"↑↓/kj move ↵ enter q return",
|
"↑↓/kj move ↵ enter q return",
|
||||||
cfg,
|
cfg,
|
||||||
[]string{
|
[]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?
|
`do you want to publish your feels online?
|
||||||
|
|
||||||
if yes, your feels will be published to a directory of your choice in your
|
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":
|
case "Enter", "l", "Right", "Space":
|
||||||
switch config.list.Index() {
|
switch config.list.Index() {
|
||||||
case 0:
|
case 0:
|
||||||
config.config.Publishing = !config.config.Publishing
|
config.config.Pager = config.changePager(state)
|
||||||
case 1:
|
case 1:
|
||||||
config.config.Gopher = !config.config.Gopher
|
config.config.Publishing = !config.config.Publishing
|
||||||
case 2:
|
case 2:
|
||||||
config.config.Nopub = !config.config.Nopub
|
config.config.Gopher = !config.config.Gopher
|
||||||
case 3:
|
case 3:
|
||||||
config.config.HTML = !config.config.HTML
|
config.config.Nopub = !config.config.Nopub
|
||||||
case 4:
|
case 4:
|
||||||
|
config.config.HTML = !config.config.HTML
|
||||||
|
case 5:
|
||||||
config.config.PublishDir = config.changePublishDir(state)
|
config.config.PublishDir = config.changePublishDir(state)
|
||||||
}
|
}
|
||||||
config.config.Write()
|
config.config.Write()
|
||||||
|
@ -117,18 +124,19 @@ func (config *Config) Draw(state *ui.State) {
|
||||||
Column: win.Width/2 - 21,
|
Column: win.Width/2 - 21,
|
||||||
Row: win.Height/2 - 2,
|
Row: win.Height/2 - 2,
|
||||||
Width: 28,
|
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-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+14, 30, 1).Print(vaxis.Segment{Text: config.help})
|
win.New(win.Width/2-15, win.Height/2+15, 30, 1).Print(vaxis.Segment{Text: config.help})
|
||||||
|
|
||||||
// drawing the current selected options
|
// 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-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.Gopher)})
|
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.Nopub)})
|
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.HTML)})
|
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 {
|
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 ""
|
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 ""
|
||||||
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ func (graffiti *Graffiti) Event(state *ui.State, event vaxis.Event) (processed b
|
||||||
}
|
}
|
||||||
win := state.Window()
|
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-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})
|
win.New(win.Width/2-9, win.Height/2+8, 18, 1).Print(vaxis.Segment{Text: graffiti.help})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
13
app/user.go
13
app/user.go
|
@ -9,6 +9,7 @@ import (
|
||||||
|
|
||||||
"git.sr.ht/~rockorager/vaxis"
|
"git.sr.ht/~rockorager/vaxis"
|
||||||
"git.sr.ht/~rockorager/vaxis/widgets/term"
|
"git.sr.ht/~rockorager/vaxis/widgets/term"
|
||||||
|
"git.tilde.town/nbsp/neofeels/config"
|
||||||
"git.tilde.town/nbsp/neofeels/ttbp"
|
"git.tilde.town/nbsp/neofeels/ttbp"
|
||||||
"git.tilde.town/nbsp/neofeels/ui"
|
"git.tilde.town/nbsp/neofeels/ui"
|
||||||
)
|
)
|
||||||
|
@ -95,7 +96,15 @@ func showPost(state *ui.State, post ttbp.Post) {
|
||||||
vt.Attach(state.PostEvent())
|
vt.Attach(state.PostEvent())
|
||||||
vt.Focus()
|
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 == "" {
|
if pager == "" {
|
||||||
pager = "less"
|
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)
|
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 {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ type Config struct {
|
||||||
Publishing bool `json:"publishing"`
|
Publishing bool `json:"publishing"`
|
||||||
Rainbows bool `json:"rainbows"` // we don't care about this
|
Rainbows bool `json:"rainbows"` // we don't care about this
|
||||||
HTML bool `json:"html"`
|
HTML bool `json:"html"`
|
||||||
|
Pager string `json:"pager"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var Default = &Config{
|
var Default = &Config{
|
||||||
|
@ -24,6 +25,7 @@ var Default = &Config{
|
||||||
Publishing: false,
|
Publishing: false,
|
||||||
Rainbows: false,
|
Rainbows: false,
|
||||||
HTML: false,
|
HTML: false,
|
||||||
|
Pager: "less",
|
||||||
}
|
}
|
||||||
|
|
||||||
func Read() (config *Config, err error) {
|
func Read() (config *Config, err error) {
|
||||||
|
|
Loading…
Reference in New Issue