- 
                Notifications
    
You must be signed in to change notification settings  - Fork 57
 
Fix interactive prompt for options > terminal rows #35
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
Conversation
        
          
                lib/cli/ui.rb
              
                Outdated
          
        
      | # | ||
| # * +enable_color+ - should color be used? default to true | ||
| # | ||
| def self.fmt_full_line(input, enable_color: true) | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be able to accomplish the same thing by writing something like:
\e[nA or \e[nB # to move to the right row
\r # to reset to col 0
<text>
\e[K # to clear to the end of the line
This would be flicker-free too.
EDIT: e.g.: puts "asdf asdf asdf asdf \n\e[A\rasdf\e[K\n"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly LGTM but let's use \e[K rather than padding
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 
           @burke: I did this without   | 
    
1360fa1    to
    98e4133      
    Compare
  
    | end | ||
| end | ||
| 
               | 
          ||
| def presented_options(recalculate: false) | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is really hard to follow.
I feel like it would do well to have some comments throughout explaining the code as it's quite logic dense and sort of magic with the [-2].last etc
| 
           Refactored to hopefully improve clarity.  | 
    
| def presented_options(recalculate: false) | ||
| return @presented_options unless recalculate | ||
| 
               | 
          ||
| @presented_options = @options.zip(1..Float::INFINITY) | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@options.each.with_index(1) is another way if you think it's more clear. I'm undecided.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change would need to_a as well (as you suggest is an emumerator which prevents the manipulations below).  The zip seems clearer to me.
| 
               | 
          ||
| @presented_options = @options.zip(1..Float::INFINITY) | ||
| while num_lines > max_options | ||
| if last_visible_option_number - @active > @active - first_visible_option_number | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that this is kind of hard to read. Maybe change to:
distance_from_selection_to_end = last_visible_option_number - @active
distance_from_start_to_selection = @active - first_visible_option_number
# try to keep the selection centered in the window:
if distance_from_selection_to_end > distance_from_start_to_selection
  # selection is closer to top than bottom, so trim a row from the bottom
  ...
else
  # closer to bottom, so trim from top        
          
                lib/cli/ui/terminal.rb
              
                Outdated
          
        
      | module UI | ||
| module Terminal | ||
| DEFAULT_WIDTH = 80 | ||
| DEFAULT_HEIGHT = 5 | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The typical default height is 24 fwiw
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I still think I like my naming for the dense bit a little better but no major complaint.
Implement a scrolling list
038d9bd    to
    32ef33b      
    Compare
  
    | 
           Updated.  | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉

Implement a scrolling list.
wait_for_actionable_user_inputstops re-rendering options when not necessary (midway through processing a ⬆️/⬇️ sequence) since it was causing some noticeable flicker, but also means that tests had to change more, since fewer lines are written.fmt_full_lineis needed now since the lengths of lines can change, which was not true before since the only thing that changed was the marker vs space and colour. This also caused tests to change, prompting theoption_texthelper.cc @Shopify/dev-infra
Fixes #34