mirror of
https://github.com/makew0rld/amfora.git
synced 2024-12-01 00:53:28 +03: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]
|
||||
### Added
|
||||
- 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
|
||||
- Bottom bar now says `URL/Num./Search: ` when space is pressed
|
||||
|
@ -2,6 +2,8 @@ package display
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@ -122,6 +124,8 @@ func Init() {
|
||||
}
|
||||
bottomBar.SetBackgroundColor(tcell.ColorWhite)
|
||||
bottomBar.SetDoneFunc(func(key tcell.Key) {
|
||||
defer bottomBar.SetLabel("")
|
||||
|
||||
switch key {
|
||||
case tcell.KeyEnter:
|
||||
// Figure out whether it's a URL, link number, or search
|
||||
@ -131,11 +135,33 @@ func Init() {
|
||||
|
||||
if strings.TrimSpace(query) == "" {
|
||||
// Ignore
|
||||
bottomBar.SetLabel("")
|
||||
bottomBar.SetText(tabMap[curTab].Url)
|
||||
App.SetFocus(tabViews[curTab])
|
||||
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)
|
||||
if err != nil {
|
||||
@ -147,23 +173,19 @@ func Init() {
|
||||
// Full URL
|
||||
URL(query)
|
||||
}
|
||||
bottomBar.SetLabel("")
|
||||
return
|
||||
}
|
||||
if i <= len(tabMap[curTab].Links) && i > 0 {
|
||||
// It's a valid link number
|
||||
followLink(tabMap[curTab].Url, tabMap[curTab].Links[i-1])
|
||||
bottomBar.SetLabel("")
|
||||
return
|
||||
}
|
||||
// Invalid link number
|
||||
bottomBar.SetLabel("")
|
||||
bottomBar.SetText(tabMap[curTab].Url)
|
||||
App.SetFocus(tabViews[curTab])
|
||||
|
||||
case tcell.KeyEscape:
|
||||
// Set back to what it was
|
||||
bottomBar.SetLabel("")
|
||||
bottomBar.SetText(tabMap[curTab].Url)
|
||||
App.SetFocus(tabViews[curTab])
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ b, Alt-Left|Go back a page
|
||||
f, Alt-Right|Go forward a page
|
||||
g|Go to top 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.
|
||||
Shift-NUMBER|Go to a specific tab.
|
||||
Shift-0, )|Go to the last tab.
|
||||
|
Loading…
Reference in New Issue
Block a user