Exemplo n.º 1
0
void input_init(void)
{
  log_msg("INIT", "INPUT");
  tk = termkey_new(0,0);
  termkey_set_flags(tk, TERMKEY_FLAG_UTF8 | TERMKEY_CANON_DELBS);

  uv_poll_init(eventloop(), &poll_handle, 0);
  uv_poll_start(&poll_handle, UV_READABLE, input_check);
}
Exemplo n.º 2
0
TermKey *termkey_new(int fd, int flags)
{
  TermKey *tk = termkey_alloc();
  if(!tk)
    return NULL;

  tk->fd = fd;

  if(!(flags & (TERMKEY_FLAG_RAW|TERMKEY_FLAG_UTF8))) {
    char *e;

    /* Most OSes will set .UTF-8. Some will set .utf8. Try to be fairly
     * generous in parsing these
     */
    if(((e = getenv("LANG")) || (e = getenv("LC_MESSAGES")) || (e = getenv("LC_ALL"))) &&
       (e = strchr(e, '.')) && e++ &&
       (strcaseeq(e, "UTF-8") || strcaseeq(e, "UTF8")))
      flags |= TERMKEY_FLAG_UTF8;
    else
      flags |= TERMKEY_FLAG_RAW;
  }

  termkey_set_flags(tk, flags);

  const char *term = getenv("TERM");

  if(!termkey_init(tk, term))
    goto abort;

  if(!(flags & TERMKEY_FLAG_NOSTART) && !termkey_start(tk))
    goto abort;

  return tk;

abort:
  free(tk);
  return NULL;
}
Exemplo n.º 3
0
TermKey *termkey_new_abstract(const char *term, int flags)
{
  TermKey *tk = termkey_alloc();
  if(!tk)
    return NULL;

  tk->fd = -1;

  termkey_set_flags(tk, flags);

  if(!termkey_init(tk, term)) {
    free(tk);
    return NULL;
  }

  if(!(flags & TERMKEY_FLAG_NOSTART) && !termkey_start(tk))
    goto abort;

  return tk;

abort:
  free(tk);
  return NULL;
}