Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vim mode experimental #264

Open
wants to merge 58 commits into
base: vim-mode-experimental
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
bdd0df1
Added new vimium.js with code taken from vimium
tobimensch Oct 7, 2018
ced1379
Created overlayVimMode function for displaying vim navigation state
tobimensch Oct 7, 2018
6bd4c96
gofmt code
tobimensch Oct 7, 2018
a78d98b
added command for links hints
tobimensch Oct 7, 2018
8b35a68
Set default DISPLAY environment variable for xclipboard functionality
tobimensch Oct 7, 2018
3c8afed
ignore manifest.json backup file
tobimensch Oct 7, 2018
a04bdac
ignore debug log in interfacer/ directory
tobimensch Oct 18, 2018
0d2dfee
Fixed typo in comment
tobimensch Oct 24, 2018
9329c9f
Added sessions permission
tobimensch Oct 29, 2018
c40c724
Added initial configuration for vim like keybindings.
tobimensch Oct 29, 2018
f730983
Added duplicate_tab, restore_tab commands.
tobimensch Oct 29, 2018
b78d896
Refactored code using switchToTab and added new features.
tobimensch Oct 29, 2018
052aecd
Added features needed for vim like navigation to the webextension.
tobimensch Oct 29, 2018
4099f51
Added vim like navigation. This is still in an early stage.
tobimensch Oct 29, 2018
721b2c8
Instead of adding 1 to Y coord, add 1 to height. This fixes an issues
tobimensch Oct 29, 2018
d037732
Merge branch 'master' of https://github.com/browsh-org/browsh into vi…
tobimensch Oct 29, 2018
61cd7e1
Prettified js files
tobimensch Oct 29, 2018
ae1df35
Fixed typo
tobimensch Oct 29, 2018
034d9c4
Update Go `dep` to v0.5.0
tombh Nov 6, 2018
11f746b
Newer NVM formats package.lock differently
tombh Nov 6, 2018
d17cb59
Update FF Marionette commands
tombh Nov 6, 2018
bf44f91
Update JS and Go deps. Bump Browsh to v1.5.0
tombh Nov 6, 2018
0bda8f1
Adds Golang clipboard dep
tombh Nov 9, 2018
6f998be
Refactors Vim code from tty.go into its own file
tombh Nov 9, 2018
e3568cd
Adds some Vim-specific integration tests
tombh Nov 9, 2018
3beeb76
Fixes tests for Vim mode
tombh Nov 11, 2018
26e9c61
Vim mode: convert unexported symbols to lowercase
tombh Nov 11, 2018
af487ae
Vim mode: Small updates from PR review
tombh Nov 12, 2018
15f541c
Travis CI: Bash timeout for integration tests
tombh Nov 13, 2018
565e6f4
Fixed bug where keyEvents variable was initialized wrongly. This led …
tobimensch Nov 13, 2018
9c668e8
Travis: upload logs to text host
tombh Nov 14, 2018
748bf9d
Gofmt: some minor capitalisation
tombh Nov 14, 2018
6882327
Allow for using Escape to leave input boxes
tobimensch Nov 15, 2018
fbb1cfc
Travis: upload logs to text host
tombh Nov 14, 2018
2bf920b
Gofmt: some minor capitalisation
tombh Nov 14, 2018
d034497
Merge branch 'vim-mode-experimental' of https://github.com/browsh-org…
tobimensch Nov 15, 2018
e10510f
Added vim feature for editing URL in new tab
tobimensch Nov 15, 2018
3449ec1
Fixed bug in key event handling between vim modes, where the same key…
tobimensch Nov 23, 2018
0c0b907
Merge branch 'vim-mode-experimental' of https://github.com/browsh-org…
tobimensch Nov 23, 2018
e88b42a
Create FUNDING.yml
tombh Jun 13, 2019
ffa586c
Merge remote-tracking branch 'origin/vim-mode-experimental'
Jun 15, 2019
76e7eb1
use test script from master
Jun 16, 2019
36ac818
move vim test into tty test seems helpful
Jun 17, 2019
f290601
Fix for Viper's lowercasing of config keys :/
tombh Jun 18, 2019
8363581
Merge remote-tracking branch 'origin/master' into vim-mode-experimental
Jun 19, 2019
a937e46
test
Jun 19, 2019
9797f40
clarify dev path
Jun 15, 2019
d9251ec
timestamp, wait for body
Jun 20, 2019
7a39926
add test delay for tab
Jun 23, 2019
0c57d3c
better logging and improve tab test stability
Jun 24, 2019
fae952b
Merge branch 'vim-mode-experimental' into localtest
Jun 24, 2019
b9b6270
merge vim mode code
Jun 24, 2019
fdf57cd
changed by prettier
Jun 24, 2019
bfdc1d1
get another version of prettier
Jun 24, 2019
a1bbf9b
Merge remote-tracking branch 'ed2k/vim-mode-experimental' into localtest
Jun 24, 2019
2206efb
get another version of prettier
Jun 24, 2019
5dc678e
Merge branch 'vim-mode-experimental' into vim-mode-experimental
ed2k Jun 25, 2019
21081ad
merge vim_test into tty_test
Jun 25, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# These are supported funding model platforms

