~chrisppy/beagles

93c52c7cdc138bda39e68132115e5766c6d4536c — Chris Palmer 1 year, 2 months ago 43f0f22
Fix scrolling on help page
4 files changed, 126 insertions(+), 85 deletions(-)

A ui/helpContent.go
M ui/helpPage.go
M ui/status.go
M ui/ui.go
A ui/helpContent.go => ui/helpContent.go +119 -0
@@ 0,0 1,119 @@
// This file is part of beagles.
//
// Copyright © 2020 Chris Palmer <chris@red-oxide.org>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

package ui

import (
	"fmt"

	"git.sr.ht/~chrisppy/beagles/config"
	"github.com/gdamore/tcell"
	tui "gitlab.com/tslocum/cview"
)

type helpContent struct {
	Widget *tui.TextView
}

func newHelpContent(config *config.Config, version string) *helpContent {
	text := `beagles v%s is available under the terms of the GPL-3.0 license.
Copyright © 2020  Chris Palmer <chris@red-oxide.org>
https://git.sr.ht/~chrisppy/beagles

KEYS:
	%c,🠔
		move to the left section (if applicable)
	
	%c,🠗
		navigate down in the current section (if applicable)
	
	%c,🠕
		navigate up in the current section (if applicable)
	
	%c,🠖
		move the the right section (if applicable)
	
	%c
		mark current post as read when in LIST, CONTENT, or 
		SUBSCRIPTIONS

	%c
		mark current post as unread when in CONTENT or SUBSCRIPTIONS

	%c
		open post url when in LIST or CONTENT

	%c
		download a single podcast when in LIST, CONTENT, or 
		SUBSCRIPTIONS

	%c
		play single podcast when in LIST, CONTENT, or SUBSCRIPTIONS

	ENTER
		expand/collapse subscription in SUBSCRIPTIONS

	:
		enter command mode

COMMANDS:
	add [url]
		add a feed

	remove,rm [url]
		remove the feed

	update,up
		update all feeds

	help,h,?
		display help page

	list
		display list page

	sub,subscriptions
		display subscriptions page
	
	quit,q
		exit the application

SEE ALSO:
	Additional information can be found in the manual pages:
		beagles(1)
		beagles-config(5)
`

	h := tui.NewTextView()
	h.SetTextAlign(tui.AlignLeft)
	h.SetScrollable(true)
	h.SetText(fmt.Sprintf(text, version, config.KeyCommands.Left, config.KeyCommands.Down, config.KeyCommands.Up, config.KeyCommands.Right, config.KeyCommands.MarkRead, config.KeyCommands.MarkUnread, config.KeyCommands.OpenURL, config.KeyCommands.Download, config.KeyCommands.Play))

	bgColor := config.BackgroundColor
	fgColor := config.ForegroundColor
	if config.Help != nil {
		bgColor = config.Help.BackgroundColor
		fgColor = config.Help.ForegroundColor
	}

	h.SetBackgroundColor(tcell.GetColor(bgColor))
	h.SetTextColor(tcell.GetColor(fgColor))

	return &helpContent{
		Widget: h,
	}
}

M ui/helpPage.go => ui/helpPage.go +4 -85
@@ 18,100 18,19 @@
package ui

import (
	"fmt"

	"git.sr.ht/~chrisppy/beagles/config"
	"github.com/gdamore/tcell"
	tui "gitlab.com/tslocum/cview"
)

func (i *UI) createHelpPage(config *config.Config) {
	text := `beagles v%s is available under the terms of the GPL-3.0 license.
Copyright © 2020  Chris Palmer <chris@red-oxide.org>
https://git.sr.ht/~chrisppy/beagles

KEYS:
	%c,🠔
		move to the left section (if applicable)
	
	%c,🠗
		navigate down in the current section (if applicable)
	
	%c,🠕
		navigate up in the current section (if applicable)
	
	%c,🠖
		move the the right section (if applicable)
	
	%c
		mark current post as read when in LIST, CONTENT, or 
		SUBSCRIPTIONS

	%c
		mark current post as unread when in CONTENT or SUBSCRIPTIONS

	%c
		open post url when in LIST or CONTENT

	%c
		download a single podcast when in LIST, CONTENT, or 
		SUBSCRIPTIONS

	%c
		play single podcast when in LIST, CONTENT, or SUBSCRIPTIONS

	ENTER
		expand/collapse subscription in SUBSCRIPTIONS

	:
		enter command mode

COMMANDS:
	add [url]
		add a feed

	remove,rm [url]
		remove the feed

	update,up
		update all feeds

	help,h,?
		display help page

	list
		display list page

	sub,subscriptions
		display subscriptions page
	
	quit,q
		exit the application

SEE ALSO:
	Additional information can be found in the manual pages:
		beagles(1)
		beagles-config(5)
`

	h := tui.NewTextView()
	h.SetText(fmt.Sprintf(text, i.Version, i.Config.KeyCommands.Left, i.Config.KeyCommands.Down, i.Config.KeyCommands.Up, i.Config.KeyCommands.Right, i.Config.KeyCommands.MarkRead, i.Config.KeyCommands.MarkUnread, i.Config.KeyCommands.OpenURL, i.Config.KeyCommands.Download, i.Config.KeyCommands.Play))
	h.SetTextAlign(tui.AlignLeft)

	bgColor := config.BackgroundColor
	fgColor := config.ForegroundColor
	if config.Help != nil {
		bgColor = config.Help.BackgroundColor
		fgColor = config.Help.ForegroundColor
	}

	h.SetBackgroundColor(tcell.GetColor(bgColor))
	h.SetTextColor(tcell.GetColor(fgColor))
	qc := tui.NewFlex()
	qc.SetDirection(tui.FlexColumn)
	qc.AddItem(i.helpContent.Widget, 0, 1, false)

	cv := tui.NewFlex()
	cv.SetDirection(tui.FlexRow)
	cv.AddItem(newTitleLine(config), 1, 0, false)
	cv.AddItem(h, 0, 1, false)
	cv.AddItem(qc, 0, 1, false)
	cv.AddItem(i.statusLine.Widget, 1, 1, false)
	cv.AddItem(i.commandLine.Widget, 1, 0, false)


M ui/status.go => ui/status.go +1 -0
@@ 48,6 48,7 @@ func (i *UI) setStatus(s statusType) {
		i.inCmdMode = false
		i.statusLine.setText("-- HELP --")
		i.pages.SwitchToPage("help")
		i.app.switchTo(i.helpContent.Widget)
	case subStatus:
		i.inCmdMode = false
		i.statusLine.setText("-- SUBSCRIPTIONS --")

M ui/ui.go => ui/ui.go +2 -0
@@ 40,6 40,7 @@ type UI struct {
	commandLine  *commandLine
	content      *content
	subContent   *content
	helpContent  *helpContent
	list         *list
	subTree      *tree
	statusLine   *statusLine


@@ 51,6 52,7 @@ func (i *UI) Init() {
	i.commandLine = newCommandLine(i.Config)
	i.content = newContent(i.Config)
	i.subContent = newContent(i.Config)
	i.helpContent = newHelpContent(i.Config, i.Version)
	i.list = newList(i.Config)
	i.subTree = newTree(i.Config)
	i.statusLine = newStatusLine(i.Config)