How to use key method of main Package

Best Syzkaller code snippet using main.key

key_index_test.go

Source:key_index_test.go Github

copy

Full Screen

...16 "reflect"17 "testing"18)19func TestKeyIndexGet(t *testing.T) {20 // key: "foo"21 // rev: 1622 // generations:23 // {empty}24 // {{14, 0}[1], {14, 1}[2], {16, 0}(t)[3]}25 // {{8, 0}[1], {10, 0}[2], {12, 0}(t)[3]}26 // {{2, 0}[1], {4, 0}[2], {6, 0}(t)[3]}27 ki := newTestKeyIndex()28 ki.compact(4, make(map[revision]struct{}))29 tests := []struct {30 rev int6431 wmod revision32 wcreat revision33 wver int6434 werr error35 }{36 {17, revision{}, revision{}, 0, ErrRevisionNotFound},37 {16, revision{}, revision{}, 0, ErrRevisionNotFound},38 // get on generation 339 {15, revision{14, 1}, revision{14, 0}, 2, nil},40 {14, revision{14, 1}, revision{14, 0}, 2, nil},41 {13, revision{}, revision{}, 0, ErrRevisionNotFound},42 {12, revision{}, revision{}, 0, ErrRevisionNotFound},43 // get on generation 244 {11, revision{10, 0}, revision{8, 0}, 2, nil},45 {10, revision{10, 0}, revision{8, 0}, 2, nil},46 {9, revision{8, 0}, revision{8, 0}, 1, nil},47 {8, revision{8, 0}, revision{8, 0}, 1, nil},48 {7, revision{}, revision{}, 0, ErrRevisionNotFound},49 {6, revision{}, revision{}, 0, ErrRevisionNotFound},50 // get on generation 151 {5, revision{4, 0}, revision{2, 0}, 2, nil},52 {4, revision{4, 0}, revision{2, 0}, 2, nil},53 {3, revision{}, revision{}, 0, ErrRevisionNotFound},54 {2, revision{}, revision{}, 0, ErrRevisionNotFound},55 {1, revision{}, revision{}, 0, ErrRevisionNotFound},56 {0, revision{}, revision{}, 0, ErrRevisionNotFound},57 }58 for i, tt := range tests {59 mod, creat, ver, err := ki.get(tt.rev)60 if err != tt.werr {61 t.Errorf("#%d: err = %v, want %v", i, err, tt.werr)62 }63 if mod != tt.wmod {64 t.Errorf("#%d: modified = %+v, want %+v", i, mod, tt.wmod)65 }66 if creat != tt.wcreat {67 t.Errorf("#%d: created = %+v, want %+v", i, creat, tt.wcreat)68 }69 if ver != tt.wver {70 t.Errorf("#%d: version = %d, want %d", i, ver, tt.wver)71 }72 }73}74func TestKeyIndexSince(t *testing.T) {75 ki := newTestKeyIndex()76 ki.compact(4, make(map[revision]struct{}))77 allRevs := []revision{{4, 0}, {6, 0}, {8, 0}, {10, 0}, {12, 0}, {14, 1}, {16, 0}}78 tests := []struct {79 rev int6480 wrevs []revision81 }{82 {17, nil},83 {16, allRevs[6:]},84 {15, allRevs[6:]},85 {14, allRevs[5:]},86 {13, allRevs[5:]},87 {12, allRevs[4:]},88 {11, allRevs[4:]},89 {10, allRevs[3:]},90 {9, allRevs[3:]},91 {8, allRevs[2:]},92 {7, allRevs[2:]},93 {6, allRevs[1:]},94 {5, allRevs[1:]},95 {4, allRevs},96 {3, allRevs},97 {2, allRevs},98 {1, allRevs},99 {0, allRevs},100 }101 for i, tt := range tests {102 revs := ki.since(tt.rev)103 if !reflect.DeepEqual(revs, tt.wrevs) {104 t.Errorf("#%d: revs = %+v, want %+v", i, revs, tt.wrevs)105 }106 }107}108func TestKeyIndexPut(t *testing.T) {109 ki := &keyIndex{key: []byte("foo")}110 ki.put(5, 0)111 wki := &keyIndex{112 key: []byte("foo"),113 modified: revision{5, 0},114 generations: []generation{{created: revision{5, 0}, ver: 1, revs: []revision{{main: 5}}}},115 }116 if !reflect.DeepEqual(ki, wki) {117 t.Errorf("ki = %+v, want %+v", ki, wki)118 }119 ki.put(7, 0)120 wki = &keyIndex{121 key: []byte("foo"),122 modified: revision{7, 0},123 generations: []generation{{created: revision{5, 0}, ver: 2, revs: []revision{{main: 5}, {main: 7}}}},124 }125 if !reflect.DeepEqual(ki, wki) {126 t.Errorf("ki = %+v, want %+v", ki, wki)127 }128}129func TestKeyIndexRestore(t *testing.T) {130 ki := &keyIndex{key: []byte("foo")}131 ki.restore(revision{5, 0}, revision{7, 0}, 2)132 wki := &keyIndex{133 key: []byte("foo"),134 modified: revision{7, 0},135 generations: []generation{{created: revision{5, 0}, ver: 2, revs: []revision{{main: 7}}}},136 }137 if !reflect.DeepEqual(ki, wki) {138 t.Errorf("ki = %+v, want %+v", ki, wki)139 }140}141func TestKeyIndexTombstone(t *testing.T) {142 ki := &keyIndex{key: []byte("foo")}143 ki.put(5, 0)144 err := ki.tombstone(7, 0)145 if err != nil {146 t.Errorf("unexpected tombstone error: %v", err)147 }148 wki := &keyIndex{149 key: []byte("foo"),150 modified: revision{7, 0},151 generations: []generation{{created: revision{5, 0}, ver: 2, revs: []revision{{main: 5}, {main: 7}}}, {}},152 }153 if !reflect.DeepEqual(ki, wki) {154 t.Errorf("ki = %+v, want %+v", ki, wki)155 }156 ki.put(8, 0)157 ki.put(9, 0)158 err = ki.tombstone(15, 0)159 if err != nil {160 t.Errorf("unexpected tombstone error: %v", err)161 }162 wki = &keyIndex{163 key: []byte("foo"),164 modified: revision{15, 0},165 generations: []generation{166 {created: revision{5, 0}, ver: 2, revs: []revision{{main: 5}, {main: 7}}},167 {created: revision{8, 0}, ver: 3, revs: []revision{{main: 8}, {main: 9}, {main: 15}}},168 {},169 },170 }171 if !reflect.DeepEqual(ki, wki) {172 t.Errorf("ki = %+v, want %+v", ki, wki)173 }174 err = ki.tombstone(16, 0)175 if err != ErrRevisionNotFound {176 t.Errorf("tombstone error = %v, want %v", err, ErrRevisionNotFound)177 }178}179func TestKeyIndexCompactAndKeep(t *testing.T) {180 tests := []struct {181 compact int64182 wki *keyIndex183 wam map[revision]struct{}184 }{185 {186 1,187 &keyIndex{188 key: []byte("foo"),189 modified: revision{16, 0},190 generations: []generation{191 {created: revision{2, 0}, ver: 3, revs: []revision{{main: 2}, {main: 4}, {main: 6}}},192 {created: revision{8, 0}, ver: 3, revs: []revision{{main: 8}, {main: 10}, {main: 12}}},193 {created: revision{14, 0}, ver: 3, revs: []revision{{main: 14}, {main: 14, sub: 1}, {main: 16}}},194 {},195 },196 },197 map[revision]struct{}{},198 },199 {200 2,201 &keyIndex{202 key: []byte("foo"),203 modified: revision{16, 0},204 generations: []generation{205 {created: revision{2, 0}, ver: 3, revs: []revision{{main: 2}, {main: 4}, {main: 6}}},206 {created: revision{8, 0}, ver: 3, revs: []revision{{main: 8}, {main: 10}, {main: 12}}},207 {created: revision{14, 0}, ver: 3, revs: []revision{{main: 14}, {main: 14, sub: 1}, {main: 16}}},208 {},209 },210 },211 map[revision]struct{}{212 {main: 2}: {},213 },214 },215 {216 3,217 &keyIndex{218 key: []byte("foo"),219 modified: revision{16, 0},220 generations: []generation{221 {created: revision{2, 0}, ver: 3, revs: []revision{{main: 2}, {main: 4}, {main: 6}}},222 {created: revision{8, 0}, ver: 3, revs: []revision{{main: 8}, {main: 10}, {main: 12}}},223 {created: revision{14, 0}, ver: 3, revs: []revision{{main: 14}, {main: 14, sub: 1}, {main: 16}}},224 {},225 },226 },227 map[revision]struct{}{228 {main: 2}: {},229 },230 },231 {232 4,233 &keyIndex{234 key: []byte("foo"),235 modified: revision{16, 0},236 generations: []generation{237 {created: revision{2, 0}, ver: 3, revs: []revision{{main: 4}, {main: 6}}},238 {created: revision{8, 0}, ver: 3, revs: []revision{{main: 8}, {main: 10}, {main: 12}}},239 {created: revision{14, 0}, ver: 3, revs: []revision{{main: 14}, {main: 14, sub: 1}, {main: 16}}},240 {},241 },242 },243 map[revision]struct{}{244 {main: 4}: {},245 },246 },247 {248 5,249 &keyIndex{250 key: []byte("foo"),251 modified: revision{16, 0},252 generations: []generation{253 {created: revision{2, 0}, ver: 3, revs: []revision{{main: 4}, {main: 6}}},254 {created: revision{8, 0}, ver: 3, revs: []revision{{main: 8}, {main: 10}, {main: 12}}},255 {created: revision{14, 0}, ver: 3, revs: []revision{{main: 14}, {main: 14, sub: 1}, {main: 16}}},256 {},257 },258 },259 map[revision]struct{}{260 {main: 4}: {},261 },262 },263 {264 6,265 &keyIndex{266 key: []byte("foo"),267 modified: revision{16, 0},268 generations: []generation{269 {created: revision{8, 0}, ver: 3, revs: []revision{{main: 8}, {main: 10}, {main: 12}}},270 {created: revision{14, 0}, ver: 3, revs: []revision{{main: 14}, {main: 14, sub: 1}, {main: 16}}},271 {},272 },273 },274 map[revision]struct{}{},275 },276 {277 7,278 &keyIndex{279 key: []byte("foo"),280 modified: revision{16, 0},281 generations: []generation{282 {created: revision{8, 0}, ver: 3, revs: []revision{{main: 8}, {main: 10}, {main: 12}}},283 {created: revision{14, 0}, ver: 3, revs: []revision{{main: 14}, {main: 14, sub: 1}, {main: 16}}},284 {},285 },286 },287 map[revision]struct{}{},288 },289 {290 8,291 &keyIndex{292 key: []byte("foo"),293 modified: revision{16, 0},294 generations: []generation{295 {created: revision{8, 0}, ver: 3, revs: []revision{{main: 8}, {main: 10}, {main: 12}}},296 {created: revision{14, 0}, ver: 3, revs: []revision{{main: 14}, {main: 14, sub: 1}, {main: 16}}},297 {},298 },299 },300 map[revision]struct{}{301 {main: 8}: {},302 },303 },304 {305 9,306 &keyIndex{307 key: []byte("foo"),308 modified: revision{16, 0},309 generations: []generation{310 {created: revision{8, 0}, ver: 3, revs: []revision{{main: 8}, {main: 10}, {main: 12}}},311 {created: revision{14, 0}, ver: 3, revs: []revision{{main: 14}, {main: 14, sub: 1}, {main: 16}}},312 {},313 },314 },315 map[revision]struct{}{316 {main: 8}: {},317 },318 },319 {320 10,321 &keyIndex{322 key: []byte("foo"),323 modified: revision{16, 0},324 generations: []generation{325 {created: revision{8, 0}, ver: 3, revs: []revision{{main: 10}, {main: 12}}},326 {created: revision{14, 0}, ver: 3, revs: []revision{{main: 14}, {main: 14, sub: 1}, {main: 16}}},327 {},328 },329 },330 map[revision]struct{}{331 {main: 10}: {},332 },333 },334 {335 11,336 &keyIndex{337 key: []byte("foo"),338 modified: revision{16, 0},339 generations: []generation{340 {created: revision{8, 0}, ver: 3, revs: []revision{{main: 10}, {main: 12}}},341 {created: revision{14, 0}, ver: 3, revs: []revision{{main: 14}, {main: 14, sub: 1}, {main: 16}}},342 {},343 },344 },345 map[revision]struct{}{346 {main: 10}: {},347 },348 },349 {350 12,351 &keyIndex{352 key: []byte("foo"),353 modified: revision{16, 0},354 generations: []generation{355 {created: revision{14, 0}, ver: 3, revs: []revision{{main: 14}, {main: 14, sub: 1}, {main: 16}}},356 {},357 },358 },359 map[revision]struct{}{},360 },361 {362 13,363 &keyIndex{364 key: []byte("foo"),365 modified: revision{16, 0},366 generations: []generation{367 {created: revision{14, 0}, ver: 3, revs: []revision{{main: 14}, {main: 14, sub: 1}, {main: 16}}},368 {},369 },370 },371 map[revision]struct{}{},372 },373 {374 14,375 &keyIndex{376 key: []byte("foo"),377 modified: revision{16, 0},378 generations: []generation{379 {created: revision{14, 0}, ver: 3, revs: []revision{{main: 14, sub: 1}, {main: 16}}},380 {},381 },382 },383 map[revision]struct{}{384 {main: 14, sub: 1}: {},385 },386 },387 {388 15,389 &keyIndex{390 key: []byte("foo"),391 modified: revision{16, 0},392 generations: []generation{393 {created: revision{14, 0}, ver: 3, revs: []revision{{main: 14, sub: 1}, {main: 16}}},394 {},395 },396 },397 map[revision]struct{}{398 {main: 14, sub: 1}: {},399 },400 },401 {402 16,403 &keyIndex{404 key: []byte("foo"),405 modified: revision{16, 0},406 generations: []generation{407 {},408 },409 },410 map[revision]struct{}{},411 },412 }413 // Continuous Compaction and finding Keep414 ki := newTestKeyIndex()415 for i, tt := range tests {416 am := make(map[revision]struct{})417 kiclone := cloneKeyIndex(ki)418 ki.keep(tt.compact, am)419 if !reflect.DeepEqual(ki, kiclone) {420 t.Errorf("#%d: ki = %+v, want %+v", i, ki, kiclone)421 }422 if !reflect.DeepEqual(am, tt.wam) {423 t.Errorf("#%d: am = %+v, want %+v", i, am, tt.wam)424 }425 am = make(map[revision]struct{})426 ki.compact(tt.compact, am)427 if !reflect.DeepEqual(ki, tt.wki) {428 t.Errorf("#%d: ki = %+v, want %+v", i, ki, tt.wki)429 }430 if !reflect.DeepEqual(am, tt.wam) {431 t.Errorf("#%d: am = %+v, want %+v", i, am, tt.wam)432 }433 }434 // Jump Compaction and finding Keep435 ki = newTestKeyIndex()436 for i, tt := range tests {437 if (i%2 == 0 && i < 6) || (i%2 == 1 && i > 6) {438 am := make(map[revision]struct{})439 kiclone := cloneKeyIndex(ki)440 ki.keep(tt.compact, am)441 if !reflect.DeepEqual(ki, kiclone) {442 t.Errorf("#%d: ki = %+v, want %+v", i, ki, kiclone)443 }444 if !reflect.DeepEqual(am, tt.wam) {445 t.Errorf("#%d: am = %+v, want %+v", i, am, tt.wam)446 }447 am = make(map[revision]struct{})448 ki.compact(tt.compact, am)449 if !reflect.DeepEqual(ki, tt.wki) {450 t.Errorf("#%d: ki = %+v, want %+v", i, ki, tt.wki)451 }452 if !reflect.DeepEqual(am, tt.wam) {453 t.Errorf("#%d: am = %+v, want %+v", i, am, tt.wam)454 }455 }456 }457 kiClone := newTestKeyIndex()458 // Once Compaction and finding Keep459 for i, tt := range tests {460 ki := newTestKeyIndex()461 am := make(map[revision]struct{})462 ki.keep(tt.compact, am)463 if !reflect.DeepEqual(ki, kiClone) {464 t.Errorf("#%d: ki = %+v, want %+v", i, ki, kiClone)465 }466 if !reflect.DeepEqual(am, tt.wam) {467 t.Errorf("#%d: am = %+v, want %+v", i, am, tt.wam)468 }469 am = make(map[revision]struct{})470 ki.compact(tt.compact, am)471 if !reflect.DeepEqual(ki, tt.wki) {472 t.Errorf("#%d: ki = %+v, want %+v", i, ki, tt.wki)473 }474 if !reflect.DeepEqual(am, tt.wam) {475 t.Errorf("#%d: am = %+v, want %+v", i, am, tt.wam)476 }477 }478}479func cloneKeyIndex(ki *keyIndex) *keyIndex {480 generations := make([]generation, len(ki.generations))481 for i, gen := range ki.generations {482 generations[i] = *cloneGeneration(&gen)483 }484 return &keyIndex{ki.key, ki.modified, generations}485}486func cloneGeneration(g *generation) *generation {487 if g.revs == nil {488 return &generation{g.ver, g.created, nil}489 }490 tmp := make([]revision, len(g.revs))491 copy(tmp, g.revs)492 return &generation{g.ver, g.created, tmp}493}494// test that compact on version that higher than last modified version works well495func TestKeyIndexCompactOnFurtherRev(t *testing.T) {496 ki := &keyIndex{key: []byte("foo")}497 ki.put(1, 0)498 ki.put(2, 0)499 am := make(map[revision]struct{})500 ki.compact(3, am)501 wki := &keyIndex{502 key: []byte("foo"),503 modified: revision{2, 0},504 generations: []generation{505 {created: revision{1, 0}, ver: 2, revs: []revision{{main: 2}}},506 },507 }508 wam := map[revision]struct{}{509 {main: 2}: {},510 }511 if !reflect.DeepEqual(ki, wki) {512 t.Errorf("ki = %+v, want %+v", ki, wki)513 }514 if !reflect.DeepEqual(am, wam) {515 t.Errorf("am = %+v, want %+v", am, wam)516 }517}518func TestKeyIndexIsEmpty(t *testing.T) {519 tests := []struct {520 ki *keyIndex521 w bool522 }{523 {524 &keyIndex{525 key: []byte("foo"),526 generations: []generation{{}},527 },528 true,529 },530 {531 &keyIndex{532 key: []byte("foo"),533 modified: revision{2, 0},534 generations: []generation{535 {created: revision{1, 0}, ver: 2, revs: []revision{{main: 2}}},536 },537 },538 false,539 },540 }541 for i, tt := range tests {542 g := tt.ki.isEmpty()543 if g != tt.w {544 t.Errorf("#%d: isEmpty = %v, want %v", i, g, tt.w)545 }546 }547}548func TestKeyIndexFindGeneration(t *testing.T) {549 ki := newTestKeyIndex()550 tests := []struct {551 rev int64552 wg *generation553 }{554 {0, nil},555 {1, nil},556 {2, &ki.generations[0]},557 {3, &ki.generations[0]},558 {4, &ki.generations[0]},559 {5, &ki.generations[0]},560 {6, nil},561 {7, nil},562 {8, &ki.generations[1]},563 {9, &ki.generations[1]},564 {10, &ki.generations[1]},565 {11, &ki.generations[1]},566 {12, nil},567 {13, nil},568 }569 for i, tt := range tests {570 g := ki.findGeneration(tt.rev)571 if g != tt.wg {572 t.Errorf("#%d: generation = %+v, want %+v", i, g, tt.wg)573 }574 }575}576func TestKeyIndexLess(t *testing.T) {577 ki := &keyIndex{key: []byte("foo")}578 tests := []struct {579 ki *keyIndex580 w bool581 }{582 {&keyIndex{key: []byte("doo")}, false},583 {&keyIndex{key: []byte("foo")}, false},584 {&keyIndex{key: []byte("goo")}, true},585 }586 for i, tt := range tests {587 g := ki.Less(tt.ki)588 if g != tt.w {589 t.Errorf("#%d: Less = %v, want %v", i, g, tt.w)590 }591 }592}593func TestGenerationIsEmpty(t *testing.T) {594 tests := []struct {595 g *generation596 w bool597 }{598 {nil, true},599 {&generation{}, true},600 {&generation{revs: []revision{{main: 1}}}, false},601 }602 for i, tt := range tests {603 g := tt.g.isEmpty()604 if g != tt.w {605 t.Errorf("#%d: isEmpty = %v, want %v", i, g, tt.w)606 }607 }608}609func TestGenerationWalk(t *testing.T) {610 g := &generation{611 ver: 3,612 created: revision{2, 0},613 revs: []revision{{main: 2}, {main: 4}, {main: 6}},614 }615 tests := []struct {616 f func(rev revision) bool617 wi int618 }{619 {func(rev revision) bool { return rev.main >= 7 }, 2},620 {func(rev revision) bool { return rev.main >= 6 }, 1},621 {func(rev revision) bool { return rev.main >= 5 }, 1},622 {func(rev revision) bool { return rev.main >= 4 }, 0},623 {func(rev revision) bool { return rev.main >= 3 }, 0},624 {func(rev revision) bool { return rev.main >= 2 }, -1},625 }626 for i, tt := range tests {627 idx := g.walk(tt.f)628 if idx != tt.wi {629 t.Errorf("#%d: index = %d, want %d", i, idx, tt.wi)630 }631 }632}633func newTestKeyIndex() *keyIndex {634 // key: "foo"635 // rev: 16636 // generations:637 // {empty}638 // {{14, 0}[1], {14, 1}[2], {16, 0}(t)[3]}639 // {{8, 0}[1], {10, 0}[2], {12, 0}(t)[3]}640 // {{2, 0}[1], {4, 0}[2], {6, 0}(t)[3]}641 ki := &keyIndex{key: []byte("foo")}642 ki.put(2, 0)643 ki.put(4, 0)644 ki.tombstone(6, 0)645 ki.put(8, 0)646 ki.put(10, 0)647 ki.tombstone(12, 0)648 ki.put(14, 0)649 ki.put(14, 1)650 ki.tombstone(16, 0)651 return ki652}...

Full Screen

Full Screen

keybindings.go

Source:keybindings.go Github

copy

Full Screen

2import (3 "fmt"4 "github.com/jesseduffield/gocui"5)6// Binding - a keybinding mapping a key and modifier to a handler. The keypress7// is only handled if the given view has focus, or handled globally if the view8// is ""9type Binding struct {10 ViewName string11 Handler func(*gocui.Gui, *gocui.View) error12 Key interface{} // FIXME: find out how to get `gocui.Key | rune`13 Modifier gocui.Modifier14 Description string15}16// GetDisplayStrings returns the display string of a file17func (b *Binding) GetDisplayStrings(isFocused bool) []string {18 return []string{b.GetKey(), b.Description}19}20// GetKey is a function.21func (b *Binding) GetKey() string {22 key := 023 switch b.Key.(type) {24 case rune:25 key = int(b.Key.(rune))26 case gocui.Key:27 key = int(b.Key.(gocui.Key))28 }29 // special keys30 switch key {31 case 27:32 return "esc"33 case 13:34 return "enter"35 case 32:36 return "space"37 case 65514:38 return "►"39 case 65515:40 return "◄"41 case 65517:42 return "▲"43 case 65516:44 return "▼"45 case 65508:46 return "PgUp"47 case 65507:48 return "PgDn"49 }50 return fmt.Sprintf("%c", key)51}52// GetInitialKeybindings is a function.53func (gui *Gui) GetInitialKeybindings() []*Binding {54 bindings := []*Binding{55 {56 ViewName: "",57 Key: 'q',58 Modifier: gocui.ModNone,59 Handler: gui.quit,60 },61 {62 ViewName: "",63 Key: gocui.KeyCtrlC,64 Modifier: gocui.ModNone,65 Handler: gui.quit,66 },67 {68 ViewName: "",69 Key: gocui.KeyEsc,70 Modifier: gocui.ModNone,71 Handler: gui.quit,72 },73 {74 ViewName: "",75 Key: gocui.KeyPgup,76 Modifier: gocui.ModNone,77 Handler: gui.scrollUpMain,78 },79 {80 ViewName: "",81 Key: gocui.KeyPgdn,82 Modifier: gocui.ModNone,83 Handler: gui.scrollDownMain,84 },85 {86 ViewName: "",87 Key: gocui.KeyCtrlU,88 Modifier: gocui.ModNone,89 Handler: gui.scrollUpMain,90 },91 {92 ViewName: "",93 Key: gocui.KeyCtrlD,94 Modifier: gocui.ModNone,95 Handler: gui.scrollDownMain,96 },97 {98 ViewName: "",99 Key: gocui.KeyEnd,100 Modifier: gocui.ModNone,101 Handler: gui.autoScrollMain,102 },103 {104 ViewName: "",105 Key: 'x',106 Modifier: gocui.ModNone,107 Handler: gui.handleCreateOptionsMenu,108 },109 {110 ViewName: "",111 Key: '?',112 Modifier: gocui.ModNone,113 Handler: gui.handleCreateOptionsMenu,114 },115 {116 ViewName: "",117 Key: 'X',118 Modifier: gocui.ModNone,119 Handler: gui.handleCustomCommand,120 },121 {122 ViewName: "project",123 Key: 'e',124 Modifier: gocui.ModNone,125 Handler: gui.handleEditConfig,126 Description: gui.Tr.EditConfig,127 },128 {129 ViewName: "project",130 Key: 'o',131 Modifier: gocui.ModNone,132 Handler: gui.handleOpenConfig,133 Description: gui.Tr.OpenConfig,134 },135 {136 ViewName: "project",137 Key: '[',138 Modifier: gocui.ModNone,139 Handler: gui.handleProjectPrevContext,140 Description: gui.Tr.PreviousContext,141 },142 {143 ViewName: "project",144 Key: ']',145 Modifier: gocui.ModNone,146 Handler: gui.handleProjectNextContext,147 Description: gui.Tr.NextContext,148 },149 {150 ViewName: "project",151 Key: gocui.MouseLeft,152 Modifier: gocui.ModNone,153 Handler: gui.handleProjectClick,154 },155 {156 ViewName: "project",157 Key: 'm',158 Modifier: gocui.ModNone,159 Handler: gui.handleViewAllLogs,160 Description: gui.Tr.ViewLogs,161 },162 {163 ViewName: "project",164 Key: gocui.MouseLeft,165 Modifier: gocui.ModNone,166 Handler: gui.handleProjectSelect,167 },168 {169 ViewName: "menu",170 Key: gocui.KeyEsc,171 Modifier: gocui.ModNone,172 Handler: gui.handleMenuClose,173 },174 {175 ViewName: "menu",176 Key: 'q',177 Modifier: gocui.ModNone,178 Handler: gui.handleMenuClose,179 },180 {181 ViewName: "information",182 Key: gocui.MouseLeft,183 Modifier: gocui.ModNone,184 Handler: gui.handleDonate,185 },186 {187 ViewName: "containers",188 Key: '[',189 Modifier: gocui.ModNone,190 Handler: gui.handleContainersPrevContext,191 Description: gui.Tr.PreviousContext,192 },193 {194 ViewName: "containers",195 Key: ']',196 Modifier: gocui.ModNone,197 Handler: gui.handleContainersNextContext,198 Description: gui.Tr.NextContext,199 },200 {201 ViewName: "containers",202 Key: 'd',203 Modifier: gocui.ModNone,204 Handler: gui.handleContainersRemoveMenu,205 Description: gui.Tr.Remove,206 },207 {208 ViewName: "containers",209 Key: 'e',210 Modifier: gocui.ModNone,211 Handler: gui.handleHideStoppedContainers,212 Description: gui.Tr.HideStopped,213 },214 {215 ViewName: "containers",216 Key: 's',217 Modifier: gocui.ModNone,218 Handler: gui.handleContainerStop,219 Description: gui.Tr.Stop,220 },221 {222 ViewName: "containers",223 Key: 'r',224 Modifier: gocui.ModNone,225 Handler: gui.handleContainerRestart,226 Description: gui.Tr.Restart,227 },228 {229 ViewName: "containers",230 Key: 'a',231 Modifier: gocui.ModNone,232 Handler: gui.handleContainerAttach,233 Description: gui.Tr.Attach,234 },235 {236 ViewName: "containers",237 Key: 'm',238 Modifier: gocui.ModNone,239 Handler: gui.handleContainerViewLogs,240 Description: gui.Tr.ViewLogs,241 },242 {243 ViewName: "containers",244 Key: 'E',245 Modifier: gocui.ModNone,246 Handler: gui.handleContainersExecShell,247 Description: gui.Tr.ExecShell,248 },249 {250 ViewName: "containers",251 Key: 'c',252 Modifier: gocui.ModNone,253 Handler: gui.handleContainersCustomCommand,254 Description: gui.Tr.RunCustomCommand,255 },256 {257 ViewName: "containers",258 Key: 'b',259 Modifier: gocui.ModNone,260 Handler: gui.handleContainersBulkCommand,261 Description: gui.Tr.ViewBulkCommands,262 },263 {264 ViewName: "containers",265 Key: 'w',266 Modifier: gocui.ModNone,267 Handler: gui.handleContainersOpenInBrowserCommand,268 Description: gui.Tr.OpenInBrowser,269 },270 {271 ViewName: "services",272 Key: 'd',273 Modifier: gocui.ModNone,274 Handler: gui.handleServiceRemoveMenu,275 Description: gui.Tr.RemoveService,276 },277 {278 ViewName: "services",279 Key: 's',280 Modifier: gocui.ModNone,281 Handler: gui.handleServiceStop,282 Description: gui.Tr.Stop,283 },284 {285 ViewName: "services",286 Key: 'r',287 Modifier: gocui.ModNone,288 Handler: gui.handleServiceRestart,289 Description: gui.Tr.Restart,290 },291 {292 ViewName: "services",293 Key: 'S',294 Modifier: gocui.ModNone,295 Handler: gui.handleServiceStart,296 Description: gui.Tr.Start,297 },298 {299 ViewName: "services",300 Key: 'a',301 Modifier: gocui.ModNone,302 Handler: gui.handleServiceAttach,303 Description: gui.Tr.Attach,304 },305 {306 ViewName: "services",307 Key: 'm',308 Modifier: gocui.ModNone,309 Handler: gui.handleServiceViewLogs,310 Description: gui.Tr.ViewLogs,311 },312 {313 ViewName: "services",314 Key: '[',315 Modifier: gocui.ModNone,316 Handler: gui.handleServicesPrevContext,317 Description: gui.Tr.PreviousContext,318 },319 {320 ViewName: "services",321 Key: ']',322 Modifier: gocui.ModNone,323 Handler: gui.handleServicesNextContext,324 Description: gui.Tr.NextContext,325 },326 {327 ViewName: "services",328 Key: 'R',329 Modifier: gocui.ModNone,330 Handler: gui.handleServiceRestartMenu,331 Description: gui.Tr.ViewRestartOptions,332 },333 {334 ViewName: "services",335 Key: 'c',336 Modifier: gocui.ModNone,337 Handler: gui.handleServicesCustomCommand,338 Description: gui.Tr.RunCustomCommand,339 },340 {341 ViewName: "services",342 Key: 'b',343 Modifier: gocui.ModNone,344 Handler: gui.handleServicesBulkCommand,345 Description: gui.Tr.ViewBulkCommands,346 },347 {348 ViewName: "services",349 Key: 'w',350 Modifier: gocui.ModNone,351 Handler: gui.handleServicesOpenInBrowserCommand,352 Description: gui.Tr.OpenInBrowser,353 },354 {355 ViewName: "images",356 Key: '[',357 Modifier: gocui.ModNone,358 Handler: gui.handleImagesPrevContext,359 Description: gui.Tr.PreviousContext,360 },361 {362 ViewName: "images",363 Key: ']',364 Modifier: gocui.ModNone,365 Handler: gui.handleImagesNextContext,366 Description: gui.Tr.NextContext,367 },368 {369 ViewName: "images",370 Key: 'c',371 Modifier: gocui.ModNone,372 Handler: gui.handleImagesCustomCommand,373 Description: gui.Tr.RunCustomCommand,374 },375 {376 ViewName: "images",377 Key: 'd',378 Modifier: gocui.ModNone,379 Handler: gui.handleImagesRemoveMenu,380 Description: gui.Tr.RemoveImage,381 },382 {383 ViewName: "images",384 Key: 'b',385 Modifier: gocui.ModNone,386 Handler: gui.handleImagesBulkCommand,387 Description: gui.Tr.ViewBulkCommands,388 },389 {390 ViewName: "volumes",391 Key: '[',392 Modifier: gocui.ModNone,393 Handler: gui.handleVolumesPrevContext,394 Description: gui.Tr.PreviousContext,395 },396 {397 ViewName: "volumes",398 Key: ']',399 Modifier: gocui.ModNone,400 Handler: gui.handleVolumesNextContext,401 Description: gui.Tr.NextContext,402 },403 {404 ViewName: "volumes",405 Key: 'c',406 Modifier: gocui.ModNone,407 Handler: gui.handleVolumesCustomCommand,408 Description: gui.Tr.RunCustomCommand,409 },410 {411 ViewName: "volumes",412 Key: 'd',413 Modifier: gocui.ModNone,414 Handler: gui.handleVolumesRemoveMenu,415 Description: gui.Tr.RemoveVolume,416 },417 {418 ViewName: "volumes",419 Key: 'b',420 Modifier: gocui.ModNone,421 Handler: gui.handleVolumesBulkCommand,422 Description: gui.Tr.ViewBulkCommands,423 },424 {425 ViewName: "main",426 Key: gocui.KeyEsc,427 Modifier: gocui.ModNone,428 Handler: gui.handleExitMain,429 Description: gui.Tr.Return,430 },431 {432 ViewName: "main",433 Key: gocui.KeyArrowLeft,434 Modifier: gocui.ModNone,435 Handler: gui.scrollLeftMain,436 },437 {438 ViewName: "main",439 Key: gocui.KeyArrowRight,440 Modifier: gocui.ModNone,441 Handler: gui.scrollRightMain,442 },443 {444 ViewName: "main",445 Key: 'h',446 Modifier: gocui.ModNone,447 Handler: gui.scrollLeftMain,448 },449 {450 ViewName: "main",451 Key: 'l',452 Modifier: gocui.ModNone,453 Handler: gui.scrollRightMain,454 },455 {456 ViewName: "",457 Key: 'J',458 Modifier: gocui.ModNone,459 Handler: gui.scrollDownMain,460 },461 {462 ViewName: "",463 Key: 'K',464 Modifier: gocui.ModNone,465 Handler: gui.scrollUpMain,466 },467 {468 ViewName: "",469 Key: 'H',470 Modifier: gocui.ModNone,471 Handler: gui.scrollLeftMain,472 },473 {474 ViewName: "",475 Key: 'L',476 Modifier: gocui.ModNone,477 Handler: gui.scrollRightMain,478 },479 }480 // TODO: add more views here481 for _, viewName := range []string{"project", "services", "containers", "images", "volumes", "menu"} {482 bindings = append(bindings, []*Binding{483 {ViewName: viewName, Key: gocui.KeyArrowLeft, Modifier: gocui.ModNone, Handler: gui.previousView},484 {ViewName: viewName, Key: gocui.KeyArrowRight, Modifier: gocui.ModNone, Handler: gui.nextView},485 {ViewName: viewName, Key: 'h', Modifier: gocui.ModNone, Handler: gui.previousView},486 {ViewName: viewName, Key: 'l', Modifier: gocui.ModNone, Handler: gui.nextView},487 }...)488 }489 panelMap := map[string]struct {490 onKeyUpPress func(*gocui.Gui, *gocui.View) error491 onKeyDownPress func(*gocui.Gui, *gocui.View) error492 onClick func(*gocui.Gui, *gocui.View) error493 }{494 "menu": {onKeyUpPress: gui.handleMenuPrevLine, onKeyDownPress: gui.handleMenuNextLine, onClick: gui.handleMenuClick},495 "services": {onKeyUpPress: gui.handleServicesPrevLine, onKeyDownPress: gui.handleServicesNextLine, onClick: gui.handleServicesClick},496 "containers": {onKeyUpPress: gui.handleContainersPrevLine, onKeyDownPress: gui.handleContainersNextLine, onClick: gui.handleContainersClick},497 "images": {onKeyUpPress: gui.handleImagesPrevLine, onKeyDownPress: gui.handleImagesNextLine, onClick: gui.handleImagesClick},498 "volumes": {onKeyUpPress: gui.handleVolumesPrevLine, onKeyDownPress: gui.handleVolumesNextLine, onClick: gui.handleVolumesClick},499 "main": {onKeyUpPress: gui.scrollUpMain, onKeyDownPress: gui.scrollDownMain, onClick: gui.handleMainClick},500 }501 for viewName, functions := range panelMap {502 bindings = append(bindings, []*Binding{503 {ViewName: viewName, Key: 'k', Modifier: gocui.ModNone, Handler: functions.onKeyUpPress},504 {ViewName: viewName, Key: gocui.KeyArrowUp, Modifier: gocui.ModNone, Handler: functions.onKeyUpPress},505 {ViewName: viewName, Key: gocui.MouseWheelUp, Modifier: gocui.ModNone, Handler: functions.onKeyUpPress},506 {ViewName: viewName, Key: 'j', Modifier: gocui.ModNone, Handler: functions.onKeyDownPress},507 {ViewName: viewName, Key: gocui.KeyArrowDown, Modifier: gocui.ModNone, Handler: functions.onKeyDownPress},508 {ViewName: viewName, Key: gocui.MouseWheelDown, Modifier: gocui.ModNone, Handler: functions.onKeyDownPress},509 {ViewName: viewName, Key: gocui.MouseLeft, Modifier: gocui.ModNone, Handler: functions.onClick},510 }...)511 }512 for _, viewName := range []string{"project", "services", "containers", "images", "volumes"} {513 bindings = append(bindings, &Binding{514 ViewName: viewName,515 Key: gocui.KeyEnter,516 Modifier: gocui.ModNone,517 Handler: gui.handleEnterMain,518 Description: gui.Tr.FocusMain,519 })520 }521 return bindings522}523func (gui *Gui) keybindings(g *gocui.Gui) error {524 bindings := gui.GetInitialKeybindings()525 for _, binding := range bindings {526 if err := g.SetKeybinding(binding.ViewName, nil, binding.Key, binding.Modifier, binding.Handler); err != nil {527 return err528 }529 }530 if err := g.SetTabClickBinding("main", gui.onMainTabClick); err != nil {531 return err532 }533 return nil534}...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Syzkaller automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful