Guest User

Untitled

a guest
Jun 18th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. def match_text_for_idx idx
  2. match = truncated_match @matches[idx]
  3. if idx == @selection
  4. prefix = @@selection_marker
  5. suffix = padding_for_selected_match match
  6. else
  7. prefix = @@unselected_marker
  8. suffix = ''
  9. end
  10. prefix + file_name(match) + match + suffix
  11. end
  12.  
  13. def file_name(match)
  14. file = match.split('/').last
  15. if file.length >= 50
  16. shorten_file_name(file)
  17. else
  18. spaces = 50 - file.length
  19. file = file + " " * (spaces)
  20. end
  21. end
  22.  
  23. def shorten_file_name match
  24. len = match.length
  25. max_width = 50
  26. return match if len <= max_width
  27. left = (max_width / 2) - 1
  28. right = (max_width / 2) - 2 + (max_width % 2)
  29. match[0, left] + '...' + match[-right, right]
  30. end
Add Comment
Please, Sign In to add comment