forked from sloum/bombadillo
Merge branch 'run-format' of sloum/bombadillo into develop
This commit is contained in:
commit
c36ded496f
20
bookmarks.go
20
bookmarks.go
|
@ -11,6 +11,9 @@ import (
|
||||||
// + + + T Y P E S + + + \\
|
// + + + T Y P E S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
|
||||||
|
// Bookmarks represents the contents of the bookmarks
|
||||||
|
// bar, as well as its visibility, focus, and scroll
|
||||||
|
// state.
|
||||||
type Bookmarks struct {
|
type Bookmarks struct {
|
||||||
IsOpen bool
|
IsOpen bool
|
||||||
IsFocused bool
|
IsFocused bool
|
||||||
|
@ -24,6 +27,7 @@ type Bookmarks struct {
|
||||||
// + + + R E C E I V E R S + + + \\
|
// + + + R E C E I V E R S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
|
||||||
|
// Add a bookmark to the bookmarks struct
|
||||||
func (b *Bookmarks) Add(v []string) (string, error) {
|
func (b *Bookmarks) Add(v []string) (string, error) {
|
||||||
if len(v) < 2 {
|
if len(v) < 2 {
|
||||||
return "", fmt.Errorf("Received %d arguments, expected 2+", len(v))
|
return "", fmt.Errorf("Received %d arguments, expected 2+", len(v))
|
||||||
|
@ -34,6 +38,7 @@ func (b *Bookmarks) Add(v []string) (string, error) {
|
||||||
return "Bookmark added successfully", nil
|
return "Bookmark added successfully", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete a bookmark from the bookmarks struct
|
||||||
func (b *Bookmarks) Delete(i int) (string, error) {
|
func (b *Bookmarks) Delete(i int) (string, error) {
|
||||||
if i < len(b.Titles) && len(b.Titles) == len(b.Links) {
|
if i < len(b.Titles) && len(b.Titles) == len(b.Links) {
|
||||||
b.Titles = append(b.Titles[:i], b.Titles[i+1:]...)
|
b.Titles = append(b.Titles[:i], b.Titles[i+1:]...)
|
||||||
|
@ -44,6 +49,7 @@ func (b *Bookmarks) Delete(i int) (string, error) {
|
||||||
return "", fmt.Errorf("Bookmark %d does not exist", i)
|
return "", fmt.Errorf("Bookmark %d does not exist", i)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ToggleOpen toggles visibility state of the bookmarks bar
|
||||||
func (b *Bookmarks) ToggleOpen() {
|
func (b *Bookmarks) ToggleOpen() {
|
||||||
b.IsOpen = !b.IsOpen
|
b.IsOpen = !b.IsOpen
|
||||||
if b.IsOpen {
|
if b.IsOpen {
|
||||||
|
@ -53,12 +59,15 @@ func (b *Bookmarks) ToggleOpen() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ToggleFocused toggles the focal state of the bookmarks bar
|
||||||
func (b *Bookmarks) ToggleFocused() {
|
func (b *Bookmarks) ToggleFocused() {
|
||||||
if b.IsOpen {
|
if b.IsOpen {
|
||||||
b.IsFocused = !b.IsFocused
|
b.IsFocused = !b.IsFocused
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IniDump returns a string representing the current bookmarks
|
||||||
|
// in the format that .bombadillo.ini uses
|
||||||
func (b Bookmarks) IniDump() string {
|
func (b Bookmarks) IniDump() string {
|
||||||
if len(b.Titles) < 1 {
|
if len(b.Titles) < 1 {
|
||||||
return ""
|
return ""
|
||||||
|
@ -73,7 +82,7 @@ func (b Bookmarks) IniDump() string {
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get a list, including link nums, of bookmarks
|
// List returns a list, including link nums, of bookmarks
|
||||||
// as a string slice
|
// as a string slice
|
||||||
func (b Bookmarks) List() []string {
|
func (b Bookmarks) List() []string {
|
||||||
var out []string
|
var out []string
|
||||||
|
@ -83,6 +92,8 @@ func (b Bookmarks) List() []string {
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Render returns a string slice with the contents of each
|
||||||
|
// visual row of the bookmark bar.
|
||||||
func (b Bookmarks) Render(termwidth, termheight int) []string {
|
func (b Bookmarks) Render(termwidth, termheight int) []string {
|
||||||
width := 40
|
width := 40
|
||||||
termheight -= 3
|
termheight -= 3
|
||||||
|
@ -128,16 +139,11 @@ func (b Bookmarks) Render(termwidth, termheight int) []string {
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO handle scrolling of the bookmarks list
|
|
||||||
// either here with a scroll up/down or in the client
|
|
||||||
// code for scroll
|
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
// + + + F U N C T I O N S + + + \\
|
// + + + F U N C T I O N S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
|
||||||
|
// MakeBookmarks creates a Bookmark struct with default values
|
||||||
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)}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
24
client.go
24
client.go
|
@ -51,7 +51,7 @@ func (c *client) GetSizeOnce() {
|
||||||
os.Exit(5)
|
os.Exit(5)
|
||||||
}
|
}
|
||||||
var h, w int
|
var h, w int
|
||||||
fmt.Sscan(string(out), &h, &w)
|
_, _ = fmt.Sscan(string(out), &h, &w)
|
||||||
c.Height = h
|
c.Height = h
|
||||||
c.Width = w
|
c.Width = w
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ func (c *client) GetSize() {
|
||||||
os.Exit(5)
|
os.Exit(5)
|
||||||
}
|
}
|
||||||
var h, w int
|
var h, w int
|
||||||
fmt.Sscan(string(out), &h, &w)
|
_, _ = fmt.Sscan(string(out), &h, &w)
|
||||||
if h != c.Height || w != c.Width {
|
if h != c.Height || w != c.Width {
|
||||||
c.Height = h
|
c.Height = h
|
||||||
c.Width = w
|
c.Width = w
|
||||||
|
@ -268,7 +268,7 @@ func (c *client) routeCommandInput(com *cmdparse.Command) error {
|
||||||
case cmdparse.DOLINKAS:
|
case cmdparse.DOLINKAS:
|
||||||
c.doLinkCommandAs(com.Action, com.Target, com.Value)
|
c.doLinkCommandAs(com.Action, com.Target, com.Value)
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("Unknown command entry!")
|
return fmt.Errorf("Unknown command entry")
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
@ -385,10 +385,9 @@ func (c *client) doCommandAs(action string, values []string) {
|
||||||
c.SetMessage(err.Error(), true)
|
c.SetMessage(err.Error(), true)
|
||||||
c.DrawMessage()
|
c.DrawMessage()
|
||||||
return
|
return
|
||||||
} else {
|
}
|
||||||
c.SetMessage(msg, false)
|
c.SetMessage(msg, false)
|
||||||
c.DrawMessage()
|
c.DrawMessage()
|
||||||
}
|
|
||||||
|
|
||||||
err = saveConfig()
|
err = saveConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -437,7 +436,7 @@ func (c *client) doLinkCommandAs(action, target string, values []string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
num -= 1
|
num--
|
||||||
|
|
||||||
links := c.PageState.History[c.PageState.Position].Links
|
links := c.PageState.History[c.PageState.Position].Links
|
||||||
if num >= len(links) || num < 0 {
|
if num >= len(links) || num < 0 {
|
||||||
|
@ -456,10 +455,9 @@ func (c *client) doLinkCommandAs(action, target string, values []string) {
|
||||||
c.SetMessage(err.Error(), true)
|
c.SetMessage(err.Error(), true)
|
||||||
c.DrawMessage()
|
c.DrawMessage()
|
||||||
return
|
return
|
||||||
} else {
|
}
|
||||||
c.SetMessage(msg, false)
|
c.SetMessage(msg, false)
|
||||||
c.DrawMessage()
|
c.DrawMessage()
|
||||||
}
|
|
||||||
|
|
||||||
err = saveConfig()
|
err = saveConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -564,10 +562,9 @@ func (c *client) doLinkCommand(action, target string) {
|
||||||
c.SetMessage(err.Error(), true)
|
c.SetMessage(err.Error(), true)
|
||||||
c.DrawMessage()
|
c.DrawMessage()
|
||||||
return
|
return
|
||||||
} else {
|
}
|
||||||
c.SetMessage(msg, false)
|
c.SetMessage(msg, false)
|
||||||
c.DrawMessage()
|
c.DrawMessage()
|
||||||
}
|
|
||||||
|
|
||||||
err = saveConfig()
|
err = saveConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -585,7 +582,7 @@ func (c *client) doLinkCommand(action, target string) {
|
||||||
}
|
}
|
||||||
c.Visit(c.BookMarks.Links[num])
|
c.Visit(c.BookMarks.Links[num])
|
||||||
case "CHECK", "C":
|
case "CHECK", "C":
|
||||||
num -= 1
|
num--
|
||||||
|
|
||||||
links := c.PageState.History[c.PageState.Position].Links
|
links := c.PageState.History[c.PageState.Position].Links
|
||||||
if num >= len(links) || num < 0 {
|
if num >= len(links) || num < 0 {
|
||||||
|
@ -877,7 +874,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) {
|
||||||
|
@ -1049,11 +1045,12 @@ func (c *client) handleWeb(u Url) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
// + + + F U N C T I O N S + + + \\
|
// + + + F U N C T I O N S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
|
||||||
|
// MakeClient returns a client struct and names the client after
|
||||||
|
// the string that is passed in
|
||||||
func MakeClient(name string) *client {
|
func MakeClient(name string) *client {
|
||||||
c := client{0, 0, defaultOptions, "", false, MakePages(), MakeBookmarks(), MakeHeadbar(name), MakeFootbar(), gemini.MakeTofuDigest()}
|
c := client{0, 0, defaultOptions, "", false, MakePages(), MakeBookmarks(), MakeHeadbar(name), MakeFootbar(), gemini.MakeTofuDigest()}
|
||||||
return &c
|
return &c
|
||||||
|
@ -1075,4 +1072,3 @@ func findAvailableFileName(fpath, fname string) (string, error) {
|
||||||
|
|
||||||
return savePath, nil
|
return savePath, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
13
cui/cui.go
13
cui/cui.go
|
@ -26,19 +26,6 @@ var Shapes = map[string]string{
|
||||||
"abr": "▟",
|
"abr": "▟",
|
||||||
}
|
}
|
||||||
|
|
||||||
func drawShape(shape string) {
|
|
||||||
if val, ok := Shapes[shape]; ok {
|
|
||||||
fmt.Printf("%s", val)
|
|
||||||
} else {
|
|
||||||
fmt.Print("x")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func moveThenDrawShape(r, c int, s string) {
|
|
||||||
MoveCursorTo(r, c)
|
|
||||||
drawShape(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
func MoveCursorTo(row, col int) {
|
func MoveCursorTo(row, col int) {
|
||||||
fmt.Printf("\033[%d;%dH", row, col)
|
fmt.Printf("\033[%d;%dH", row, col)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
package cui
|
|
||||||
|
|
||||||
import (
|
|
||||||
)
|
|
||||||
|
|
|
@ -29,4 +29,3 @@ var defaultOptions = map[string]string{
|
||||||
"tlskey": "",
|
"tlskey": "",
|
||||||
"lynxmode": "false",
|
"lynxmode": "false",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,8 @@ package finger
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
13
footbar.go
13
footbar.go
|
@ -5,21 +5,23 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
// + + + T Y P E S + + + \\
|
// + + + T Y P E S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
|
||||||
|
// Footbar deals with the values present in the
|
||||||
|
// client's footbar
|
||||||
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 + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
|
||||||
|
// SetPercentRead sets the percentage of the current
|
||||||
|
// document the user has read
|
||||||
func (f *Footbar) SetPercentRead(p int) {
|
func (f *Footbar) SetPercentRead(p int) {
|
||||||
if p > 100 {
|
if p > 100 {
|
||||||
p = 100
|
p = 100
|
||||||
|
@ -29,10 +31,14 @@ func (f *Footbar) SetPercentRead(p int) {
|
||||||
f.PercentRead = strconv.Itoa(p) + "%"
|
f.PercentRead = strconv.Itoa(p) + "%"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetPageType sets the current page's type
|
||||||
|
// NOTE: This is not currently in use
|
||||||
func (f *Footbar) SetPageType(t string) {
|
func (f *Footbar) SetPageType(t string) {
|
||||||
f.PageType = t
|
f.PageType = t
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Render returns a string representing the visual display
|
||||||
|
// of the bookmarks bar
|
||||||
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 "
|
||||||
|
@ -42,12 +48,11 @@ func (f *Footbar) Render(termWidth, position int, theme string) string {
|
||||||
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 + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
|
||||||
|
// MakeFootbar returns a footbar with default values
|
||||||
func MakeFootbar() Footbar {
|
func MakeFootbar() Footbar {
|
||||||
return Footbar{"---", "N/A"}
|
return Footbar{"---", "N/A"}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
type Capsule struct {
|
type Capsule struct {
|
||||||
MimeMaj string
|
MimeMaj string
|
||||||
MimeMin string
|
MimeMin string
|
||||||
|
@ -20,13 +19,11 @@ type Capsule struct {
|
||||||
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 + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
@ -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 + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
11
headbar.go
11
headbar.go
|
@ -8,31 +8,32 @@ import (
|
||||||
// + + + T Y P E S + + + \\
|
// + + + T Y P E S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
|
||||||
|
// Headbar represents the contents of the top bar of
|
||||||
|
// the client and contains the client name and the
|
||||||
|
// current URL
|
||||||
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 + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
|
||||||
|
// Render returns a string with the contents of theHeadbar
|
||||||
func (h *Headbar) Render(width int, theme string) string {
|
func (h *Headbar) Render(width int, theme string) string {
|
||||||
maxMsgWidth := width - len([]rune(h.title)) - 2
|
maxMsgWidth := width - len([]rune(h.title)) - 2
|
||||||
if theme == "inverse" {
|
if theme == "inverse" {
|
||||||
return fmt.Sprintf("\033[7m%s▟\033[27m %-*.*s\033[0m", h.title, maxMsgWidth, maxMsgWidth, h.url)
|
return fmt.Sprintf("\033[7m%s▟\033[27m %-*.*s\033[0m", h.title, maxMsgWidth, maxMsgWidth, h.url)
|
||||||
} else {
|
}
|
||||||
return fmt.Sprintf("%s▟\033[7m %-*.*s\033[0m", h.title, maxMsgWidth, maxMsgWidth, h.url)
|
return fmt.Sprintf("%s▟\033[7m %-*.*s\033[0m", h.title, maxMsgWidth, maxMsgWidth, h.url)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
// + + + F U N C T I O N S + + + \\
|
// + + + F U N C T I O N S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
|
||||||
|
// MakeHeadbar returns a Headbar with default values
|
||||||
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,7 +39,6 @@ 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
|
||||||
|
|
||||||
|
|
11
main.go
11
main.go
|
@ -82,9 +82,8 @@ func validateOpt(opt, val string) bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
} else {
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func lowerCaseOpt(opt, val string) string {
|
func lowerCaseOpt(opt, val string) string {
|
||||||
|
@ -107,7 +106,7 @@ func loadConfig() error {
|
||||||
|
|
||||||
confparser := config.NewParser(file)
|
confparser := config.NewParser(file)
|
||||||
settings, _ = confparser.Parse()
|
settings, _ = confparser.Parse()
|
||||||
file.Close()
|
_ = file.Close()
|
||||||
for _, v := range settings.Settings {
|
for _, v := range settings.Settings {
|
||||||
lowerkey := strings.ToLower(v.Key)
|
lowerkey := strings.ToLower(v.Key)
|
||||||
if lowerkey == "configlocation" {
|
if lowerkey == "configlocation" {
|
||||||
|
@ -129,7 +128,7 @@ func loadConfig() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, v := range settings.Bookmarks.Titles {
|
for i, v := range settings.Bookmarks.Titles {
|
||||||
bombadillo.BookMarks.Add([]string{v, settings.Bookmarks.Links[i]})
|
_, _ = bombadillo.BookMarks.Add([]string{v, settings.Bookmarks.Links[i]})
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, v := range settings.Certs {
|
for _, v := range settings.Certs {
|
||||||
|
@ -157,7 +156,7 @@ func handleSignals(c <-chan os.Signal) {
|
||||||
switch <-c {
|
switch <-c {
|
||||||
case syscall.SIGTSTP:
|
case syscall.SIGTSTP:
|
||||||
cui.CleanupTerm()
|
cui.CleanupTerm()
|
||||||
syscall.Kill(syscall.Getpid(), syscall.SIGSTOP)
|
_ = syscall.Kill(syscall.Getpid(), syscall.SIGSTOP)
|
||||||
case syscall.SIGCONT:
|
case syscall.SIGCONT:
|
||||||
cui.InitTerm()
|
cui.InitTerm()
|
||||||
bombadillo.Draw()
|
bombadillo.Draw()
|
||||||
|
@ -179,7 +178,7 @@ Examples: bombadillo gopher://bombadillo.colorfield.space
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
`
|
`
|
||||||
fmt.Fprint(os.Stdout, art)
|
_, _ = fmt.Fprint(os.Stdout, art)
|
||||||
flag.PrintDefaults()
|
flag.PrintDefaults()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
9
page.go
9
page.go
|
@ -8,6 +8,9 @@ import (
|
||||||
// + + + T Y P E S + + + \\
|
// + + + T Y P E S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
|
||||||
|
// Page represents a visited URL's contents; including
|
||||||
|
// the raw content, wrapped content, link slice, URL,
|
||||||
|
// and the current scroll position
|
||||||
type Page struct {
|
type Page struct {
|
||||||
WrappedContent []string
|
WrappedContent []string
|
||||||
RawContent string
|
RawContent string
|
||||||
|
@ -20,6 +23,8 @@ type Page struct {
|
||||||
// + + + R E C E I V E R S + + + \\
|
// + + + R E C E I V E R S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
|
||||||
|
// ScrollPositionRange may not be in actual usage....
|
||||||
|
// TODO: find where this is being used
|
||||||
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 {
|
||||||
|
@ -38,7 +43,7 @@ func (p *Page) ScrollPositionRange(termHeight int) (int, int) {
|
||||||
return p.ScrollPosition, end
|
return p.ScrollPosition, end
|
||||||
}
|
}
|
||||||
|
|
||||||
// Performs a hard wrap to the requested
|
// WrapContent performs a hard wrap to the requested
|
||||||
// width and updates the WrappedContent
|
// width and updates the WrappedContent
|
||||||
// of the Page struct width a string slice
|
// of the Page struct width a string slice
|
||||||
// of the wrapped data
|
// of the wrapped data
|
||||||
|
@ -85,8 +90,8 @@ func (p *Page) WrapContent(width int) {
|
||||||
// + + + F U N C T I O N S + + + \\
|
// + + + F U N C T I O N S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
|
||||||
|
// MakePage returns a Page struct with default values
|
||||||
func MakePage(url Url, content string, links []string) Page {
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
19
pages.go
19
pages.go
|
@ -8,17 +8,23 @@ import (
|
||||||
// + + + T Y P E S + + + \\
|
// + + + T Y P E S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
|
||||||
|
// Pages is a struct that represents the history of the client.
|
||||||
|
// It functions as a container for the pages (history array) and
|
||||||
|
// tracks the current history length and location.
|
||||||
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 + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
|
||||||
|
// NavigateHistory takes a positive or negative integer
|
||||||
|
// and updates the current history position. Checks are done
|
||||||
|
// to make sure that the position moved to is a valid history
|
||||||
|
// location. Returns an error or nil.
|
||||||
func (p *Pages) NavigateHistory(qty int) error {
|
func (p *Pages) NavigateHistory(qty int) error {
|
||||||
newPosition := p.Position + qty
|
newPosition := p.Position + qty
|
||||||
if newPosition < 0 {
|
if newPosition < 0 {
|
||||||
|
@ -31,6 +37,10 @@ func (p *Pages) NavigateHistory(qty int) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add gets passed a Page, which gets added to the history
|
||||||
|
// arrayr. Add also updates the current length and position
|
||||||
|
// of the Pages struct to which it belongs. Add also shifts
|
||||||
|
// off array items if necessary.
|
||||||
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
|
||||||
|
@ -42,12 +52,14 @@ func (p *Pages) Add(pg Page) {
|
||||||
}
|
}
|
||||||
p.History[len(p.History)-1] = pg
|
p.History[len(p.History)-1] = pg
|
||||||
} else {
|
} else {
|
||||||
p.Position += 1
|
p.Position++
|
||||||
p.Length = p.Position + 1
|
p.Length = p.Position + 1
|
||||||
p.History[p.Position] = pg
|
p.History[p.Position] = pg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Render wraps the content for the current page and returns
|
||||||
|
// the page content as a string slice
|
||||||
func (p *Pages) Render(termHeight, termWidth int) []string {
|
func (p *Pages) Render(termHeight, termWidth int) []string {
|
||||||
if p.Length < 1 {
|
if p.Length < 1 {
|
||||||
return make([]string, 0)
|
return make([]string, 0)
|
||||||
|
@ -80,8 +92,7 @@ func (p *Pages) Render(termHeight, termWidth int) []string {
|
||||||
// + + + F U N C T I O N S + + + \\
|
// + + + F U N C T I O N S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
|
||||||
|
// MakePages returns a Pages struct with default values
|
||||||
func MakePages() Pages {
|
func MakePages() Pages {
|
||||||
return Pages{-1, 0, [20]Page{}}
|
return Pages{-1, 0, [20]Page{}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
9
url.go
9
url.go
|
@ -12,6 +12,11 @@ import (
|
||||||
// + + + T Y P E S + + + \\
|
// + + + T Y P E S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
|
||||||
|
// Url is a struct representing the different pieces
|
||||||
|
// of a url. This custom struct is used rather than the
|
||||||
|
// built-in url library so-as to support gopher URLs, as
|
||||||
|
// well as track mime-type and renderability (can the
|
||||||
|
// response to the url be rendered as text in the client).
|
||||||
type Url struct {
|
type Url struct {
|
||||||
Scheme string
|
Scheme string
|
||||||
Host string
|
Host string
|
||||||
|
@ -28,12 +33,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 +170,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