(options []string, text string, init []int, multiResults bool)
| 484 | } |
| 485 | |
| 486 | func (s *Shell) multiChoice(options []string, text string, init []int, multiResults bool) []int { |
| 487 | s.multiChoiceActive = true |
| 488 | defer func() { s.multiChoiceActive = false }() |
| 489 | |
| 490 | conf := s.reader.scanner.Config.Clone() |
| 491 | |
| 492 | conf.DisableAutoSaveHistory = true |
| 493 | |
| 494 | conf.FuncFilterInputRune = func(r rune) (rune, bool) { |
| 495 | switch r { |
| 496 | case 16: |
| 497 | return -1, true |
| 498 | case 14: |
| 499 | return -2, true |
| 500 | case 32: |
| 501 | return -3, true |
| 502 | |
| 503 | } |
| 504 | return r, true |
| 505 | } |
| 506 | |
| 507 | var selected []int |
| 508 | if multiResults { |
| 509 | selected = initSelected(init, len(options)) |
| 510 | } |
| 511 | |
| 512 | s.ShowPrompt(false) |
| 513 | defer s.ShowPrompt(true) |
| 514 | |
| 515 | // TODO this may not work on windows. |
| 516 | s.Print("\033[?25l") |
| 517 | defer s.Print("\033[?25h") |
| 518 | |
| 519 | cur := 0 |
| 520 | if len(selected) > 0 { |
| 521 | cur = selected[len(selected)-1] |
| 522 | } |
| 523 | |
| 524 | fd := int(os.Stdout.Fd()) |
| 525 | _, maxRows, err := readline.GetSize(fd) |
| 526 | if err != nil { |
| 527 | return nil |
| 528 | } |
| 529 | |
| 530 | // move cursor to the top |
| 531 | // TODO it happens on every update, however, some trash appears in history without this line |
| 532 | s.Print("\033[0;0H") |
| 533 | |
| 534 | offset := fd |
| 535 | |
| 536 | update := func() { |
| 537 | strs := buildOptionsStrings(options, selected, cur) |
| 538 | if len(strs) > maxRows-1 { |
| 539 | strs = strs[offset : maxRows+offset-1] |
| 540 | } |
| 541 | s.Print("\033[0;0H") |
| 542 | // clear from the cursor to the end of the screen |
| 543 | s.Print("\033[0J") |
no test coverage detected