hlstate_spec.lua 13 KB

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