From c8243be0dfcf6055718f10383b0c4766d17306b2 Mon Sep 17 00:00:00 2001 From: egawata Date: Fri, 12 Aug 2022 13:17:23 +0900 Subject: [PATCH 01/26] fix: set eastasian width to fix broken layout --- main.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/main.go b/main.go index 3f4eeba..35da0cc 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "github.com/adrg/xdg" "github.com/fatih/color" + "github.com/mattn/go-runewidth" "github.com/rivo/tview" "github.com/spf13/viper" "github.com/tcnksm/go-latest" @@ -32,6 +33,8 @@ func printVersion() { } func main() { + runewidth.DefaultCondition.EastAsianWidth = false + v := viper.New() v.SetConfigType("toml") v.SetConfigName("viddy") From 6431f52ed352024bde235ee1ebd4ee4d69e13023 Mon Sep 17 00:00:00 2001 From: coolabhays Date: Sat, 24 Dec 2022 22:46:28 +0530 Subject: [PATCH 02/26] feat: fix & update description in help view --- viddy.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/viddy.go b/viddy.go index ca1f64e..bf34745 100644 --- a/viddy.go +++ b/viddy.go @@ -681,7 +681,7 @@ func (v *Viddy) goToOldestOnTimeMachine() { } } -var helpTemplate = `Press ESC or Q to go back +var helpTemplate = `Press ESC or q to go back [::b]Key Bindings[-:-:-] @@ -693,6 +693,7 @@ var helpTemplate = `Press ESC or Q to go back Toggle diff : [yellow]d[-:-:-] Toggle header display : [yellow]t[-:-:-] Toggle help view : [yellow]?[-:-:-] + Quit Viddy : [yellow]Q[-:-:-] [::u]Pager[-:-:-] From 9fa4c289a8f41cb3c3bb805e358aaa6b558b325a Mon Sep 17 00:00:00 2001 From: coolabhays Date: Sat, 24 Dec 2022 22:47:19 +0530 Subject: [PATCH 03/26] feat: update keybinding to quit Viddy * 'q' will quit viddy, only if it's not in help view, else it'll go back * 'Q` to exit viddy from any view --- viddy.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/viddy.go b/viddy.go index bf34745..151830c 100644 --- a/viddy.go +++ b/viddy.go @@ -553,11 +553,27 @@ func (v *Viddy) Run() error { any = true } - if event.Key() == tcell.KeyEsc || event.Rune() == 'q' { + if event.Key() == tcell.KeyEsc { v.showHelpView = false v.arrange() } + if event.Rune() == 'q' { + if (v.showHelpView) { // if it's help mode, just go back + v.showHelpView = false + v.arrange() + } else { // it's not help view, so just quit + v.app.Stop() + os.Exit(0) + } + } + + // quit viddy from any view + if event.Rune() == 'Q' { + v.app.Stop() + os.Exit(0) + } + switch event.Rune() { case 's': v.isSuspend = !v.isSuspend From 023727f421ba6d6d4adf0e2ccc62eda5156ddaab Mon Sep 17 00:00:00 2001 From: coolabhays Date: Sun, 25 Dec 2022 09:36:14 +0530 Subject: [PATCH 04/26] feat: toggle unfold with hotkey * added hotkey functionality for unfold * added key-bindings description for unfold --- viddy.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/viddy.go b/viddy.go index ca1f64e..4b86b91 100644 --- a/viddy.go +++ b/viddy.go @@ -567,6 +567,9 @@ func (v *Viddy) Run() error { v.SetIsShowDiff(!v.isShowDiff) case 't': v.SetIsNoTitle(!v.isNoTitle) + case 'u': + b.SetWrap(v.unfold) + v.unfold = !v.unfold case 'x': if v.isDebug { v.ShowLogView(!v.showLogView) @@ -693,6 +696,7 @@ var helpTemplate = `Press ESC or Q to go back Toggle diff : [yellow]d[-:-:-] Toggle header display : [yellow]t[-:-:-] Toggle help view : [yellow]?[-:-:-] + Toggle unfold : [yellow]u[-:-:-] [::u]Pager[-:-:-] From be0fb7a8050a928198afb5b86d2aa2c4b5261c0f Mon Sep 17 00:00:00 2001 From: Trevor Sullivan Date: Fri, 20 Jan 2023 13:58:55 -0700 Subject: [PATCH 05/26] =?UTF-8?q?=F0=9F=AA=9F=20Add=20Windows=20install=20?= =?UTF-8?q?steps?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index ac9b43a..3f6847c 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,20 @@ brew install viddy sudo port install viddy ``` +### Windows + +#### [Scoop](https://scoop.sh/) + +To install Viddy on Windows, first install the Scoop package manager, and then run the commands below. + +**NOTE**: The git package is required in order to add additional Scoop "buckets". + +``` +scoop install git +scoop bucket add extras +scoop install extras/viddy +``` + ### Linux ```shell From 208f69c8f68f944ffce657f69702bfad41798a48 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 23 Feb 2023 08:26:54 +0000 Subject: [PATCH 06/26] Bump golang.org/x/text from 0.3.7 to 0.3.8 Bumps [golang.org/x/text](https://github.com/golang/text) from 0.3.7 to 0.3.8. - [Release notes](https://github.com/golang/text/releases) - [Commits](https://github.com/golang/text/compare/v0.3.7...v0.3.8) --- updated-dependencies: - dependency-name: golang.org/x/text dependency-type: indirect ... Signed-off-by: dependabot[bot] --- go.mod | 6 +++--- go.sum | 17 ++++------------- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/go.mod b/go.mod index 3e98042..808ad60 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/creack/pty v1.1.15 github.com/fatih/color v1.12.0 github.com/gdamore/tcell/v2 v2.5.1 + github.com/mattn/go-runewidth v0.0.13 github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 github.com/rivo/tview v0.0.0-20220610163003-691f46d6f500 github.com/sergi/go-diff v1.2.0 @@ -30,7 +31,6 @@ require ( github.com/magiconair/properties v1.8.5 // indirect github.com/mattn/go-colorable v0.1.8 // indirect github.com/mattn/go-isatty v0.0.12 // indirect - github.com/mattn/go-runewidth v0.0.13 // indirect github.com/mitchellh/mapstructure v1.4.1 // indirect github.com/pelletier/go-toml v1.9.3 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect @@ -39,9 +39,9 @@ require ( github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/subosito/gotenv v1.2.0 // indirect golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 // indirect - golang.org/x/sys v0.0.0-20220624220833-87e55d714810 // indirect + golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect golang.org/x/term v0.0.0-20220526004731-065cf7ba2467 // indirect - golang.org/x/text v0.3.7 // indirect + golang.org/x/text v0.3.8 // indirect gopkg.in/ini.v1 v1.62.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect diff --git a/go.sum b/go.sum index 3b66119..5da7fe4 100644 --- a/go.sum +++ b/go.sum @@ -80,9 +80,6 @@ github.com/fsnotify/fsnotify v1.5.1 h1:mZcQUHVQUQWoPXXtuf9yuEXKudkV2sx1E06UadKWp github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU= github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko= github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg= -github.com/gdamore/tcell/v2 v2.4.1-0.20210904044819-ae5116d72813 h1:uqlt4EHPdtAAXKBq6OKc0auHsQP5zfhdHo/BYe6hz2Q= -github.com/gdamore/tcell/v2 v2.4.1-0.20210904044819-ae5116d72813/go.mod h1:Az6Jt+M5idSED2YPGtwnfJV0kXohgdCBPmHGSYc1r04= -github.com/gdamore/tcell/v2 v2.4.1-0.20210905002822-f057f0a857a1 h1:QqwPZCwh/k1uYqq6uXSb9TRDhTkfQbO80v8zhnIe5zM= github.com/gdamore/tcell/v2 v2.4.1-0.20210905002822-f057f0a857a1/go.mod h1:Az6Jt+M5idSED2YPGtwnfJV0kXohgdCBPmHGSYc1r04= github.com/gdamore/tcell/v2 v2.5.1 h1:zc3LPdpK184lBW7syF2a5C6MV827KmErk9jGVnmsl/I= github.com/gdamore/tcell/v2 v2.5.1/go.mod h1:wSkrPaXoiIWZqW/g7Px4xc79di6FTcpB8tvaKJ6uGBo= @@ -237,8 +234,6 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/rivo/tview v0.0.0-20211202162923-2a6de950f73b h1:EMgbQ+bOHWkl0Ptano8M0yrzVZkxans+Vfv7ox/EtO8= -github.com/rivo/tview v0.0.0-20211202162923-2a6de950f73b/go.mod h1:WIfMkQNY+oq/mWwtsjOYHIZBuwthioY2srOmljJkTnk= github.com/rivo/tview v0.0.0-20220610163003-691f46d6f500 h1:KvoRB2TMfMqK2NF2mIvZprDT/Ofvsa4RphWLoCmUDag= github.com/rivo/tview v0.0.0-20220610163003-691f46d6f500/go.mod h1:WIfMkQNY+oq/mWwtsjOYHIZBuwthioY2srOmljJkTnk= github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= @@ -246,8 +241,6 @@ github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJ github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= -github.com/sachaos/tview v0.0.0-20210909084047-7f6f0b84f61c h1:OYO8SfrdARTchNFYwtSpQf1pY7FeZRY85PuOh0akRmQ= -github.com/sachaos/tview v0.0.0-20210909084047-7f6f0b84f61c/go.mod h1:NpihEwB0BMEMry10psTJveTy9b5l3GMVwBuVpKR3Jo0= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= @@ -444,14 +437,11 @@ golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/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-20210903071746-97244b99971b h1:3Dq0eVHn0uaQJmPO+/aYPI/fRMqdrVDbu7MQcku54gg= -golang.org/x/sys v0.0.0-20210903071746-97244b99971b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220318055525-2edf467146b5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220624220833-87e55d714810 h1:rHZQSjJdAI4Xf5Qzeh2bBc5YJIkPFVM6oDtMFYmgws0= -golang.org/x/sys v0.0.0-20220624220833-87e55d714810/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d h1:SZxvLBoTP5yHO3Frd4z4vrF+DBX9vMVanchswa69toE= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20220526004731-065cf7ba2467 h1:CBpWXWQpIRjzmkkA+M7q9Fqnwd2mZr3AFqexg8YTfoM= golang.org/x/term v0.0.0-20220526004731-065cf7ba2467/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -463,8 +453,9 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -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/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY= +golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= From 24c934e3d306a7e52df32e4aeb6c0131d15b0a5d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 6 Mar 2023 23:38:32 +0000 Subject: [PATCH 07/26] Bump golang.org/x/net from 0.0.0-20210405180319-a5a99cb37ef4 to 0.7.0 Bumps [golang.org/x/net](https://github.com/golang/net) from 0.0.0-20210405180319-a5a99cb37ef4 to 0.7.0. - [Release notes](https://github.com/golang/net/releases) - [Commits](https://github.com/golang/net/commits/v0.7.0) --- updated-dependencies: - dependency-name: golang.org/x/net dependency-type: indirect ... Signed-off-by: dependabot[bot] --- go.mod | 8 ++++---- go.sum | 15 ++++++++------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index 808ad60..45a870b 100644 --- a/go.mod +++ b/go.mod @@ -38,10 +38,10 @@ require ( github.com/spf13/afero v1.6.0 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/subosito/gotenv v1.2.0 // indirect - golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 // indirect - golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect - golang.org/x/term v0.0.0-20220526004731-065cf7ba2467 // indirect - golang.org/x/text v0.3.8 // indirect + golang.org/x/net v0.7.0 // indirect + golang.org/x/sys v0.5.0 // indirect + golang.org/x/term v0.5.0 // indirect + golang.org/x/text v0.7.0 // indirect gopkg.in/ini.v1 v1.62.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect diff --git a/go.sum b/go.sum index 5da7fe4..807f8f7 100644 --- a/go.sum +++ b/go.sum @@ -367,8 +367,9 @@ golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc= -golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 h1:4nGaVu0QrbjT/AK2PRLuQfQuh6DJve+pELhqTdAj3x0= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= +golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= +golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -438,13 +439,13 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/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-20220318055525-2edf467146b5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/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= golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20220526004731-065cf7ba2467 h1:CBpWXWQpIRjzmkkA+M7q9Fqnwd2mZr3AFqexg8YTfoM= -golang.org/x/term v0.0.0-20220526004731-065cf7ba2467/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0 h1:n2a8QNdAb0sZNpU9R1ALUXBbY+w51fCQDN+7EdxNBsY= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -454,8 +455,8 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY= -golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= +golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= From 66861ce3eef69a8961d91d532f27bcb1088571c2 Mon Sep 17 00:00:00 2001 From: Kian-Meng Ang Date: Thu, 6 Apr 2023 10:42:34 +0800 Subject: [PATCH 08/26] docs: fix typo, connot -> cannot Found via `typos --format brief` --- config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.go b/config.go index b9bd356..98a44fb 100644 --- a/config.go +++ b/config.go @@ -295,7 +295,7 @@ type parseKeyStrokeError struct { } func (e parseKeyStrokeError) Error() string { - return fmt.Sprintf("connot parse key: %q", e.key) + return fmt.Sprintf("cannot parse key: %q", e.key) } // ParseKeyStroke parse string describing key. From c3f1e9b9995321b9e06f4c54ecea5aad06b56a98 Mon Sep 17 00:00:00 2001 From: ChengDaqi2023 <131479795+ChengDaqi2023@users.noreply.github.com> Date: Fri, 11 Aug 2023 09:59:27 +0800 Subject: [PATCH 09/26] update gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b to 3.0.0 --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 45a870b..9855b98 100644 --- a/go.mod +++ b/go.mod @@ -44,5 +44,5 @@ require ( golang.org/x/text v0.7.0 // indirect gopkg.in/ini.v1 v1.62.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect - gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect + gopkg.in/yaml.v3 v3.0.0 // indirect ) diff --git a/go.sum b/go.sum index 807f8f7..c940187 100644 --- a/go.sum +++ b/go.sum @@ -634,6 +634,8 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA= +gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools/v3 v3.0.2 h1:kG1BFyqVHuQoVQiR1bWGnfz/fmHvvuiSPIV7rvl360E= gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= From 7c379e5d6f6fdc735450b6571cf422b9d5dbdea9 Mon Sep 17 00:00:00 2001 From: Takumasa Sakao Date: Thu, 24 Aug 2023 18:00:44 +0900 Subject: [PATCH 10/26] Disable mouse --- viddy.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/viddy.go b/viddy.go index 0cb84d5..1480225 100644 --- a/viddy.go +++ b/viddy.go @@ -412,7 +412,7 @@ func (v *Viddy) arrange() { } // Run is entry point to run viddy. -//nolint: funlen,gocognit,cyclop +// nolint: funlen,gocognit,cyclop func (v *Viddy) Run() error { b := tview.NewTextView() b.SetDynamicColors(true) @@ -559,10 +559,10 @@ func (v *Viddy) Run() error { } if event.Rune() == 'q' { - if (v.showHelpView) { // if it's help mode, just go back + if v.showHelpView { // if it's help mode, just go back v.showHelpView = false v.arrange() - } else { // it's not help view, so just quit + } else { // it's not help view, so just quit v.app.Stop() os.Exit(0) } @@ -616,8 +616,6 @@ func (v *Viddy) Run() error { v.UpdateStatusView() - app.EnableMouse(true) - v.app = app v.arrange() From afd0067479398ec536db7ef246f65b9b617301cd Mon Sep 17 00:00:00 2001 From: Takumasa Sakao Date: Thu, 24 Aug 2023 18:33:59 +0900 Subject: [PATCH 11/26] Update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3f6847c..a2f06d3 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ scoop install extras/viddy ### Linux ```shell -wget -O viddy.tar.gz https://github.com/sachaos/viddy/releases/download/v0.3.6/viddy_0.3.6_Linux_x86_64.tar.gz && tar xvf viddy.tar.gz && mv viddy /usr/local/bin +wget -O viddy.tar.gz https://github.com/sachaos/viddy/releases/download/v0.3.7/viddy_0.3.7_Linux_x86_64.tar.gz && tar xvf viddy.tar.gz && mv viddy /usr/local/bin ``` #### ArchLinux ( AUR ) From 74ca6ef207a8158e5cfbb82122db73efd3bcab40 Mon Sep 17 00:00:00 2001 From: Takumasa Sakao Date: Thu, 24 Aug 2023 18:39:55 +0900 Subject: [PATCH 12/26] Update goreleaser config --- .goreleaser.yml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index 0dc1173..916956b 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -17,12 +17,14 @@ builds: ldflags: - -s -w -X main.version={{.Version}} archives: -- replacements: - darwin: Darwin - linux: Linux - windows: Windows - 386: i386 - amd64: x86_64 + - id: replace + name_template: >- + {{- .ProjectName }}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end -}} checksum: name_template: 'checksums.txt' snapshot: From e37f0a493509d451e2c7bc9da3cd896e31928958 Mon Sep 17 00:00:00 2001 From: Casper Date: Thu, 24 Aug 2023 12:07:54 +0200 Subject: [PATCH 13/26] Fix link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a2f06d3..9500e29 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ scoop install extras/viddy ### Linux ```shell -wget -O viddy.tar.gz https://github.com/sachaos/viddy/releases/download/v0.3.7/viddy_0.3.7_Linux_x86_64.tar.gz && tar xvf viddy.tar.gz && mv viddy /usr/local/bin +wget -O viddy.tar.gz https://github.com/sachaos/viddy/releases/download/v0.3.7/viddy_Linux_x86_64.tar.gz && tar xvf viddy.tar.gz && mv viddy /usr/local/bin ``` #### ArchLinux ( AUR ) From 5270bbfb67e2f19944462a35b17cd0f6e5b54131 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 30 Aug 2023 14:17:27 +0000 Subject: [PATCH 14/26] Bump gopkg.in/yaml.v3 from 3.0.0-20210107192922-496545a6307b to 3.0.0 Bumps gopkg.in/yaml.v3 from 3.0.0-20210107192922-496545a6307b to 3.0.0. --- updated-dependencies: - dependency-name: gopkg.in/yaml.v3 dependency-type: indirect ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 45a870b..9855b98 100644 --- a/go.mod +++ b/go.mod @@ -44,5 +44,5 @@ require ( golang.org/x/text v0.7.0 // indirect gopkg.in/ini.v1 v1.62.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect - gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect + gopkg.in/yaml.v3 v3.0.0 // indirect ) diff --git a/go.sum b/go.sum index 807f8f7..f91ec0f 100644 --- a/go.sum +++ b/go.sum @@ -632,8 +632,9 @@ gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA= +gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools/v3 v3.0.2 h1:kG1BFyqVHuQoVQiR1bWGnfz/fmHvvuiSPIV7rvl360E= gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= From c59e27eab4853292898cc02c4ae8c7a033af1f04 Mon Sep 17 00:00:00 2001 From: NikolayXHD Date: Fri, 1 Sep 2023 16:56:07 +0300 Subject: [PATCH 15/26] diff: alter foreground color as well to keep readable contrast between bg and fg --- snapshot.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snapshot.go b/snapshot.go index ed49e1b..9e5ccc5 100644 --- a/snapshot.go +++ b/snapshot.go @@ -168,7 +168,7 @@ func DiffPrettyText(diffs []diffmatchpatch.Diff) string { if unicode.IsSpace(c) { _, _ = buff.WriteRune(c) } else { - _, _ = buff.WriteString(color.New(color.BgGreen).Sprintf(string(c))) + _, _ = buff.WriteString(color.New(color.FgBlack).Sprintf(color.New(color.BgGreen).Sprintf(string(c)))) } } case diffmatchpatch.DiffEqual: From cf91ff68d95d5521d385d06d5a62c5c7f1915fd1 Mon Sep 17 00:00:00 2001 From: Vamsi Avula Date: Mon, 11 Sep 2023 14:14:00 +0530 Subject: [PATCH 16/26] $ go fmt --- snapshot.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/snapshot.go b/snapshot.go index 9e5ccc5..f645a4d 100644 --- a/snapshot.go +++ b/snapshot.go @@ -47,8 +47,9 @@ type Snapshot struct { finish chan<- struct{} } -//nolint:lll // NewSnapshot returns Snapshot object. +// +//nolint:lll func NewSnapshot(id int64, command string, args []string, shell string, shellOpts string, before *Snapshot, finish chan<- struct{}) *Snapshot { return &Snapshot{ id: id, From d287f8df9e34bb6a826daccd4b5cac91b0aa5c5b Mon Sep 17 00:00:00 2001 From: Vamsi Avula Date: Mon, 11 Sep 2023 11:16:37 +0530 Subject: [PATCH 17/26] cleanup: refactor goToRow functionality into its own method --- viddy.go | 71 ++++++++++++++++++-------------------------------------- 1 file changed, 22 insertions(+), 49 deletions(-) diff --git a/viddy.go b/viddy.go index 1480225..1adae4c 100644 --- a/viddy.go +++ b/viddy.go @@ -628,81 +628,54 @@ func (v *Viddy) Run() error { return app.Run() } +func (v *Viddy) goToRow(row int) { + if row < 0 { + row = 0 + } else if count := v.historyView.GetRowCount(); row >= count { + row = count - 1 + } + var ( + cell = v.historyView.GetCell(row, 0) + id, err = strconv.ParseInt(cell.Text, 10, 64) + ) + if err == nil { // if _no_ error + v.setSelection(id) + } +} + func (v *Viddy) goToPastOnTimeMachine() { - count := v.historyView.GetRowCount() selection, _ := v.historyView.GetSelection() - - if selection+1 < count { - cell := v.historyView.GetCell(selection+1, 0) - if id, err := strconv.ParseInt(cell.Text, 10, 64); err == nil { - v.setSelection(id) - } - } + v.goToRow(selection + 1) } func (v *Viddy) goToFutureOnTimeMachine() { selection, _ := v.historyView.GetSelection() - if 0 <= selection-1 { - cell := v.historyView.GetCell(selection-1, 0) - if id, err := strconv.ParseInt(cell.Text, 10, 64); err == nil { - v.setSelection(id) - } - } + v.goToRow(selection - 1) } func (v *Viddy) goToMorePastOnTimeMachine() { - count := v.historyView.GetRowCount() selection, _ := v.historyView.GetSelection() - - if selection+10 < count { - cell := v.historyView.GetCell(selection+10, 0) - if id, err := strconv.ParseInt(cell.Text, 10, 64); err == nil { - v.setSelection(id) - } - } else { - cell := v.historyView.GetCell(count-1, 0) - if id, err := strconv.ParseInt(cell.Text, 10, 64); err == nil { - v.setSelection(id) - } - } + v.goToRow(selection + 10) } func (v *Viddy) goToMoreFutureOnTimeMachine() { selection, _ := v.historyView.GetSelection() - if 0 <= selection-10 { - cell := v.historyView.GetCell(selection-10, 0) - if id, err := strconv.ParseInt(cell.Text, 10, 64); err == nil { - v.setSelection(id) - } - } else { - cell := v.historyView.GetCell(0, 0) - if id, err := strconv.ParseInt(cell.Text, 10, 64); err == nil { - v.setSelection(id) - } - } + v.goToRow(selection - 10) } func (v *Viddy) goToNowOnTimeMachine() { - cell := v.historyView.GetCell(0, 0) - if id, err := strconv.ParseInt(cell.Text, 10, 64); err == nil { - v.setSelection(id) - } + v.goToRow(0) } func (v *Viddy) goToOldestOnTimeMachine() { - count := v.historyView.GetRowCount() - cell := v.historyView.GetCell(count-1, 0) - - if id, err := strconv.ParseInt(cell.Text, 10, 64); err == nil { - v.setSelection(id) - } + v.goToRow(v.historyView.GetRowCount() - 1) } var helpTemplate = `Press ESC or q to go back [::b]Key Bindings[-:-:-] - [::u]General[-:-:-] + [::u]General[-:-:-] Toggle time machine mode : [yellow]SPACE[-:-:-] Toggle suspend execution : [yellow]s[-:-:-] From dcf49c8cce25dba11b108bc74a7d205c5b46e334 Mon Sep 17 00:00:00 2001 From: Vamsi Avula Date: Mon, 11 Sep 2023 11:16:37 +0530 Subject: [PATCH 18/26] cleanup: make setSelection more efficient by hinting row --- viddy.go | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/viddy.go b/viddy.go index 1adae4c..576b1f8 100644 --- a/viddy.go +++ b/viddy.go @@ -153,14 +153,14 @@ func (v *Viddy) SetIsNoTitle(b bool) { func (v *Viddy) SetIsShowDiff(b bool) { v.isShowDiff = b - v.setSelection(v.currentID) + v.setSelection(v.currentID, -1) v.arrange() } func (v *Viddy) SetIsTimeMachine(b bool) { v.isTimeMachine = b if !v.isTimeMachine { - v.setSelection(v.latestFinishedID) + v.setSelection(v.latestFinishedID, -1) } v.arrange() @@ -250,9 +250,9 @@ func (v *Viddy) queueHandler() { if ls == nil || s.start.After(ls.start) { v.latestFinishedID = id if !v.isTimeMachine { - v.setSelection(id) + v.setSelection(id, -1) } else { - v.setSelection(v.currentID) + v.setSelection(v.currentID, -1) } } case id := <-v.queue: @@ -284,16 +284,19 @@ func (v *Viddy) queueHandler() { v.Unlock() if !v.isTimeMachine { - v.setSelection(v.latestFinishedID) + v.setSelection(v.latestFinishedID, -1) } else { - v.setSelection(v.currentID) + v.setSelection(v.currentID, -1) } } }() } } -func (v *Viddy) setSelection(id int64) { +// setSelection selects the given row in the history view. If row is -1, it will +// attempt to select the row corresponding to the given id (or default to the +// latest row if id doesn't exist). +func (v *Viddy) setSelection(id int64, row int) { if id == -1 { return } @@ -305,14 +308,16 @@ func (v *Viddy) setSelection(id int64) { v.historyView.SetSelectable(true, false) } - v.RLock() - index := sort.Search(len(v.idList), func(i int) bool { - return v.idList[i] >= id - }) - i := len(v.idList) - index - 1 - v.RUnlock() + if row == -1 { + v.RLock() + index := sort.Search(len(v.idList), func(i int) bool { + return v.idList[i] >= id + }) + row = len(v.idList) - index - 1 + v.RUnlock() + } - v.historyView.Select(i, 0) + v.historyView.Select(row, 0) v.currentID = id unix := v.begin + id*int64(time.Millisecond) v.timeView.SetText(time.Unix(unix/int64(time.Second), unix%int64(time.Second)).String()) @@ -639,7 +644,7 @@ func (v *Viddy) goToRow(row int) { id, err = strconv.ParseInt(cell.Text, 10, 64) ) if err == nil { // if _no_ error - v.setSelection(id) + v.setSelection(id, row) } } From 106e52d8f0ff8ce8e25dd97c2f65670289cec81a Mon Sep 17 00:00:00 2001 From: Vamsi Avula Date: Mon, 11 Sep 2023 11:16:37 +0530 Subject: [PATCH 19/26] history: skip snapshots with no changes (+0 -0) This is controlled by the flag --skip-empty-diffs (defaulting to existing behaviour of showing everything). --- config.go | 23 ++++++++----- main.go | 1 + viddy.go | 101 ++++++++++++++++++++++++++++++++++-------------------- 3 files changed, 79 insertions(+), 46 deletions(-) diff --git a/config.go b/config.go index 98a44fb..5b9775f 100644 --- a/config.go +++ b/config.go @@ -38,14 +38,15 @@ type runtimeConfig struct { } type general struct { - shell string - shellOptions string - debug bool - bell bool - differences bool - noTitle bool - pty bool - unfold bool + shell string + shellOptions string + debug bool + bell bool + differences bool + skipEmptyDiffs bool + noTitle bool + pty bool + unfold bool } type theme struct { @@ -87,6 +88,7 @@ func newConfig(v *viper.Viper, args []string) (*config, error) { // general flagSet.BoolP("bell", "b", false, "ring terminal bell changes between updates") flagSet.BoolP("differences", "d", false, "highlight changes between updates") + flagSet.BoolP("skip-empty-diffs", "s", false, "skip snapshots with no changes (+0 -0) in history") flagSet.BoolP("no-title", "t", false, "turn off header") flagSet.Bool("debug", false, "") flagSet.String("shell", "", "shell (default \"sh\")") @@ -148,6 +150,10 @@ func newConfig(v *viper.Viper, args []string) (*config, error) { return nil, err } + if err := v.BindPFlag("general.skip_empty_diffs", flagSet.Lookup("skip-empty-diffs")); err != nil { + return nil, err + } + if err := v.BindPFlag("general.no_title", flagSet.Lookup("no-title")); err != nil { return nil, err } @@ -165,6 +171,7 @@ func newConfig(v *viper.Viper, args []string) (*config, error) { conf.general.shellOptions = v.GetString("general.shell_options") conf.general.bell, _ = flagSet.GetBool("bell") conf.general.differences, _ = flagSet.GetBool("differences") + conf.general.skipEmptyDiffs, _ = flagSet.GetBool("skip-empty-diffs") conf.general.noTitle, _ = flagSet.GetBool("no-title") conf.general.unfold = v.GetBool("general.unfold") conf.general.pty = v.GetBool("general.pty") diff --git a/main.go b/main.go index 35da0cc..b75fbfd 100644 --- a/main.go +++ b/main.go @@ -77,6 +77,7 @@ Usage: Options: -b, --bell ring terminal bell changes between updates -d, --differences highlight changes between updates + -s, --skip-empty-diffs skip snapshots with no changes (+0 -0) in history -n, --interval seconds to wait between updates (default "2s") -p, --precise attempt run command in precise intervals -c, --clockwork run command in precise intervals forcibly diff --git a/viddy.go b/viddy.go index 576b1f8..521bdbf 100644 --- a/viddy.go +++ b/viddy.go @@ -7,7 +7,6 @@ import ( "html/template" "io" "os" - "sort" "strconv" "strings" "sync" @@ -43,12 +42,12 @@ type Viddy struct { timeView *tview.TextView historyView *tview.Table historyRows map[int64]*HistoryRow - sync.RWMutex // bWidth store current pty width. bWidth atomic.Value - idList []int64 + // id -> row count (as of just after the snapshot was added). + historyRowCount map[int64]int bodyView *tview.TextView app *tview.Application @@ -69,6 +68,7 @@ type Viddy struct { isNoTitle bool isRingBell bool isShowDiff bool + skipEmptyDiffs bool isEditQuery bool unfold bool pty bool @@ -124,17 +124,20 @@ func NewViddy(conf *config) *Viddy { snapshots: sync.Map{}, historyRows: map[int64]*HistoryRow{}, + historyRowCount: map[int64]int{}, + snapshotQueue: snapshotQueue, queue: make(chan int64), finishedQueue: make(chan int64), diffQueue: make(chan int64, 100), - isRingBell: conf.general.bell, - isShowDiff: conf.general.differences, - isNoTitle: conf.general.noTitle, - isDebug: conf.general.debug, - unfold: conf.general.unfold, - pty: conf.general.pty, + isRingBell: conf.general.bell, + isShowDiff: conf.general.differences, + skipEmptyDiffs: conf.general.skipEmptyDiffs, + isNoTitle: conf.general.noTitle, + isDebug: conf.general.debug, + unfold: conf.general.unfold, + pty: conf.general.pty, currentID: -1, latestFinishedID: -1, @@ -183,6 +186,26 @@ func (v *Viddy) startRunner() { } } +func (v *Viddy) updateSelection() { + if !v.isTimeMachine { + v.setSelection(v.latestFinishedID, -1) + } else { + v.setSelection(v.currentID, -1) + } +} + +func (v *Viddy) addSnapshotToView(id int64, r *HistoryRow) { + v.historyView.InsertRow(0) + v.historyView.SetCell(0, 0, r.id) + v.historyView.SetCell(0, 1, r.addition) + v.historyView.SetCell(0, 2, r.deletion) + v.historyView.SetCell(0, 3, r.exitCode) + + v.historyRowCount[id] = v.historyView.GetRowCount() + + v.updateSelection() +} + func (v *Viddy) diffQueueHandler() { for { func() { @@ -203,10 +226,12 @@ func (v *Viddy) diffQueueHandler() { return } - if v.isRingBell { - if s.diffAdditionCount > 0 || s.diffDeletionCount > 0 { + if s.diffAdditionCount > 0 || s.diffDeletionCount > 0 { + if v.isRingBell { fmt.Print(string(byte(7))) } + } else if v.skipEmptyDiffs { + return } r, ok := v.historyRows[id] @@ -214,6 +239,11 @@ func (v *Viddy) diffQueueHandler() { return } + // if skipEmptyDiffs is true, queueHandler wouldn't have added the + // snapshot to view, so we need to add it here. + if v.skipEmptyDiffs { + v.addSnapshotToView(id, r) + } r.addition.SetText("+" + strconv.Itoa(s.diffAdditionCount)) r.deletion.SetText("-" + strconv.Itoa(s.diffDeletionCount)) }() @@ -249,11 +279,7 @@ func (v *Viddy) queueHandler() { ls := v.getSnapShot(v.latestFinishedID) if ls == nil || s.start.After(ls.start) { v.latestFinishedID = id - if !v.isTimeMachine { - v.setSelection(id, -1) - } else { - v.setSelection(v.currentID, -1) - } + v.updateSelection() } case id := <-v.queue: if v.isSuspend { @@ -266,27 +292,31 @@ func (v *Viddy) queueHandler() { deletionCell := tview.NewTableCell("").SetTextColor(tcell.ColorRed) exitCodeCell := tview.NewTableCell("").SetTextColor(tcell.ColorYellow) - v.historyRows[s.id] = &HistoryRow{ + r := &HistoryRow{ id: idCell, addition: additionCell, deletion: deletionCell, exitCode: exitCodeCell, } - - v.historyView.InsertRow(0) - v.historyView.SetCell(0, 0, idCell) - v.historyView.SetCell(0, 1, additionCell) - v.historyView.SetCell(0, 2, deletionCell) - v.historyView.SetCell(0, 3, exitCodeCell) - - v.Lock() - v.idList = append(v.idList, id) - v.Unlock() - - if !v.isTimeMachine { - v.setSelection(v.latestFinishedID, -1) - } else { - v.setSelection(v.currentID, -1) + v.historyRows[s.id] = r + + // if skipEmptyDiffs is true, we need to check if the snapshot + // is empty before adding it to the view (in diffQueueHandler). + // + // This means we're trading off two things: + // + // 1. We're not showing the snapshot in history view until the + // command finishes running, which means it's not possible + // to see partial output. + // 2. Order of the snapshots in history view is lost + // (in non-sequential modes), as some commands could finish + // running quicker than others for whatever reason. + // + // It of course is possible to address these issues by adding + // all snapshots to the history view and then removing the empty + // ones but it unnecessarily complicates the implementation. + if !v.skipEmptyDiffs { + v.addSnapshotToView(id, r) } } }() @@ -309,12 +339,7 @@ func (v *Viddy) setSelection(id int64, row int) { } if row == -1 { - v.RLock() - index := sort.Search(len(v.idList), func(i int) bool { - return v.idList[i] >= id - }) - row = len(v.idList) - index - 1 - v.RUnlock() + row = v.historyView.GetRowCount() - v.historyRowCount[id] } v.historyView.Select(row, 0) From 4c07af3229abe1dfb9393f867cae3cea2ec99897 Mon Sep 17 00:00:00 2001 From: Takumasa Sakao Date: Sun, 15 Oct 2023 10:53:14 +0900 Subject: [PATCH 20/26] Fix lint error --- .github/workflows/lint.yml | 2 +- .golang-ci.yml | 10 ++++++++++ viddy.go | 8 ++++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index c875707..a6c2cf3 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -16,6 +16,6 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v2 with: - version: v1.46.2 + version: v1.51.2 args: -c .golang-ci.yml diff --git a/.golang-ci.yml b/.golang-ci.yml index 0668433..283529f 100644 --- a/.golang-ci.yml +++ b/.golang-ci.yml @@ -19,3 +19,13 @@ linters: - predeclared - nilnil - varnamelen + - nosnakecase + - varcheck + - interfacer + - structcheck + - golint + - scopelint + - deadcode + - ifshort + - rowserrcheck + - wastedassign diff --git a/viddy.go b/viddy.go index 521bdbf..c2abd99 100644 --- a/viddy.go +++ b/viddy.go @@ -244,13 +244,14 @@ func (v *Viddy) diffQueueHandler() { if v.skipEmptyDiffs { v.addSnapshotToView(id, r) } + r.addition.SetText("+" + strconv.Itoa(s.diffAdditionCount)) r.deletion.SetText("-" + strconv.Itoa(s.diffDeletionCount)) }() } } -//nolint:funlen,gocognit,cyclop +//nolint:funlen,cyclop func (v *Viddy) queueHandler() { for { func() { @@ -442,7 +443,8 @@ func (v *Viddy) arrange() { } // Run is entry point to run viddy. -// nolint: funlen,gocognit,cyclop +// +//nolint:funlen,gocognit,cyclop,gocyclo,maintidx func (v *Viddy) Run() error { b := tview.NewTextView() b.SetDynamicColors(true) @@ -664,10 +666,12 @@ func (v *Viddy) goToRow(row int) { } else if count := v.historyView.GetRowCount(); row >= count { row = count - 1 } + var ( cell = v.historyView.GetCell(row, 0) id, err = strconv.ParseInt(cell.Text, 10, 64) ) + if err == nil { // if _no_ error v.setSelection(id, row) } From db8cd5f25ae46b76ecfd5b77cc1e1628011b417f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 15 Oct 2023 01:56:51 +0000 Subject: [PATCH 21/26] Bump golang.org/x/net from 0.7.0 to 0.17.0 Bumps [golang.org/x/net](https://github.com/golang/net) from 0.7.0 to 0.17.0. - [Commits](https://github.com/golang/net/compare/v0.7.0...v0.17.0) --- updated-dependencies: - dependency-name: golang.org/x/net dependency-type: indirect ... Signed-off-by: dependabot[bot] --- go.mod | 8 ++++---- go.sum | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 9855b98..ac93456 100644 --- a/go.mod +++ b/go.mod @@ -38,10 +38,10 @@ require ( github.com/spf13/afero v1.6.0 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/subosito/gotenv v1.2.0 // indirect - golang.org/x/net v0.7.0 // indirect - golang.org/x/sys v0.5.0 // indirect - golang.org/x/term v0.5.0 // indirect - golang.org/x/text v0.7.0 // indirect + golang.org/x/net v0.17.0 // indirect + golang.org/x/sys v0.13.0 // indirect + golang.org/x/term v0.13.0 // indirect + golang.org/x/text v0.13.0 // indirect gopkg.in/ini.v1 v1.62.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.0 // indirect diff --git a/go.sum b/go.sum index f91ec0f..7b019c9 100644 --- a/go.sum +++ b/go.sum @@ -368,8 +368,8 @@ golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= -golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -439,13 +439,13 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/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-20220318055525-2edf467146b5/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/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.5.0 h1:n2a8QNdAb0sZNpU9R1ALUXBbY+w51fCQDN+7EdxNBsY= -golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek= +golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -455,8 +455,8 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= -golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= From ddbd82b6b0db44feeb474d3feda10b42d601f5c1 Mon Sep 17 00:00:00 2001 From: Takumasa Sakao Date: Sun, 15 Oct 2023 14:11:29 +0900 Subject: [PATCH 22/26] Fix bug of switching time machine --- viddy.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/viddy.go b/viddy.go index c2abd99..59f73de 100644 --- a/viddy.go +++ b/viddy.go @@ -164,6 +164,8 @@ func (v *Viddy) SetIsTimeMachine(b bool) { v.isTimeMachine = b if !v.isTimeMachine { v.setSelection(v.latestFinishedID, -1) + } else { + v.goToNowOnTimeMachine() } v.arrange() From e676badc07a01d82e76b9b168354035e35c2642c Mon Sep 17 00:00:00 2001 From: Takumasa Sakao Date: Sun, 15 Oct 2023 15:43:18 +0900 Subject: [PATCH 23/26] Do not execute command when suspended --- generator.go | 49 +++++++++++++++++++++++++++++++++++++++++++------ viddy.go | 36 +++++++++++++++++++----------------- 2 files changed, 62 insertions(+), 23 deletions(-) diff --git a/generator.go b/generator.go index 62c65cb..f3fa845 100644 --- a/generator.go +++ b/generator.go @@ -4,8 +4,10 @@ import "time" type newSnapFunc func(int64, *Snapshot, chan<- struct{}) *Snapshot -func ClockSnapshot(begin int64, newSnap newSnapFunc, interval time.Duration) <-chan *Snapshot { +func ClockSnapshot(begin int64, newSnap newSnapFunc, interval time.Duration) (<-chan *Snapshot, chan<- bool) { c := make(chan *Snapshot) + isSuspended := false + isSuspendedQueue := make(chan bool) go func() { var s *Snapshot @@ -13,6 +15,15 @@ func ClockSnapshot(begin int64, newSnap newSnapFunc, interval time.Duration) <-c t := time.Tick(interval) for now := range t { + select { + case isSuspended = <-isSuspendedQueue: + default: + } + + if isSuspended { + continue + } + finish := make(chan struct{}) id := (now.UnixNano() - begin) / int64(time.Millisecond) s = newSnap(id, s, finish) @@ -20,11 +31,13 @@ func ClockSnapshot(begin int64, newSnap newSnapFunc, interval time.Duration) <-c } }() - return c + return c, isSuspendedQueue } -func PreciseSnapshot(newSnap newSnapFunc, interval time.Duration) <-chan *Snapshot { +func PreciseSnapshot(newSnap newSnapFunc, interval time.Duration) (<-chan *Snapshot, chan<- bool) { c := make(chan *Snapshot) + isSuspended := false + isSuspendedQueue := make(chan bool) go func() { var s *Snapshot @@ -32,6 +45,17 @@ func PreciseSnapshot(newSnap newSnapFunc, interval time.Duration) <-chan *Snapsh begin := time.Now().UnixNano() for { + select { + case isSuspended = <-isSuspendedQueue: + default: + } + + if isSuspended { + time.Sleep(interval) + + continue + } + finish := make(chan struct{}) start := time.Now() id := (start.UnixNano() - begin) / int64(time.Millisecond) @@ -52,11 +76,13 @@ func PreciseSnapshot(newSnap newSnapFunc, interval time.Duration) <-chan *Snapsh } }() - return c + return c, isSuspendedQueue } -func SequentialSnapshot(newSnap newSnapFunc, interval time.Duration) <-chan *Snapshot { +func SequentialSnapshot(newSnap newSnapFunc, interval time.Duration) (<-chan *Snapshot, chan<- bool) { c := make(chan *Snapshot) + isSuspended := false + isSuspendedQueue := make(chan bool) go func() { var s *Snapshot @@ -64,6 +90,17 @@ func SequentialSnapshot(newSnap newSnapFunc, interval time.Duration) <-chan *Sna begin := time.Now().UnixNano() for { + select { + case isSuspended = <-isSuspendedQueue: + default: + } + + if isSuspended { + time.Sleep(interval) + + continue + } + finish := make(chan struct{}) id := (time.Now().UnixNano() - begin) / int64(time.Millisecond) s = newSnap(id, s, finish) @@ -75,5 +112,5 @@ func SequentialSnapshot(newSnap newSnapFunc, interval time.Duration) <-chan *Sna } }() - return c + return c, isSuspendedQueue } diff --git a/viddy.go b/viddy.go index 59f73de..42e063a 100644 --- a/viddy.go +++ b/viddy.go @@ -56,10 +56,11 @@ type Viddy struct { statusView *tview.TextView queryEditor *tview.InputField - snapshotQueue <-chan *Snapshot - queue chan int64 - finishedQueue chan int64 - diffQueue chan int64 + snapshotQueue <-chan *Snapshot + isSuspendedQueue chan<- bool + queue chan int64 + finishedQueue chan int64 + diffQueue chan int64 currentID int64 latestFinishedID int64 @@ -103,15 +104,18 @@ func NewViddy(conf *config) *Viddy { return NewSnapshot(id, conf.runtime.cmd, conf.runtime.args, conf.general.shell, conf.general.shellOptions, before, finish) } - var snapshotQueue <-chan *Snapshot + var ( + snapshotQueue <-chan *Snapshot + isSuspendedQueue chan<- bool + ) switch conf.runtime.mode { case ViddyIntervalModeClockwork: - snapshotQueue = ClockSnapshot(begin, newSnap, conf.runtime.interval) + snapshotQueue, isSuspendedQueue = ClockSnapshot(begin, newSnap, conf.runtime.interval) case ViddyIntervalModeSequential: - snapshotQueue = SequentialSnapshot(newSnap, conf.runtime.interval) + snapshotQueue, isSuspendedQueue = SequentialSnapshot(newSnap, conf.runtime.interval) case ViddyIntervalModePrecise: - snapshotQueue = PreciseSnapshot(newSnap, conf.runtime.interval) + snapshotQueue, isSuspendedQueue = PreciseSnapshot(newSnap, conf.runtime.interval) } return &Viddy{ @@ -126,10 +130,11 @@ func NewViddy(conf *config) *Viddy { historyRowCount: map[int64]int{}, - snapshotQueue: snapshotQueue, - queue: make(chan int64), - finishedQueue: make(chan int64), - diffQueue: make(chan int64, 100), + snapshotQueue: snapshotQueue, + isSuspendedQueue: isSuspendedQueue, + queue: make(chan int64), + finishedQueue: make(chan int64), + diffQueue: make(chan int64, 100), isRingBell: conf.general.bell, isShowDiff: conf.general.differences, @@ -253,7 +258,7 @@ func (v *Viddy) diffQueueHandler() { } } -//nolint:funlen,cyclop +//nolint:funlen func (v *Viddy) queueHandler() { for { func() { @@ -285,10 +290,6 @@ func (v *Viddy) queueHandler() { v.updateSelection() } case id := <-v.queue: - if v.isSuspend { - return - } - s := v.getSnapShot(id) idCell := tview.NewTableCell(strconv.FormatInt(s.id, 10)).SetTextColor(tview.Styles.SecondaryTextColor) additionCell := tview.NewTableCell("").SetTextColor(tcell.ColorGreen) @@ -611,6 +612,7 @@ func (v *Viddy) Run() error { switch event.Rune() { case 's': v.isSuspend = !v.isSuspend + v.isSuspendedQueue <- v.isSuspend case 'b': v.isRingBell = !v.isRingBell case 'd': From 2293a2301995ca28b7c69c0cf39de7ee0bb73efd Mon Sep 17 00:00:00 2001 From: Takumasa Sakao Date: Sun, 15 Oct 2023 16:23:26 +0900 Subject: [PATCH 24/26] Add --no-shell option --- README.md | 1 + config.go | 7 +++++++ snapshot.go | 27 ++++++++++++++++----------- viddy.go | 11 ++++++++++- 4 files changed, 34 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 9500e29..fcacccd 100644 --- a/README.md +++ b/README.md @@ -134,6 +134,7 @@ On macOS, the path is `~/Library/Application\ Support/viddy.toml`. ```toml [general] +no_shell = false shell = "zsh" shell_options = "" diff --git a/config.go b/config.go index 5b9775f..2cc0325 100644 --- a/config.go +++ b/config.go @@ -38,6 +38,7 @@ type runtimeConfig struct { } type general struct { + noShell bool shell string shellOptions string debug bool @@ -91,6 +92,7 @@ func newConfig(v *viper.Viper, args []string) (*config, error) { flagSet.BoolP("skip-empty-diffs", "s", false, "skip snapshots with no changes (+0 -0) in history") flagSet.BoolP("no-title", "t", false, "turn off header") flagSet.Bool("debug", false, "") + flagSet.Bool("no-shell", false, "do not use a shell even if --shell is set") flagSet.String("shell", "", "shell (default \"sh\")") flagSet.String("shell-options", "", "additional shell options") flagSet.Bool("unfold", false, "unfold") @@ -132,6 +134,10 @@ func newConfig(v *viper.Viper, args []string) (*config, error) { return nil, err } + if err := v.BindPFlag("general.no_shell", flagSet.Lookup("no-shell")); err != nil { + return nil, err + } + if err := v.BindPFlag("general.shell", flagSet.Lookup("shell")); err != nil { return nil, err } @@ -167,6 +173,7 @@ func newConfig(v *viper.Viper, args []string) (*config, error) { } conf.general.debug = v.GetBool("general.debug") + conf.general.noShell = v.GetBool("general.no_shell") conf.general.shell = v.GetString("general.shell") conf.general.shellOptions = v.GetString("general.shell_options") conf.general.bell, _ = flagSet.GetBool("bell") diff --git a/snapshot.go b/snapshot.go index f645a4d..45438be 100644 --- a/snapshot.go +++ b/snapshot.go @@ -24,6 +24,7 @@ type Snapshot struct { command string args []string + noShell bool shell string shellOpts string @@ -50,12 +51,13 @@ type Snapshot struct { // NewSnapshot returns Snapshot object. // //nolint:lll -func NewSnapshot(id int64, command string, args []string, shell string, shellOpts string, before *Snapshot, finish chan<- struct{}) *Snapshot { +func NewSnapshot(id int64, command string, args []string, noShell bool, shell string, shellOpts string, before *Snapshot, finish chan<- struct{}) *Snapshot { return &Snapshot{ id: id, command: command, args: args, + noShell: noShell, shell: shell, shellOpts: shellOpts, @@ -97,22 +99,25 @@ func (s *Snapshot) compareFromBefore() error { return nil } +//nolint:gosec func (s *Snapshot) prepareCommand(commands []string) *exec.Cmd { - var command *exec.Cmd - if runtime.GOOS == "windows" { cmdStr := strings.Join(commands, " ") compSec := os.Getenv("COMSPEC") - command = exec.Command(compSec, "/c", cmdStr) - } else { - var args []string - args = append(args, strings.Fields(s.shellOpts)...) - args = append(args, "-c") - args = append(args, strings.Join(commands, " ")) - command = exec.Command(s.shell, args...) //nolint:gosec + + return exec.Command(compSec, "/c", cmdStr) } - return command + if s.noShell { + return exec.Command(commands[0], commands[1:]...) + } + + var args []string + args = append(args, strings.Fields(s.shellOpts)...) + args = append(args, "-c") + args = append(args, strings.Join(commands, " ")) + + return exec.Command(s.shell, args...) } func isWhiteString(str string) bool { diff --git a/viddy.go b/viddy.go index 42e063a..f659dbf 100644 --- a/viddy.go +++ b/viddy.go @@ -101,7 +101,16 @@ func NewViddy(conf *config) *Viddy { begin := time.Now().UnixNano() newSnap := func(id int64, before *Snapshot, finish chan<- struct{}) *Snapshot { - return NewSnapshot(id, conf.runtime.cmd, conf.runtime.args, conf.general.shell, conf.general.shellOptions, before, finish) + return NewSnapshot( + id, + conf.runtime.cmd, + conf.runtime.args, + conf.general.noShell, + conf.general.shell, + conf.general.shellOptions, + before, + finish, + ) } var ( From a242d49adf668cb9ff2833c5b4cbc965db096904 Mon Sep 17 00:00:00 2001 From: Takumasa Sakao Date: Sun, 15 Oct 2023 16:35:58 +0900 Subject: [PATCH 25/26] Update viddy to v0.4.0 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fcacccd..5603507 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ scoop install extras/viddy ### Linux ```shell -wget -O viddy.tar.gz https://github.com/sachaos/viddy/releases/download/v0.3.7/viddy_Linux_x86_64.tar.gz && tar xvf viddy.tar.gz && mv viddy /usr/local/bin +wget -O viddy.tar.gz https://github.com/sachaos/viddy/releases/download/v0.4.0/viddy_Linux_x86_64.tar.gz && tar xvf viddy.tar.gz && mv viddy /usr/local/bin ``` #### ArchLinux ( AUR ) From cb3896a16b1319128c429e21350756e34b5a694d Mon Sep 17 00:00:00 2001 From: Bengt Brodersen Date: Sat, 30 Mar 2024 09:31:16 +0100 Subject: [PATCH 26/26] Minor README.md improvements --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5603507..19aac75 100644 --- a/README.md +++ b/README.md @@ -108,10 +108,10 @@ Download from [release page](https://github.com/sachaos/viddy/releases). | key | | |-----------|--------------------------------------------| | SPACE | Toggle time machine mode | -| s | Toggle suspend execution | -| b | Toggle ring terminal bell | -| d | Toggle diff | -| t | Toggle header display | +| s | Toggle suspend execution | +| b | Toggle ring terminal bell | +| d | Toggle diff | +| t | Toggle header/title display | | ? | Toggle help view | | / | Search text | | j | Pager: next line |