~lucasemmoreira/janet-ncurses

8be85b4344613aa170860ce52a8c4e5881589c52 — Lucas Moreira 1 year, 6 months ago 64095ee feature/win-info
Add: begin and max window information
2 files changed, 34 insertions(+), 0 deletions(-)

M janet-ncurses.c
M test/term-info.janet
M janet-ncurses.c => janet-ncurses.c +24 -0
@@ 99,6 99,28 @@ static Janet jgetyx(int32_t argc, Janet *argv){
  return janet_wrap_array(arr);
}

static Janet jgetbegyx(int32_t argc, Janet *argv){
  janet_fixarity(argc, 1);
  WINDOW *win = (WINDOW *) janet_getpointer(argv, 0);
  int y, x; 
  getbegyx(win, y, x);
  JanetArray *arr = janet_array(2);
  janet_array_push(arr, janet_wrap_integer(y));
  janet_array_push(arr, janet_wrap_integer(x));
  return janet_wrap_array(arr);
}

static Janet jgetmaxyx(int32_t argc, Janet *argv){
  janet_fixarity(argc, 1);
  WINDOW *win = (WINDOW *) janet_getpointer(argv, 0);
  int y, x; 
  getmaxyx(win, y, x);
  JanetArray *arr = janet_array(2);
  janet_array_push(arr, janet_wrap_integer(y));
  janet_array_push(arr, janet_wrap_integer(x));
  return janet_wrap_array(arr);
}

static const JanetReg cfuns[] = {
  {"initscr", jinitscr, "initializes the screen"},
  {"cbreak", jcbreak, "forces C-c to close program"},


@@ 113,6 135,8 @@ static const JanetReg cfuns[] = {
  {"mvwprintw", jmvwprintw, "moves inside a window to print something"},
  {"wprintw", jwprintw, "print onto a window - last cursor point"},
  {"getyx", jgetyx, "gets position of the cursor"},
  {"getbegyx", jgetbegyx, "gets begin position of the window"},
  {"getmaxyx", jgetmaxyx, "gets end position of the window"},
  {NULL, NULL, NULL}
};


M test/term-info.janet => test/term-info.janet +10 -0
@@ 24,6 24,16 @@

(nc/wrefresh win)

(def info (nc/getbegyx win))

(nc/mvwprintw win 3 2 (string (get info 1) " " (get info 0)))

(def info (nc/getmaxyx win))

(nc/mvwprintw win 4 2 (string (get info 1) " " (get info 0)))

(nc/wrefresh win)

(nc/getch)

(nc/endwin)