@@ -481,24 +481,17 @@ func (s *Shell) multiChoice(options []string, text string, init []int, multiResu
481
481
cur = selected [len (selected )- 1 ]
482
482
}
483
483
484
- _ , curRow , err := getPosition ()
484
+ fd := int (os .Stdout .Fd ())
485
+ _ , maxRows , err := readline .GetSize (fd )
485
486
if err != nil {
486
487
return nil
487
488
}
488
489
489
- _ , maxRows , err := readline .GetSize (0 )
490
- if err != nil {
491
- return nil
492
- }
493
-
494
- // allocate some space to be at the top of the screen
495
- s .Printf ("\033 [%dS" , curRow )
496
-
497
490
// move cursor to the top
498
491
// TODO it happens on every update, however, some trash appears in history without this line
499
492
s .Print ("\033 [0;0H" )
500
493
501
- offset := 0
494
+ offset := fd
502
495
503
496
update := func () {
504
497
strs := buildOptionsStrings (options , selected , cur )
@@ -521,7 +514,7 @@ func (s *Shell) multiChoice(options []string, text string, init []int, multiResu
521
514
offset ++
522
515
}
523
516
if cur >= len (options ) {
524
- offset = 0
517
+ offset = fd
525
518
cur = 0
526
519
}
527
520
} else if key == - 1 {
@@ -533,7 +526,7 @@ func (s *Shell) multiChoice(options []string, text string, init []int, multiResu
533
526
if len (options ) > maxRows - 1 {
534
527
offset = len (options ) - maxRows + 1
535
528
} else {
536
- offset = 0
529
+ offset = fd
537
530
}
538
531
cur = len (options ) - 1
539
532
}
@@ -563,7 +556,7 @@ func (s *Shell) multiChoice(options []string, text string, init []int, multiResu
563
556
case <- refresh :
564
557
update ()
565
558
case <- t .C :
566
- _ , rows , _ := readline .GetSize (0 )
559
+ _ , rows , _ := readline .GetSize (fd )
567
560
if maxRows != rows {
568
561
maxRows = rows
569
562
update ()
@@ -659,11 +652,12 @@ func copyShellProgressBar(s *Shell) ProgressBar {
659
652
}
660
653
661
654
func getPosition () (int , int , error ) {
662
- state , err := readline .MakeRaw (0 )
655
+ fd := int (os .Stdout .Fd ())
656
+ state , err := readline .MakeRaw (fd )
663
657
if err != nil {
664
658
return 0 , 0 , err
665
659
}
666
- defer readline .Restore (0 , state )
660
+ defer readline .Restore (fd , state )
667
661
fmt .Printf ("\033 [6n" )
668
662
var out string
669
663
reader := bufio .NewReader (os .Stdin )
0 commit comments