Ejemplo n.º 1
0
/* _term_it_show_clear(): clear to the beginning of the current line.
*/
static void
_term_it_show_clear(u2_utty* uty_u)
{
  u2_utat* tat_u = &uty_u->tat_u;

  if ( tat_u->siz.col_l ) {
    c3_w     ful_w = tat_u->mir.cus_w / tat_u->siz.col_l;

    if ( 0 != tat_u->mir.cus_w &&
         ful_w * tat_u->siz.col_l == tat_u->mir.cus_w )
    {
      ful_w--;
    }

    while ( ful_w-- ) {
      _term_it_write_txt(uty_u, uty_u->ufo_u.out.cuu1_y);
    }

    _term_it_write_str(uty_u, "\r");
    _term_it_write_txt(uty_u, uty_u->ufo_u.out.ed_y);

    tat_u->mir.len_w = 0;
    tat_u->mir.cus_w = 0;
  }
}
Ejemplo n.º 2
0
/* _term_it_show_cursor(): set current line, transferring pointer.
*/
static void
_term_it_show_cursor(u2_utty* uty_u, c3_w cur_w)
{
  if ( cur_w < uty_u->tat_u.mir.cus_w ) {
    c3_w dif_w = (uty_u->tat_u.mir.cus_w - cur_w);

    while ( dif_w-- ) {
      _term_it_write_txt(uty_u, uty_u->ufo_u.out.cub1_y);
    }
  }
  else if ( cur_w > uty_u->tat_u.mir.cus_w ) {
    c3_w dif_w = (cur_w - uty_u->tat_u.mir.cus_w);

    while ( dif_w-- ) {
      _term_it_write_txt(uty_u, uty_u->ufo_u.out.cuf1_y);
    }
  }
  uty_u->tat_u.mir.cus_w = cur_w;
}
Ejemplo n.º 3
0
/* _term_ef_blit(): send blit to terminal.
*/
static void
_term_ef_blit(u2_utty* uty_u,
              u2_noun  blt)
{
  switch ( u2h(blt) ) {
    default: break;
    case c3__bel: {
      if ( u2_no == u2_Host.ops_u.dem ) {
        _term_it_write_txt(uty_u, uty_u->ufo_u.out.bel_y);
      }
    } break;

    case c3__clr: {
      if ( u2_no == u2_Host.ops_u.dem ) {
        _term_it_show_blank(uty_u);
        _term_it_refresh_line(uty_u);
      }
    } break;

    case c3__hop: {
      if ( u2_no == u2_Host.ops_u.dem ) {
        _term_it_show_cursor(uty_u, u2t(blt));
      }
    } break;

    case c3__lin: {
      u2_noun lin = u2t(blt);
      c3_w    len_w = u2_ckb_lent(u2k(lin));
      c3_w*   lin_w = malloc(4 * len_w);

      {
        c3_w i_w;

        for ( i_w = 0; u2_nul != lin; i_w++, lin = u2t(lin) ) {
          lin_w[i_w] = u2_cr_word(0, u2h(lin));
        }
      }

      if ( u2_no == u2_Host.ops_u.dem ) {
        _term_it_show_clear(uty_u);
        _term_it_show_line(uty_u, lin_w, len_w);
      } else {
        while ( uty_u->out_u ) {
          u2_ubuf* out_u = uty_u->out_u;
          uty_u->out_u = uty_u->out_u->nex_u;
          if ( 0 == uty_u->out_u ) {
            c3_assert(out_u == uty_u->tou_u);
            uty_u->tou_u = 0;
          }
          free(out_u);
        }
        _term_it_show_line(uty_u, lin_w, len_w);
      }
    } break;

    case c3__mor: {
      if ( u2_no == u2_Host.ops_u.dem ) {
        _term_it_show_more(uty_u);
      } else {
        _term_it_show_more(uty_u);
        _term_it_do_writes(uty_u);
      }
    } break;

    case c3__sav: {
      _term_it_save(u2k(u2h(u2t(blt))), u2k(u2t(u2t(blt))));
    } break;
  }
  u2z(blt);

  return;
}
Ejemplo n.º 4
0
/* _term_io_suck_char(): process a single character.
*/
static void
_term_io_suck_char(u2_utty* uty_u, c3_y cay_y)
{
  u2_utat* tat_u = &uty_u->tat_u;

  // uL(fprintf(uH, "suck-char %x\n", cay_y));

  if ( u2_yes == tat_u->esc.ape ) {
    if ( u2_yes == tat_u->esc.bra ) {
      switch ( cay_y ) {
        default: {
          _term_it_write_txt(uty_u, uty_u->ufo_u.out.bel_y);
          break;
        }
        case 'A': _term_io_belt(uty_u, u2nc(c3__aro, 'u')); break;
        case 'B': _term_io_belt(uty_u, u2nc(c3__aro, 'd')); break;
        case 'C': _term_io_belt(uty_u, u2nc(c3__aro, 'r')); break;
        case 'D': _term_io_belt(uty_u, u2nc(c3__aro, 'l')); break;
      }
      tat_u->esc.ape = tat_u->esc.bra = u2_no;
    }
    else {
      if ( (cay_y >= 'a') && (cay_y <= 'z') ) {
        tat_u->esc.ape = u2_no;
        _term_io_belt(uty_u, u2nc(c3__met, cay_y));
      }
      else if ( ('[' == cay_y) || ('O' == cay_y) ) {
        tat_u->esc.bra = u2_yes;
      }
      else {
        tat_u->esc.ape = u2_no;

        _term_it_write_txt(uty_u, uty_u->ufo_u.out.bel_y);
      }
    }
  }
  else if ( 0 != tat_u->fut.wid_w ) {
    tat_u->fut.syb_y[tat_u->fut.len_w++] = cay_y;

    if ( tat_u->fut.len_w == tat_u->fut.wid_w ) {
      u2_noun huv = u2_ci_bytes(tat_u->fut.wid_w, tat_u->fut.syb_y);
      u2_noun wug;

      // uL(fprintf(uH, "muck-utf8 len %d\n", tat_u->fut.len_w));
      // uL(fprintf(uH, "muck-utf8 %x\n", huv));
      wug = u2_do("turf", huv);
      // uL(fprintf(uH, "muck-utf32 %x\n", tat_u->fut.len_w));

      tat_u->fut.len_w = tat_u->fut.wid_w = 0;
      _term_io_belt(uty_u, u2nt(c3__txt, wug, u2_nul));
    }
  }
  else {
    if ( (cay_y >= 32) && (cay_y < 127) ) {
      _term_io_belt(uty_u, u2nt(c3__txt, cay_y, u2_nul));
    }
    else if ( 0 == cay_y ) {
      _term_it_write_txt(uty_u, uty_u->ufo_u.out.bel_y);
    }
    else if ( 8 == cay_y || 127 == cay_y ) {
      _term_io_belt(uty_u, u2nc(c3__bac, u2_nul));
    }
    else if ( 13 == cay_y ) {
      _term_io_belt(uty_u, u2nc(c3__ret, u2_nul));
    }
    else if ( cay_y <= 26 ) {
      _term_io_belt(uty_u, u2nc(c3__ctl, ('a' + (cay_y - 1))));
    }
    else if ( 27 == cay_y ) {
      tat_u->esc.ape = u2_yes;
    }
    else if ( cay_y >= 128 ) {
      tat_u->fut.len_w = 1;
      tat_u->fut.syb_y[0] = cay_y;

      if ( cay_y <= 224 ) {
        tat_u->fut.wid_w = 2;
      } else if ( cay_y <= 240 ) {
        tat_u->fut.wid_w = 3;
      } else tat_u->fut.wid_w = 4;
    }
  }
}
Ejemplo n.º 5
0
/* _term_it_show_blank(): blank the screen.
*/
static void
_term_it_show_blank(u2_utty* uty_u)
{
  _term_it_write_txt(uty_u, uty_u->ufo_u.out.clear_y);
  uty_u->tat_u.mir.cus_w = 0;
}
Ejemplo n.º 6
0
/* _term_it_write_str(): write null-terminated string, retaining pointer.
*/
static void
_term_it_write_str(u2_utty*    uty_u,
                   const c3_c* str_c)
{
  _term_it_write_txt(uty_u, (const c3_y*) str_c);
}
Ejemplo n.º 7
0
Archivo: term.c Proyecto: laanwj/urbit
/* _term_ef_blit(): send blit to terminal.
*/
static void
_term_ef_blit(u3_utty* uty_u,
              u3_noun  blt)
{
  switch ( u3h(blt) ) {
    default: break;
    case c3__bel: {
      if ( c3n == u3_Host.ops_u.dem ) {
        _term_it_write_txt(uty_u, uty_u->ufo_u.out.bel_y);
      }
    } break;

    case c3__clr: {
      if ( c3n == u3_Host.ops_u.dem ) {
        _term_it_show_blank(uty_u);
        _term_it_refresh_line(uty_u);
      }
    } break;

    case c3__hop: {
      if ( c3n == u3_Host.ops_u.dem ) {
        _term_it_show_cursor(uty_u, u3t(blt));
      }
    } break;

    case c3__lin: {
      u3_noun lin = u3t(blt);
      c3_w    len_w = u3kb_lent(u3k(lin));
      c3_w*   lin_w = c3_malloc(4 * len_w);

      {
        c3_w i_w;

        for ( i_w = 0; u3_nul != lin; i_w++, lin = u3t(lin) ) {
          lin_w[i_w] = u3r_word(0, u3h(lin));
        }
      }

      if ( c3n == u3_Host.ops_u.dem ) {
        _term_it_show_clear(uty_u);
        _term_it_show_line(uty_u, lin_w, len_w);
      } else {
        _term_it_show_line(uty_u, lin_w, len_w);
      }
    } break;

    case c3__mor: {
      _term_it_show_more(uty_u);
    } break;

    case c3__sav: {
      _term_it_save(u3k(u3h(u3t(blt))), u3k(u3t(u3t(blt))));
    } break;

    case c3__sag: {
      u3_noun pib = u3k(u3t(u3t(blt)));
      u3_noun jam;

      fprintf(stderr, "jamming...\r\n");
      jam = u3ke_jam(pib);
      fprintf(stderr, "jammed.\r\n");

      _term_it_save(u3k(u3h(u3t(blt))), jam);
    } break;
  }
  u3z(blt);

  return;
}