-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
42 lines (35 loc) · 776 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// main.go
package main
import (
"fmt"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)
func main() {
app := tview.NewApplication()
browser := NewBrowser()
urlInput := tview.NewInputField().
SetLabel("URL: ").
SetFieldWidth(50)
urlInput.SetDoneFunc(func(key tcell.Key) {
if key == tcell.KeyEnter {
url := urlInput.GetText()
go func() {
content, err := fetchPage(url)
if err != nil {
content = err.Error()
}
app.QueueUpdateDraw(func() {
browser.SetContent(content)
})
}()
}
})
flex := tview.NewFlex().
SetDirection(tview.FlexRow).
AddItem(urlInput, 1, 1, true).
AddItem(browser, 0, 1, false)
if err := app.SetRoot(flex, true).Run(); err != nil {
fmt.Println("Error running application:", err)
}
}