~lucasemmoreira/janet-ncurses

facc016399db116a1ab6cf1a8f2d383fe34b033a — Lucas Moreira 1 year, 6 months ago 645c9dc feature/menu
Add: working items
2 files changed, 7 insertions(+), 6 deletions(-)

M janet-ncurses.c
M test/menu.janet
M janet-ncurses.c => janet-ncurses.c +5 -5
@@ 114,7 114,6 @@ static Janet jKEY_UP(int32_t argc, Janet *argv){
  return janet_wrap_integer(KEY_UP);
}


// color and attribute stuff
static Janet jstart_color(int32_t argc, Janet *argv){
  janet_fixarity(argc, 0);


@@ 124,13 123,14 @@ static Janet jstart_color(int32_t argc, Janet *argv){

static Janet jitems(int32_t argc, Janet *argv){
  janet_fixarity(argc, 1);
  char *choices[] = {"Test", "Test2"};
  JanetArray *jarray = janet_getarray(argv, 0);
  ITEM **items;
  int n_choices = sizeof(choices)/sizeof(choices[0]);
  int n_choices = jarray->count;
  int i;
  items = (ITEM **) calloc(n_choices + 1, sizeof(ITEM *));
  for(i = 0;i < n_choices;i++){
    items[i] = new_item(choices[i], choices[i]);
  for(i = 0; i < n_choices; i++){
    const uint8_t *value = janet_unwrap_string(jarray->data[i]);
    items[i] = new_item(value, value);
  }
  items[n_choices] = (ITEM *) NULL;
  return janet_wrap_pointer(items);

M test/menu.janet => test/menu.janet +2 -1
@@ 12,6 12,8 @@

(def items (nc/items choices))

(nc/refresh)

(def menu (nc/new_menu items))

(nc/post_menu menu)


@@ 20,7 22,6 @@

(while true
  (let [c (nc/getch)]
    (nc/mvwprintw (nc/stdscr) 5 1 (string c (nc/KEY_DOWN) (nc/KEY_UP)))
    (case c 
      (nc/KEY_DOWN) (nc/menu_driver menu (nc/REQ_DOWN_ITEM))
      (nc/KEY_UP) (nc/menu_driver menu (nc/REQ_UP_ITEM)))))