Skip to content

Commit

Permalink
Merge pull request #298 from noborus/change-cache
Browse files Browse the repository at this point in the history
Change cache
  • Loading branch information
noborus authored Feb 26, 2023
2 parents 883857d + 8721f70 commit 90d4c9c
Show file tree
Hide file tree
Showing 15 changed files with 826 additions and 574 deletions.
6 changes: 1 addition & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ go 1.19
require (
code.rocketnine.space/tslocum/cbind v0.1.5
github.com/atotto/clipboard v0.1.4
github.com/dgraph-io/ristretto v0.1.1
github.com/fsnotify/fsnotify v1.6.0
github.com/gdamore/tcell/v2 v2.6.0
github.com/hashicorp/golang-lru v0.5.4
github.com/jwalton/gchalk v1.3.0
github.com/klauspost/compress v1.15.15
github.com/mattn/go-runewidth v0.0.14
Expand All @@ -22,18 +22,14 @@ require (
)

require (
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/gdamore/encoding v1.0.0 // indirect
github.com/golang/glog v1.0.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jwalton/go-supportscolor v1.1.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/cast v1.5.0 // indirect
Expand Down
16 changes: 2 additions & 14 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
Expand All @@ -57,13 +54,6 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgraph-io/ristretto v0.1.1 h1:6CWw5tJNgpegArSHpNHJKldNeq03FQCwYvfMVWajOK8=
github.com/dgraph-io/ristretto v0.1.1/go.mod h1:S1GPSBCYCIhmVNfcth17y2zZtQT6wzkzgwUve0VDWWA=
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 h1:tdlZCpZ/P9DhczCTSixgIKmwPv6+wP5DGjqLYw5SUiA=
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
Expand All @@ -82,8 +72,6 @@ github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/glog v1.0.0 h1:nfP3RFugxnNRyKgeWd4oI1nYvXpxrx8ck8ZrcizshdQ=
github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4=
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
Expand Down Expand Up @@ -140,6 +128,8 @@ github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5m
github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
Expand Down Expand Up @@ -176,7 +166,6 @@ github.com/pelletier/go-toml/v2 v2.0.6 h1:nrzqCb7j9cDFj2coyLNLaZuJTLjWjlaz6nvTvI
github.com/pelletier/go-toml/v2 v2.0.6/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek=
github.com/pierrec/lz4 v2.6.1+incompatible h1:9UY3+iC23yxF0UfGaYrGplQ+79Rg+h/q9FV9ix19jjM=
github.com/pierrec/lz4 v2.6.1+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down Expand Up @@ -367,7 +356,6 @@ golang.org/x/sys v0.0.0-20211004093028-2c5d950f24ef/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
Expand Down
12 changes: 6 additions & 6 deletions oviewer/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func (root *Root) setHeader(input string) {
root.setMessagef("Set header: %s", ErrInvalidNumber.Error())
return
}
if num < 0 || num > root.vHeight-1 {
if num < 0 || num > root.scr.vHeight-1 {
root.setMessagef("Set header %d: %s", num, ErrOutOfRange.Error())
return
}
Expand Down Expand Up @@ -465,8 +465,8 @@ func (root *Root) setMultiColor(input string) {

// setJumpTarget sets the position of the search result.
func (root *Root) setJumpTarget(input string) {
num := jumpPosition(root.vHeight, input)
if num < 0 || num > root.vHeight-1 {
num := jumpPosition(root.scr.vHeight, input)
if num < 0 || num > root.scr.vHeight-1 {
root.setMessagef("Set JumpTarget %d: %s", num, ErrOutOfRange.Error())
return
}
Expand Down Expand Up @@ -539,7 +539,7 @@ func (root *Root) ViewSync() {
root.prepareStartX()
root.prepareView()
root.Screen.Sync()
root.Doc.JumpTarget = jumpPosition(root.vHeight, root.Doc.JumpTargetString)
root.Doc.JumpTarget = jumpPosition(root.scr.vHeight, root.Doc.JumpTargetString)
}

// TailSync move to tail and sync.
Expand All @@ -561,9 +561,9 @@ func (root *Root) tailSection() {

// prepareStartX prepares startX.
func (root *Root) prepareStartX() {
root.startX = 0
root.scr.startX = 0
if root.Doc.LineNumMode {
root.startX = len(fmt.Sprintf("%d", root.Doc.BufEndNum())) + 1
root.scr.startX = len(fmt.Sprintf("%d", root.Doc.BufEndNum())) + 1
}
}

Expand Down
18 changes: 18 additions & 0 deletions oviewer/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,3 +519,21 @@ func (pos widthPos) x(x int) int {
}
return pos[len(pos)-1]
}

// n return string position from content.
func (pos widthPos) n(w int) int {
var x int
for _, c := range pos {
if c >= w {
x = c
break
}
}
// It should return the last byte of a multibyte character.
for i := len(pos) - 1; i >= 0; i-- {
if pos[i] == x {
return i
}
}
return len(pos) - 1
}
70 changes: 70 additions & 0 deletions oviewer/content_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,3 +741,73 @@ func Test_contentsToStr(t *testing.T) {
})
}
}

func Test_widthPos_x(t *testing.T) {
type args struct {
x int
}
tests := []struct {
name string
pos widthPos
args args
want int
}{
{
name: "\ttest",
pos: widthPos{0, 1, 8, 9, 10, 11},
args: args{2},
want: 8,
},
{
name: "testあいうえお",
pos: widthPos{0, 2, 2, 2, 4, 4, 4, 6, 6, 6, 8, 8, 8, 10, 10, 10},
args: args{12},
want: 8,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.pos.x(tt.args.x); got != tt.want {
t.Errorf("widthPos.x() = %v, want %v", got, tt.want)
}
})
}
}

func Test_widthPos_n(t *testing.T) {
type args struct {
w int
}
tests := []struct {
name string
pos widthPos
args args
want int
}{
{
name: "\ttest",
pos: widthPos{0, 1, 8, 9, 10, 11},
args: args{8},
want: 2,
},
{
name: "testあいうえお",
pos: widthPos{0, 2, 2, 2, 4, 4, 4, 6, 6, 6, 8, 8, 8, 10, 10, 10},
args: args{8},
want: 12,
},
{
name: "test2あいうえお",
pos: widthPos{0, 2, 2, 2, 4, 4, 4, 6, 6, 6, 8, 8, 8, 10, 10, 10},
args: args{9},
want: 15,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.pos.n(tt.args.w); got != tt.want {
t.Errorf("widthPos.n() = %v, want %v", got, tt.want)
}
})
}
}
4 changes: 0 additions & 4 deletions oviewer/doclist.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package oviewer

import (
"fmt"
"log"
"sync/atomic"
)
Expand Down Expand Up @@ -69,22 +68,19 @@ func (root *Root) nextDoc() {
root.setDocumentNum(root.CurrentDoc + 1)
root.input.Event = normal()
root.debugMessage("next document")
root.debugMessage(fmt.Sprintf("cache %v\n", root.Doc.cache.Metrics.String()))
}

// previouseDoc displays the previous document.
func (root *Root) previousDoc() {
root.setDocumentNum(root.CurrentDoc - 1)
root.input.Event = normal()
root.debugMessage("previous document")
root.debugMessage(fmt.Sprintf("cache %v\n", root.Doc.cache.Metrics.String()))
}

// switchDocument displays the document of the specified docNum.
func (root *Root) switchDocument(docNum int) {
root.setDocumentNum(docNum)
root.debugMessage("switch document")
root.debugMessage(fmt.Sprintf("cache %v\n", root.Doc.cache.Metrics.String()))
}

// setDocumentNum actually specifies docNum to display the document.
Expand Down
Loading

0 comments on commit 90d4c9c

Please sign in to comment.