hlstate_spec.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. local helpers = require('test.functional.helpers')(after_each)
  2. local Screen = require('test.functional.ui.screen')
  3. local clear, insert = helpers.clear, helpers.insert
  4. local command = helpers.command
  5. local meths = helpers.meths
  6. local iswin = helpers.iswin
  7. local nvim_dir = helpers.nvim_dir
  8. local thelpers = require('test.functional.terminal.helpers')
  9. describe('ext_hlstate detailed highlights', function()
  10. local screen
  11. before_each(function()
  12. clear()
  13. command('syntax on')
  14. screen = Screen.new(40, 8)
  15. screen:attach({ext_hlstate=true})
  16. end)
  17. after_each(function()
  18. screen:detach()
  19. end)
  20. it('work with combined UI and syntax highlights', function()
  21. insert([[
  22. these are some lines
  23. with colorful text]])
  24. meths.buf_add_highlight(0, -1, "String", 0 , 10, 14)
  25. meths.buf_add_highlight(0, -1, "Statement", 1 , 5, -1)
  26. command("/th co")
  27. screen:expect([[
  28. these are {1:some} lines |
  29. ^wi{2:th }{4:co}{3:lorful text} |
  30. {5:~ }|
  31. {5:~ }|
  32. {5:~ }|
  33. {5:~ }|
  34. {5:~ }|
  35. {6:search hit BOTTOM, continuing at TOP} |
  36. ]], {
  37. [1] = {{foreground = Screen.colors.Magenta},
  38. {{hi_name = "Constant", kind = "syntax"}}},
  39. [2] = {{background = Screen.colors.Yellow},
  40. {{hi_name = "Search", ui_name = "Search", kind = "ui"}}},
  41. [3] = {{bold = true, foreground = Screen.colors.Brown},
  42. {{hi_name = "Statement", kind = "syntax"}}},
  43. [4] = {{bold = true, background = Screen.colors.Yellow, foreground = Screen.colors.Brown}, {3, 2}},
  44. [5] = {{bold = true, foreground = Screen.colors.Blue1},
  45. {{hi_name = "NonText", ui_name = "EndOfBuffer", kind = "ui"}}},
  46. [6] = {{foreground = Screen.colors.Red},
  47. {{hi_name = "WarningMsg", ui_name = "WarningMsg", kind = "ui"}}},
  48. })
  49. end)
  50. it('work with cleared UI highlights', function()
  51. screen:set_default_attr_ids({
  52. [1] = {{}, {{hi_name = "VertSplit", ui_name = "VertSplit", kind = "ui"}}},
  53. [2] = {{bold = true, foreground = Screen.colors.Blue1},
  54. {{hi_name = "NonText", ui_name = "EndOfBuffer", kind = "ui"}}},
  55. [3] = {{bold = true, reverse = true},
  56. {{hi_name = "StatusLine", ui_name = "StatusLine", kind = "ui"}}} ,
  57. [4] = {{reverse = true},
  58. {{hi_name = "StatusLineNC", ui_name = "StatusLineNC" , kind = "ui"}}},
  59. [5] = {{}, {{hi_name = "StatusLine", ui_name = "StatusLine", kind = "ui"}}},
  60. [6] = {{}, {{hi_name = "StatusLineNC", ui_name = "StatusLineNC", kind = "ui"}}},
  61. })
  62. command("hi clear VertSplit")
  63. command("vsplit")
  64. screen:expect([[
  65. ^ {1:│} |
  66. {2:~ }{1:│}{2:~ }|
  67. {2:~ }{1:│}{2:~ }|
  68. {2:~ }{1:│}{2:~ }|
  69. {2:~ }{1:│}{2:~ }|
  70. {2:~ }{1:│}{2:~ }|
  71. {3:[No Name] }{4:[No Name] }|
  72. |
  73. ]])
  74. command("hi clear StatusLine | hi clear StatuslineNC")
  75. screen:expect([[
  76. ^ {1:│} |
  77. {2:~ }{1:│}{2:~ }|
  78. {2:~ }{1:│}{2:~ }|
  79. {2:~ }{1:│}{2:~ }|
  80. {2:~ }{1:│}{2:~ }|
  81. {2:~ }{1:│}{2:~ }|
  82. {5:[No Name] }{6:[No Name] }|
  83. |
  84. ]])
  85. -- redrawing is done even if visible highlights didn't change
  86. command("wincmd w")
  87. screen:expect([[
  88. {1:│}^ |
  89. {2:~ }{1:│}{2:~ }|
  90. {2:~ }{1:│}{2:~ }|
  91. {2:~ }{1:│}{2:~ }|
  92. {2:~ }{1:│}{2:~ }|
  93. {2:~ }{1:│}{2:~ }|
  94. {6:[No Name] }{5:[No Name] }|
  95. |
  96. ]])
  97. end)
  98. it("work with window-local highlights", function()
  99. screen:set_default_attr_ids({
  100. [1] = {{foreground = Screen.colors.Brown}, {{hi_name = "LineNr", ui_name = "LineNr", kind = "ui"}}},
  101. [2] = {{bold = true, foreground = Screen.colors.Blue1}, {{hi_name = "NonText", ui_name = "EndOfBuffer", kind = "ui"}}},
  102. [3] = {{bold = true, reverse = true}, {{hi_name = "StatusLine", ui_name = "StatusLine", kind = "ui"}}},
  103. [4] = {{reverse = true}, {{hi_name = "StatusLineNC", ui_name = "StatusLineNC", kind = "ui"}}},
  104. [5] = {{background = Screen.colors.Red, foreground = Screen.colors.Grey100}, {{hi_name = "ErrorMsg", ui_name = "LineNr", kind = "ui"}}},
  105. [6] = {{bold = true, reverse = true}, {{hi_name = "MsgSeparator", ui_name = "Normal", kind = "ui"}}},
  106. [7] = {{foreground = Screen.colors.Brown, bold = true, reverse = true}, {6, 1}},
  107. [8] = {{foreground = Screen.colors.Blue1, bold = true, reverse = true}, {6, 2}},
  108. [9] = {{bold = true, foreground = Screen.colors.Brown}, {{hi_name = "Statement", ui_name = "NormalNC", kind = "ui"}}},
  109. [10] = {{bold = true, foreground = Screen.colors.Brown}, {9, 1}},
  110. [11] = {{bold = true, foreground = Screen.colors.Blue1}, {9, 2}}
  111. })
  112. command("set number")
  113. command("split")
  114. -- NormalNC is not applied if not set, to avoid spurious redraws
  115. screen:expect([[
  116. {1: 1 }^ |
  117. {2:~ }|
  118. {2:~ }|
  119. {3:[No Name] }|
  120. {1: 1 } |
  121. {2:~ }|
  122. {4:[No Name] }|
  123. |
  124. ]])
  125. command("set winhl=LineNr:ErrorMsg")
  126. screen:expect([[
  127. {5: 1 }^ |
  128. {2:~ }|
  129. {2:~ }|
  130. {3:[No Name] }|
  131. {1: 1 } |
  132. {2:~ }|
  133. {4:[No Name] }|
  134. |
  135. ]])
  136. command("set winhl=Normal:MsgSeparator,NormalNC:Statement")
  137. screen:expect([[
  138. {7: 1 }{6:^ }|
  139. {8:~ }|
  140. {8:~ }|
  141. {3:[No Name] }|
  142. {1: 1 } |
  143. {2:~ }|
  144. {4:[No Name] }|
  145. |
  146. ]])
  147. command("wincmd w")
  148. screen:expect([[
  149. {10: 1 }{9: }|
  150. {11:~ }|
  151. {11:~ }|
  152. {4:[No Name] }|
  153. {1: 1 }^ |
  154. {2:~ }|
  155. {3:[No Name] }|
  156. |
  157. ]])
  158. end)
  159. it("work with :terminal", function()
  160. screen:set_default_attr_ids({
  161. [1] = {{}, {{hi_name = "TermCursorNC", ui_name = "TermCursorNC", kind = "ui"}}},
  162. [2] = {{foreground = 52479}, {{kind = "term"}}},
  163. [3] = {{bold = true, foreground = 52479}, {{kind = "term"}}},
  164. [4] = {{foreground = 52479}, {2, 1}},
  165. [5] = {{foreground = 4259839}, {{kind = "term"}}},
  166. [6] = {{foreground = 4259839}, {5, 1}},
  167. })
  168. command('enew | call termopen(["'..nvim_dir..'/tty-test"])')
  169. screen:expect([[
  170. ^tty ready |
  171. {1: } |
  172. |
  173. |
  174. |
  175. |
  176. |
  177. |
  178. ]])
  179. thelpers.feed_data('x ')
  180. thelpers.set_fg(45)
  181. thelpers.feed_data('y ')
  182. thelpers.set_bold()
  183. thelpers.feed_data('z\n')
  184. -- TODO(bfredl): check if this distinction makes sense
  185. if iswin() then
  186. screen:expect([[
  187. ^tty ready |
  188. x {5:y z} |
  189. {1: } |
  190. |
  191. |
  192. |
  193. |
  194. |
  195. ]])
  196. else
  197. screen:expect([[
  198. ^tty ready |
  199. x {2:y }{3:z} |
  200. {1: } |
  201. |
  202. |
  203. |
  204. |
  205. |
  206. ]])
  207. end
  208. thelpers.feed_termcode("[A")
  209. thelpers.feed_termcode("[2C")
  210. if iswin() then
  211. screen:expect([[
  212. ^tty ready |
  213. x {6:y}{5: z} |
  214. |
  215. |
  216. |
  217. |
  218. |
  219. |
  220. ]])
  221. else
  222. screen:expect([[
  223. ^tty ready |
  224. x {4:y}{2: }{3:z} |
  225. |
  226. |
  227. |
  228. |
  229. |
  230. |
  231. ]])
  232. end
  233. end)
  234. it("can use independent cterm and rgb colors", function()
  235. -- tell test module to save all attributes (doesn't change nvim options)
  236. screen:set_hlstate_cterm(true)
  237. screen:set_default_attr_ids({
  238. [1] = {{bold = true, foreground = Screen.colors.Blue1}, {foreground = 12}, {{hi_name = "NonText", ui_name = "EndOfBuffer", kind = "ui"}}},
  239. [2] = {{reverse = true, foreground = Screen.colors.Red}, {foreground = 10, italic=true}, {{hi_name = "NonText", ui_name = "EndOfBuffer", kind = "ui"}}},
  240. })
  241. screen:expect([[
  242. ^ |
  243. {1:~ }|
  244. {1:~ }|
  245. {1:~ }|
  246. {1:~ }|
  247. {1:~ }|
  248. {1:~ }|
  249. |
  250. ]])
  251. command("hi NonText guifg=Red gui=reverse ctermfg=Green cterm=italic")
  252. screen:expect([[
  253. ^ |
  254. {2:~ }|
  255. {2:~ }|
  256. {2:~ }|
  257. {2:~ }|
  258. {2:~ }|
  259. {2:~ }|
  260. |
  261. ]])
  262. end)
  263. end)