mirror of
https://github.com/makew0rld/amfora.git
synced 2025-01-03 14:56:27 -05:00
Close links chan at end; remove TODOs
This commit is contained in:
parent
38674eebbd
commit
f3f8a63c38
@ -48,7 +48,6 @@ type GemtextRenderer struct {
|
||||
// If it's not a gemini:// page, set this to true.
|
||||
func NewGemtextRenderer(width int, proxied bool) *GemtextRenderer {
|
||||
pr, pw := io.Pipe()
|
||||
links := make(chan string, 10)
|
||||
|
||||
ansiEnabled := false
|
||||
if viper.GetBool("a-general.color") && viper.GetBool("a-general.ansi") {
|
||||
@ -62,7 +61,7 @@ func NewGemtextRenderer(width int, proxied bool) *GemtextRenderer {
|
||||
return &GemtextRenderer{
|
||||
r: pr,
|
||||
w: pw,
|
||||
links: links,
|
||||
links: make(chan string, 10),
|
||||
width: width,
|
||||
proxied: proxied,
|
||||
ansiEnabled: ansiEnabled,
|
||||
@ -272,7 +271,6 @@ func (ren *GemtextRenderer) renderLine(line string) string {
|
||||
|
||||
func (ren *GemtextRenderer) ReadFrom(r io.Reader) (int64, error) {
|
||||
// Go through lines, render, and write each line
|
||||
// TODO: Should writes be buffered?
|
||||
|
||||
var n int64
|
||||
scanner := bufio.NewScanner(r)
|
||||
@ -282,6 +280,8 @@ func (ren *GemtextRenderer) ReadFrom(r io.Reader) (int64, error) {
|
||||
n += int64(len(scanner.Bytes()))
|
||||
line := scanner.Text()
|
||||
|
||||
// Process the one possibly invisible line
|
||||
|
||||
if strings.HasPrefix(line, "```") {
|
||||
ren.pre = !ren.pre
|
||||
continue
|
||||
@ -295,6 +295,10 @@ func (ren *GemtextRenderer) ReadFrom(r io.Reader) (int64, error) {
|
||||
))
|
||||
|
||||
}
|
||||
|
||||
// Everything has been read, no more links
|
||||
close(ren.links)
|
||||
|
||||
return n, scanner.Err()
|
||||
}
|
||||
|
||||
|
@ -22,9 +22,8 @@ type Renderer interface {
|
||||
io.ReadWriter
|
||||
io.ReaderFrom
|
||||
|
||||
// Links returns a channel that yields Link URLs as they are parsed.
|
||||
// It is buffered. The channel might be closed to indicate links aren't supported
|
||||
// for this renderer.
|
||||
// Links returns a channel that yields link URLs as they are parsed.
|
||||
// It is buffered. The channel will be closed when there won't be anymore links.
|
||||
Links() <-chan string
|
||||
}
|
||||
|
||||
@ -62,7 +61,6 @@ func NewPlaintextRenderer() *PlaintextRenderer {
|
||||
|
||||
func (ren *PlaintextRenderer) ReadFrom(r io.Reader) (int64, error) {
|
||||
// Go through lines and escape bytes and write each line
|
||||
// TODO: Should writes be buffered?
|
||||
|
||||
var n int64
|
||||
scanner := bufio.NewScanner(r)
|
||||
@ -127,7 +125,6 @@ func (ren *ANSIRenderer) Write(p []byte) (n int, err error) {
|
||||
|
||||
func (ren *ANSIRenderer) ReadFrom(r io.Reader) (int64, error) {
|
||||
// Go through lines, render, and write each line
|
||||
// TODO: Should writes be buffered?
|
||||
|
||||
var n int64
|
||||
scanner := bufio.NewScanner(r)
|
||||
|
Loading…
Reference in New Issue
Block a user