Beispiel #1
0
void console_up() {

    int i, j, o;

    if (cur_row == 1) {
        /* need to scroll up! */
        console_scroll_up();
        if (cur_row == 1) /* still no change */
            return;
    }

    /* move backwards: */
    o = cursor_off;

    for (j = cur_col; j >= 0; j--) {
        if (screen_copy[cur_row][j])
            o--;
    }

    for (j = 79; j >= 0; j--) {
        if (screen_copy[cur_row-1][j]) {
            if (j <= seek_col) {
                break;
            }
            o--;
        }
    }

    cursor_off = o;

    console_update();

}
Beispiel #2
0
/* Multi line low level line refresh.
 *
 * Rewrite the currently edited line accordingly to the buffer content,
 * cursor position, and number of columns of the terminal. */
static void refreshMultiLine(struct linenoiseState *l) {
    int plen = wcslen(l->prompt);
    int rows = (plen+l->len+l->cols-1)/l->cols; /* rows used by current buf. */
    int rpos = (plen+l->oldpos+l->cols)/l->cols; /* cursor relative row. */
    int rpos2; /* rpos after refresh. */
    int old_rows = l->maxrows;
    int j;

    /* Update maxrows if needed. */
    if (rows > (int)l->maxrows) l->maxrows = rows;

    /* First step: clear all the lines used before. To do so start by
     * going to the last row. */
    if (old_rows-rpos > 0) {
        console_move_down(old_rows - rpos);
    }

    /* Now for every row clear it, go up. */
    for (j = 0; j < old_rows-1; j++) {
        console_move_to_column(0);
        console_erase_to_end_of_line();
        console_move_up(1);
    }

    /* Clean the top line. */
    console_move_to_column(0);
    console_erase_to_end_of_line();
    
    /* Write the prompt and the current buffer content */
    console_write_wchar_string(l->prompt, plen);
    console_write_wchar_string(l->buf, l->len);

    /* If we are at the very end of the screen with our prompt, we need to
     * emit a newline and move the prompt to the first column. */
    if (l->pos &&
        l->pos == l->len &&
        (l->pos+plen) % l->cols == 0)
    {
        console_scroll_up(1);
        console_move_to_column(0);
        rows++;
        if (rows > (int)l->maxrows)
            l->maxrows = rows;
    }

    /* Move cursor to right position. */
    rpos2 = (plen+l->pos+l->cols)/l->cols; /* current cursor relative row. */

    /* Go up till we reach the expected positon. */
    if (rows-rpos2 > 0) {
        console_move_up(rows - rpos2);
    }

    /* Set column. */
    console_move_to_column(((plen+(int)l->pos) % (int)l->cols));

    // console_move_down(1);
    l->oldpos = l->pos;
}
Beispiel #3
0
void console_move_down(int n)
{
  SDL_assert (n > 0);
  row += n;
  while (row >= CONSOLE_ROWS) {
      console_scroll_up(1);
      row --;
  }
}
Beispiel #4
0
void console_newline(void)
{
    current_col = 0;
    if (++current_row == num_rows)
    {
        current_row--;
        console_scroll_up();
    }
}
Beispiel #5
0
void
console_write_wchar_string (const wchar_t *str, size_t len)
{
    for (size_t i = 0; i < len; i ++) {
        if (col == CONSOLE_COLS - 1) {
            row ++;
            col = 0;
            if (row == CONSOLE_ROWS) {
                console_scroll_up (1);
                row --;
            }
        }
        console_write_char (str[i], 0, 0, 0, 0, CONSOLE_COLS - 1);
    }
}
Beispiel #6
0
void console_left() {

    if (cursor_off == 0)
        return;

    cursor_off--;

    /* need scroll? */
    if (cursor_off < file_start) {
        console_scroll_up();
    } else {
        /* just update: */
        console_update();
    }

    seek_col = cur_col;

}
Beispiel #7
0
void
console_write_latin1_string (const char * str)
{
    size_t i = 0;
    while (str[i] != '\0')
    {
        if (col == CONSOLE_COLS - 1)
        {
            row ++;
            col = 0;
            if (row == CONSOLE_ROWS)
            {
                console_scroll_up (1);
                row --;
            }
        }
        console_write_char ((uint8_t)(str[i]), 0, 0, 0, 0, CONSOLE_COLS - 1);
        i = i + 1;
    }
}
Beispiel #8
0
void
console_write_ucs4_string (const uint32_t *str)
{
    size_t i = 0;
    while (str[i] != 0)
    {
        if (col == CONSOLE_COLS - 1)
        {
            row ++;
            col = 0;
            if (row == CONSOLE_ROWS)
            {
                console_scroll_up (1);
                row --;
            }
        }
        console_write_char (str[i], 0, 0, 0, 0, CONSOLE_COLS - 1);
        i = i + 1;
    }
}