Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom new tab page #83

Merged
merged 9 commits into from
Sep 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ var amforaAppData string // Where amfora files are stored on Windows - cached he
var configDir string
var configPath string

var NewTabPath string
var CustomNewTab bool

var TofuStore = viper.New()
var tofuDBDir string
var tofuDBPath string
Expand Down Expand Up @@ -61,6 +64,13 @@ func Init() error {
}
configPath = filepath.Join(configDir, "config.toml")

// Search for a custom new tab
NewTabPath = filepath.Join(configDir, "newtab.gmi")
CustomNewTab = false
if _, err := os.Stat(NewTabPath); err == nil {
CustomNewTab = true
}

// Store TOFU db directory and file paths
if runtime.GOOS == "windows" {
// Windows just stores it in APPDATA along with other stuff
Expand Down
23 changes: 20 additions & 3 deletions display/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ var tabRow = cview.NewTextView().
var layout = cview.NewFlex().
SetDirection(cview.FlexRow)

var renderedNewTabContent string
var newTabLinks []string
var newTabPage structs.Page

var App = cview.NewApplication().
Expand Down Expand Up @@ -202,7 +200,8 @@ func Init() {
})

// Render the default new tab content ONCE and store it for later
renderedNewTabContent, newTabLinks = renderer.RenderGemini(newTabContent, textWidth(), leftMargin())
newTabContent := getNewTabContent()
renderedNewTabContent, newTabLinks := renderer.RenderGemini(newTabContent, textWidth(), leftMargin())
newTabPage = structs.Page{
Raw: newTabContent,
Content: renderedNewTabContent,
Expand Down Expand Up @@ -519,6 +518,24 @@ func SwitchTab(tab int) {
}

func Reload() {
if tabs[curTab].page.URL == "about:newtab" && config.CustomNewTab {
// Re-render new tab, similar to Init()
newTabContent := getNewTabContent()
tmpTermW := termW
renderedNewTabContent, newTabLinks := renderer.RenderGemini(newTabContent, textWidth(), leftMargin())
newTabPage = structs.Page{
Raw: newTabContent,
Content: renderedNewTabContent,
Links: newTabLinks,
URL: "about:newtab",
Width: tmpTermW,
Mediatype: structs.TextGemini,
}
temp := newTabPage // Copy
setPage(tabs[curTab], &temp)
return
}

if !tabs[curTab].hasContent() {
return
}
Expand Down
21 changes: 19 additions & 2 deletions display/newtab.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
//nolint
package display

var newTabContent = `# New Tab
import (
"io/ioutil"

"github.com/makeworld-the-better-one/amfora/config"
)

//nolint
var defaultNewTabContent = `# New Tab

You've opened a new tab. Use the bar at the bottom to browse around. You can start typing in it by pressing the space key.

Press the ? key at any time to bring up the help, and see other keybindings. Most are what you expect.

You can customize this page by creating a gemtext file called newtab.gmi, in Amfora's configuration folder.

Happy browsing!

=> about:bookmarks Bookmarks

=> //gemini.circumlunar.space Project Gemini
=> https://github.com/makeworld-the-better-one/amfora Amfora homepage [HTTPS]
`

// Read the new tab content from a file if it exists or fallback to a default page.
func getNewTabContent() string {
data, err := ioutil.ReadFile(config.NewTabPath)
if err == nil {
return string(data)
}
return defaultNewTabContent
}