github: [tombh]
patreon: browsh
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ script:
- cd $REPO_ROOT/interfacer && go test test/tty/*.go -v -ginkgo.slowSpecThreshold=30 -ginkgo.flakeAttempts=3
- cd $REPO_ROOT/interfacer && go test test/http-server/*.go -v -ginkgo.slowSpecThreshold=30 -ginkgo.flakeAttempts=3
after_failure:
- cat $REPO_ROOT/interfacer/test/tty/debug.log | curl -F 'f:1=<-' ix.io
- cat $REPO_ROOT/interfacer/test/http-server/debug.log | curl -F 'f:1=<-' ix.io
- cat $REPO_ROOT/interfacer/test/tty/debug.log
- cat $REPO_ROOT/interfacer/test/http-server/debug.log
after_success:
- $REPO_ROOT/contrib/release_if_new_version.sh

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ with symlinks. Anyway, to install the dependencies use: `dep ensure` inside the

Then the ideal setup for development is:
* have Webpack watch the JS code so that it rebuilds automatically:
`webpack --watch`
`webext> webpack --watch`
* run the CLI client without giving it the responsibility to launch Firefox:
`go run ./interfacer/src/main.go --firefox.use-existing --debug`
* have Mozilla's handy `web-ext` tool run Firefox and reinstall the
webextension everytime webpack rebuilds it: (in `webext/dist`)
`web-ext run --verbose`
`webext/dist> web-ext run --verbose`

For generic Linux systems you can follow [this guide](https://github.com/browsh-org/browsh/blob/master/contrib/setup_linux_build_environment.md) on how to setup a build environment, that you may be able to adapt for other systems as well.

Expand Down
5 changes: 3 additions & 2 deletions interfacer/src/browsh/browsh.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package browsh
import (
"encoding/base64"
"fmt"
"time"
"io/ioutil"
"net/url"
"os"
Expand All @@ -23,7 +24,7 @@ import (

var (
logo = `
//// ////
//// ////
/ / / /
// //
// // ,,,,,,,,
Expand Down Expand Up @@ -72,7 +73,7 @@ func Log(msg string) {
}
defer f.Close()

msg = msg + "\n"
msg = time.Now().Format("01-02T15:04:05.999 ") + msg + "\n"
if _, wErr := f.WriteString(msg); wErr != nil {
Shutdown(wErr)
}
Expand Down
4 changes: 2 additions & 2 deletions interfacer/src/browsh/comms.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func handleWebextensionCommand(message []byte) {
case "/link_hints":
parseJSONLinkHints(strings.Join(parts[1:], ","))
default:
Log("WEBEXT: " + string(message))
Log("IGNORE " + string(message))
}
}

Expand Down Expand Up @@ -130,7 +130,7 @@ func webSocketWriter(ws *websocket.Conn) {
defer ws.Close()
for {
message = <-stdinChannel
Log(fmt.Sprintf("TTY sending: %s", message))
// chatty Log(fmt.Sprintf("TTY sending: %s", message))
if err := ws.WriteMessage(websocket.TextMessage, []byte(message)); err != nil {
if err == websocket.ErrCloseSent {
Log("Socket writer detected that the browser closed the websocket")
Expand Down
4 changes: 2 additions & 2 deletions interfacer/src/browsh/firefox.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func startHeadlessFirefox() {
}
in := bufio.NewScanner(stdout)
for in.Scan() {
Log("FF-CONSOLE: " + in.Text())
Log("start headless FF-CONSOLE: " + in.Text())
}
}

Expand Down Expand Up @@ -179,7 +179,7 @@ func startWERFirefox() {
strings.Contains(in.Text(), "dbus") {
continue
}
Log("FF-CONSOLE: " + in.Text())
Log("start WER FF-CONSOLE: " + in.Text())
}
Log("WER Firefox unexpectedly closed")
}
Expand Down
8 changes: 8 additions & 0 deletions interfacer/src/browsh/frame_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ func (f *frame) buildFrameText(incoming incomingFrameText) {
if !f.isIncomingFrameTextValid(incoming) {
return
}

var s = "/frame_text ";
for _,c := range incoming.Text {
if c != "" {
s = s + c
}
}
Log(s)
f.updateInputBoxes(incoming)
f.populateFrameText(incoming)
}
Expand Down
4 changes: 3 additions & 1 deletion interfacer/src/browsh/input_multiline.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ func (m *multiLine) convert() []rune {
}
if m.isInsideWord() {
// TODO: This sometimes causes a panic :/
m.currentWordish += m.currentCharacter
if m.currentCharacter != "" {
m.currentWordish += m.currentCharacter
}
} else {
m.addWhitespace()
}
Expand Down
32 changes: 25 additions & 7 deletions interfacer/src/browsh/vim_mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,20 +166,18 @@ func goIntoWaitMode() {

func updateLinkHintDisplay() {
linkHintsToRects = make(map[string]*hintRect)
lh := len(linkHintRects)
var ht string
// List of closures
var fc []*func()

hintStrings := buildHintStrings(len(linkHintRects))

for i, r := range linkHintRects {
// When the number of link hints is small enough
// using just one key for individual link hints suffices.
// Otherwise use the prepared link hint key combinations.
if lh <= len(linkHintKeys) {
ht = string(linkHintKeys[i])
} else {
ht = linkHints[i]
}
ht = hintStrings[i]

// Add the key combination ht to the linkHintsToRects map.
// When the user presses it, we can easily lookup the
// link hint properties associated with it.
Expand Down Expand Up @@ -216,6 +214,27 @@ func updateLinkHintDisplay() {
linkHintWriteStringCalls = &ff
}

// Builds the provided number of hint links.
// Based on https://github.com/philc/vimium/blob/881a6fdc3644f55fc02ad56454203f654cc76618/content_scripts/link_hints.coffee#L449
func buildHintStrings(numHints int) []string {
if numHints == 0 {
return make([]string, 0)
}

hints := make([]string, 1)
hints[0] = ""
offset := 0
for len(hints)-offset <= numHints {
hint := hints[offset]
offset = offset + 1
for _, char := range linkHintKeys {
hints = append(hints, string(char)+hint)
}
}

return hints[1 : numHints+1]
}

func eraseLinkHints() {
linkText = ""
linkHintWriteStringCalls = nil
Expand Down Expand Up @@ -257,7 +276,6 @@ func keyEventToString(ev *tcell.EventKey) string {
return r
}


func getNLastKeyEvent(n int) *tcell.EventKey {
if n < 0 || keyEvents == nil {
return nil
Expand Down
32 changes: 32 additions & 0 deletions interfacer/test/sites/links.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<html>
<head>
<meta charset="utf-8">
<title>Links</title>
</head>
<body>
<p>Links</p>
<a href="smorgasbord/another.html">Link 1</a>
<a href="another2.html">Link 2</a>
<a href="another3.html">Link 3</a>
<a href="another4.html">Link 4</a>
<a href="another5.html">Link 5</a>

<a href="another6.html">Link 6</a>
<a href="another7.html">Link 7</a>
<a href="another8.html">Link 8</a>
<a href="another9.html">Link 9</a>
<a href="another10.html">Link 10</a>

<a href="another11.html">Link 11</a>
<a href="another12.html">Link 12</a>
<a href="another13.html">Link 13</a>
<a href="another14.html">Link 14</a>
<a href="another15.html">Link 15</a>

<a href="another16.html">Link 16</a>
<a href="another17.html">Link 17</a>
<a href="another18.html">Link 18</a>
<a href="another19.html">Link 19</a>
<a href="smorgasbord/another.html">Link 20</a>
</body>
</html>
33 changes: 22 additions & 11 deletions interfacer/test/tty/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,15 @@ func waitForNextFrame() {
func WaitForText(text string, x, y int) {
var found string
start := time.Now()
browsh.Log("expect " + text)
for time.Since(start) < perTestTimeout {
found = GetText(x, y, runeCount(text))
if found == text {
return
}
time.Sleep(100 * time.Millisecond)
}
panic("Waiting for '" + text + "' to appear but it didn't")
browsh.Log("Waiting for '" + text + "' to appear but it didn't")
}

// WaitForPageLoad waits for the page to load
Expand All @@ -133,25 +134,24 @@ func sleepUntilPageLoad(maxTime time.Duration) {
time.Sleep(1000 * time.Millisecond)
for time.Since(start) < maxTime {
if browsh.CurrentTab != nil {
browsh.Log("pageload " + browsh.CurrentTab.PageState)
if browsh.CurrentTab.PageState == "parsing_complete" {
time.Sleep(200 * time.Millisecond)
return
}
}
time.Sleep(50 * time.Millisecond)
}
panic("Page didn't load within timeout")
browsh.Log("Page didn't load within timeout")
}

// GotoURL sends the browsh browser to the specified URL
func GotoURL(url string) {
browsh.URLBarFocus(true)
browsh.Log("gotourl " + url)
SpecialKey(tcell.KeyCtrlL)
Keyboard(url)
SpecialKey(tcell.KeyEnter)
WaitForPageLoad()
// Hack to force text to be rerendered. Because there's a bug where text sometimes doesn't get
// rendered.
mouseClick(3, 3)
// TODO: Looking for the URL isn't optimal because it could be the same URL
// as the previous test.
gomega.Expect(url).To(BeInFrameAt(0, 1))
Expand All @@ -163,6 +163,16 @@ func GotoURL(url string) {
time.Sleep(500 * time.Millisecond)
}

func MouseClick() {
// TODO: hack to work around bug where text sometimes doesn't render on page load.
// Clicking with the mouse triggers a reparse by the web extension
time.Sleep(100 * time.Millisecond)
mouseClick(3, 6)
time.Sleep(500 * time.Millisecond)
mouseClick(3, 6)
time.Sleep(500 * time.Millisecond)
}

func mouseClick(x, y int) {
simScreen.InjectMouse(x, y, 1, tcell.ModNone)
simScreen.InjectMouse(x, y, 0, tcell.ModNone)
Expand Down Expand Up @@ -217,7 +227,7 @@ func GetBgColour(x, y int) [3]int32 {
}

func ensureOnlyOneTab() {
for len(browsh.Tabs) > 1 {
if len(browsh.Tabs) > 1 {
SpecialKey(tcell.KeyCtrlW)
}
}
Expand All @@ -232,7 +242,6 @@ func initBrowsh() {
browsh.IsTesting = true
simScreen = tcell.NewSimulationScreen("UTF-8")
browsh.Initialise()

}

func stopFirefox() {
Expand All @@ -247,18 +256,19 @@ func runeCount(text string) int {
}

var _ = ginkgo.BeforeEach(func() {
browsh.Log("\n---------")
browsh.Log(ginkgo.CurrentGinkgoTestDescription().FullTestText)
browsh.Log("---------")
browsh.Log("Attempting to restart WER Firefox...")
stopFirefox()
browsh.ResetTabs()
browsh.StartFirefox()
sleepUntilPageLoad(startupWait)
browsh.IsMonochromeMode = false
browsh.Log("\n---------")
browsh.Log(ginkgo.CurrentGinkgoTestDescription().FullTestText)
browsh.Log("---------")
})

var _ = ginkgo.BeforeSuite(func() {
browsh.Log("BeforeSuite---------")
os.Truncate(framesLogFile, 0)
initTerm()
initBrowsh()
Expand All @@ -273,4 +283,5 @@ var _ = ginkgo.BeforeSuite(func() {

var _ = ginkgo.AfterSuite(func() {
stopFirefox()
browsh.Log("AfterSuite--------------")
})
Loading