Browse Source

Globally reformat with go fmt

Benton Edmondson 1 year ago
parent
commit
6928d069ff

+ 4 - 4
ansi/ansi.go

@@ -216,8 +216,8 @@ func DumbWrap(text string, width int) string {
 }
 
 /*
-	Limits `text` to the given `height` and `width`, adding an
-	ellipsis to the end and omitting trailing whitespace-only lines
+Limits `text` to the given `height` and `width`, adding an
+ellipsis to the end and omitting trailing whitespace-only lines
 */
 func Snip(text string, width, height int, ellipsis string) string {
 	snipped := make([]string, 0, height)
@@ -316,10 +316,10 @@ func SetLength(text string, length int, ellipsis string) string {
 		return ""
 	}
 	if len(text) > length {
-		return text[:length - 1] + ellipsis
+		return text[:length-1] + ellipsis
 	}
 	if len(text) < length {
-		return text + strings.Repeat(" ", length - len(text))
+		return text + strings.Repeat(" ", length-len(text))
 	}
 	return text
 }

+ 10 - 10
config/config.go

@@ -8,11 +8,11 @@ import (
 )
 
 type Config struct {
-	Context int `toml:"context"`
-	Timeout int `toml:"timeout"`
-	Feeds   feeds `toml:"feeds"`
-	Algos   algos `toml:"algos"`
-	MediaHook   []string `toml:"media_hook"`
+	Context   int      `toml:"context"`
+	Timeout   int      `toml:"timeout"`
+	Feeds     feeds    `toml:"feeds"`
+	Algos     algos    `toml:"algos"`
+	MediaHook []string `toml:"media_hook"`
 }
 
 type feeds = map[string][]string
@@ -24,11 +24,11 @@ type algos = map[string]struct {
 func Parse() (*Config, error) {
 	/* Default values */
 	config := &Config{
-		Context: 5,
-		Timeout: 10,
-		Feeds:   feeds{},
-		Algos:   algos{},
-		MediaHook:   []string{"xdg-open", "%u"},
+		Context:   5,
+		Timeout:   10,
+		Feeds:     feeds{},
+		Algos:     algos{},
+		MediaHook: []string{"xdg-open", "%u"},
 	}
 
 	location := location()

+ 7 - 7
feed/feed.go

@@ -20,7 +20,7 @@ func CreateEmpty() *Feed {
 		feed:       map[int]pub.Tangible{},
 		upperBound: 0,
 		lowerBound: 0,
-		index: 0,
+		index:      0,
 	}
 }
 
@@ -31,7 +31,7 @@ func Create(input pub.Tangible) *Feed {
 		},
 		upperBound: 1,
 		lowerBound: -1,
-		index: 0,
+		index:      0,
 	}
 }
 
