Skip to content

Commit 6de800f

Browse files
Added animated demo
1 parent c418d50 commit 6de800f

File tree

5 files changed

+49
-26
lines changed

5 files changed

+49
-26
lines changed

Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ build:
88
CGO_ENABLED=0 go build -ldflags "-s -w" -trimpath -o ./bin/${APP_NAME} ./cmd/${APP_NAME}/*.go
99

1010

11-
${TEST_FILE}:
12-
go test -c -race
13-
1411
.PHONY: bench
15-
bench: ${TEST_FILE}
16-
./$< -test.bench=. -test.benchmem -test.run=^$$ -test.benchtime 100x \
17-
-test.cpuprofile='cpu.prof' -test.memprofile='mem.prof'
12+
bench:
13+
go test -bench=. -benchmem -run=^$$ -benchtime 100x -cpuprofile='cpu.prof' -memprofile='mem.prof'
14+
15+
.PHONY: demo
16+
demo:
17+
go test . -v -run=TestOutput -count=1

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
[![Go Reference](https://pkg.go.dev/badge/github.com/shadowy-pycoder/goso.svg)](https://pkg.go.dev/github.com/shadowy-pycoder/goso)
77

88

9+
## Demo
10+
11+
![goso - Animated gif demo](demo/demo.gif)
12+
13+
914

1015
## Installation
1116

demo/demo.gif

7.49 MB
Loading

goso.go

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,22 @@ import (
2121
)
2222

2323
const (
24-
codeStartTag string = "<pre><code>"
25-
codeEndTag string = "</code></pre>"
26-
reset string = "\033[0m"
27-
bold string = "\033[1m"
28-
italic string = "\033[3m"
29-
strikethrough string = "\033[9m"
30-
gray string = "\033[37m"
31-
blue string = "\033[36m"
32-
green string = "\033[32m"
33-
yellow string = "\033[33m"
34-
magenta string = "\033[35m"
35-
questionColor string = "\033[38;5;204m"
36-
answerColor string = "\033[38;5;255m"
37-
downvoted string = "\033[38;5;160m"
38-
lightgray string = "\033[38;5;248m"
24+
codeStartTag string = "<pre><code>"
25+
codeEndTag string = "</code></pre>"
26+
reset string = "\033[0m"
27+
bold string = "\033[1m"
28+
italic string = "\033[3m"
29+
strikethrough string = "\033[9m"
30+
gray string = "\033[37m"
31+
blue string = "\033[36m"
32+
green string = "\033[32m"
33+
yellow string = "\033[33m"
34+
magenta string = "\033[35m"
35+
questionColor string = "\033[38;5;204m"
36+
answerColor string = "\033[38;5;255m"
37+
downvoted string = "\033[38;5;160m"
38+
lightgray string = "\033[38;5;248m"
39+
terminalMaxWidth int = 80
3940
)
4041

4142
var (
@@ -64,7 +65,6 @@ var (
6465
"</ol>", "",
6566
"<li>", " - ",
6667
"</li>", "",
67-
6868
"<b>", bold,
6969
"</b>", reset,
7070
"<h1>", bold,
@@ -411,11 +411,15 @@ func GetAnswers(conf *Config,
411411
fetchAnswers func(*Config, *GoogleSearchResult) (map[int]*Result, error),
412412
) (string, error) {
413413
var err error
414-
terminalWidth, _, err = term.GetSize(0)
415-
if err != nil {
416-
return "", err
414+
if term.IsTerminal(0) {
415+
terminalWidth, _, err = term.GetSize(0)
416+
if err != nil {
417+
return "", err
418+
}
419+
terminalWidth = min(terminalWidth, terminalMaxWidth)
420+
} else {
421+
terminalWidth = terminalMaxWidth
417422
}
418-
terminalWidth = min(terminalWidth, 80)
419423
var answers strings.Builder
420424
style := styles.Get(conf.Style)
421425
if style == nil {

goso_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,17 @@ func BenchmarkGetAnswers(b *testing.B) {
106106
}
107107
}
108108
}
109+
110+
func TestOutput(t *testing.T) {
111+
conf := &Config{
112+
Style: "onedark",
113+
Lexer: "c",
114+
QuestionNum: 10,
115+
AnswerNum: 10,
116+
}
117+
answers, err := GetAnswers(conf, fetchGoogle, fetchStackOverflow)
118+
if err != nil {
119+
t.Fatal(err)
120+
}
121+
fmt.Println(answers)
122+
}

0 commit comments

Comments
 (0)