mirror of
https://github.com/makeworld-the-better-one/amfora.git
synced 2024-11-22 07:23:05 +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
|
### Changed
|
||||||
- Center text automatically, removing `left_margin` from the config (#233)
|
- Center text automatically, removing `left_margin` from the config (#233)
|
||||||
- `max_width` defaults to 80 columns instead of 100 (#233)
|
- `max_width` defaults to 80 columns instead of 100 (#233)
|
||||||
|
- Tabs have the domain of the current page instead of numbers (#202)
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Modal can't be closed when opening non-gemini text URLs from the commandline (#283, #284)
|
- 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
|
// Overwrite all tabs with a new, differently sized, left margin
|
||||||
browser.AddTab(
|
browser.AddTab(
|
||||||
strconv.Itoa(i),
|
strconv.Itoa(i),
|
||||||
makeTabLabel(strconv.Itoa(i+1)),
|
tabs[i].label(),
|
||||||
makeContentLayout(tabs[i].view, leftMargin()),
|
makeContentLayout(tabs[i].view, leftMargin()),
|
||||||
)
|
)
|
||||||
if tabs[i] == t {
|
if tabs[i] == t {
|
||||||
@ -438,7 +438,7 @@ func NewTabWithURL(url string) {
|
|||||||
|
|
||||||
browser.AddTab(
|
browser.AddTab(
|
||||||
strconv.Itoa(curTab),
|
strconv.Itoa(curTab),
|
||||||
makeTabLabel(strconv.Itoa(curTab+1)),
|
tabs[curTab].label(),
|
||||||
makeContentLayout(tabs[curTab].view, leftMargin()),
|
makeContentLayout(tabs[curTab].view, leftMargin()),
|
||||||
)
|
)
|
||||||
browser.SetCurrentTab(strconv.Itoa(curTab))
|
browser.SetCurrentTab(strconv.Itoa(curTab))
|
||||||
|
@ -118,7 +118,7 @@ func setPage(t *tab, p *structs.Page) {
|
|||||||
tabNum := tabNumber(t)
|
tabNum := tabNumber(t)
|
||||||
browser.AddTab(
|
browser.AddTab(
|
||||||
strconv.Itoa(tabNum),
|
strconv.Itoa(tabNum),
|
||||||
makeTabLabel(strconv.Itoa(tabNum+1)),
|
t.label(),
|
||||||
makeContentLayout(t.view, leftMargin()),
|
makeContentLayout(t.view, leftMargin()),
|
||||||
)
|
)
|
||||||
App.Draw()
|
App.Draw()
|
||||||
|
@ -3,6 +3,7 @@ package display
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -389,7 +390,7 @@ func (t *tab) applyHorizontalScroll() {
|
|||||||
// Scrolled to the right far enough that no left margin is needed
|
// Scrolled to the right far enough that no left margin is needed
|
||||||
browser.AddTab(
|
browser.AddTab(
|
||||||
strconv.Itoa(i),
|
strconv.Itoa(i),
|
||||||
makeTabLabel(strconv.Itoa(i+1)),
|
t.label(),
|
||||||
makeContentLayout(t.view, 0),
|
makeContentLayout(t.view, 0),
|
||||||
)
|
)
|
||||||
t.view.ScrollTo(t.page.Row, t.page.Column-leftMargin())
|
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
|
// Left margin is still needed, but is not necessarily at the right size by default
|
||||||
browser.AddTab(
|
browser.AddTab(
|
||||||
strconv.Itoa(i),
|
strconv.Itoa(i),
|
||||||
makeTabLabel(strconv.Itoa(i+1)),
|
t.label(),
|
||||||
makeContentLayout(t.view, leftMargin()-t.page.Column),
|
makeContentLayout(t.view, leftMargin()-t.page.Column),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -508,3 +509,35 @@ func (t *tab) highlightedURL() string {
|
|||||||
}
|
}
|
||||||
return ""
|
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
|
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
|
// tabNumber gets the index of the tab in the tabs slice. It returns -1
|
||||||
// if the tab is not in that slice.
|
// if the tab is not in that slice.
|
||||||
func tabNumber(t *tab) int {
|
func tabNumber(t *tab) int {
|
||||||
|
Loading…
Reference in New Issue
Block a user