forked from sloum/bombadillo
Gofmt all code, switch to canonical function naming, add a go.mod file for use with the latest go version
This commit is contained in:
parent
3a173d89e0
commit
701753b890
|
@ -0,0 +1 @@
|
||||||
|
bombadillo
|
|
@ -2,13 +2,11 @@ package cmdparse
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"strings"
|
|
||||||
"io"
|
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"io"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
// + + + T Y P E S + + + \\
|
// + + + T Y P E S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
@ -24,12 +22,12 @@ type scanner struct {
|
||||||
|
|
||||||
type tok int
|
type tok int
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
// + + + V A R I A B L E S + + + \\
|
// + + + V A R I A B L E S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
|
||||||
var eof rune = rune(0)
|
var eof rune = rune(0)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Word tok = iota
|
Word tok = iota
|
||||||
Action
|
Action
|
||||||
|
@ -43,7 +41,6 @@ const (
|
||||||
illegal
|
illegal
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
// + + + R E C E I V E R S + + + \\
|
// + + + R E C E I V E R S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
@ -143,7 +140,6 @@ func (s *scanner) scan() Token {
|
||||||
return Token{illegal, string(char)}
|
return Token{illegal, string(char)}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
// + + + F U N C T I O N S + + + \\
|
// + + + F U N C T I O N S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
@ -167,4 +163,3 @@ func isDigit(ch rune) bool {
|
||||||
func isEOF(ch rune) bool {
|
func isEOF(ch rune) bool {
|
||||||
return ch == rune(0)
|
return ch == rune(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
package cmdparse
|
package cmdparse
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
// + + + T Y P E S + + + \\
|
// + + + T Y P E S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
@ -26,6 +25,7 @@ type Command struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Comtype int
|
type Comtype int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
GOURL Comtype = iota
|
GOURL Comtype = iota
|
||||||
GOLINK
|
GOLINK
|
||||||
|
@ -35,7 +35,6 @@ const (
|
||||||
DOAS
|
DOAS
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
// + + + R E C E I V E R S + + + \\
|
// + + + R E C E I V E R S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
@ -132,7 +131,6 @@ func (p *Parser) Parse() (*Command, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
// + + + F U N C T I O N S + + + \\
|
// + + + F U N C T I O N S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
|
|
@ -2,13 +2,11 @@ package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"io"
|
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
// + + + T Y P E S + + + \\
|
// + + + T Y P E S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
@ -24,7 +22,6 @@ type scanner struct {
|
||||||
|
|
||||||
type TokenType int
|
type TokenType int
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
// + + + V A R I A B L E S + + + \\
|
// + + + V A R I A B L E S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
@ -35,7 +32,6 @@ var r_brace rune = ']'
|
||||||
var newline rune = '\n'
|
var newline rune = '\n'
|
||||||
var equal rune = '='
|
var equal rune = '='
|
||||||
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TOK_SECTION TokenType = iota
|
TOK_SECTION TokenType = iota
|
||||||
TOK_KEY
|
TOK_KEY
|
||||||
|
@ -47,7 +43,6 @@ const (
|
||||||
TOK_WHITESPACE
|
TOK_WHITESPACE
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
// + + + R E C E I V E R S + + + \\
|
// + + + R E C E I V E R S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
@ -184,7 +179,6 @@ func (s *scanner) scan() Token {
|
||||||
return Token{TOK_ERROR, fmt.Sprintf("Error on character %q", char)}
|
return Token{TOK_ERROR, fmt.Sprintf("Error on character %q", char)}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
// + + + F U N C T I O N S + + + \\
|
// + + + F U N C T I O N S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
"bombadillo/gopher"
|
"tildegit.org/sloum/bombadillo/gopher"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
// + + + T Y P E S + + + \\
|
// + + + T Y P E S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
@ -32,7 +31,6 @@ type KeyValue struct {
|
||||||
Value string
|
Value string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
// + + + R E C E I V E R S + + + \\
|
// + + + R E C E I V E R S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
@ -68,7 +66,6 @@ func (p *Parser) parseKeyValue() (KeyValue, error) {
|
||||||
|
|
||||||
func (p *Parser) unscan() { p.buffer.size = 1 }
|
func (p *Parser) unscan() { p.buffer.size = 1 }
|
||||||
|
|
||||||
|
|
||||||
func (p *Parser) Parse() (Config, error) {
|
func (p *Parser) Parse() (Config, error) {
|
||||||
p.row = 1
|
p.row = 1
|
||||||
section := ""
|
section := ""
|
||||||
|
@ -103,7 +100,6 @@ func (p *Parser) Parse() (Config, error) {
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
// + + + F U N C T I O N S + + + \\
|
// + + + F U N C T I O N S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package cui
|
package cui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"bufio"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var shapes = map[string]string{
|
var shapes = map[string]string{
|
||||||
|
@ -24,7 +24,6 @@ var shapes = map[string]string{
|
||||||
"abr": "╝",
|
"abr": "╝",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func drawShape(shape string) {
|
func drawShape(shape string) {
|
||||||
if val, ok := shapes[shape]; ok {
|
if val, ok := shapes[shape]; ok {
|
||||||
fmt.Printf("%s", val)
|
fmt.Printf("%s", val)
|
||||||
|
|
|
@ -9,7 +9,6 @@ type MsgBar struct {
|
||||||
showTitle bool
|
showTitle bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// SetTitle sets the title for the MsgBar in question
|
// SetTitle sets the title for the MsgBar in question
|
||||||
func (m *MsgBar) SetTitle(s string) {
|
func (m *MsgBar) SetTitle(s string) {
|
||||||
m.title = s
|
m.title = s
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package cui
|
package cui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"bytes"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// screenInit records whether or not the screen has been initialized
|
// screenInit records whether or not the screen has been initialized
|
||||||
|
@ -24,7 +24,6 @@ type Screen struct {
|
||||||
Bars []*MsgBar
|
Bars []*MsgBar
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// AddWindow adds a new window to the Screen struct in question
|
// AddWindow adds a new window to the Screen struct in question
|
||||||
func (s *Screen) AddWindow(r1, c1, r2, c2 int, scroll, border, show bool) {
|
func (s *Screen) AddWindow(r1, c1, r2, c2 int, scroll, border, show bool) {
|
||||||
w := Window{box{r1, c1, r2, c2}, scroll, 0, []string{}, border, false, show}
|
w := Window{box{r1, c1, r2, c2}, scroll, 0, []string{}, border, false, show}
|
||||||
|
@ -57,7 +56,6 @@ func (s Screen) Clear() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ReflashScreen checks for a screen resize and resizes windows if
|
// ReflashScreen checks for a screen resize and resizes windows if
|
||||||
// needed then redraws the screen. It takes a bool to decide whether
|
// needed then redraws the screen. It takes a bool to decide whether
|
||||||
// to redraw the full screen or just the content. On a resize
|
// to redraw the full screen or just the content. On a resize
|
||||||
|
@ -124,7 +122,6 @@ func (s *Screen) DrawMsgBars() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// GetSize retrieves the terminal size and sets the Screen
|
// GetSize retrieves the terminal size and sets the Screen
|
||||||
// width and height to that size
|
// width and height to that size
|
||||||
func (s *Screen) GetSize() {
|
func (s *Screen) GetSize() {
|
||||||
|
@ -141,7 +138,6 @@ func (s *Screen) GetSize() {
|
||||||
s.Width = w
|
s.Width = w
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
||||||
// NewScreen is a constructor function that returns a pointer
|
// NewScreen is a constructor function that returns a pointer
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
type box struct {
|
type box struct {
|
||||||
row1 int
|
row1 int
|
||||||
col1 int
|
col1 int
|
||||||
|
@ -53,17 +52,17 @@ func (w *Window) DrawBox(){
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Window) DrawContent() {
|
func (w *Window) DrawContent() {
|
||||||
var maxlines, border_thickness, contenth int
|
var maxlines, borderThickness, contenth int
|
||||||
var short_content bool = false
|
var short_content bool = false
|
||||||
|
|
||||||
if w.drawBox {
|
if w.drawBox {
|
||||||
border_thickness, contenth = -1, 1
|
borderThickness, contenth = -1, 1
|
||||||
} else {
|
} else {
|
||||||
border_thickness, contenth = 1, 0
|
borderThickness, contenth = 1, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
height := w.Box.row2 - w.Box.row1 + border_thickness
|
height := w.Box.row2 - w.Box.row1 + borderThickness
|
||||||
width := w.Box.col2 - w.Box.col1 + border_thickness
|
width := w.Box.col2 - w.Box.col1 + borderThickness
|
||||||
|
|
||||||
content := WrapLines(w.Content, width)
|
content := WrapLines(w.Content, width)
|
||||||
|
|
||||||
|
@ -89,14 +88,14 @@ func (w *Window) DrawContent(){
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Window) ScrollDown() {
|
func (w *Window) ScrollDown() {
|
||||||
var border_thickness int
|
var borderThickness int
|
||||||
if w.drawBox {
|
if w.drawBox {
|
||||||
border_thickness = -1
|
borderThickness = -1
|
||||||
} else {
|
} else {
|
||||||
border_thickness = 1
|
borderThickness = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
height := w.Box.row2 - w.Box.row1 + border_thickness
|
height := w.Box.row2 - w.Box.row1 + borderThickness
|
||||||
contentLength := len(w.Content)
|
contentLength := len(w.Content)
|
||||||
if w.Scrollposition < contentLength-height {
|
if w.Scrollposition < contentLength-height {
|
||||||
w.Scrollposition++
|
w.Scrollposition++
|
||||||
|
@ -112,4 +111,3 @@ func (w *Window) ScrollUp() {
|
||||||
fmt.Print("\a")
|
fmt.Print("\a")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
// + + + T Y P E S + + + \\
|
// + + + T Y P E S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
|
||||||
|
|
||||||
//Bookmarks is a holder for titles and links that
|
//Bookmarks is a holder for titles and links that
|
||||||
//can be retrieved by index
|
//can be retrieved by index
|
||||||
type Bookmarks struct {
|
type Bookmarks struct {
|
||||||
|
@ -17,14 +16,10 @@ type Bookmarks struct {
|
||||||
Links []string
|
Links []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
// + + + R E C E I V E R S + + + \\
|
// + + + R E C E I V E R S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
|
||||||
|
|
||||||
// Add adds a new title and link combination to the bookmarks
|
// Add adds a new title and link combination to the bookmarks
|
||||||
// struct. It takes as input a string slice in which the first
|
// struct. It takes as input a string slice in which the first
|
||||||
// element represents the link and all following items represent
|
// element represents the link and all following items represent
|
||||||
|
@ -55,7 +50,6 @@ func (b Bookmarks) List() []string {
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (b Bookmarks) IniDump() string {
|
func (b Bookmarks) IniDump() string {
|
||||||
if len(b.Titles) < 0 {
|
if len(b.Titles) < 0 {
|
||||||
return ""
|
return ""
|
||||||
|
@ -70,7 +64,6 @@ func (b Bookmarks) IniDump() string {
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func MakeBookmarks() Bookmarks {
|
func MakeBookmarks() Bookmarks {
|
||||||
return Bookmarks{[]string{}, []string{}}
|
return Bookmarks{[]string{}, []string{}}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,17 +4,16 @@
|
||||||
package gopher
|
package gopher
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
|
||||||
"errors"
|
"errors"
|
||||||
"net"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"time"
|
"net"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
"fmt"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
// + + + V A R I A B L E S + + + \\
|
// + + + V A R I A B L E S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
@ -37,13 +36,10 @@ var types = map[string]string{
|
||||||
"p": "PNG",
|
"p": "PNG",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
// + + + F U N C T I O N S + + + \\
|
// + + + F U N C T I O N S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
|
||||||
|
|
||||||
// Retrieve makes a request to a Url and resturns
|
// Retrieve makes a request to a Url and resturns
|
||||||
// the response as []byte/error. This function is
|
// the response as []byte/error. This function is
|
||||||
// available to use directly, but in most implementations
|
// available to use directly, but in most implementations
|
||||||
|
@ -82,7 +78,6 @@ func Retrieve(u Url) ([]byte, error) {
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Visit is a high level combination of a few different
|
// Visit is a high level combination of a few different
|
||||||
// types that makes it easy to create a Url, make a request
|
// types that makes it easy to create a Url, make a request
|
||||||
// to that Url, and add the response and Url to a View.
|
// to that Url, and add the response and Url to a View.
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package gopher
|
package gopher
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
|
@ -22,7 +22,6 @@ type History struct {
|
||||||
Collection [20]View
|
Collection [20]View
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
// + + + R E C E I V E R S + + + \\
|
// + + + R E C E I V E R S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
@ -76,7 +75,6 @@ func (h *History) GoBack() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// The "GoForward" receiver is called by a history struct.
|
// The "GoForward" receiver is called by a history struct.
|
||||||
// When called it increments the current position and
|
// When called it increments the current position and
|
||||||
// displays the content for the View in that position.
|
// displays the content for the View in that position.
|
||||||
|
@ -100,12 +98,10 @@ func (h *History) DisplayCurrentView() {
|
||||||
h.Collection[h.Position].Display()
|
h.Collection[h.Position].Display()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
// + + + F U N C T I O N S + + + \\
|
// + + + F U N C T I O N S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
|
||||||
|
|
||||||
// Constructor function for History struct.
|
// Constructor function for History struct.
|
||||||
// This is used to initialize history position
|
// This is used to initialize history position
|
||||||
// as -1, which is needed. Returns a copy of
|
// as -1, which is needed. Returns a copy of
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
package gopher
|
package gopher
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"regexp"
|
|
||||||
"errors"
|
"errors"
|
||||||
|
"regexp"
|
||||||
)
|
)
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
// + + + T Y P E S + + + \\
|
// + + + T Y P E S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
|
||||||
|
|
||||||
// The url struct represents a URL for the rest of the system.
|
// The url struct represents a URL for the rest of the system.
|
||||||
// It includes component parts as well as a full URL string.
|
// It includes component parts as well as a full URL string.
|
||||||
type Url struct {
|
type Url struct {
|
||||||
|
@ -22,7 +21,6 @@ type Url struct {
|
||||||
IsBinary bool
|
IsBinary bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
// + + + F U N C T I O N S + + + \\
|
// + + + F U N C T I O N S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
@ -87,4 +85,3 @@ func MakeUrl(u string) (Url, error) {
|
||||||
|
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,14 @@
|
||||||
package gopher
|
package gopher
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
// + + + T Y P E S + + + \\
|
// + + + T Y P E S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
|
||||||
|
|
||||||
// View is a struct representing a gopher page. It contains
|
// View is a struct representing a gopher page. It contains
|
||||||
// the page content as a string slice, a list of link URLs
|
// the page content as a string slice, a list of link URLs
|
||||||
// as string slices, and the Url struct representing the page.
|
// as string slices, and the Url struct representing the page.
|
||||||
|
@ -21,12 +18,10 @@ type View struct {
|
||||||
Address Url
|
Address Url
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
// + + + R E C E I V E R S + + + \\
|
// + + + R E C E I V E R S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
|
||||||
|
|
||||||
// ParseMap is called by a view struct to parse a gophermap.
|
// ParseMap is called by a view struct to parse a gophermap.
|
||||||
// It checks if the view is for a gophermap. If not,it does
|
// It checks if the view is for a gophermap. If not,it does
|
||||||
// nothing. If so, it parses the gophermap into comment lines
|
// nothing. If so, it parses the gophermap into comment lines
|
||||||
|
@ -73,12 +68,10 @@ func (v View) Display() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
// + + + F U N C T I O N S + + + \\
|
// + + + F U N C T I O N S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
|
||||||
|
|
||||||
// MakeView creates and returns a new View struct from
|
// MakeView creates and returns a new View struct from
|
||||||
// a Url and a string splice of content. This is used to
|
// a Url and a string splice of content. This is used to
|
||||||
// initialize a View with a Url struct, links, and content.
|
// initialize a View with a Url struct, links, and content.
|
||||||
|
@ -89,5 +82,3 @@ func MakeView(url Url, content []string) View {
|
||||||
v.ParseMap()
|
v.ParseMap()
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bombadillo/gopher"
|
"fmt"
|
||||||
"bombadillo/cmdparse"
|
|
||||||
"bombadillo/config"
|
|
||||||
"bombadillo/cui"
|
|
||||||
"os/user"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"fmt"
|
"os/user"
|
||||||
"strings"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"tildegit.org/sloum/bombadillo/cmdparse"
|
||||||
|
"tildegit.org/sloum/bombadillo/config"
|
||||||
|
"tildegit.org/sloum/bombadillo/cui"
|
||||||
|
"tildegit.org/sloum/bombadillo/gopher"
|
||||||
)
|
)
|
||||||
|
|
||||||
var helplocation string = "gopher://colorfield.space:70/1/bombadillo-info"
|
var helplocation string = "gopher://colorfield.space:70/1/bombadillo-info"
|
||||||
|
@ -27,12 +27,12 @@ var options = map[string]string{
|
||||||
"httpbrowser": "lynx",
|
"httpbrowser": "lynx",
|
||||||
}
|
}
|
||||||
|
|
||||||
func err_exit(err string, code int) {
|
func errExit(err string, code int) {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(code)
|
os.Exit(code)
|
||||||
}
|
}
|
||||||
|
|
||||||
func save_file(address, name string) error {
|
func saveFile(address, name string) error {
|
||||||
quickMessage("Saving file...", false)
|
quickMessage("Saving file...", false)
|
||||||
defer quickMessage("Saving file...", true)
|
defer quickMessage("Saving file...", true)
|
||||||
|
|
||||||
|
@ -54,18 +54,18 @@ func save_file(address, name string) error {
|
||||||
return fmt.Errorf("Saved file to " + options["savelocation"] + name)
|
return fmt.Errorf("Saved file to " + options["savelocation"] + name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func save_file_from_data(v gopher.View) error {
|
func saveFileFromData(v gopher.View) error {
|
||||||
urlsplit := strings.Split(v.Address.Full, "/")
|
urlsplit := strings.Split(v.Address.Full, "/")
|
||||||
filename := urlsplit[len(urlsplit)-1]
|
filename := urlsplit[len(urlsplit)-1]
|
||||||
save_msg := fmt.Sprintf("Saved file as %q", options["savelocation"] + filename)
|
saveMsg := fmt.Sprintf("Saved file as %q", options["savelocation"]+filename)
|
||||||
quickMessage(save_msg, false)
|
quickMessage(saveMsg, false)
|
||||||
defer quickMessage(save_msg, true)
|
defer quickMessage(saveMsg, true)
|
||||||
err := ioutil.WriteFile(options["savelocation"]+filename, []byte(strings.Join(v.Content, "")), 0644)
|
err := ioutil.WriteFile(options["savelocation"]+filename, []byte(strings.Join(v.Content, "")), 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Errorf(save_msg)
|
return fmt.Errorf(saveMsg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func search(u string) error {
|
func search(u string) error {
|
||||||
|
@ -89,22 +89,21 @@ func search(u string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func routeInput(com *cmdparse.Command) error {
|
||||||
func route_input(com *cmdparse.Command) error {
|
|
||||||
var err error
|
var err error
|
||||||
switch com.Type {
|
switch com.Type {
|
||||||
case cmdparse.SIMPLE:
|
case cmdparse.SIMPLE:
|
||||||
err = simple_command(com.Action)
|
err = simpleCommand(com.Action)
|
||||||
case cmdparse.GOURL:
|
case cmdparse.GOURL:
|
||||||
err = go_to_url(com.Target)
|
err = goToURL(com.Target)
|
||||||
case cmdparse.GOLINK:
|
case cmdparse.GOLINK:
|
||||||
err = go_to_link(com.Target)
|
err = goToLink(com.Target)
|
||||||
case cmdparse.DOLINK:
|
case cmdparse.DOLINK:
|
||||||
err = do_link_command(com.Action, com.Target)
|
err = doLinkCommand(com.Action, com.Target)
|
||||||
case cmdparse.DOAS:
|
case cmdparse.DOAS:
|
||||||
err = do_command_as(com.Action, com.Value)
|
err = doCommandAs(com.Action, com.Value)
|
||||||
case cmdparse.DOLINKAS:
|
case cmdparse.DOLINKAS:
|
||||||
err = do_link_command_as(com.Action, com.Target, com.Value)
|
err = doLinkCommandAs(com.Action, com.Target, com.Value)
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("Unknown command entry!")
|
return fmt.Errorf("Unknown command entry!")
|
||||||
}
|
}
|
||||||
|
@ -112,7 +111,7 @@ func route_input(com *cmdparse.Command) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func toggle_bookmarks() {
|
func toggleBookmarks() {
|
||||||
bookmarks := screen.Windows[1]
|
bookmarks := screen.Windows[1]
|
||||||
main := screen.Windows[0]
|
main := screen.Windows[0]
|
||||||
if bookmarks.Show {
|
if bookmarks.Show {
|
||||||
|
@ -133,19 +132,19 @@ func toggle_bookmarks() {
|
||||||
screen.ReflashScreen(false)
|
screen.ReflashScreen(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func simple_command(a string) error {
|
func simpleCommand(a string) error {
|
||||||
a = strings.ToUpper(a)
|
a = strings.ToUpper(a)
|
||||||
switch a {
|
switch a {
|
||||||
case "Q", "QUIT":
|
case "Q", "QUIT":
|
||||||
cui.Exit()
|
cui.Exit()
|
||||||
case "H", "HOME":
|
case "H", "HOME":
|
||||||
return go_home()
|
return goHome()
|
||||||
case "B", "BOOKMARKS":
|
case "B", "BOOKMARKS":
|
||||||
toggle_bookmarks()
|
toggleBookmarks()
|
||||||
case "SEARCH":
|
case "SEARCH":
|
||||||
return search(options["searchengine"])
|
return search(options["searchengine"])
|
||||||
case "HELP":
|
case "HELP":
|
||||||
return go_to_url(helplocation)
|
return goToURL(helplocation)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("Unknown action %q", a)
|
return fmt.Errorf("Unknown action %q", a)
|
||||||
|
@ -153,7 +152,7 @@ func simple_command(a string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func go_to_url(u string) error {
|
func goToURL(u string) error {
|
||||||
quickMessage("Loading...", false)
|
quickMessage("Loading...", false)
|
||||||
v, err := gopher.Visit(u, options["openhttp"])
|
v, err := gopher.Visit(u, options["openhttp"])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -169,7 +168,7 @@ func go_to_url(u string) error {
|
||||||
}
|
}
|
||||||
} else if v.Address.IsBinary {
|
} else if v.Address.IsBinary {
|
||||||
// TO DO: run this into the write to file method
|
// TO DO: run this into the write to file method
|
||||||
return save_file_from_data(v)
|
return saveFileFromData(v)
|
||||||
} else {
|
} else {
|
||||||
history.Add(v)
|
history.Add(v)
|
||||||
}
|
}
|
||||||
|
@ -179,7 +178,7 @@ func go_to_url(u string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func go_to_link(l string) error {
|
func goToLink(l string) error {
|
||||||
if num, _ := regexp.MatchString(`^\d+$`, l); num && history.Length > 0 {
|
if num, _ := regexp.MatchString(`^\d+$`, l); num && history.Length > 0 {
|
||||||
linkcount := len(history.Collection[history.Position].Links)
|
linkcount := len(history.Collection[history.Position].Links)
|
||||||
item, _ := strconv.Atoi(l)
|
item, _ := strconv.Atoi(l)
|
||||||
|
@ -199,7 +198,7 @@ func go_to_link(l string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else if v.Address.IsBinary {
|
} else if v.Address.IsBinary {
|
||||||
return save_file_from_data(v)
|
return saveFileFromData(v)
|
||||||
} else {
|
} else {
|
||||||
history.Add(v)
|
history.Add(v)
|
||||||
}
|
}
|
||||||
|
@ -215,14 +214,14 @@ func go_to_link(l string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func go_home() error {
|
func goHome() error {
|
||||||
if options["homeurl"] != "unset" {
|
if options["homeurl"] != "unset" {
|
||||||
return go_to_url(options["homeurl"])
|
return goToURL(options["homeurl"])
|
||||||
}
|
}
|
||||||
return fmt.Errorf("No home address has been set")
|
return fmt.Errorf("No home address has been set")
|
||||||
}
|
}
|
||||||
|
|
||||||
func do_link_command(action, target string) error {
|
func doLinkCommand(action, target string) error {
|
||||||
num, err := strconv.Atoi(target)
|
num, err := strconv.Atoi(target)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Expected number, got %q", target)
|
return fmt.Errorf("Expected number, got %q", target)
|
||||||
|
@ -232,21 +231,21 @@ func do_link_command(action, target string) error {
|
||||||
case "DELETE", "D":
|
case "DELETE", "D":
|
||||||
err := settings.Bookmarks.Del(num)
|
err := settings.Bookmarks.Del(num)
|
||||||
screen.Windows[1].Content = settings.Bookmarks.List()
|
screen.Windows[1].Content = settings.Bookmarks.List()
|
||||||
save_config()
|
saveConfig()
|
||||||
screen.ReflashScreen(false)
|
screen.ReflashScreen(false)
|
||||||
return err
|
return err
|
||||||
case "BOOKMARKS", "B":
|
case "BOOKMARKS", "B":
|
||||||
if num > len(settings.Bookmarks.Links)-1 {
|
if num > len(settings.Bookmarks.Links)-1 {
|
||||||
return fmt.Errorf("There is no bookmark with ID %d", num)
|
return fmt.Errorf("There is no bookmark with ID %d", num)
|
||||||
}
|
}
|
||||||
err := go_to_url(settings.Bookmarks.Links[num])
|
err := goToURL(settings.Bookmarks.Links[num])
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Errorf("This method has not been built")
|
return fmt.Errorf("This method has not been built")
|
||||||
}
|
}
|
||||||
|
|
||||||
func do_command_as(action string, values []string) error {
|
func doCommandAs(action string, values []string) error {
|
||||||
if len(values) < 2 {
|
if len(values) < 2 {
|
||||||
return fmt.Errorf("%q", values)
|
return fmt.Errorf("%q", values)
|
||||||
}
|
}
|
||||||
|
@ -262,15 +261,15 @@ func do_command_as(action string, values []string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
screen.Windows[1].Content = settings.Bookmarks.List()
|
screen.Windows[1].Content = settings.Bookmarks.List()
|
||||||
save_config()
|
saveConfig()
|
||||||
screen.ReflashScreen(false)
|
screen.ReflashScreen(false)
|
||||||
return nil
|
return nil
|
||||||
case "WRITE", "W":
|
case "WRITE", "W":
|
||||||
return save_file(values[0], strings.Join(values[1:], " "))
|
return saveFile(values[0], strings.Join(values[1:], " "))
|
||||||
case "SET", "S":
|
case "SET", "S":
|
||||||
if _, ok := options[values[0]]; ok {
|
if _, ok := options[values[0]]; ok {
|
||||||
options[values[0]] = strings.Join(values[1:], " ")
|
options[values[0]] = strings.Join(values[1:], " ")
|
||||||
save_config()
|
saveConfig()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return fmt.Errorf("Unable to set %s, it does not exist", values[0])
|
return fmt.Errorf("Unable to set %s, it does not exist", values[0])
|
||||||
|
@ -278,7 +277,7 @@ func do_command_as(action string, values []string) error {
|
||||||
return fmt.Errorf("Unknown command structure")
|
return fmt.Errorf("Unknown command structure")
|
||||||
}
|
}
|
||||||
|
|
||||||
func do_link_command_as(action, target string, values []string) error {
|
func doLinkCommandAs(action, target string, values []string) error {
|
||||||
num, err := strconv.Atoi(target)
|
num, err := strconv.Atoi(target)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Expected number, got %q", target)
|
return fmt.Errorf("Expected number, got %q", target)
|
||||||
|
@ -297,17 +296,16 @@ func do_link_command_as(action, target string, values []string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
screen.Windows[1].Content = settings.Bookmarks.List()
|
screen.Windows[1].Content = settings.Bookmarks.List()
|
||||||
save_config()
|
saveConfig()
|
||||||
screen.ReflashScreen(false)
|
screen.ReflashScreen(false)
|
||||||
return nil
|
return nil
|
||||||
case "WRITE", "W":
|
case "WRITE", "W":
|
||||||
return save_file(links[num - 1], strings.Join(values, " "))
|
return saveFile(links[num-1], strings.Join(values, " "))
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Errorf("This method has not been built")
|
return fmt.Errorf("This method has not been built")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func updateMainContent() {
|
func updateMainContent() {
|
||||||
screen.Windows[0].Content = history.Collection[history.Position].Content
|
screen.Windows[0].Content = history.Collection[history.Position].Content
|
||||||
screen.Bars[0].SetMessage(history.Collection[history.Position].Address.Full)
|
screen.Bars[0].SetMessage(history.Collection[history.Position].Address.Full)
|
||||||
|
@ -331,8 +329,7 @@ func quickMessage(msg string, clearMsg bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func saveConfig() {
|
||||||
func save_config() {
|
|
||||||
bkmrks := settings.Bookmarks.IniDump()
|
bkmrks := settings.Bookmarks.IniDump()
|
||||||
opts := "\n[SETTINGS]\n"
|
opts := "\n[SETTINGS]\n"
|
||||||
for k, v := range options {
|
for k, v := range options {
|
||||||
|
@ -344,11 +341,10 @@ func save_config() {
|
||||||
ioutil.WriteFile(userinfo.HomeDir+"/.bombadillo.ini", []byte(bkmrks+opts), 0644)
|
ioutil.WriteFile(userinfo.HomeDir+"/.bombadillo.ini", []byte(bkmrks+opts), 0644)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func loadConfig() {
|
||||||
func load_config() {
|
|
||||||
file, err := os.Open(userinfo.HomeDir + "/.bombadillo.ini")
|
file, err := os.Open(userinfo.HomeDir + "/.bombadillo.ini")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
save_config()
|
saveConfig()
|
||||||
}
|
}
|
||||||
confparser := config.NewParser(file)
|
confparser := config.NewParser(file)
|
||||||
settings, _ = confparser.Parse()
|
settings, _ = confparser.Parse()
|
||||||
|
@ -377,13 +373,11 @@ func toggleActiveWindow(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func displayError(err error) {
|
||||||
func display_error(err error) {
|
|
||||||
cui.MoveCursorTo(screen.Height, 0)
|
cui.MoveCursorTo(screen.Height, 0)
|
||||||
fmt.Print("\033[41m\033[37m", err, "\033[0m")
|
fmt.Print("\033[41m\033[37m", err, "\033[0m")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func initClient() {
|
func initClient() {
|
||||||
history.Position = -1
|
history.Position = -1
|
||||||
screen = cui.NewScreen()
|
screen = cui.NewScreen()
|
||||||
|
@ -396,20 +390,19 @@ func initClient() {
|
||||||
bookmarksWidth = screen.Width
|
bookmarksWidth = screen.Width
|
||||||
}
|
}
|
||||||
screen.AddWindow(2, screen.Width-bookmarksWidth, screen.Height-2, screen.Width, false, true, false)
|
screen.AddWindow(2, screen.Width-bookmarksWidth, screen.Height-2, screen.Width, false, true, false)
|
||||||
load_config()
|
loadConfig()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
defer cui.Exit()
|
defer cui.Exit()
|
||||||
initClient()
|
initClient()
|
||||||
mainWindow := screen.Windows[0]
|
mainWindow := screen.Windows[0]
|
||||||
first_load := true
|
firstLoad := true
|
||||||
|
|
||||||
for {
|
for {
|
||||||
if first_load {
|
if firstLoad {
|
||||||
first_load = false
|
firstLoad = false
|
||||||
err := go_home()
|
err := goHome()
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
updateMainContent()
|
updateMainContent()
|
||||||
|
@ -435,7 +428,7 @@ func main() {
|
||||||
screen.ReflashScreen(true)
|
screen.ReflashScreen(true)
|
||||||
}
|
}
|
||||||
case 'B':
|
case 'B':
|
||||||
toggle_bookmarks()
|
toggleBookmarks()
|
||||||
case 'f', 'F':
|
case 'f', 'F':
|
||||||
success := history.GoForward()
|
success := history.GoForward()
|
||||||
if success {
|
if success {
|
||||||
|
@ -456,11 +449,11 @@ func main() {
|
||||||
parser := cmdparse.NewParser(strings.NewReader(entry))
|
parser := cmdparse.NewParser(strings.NewReader(entry))
|
||||||
p, err := parser.Parse()
|
p, err := parser.Parse()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
display_error(err)
|
displayError(err)
|
||||||
} else {
|
} else {
|
||||||
err := route_input(p)
|
err := routeInput(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
display_error(err)
|
displayError(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue