Exemple #1
0
/* u2_term_get_blew(): return window size [columns rows].
*/
u2_noun
u2_term_get_blew(c3_l tid_l)
{
  u2_utty*       uty_u = _term_ef_get(tid_l);
  c3_l           col_l, row_l;

#if 1
  struct winsize siz_u;
  if ( uty_u && (0 == ioctl(uty_u->fid_i, TIOCGWINSZ, &siz_u)) ) {
    col_l = siz_u.ws_col;
    row_l = siz_u.ws_row;
  } else {
    col_l = 80;
    row_l = 24;
  }
#else
  {
    c3_i col_i, row_i;

    uv_tty_get_winsize(&uty_u->wax_u, &col_i, &row_i);
    col_l = col_i;
    row_l = row_i;
  }
#endif
  if ( uty_u ) {
    uty_u->tat_u.siz.col_l = col_l;
    uty_u->tat_u.siz.row_l = row_l;
  }

  return u2nc(col_l, row_l);
}
Exemple #2
0
Fichier : tty.c Projet : luvit/luv
static int luv_tty_get_winsize(lua_State* L) {
    uv_tty_t* handle = luv_check_tty(L, 1);
    int width, height;
    int ret = uv_tty_get_winsize(handle, &width, &height);
    if (ret < 0) return luv_error(L, ret);
    lua_pushinteger(L, width);
    lua_pushinteger(L, height);
    return 2;
}
Exemple #3
0
SCM TTY::GetWinSize(SCM id){
  assert_object_type(id);
  TTY * t = (TTY *)get_object(id);
  assert(t!=NULL);
  int width = 0;
  int height = 0;
  int r = uv_tty_get_winsize(GetHandle(t), &width, &height);
  if(r) Logger::Err("uv_tty_get_winsize failed! : %d", r);
  return scm_list_2(scm_from_int(width), scm_from_int(height));
}
Exemple #4
0
static PyObject *
TTY_func_get_winsize(TTY *self)
{
    int r, width, height;

    RAISE_IF_HANDLE_CLOSED(self, PyExc_HandleClosedError, NULL);

    r = uv_tty_get_winsize((uv_tty_t *)UV_HANDLE(self), &width, &height);
    if (r != 0) {
        RAISE_UV_EXCEPTION(UV_HANDLE_LOOP(self), PyExc_TTYError);
        return NULL;
    }

    return Py_BuildValue("(ii)", width, height);
}
Exemple #5
0
static void sig_handler(int signum)
{
  switch (signum) {
  case SIGWINCH: {
    int width, height;
    uv_tty_get_winsize(&tty, &width, &height);
    fprintf(stderr, "rows: %d, cols: %d\n", height, width);
    return;
  }
  case SIGHUP:
    exit(42);  // arbitrary exit code to test against
    return;
  default:
    return;
  }
}
Exemple #6
0
int luv_tty_get_winsize(lua_State* L) {
  int before = lua_gettop(L);
  uv_tty_t* handle = (uv_tty_t*)luv_checkudata(L, 1, "tty");

  int width, height;

  if (uv_tty_get_winsize(handle, &width, &height)) {
    uv_err_t err = uv_last_error(uv_default_loop());
    return luaL_error(L, "tcp_get_winsize: %s", uv_strerror(err));
  }

  lua_pushinteger(L, width);
  lua_pushinteger(L, height);
  assert(lua_gettop(L) == before + 2);
  return 2;
}
Exemple #7
0
int main() {
    loop = uv_default_loop();

    uv_tty_init(loop, &tty, 1, 0);
    uv_tty_set_mode(&tty, 0);
    
    if (uv_tty_get_winsize(&tty, &width, &height)) {
        fprintf(stderr, "Could not get TTY information\n");
        uv_tty_reset_mode();
        return 1;
    }

    fprintf(stderr, "Width %d, height %d\n", width, height);
    uv_timer_init(loop, &tick);
    uv_timer_start(&tick, update, 200, 200);
    return uv_run(loop, UV_RUN_DEFAULT);
}
Exemple #8
0
static void sigwinch_cb(uv_signal_t *handle, int signum)
{
  int width, height;
  uv_tty_get_winsize(&tty_out, &width, &height);
  fprintf(stderr, "rows: %d, cols: %d\n", height, width);
}
Exemple #9
0
int main(int argc, char **argv)
{
  if (!owns_tty()) {
    fprintf(stderr, "process does not own the terminal\n");
    exit(2);
  }

  if (!is_terminal(stdin)) {
    fprintf(stderr, "stdin is not a terminal\n");
    exit(2);
  }

  if (!is_terminal(stdout)) {
    fprintf(stderr, "stdout is not a terminal\n");
    exit(2);
  }

  if (!is_terminal(stderr)) {
    fprintf(stderr, "stderr is not a terminal\n");
    exit(2);
  }

  if (argc > 1) {
    errno = 0;
    int count = (int)strtol(argv[1], NULL, 10);
    if (errno != 0) {
      abort();
    }
    count = (count < 0 || count > 99999) ? 0 : count;
    for (int i = 0; i < count; i++) {
      printf("line%d\n", i);
    }
    fflush(stdout);
    return 0;
  }

  int interrupted = 0;
  uv_prepare_t prepare;
  uv_prepare_init(uv_default_loop(), &prepare);
  uv_prepare_start(&prepare, prepare_cb);
#ifndef WIN32
  uv_tty_init(uv_default_loop(), &tty, fileno(stderr), 1);
#else
  uv_tty_init(uv_default_loop(), &tty, fileno(stdin), 1);
  uv_tty_init(uv_default_loop(), &tty_out, fileno(stdout), 0);
  int width, height;
  uv_tty_get_winsize(&tty_out, &width, &height);
#endif
  uv_tty_set_mode(&tty, UV_TTY_MODE_RAW);
  tty.data = &interrupted;
  uv_read_start(STRUCT_CAST(uv_stream_t, &tty), alloc_cb, read_cb);
#ifndef WIN32
  struct sigaction sa;
  sigemptyset(&sa.sa_mask);
  sa.sa_flags = 0;
  sa.sa_handler = sig_handler;
  sigaction(SIGHUP, &sa, NULL);
  sigaction(SIGWINCH, &sa, NULL);
#else
  uv_signal_t sigwinch_watcher;
  uv_signal_init(uv_default_loop(), &sigwinch_watcher);
  uv_signal_start(&sigwinch_watcher, sigwinch_cb, SIGWINCH);
#endif
  uv_run(uv_default_loop(), UV_RUN_DEFAULT);

#ifndef WIN32
  // XXX: Without this the SIGHUP handler is skipped on some systems.
  sleep(100);
#endif

  return 0;
}
Exemple #10
0
extern "C" int
rust_uv_tty_get_winsize(uv_tty_t *tty, int *width, int *height) {
    return uv_tty_get_winsize(tty, width, height);
}