mirror of
https://github.com/makew0rld/amfora.git
synced 2024-09-11 05:55:27 +03:00
parent
03c4d3e286
commit
1aa13f2408
@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
### Changed
|
||||
- Center text automatically, removing `left_margin` from the config (#233)
|
||||
- `max_width` defaults to 80 columns instead of 100 (#233)
|
||||
- Tabs have the domain of the current page instead of numbers (#202)
|
||||
|
||||
### Fixed
|
||||
- Modal can't be closed when opening non-gemini text URLs from the commandline (#283, #284)
|
||||
|
@ -88,7 +88,7 @@ func Init(version, commit, builtBy string) {
|
||||
// Overwrite all tabs with a new, differently sized, left margin
|
||||
browser.AddTab(
|
||||
strconv.Itoa(i),
|
||||
makeTabLabel(strconv.Itoa(i+1)),
|
||||
tabs[i].label(),
|
||||
makeContentLayout(tabs[i].view, leftMargin()),
|
||||
)
|
||||
if tabs[i] == t {
|
||||
@ -438,7 +438,7 @@ func NewTabWithURL(url string) {
|
||||
|
||||
browser.AddTab(
|
||||
strconv.Itoa(curTab),
|
||||
makeTabLabel(strconv.Itoa(curTab+1)),
|
||||
tabs[curTab].label(),
|
||||
makeContentLayout(tabs[curTab].view, leftMargin()),
|
||||
)
|
||||
browser.SetCurrentTab(strconv.Itoa(curTab))
|
||||
|
@ -118,7 +118,7 @@ func setPage(t *tab, p *structs.Page) {
|
||||
tabNum := tabNumber(t)
|
||||
browser.AddTab(
|
||||
strconv.Itoa(tabNum),
|
||||
makeTabLabel(strconv.Itoa(tabNum+1)),
|
||||
t.label(),
|
||||
makeContentLayout(t.view, leftMargin()),
|
||||
)
|
||||
App.Draw()
|
||||
|
@ -3,6 +3,7 @@ package display
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@ -389,7 +390,7 @@ func (t *tab) applyHorizontalScroll() {
|
||||
// Scrolled to the right far enough that no left margin is needed
|
||||
browser.AddTab(
|
||||
strconv.Itoa(i),
|
||||
makeTabLabel(strconv.Itoa(i+1)),
|
||||
t.label(),
|
||||
makeContentLayout(t.view, 0),
|
||||
)
|
||||
t.view.ScrollTo(t.page.Row, t.page.Column-leftMargin())
|
||||
@ -397,7 +398,7 @@ func (t *tab) applyHorizontalScroll() {
|
||||
// Left margin is still needed, but is not necessarily at the right size by default
|
||||
browser.AddTab(
|
||||
strconv.Itoa(i),
|
||||
makeTabLabel(strconv.Itoa(i+1)),
|
||||
t.label(),
|
||||
makeContentLayout(t.view, leftMargin()-t.page.Column),
|
||||
)
|
||||
}
|
||||
@ -508,3 +509,35 @@ func (t *tab) highlightedURL() string {
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// label returns the label to use for the tab name
|
||||
func (t *tab) label() string {
|
||||
tn := tabNumber(t)
|
||||
if tn < 0 {
|
||||
// Invalid tab, shouldn't happen
|
||||
return ""
|
||||
}
|
||||
|
||||
// Increment so there's no tab 0 in the label
|
||||
tn++
|
||||
|
||||
if t.page.URL == "" || t.page.URL == "about:newtab" {
|
||||
// Just use tab number
|
||||
// Spaces around to keep original Amfora look
|
||||
return fmt.Sprintf(" %d ", tn)
|
||||
}
|
||||
if strings.HasPrefix(t.page.URL, "about:") {
|
||||
// Don't look for domain, put the whole URL except query strings
|
||||
return strings.SplitN(t.page.URL, "?", 2)[0]
|
||||
}
|
||||
if strings.HasPrefix(t.page.URL, "file://") {
|
||||
// File URL, use file or folder as tab name
|
||||
return path.Base(t.page.URL[7:])
|
||||
}
|
||||
// Otherwise, it's a Gemini URL
|
||||
pu, err := url.Parse(t.page.URL)
|
||||
if err != nil {
|
||||
return fmt.Sprintf(" %d ", tn)
|
||||
}
|
||||
return pu.Host
|
||||
}
|
||||
|
@ -32,12 +32,6 @@ func makeContentLayout(tv *cview.TextView, leftMargin int) *cview.Flex {
|
||||
return vert
|
||||
}
|
||||
|
||||
// makeTabLabel takes a string and adds spacing to it, making it
|
||||
// suitable for display as a tab label.
|
||||
func makeTabLabel(s string) string {
|
||||
return " " + s + " "
|
||||
}
|
||||
|
||||
// tabNumber gets the index of the tab in the tabs slice. It returns -1
|
||||
// if the tab is not in that slice.
|
||||
func tabNumber(t *tab) int {
|
||||
|
Loading…
Reference in New Issue
Block a user