mirror of
https://github.com/makew0rld/amfora.git
synced 2024-09-27 23:05:55 -04:00
parent
d0998128f9
commit
4480e2d540
21
amfora.go
21
amfora.go
@ -2,7 +2,9 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/makeworld-the-better-one/amfora/bookmarks"
|
"github.com/makeworld-the-better-one/amfora/bookmarks"
|
||||||
"github.com/makeworld-the-better-one/amfora/client"
|
"github.com/makeworld-the-better-one/amfora/client"
|
||||||
@ -68,6 +70,8 @@ func main() {
|
|||||||
display.NewTab()
|
display.NewTab()
|
||||||
if len(os.Args[1:]) > 0 {
|
if len(os.Args[1:]) > 0 {
|
||||||
display.URL(os.Args[1])
|
display.URL(os.Args[1])
|
||||||
|
} else if !isStdinEmpty() {
|
||||||
|
renderFromStdin()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start
|
// Start
|
||||||
@ -75,3 +79,20 @@ func main() {
|
|||||||
panic(err)
|
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))
|
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 {
|
func NumTabs() int {
|
||||||
return len(tabs)
|
return len(tabs)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user