fortune.vim 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. " Variables {{{1
  2. let s:cow = [
  3. \ ' o',
  4. \ ' o ^__^',
  5. \ ' o (oo)\_______',
  6. \ ' (__)\ )\/\',
  7. \ ' ||----w |',
  8. \ ' || ||',
  9. \ ]
  10. let s:quotes = exists('g:startify_custom_header_quotes')
  11. \ ? g:startify_custom_header_quotes
  12. \ : [
  13. \ ['Almost every programming language is overrated by its practitioners.', '', '- Larry Wall'],
  14. \ ]
  15. " Function: s:get_random_offset {{{1
  16. function! s:get_random_offset(max) abort
  17. return str2nr(matchstr(reltimestr(reltime()), '\.\zs\d\+')[1:]) % a:max
  18. endfunction
  19. " Function: s:draw_box {{{1
  20. function! s:draw_box(lines) abort
  21. let longest_line = max(map(copy(a:lines), 'strwidth(v:val)'))
  22. if &encoding == 'utf-8' && get(g:, 'startify_fortune_use_unicode')
  23. let top_left_corner = '╭'
  24. let top_right_corner = '╮'
  25. let bottom_left_corner = '╰'
  26. let bottom_right_corner = '╯'
  27. let side = '│'
  28. let top_bottom_side = '─'
  29. else
  30. let top_left_corner = '*'
  31. let top_right_corner = '*'
  32. let bottom_left_corner = '*'
  33. let bottom_right_corner = '*'
  34. let side = '|'
  35. let top_bottom_side = '-'
  36. endif
  37. let top = top_left_corner . repeat(top_bottom_side, longest_line + 2) . top_right_corner
  38. let bottom = bottom_left_corner . repeat(top_bottom_side, longest_line + 2) . bottom_right_corner
  39. let lines = [top]
  40. for l in a:lines
  41. let offset = longest_line - strwidth(l)
  42. let lines += [side . ' '. l . repeat(' ', offset) .' ' . side]
  43. endfor
  44. let lines += [bottom]
  45. return lines
  46. endfunction
  47. " Function: #quote {{{1
  48. function! startify#fortune#quote() abort
  49. return s:quotes[s:get_random_offset(len(s:quotes))]
  50. endfunction
  51. " Function: #boxed {{{1
  52. function! startify#fortune#boxed() abort
  53. let wrapped_quote = []
  54. let quote = startify#fortune#quote()
  55. for line in quote
  56. let wrapped_quote += split(line, '\%50c.\{-}\zs\s', 1)
  57. endfor
  58. let wrapped_quote = s:draw_box(wrapped_quote)
  59. return wrapped_quote
  60. endfunction
  61. " Function: #cowsay {{{1
  62. function! startify#fortune#cowsay() abort
  63. let boxed_quote = startify#fortune#boxed()
  64. let boxed_quote += s:cow
  65. return map(boxed_quote, '" ". v:val')
  66. endfunction