Fix output formatting + gofmt
This commit is contained in:
parent
f309c62d5a
commit
44e58de30a
20
main.go
20
main.go
@ -45,6 +45,10 @@ Output types:
|
|||||||
os.Exit(exitStatus)
|
os.Exit(exitStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func clearLine() {
|
||||||
|
fmt.Print("\033[2K")
|
||||||
|
}
|
||||||
|
|
||||||
func printInfo(f string, v ...interface{}) {
|
func printInfo(f string, v ...interface{}) {
|
||||||
fmt.Printf("* "+f+"\n", v...)
|
fmt.Printf("* "+f+"\n", v...)
|
||||||
}
|
}
|
||||||
@ -131,7 +135,7 @@ func NewExtractor(rawurl string, w io.Writer) (*Extractor, error) {
|
|||||||
}
|
}
|
||||||
return &Extractor{
|
return &Extractor{
|
||||||
BaseUrl: baseUrl,
|
BaseUrl: baseUrl,
|
||||||
W: w,
|
W: w,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,7 +262,7 @@ func (e *Extractor) parseAdditionalPage(doc *gq.Document) error {
|
|||||||
if hasClass("centerbig") {
|
if hasClass("centerbig") {
|
||||||
ret = "#### " + processChildren() + "\n\n"
|
ret = "#### " + processChildren() + "\n\n"
|
||||||
} else {
|
} else {
|
||||||
ret = /*" " + */processChildren() + "\n\n"
|
ret = /*" " + */ processChildren() + "\n\n"
|
||||||
}
|
}
|
||||||
case atom.Div:
|
case atom.Div:
|
||||||
ret = processChildren()
|
ret = processChildren()
|
||||||
@ -272,7 +276,8 @@ func (e *Extractor) parseAdditionalPage(doc *gq.Document) error {
|
|||||||
ret = processChildren()
|
ret = processChildren()
|
||||||
case atom.Img:
|
case atom.Img:
|
||||||
default:
|
default:
|
||||||
printWarn("Unknown data atom:", n.Data)
|
clearLine()
|
||||||
|
printWarn("Unknown data atom: %v", n.Data)
|
||||||
}
|
}
|
||||||
// Add some CSS effects.
|
// Add some CSS effects.
|
||||||
if hasClass("spaced") {
|
if hasClass("spaced") {
|
||||||
@ -289,7 +294,8 @@ func (e *Extractor) parseAdditionalPage(doc *gq.Document) error {
|
|||||||
ret = newRet
|
ret = newRet
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
printWarn("Unknown type:", n.Type)
|
clearLine()
|
||||||
|
printWarn("Unknown type: %v", n.Type)
|
||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
@ -382,7 +388,8 @@ func main() {
|
|||||||
|
|
||||||
// Download the actual chapters.
|
// Download the actual chapters.
|
||||||
for i, chapter := range e.ChapterUrls {
|
for i, chapter := range e.ChapterUrls {
|
||||||
fmt.Printf("\033[2K* Downloading chapter %v/%v...\r", i+1, len(e.ChapterUrls))
|
clearLine()
|
||||||
|
fmt.Printf("* Downloading chapter %v/%v...\r", i+1, len(e.ChapterUrls))
|
||||||
err = e.FetchAndProcessChapter(chapter)
|
err = e.FetchAndProcessChapter(chapter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -390,7 +397,8 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Write the generated markdown text to a file.
|
// Write the generated markdown text to a file.
|
||||||
filename := path.Join(dir, bookName + ".md")
|
filename := path.Join(dir, bookName+".md")
|
||||||
os.WriteFile(filename, b.Bytes(), 0666)
|
os.WriteFile(filename, b.Bytes(), 0666)
|
||||||
|
clearLine()
|
||||||
printInfo("Saved as: %v", filename)
|
printInfo("Saved as: %v", filename)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user