@@ -61,10 +61,10 @@ func (f *Feed) Prepend(input []pub.Tangible) {
 
 func (f *Feed) Get(offset int) pub.Tangible {
 	if !f.Contains(offset) {
-		panic(fmt.Sprintf("indexing feed at %d whereas bounds are %d and %d", f.index + offset, f.lowerBound, f.upperBound))
+		panic(fmt.Sprintf("indexing feed at %d whereas bounds are %d and %d", f.index+offset, f.lowerBound, f.upperBound))
 	}
 
-	return f.feed[f.index + offset]
+	return f.feed[f.index+offset]
 }
 
 func (f *Feed) Current() pub.Tangible {
@@ -90,13 +90,13 @@ func (f *Feed) MoveToCenter() {
 }
 
 func (f *Feed) Contains(offset int) bool {
-	return f.index + offset < f.upperBound && f.index + offset> f.lowerBound
+	return f.index+offset < f.upperBound && f.index+offset > f.lowerBound
 }
 
 func (f *Feed) IsParent(offset int) bool {
-	return f.index + offset < 0
+	return f.index+offset < 0
 }
 
 func (f *Feed) IsChild(offset int) bool {
-	return f.index + offset > 0
+	return f.index+offset > 0
 }

+ 4 - 4
gemtext/gemtext.go

@@ -12,8 +12,8 @@ import (
 */
 
 type Markup struct {
-	tree []string
-	cached string
+	tree        []string
+	cached      string
 	cachedWidth int
 }
 
@@ -21,8 +21,8 @@ func NewMarkup(text string) (*Markup, []string, error) {
 	lines := strings.Split(text, "\n")
 	rendered, links := renderWithLinks(lines, 80)
 	return &Markup{
-		tree: lines,
-		cached: rendered,
+		tree:        lines,
+		cached:      rendered,
 		cachedWidth: 80,
 	}, links, nil
 }

+ 1 - 1
gemtext/gemtext_test.go

@@ -31,7 +31,7 @@ func TestBasic(t *testing.T) {
 	if links[1] != "http://example.org/" {
 		t.Fatalf("second link should be http://example.org/ not %s", links[1])
 	}
-	
+
 	output := markup.Render(50)
 	expected := style.QuoteBlock("blockquote") + "\n\n" +
 		style.Bullet("bullet point") + "\n\n" +

+ 2 - 2
history/history.go

@@ -2,7 +2,7 @@ package history
 
 type History[T any] struct {
 	elements []T
-	index int
+	index    int
 }
 
 func (h *History[T]) Current() T {
@@ -16,7 +16,7 @@ func (h *History[T]) Back() {
 }
 
 func (h *History[T]) Forward() {
-	if len(h.elements) > h.index + 1 {
+	if len(h.elements) > h.index+1 {
 		h.index += 1
 	}
 }

+ 9 - 9
hypertext/hypertext.go

@@ -10,15 +10,15 @@ import (
 )
 
 type Markup struct {
-	tree []*html.Node
-	cached string
+	tree        []*html.Node
+	cached      string
 	cachedWidth int
 }
 
 type context struct {
 	preserveWhitespace bool
-	width int
-	links *[]string
+	width              int
+	links              *[]string
 }
 
 func NewMarkup(text string) (*Markup, []string, error) {
@@ -32,8 +32,8 @@ func NewMarkup(text string) (*Markup, []string, error) {
 	}
 	rendered, links := renderWithLinks(nodes, 80)
 	return &Markup{
-		tree: nodes,
-		cached: rendered,
+		tree:        nodes,
+		cached:      rendered,
 		cachedWidth: 80,
 	}, links, nil
 }
@@ -51,8 +51,8 @@ func (m *Markup) Render(width int) string {
 func renderWithLinks(nodes []*html.Node, width int) (string, []string) {
 	ctx := context{
 		preserveWhitespace: false,
-		width: width,
-		links: &[]string{},
+		width:              width,
+		links:              &[]string{},
 	}
 	output := ""
 	for _, current := range nodes {
@@ -268,7 +268,7 @@ func bulletedList(node *html.Node, ctx context) string {
 }
 
 func bad(node *html.Node, ctx context) string {
-	return style.Red("<" + node.Data + ">") + renderChildren(node, ctx) + style.Red("</" + node.Data + ">")
+	return style.Red("<"+node.Data+">") + renderChildren(node, ctx) + style.Red("</"+node.Data+">")
 }
 
 func getAttribute(name string, attributes []html.Attribute) string {

+ 1 - 1
hypertext/hypertext_test.go

@@ -1,9 +1,9 @@
 package hypertext
 
 import (
+	"mimicry/ansi"
 	"mimicry/style"
 	"testing"
-	"mimicry/ansi"
 )
 
 func TestMergeText(t *testing.T) {

+ 1 - 1
jtp/jtp.go

@@ -7,12 +7,12 @@ import (
 	"errors"
 	"fmt"
 	lru "github.com/hashicorp/golang-lru/v2"
+	"mimicry/mime"
 	"net"
 	"net/url"
 	"regexp"
 	"strings"
 	"time"
-	"mimicry/mime"
 )
 
 var dialer = &net.Dialer{

+ 1 - 0
jtp/jtp_test.go

@@ -1,3 +1,4 @@
+//go:build !offline
 // +build !offline
 
 package jtp

+ 1 - 1
main.go

@@ -77,7 +77,7 @@ const version = "0.0.0"
 
 func help() {
 	os.Stdout.WriteString(
-"Servitor v" + version + `
+		"Servitor v" + version + `
 
 Commands:
 servitor open <url or @>

+ 6 - 6
mime/mime.go

@@ -25,18 +25,18 @@ func Default() *MediaType {
 }
 
 func Unknown() *MediaType {
-	return &MediaType {
-		Essence: "*/*",
+	return &MediaType{
+		Essence:   "*/*",
 		Supertype: "*",
-		Subtype: "*",
+		Subtype:   "*",
 	}
 }
 
 func UnknownSubtype(supertype string) *MediaType {
-	return &MediaType {
-		Essence: supertype + "/*",
+	return &MediaType{
+		Essence:   supertype + "/*",
 		Supertype: supertype,
-		Subtype: "*",
+		Subtype:   "*",
 	}
 }
 

+ 6 - 6
object/object.go

@@ -3,15 +3,15 @@ package object
 import (
 	"errors"
 	"fmt"
+	"math"
+	"mimicry/ansi"
+	"mimicry/gemtext"
+	"mimicry/hypertext"
+	"mimicry/markdown"
 	"mimicry/mime"
+	"mimicry/plaintext"
 	"net/url"
 	"time"
-	"mimicry/plaintext"
-	"mimicry/hypertext"
-	"mimicry/markdown"
-	"mimicry/gemtext"
-	"math"
-	"mimicry/ansi"
 )
 
 type Object map[string]any

+ 4 - 4
plaintext/plaintext.go

@@ -8,8 +8,8 @@ import (
 )
 
 type Markup struct {
-	text string
-	cached string
+	text        string
+	cached      string
 	cachedWidth int
 }
 
@@ -17,8 +17,8 @@ func NewMarkup(text string) (*Markup, []string, error) {
 	rendered, links := renderWithLinks(text, 80)
 
 	return &Markup{
-		text: text,
-		cached: rendered,
+		text:        text,
+		cached:      rendered,
 		cachedWidth: 80,
 	}, links, nil
 }

+ 1 - 1
plaintext/plaintext_test.go

@@ -27,7 +27,7 @@ Note the warning in <http://www.ics.uci.edu/pub/ietf/uri/historical.html#WARNING
 	}
 
 	expected := ansi.Wrap("Yes, Jim, I found it under \""+style.Link("http://www.w3.org/Addressing/", 1)+
-		"\",\nbut you can probably pick it up from the store.\n" +
+		"\",\nbut you can probably pick it up from the store.\n"+
 		"Note the warning in <"+style.Link("http://www.ics.uci.edu/pub/ietf/uri/historical.html#WARNING", 2)+">.", 50)
 
 	if expected != output {

+ 1 - 1
pub/activity.go

@@ -6,12 +6,12 @@ import (
 	"golang.org/x/exp/slices"
 	"mimicry/ansi"
 	"mimicry/client"
+	"mimicry/mime"
 	"mimicry/object"
 	"mimicry/style"
 	"net/url"
 	"sync"
 	"time"
-	"mimicry/mime"
 )
 
 type Activity struct {

+ 4 - 4
pub/actor.go

@@ -6,12 +6,12 @@ import (
 	"golang.org/x/exp/slices"
 	"mimicry/ansi"
 	"mimicry/client"
+	"mimicry/mime"
 	"mimicry/object"
 	"mimicry/style"
 	"net/url"
 	"strings"
 	"time"
-	"mimicry/mime"
 )
 
 type Actor struct {
@@ -23,9 +23,9 @@ type Actor struct {
 
 	id *url.URL
 
-	bio          object.Markup
-	bioLinks	[]string
-	bioErr       error
+	bio      object.Markup
+	bioLinks []string
+	bioErr   error
 
 	joined    time.Time
 	joinedErr error

+ 1 - 1
pub/common.go

@@ -236,7 +236,7 @@ func getBestLink(o object.Object, key string, supertype string) (*Link, error) {
 func ago(t time.Time) string {
 	duration := time.Since(t)
 
-	if days := int(duration.Hours()/24); days > 1 {
+	if days := int(duration.Hours() / 24); days > 1 {
 		return fmt.Sprintf("%d days ago", int(days))
 	} else if days == 1 {
 		return "1 day ago"

+ 1 - 1
pub/failure.go

@@ -1,9 +1,9 @@
 package pub
 
 import (
+	"mimicry/mime"
 	"mimicry/style"
 	"time"
-	"mimicry/mime"
 )
 
 type Failure struct {

+ 1 - 1
pub/interfaces.go

@@ -1,8 +1,8 @@
 package pub
 
 import (
-	"time"
 	"mimicry/mime"
+	"time"
 )
 
 type Any any

+ 15 - 15
pub/post.go

@@ -6,32 +6,32 @@ import (
 	"golang.org/x/exp/slices"
 	"mimicry/ansi"
 	"mimicry/client"
+	"mimicry/mime"
 	"mimicry/object"
 	"mimicry/style"
 	"net/url"
 	"strings"
 	"sync"
 	"time"
-	"mimicry/mime"
 )
 
 type Post struct {
 	kind string
 	id   *url.URL
 
-	title        string
-	titleErr     error
-	body         object.Markup
-	bodyLinks	[]string
-	bodyErr      error
-	media         *Link
-	mediaErr      error
-	created      time.Time
-	createdErr   error
-	edited       time.Time
-	editedErr    error
-	parent       any
-	parentErr    error
+	title      string
+	titleErr   error
+	body       object.Markup
+	bodyLinks  []string
+	bodyErr    error
+	media      *Link
+	mediaErr   error
+	created    time.Time
+	createdErr error
+	edited     time.Time
+	editedErr  error
+	parent     any
+	parentErr  error
 
 	// just as body dies completely if members die,
 	// attachments dies completely if any member dies
@@ -209,7 +209,7 @@ func (p *Post) supplement(width int) (string, bool) {
 			output += style.Problem(err)
 			continue
 		}
-		output += style.LinkBlock(ansi.Wrap(alt, width-2), len(p.bodyLinks) + i + 1)
+		output += style.LinkBlock(ansi.Wrap(alt, width-2), len(p.bodyLinks)+i+1)
 	}
 	return output, true
 }

+ 21 - 11
style/style.go

@@ -3,8 +3,8 @@ package style
 import (
 	"fmt"
 	"mimicry/ansi"
-	"strings"
 	"strconv"
+	"strings"
 )
 
 func background(text string, r uint8, g uint8, b uint8) string {
@@ -84,16 +84,26 @@ func superscript(value int) string {
 	text := strconv.Itoa(value)
 	return strings.Map(func(input rune) rune {
 		switch input {
-		case '0': return '\u2070'
-		case '1': return '\u00B9'
-		case '2': return '\u00B2'
-		case '3': return '\u00B3'
-		case '4': return '\u2074'
-		case '5': return '\u2075'
-		case '6': return '\u2076'
-		case '7': return '\u2077'
-		case '8': return '\u2078'
-		case '9': return '\u2079'
+		case '0':
+			return '\u2070'
+		case '1':
+			return '\u00B9'
+		case '2':
+			return '\u00B2'
+		case '3':
+			return '\u00B3'
+		case '4':
+			return '\u2074'
+		case '5':
+			return '\u2075'
+		case '6':
+			return '\u2076'
+		case '7':
+			return '\u2077'
+		case '8':
+			return '\u2078'
+		case '9':
+			return '\u2079'
 		default:
 			panic("can't superscript non-digit")
 		}

+ 23 - 24
ui/ui.go

@@ -5,15 +5,15 @@ import (
 	"mimicry/ansi"
 	"mimicry/config"
 	"mimicry/feed"
+	"mimicry/history"
+	"mimicry/mime"
 	"mimicry/pub"
 	"mimicry/splicer"
 	"mimicry/style"
-	"sync"
-	"mimicry/history"
 	"os/exec"
-	"mimicry/mime"
-	"strings"
 	"strconv"
+	"strings"
+	"sync"
 )
 
 /*
@@ -32,18 +32,18 @@ const (
 )
 
 const (
-	enterKey byte = '\r'
-	escapeKey byte = 27
+	enterKey     byte = '\r'
+	escapeKey    byte = 27
 	backspaceKey byte = 127
 )
 
 type Page struct {
-	feed  *feed.Feed
+	feed *feed.Feed
 
 	frontier  pub.Tangible
 	loadingUp bool
 
-	children        pub.Container
+	children    pub.Container
 	basepoint   uint
 	loadingDown bool
 }
@@ -59,7 +59,7 @@ type State struct {
 
 	config *config.Config
 
-	mode int
+	mode   int
 	buffer string
 }
 
@@ -69,7 +69,6 @@ func (s *State) view() string {
 	const parentConnector = "  │\n"
 	const childConnector = "\n"
 
-
 	if s.mode == loading {
 		return ansi.CenterVertically("", style.Color("  Loading…"), "", uint(s.height))
 	}
@@ -96,7 +95,7 @@ func (s *State) view() string {
 			}
 			continue
 		}
-		
+
 		serialized = ansi.Indent(serialized, "  ", true) + "\n"
 		if s.h.Current().feed.IsParent(i) {
 			serialized += parentConnector
@@ -109,10 +108,10 @@ func (s *State) view() string {
 			bottom += serialized
 		}
 	}
-	if s.h.Current().loadingUp && !s.h.Current().feed.Contains(-s.config.Context - 1) {
+	if s.h.Current().loadingUp && !s.h.Current().feed.Contains(-s.config.Context-1) {
 		top = "\n  " + style.Color("Loading…") + "\n\n" + top
 	}
-	if s.h.Current().loadingDown && !s.h.Current().feed.Contains(s.config.Context + 1) {
+	if s.h.Current().loadingDown && !s.h.Current().feed.Contains(s.config.Context+1) {
 		bottom += "  " + style.Color("Loading…") + "\n"
 	}
 
@@ -121,7 +120,7 @@ func (s *State) view() string {
 	bottom = strings.TrimSuffix(bottom, "\n")
 
 	output := ansi.CenterVertically(top, center, bottom, uint(s.height))
-	
+
 	var footer string
 	switch s.mode {
 	case normal:
@@ -233,7 +232,7 @@ func (s *State) Update(input byte) {
 				s.openExternally(link, mediaType)
 				return
 			}
-			
+
 		}
 		/* At this point we know input is a non-number, non-., non-enter */
 		s.mode = normal
@@ -313,7 +312,7 @@ func (s *State) switchTo(item any) {
 		}
 		if len(narrowed) == 1 {
 			s.h.Add(&Page{
-				feed: feed.Create(narrowed[0]),
+				feed:     feed.Create(narrowed[0]),
 				children: narrowed[0].Children(),
 				frontier: narrowed[0],
 			})
@@ -324,7 +323,7 @@ func (s *State) switchTo(item any) {
 		}
 	case pub.Tangible:
 		s.h.Add(&Page{
-			feed: feed.Create(narrowed),
+			feed:     feed.Create(narrowed),
 			children: narrowed.Children(),
 			frontier: narrowed,
 		})
@@ -335,8 +334,8 @@ func (s *State) switchTo(item any) {
 		children, nextCollection, newBasepoint := narrowed.Harvest(uint(s.config.Context), 0)
 		s.h.Add(&Page{
 			basepoint: newBasepoint,
-			children: nextCollection,
-			feed: feed.CreateAndAppend(children),
+			children:  nextCollection,
+			feed:      feed.CreateAndAppend(children),
 		})
 	default:
 		panic("can't switch to non-Tangible non-Container")
@@ -392,7 +391,7 @@ func (s *State) openUserInput(input string) {
 	s.mode = loading
 	s.buffer = ""
 	s.output(s.view())
-	go func(){
+	go func() {
 		result := pub.FetchUserInput(input)
 		s.m.Lock()
 		s.switchTo(result)
@@ -405,7 +404,7 @@ func (s *State) openInternally(input string) {
 	s.mode = loading
 	s.buffer = ""
 	s.output(s.view())
-	go func(){
+	go func() {
 		result := pub.New(input, nil)
 		s.m.Lock()
 		s.switchTo(result)
@@ -436,7 +435,7 @@ func (s *State) openFeed(input string) {
 
 func NewState(config *config.Config, width int, height int, output func(string)) *State {
 	s := &State{
-		h: history.History[*Page]{},
+		h:      history.History[*Page]{},
 		config: config,
 		width:  width,
 		height: height,
@@ -506,7 +505,7 @@ func (s *State) openExternally(link string, mediaType *mime.MediaType) {
 
 		s.m.Lock()
 		defer s.m.Unlock()
-		
+
 		if s.mode != opening {
 			return
 		}
@@ -519,7 +518,7 @@ func (s *State) openExternally(link string, mediaType *mime.MediaType) {
 			s.buffer = ""
 			return
 		}
-	
+
 		s.mode = normal
 		s.buffer = ""
 		s.output(s.view())