~chrisppy/titan

3fe56b6f75ca6d6475e7b9dae0ab00bc03eeee1a — Chris Palmer 2 months ago 17021ce main
move to some constants and change from browser to capsules
10 files changed, 75 insertions(+), 69 deletions(-)

M app.go
M bindings.go
M browser.go
M config.go
M defaultConfig.go
M doc/titan-config.5.scd
M doc/titan.1.scd
M help.go
M main.go
M ui.go
M app.go => app.go +2 -2
@@ 90,7 90,7 @@ func (a *app) init() {
	a.loadGemini()
	a.loadUI(links)

	a.Dirs.Log = filepath.Join(a.Dirs.Log, "beagles.log")
	a.Dirs.Log = filepath.Join(a.Dirs.Log, "titan.log")
	f, err := os.OpenFile(filepath.Clean(a.Dirs.Log), os.O_WRONLY|os.O_CREATE|os.O_APPEND, 00600)
	if err != nil {
		a.Logger.Fatalf("Error: unable to load logfile due to %s", err.Error())


@@ 101,7 101,7 @@ func (a *app) init() {
func (a *app) run() error {
	a.UI.Application.SetRoot(a.UI.MainView, true)

	a.UI.Panels.SetCurrentPanel("browser")
	a.UI.Panels.SetCurrentPanel(capsulesName)
	a.UI.Application.SetFocus(a.UI.BrowserPanel.TabbedPanels)

	return a.UI.Application.Run()

M bindings.go => bindings.go +32 -32
@@ 39,7 39,7 @@ func (a *app) addBindings() {
	a.addBinding(a.moveUp, a.Config.NavUp)
	a.addBinding(a.moveDown, a.Config.NavDown)
	a.addBinding(a.moveRight, a.Config.NavRight)
	a.addBinding(a.showBrowser, a.Config.BrowserPage)
	a.addBinding(a.showBrowser, a.Config.CapsulesPage)
	a.addBinding(a.showHelp, a.Config.HelpPage)

	// CommandLine


@@ 71,7 71,7 @@ func (a *app) moveLeft(event *tcell.EventKey) *tcell.EventKey {
	}

	switch a.UI.Status {
	case browserStatus:
	case capsulesStatus:
		if len(a.UI.BrowserPanel.TabNames) < 2 {
			return nil
		} else if a.UI.BrowserPanel.CurrentIndex == 0 {


@@ 93,7 93,7 @@ func (a *app) moveRight(event *tcell.EventKey) *tcell.EventKey {
	}

	switch a.UI.Status {
	case browserStatus:
	case capsulesStatus:
		if len(a.UI.BrowserPanel.TabNames) < 2 {
			return nil
		} else if a.UI.BrowserPanel.CurrentIndex == len(a.UI.BrowserPanel.TabNames)-1 {


@@ 113,7 113,7 @@ func (a *app) moveUp(event *tcell.EventKey) *tcell.EventKey {
	}

	switch a.UI.Status {
	case browserStatus:
	case capsulesStatus:
		if page, ok := a.UI.BrowserPanel.Tabs[a.UI.BrowserPanel.TabbedPanels.GetCurrentTab()]; ok {
			a.UI.Application.QueueUpdateDraw(func() {
				r, c := page.Content.GetScrollOffset()


@@ 137,7 137,7 @@ func (a *app) moveDown(event *tcell.EventKey) *tcell.EventKey {
	}

	switch a.UI.Status {
	case browserStatus:
	case capsulesStatus:
		if page, ok := a.UI.BrowserPanel.Tabs[a.UI.BrowserPanel.TabbedPanels.GetCurrentTab()]; ok {
			a.UI.Application.QueueUpdateDraw(func() {
				r, c := page.Content.GetScrollOffset()


@@ 161,7 161,7 @@ func (a *app) movePageUp(event *tcell.EventKey) *tcell.EventKey {
	}

	switch a.UI.Status {
	case browserStatus:
	case capsulesStatus:
		if page, ok := a.UI.BrowserPanel.Tabs[a.UI.BrowserPanel.TabbedPanels.GetCurrentTab()]; ok {
			a.UI.Application.QueueUpdateDraw(func() {
				r, c := page.Content.GetScrollOffset()


@@ 187,7 187,7 @@ func (a *app) movePageDown(event *tcell.EventKey) *tcell.EventKey {
	}

	switch a.UI.Status {
	case browserStatus:
	case capsulesStatus:
		if page, ok := a.UI.BrowserPanel.Tabs[a.UI.BrowserPanel.TabbedPanels.GetCurrentTab()]; ok {
			a.UI.Application.QueueUpdateDraw(func() {
				r, c := page.Content.GetScrollOffset()


@@ 211,11 211,11 @@ func (a *app) showBrowser(event *tcell.EventKey) *tcell.EventKey {
		return event
	}

	a.UI.Status = browserStatus
	a.UI.Status = capsulesStatus
	a.UI.Application.QueueUpdateDraw(func() {
		a.UI.CommandLine.SetText("")
		a.UI.StatusLine.SetText("-- BROWSER --")
		a.UI.Panels.SetCurrentPanel("browser")
		a.UI.StatusLine.SetText(capsulesLabel)
		a.UI.Panels.SetCurrentPanel(capsulesName)
		a.UI.Application.SetFocus(a.UI.BrowserPanel.TabbedPanels)
	})



@@ 230,8 230,8 @@ func (a *app) showHelp(event *tcell.EventKey) *tcell.EventKey {
	a.UI.Status = helpStatus
	a.UI.Application.QueueUpdateDraw(func() {
		a.UI.CommandLine.SetText("")
		a.UI.StatusLine.SetText("-- HELP --")
		a.UI.Panels.SetCurrentPanel("help")
		a.UI.StatusLine.SetText(helpLabel)
		a.UI.Panels.SetCurrentPanel(helpName)
		a.UI.Application.SetFocus(a.UI.HelpPanel.Content)
	})



@@ 246,7 246,7 @@ func (a *app) enterCommandMode(event *tcell.EventKey) *tcell.EventKey {
	a.UI.Application.QueueUpdateDraw(func() {
		a.UI.CommandLine.SetFieldTextColor(a.Config.Theme.CMDFGColor)
		a.UI.CommandLine.SetText(":")
		a.UI.StatusLine.SetText("-- COMMAND --")
		a.UI.StatusLine.SetText(cmdLabel)
		a.UI.Application.SetFocus(a.UI.CommandLine)
	})
	a.UI.InputMode = commandMode


@@ 264,10 264,10 @@ func (a *app) escapeCommandMode(event *tcell.EventKey) *tcell.EventKey {
		a.UI.CommandLine.SetFieldTextColor(a.Config.Theme.CMDFGColor)
		switch a.UI.Status {
		case helpStatus:
			a.UI.StatusLine.SetText("-- HELP --")
			a.UI.StatusLine.SetText(helpLabel)
			a.UI.Application.SetFocus(a.UI.HelpPanel.Content)
		case browserStatus:
			a.UI.StatusLine.SetText("-- BROWSER --")
		case capsulesStatus:
			a.UI.StatusLine.SetText(capsulesLabel)
			a.UI.Application.SetFocus(a.UI.BrowserPanel.TabbedPanels)
		}
		a.UI.CommandLine.SetMaskCharacter(0)


@@ 288,7 288,7 @@ func (a *app) edit(event *tcell.EventKey) *tcell.EventKey {
		a.UI.CommandLine.SetFieldTextColor(a.Config.Theme.CMDFGColor)
		t := a.UI.BrowserPanel.Tabs[a.UI.BrowserPanel.TabbedPanels.GetCurrentTab()]
		a.UI.CommandLine.SetText(fmt.Sprintf(":open %s", t.Capsules[t.CurrentIndex].URL))
		a.UI.StatusLine.SetText("-- COMMAND --")
		a.UI.StatusLine.SetText(cmdLabel)
		a.UI.Application.SetFocus(a.UI.CommandLine)
	})
	a.UI.InputMode = commandMode


@@ 304,7 304,7 @@ func (a *app) open(event *tcell.EventKey) *tcell.EventKey {
	a.UI.Application.QueueUpdateDraw(func() {
		a.UI.CommandLine.SetFieldTextColor(a.Config.Theme.CMDFGColor)
		a.UI.CommandLine.SetText(":open ")
		a.UI.StatusLine.SetText("-- COMMAND --")
		a.UI.StatusLine.SetText(cmdLabel)
		a.UI.Application.SetFocus(a.UI.CommandLine)
	})
	a.UI.InputMode = commandMode


@@ 320,7 320,7 @@ func (a *app) openTab(event *tcell.EventKey) *tcell.EventKey {
	a.UI.Application.QueueUpdateDraw(func() {
		a.UI.CommandLine.SetFieldTextColor(a.Config.Theme.CMDFGColor)
		a.UI.CommandLine.SetText(":open-tab ")
		a.UI.StatusLine.SetText("-- COMMAND --")
		a.UI.StatusLine.SetText(cmdLabel)
		a.UI.Application.SetFocus(a.UI.CommandLine)
	})
	a.UI.InputMode = commandMode


@@ 334,7 334,7 @@ func (a *app) closeTab(event *tcell.EventKey) *tcell.EventKey {
	}

	switch a.UI.Status {
	case browserStatus:
	case capsulesStatus:
		a.UI.Application.QueueUpdateDraw(func() {
			if len(a.UI.BrowserPanel.Tabs) == 1 {
				return


@@ 362,7 362,7 @@ func (a *app) back(event *tcell.EventKey) *tcell.EventKey {
	}

	switch a.UI.Status {
	case browserStatus:
	case capsulesStatus:
		name := a.UI.BrowserPanel.TabbedPanels.GetCurrentTab()
		if a.UI.BrowserPanel.Tabs[name].CurrentIndex == 0 {
			return nil


@@ 388,7 388,7 @@ func (a *app) forward(event *tcell.EventKey) *tcell.EventKey {
	}

	switch a.UI.Status {
	case browserStatus:
	case capsulesStatus:
		name := a.UI.BrowserPanel.TabbedPanels.GetCurrentTab()
		if a.UI.BrowserPanel.Tabs[name].CurrentIndex == len(a.UI.BrowserPanel.Tabs[name].Capsules)-1 {
			return nil


@@ 414,7 414,7 @@ func (a *app) navZero(event *tcell.EventKey) *tcell.EventKey {
	}

	switch a.UI.Status {
	case browserStatus:
	case capsulesStatus:
		a.openCapsule("0", "")
	default:
		return event


@@ 428,7 428,7 @@ func (a *app) navOne(event *tcell.EventKey) *tcell.EventKey {
	}

	switch a.UI.Status {
	case browserStatus:
	case capsulesStatus:
		a.openCapsule("1", "")
	default:
		return event


@@ 442,7 442,7 @@ func (a *app) navTwo(event *tcell.EventKey) *tcell.EventKey {
	}

	switch a.UI.Status {
	case browserStatus:
	case capsulesStatus:
		a.openCapsule("2", "")
	default:
		return event


@@ 456,7 456,7 @@ func (a *app) navThree(event *tcell.EventKey) *tcell.EventKey {
	}

	switch a.UI.Status {
	case browserStatus:
	case capsulesStatus:
		a.openCapsule("3", "")
	default:
		return event


@@ 470,7 470,7 @@ func (a *app) navFour(event *tcell.EventKey) *tcell.EventKey {
	}

	switch a.UI.Status {
	case browserStatus:
	case capsulesStatus:
		a.openCapsule("4", "")
	default:
		return event


@@ 484,7 484,7 @@ func (a *app) navFive(event *tcell.EventKey) *tcell.EventKey {
	}

	switch a.UI.Status {
	case browserStatus:
	case capsulesStatus:
		a.openCapsule("5", "")
	default:
		return event


@@ 498,7 498,7 @@ func (a *app) navSix(event *tcell.EventKey) *tcell.EventKey {
	}

	switch a.UI.Status {
	case browserStatus:
	case capsulesStatus:
		a.openCapsule("6", "")
	default:
		return event


@@ 512,7 512,7 @@ func (a *app) navSeven(event *tcell.EventKey) *tcell.EventKey {
	}

	switch a.UI.Status {
	case browserStatus:
	case capsulesStatus:
		a.openCapsule("7", "")
	default:
		return event


@@ 526,7 526,7 @@ func (a *app) navEight(event *tcell.EventKey) *tcell.EventKey {
	}

	switch a.UI.Status {
	case browserStatus:
	case capsulesStatus:
		a.openCapsule("8", "")
	default:
		return event


@@ 540,7 540,7 @@ func (a *app) navNine(event *tcell.EventKey) *tcell.EventKey {
	}

	switch a.UI.Status {
	case browserStatus:
	case capsulesStatus:
		a.openCapsule("9", "")
	default:
		return event

M browser.go => browser.go +1 -1
@@ 90,5 90,5 @@ func (a *app) loadBrowserPanel(links []string) {
	}
	a.UI.BrowserPanel.TabbedPanels.SetCurrentTab(a.UI.BrowserPanel.TabNames[a.UI.BrowserPanel.CurrentIndex])

	a.UI.Panels.AddPanel("browser", a.UI.BrowserPanel.View, true, true)
	a.UI.Panels.AddPanel(capsulesName, a.UI.BrowserPanel.View, true, true)
}

M config.go => config.go +5 -5
@@ 55,7 55,7 @@ type config struct {
	OpenTab            keyCMD
	CloseTab           keyCMD
	Edit               keyCMD
	BrowserPage        keyCMD
	CapsulesPage       keyCMD
	HelpPage           keyCMD
	Back               keyCMD
	Forward            keyCMD


@@ 304,13 304,13 @@ func (a *app) parseKeyCommands(dir *scfg.Directive) map[error]bool {
			} else {
				a.Config.Back = k
			}
		case "browser-page":
		case "capsules-page":
			if err := validateDirective(n, d, one); err != nil {
				errors[err] = false
			} else if k, err := createKeyCMD(d.Params[0]); err != nil {
				errors[err] = false
			} else {
				a.Config.BrowserPage = k
				a.Config.CapsulesPage = k
			}
		case "close-tab":
			if err := validateDirective(n, d, one); err != nil {


@@ 419,8 419,8 @@ func (a *app) parseKeyCommands(dir *scfg.Directive) map[error]bool {
	if reflect.DeepEqual(a.Config.HelpPage, keyCMD{}) {
		errors[fmt.Errorf("help-page is a required directive for key-commands")] = false
	}
	if reflect.DeepEqual(a.Config.BrowserPage, keyCMD{}) {
		errors[fmt.Errorf("browser-page is a required directive for key-commands")] = false
	if reflect.DeepEqual(a.Config.CapsulesPage, keyCMD{}) {
		errors[fmt.Errorf("capsulesbrowser-page is a required directive for key-commands")] = false
	}
	if reflect.DeepEqual(a.Config.NavLeft, keyCMD{}) {
		errors[fmt.Errorf("left is a required directive for key-commands")] = false

M defaultConfig.go => defaultConfig.go +1 -1
@@ 33,7 33,7 @@ home-page "gemini.circumlunar.space/"
# Reserved keys: 'Enter', 'Esc', ':' 
#
key-commands {
	browser-page B
	capsules-page C
	help-page H
	left h
	down j

M doc/titan-config.5.scd => doc/titan-config.5.scd +2 -2
@@ 131,8 131,8 @@ adding added a + between they keys, i.e. Alt+1. Note this is a ++
required block.


*browser-page* <key>
	Key used to switch the browser page.
*capsules-page* <key>
	Key used to switch the capsules page.

*help-page* <key>
	Key used to switch the help page.

M doc/titan.1.scd => doc/titan.1.scd +2 -2
@@ 30,8 30,8 @@ _titan_ is a terminal user interface based gemini browser.

## GENERAL

*B*
	display browser page
*C*
	display capsules page

*?*
	display help page

M help.go => help.go +3 -3
@@ 30,7 30,7 @@ https://git.sr.ht/~chrisppy/titan

KEYS:
	%s
		display browser page
		display capsules page

	%s
		display help page


@@ 102,7 102,7 @@ SEE ALSO:
func (a *app) loadHelpPanel() {
	content := fmt.Sprintf(helpText,
		Version,
		a.Config.BrowserPage.Text,
		a.Config.CapsulesPage.Text,
		a.Config.HelpPage.Text,
		a.Config.NavLeft.Text,
		a.Config.NavDown.Text,


@@ 133,5 133,5 @@ func (a *app) loadHelpPanel() {
	a.UI.HelpPanel.View.SetDirection(cview.FlexColumn)
	a.UI.HelpPanel.View.AddItem(a.UI.HelpPanel.Content, 0, 1, false)

	a.UI.Panels.AddPanel("help", a.UI.HelpPanel.View, true, true)
	a.UI.Panels.AddPanel(helpName, a.UI.HelpPanel.View, true, true)
}

M main.go => main.go +9 -3
@@ 23,11 23,17 @@ import (
	"github.com/emersion/go-appdir"
)

var (
	// Version of the application
	Version string
const (
	capsulesLabel = "-- CAPSULES --"
	helpLabel     = "-- HELP --"
	cmdLabel      = "-- COMMAND --"
	capsulesName  = "capsules"
	helpName      = "help"
)

// Version of the application
var Version string

func main() {
	d := appdir.New("titan")


M ui.go => ui.go +18 -18
@@ 39,7 39,7 @@ type status int

const (
	helpStatus status = iota
	browserStatus
	capsulesStatus
)

type ui struct {


@@ 89,7 89,7 @@ type browserPanel struct {
func (a *app) loadUI(links []string) {
	a.UI = &ui{
		InputMode:   normalMode,
		Status:      browserStatus,
		Status:      capsulesStatus,
		Bindings:    cbind.NewConfiguration(),
		Application: cview.NewApplication(),
		MainView:    cview.NewFlex(),


@@ 115,7 115,7 @@ func (a *app) loadUI(links []string) {
	a.UI.TitleLine.SetTextColor(a.Config.Theme.TitleFGColor)

	a.UI.StatusLine.SetTextAlign(cview.AlignLeft)
	a.UI.StatusLine.SetText("-- BROWSER --")
	a.UI.StatusLine.SetText(capsulesLabel)
	a.UI.StatusLine.SetBackgroundColor(a.Config.Theme.StatusBGColor)
	a.UI.StatusLine.SetTextColor(a.Config.Theme.StatusFGColor)



@@ 126,10 126,10 @@ func (a *app) loadUI(links []string) {
			a.UI.Application.QueueUpdateDraw(func() {
				switch a.UI.Status {
				case helpStatus:
					a.UI.StatusLine.SetText("-- HELP --")
					a.UI.StatusLine.SetText(helpLabel)
					a.UI.Application.SetFocus(a.UI.HelpPanel.Content)
				case browserStatus:
					a.UI.StatusLine.SetText("-- BROWSER --")
				case capsulesStatus:
					a.UI.StatusLine.SetText(capsulesLabel)
					a.UI.Application.SetFocus(a.UI.BrowserPanel.TabbedPanels)
				}
			})


@@ 153,10 153,10 @@ func (a *app) loadUI(links []string) {
				a.UI.CommandLine.SetFieldTextColor(a.Config.Theme.CMDFGColor)
				switch a.UI.Status {
				case helpStatus:
					a.UI.StatusLine.SetText("-- HELP --")
					a.UI.StatusLine.SetText(helpLabel)
					a.UI.Application.SetFocus(a.UI.HelpPanel.Content)
				case browserStatus:
					a.UI.StatusLine.SetText("-- BROWSER --")
				case capsulesStatus:
					a.UI.StatusLine.SetText(capsulesLabel)
					a.UI.Application.SetFocus(a.UI.BrowserPanel.TabbedPanels)
				}
				a.UI.CommandLine.SetMaskCharacter(0)


@@ 169,9 169,9 @@ func (a *app) loadUI(links []string) {
			switch args[0] {
			case ":open":
				a.UI.Application.QueueUpdateDraw(func() {
					a.UI.Status = browserStatus
					a.UI.StatusLine.SetText("-- BROWSER --")
					a.UI.Panels.SetCurrentPanel("browser")
					a.UI.Status = capsulesStatus
					a.UI.StatusLine.SetText(capsulesLabel)
					a.UI.Panels.SetCurrentPanel(capsulesName)
					a.UI.Application.SetFocus(a.UI.BrowserPanel.TabbedPanels)

					if len(args) != 2 {


@@ 201,9 201,9 @@ func (a *app) loadUI(links []string) {
					a.UI.BrowserPanel.Tabs[name].Capsules = append(a.UI.BrowserPanel.Tabs[name].Capsules[:a.UI.BrowserPanel.Tabs[name].CurrentIndex], c)
				})
			case ":open-tab":
				a.UI.Status = browserStatus
				a.UI.StatusLine.SetText("-- BROWSER --")
				a.UI.Panels.SetCurrentPanel("browser")
				a.UI.Status = capsulesStatus
				a.UI.StatusLine.SetText(capsulesLabel)
				a.UI.Panels.SetCurrentPanel(capsulesName)
				a.UI.Application.SetFocus(a.UI.BrowserPanel.TabbedPanels)

				if len(args) != 2 {


@@ 259,7 259,7 @@ func (a *app) loadUI(links []string) {
				a.UI.BrowserPanel.TabbedPanels.SetCurrentTab(a.UI.BrowserPanel.TabNames[a.UI.BrowserPanel.CurrentIndex])
			case ":trust":
				switch a.UI.Status {
				case browserStatus:
				case capsulesStatus:
					if t, ok := a.UI.BrowserPanel.Tabs[a.UI.BrowserPanel.TabbedPanels.GetCurrentTab()]; ok {
						if host, ok := a.Gemini.Hosts.Lookup(t.Capsules[t.CurrentIndex].Host); ok {
							if err := a.Gemini.HostsFile.WriteHost(host); err != nil {


@@ 275,8 275,8 @@ func (a *app) loadUI(links []string) {
			case ":help", ":h":
				a.UI.Application.QueueUpdateDraw(func() {
					a.UI.Status = helpStatus
					a.UI.StatusLine.SetText("-- HELP --")
					a.UI.Panels.SetCurrentPanel("help")
					a.UI.StatusLine.SetText(helpLabel)
					a.UI.Panels.SetCurrentPanel(helpName)
					a.UI.Application.SetFocus(a.UI.HelpPanel.Content)
				})
			case ":quit", ":q":