Repository: raviqqe/muffet
Pull request #82 (2020-07-05 10:35:05)

fix an issue with the colored log in Windows shell.
# Issue

When running muffet with Windows PowerShell or Command prompt, the colored log portion does not display properly.

*PowerShell on Windows 10 (1909)*
![windows-powershell](https://user-images.githubusercontent.com/12206485/86530466-cfbfb800-bef3-11ea-85f3-0bac60480007.png)

*Command prompt on Windows 10 (1909)*
![windows-command_prompt](https://user-images.githubusercontent.com/12206485/86530468-d51d0280-bef3-11ea-826d-bf4a2cebb008.png)

# Solution

I fixed it by using [go-colorable](https://github.com/mattn/go-colorable) to replace `os.Stdout`. Because this library returns `os.Stdout` as `io.Writer` for non-Windows systems, I think that this fix have no effect on the operation of other OSes.

## fixed results

*PowerShell on Windows 10 (1909)*
![windows-powershell-fixed](https://user-images.githubusercontent.com/12206485/86530758-7efd8e80-bef6-11ea-8418-3378baf5f9f6.png)

*Command prompt on Windows 10 (1909)*
![windows-command_prompt-fixed](https://user-images.githubusercontent.com/12206485/86530762-84f36f80-bef6-11ea-8ca7-77c91bdf9661.png)



Patch:
diff --git a/go.mod b/go.mod
index 94bfbd0..2cff53d 100644
--- a/go.mod
+++ b/go.mod
@@ -32,6 +32,7 @@ require (
 	github.com/m3ng9i/go-utils v0.0.0-20160811013010-f9b7dc669fde // indirect
 	github.com/m3ng9i/ran v0.1.4 // indirect
 	github.com/magiconair/properties v1.8.1 // indirect
+	github.com/mattn/go-colorable v0.1.4
 	github.com/mitchellh/go-ps v0.0.0-20190716172923-621e5597135b // indirect
 	github.com/mozilla/tls-observatory v0.0.0-20190404164649-a3c1b6cfecfd // indirect
 	github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
@@ -58,7 +59,7 @@ require (
 	github.com/temoto/robotstxt v1.1.1
 	github.com/ugorji/go v1.1.7 // indirect
 	github.com/ultraware/funlen v0.0.2 // indirect
-	github.com/valyala/fasthttp v1.14.0
+	github.com/valyala/fasthttp v1.16.0
 	github.com/valyala/quicktemplate v1.2.0 // indirect
 	github.com/yhat/scrape v0.0.0-20161128144610-24b7890b0945
 	github.com/yterajima/go-sitemap v0.2.2
@@ -69,7 +70,7 @@ require (
 	golang.org/x/image v0.0.0-20190910094157-69e4b8554b2a // indirect
 	golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac // indirect
 	golang.org/x/mobile v0.0.0-20190910184405-b558ed863381 // indirect
-	golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e
+	golang.org/x/net v0.0.0-20200602114024-627f9648deb9
 	golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e // indirect
 	golang.org/x/tools v0.0.0-20190912132005-44811c017489 // indirect
 	google.golang.org/api v0.10.0 // indirect
diff --git a/go.sum b/go.sum
index 347f602..487c305 100644
--- a/go.sum
+++ b/go.sum
@@ -229,6 +229,8 @@ github.com/klauspost/compress v1.9.2 h1:LfVyl+ZlLlLDeQ/d2AqfGIIH4qEDu0Ed2S5GyhCW
 github.com/klauspost/compress v1.9.2/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
 github.com/klauspost/compress v1.10.4 h1:jFzIFaf586tquEB5EhzQG0HwGNSlgAJpG53G6Ss11wc=
 github.com/klauspost/compress v1.10.4/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
+github.com/klauspost/compress v1.10.7 h1:7rix8v8GpI3ZBb0nSozFRgbtXKv+hOe+qfEpZqybrAg=
+github.com/klauspost/compress v1.10.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
 github.com/klauspost/cpuid v0.0.0-20180405133222-e7e905edc00e h1:+lIPJOWl+jSiJOc70QXJ07+2eg2Jy2EC7Mi11BWujeM=
 github.com/klauspost/cpuid v0.0.0-20180405133222-e7e905edc00e/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
 github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
@@ -423,6 +425,10 @@ github.com/valyala/fasthttp v1.9.0 h1:hNpmUdy/+ZXYpGy0OBfm7K0UQTzb73W0T0U4iJIVrM
 github.com/valyala/fasthttp v1.9.0/go.mod h1:FstJa9V+Pj9vQ7OJie2qMHdwemEDaDiSdBnvPM1Su9w=
 github.com/valyala/fasthttp v1.14.0 h1:67bfuW9azCMwW/Jlq/C+VeihNpAuJMWkYPBig1gdi3A=
 github.com/valyala/fasthttp v1.14.0/go.mod h1:ol1PCaL0dX20wC0htZ7sYCsvCYmrouYra0zHzaclZhE=
+github.com/valyala/fasthttp v1.15.0 h1:U2WxMim6rzae8NgjlDXNeH84c7XBBTeUcq+YXh5k+ok=
+github.com/valyala/fasthttp v1.15.0/go.mod h1:YOKImeEosDdBPnxc0gy7INqi3m1zK6A+xl6TwOBhHCA=
+github.com/valyala/fasthttp v1.16.0 h1:9zAqOYLl8Tuy3E5R6ckzGDJ1g8+pw15oQp2iL9Jl6gQ=
+github.com/valyala/fasthttp v1.16.0/go.mod h1:YOKImeEosDdBPnxc0gy7INqi3m1zK6A+xl6TwOBhHCA=
 github.com/valyala/quicktemplate v1.1.1/go.mod h1:EH+4AkTd43SvgIbQHYu59/cJyxDoOVRUAfrukLPuGJ4=
 github.com/valyala/quicktemplate v1.2.0/go.mod h1:EH+4AkTd43SvgIbQHYu59/cJyxDoOVRUAfrukLPuGJ4=
 github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio=
@@ -501,7 +507,10 @@ golang.org/x/net v0.0.0-20191014212845-da9a3fd4c582 h1:p9xBe/w/OzkeYVKm234g55gMd
 golang.org/x/net v0.0.0-20191014212845-da9a3fd4c582/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
 golang.org/x/net v0.0.0-20191119073136-fc4aabc6c914 h1:MlY3mEfbnWGmUi4rtHOtNnnnN4UJRGSyLPx+DXA5Sq4=
 golang.org/x/net v0.0.0-20191119073136-fc4aabc6c914/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
+golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e h1:3G+cUijn7XD+S4eJFddp53Pv7+slrESplyjG25HgL+k=
 golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
+golang.org/x/net v0.0.0-20200602114024-627f9648deb9 h1:pNX+40auqi2JqRfOP1akLGtYcn15TUbkhwuCO3foqqM=
+golang.org/x/net v0.0.0-20200602114024-627f9648deb9/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
 golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
 golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
 golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -544,7 +553,10 @@ golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7w
 golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20191119195528-f068ffe820e4 h1:FjhQftcbpdYXneEYSWZO7+6Bu+Bi1A8VPvGYWOIzIbw=
 golang.org/x/sys v0.0.0-20191119195528-f068ffe820e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884=
 golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980 h1:OjiUf46hAmXblsZdnoSXsEUSKU8r1UEzcL5RVZ4gO9Y=
+golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/text v0.0.0-20170915090833-1cbadb444a80/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
 golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
 golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
diff --git a/main.go b/main.go
index 7a79969..aa1b690 100644
--- a/main.go
+++ b/main.go
@@ -4,10 +4,12 @@ import (
 	"fmt"
 	"io"
 	"os"
+
+	"github.com/mattn/go-colorable"
 )
 
 func main() {
-	s, err := command(os.Args[1:], os.Stdout)
+	s, err := command(os.Args[1:], colorable.NewColorableStdout())
 
 	if err != nil {
 		fprintln(os.Stderr, err)
diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml
deleted file mode 100644
index 937865b..0000000
--- a/snap/snapcraft.yaml
+++ /dev/null
@@ -1,27 +0,0 @@
-name: muffet
-version: latest
-version-script: prime/bin/muffet --version
-summary: Fast website link checker in Go
-description: |
-  Muffet is a website link checker which scrapes and inspects all pages in a
-  website recursively.
-
-grade: stable
-confinement: strict
-
-apps:
-  muffet:
-    command: bin/muffet
-    plugs:
-      - network
-
-parts:
-  go:
-    source-tag: go1.10.1
-  muffet:
-    plugin: go
-    after:
-      - go
-    source: https://github.com/raviqqe/muffet.git
-    source-type: git
-    go-importpath: github.com/raviqqe/muffet


Test patch:
diff --git a/fetcher_test.go b/fetcher_test.go
index 3f12b4b..9640f63 100644
--- a/fetcher_test.go
+++ b/fetcher_test.go
@@ -151,23 +151,24 @@ func TestFetcherSendRequestWithTimeout(t *testing.T) {
 	assert.Nil(t, err)
 }
 
-func TestFetcherSendRequestConcurrency(t *testing.T) {
-	c := 900
-	f := newFetcher(&fasthttp.Client{MaxConnsPerHost: c}, fetcherOptions{Concurrency: c})
-
-	g := sync.WaitGroup{}
-
-	for i := 0; i < 10000; i++ {
-		g.Add(1)
-		go func() {
-			_, err := f.sendRequest("http://httpbin.org/get")
-			assert.Nil(t, err)
-			g.Done()
-		}()
-	}
-
-	g.Wait()
-}
+// TODO Eanble it fixing its flakiness.
+// func TestFetcherSendRequestConcurrency(t *testing.T) {
+// 	c := 900
+// 	f := newFetcher(&fasthttp.Client{MaxConnsPerHost: c}, fetcherOptions{Concurrency: c})
+
+// 	g := sync.WaitGroup{}
+
+// 	for i := 0; i < 10000; i++ {
+// 		g.Add(1)
+// 		go func() {
+// 			_, err := f.sendRequest("http://httpbin.org/get")
+// 			assert.Nil(t, err)
+// 			g.Done()
+// 		}()
+// 	}
+
+// 	g.Wait()
+// }
 
 func TestSeparateFragment(t *testing.T) {
 	for _, ss := range [][3]string{