mirror of
https://github.com/makeworld-the-better-one/amfora.git
synced 2024-09-11 14:55:51 +03:00
parent
d0998128f9
commit
4480e2d540
21
amfora.go
21
amfora.go
@ -2,7 +2,9 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/makeworld-the-better-one/amfora/bookmarks"
|
||||
"github.com/makeworld-the-better-one/amfora/client"
|
||||
@ -68,6 +70,8 @@ func main() {
|
||||
display.NewTab()
|
||||
if len(os.Args[1:]) > 0 {
|
||||
display.URL(os.Args[1])
|
||||
} else if !isStdinEmpty() {
|
||||
renderFromStdin()
|
||||
}
|
||||
|
||||
// Start
|
||||
@ -75,3 +79,20 @@ func main() {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func isStdinEmpty() bool {
|
||||
stat, _ := os.Stdin.Stat()
|
||||
return (stat.Mode() & os.ModeCharDevice) != 0
|
||||
}
|
||||
|
||||
func renderFromStdin() {
|
||||
stdinTextBuilder := new(strings.Builder)
|
||||
_, err := io.Copy(stdinTextBuilder, os.Stdin)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error reading from standard input: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
stdinText := stdinTextBuilder.String()
|
||||
display.RenderFromString(stdinText)
|
||||
}
|
||||
|
@ -529,6 +529,25 @@ func URL(u string) {
|
||||
go goURL(t, fixUserURL(u))
|
||||
}
|
||||
|
||||
func RenderFromString(str string) {
|
||||
t := tabs[curTab]
|
||||
page, _ := renderPageFromString(str)
|
||||
setPage(t, page)
|
||||
}
|
||||
|
||||
func renderPageFromString(str string) (*structs.Page, bool) {
|
||||
rendered, links := renderer.RenderGemini(str, textWidth(), false)
|
||||
page := &structs.Page{
|
||||
Mediatype: structs.TextGemini,
|
||||
Raw: str,
|
||||
Content: rendered,
|
||||
Links: links,
|
||||
TermWidth: termW,
|
||||
}
|
||||
|
||||
return page, true
|
||||
}
|
||||
|
||||
func NumTabs() int {
|
||||
return len(tabs)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user