M go.mod => go.mod +1 -1
@@ 4,7 4,7 @@ go 1.15
require (
github.com/charmbracelet/bubbles v0.7.6
- github.com/charmbracelet/bubbletea v0.12.4
+ github.com/charmbracelet/bubbletea v0.13.1
github.com/muesli/termenv v0.7.4
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3
)
M go.sum => go.sum +2 -2
@@ 3,8 3,8 @@ github.com/atotto/clipboard v0.1.2/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn
github.com/charmbracelet/bubbles v0.7.6 h1:SCAp4ZEUf2tBNEsufo+Xxxu2dvbFhYSDPrX45toQZrM=
github.com/charmbracelet/bubbles v0.7.6/go.mod h1:0D4XRYK0tjo8JMvflz1obpVcOikNZSG46SFauoZj22s=
github.com/charmbracelet/bubbletea v0.12.2/go.mod h1:3gZkYELUOiEUOp0bTInkxguucy/xRbGSOcbMs1geLxg=
-github.com/charmbracelet/bubbletea v0.12.4 h1:2cfryCnDOe7SvQF/Dj99irXKpFlfoPgQjEDdvP1pLpk=
-github.com/charmbracelet/bubbletea v0.12.4/go.mod h1:tp9tr9Dadh0PLhgiwchE5zZJXm5543JYjHG9oY+5qSg=
+github.com/charmbracelet/bubbletea v0.13.1 h1:huvX8mPaeMZ8DLulT50iEWRF+iitY5FNEDqDVLu69nM=
+github.com/charmbracelet/bubbletea v0.13.1/go.mod h1:tp9tr9Dadh0PLhgiwchE5zZJXm5543JYjHG9oY+5qSg=
github.com/containerd/console v1.0.1 h1:u7SFAJyRqWcG6ogaMAx3KjSTy1e3hT9QxqX7Jco7dRc=
github.com/containerd/console v1.0.1/go.mod h1:XUsP6YE/mKtz6bxc+I8UiKKTP04qjQL4qcS3XoQ5xkw=
github.com/google/goterm v0.0.0-20190703233501-fc88cf888a3f/go.mod h1:nOFQdrUlIlx6M6ODdSpBj1NVA+VgLC6kmw60mkw34H4=
M main.go => main.go +1 -0
@@ 332,6 332,7 @@ type LoadURLEvent struct {
type GoBackEvent struct{}
type GoForwardEvent struct{}
+type EditSourceEvent struct{}
type ToggleBookmarkEvent struct {
URL, Title string
M tab.go => tab.go +49 -22
@@ 1,12 1,15 @@
package main
import (
+ "bytes"
"context"
"errors"
"fmt"
+ "io"
"log"
neturl "net/url"
"os"
+ "os/exec"
"strings"
"time"
@@ 158,6 161,11 @@ func (tab Tab) Update(msg tea.Msg) (Tab, tea.Cmd) {
return tab.showMessage(m, msg.URL, messageDelBookmark, true)
}
return tab.showInput("Name", msg.Title, msg.URL, inputBookmark)
+ case EditSourceEvent:
+ if err := editSource(tab.lastResponse.GetData()); err != nil {
+ log.Print(err)
+ }
+ return tab, nil
case ServerResponse:
return tab.handleResponse(msg)
}
@@ 218,32 226,33 @@ func helpContent(tab Tab) string {
s := `
# Keys
-Go back h
-Go forward l
-Open link type number + enter
-Open link in tab type number + t
-Quit ctrl+c
-Next tab tab
-Previous tab shift+tab
-Goto tab alt+#
-Close tab q
-Goto URL g
-Download page d
-Home H
-Bookmark b
-Scroll up k
-Scroll download j
-Scroll up (page) Page up
-Scroll down (page) Page down
+Go back h
+Go forward l
+Open link type number + enter
+Open link in tab type number + t
+Quit ctrl+c
+Next tab tab
+Previous tab shift+tab
+Goto tab alt+#
+Close tab q
+Goto URL g
+Download page d
+Home H
+Bookmark b
+View source (in gvim) e
+Scroll up k
+Scroll down j
+Scroll up (page) Page up
+Scroll down (page) Page down
# Mouse
-Open link Left click
-Open link in tab Middle click
-Close tab Middle click (on tab)
-Go back Right click
-Scroll Mouse wheel
+Open link Left click
+Open link in tab Middle click
+Close tab Middle click (on tab)
+Go back Right click
+Scroll Mouse wheel
`
return s
}
@@ 402,3 411,21 @@ func (tab Tab) loadURL(url string, addHist bool, level int, skipVerify bool) (Ta
}
return tab, tea.Batch(cmd, spinner.Tick)
}
+
+func editSource(data []byte) error {
+ cmd := exec.Command("gvim", "-")
+ stderr, _ := cmd.StderrPipe()
+ stdin, _ := cmd.StdinPipe()
+ go stdin.Write(data)
+ go func() {
+ var buf bytes.Buffer
+ io.Copy(&buf, stderr)
+ if buf.Len() > 0 {
+ log.Print(buf.String())
+ }
+ }()
+ if err := cmd.Run(); err != nil {
+ return fmt.Errorf("could not run edit cmd: %w", err)
+ }
+ return nil
+}
M viewport.go => viewport.go +5 -0
@@ 26,6 26,7 @@ const (
buttonCloseTab = "Close Tab"
buttonQuit = "Quit"
buttonHelp = "Help"
+ buttonEdit = "Edit"
)
type Viewport struct {
@@ 137,6 138,8 @@ func (v Viewport) Update(msg tea.Msg) (Viewport, tea.Cmd) {
return v, v.handleButtonClick(buttonBookmark)
case "?":
return v, v.handleButtonClick(buttonHelp)
+ case "e":
+ return v, v.handleButtonClick(buttonEdit)
case "left", "h":
return v, v.handleButtonClick(buttonBack)
case "right", "l":
@@ 208,6 211,8 @@ func (v Viewport) handleButtonClick(btn string) tea.Cmd {
return fireEvent(ShowInputEvent{Message: "Go to", Type: inputNav, Payload: "", Value: val})
case buttonCloseTab:
return fireEvent(CloseCurrentTabEvent{})
+ case buttonEdit:
+ return fireEvent(EditSourceEvent{})
case buttonQuit:
return fireEvent(QuitEvent{})
default: