Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add --max-history option #39

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type general struct {
noTitle bool
pty bool
unfold bool
maxHistory int
}

type theme struct {
Expand Down Expand Up @@ -86,6 +87,7 @@ func newConfig(v *viper.Viper, args []string) (*config, error) {
flagSet.String("shell", "", "shell (default \"sh\")")
flagSet.String("shell-options", "", "additional shell options")
flagSet.Bool("unfold", false, "unfold")
flagSet.Int("max-history", 1000, "maximum history length (experimental)")
flagSet.Bool("pty", false, "run on pty (experimental)")

flagSet.SetInterspersed(false)
Expand Down Expand Up @@ -151,14 +153,19 @@ func newConfig(v *viper.Viper, args []string) (*config, error) {
return nil, err
}

if err := v.BindPFlag("general.max_history", flagSet.Lookup("max-history")); err != nil {
return nil, err
}

conf.general.debug = v.GetBool("general.debug")
conf.general.shell = v.GetString("general.shell")
conf.general.shellOptions = v.GetString("general.shell_options")
conf.general.bell, _ = flagSet.GetBool("bell")
conf.general.differences, _ = flagSet.GetBool("differences")
conf.general.noTitle, _ = flagSet.GetBool("no-title")
conf.general.bell = v.GetBool("general.bell")
conf.general.differences = v.GetBool("general.differences")
conf.general.noTitle = v.GetBool("general.no_title")
conf.general.unfold = v.GetBool("general.unfold")
conf.general.pty = v.GetBool("general.pty")
conf.general.maxHistory = v.GetInt("general.max_history")

v.SetDefault("color.border", "gray")
v.SetDefault("color.title", "gray")
Expand Down
1 change: 1 addition & 0 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func Test_newConfig(t *testing.T) {
differences: false,
noTitle: false,
debug: false,
maxHistory: 1000,
},
theme: theme{
Theme: tview.Theme{
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Options:
--shell-options additional shell options
--unfold unfold command result
--pty run on pty (experimental, not for Windows)
--max-history max history length, 0 is infinite (experimental, default "1000")

-h, --help display this help and exit
-v, --version output version information and exit`)
Expand Down
1 change: 1 addition & 0 deletions run.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !windows
// +build !windows

package main
Expand Down
1 change: 1 addition & 0 deletions run_windows.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build windows
// +build windows

package main
Expand Down
15 changes: 15 additions & 0 deletions viddy.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type Viddy struct {
isEditQuery bool
unfold bool
pty bool
maxHistory int

query string

Expand Down Expand Up @@ -124,6 +125,7 @@ func NewViddy(conf *config) *Viddy {
finishedQueue: make(chan int64),
diffQueue: make(chan int64, 100),

maxHistory: conf.general.maxHistory,
isRingBell: conf.general.bell,
isShowDiff: conf.general.differences,
isNoTitle: conf.general.noTitle,
Expand Down Expand Up @@ -276,6 +278,19 @@ func (v *Viddy) queueHandler() {

v.Lock()
v.idList = append(v.idList, id)
rc := v.historyView.GetRowCount()

if !v.isTimeMachine && v.maxHistory > 0 && rc > v.maxHistory {
count := rc - v.maxHistory
ids := v.idList[:count]

for i, id := range ids {
v.snapshots.Delete(id)
delete(v.historyRows, id)
v.historyView.RemoveRow(rc - 1 - i)
}
}

v.Unlock()

if !v.isTimeMachine {
Expand Down