1

I'd like to build a menu in ncurses that has section dividers.

My example list looks like this:

Aardvark
Apple
Bee
Cat
Kitten
Kalashnikov
Waffle

What I want is non-selectable dividers. Something like this:

(A) ----
Aardvark
Apple
(B) ----
Bee
(C) ----
Cat
(K) ----
Kitten
Kalashnikov
(W) ----
Waffle

Is there a built-in way to do this?

More specifically, I'm using this ruby gem: https://github.com/eclubb/ncurses-ruby I'd prefer an answer that was generic, but if it can be solved with Ruby awesomeness, that's cool too.

Sauce McBoss
  • 6,567
  • 3
  • 20
  • 22
  • Related question: http://stackoverflow.com/questions/34449492/ncurses-how-to-refresh-a-menu-without-losing-current-position/34453114 – Sauce McBoss Dec 24 '15 at 17:42

1 Answers1

2

Assuming you are talking about the ncurses menu library (as "built-in"), you can make a nonselectable item using set_item_opts.

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
  • Perfect again! Caught this question and my other (somewhat related) one: http://stackoverflow.com/questions/34449492/ncurses-how-to-refresh-a-menu-without-losing-current-position/34453114#34453114 – Sauce McBoss Dec 24 '15 at 17:41
  • After having experimented with this a bit, it looks like I can still move over the item with the cursor, even though it's not "selectable". Is there a built-in way of having these items be skipped by the menu_driver REQ__ITEM method? – Sauce McBoss Dec 25 '15 at 05:59
  • 1
    You would do this in the driver callbacks (the driver only delivers events, which the callbacks can interpret as needed). – Thomas Dickey Dec 25 '15 at 10:10
  • Thanks - that works for me. I ended up just calling `REQ__ITEM` again whenever the current item's `user_object` was nil. (Plus a bit of other logic to handle the first item in the list.) – Sauce McBoss Dec 27 '15 at 19:43