mirror of
https://github.com/makew0rld/amfora.git
synced 2025-01-03 14:56:27 -05:00
✨ Add support for .. in bottom bar - fixes #21
This commit is contained in:
parent
6499fe6ae9
commit
33f0c6781f
@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
### Added
|
### Added
|
||||||
- Alt-Left and Alt-Right for history navigation (#23)
|
- Alt-Left and Alt-Right for history navigation (#23)
|
||||||
|
- You can type `..` in the bottom bar to go up a directory in the URL (#21)
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- Bottom bar now says `URL/Num./Search: ` when space is pressed
|
- Bottom bar now says `URL/Num./Search: ` when space is pressed
|
||||||
|
@ -2,6 +2,8 @@ package display
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -122,6 +124,8 @@ func Init() {
|
|||||||
}
|
}
|
||||||
bottomBar.SetBackgroundColor(tcell.ColorWhite)
|
bottomBar.SetBackgroundColor(tcell.ColorWhite)
|
||||||
bottomBar.SetDoneFunc(func(key tcell.Key) {
|
bottomBar.SetDoneFunc(func(key tcell.Key) {
|
||||||
|
defer bottomBar.SetLabel("")
|
||||||
|
|
||||||
switch key {
|
switch key {
|
||||||
case tcell.KeyEnter:
|
case tcell.KeyEnter:
|
||||||
// Figure out whether it's a URL, link number, or search
|
// Figure out whether it's a URL, link number, or search
|
||||||
@ -131,11 +135,33 @@ func Init() {
|
|||||||
|
|
||||||
if strings.TrimSpace(query) == "" {
|
if strings.TrimSpace(query) == "" {
|
||||||
// Ignore
|
// Ignore
|
||||||
bottomBar.SetLabel("")
|
|
||||||
bottomBar.SetText(tabMap[curTab].Url)
|
bottomBar.SetText(tabMap[curTab].Url)
|
||||||
App.SetFocus(tabViews[curTab])
|
App.SetFocus(tabViews[curTab])
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if query == ".." && !strings.HasPrefix(query, "about:") {
|
||||||
|
// Go up a directory
|
||||||
|
parsed, err := url.Parse(tabMap[curTab].Url)
|
||||||
|
if err != nil {
|
||||||
|
// This shouldn't occur
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if parsed.Path == "/" {
|
||||||
|
// Can't go up further
|
||||||
|
bottomBar.SetText(tabMap[curTab].Url)
|
||||||
|
App.SetFocus(tabViews[curTab])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ex: /test/foo/ -> /test/foo//.. -> /test -> /test/
|
||||||
|
parsed.Path = path.Clean(parsed.Path+"/..") + "/"
|
||||||
|
if parsed.Path == "//" {
|
||||||
|
// Fix double slash that occurs at domain root
|
||||||
|
parsed.Path = "/"
|
||||||
|
}
|
||||||
|
URL(parsed.String())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
i, err := strconv.Atoi(query)
|
i, err := strconv.Atoi(query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -147,23 +173,19 @@ func Init() {
|
|||||||
// Full URL
|
// Full URL
|
||||||
URL(query)
|
URL(query)
|
||||||
}
|
}
|
||||||
bottomBar.SetLabel("")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if i <= len(tabMap[curTab].Links) && i > 0 {
|
if i <= len(tabMap[curTab].Links) && i > 0 {
|
||||||
// It's a valid link number
|
// It's a valid link number
|
||||||
followLink(tabMap[curTab].Url, tabMap[curTab].Links[i-1])
|
followLink(tabMap[curTab].Url, tabMap[curTab].Links[i-1])
|
||||||
bottomBar.SetLabel("")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Invalid link number
|
// Invalid link number
|
||||||
bottomBar.SetLabel("")
|
|
||||||
bottomBar.SetText(tabMap[curTab].Url)
|
bottomBar.SetText(tabMap[curTab].Url)
|
||||||
App.SetFocus(tabViews[curTab])
|
App.SetFocus(tabViews[curTab])
|
||||||
|
|
||||||
case tcell.KeyEscape:
|
case tcell.KeyEscape:
|
||||||
// Set back to what it was
|
// Set back to what it was
|
||||||
bottomBar.SetLabel("")
|
|
||||||
bottomBar.SetText(tabMap[curTab].Url)
|
bottomBar.SetText(tabMap[curTab].Url)
|
||||||
App.SetFocus(tabViews[curTab])
|
App.SetFocus(tabViews[curTab])
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ b, Alt-Left|Go back a page
|
|||||||
f, Alt-Right|Go forward a page
|
f, Alt-Right|Go forward a page
|
||||||
g|Go to top of document
|
g|Go to top of document
|
||||||
G|Go to bottom of document
|
G|Go to bottom of document
|
||||||
spacebar|Open bar at the bottom - type a URL or link number
|
spacebar|Open bar at the bottom - type a URL, link number, or search term. You can also type two dots (..) to go up a directory in the URL.
|
||||||
Enter|On a page this will start link highlighting. Press Tab and Shift-Tab to pick different links. Press enter again to go to one.
|
Enter|On a page this will start link highlighting. Press Tab and Shift-Tab to pick different links. Press enter again to go to one.
|
||||||
Shift-NUMBER|Go to a specific tab.
|
Shift-NUMBER|Go to a specific tab.
|
||||||
Shift-0, )|Go to the last tab.
|
Shift-0, )|Go to the last tab.
|
||||||
|
Loading…
Reference in New Issue
Block a user