forked from sloum/bombadillo
Ran format on each file
This commit is contained in:
parent
2038c9c4ac
commit
e4f7147e4f
18
bookmarks.go
18
bookmarks.go
|
@ -12,12 +12,12 @@ import (
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
|
||||||
type Bookmarks struct {
|
type Bookmarks struct {
|
||||||
IsOpen bool
|
IsOpen bool
|
||||||
IsFocused bool
|
IsFocused bool
|
||||||
Position int
|
Position int
|
||||||
Length int
|
Length int
|
||||||
Titles []string
|
Titles []string
|
||||||
Links []string
|
Links []string
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
|
@ -115,11 +115,11 @@ func (b Bookmarks) Render(termwidth, termheight int) []string {
|
||||||
top := fmt.Sprintf("%s%s%s", tl, strings.Repeat(ceil, contentWidth), tr)
|
top := fmt.Sprintf("%s%s%s", tl, strings.Repeat(ceil, contentWidth), tr)
|
||||||
out = append(out, top)
|
out = append(out, top)
|
||||||
marks := b.List()
|
marks := b.List()
|
||||||
for i := 0; i < termheight - 2; i++ {
|
for i := 0; i < termheight-2; i++ {
|
||||||
if i + b.Position >= len(b.Titles) {
|
if i+b.Position >= len(b.Titles) {
|
||||||
out = append(out, fmt.Sprintf("%s%-*.*s%s", walll, contentWidth, contentWidth, "", wallr))
|
out = append(out, fmt.Sprintf("%s%-*.*s%s", walll, contentWidth, contentWidth, "", wallr))
|
||||||
} else {
|
} else {
|
||||||
out = append(out, fmt.Sprintf("%s%-*.*s%s", walll, contentWidth, contentWidth, marks[i + b.Position], wallr))
|
out = append(out, fmt.Sprintf("%s%-*.*s%s", walll, contentWidth, contentWidth, marks[i+b.Position], wallr))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +132,6 @@ func (b Bookmarks) Render(termwidth, termheight int) []string {
|
||||||
// either here with a scroll up/down or in the client
|
// either here with a scroll up/down or in the client
|
||||||
// code for scroll
|
// code for scroll
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
// + + + F U N C T I O N S + + + \\
|
// + + + F U N C T I O N S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
@ -140,4 +139,3 @@ func (b Bookmarks) Render(termwidth, termheight int) []string {
|
||||||
func MakeBookmarks() Bookmarks {
|
func MakeBookmarks() Bookmarks {
|
||||||
return Bookmarks{false, false, 0, 0, make([]string, 0), make([]string, 0)}
|
return Bookmarks{false, false, 0, 0, make([]string, 0), make([]string, 0)}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -877,7 +877,6 @@ func (c *client) Visit(url string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// +++ Begin Protocol Handlers +++
|
// +++ Begin Protocol Handlers +++
|
||||||
|
|
||||||
func (c *client) handleGopher(u Url) {
|
func (c *client) handleGopher(u Url) {
|
||||||
|
@ -1022,15 +1021,15 @@ func (c *client) handleWeb(u Url) {
|
||||||
c.SetMessage("The file is non-text: writing to disk...", false)
|
c.SetMessage("The file is non-text: writing to disk...", false)
|
||||||
c.DrawMessage()
|
c.DrawMessage()
|
||||||
var fn string
|
var fn string
|
||||||
if i := strings.LastIndex(u.Full, "/"); i > 0 && i + 1 < len(u.Full) {
|
if i := strings.LastIndex(u.Full, "/"); i > 0 && i+1 < len(u.Full) {
|
||||||
fn = u.Full[i + 1:]
|
fn = u.Full[i+1:]
|
||||||
} else {
|
} else {
|
||||||
fn = "bombadillo.download"
|
fn = "bombadillo.download"
|
||||||
}
|
}
|
||||||
c.saveFile(u, fn)
|
c.saveFile(u, fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open in default web browser if available
|
// Open in default web browser if available
|
||||||
} else {
|
} else {
|
||||||
if strings.ToUpper(c.Options["terminalonly"]) == "TRUE" {
|
if strings.ToUpper(c.Options["terminalonly"]) == "TRUE" {
|
||||||
c.SetMessage("'terminalonly' is set to true and 'lynxmode' is not enabled, cannot open web link", false)
|
c.SetMessage("'terminalonly' is set to true and 'lynxmode' is not enabled, cannot open web link", false)
|
||||||
|
@ -1049,7 +1048,6 @@ func (c *client) handleWeb(u Url) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
// + + + F U N C T I O N S + + + \\
|
// + + + F U N C T I O N S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
@ -1075,4 +1073,3 @@ func findAvailableFileName(fpath, fname string) (string, error) {
|
||||||
|
|
||||||
return savePath, nil
|
return savePath, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,7 @@ func (s *scanner) scanText() Token {
|
||||||
|
|
||||||
capInput := strings.ToUpper(buf.String())
|
capInput := strings.ToUpper(buf.String())
|
||||||
switch capInput {
|
switch capInput {
|
||||||
case "D", "DELETE", "A", "ADD","W", "WRITE",
|
case "D", "DELETE", "A", "ADD", "W", "WRITE",
|
||||||
"S", "SET", "R", "RELOAD", "SEARCH",
|
"S", "SET", "R", "RELOAD", "SEARCH",
|
||||||
"Q", "QUIT", "B", "BOOKMARKS", "H",
|
"Q", "QUIT", "B", "BOOKMARKS", "H",
|
||||||
"HOME", "?", "HELP", "C", "CHECK",
|
"HOME", "?", "HELP", "C", "CHECK",
|
||||||
|
|
|
@ -21,11 +21,11 @@ type Parser struct {
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
// Bookmarks gopher.Bookmarks
|
// Bookmarks gopher.Bookmarks
|
||||||
Bookmarks struct {
|
Bookmarks struct {
|
||||||
Titles, Links []string
|
Titles, Links []string
|
||||||
}
|
}
|
||||||
Settings []KeyValue
|
Settings []KeyValue
|
||||||
Certs []KeyValue
|
Certs []KeyValue
|
||||||
}
|
}
|
||||||
|
|
||||||
type KeyValue struct {
|
type KeyValue struct {
|
||||||
|
|
|
@ -1,5 +1 @@
|
||||||
package cui
|
package cui
|
||||||
|
|
||||||
import (
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
29
defaults.go
29
defaults.go
|
@ -12,21 +12,20 @@ var defaultOptions = map[string]string{
|
||||||
// Edit these values before compile to have different default values
|
// Edit these values before compile to have different default values
|
||||||
// ... though they can always be edited from within bombadillo as well
|
// ... though they can always be edited from within bombadillo as well
|
||||||
// it just may take more time/work.
|
// it just may take more time/work.
|
||||||
//
|
//
|
||||||
// To change the default location for the config you can enter
|
// To change the default location for the config you can enter
|
||||||
// any valid path as a string, if you want an absolute, or
|
// any valid path as a string, if you want an absolute, or
|
||||||
// concatenate with the main default: `userinfo.HomeDir` like so:
|
// concatenate with the main default: `userinfo.HomeDir` like so:
|
||||||
// "configlocation": userinfo.HomeDir + "/config/"
|
// "configlocation": userinfo.HomeDir + "/config/"
|
||||||
"homeurl": "gopher://bombadillo.colorfield.space:70/1/user-guide.map",
|
"homeurl": "gopher://bombadillo.colorfield.space:70/1/user-guide.map",
|
||||||
"savelocation": userinfo.HomeDir,
|
"savelocation": userinfo.HomeDir,
|
||||||
"searchengine": "gopher://gopher.floodgap.com:70/7/v2/vs",
|
"searchengine": "gopher://gopher.floodgap.com:70/7/v2/vs",
|
||||||
"openhttp": "false",
|
"openhttp": "false",
|
||||||
"telnetcommand": "telnet",
|
"telnetcommand": "telnet",
|
||||||
"configlocation": userinfo.HomeDir,
|
"configlocation": userinfo.HomeDir,
|
||||||
"theme": "normal", // "normal", "inverted"
|
"theme": "normal", // "normal", "inverted"
|
||||||
"terminalonly": "true",
|
"terminalonly": "true",
|
||||||
"tlscertificate": "",
|
"tlscertificate": "",
|
||||||
"tlskey": "",
|
"tlskey": "",
|
||||||
"lynxmode": "false",
|
"lynxmode": "false",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,8 @@ package finger
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
10
footbar.go
10
footbar.go
|
@ -5,17 +5,15 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
// + + + T Y P E S + + + \\
|
// + + + T Y P E S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
|
||||||
type Footbar struct {
|
type Footbar struct {
|
||||||
PercentRead string
|
PercentRead string
|
||||||
PageType string
|
PageType string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
// + + + R E C E I V E R S + + + \\
|
// + + + R E C E I V E R S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
@ -34,15 +32,14 @@ func (f *Footbar) SetPageType(t string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Footbar) Render(termWidth, position int, theme string) string {
|
func (f *Footbar) Render(termWidth, position int, theme string) string {
|
||||||
pre := fmt.Sprintf("HST: (%2.2d) - - - %4s Read ", position + 1, f.PercentRead)
|
pre := fmt.Sprintf("HST: (%2.2d) - - - %4s Read ", position+1, f.PercentRead)
|
||||||
out := "\033[0m%*.*s "
|
out := "\033[0m%*.*s "
|
||||||
if theme == "inverse" {
|
if theme == "inverse" {
|
||||||
out = "\033[7m%*.*s \033[0m"
|
out = "\033[7m%*.*s \033[0m"
|
||||||
}
|
}
|
||||||
return fmt.Sprintf(out, termWidth - 1, termWidth - 1, pre)
|
return fmt.Sprintf(out, termWidth-1, termWidth-1, pre)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
// + + + F U N C T I O N S + + + \\
|
// + + + F U N C T I O N S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
@ -50,4 +47,3 @@ func (f *Footbar) Render(termWidth, position int, theme string) string {
|
||||||
func MakeFootbar() Footbar {
|
func MakeFootbar() Footbar {
|
||||||
return Footbar{"---", "N/A"}
|
return Footbar{"---", "N/A"}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,22 +11,19 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
type Capsule struct {
|
type Capsule struct {
|
||||||
MimeMaj string
|
MimeMaj string
|
||||||
MimeMin string
|
MimeMin string
|
||||||
Status int
|
Status int
|
||||||
Content string
|
Content string
|
||||||
Links []string
|
Links []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type TofuDigest struct {
|
type TofuDigest struct {
|
||||||
certs map[string]string
|
certs map[string]string
|
||||||
ClientCert tls.Certificate
|
ClientCert tls.Certificate
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
// + + + R E C E I V E R S + + + \\
|
// + + + R E C E I V E R S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
@ -107,17 +104,17 @@ func (t *TofuDigest) newCert(host string, cState *tls.ConnectionState) error {
|
||||||
reasons.WriteString("; ")
|
reasons.WriteString("; ")
|
||||||
}
|
}
|
||||||
if now.Before(cert.NotBefore) {
|
if now.Before(cert.NotBefore) {
|
||||||
reasons.WriteString(fmt.Sprintf("Cert [%d] is not valid yet", index + 1))
|
reasons.WriteString(fmt.Sprintf("Cert [%d] is not valid yet", index+1))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if now.After(cert.NotAfter) {
|
if now.After(cert.NotAfter) {
|
||||||
reasons.WriteString(fmt.Sprintf("Cert [%d] is expired", index + 1))
|
reasons.WriteString(fmt.Sprintf("Cert [%d] is expired", index+1))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := cert.VerifyHostname(host); err != nil {
|
if err := cert.VerifyHostname(host); err != nil {
|
||||||
reasons.WriteString(fmt.Sprintf("Cert [%d] hostname does not match", index + 1))
|
reasons.WriteString(fmt.Sprintf("Cert [%d] hostname does not match", index+1))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,8 +140,6 @@ func (t *TofuDigest) IniDump() string {
|
||||||
return out.String()
|
return out.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
// + + + F U N C T I O N S + + + \\
|
// + + + F U N C T I O N S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
@ -157,7 +152,7 @@ func Retrieve(host, port, resource string, td *TofuDigest) (string, error) {
|
||||||
addr := host + ":" + port
|
addr := host + ":" + port
|
||||||
|
|
||||||
conf := &tls.Config{
|
conf := &tls.Config{
|
||||||
MinVersion: tls.VersionTLS12,
|
MinVersion: tls.VersionTLS12,
|
||||||
InsecureSkipVerify: true,
|
InsecureSkipVerify: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,7 +230,7 @@ func Fetch(host, port, resource string, td *TofuDigest) ([]byte, error) {
|
||||||
if len([]rune(header[0])) != 2 {
|
if len([]rune(header[0])) != 2 {
|
||||||
header = strings.SplitN(resp[0], "\t", 2)
|
header = strings.SplitN(resp[0], "\t", 2)
|
||||||
if len([]rune(header[0])) != 2 {
|
if len([]rune(header[0])) != 2 {
|
||||||
return make([]byte,0), fmt.Errorf("Invalid response format from server")
|
return make([]byte, 0), fmt.Errorf("Invalid response format from server")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -351,7 +346,7 @@ func parseGemini(b, rootUrl, currentUrl string) (string, []string) {
|
||||||
subLn := strings.Trim(ln[2:], "\r\n\t \a")
|
subLn := strings.Trim(ln[2:], "\r\n\t \a")
|
||||||
splitPoint := strings.IndexAny(subLn, " \t")
|
splitPoint := strings.IndexAny(subLn, " \t")
|
||||||
|
|
||||||
if splitPoint < 0 || len([]rune(subLn)) - 1 <= splitPoint {
|
if splitPoint < 0 || len([]rune(subLn))-1 <= splitPoint {
|
||||||
link = subLn
|
link = subLn
|
||||||
decorator = subLn
|
decorator = subLn
|
||||||
} else {
|
} else {
|
||||||
|
@ -359,7 +354,7 @@ func parseGemini(b, rootUrl, currentUrl string) (string, []string) {
|
||||||
decorator = strings.Trim(subLn[splitPoint:], "\t\n\r \a")
|
decorator = strings.Trim(subLn[splitPoint:], "\t\n\r \a")
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.Index(link, "://") < 0 {
|
if strings.Index(link, "://") < 0 {
|
||||||
link = handleRelativeUrl(link, rootUrl, currentUrl)
|
link = handleRelativeUrl(link, rootUrl, currentUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -385,7 +380,7 @@ func handleRelativeUrl(u, root, current string) string {
|
||||||
return fmt.Sprintf("%s/%s", root, u)
|
return fmt.Sprintf("%s/%s", root, u)
|
||||||
}
|
}
|
||||||
|
|
||||||
current = current[:ind + 1]
|
current = current[:ind+1]
|
||||||
return fmt.Sprintf("%s%s", current, u)
|
return fmt.Sprintf("%s%s", current, u)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -398,7 +393,6 @@ func hashCert(cert []byte) string {
|
||||||
return fmt.Sprintf("%s", string(bytes.Join(hex, []byte(":"))))
|
return fmt.Sprintf("%s", string(bytes.Join(hex, []byte(":"))))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func MakeCapsule() Capsule {
|
func MakeCapsule() Capsule {
|
||||||
return Capsule{"", "", 0, "", make([]string, 0, 5)}
|
return Capsule{"", "", 0, "", make([]string, 0, 5)}
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,7 +92,6 @@ func Visit(gophertype, host, port, resource string) (string, []string, error) {
|
||||||
return text, []string{}, nil
|
return text, []string{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if gophertype == "1" {
|
if gophertype == "1" {
|
||||||
text, links = parseMap(text)
|
text, links = parseMap(text)
|
||||||
}
|
}
|
||||||
|
@ -116,7 +115,7 @@ func isWebLink(resource string) (string, bool) {
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseMap(text string) (string, []string) {
|
func parseMap(text string) (string, []string) {
|
||||||
splitContent := strings.Split(text, "\n")
|
splitContent := strings.Split(text, "\n")
|
||||||
links := make([]string, 0, 10)
|
links := make([]string, 0, 10)
|
||||||
|
|
||||||
|
|
|
@ -10,10 +10,9 @@ import (
|
||||||
|
|
||||||
type Headbar struct {
|
type Headbar struct {
|
||||||
title string
|
title string
|
||||||
url string
|
url string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
// + + + R E C E I V E R S + + + \\
|
// + + + R E C E I V E R S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
@ -27,7 +26,6 @@ func (h *Headbar) Render(width int, theme string) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
// + + + F U N C T I O N S + + + \\
|
// + + + F U N C T I O N S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
@ -35,4 +33,3 @@ func (h *Headbar) Render(width int, theme string) string {
|
||||||
func MakeHeadbar(title string) Headbar {
|
func MakeHeadbar(title string) Headbar {
|
||||||
return Headbar{title, ""}
|
return Headbar{title, ""}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,4 +89,3 @@ func Fetch(url string) ([]byte, error) {
|
||||||
|
|
||||||
return bodyBytes, nil
|
return bodyBytes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,6 @@ func Open(address string) (string, error) {
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
|
|
||||||
if pathIsDir(address) {
|
if pathIsDir(address) {
|
||||||
fileList, err := file.Readdirnames(0)
|
fileList, err := file.Readdirnames(0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -40,21 +39,20 @@ func Open(address string) (string, error) {
|
||||||
return string(bytes), nil
|
return string(bytes), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func pathExists(p string) bool {
|
func pathExists(p string) bool {
|
||||||
exists := true
|
exists := true
|
||||||
|
|
||||||
if _, err := os.Stat(p); os.IsNotExist(err) {
|
if _, err := os.Stat(p); os.IsNotExist(err) {
|
||||||
exists = false
|
exists = false
|
||||||
}
|
}
|
||||||
|
|
||||||
return exists
|
return exists
|
||||||
}
|
}
|
||||||
|
|
||||||
func pathIsDir(p string) bool {
|
func pathIsDir(p string) bool {
|
||||||
info, err := os.Stat(p)
|
info, err := os.Stat(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return info.IsDir()
|
return info.IsDir()
|
||||||
}
|
}
|
||||||
|
|
11
page.go
11
page.go
|
@ -10,9 +10,9 @@ import (
|
||||||
|
|
||||||
type Page struct {
|
type Page struct {
|
||||||
WrappedContent []string
|
WrappedContent []string
|
||||||
RawContent string
|
RawContent string
|
||||||
Links []string
|
Links []string
|
||||||
Location Url
|
Location Url
|
||||||
ScrollPosition int
|
ScrollPosition int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ type Page struct {
|
||||||
|
|
||||||
func (p *Page) ScrollPositionRange(termHeight int) (int, int) {
|
func (p *Page) ScrollPositionRange(termHeight int) (int, int) {
|
||||||
termHeight -= 3
|
termHeight -= 3
|
||||||
if len(p.WrappedContent) - p.ScrollPosition < termHeight {
|
if len(p.WrappedContent)-p.ScrollPosition < termHeight {
|
||||||
p.ScrollPosition = len(p.WrappedContent) - termHeight
|
p.ScrollPosition = len(p.WrappedContent) - termHeight
|
||||||
}
|
}
|
||||||
if p.ScrollPosition < 0 {
|
if p.ScrollPosition < 0 {
|
||||||
|
@ -51,7 +51,7 @@ func (p *Page) WrapContent(width int) {
|
||||||
content.WriteRune(ch)
|
content.WriteRune(ch)
|
||||||
counter = 0
|
counter = 0
|
||||||
} else if ch == '\t' {
|
} else if ch == '\t' {
|
||||||
if counter + 4 < width {
|
if counter+4 < width {
|
||||||
content.WriteString(" ")
|
content.WriteString(" ")
|
||||||
counter += 4
|
counter += 4
|
||||||
} else {
|
} else {
|
||||||
|
@ -89,4 +89,3 @@ func MakePage(url Url, content string, links []string) Page {
|
||||||
p := Page{make([]string, 0), content, links, url, 0}
|
p := Page{make([]string, 0), content, links, url, 0}
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
17
pages.go
17
pages.go
|
@ -10,11 +10,10 @@ import (
|
||||||
|
|
||||||
type Pages struct {
|
type Pages struct {
|
||||||
Position int
|
Position int
|
||||||
Length int
|
Length int
|
||||||
History [20]Page
|
History [20]Page
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
// + + + R E C E I V E R S + + + \\
|
// + + + R E C E I V E R S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
@ -23,7 +22,7 @@ func (p *Pages) NavigateHistory(qty int) error {
|
||||||
newPosition := p.Position + qty
|
newPosition := p.Position + qty
|
||||||
if newPosition < 0 {
|
if newPosition < 0 {
|
||||||
return fmt.Errorf("You are already at the beginning of history")
|
return fmt.Errorf("You are already at the beginning of history")
|
||||||
} else if newPosition > p.Length - 1 {
|
} else if newPosition > p.Length-1 {
|
||||||
return fmt.Errorf("Your way is blocked by void, there is nothing forward")
|
return fmt.Errorf("Your way is blocked by void, there is nothing forward")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,11 +31,11 @@ func (p *Pages) NavigateHistory(qty int) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Pages) Add(pg Page) {
|
func (p *Pages) Add(pg Page) {
|
||||||
if p.Position == p.Length - 1 && p.Length < len(p.History) {
|
if p.Position == p.Length-1 && p.Length < len(p.History) {
|
||||||
p.History[p.Length] = pg
|
p.History[p.Length] = pg
|
||||||
p.Length++
|
p.Length++
|
||||||
p.Position++
|
p.Position++
|
||||||
} else if p.Position == p.Length - 1 && p.Length == 20 {
|
} else if p.Position == p.Length-1 && p.Length == 20 {
|
||||||
for x := 1; x < len(p.History); x++ {
|
for x := 1; x < len(p.History); x++ {
|
||||||
p.History[x-1] = p.History[x]
|
p.History[x-1] = p.History[x]
|
||||||
}
|
}
|
||||||
|
@ -62,12 +61,12 @@ func (p *Pages) Render(termHeight, termWidth int) []string {
|
||||||
} else if prev < now {
|
} else if prev < now {
|
||||||
diff := now - prev
|
diff := now - prev
|
||||||
pos = pos + diff
|
pos = pos + diff
|
||||||
if pos > now - termHeight {
|
if pos > now-termHeight {
|
||||||
pos = now - termHeight
|
pos = now - termHeight
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if pos < 0 || now < termHeight - 3 {
|
if pos < 0 || now < termHeight-3 {
|
||||||
pos = 0
|
pos = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,5 +82,3 @@ func (p *Pages) Render(termHeight, termWidth int) []string {
|
||||||
func MakePages() Pages {
|
func MakePages() Pages {
|
||||||
return Pages{-1, 0, [20]Page{}}
|
return Pages{-1, 0, [20]Page{}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
16
url.go
16
url.go
|
@ -13,12 +13,12 @@ import (
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
|
||||||
type Url struct {
|
type Url struct {
|
||||||
Scheme string
|
Scheme string
|
||||||
Host string
|
Host string
|
||||||
Port string
|
Port string
|
||||||
Resource string
|
Resource string
|
||||||
Full string
|
Full string
|
||||||
Mime string
|
Mime string
|
||||||
DownloadOnly bool
|
DownloadOnly bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,12 +28,10 @@ type Url struct {
|
||||||
|
|
||||||
// There are currently no receivers for the Url struct
|
// There are currently no receivers for the Url struct
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
// + + + F U N C T I O N S + + + \\
|
// + + + F U N C T I O N S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
|
||||||
|
|
||||||
// MakeUrl is a Url constructor that takes in a string
|
// MakeUrl is a Url constructor that takes in a string
|
||||||
// representation of a url and returns a Url struct and
|
// representation of a url and returns a Url struct and
|
||||||
// an error (or nil).
|
// an error (or nil).
|
||||||
|
@ -167,5 +165,3 @@ func parseFinger(u string) (Url, error) {
|
||||||
out.Full = fmt.Sprintf("%s://%s%s:%s", out.Scheme, resource, out.Host, out.Port)
|
out.Full = fmt.Sprintf("%s://%s%s:%s", out.Scheme, resource, out.Host, out.Port)
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue