diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2021-11-01 09:35:54 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-11-01 10:03:49 +1100 |
commit | 2fc1498517523a20a3080816ec50ee9e7fbe533d (patch) | |
tree | 808b455c38c2e96f3d3930fa49f3f605416e5f24 | |
parent | 7a464ae5b7782b383050de6dc3ae5bd51a88bad0 (diff) |
some refactoring in anticipation of the graph feature
40 files changed, 520 insertions, 408 deletions
@@ -9,20 +9,18 @@ require ( github.com/cli/safeexec v1.0.0 github.com/cloudfoundry/jibber_jabber v0.0.0-20151120183258-bcc4c8345a21 github.com/creack/pty v1.1.11 - github.com/davecgh/go-spew v1.1.1 // indirect github.com/fatih/color v1.9.0 // indirect github.com/fsnotify/fsnotify v1.4.7 github.com/go-errors/errors v1.4.1 github.com/go-logfmt/logfmt v0.5.0 // indirect github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3 github.com/golang/protobuf v1.3.2 // indirect - github.com/google/go-cmp v0.3.1 // indirect + github.com/google/go-cmp v0.5.6 // indirect github.com/gookit/color v1.4.2 github.com/imdario/mergo v0.3.11 github.com/integrii/flaggy v1.4.0 - github.com/iriri/minimal/gitignore v0.3.2 // indirect github.com/jesseduffield/go-git/v5 v5.1.2-0.20201006095850-341962be15a4 - github.com/jesseduffield/gocui v0.3.1-0.20211024041248-681a61c53ed0 + github.com/jesseduffield/gocui v0.3.1-0.20211031223253-24baf341da75 github.com/jesseduffield/minimal/gitignore v0.3.3-0.20211018110810-9cde264e6b1e github.com/jesseduffield/yaml v2.1.0+incompatible github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 @@ -30,12 +28,11 @@ require ( github.com/kylelemons/godebug v1.1.0 // indirect github.com/kyokomi/emoji/v2 v2.2.8 github.com/lucasb-eyer/go-colorful v1.2.0 - github.com/mattn/go-colorable v0.1.7 // indirect - github.com/mattn/go-runewidth v0.0.13 // indirect + github.com/mattn/go-colorable v0.1.11 // indirect + github.com/mattn/go-runewidth v0.0.13 github.com/mgutz/str v1.2.0 github.com/onsi/ginkgo v1.10.3 // indirect github.com/onsi/gomega v1.7.1 // indirect - github.com/ozeidan/fuzzy-patricia v3.0.0+incompatible // indirect github.com/sahilm/fuzzy v0.1.0 github.com/sirupsen/logrus v1.4.2 github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad @@ -43,7 +40,7 @@ require ( github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0 // indirect golang.org/x/net v0.0.0-20201002202402-0a1ea396d57c // indirect - golang.org/x/sys v0.0.0-20211023085530-d6a326fbbf70 // indirect + golang.org/x/sys v0.0.0-20211031064116-611d5d643895 // indirect golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect golang.org/x/text v0.3.7 // indirect gopkg.in/ozeidan/fuzzy-patricia.v3 v3.0.0 @@ -56,8 +56,8 @@ github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg= -github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= +github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/gookit/color v1.4.2 h1:tXy44JFSFkKnELV6WaMo/lLfu/meqITX3iAV52do7lk= github.com/gookit/color v1.4.2/go.mod h1:fqRyamkC1W8uxl+lxCQxOT09l/vYfZ+QeiX3rKQHCoQ= github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= @@ -67,26 +67,12 @@ github.com/imdario/mergo v0.3.11 h1:3tnifQM4i+fbajXKBHXWEH+KvNHqojZ778UH75j3bGA= github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= github.com/integrii/flaggy v1.4.0 h1:A1x7SYx4jqu5NSrY14z8Z+0UyX2S5ygfJJrfolWR3zM= github.com/integrii/flaggy v1.4.0/go.mod h1:tnTxHeTJbah0gQ6/K0RW0J7fMUBk9MCF5blhm43LNpI= -github.com/iriri/minimal v0.0.0-20180828191352-9b2348d09c1a h1:mCZYG6QcX0dz/J0rFc1tcRYGeixlDcCGSPXuPMbiS5U= -github.com/iriri/minimal/gitignore v0.3.2 h1:MnTVH89iuwiyZ/a1pByw/mAU2ShWai1yvv0tgHSq5Ww= -github.com/iriri/minimal/gitignore v0.3.2/go.mod h1:v7YhsYBAInyAnQligwCIGRuQmtwQyYxkVy5vEdy2wPU= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jesseduffield/go-git/v5 v5.1.2-0.20201006095850-341962be15a4 h1:GOQrmaE8i+KEdB8NzAegKYd4tPn/inM0I1uo0NXFerg= github.com/jesseduffield/go-git/v5 v5.1.2-0.20201006095850-341962be15a4/go.mod h1:nGNEErzf+NRznT+N2SWqmHnDnF9aLgANB1CUNEan09o= -github.com/jesseduffield/gocui v0.3.1-0.20211017035223-b68948e63cc3 h1:J5s/4Y860tas8J0AMQ3gJKCbJPx8zNpiTm5UjEgPQfY= -github.com/jesseduffield/gocui v0.3.1-0.20211017035223-b68948e63cc3/go.mod h1:znJuCDnF2Ph40YZSlBwdX/4GEofnIoWLGdT4mK5zRAU= -github.com/jesseduffield/gocui v0.3.1-0.20211017041119-0ec562dfd23b h1:kepukaDQfZ6LBSvHUYReFvVSW5Lx5ZQZDgGhXj0Mx7U= -github.com/jesseduffield/gocui v0.3.1-0.20211017041119-0ec562dfd23b/go.mod h1:znJuCDnF2Ph40YZSlBwdX/4GEofnIoWLGdT4mK5zRAU= -github.com/jesseduffield/gocui v0.3.1-0.20211017063715-c74848d8ad00 h1:5TusU8ir9OHg3By2PPmLwa2y+2G9F+16QRK8bpofsC0= -github.com/jesseduffield/gocui v0.3.1-0.20211017063715-c74848d8ad00/go.mod h1:znJuCDnF2Ph40YZSlBwdX/4GEofnIoWLGdT4mK5zRAU= -github.com/jesseduffield/gocui v0.3.1-0.20211017091015-8bf4a4666b77 h1:MQUxSxVBTZQpSYybEiFA4+oIi02ycTKGCqgHItYi/20= -github.com/jesseduffield/gocui v0.3.1-0.20211017091015-8bf4a4666b77/go.mod h1:znJuCDnF2Ph40YZSlBwdX/4GEofnIoWLGdT4mK5zRAU= -github.com/jesseduffield/gocui v0.3.1-0.20211017220056-b2fc03c74a6f h1:JHrb78pj+gYC3KiJKL1WW6lYzlatBIF46oREn68plTM= -github.com/jesseduffield/gocui v0.3.1-0.20211017220056-b2fc03c74a6f/go.mod h1:znJuCDnF2Ph40YZSlBwdX/4GEofnIoWLGdT4mK5zRAU= -github.com/jesseduffield/gocui v0.3.1-0.20211024041248-681a61c53ed0 h1:To4mMbu6oQpbbyHa4WtMTc/DHa9dqiRWZpDLMNK+Hdk= -github.com/jesseduffield/gocui v0.3.1-0.20211024041248-681a61c53ed0/go.mod h1:znJuCDnF2Ph40YZSlBwdX/4GEofnIoWLGdT4mK5zRAU= -github.com/jesseduffield/minimal v0.0.0-20211018110810-9cde264e6b1e h1:WZc73tBVMMhcO6zXyZBItLEF4jgBpBH0lFCZzDgrjDg= +github.com/jesseduffield/gocui v0.3.1-0.20211031223253-24baf341da75 h1:zu+WBGwscCwu7GEuxANGl8E51HbW6ueqTF1XdAoqnZs= +github.com/jesseduffield/gocui v0.3.1-0.20211031223253-24baf341da75/go.mod h1:znJuCDnF2Ph40YZSlBwdX/4GEofnIoWLGdT4mK5zRAU= github.com/jesseduffield/minimal/gitignore v0.3.3-0.20211018110810-9cde264e6b1e h1:uw/oo+kg7t/oeMs6sqlAwr85ND/9cpO3up3VxphxY0U= github.com/jesseduffield/minimal/gitignore v0.3.3-0.20211018110810-9cde264e6b1e/go.mod h1:u60qdFGXRd36jyEXxetz0vQceQIxzI13lIo3EFUDf4I= github.com/jesseduffield/yaml v2.1.0+incompatible h1:HWQJ1gIv2zHKbDYNp0Jwjlj24K8aqpFHnMCynY1EpmE= @@ -115,13 +101,13 @@ github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69 github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/mattn/go-colorable v0.1.0/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= -github.com/mattn/go-colorable v0.1.7 h1:bQGKb3vps/j0E9GfJQ03JyhRuxsvdAanXlT9BTw3mdw= -github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-colorable v0.1.11 h1:nQ+aFkoE2TMGc0b68U2OKSexC+eq46+XwZzWXHRmPYs= +github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= -github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= -github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= +github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= @@ -136,9 +122,6 @@ github.com/onsi/ginkgo v1.10.3 h1:OoxbjfXVZyod1fmWYhI7SEyaD8B00ynP3T+D5GiyHOY= github.com/onsi/ginkgo v1.10.3/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/gomega v1.7.1 h1:K0jcRCwNQM3vFGh1ppMtDh/+7ApJrjldlX8fA0jDTLQ= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= -github.com/ozeidan/fuzzy-patricia v1.0.1 h1:YExnavqXH3OvCCqE2TunuJJHdFcFQdVEfUoWzrnPxSg= -github.com/ozeidan/fuzzy-patricia v3.0.0+incompatible h1:Pl61eMyfJqgY/wytiI4vamqPYribq6d8VxeP1CNyg9M= -github.com/ozeidan/fuzzy-patricia v3.0.0+incompatible/go.mod h1:zgvuCcYS7wB7fVCGblsaFFmEe8+aAH13dTYm8FbrpsM= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -188,17 +171,15 @@ golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211015200801-69063c4bb744 h1:KzbpndAYEM+4oHRp9JmB2ewj0NHHxO3Z0g7Gus2O1kk= -golang.org/x/sys v0.0.0-20211015200801-69063c4bb744/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211023085530-d6a326fbbf70 h1:SeSEfdIxyvwGJliREIJhRPPXvW6sDlLT+UQ3B0hD0NA= -golang.org/x/sys v0.0.0-20211023085530-d6a326fbbf70/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211031064116-611d5d643895 h1:iaNpwpnrgL5jzWS0vCNnfa8HqzxveCFpFx3uC/X4Tps= +golang.org/x/sys v0.0.0-20211031064116-611d5d643895/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -207,6 +188,8 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= diff --git a/pkg/gui/cherry_picking.go b/pkg/gui/cherry_picking.go index 8f144084c..c57854370 100644 --- a/pkg/gui/cherry_picking.go +++ b/pkg/gui/cherry_picking.go @@ -33,7 +33,7 @@ func (gui *Gui) handleCopyCommit() error { return err } - item, ok := context.SelectedItem() + item, ok := context.GetSelectedItem() if !ok { return nil } diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go index 422d8ec29..9c2914330 100644 --- a/pkg/gui/commits_panel.go +++ b/pkg/gui/commits_panel.go @@ -640,7 +640,7 @@ func (gui *Gui) handleGotoBottomForCommitsPanel() error { } for _, context := range gui.getListContexts() { - if context.ViewName == "commits" { + if context.GetViewName() == "commits" { return context.handleGotoBottom() } } diff --git a/pkg/gui/context.go b/pkg/gui/context.go index a74b12749..79db5dc26 100644 --- a/pkg/gui/context.go +++ b/pkg/gui/context.go @@ -285,9 +285,9 @@ func (gui *Gui) currentContextWithoutLock() Context { // the status panel is not yet a list context (and may never be), so this method is not // quite the same as currentSideContext() -func (gui *Gui) currentSideListContext() *ListContext { +func (gui *Gui) currentSideListContext() IListContext { context := gui.currentSideContext() - listContext, ok := context.(*ListContext) + listContext, ok := context.(IListContext) if !ok { return nil } diff --git a/pkg/gui/context_config.go b/pkg/gui/context_config.go index b7f7e3783..a3b965a69 100644 --- a/pkg/gui/context_config.go +++ b/pkg/gui/context_config.go @@ -56,19 +56,19 @@ var allContextKeys = []ContextKey{ type ContextTree struct { Status Context - Files *ListContext - Submodules *ListContext - Menu *ListContext - Branches *ListContext - Remotes *ListContext - RemoteBranches *ListContext - Tags *ListContext - BranchCommits *ListContext - CommitFiles *ListContext - ReflogCommits *ListContext - SubCommits *ListContext - Stash *ListContext - Suggestions *ListContext + Files IListContext + Submodules IListContext + Menu IListContext + Branches IListContext + Remotes IListContext + RemoteBranches IListContext + Tags IListContext + BranchCommits IListContext + CommitFiles IListContext + ReflogCommits IListContext + SubCommits IListContext + Stash IListContext + Suggestions IListContext Normal Context Staging Context PatchBuilding Context diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index cce28353e..6b5d0dd5d 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -395,9 +395,7 @@ func (gui *Gui) handleCommitPress() error { prefix := rgx.ReplaceAllString(gui.getCheckedOutBranch().Name, prefixReplace) gui.Views.CommitMessage.ClearTextArea() gui.Views.CommitMessage.TextArea.TypeString(prefix) - gui.g.Update(func(*gocui.Gui) error { - return nil - }) + gui.render() } gui.g.Update(func(g *gocui.Gui) error { diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index cfd436090..a07e1887b 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -458,6 +458,12 @@ func NewGui(log *logrus.Entry, gitCommand *commands.GitCommand, oSCommand *oscom return gui, nil } +var RuneReplacements = map[rune]string{ + // for the commit graph + '⏣': "M", + '⎔': "o", +} + // Run setup the gui with keybindings and start the mainloop func (gui *Gui) Run() error { recordEvents := recordingEvents() @@ -468,7 +474,7 @@ func (gui *Gui) Run() error { playMode = gocui.REPLAYING } - g, err := gocui.NewGui(gocui.OutputTrue, OverlappingEdges, playMode, headless()) + g, err := gocui.NewGui(gocui.OutputTrue, OverlappingEdges, playMode, headless(), RuneReplacements) if err != nil { return err } @@ -712,6 +718,7 @@ func (gui *Gui) startBackgroundFetch() { } else { gui.goEvery(time.Second*time.Duration(userConfig.Refresher.FetchInterval), gui.stopChan, func() error { err := gui.fetch(false, "") + gui.render() return err }) } diff --git a/pkg/gui/layout.go b/pkg/gui/layout.go index 0c43c3f34..59c6a761e 100644 --- a/pkg/gui/layout.go +++ b/pkg/gui/layout.go @@ -52,24 +52,19 @@ func (gui *Gui) createAllViews() error { gui.Views.Stash.Title = gui.Tr.StashTitle gui.Views.Stash.FgColor = theme.GocuiDefaultTextColor - gui.Views.Stash.ContainsList = true gui.Views.Commits.Title = gui.Tr.CommitsTitle gui.Views.Commits.FgColor = theme.GocuiDefaultTextColor - gui.Views.Commits.ContainsList = true gui.Views.CommitFiles.Title = gui.Tr.CommitFiles gui.Views.CommitFiles.FgColor = theme.GocuiDefaultTextColor - gui.Views.CommitFiles.ContainsList = true gui.Views.Branches.Title = gui.Tr.BranchesTitle gui.Views.Branches.FgColor = theme.GocuiDefaultTextColor - gui.Views.Branches.ContainsList = true gui.Views.Files.Highlight = true gui.Views.Files.Title = gui.Tr.FilesTitle gui.Views.Files.FgColor = theme.GocuiDefaultTextColor - gui.Views.Files.ContainsList = true gui.Views.Secondary.Title = gui.Tr.DiffTitle gui.Views.Secondary.Wrap = true @@ -111,7 +106,6 @@ func (gui *Gui) createAllViews() error { gui.Views.Credentials.Editable = true gui.Views.Suggestions.Visible = false - gui.Views.Suggestions.ContainsList = true gui.Views.Menu.Visible = false @@ -264,7 +258,7 @@ func (gui *Gui) layout(g *gocui.Gui) error { } for _, listContext := range gui.getListContexts() { - view, err := gui.g.View(listContext.ViewName) + view, err := gui.g.View(listContext.GetViewName()) if err != nil { continue } @@ -274,8 +268,7 @@ func (gui *Gui) layout(g *gocui.Gui) error { continue } - // check if the selected line is now out of view and if so refocus it - view.FocusPoint(0, listContext.GetPanelState().GetSelectedLineIdx()) + listContext.FocusLine() view.SelBgColor = theme.GocuiSelectedLineBgColor diff --git a/pkg/gui/list_context.go b/pkg/gui/list_context.go index a8ed12372..c8ef850a0 100644 --- a/pkg/gui/list_context.go +++ b/pkg/gui/list_context.go @@ -1,21 +1,49 @@ package gui +import ( + "fmt" +) + type ListContext struct { GetItemsLength func() int - GetDisplayStrings func() [][]string + GetDisplayStrings func(startIdx int, length int) [][]string OnFocus func() error OnFocusLost func() error OnClickSelectedItem func() error // the boolean here tells us whether the item is nil. This is needed because you can't work it out on the calling end once the pointer is wrapped in an interface (unless you want to use reflection) - SelectedItem func() (ListItem, bool) - GetPanelState func() IListPanelState + SelectedItem func() (ListItem, bool) + OnGetPanelState func() IListPanelState Gui *Gui *BasicContext } +type IListContext interface { + GetSelectedItem() (ListItem, bool) + GetSelectedItemId() string + OnRender() error + handlePrevLine() error + handleNextLine() error + handleLineChange(change int) error + handleNextPage() error + handleGotoTop() error + handleGotoBottom() error + handlePrevPage() error + handleClick() error + onSearchSelect(selectedLineIdx int) error + FocusLine() + + GetPanelState() IListPanelState + + Context +} + +func (self *ListContext) GetPanelState() IListPanelState { + return self.OnGetPanelState() +} + type IListPanelState interface { SetSelectedLineIdx(int) GetSelectedLineIdx() int @@ -29,12 +57,26 @@ type ListItem interface { Description() string } -func (lc *ListContext) GetSelectedItem() (ListItem, bool) { - return lc.SelectedItem() +func (self *ListContext) FocusLine() { + view, err := self.Gui.g.View(self.ViewName) + if err != nil { + return + } + + view.FocusPoint(0, self.GetPanelState().GetSelectedLineIdx()) + view.Footer = formatListFooter(self.GetPanelState().GetSelectedLineIdx(), self.GetItemsLength()) +} + +func formatListFooter(selectedLineIdx int, length int) string { + return fmt.Sprintf("%d of %d", selectedLineIdx+1, length) +} + +func (self *ListContext) GetSelectedItem() (ListItem, bool) { + return self.SelectedItem() } -func (lc *ListContext) GetSelectedItemId() string { - item, ok := lc.SelectedItem() +func (self *ListContext) GetSelectedItemId() string { + item, ok := self.GetSelectedItem() if !ok { return "" @@ -44,145 +86,135 @@ func (lc *ListContext) GetSelectedItemId() string { } // OnFocus assumes that the content of the context has already been rendered to the view. OnRender is the function which actually renders the content to the view -func (lc *ListContext) OnRender() error { - view, err := lc.Gui.g.View(lc.ViewName) +func (self *ListContext) OnRender() error { + view, err := self.Gui.g.View(self.ViewName) if err != nil { return nil } - if lc.GetDisplayStrings != nil { - lc.Gui.refreshSelectedLine(lc.GetPanelState(), lc.GetItemsLength()) - lc.Gui.renderDisplayStrings(view, lc.GetDisplayStrings()) + if self.GetDisplayStrings != nil { + self.Gui.refreshSelectedLine(self.GetPanelState(), self.GetItemsLength()) + self.Gui.renderDisplayStrings(view, self.GetDisplayStrings(0, self.GetItemsLength())) + self.Gui.render() } return nil } -func (lc *ListContext) HandleFocusLost() error { - if lc.OnFocusLost != nil { - return lc.OnFocusLost() +func (self *ListContext) HandleFocusLost() error { + if self.OnFocusLost != nil { + return self.OnFocusLost() } return nil } -func (lc *ListContext) HandleFocus() error { - if lc.Gui.popupPanelFocused() { +func (self *ListContext) HandleFocus() error { + if self.Gui.popupPanelFocused() { return nil } - view, err := lc.Gui.g.View(lc.ViewName) - if err != nil { - return nil - } + self.FocusLine() - view.FocusPoint(0, lc.GetPanelState().GetSelectedLineIdx()) - - if lc.Gui.State.Modes.Diffing.Active() { - return lc.Gui.renderDiff() + if self.Gui.State.Modes.Diffing.Active() { + return self.Gui.renderDiff() } - if lc.OnFocus != nil { - return lc.OnFocus() + if self.OnFocus != nil { + return self.OnFocus() } return nil } -func (lc *ListContext) HandleRender() error { - return lc.OnRender() +func (self *ListContext) HandleRender() error { + return self.OnRender() } -func (lc *ListContext) handlePrevLine() error { - return lc.handleLineChange(-1) +func (self *ListContext) handlePrevLine() error { + return self.handleLineChange(-1) } -func (lc *ListContext) handleNextLine() error { - return lc.handleLineChange(1) +func (self *ListContext) handleNextLine() error { + return self.handleLineChange(1) } -func (lc *ListContext) handleLineChange(change int) error { - if !lc.Gui.isPopupPanel(lc.ViewName) && lc.Gui.popupPanelFocused() { +func (self *ListContext) handleLineChange(change int) error { + if !self.Gui.isPopupPanel(self.ViewName) && self.Gui.popupPanelFocused() { return nil } - view, err := lc.Gui.g.View(lc.ViewName) - if err != nil { - return err - } - - selectedLineIdx := lc.GetPanelState().GetSelectedLineIdx() - if (change < 0 && selectedLineIdx == 0) || (change > 0 && selectedLineIdx == lc.GetItemsLength()-1) { + selectedLineIdx := self.GetPanelState().GetSelectedLineIdx() + if (change < 0 && selectedLineIdx == 0) || (change > 0 && selectedLineIdx == self.GetItemsLength()-1) { return nil } - lc.Gui.changeSelectedLine(lc.GetPanelState(), lc.GetItemsLength(), change) - view.FocusPoint(0, lc.GetPanelState().GetSelectedLineIdx()) + self.Gui.changeSelectedLine(self.GetPanelState(), self.GetItemsLength(), change) - return lc.HandleFocus() + return self.HandleFocus() } |