Exemple #1
0
static int debug_do_key_edit(SDL_KeyboardEvent key)
{
  SDL_Keysym k;

  k = key.keysym;

  if(k.sym == SDLK_RETURN) {
    if(edit_finish(win_get_exwin()) == EDIT_SUCCESS) {
      win_set_exwin(EDIT_EXIT);
      keymode = KEY_NORMAL;
    }
  } else if(k.sym == SDLK_ESCAPE) {
    win_set_exwin(EDIT_EXIT);
    keymode = KEY_NORMAL;
  } else if(k.sym == SDLK_LEFT) {
    edit_move(EDIT_LEFT);
  } else if(k.sym == SDLK_RIGHT) {
    edit_move(EDIT_RIGHT);
  } else if(k.sym == SDLK_BACKSPACE) {
    edit_remove_char();
  }

  display_swap_screen();
  return 0;
}
Exemple #2
0
void edit_remove_char()
{
  char tmp[80];
  if(edit.pos == 0) return;

  strcpy(tmp, &edit.text[edit.pos]);
  strcpy(&edit.text[edit.pos-1], tmp);
  edit_move(EDIT_LEFT);
}
Exemple #3
0
void edit_insert_char(int c)
{
  char tmp[80];
  if(strlen(edit.text) >= edit.len) return;
  
  strcpy(tmp, &edit.text[edit.pos]);
  edit.text[edit.pos] = c;
  strcpy(&edit.text[edit.pos+1], tmp);
  edit_move(EDIT_RIGHT);
}
Exemple #4
0
static inline void
print_to_widget (WEdit * edit, long row, int start_col, int start_col_real,
                 long end_col, struct line_s line[], char *status, int bookmarked)
{
    struct line_s *p;

    int x = start_col_real;
    int x1 = start_col + EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
    int y = row + EDIT_TEXT_VERTICAL_OFFSET;
    int cols_to_skip = abs (x);
    int i;
    int wrap_start;
    int len;

    tty_setcolor (EDITOR_NORMAL_COLOR);
    if (bookmarked != 0)
        tty_setcolor (bookmarked);

    len = end_col + 1 - start_col;
    wrap_start = option_word_wrap_line_length + edit->start_col;

    if (len > 0 && edit->widget.y + y >= 0)
    {
        if (!show_right_margin || wrap_start > end_col)
            tty_draw_hline (edit->widget.y + y, edit->widget.x + x1, ' ', len);
        else if (wrap_start < 0)
        {
            tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR);
            tty_draw_hline (edit->widget.y + y, edit->widget.x + x1, ' ', len);
        }
        else
        {
            if (wrap_start > 0)
                tty_draw_hline (edit->widget.y + y, edit->widget.x + x1, ' ', wrap_start);

            len -= wrap_start;
            if (len > 0)
            {
                tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR);
                tty_draw_hline (edit->widget.y + y, edit->widget.x + x1 + wrap_start, ' ', len);
            }
        }
    }

    if (option_line_state)
    {
        tty_setcolor (LINE_STATE_COLOR);
        for (i = 0; i < LINE_STATE_WIDTH; i++)
        {
            edit_move (x1 + i - option_line_state_width, y);
            if (status[i] == '\0')
                status[i] = ' ';
            tty_print_char (status[i]);
        }
    }

    edit_move (x1, y);
    p = line;
    i = 1;
    while (p->ch)
    {
        int style;
        unsigned int textchar;
        int color;

        if (cols_to_skip)
        {
            p++;
            cols_to_skip--;
            continue;
        }

        style = p->style & 0xFF00;
        textchar = p->ch;
        color = p->style >> 16;

        if (style & MOD_ABNORMAL)
        {
            /* Non-printable - use black background */
            color = 0;
        }

        if (style & MOD_WHITESPACE)
        {
            if (style & MOD_MARKED)
            {
                textchar = ' ';
                tty_setcolor (EDITOR_MARKED_COLOR);
            }
            else
            {
#if 0
                if (color != EDITOR_NORMAL_COLOR)
                {
                    textchar = ' ';
                    tty_lowlevel_setcolor (color);
                }
                else
#endif
                    tty_setcolor (EDITOR_WHITESPACE_COLOR);
            }
        }
        else
        {
            if (style & MOD_BOLD)
            {
                tty_setcolor (EDITOR_BOLD_COLOR);
            }
            else if (style & MOD_MARKED)
            {
                tty_setcolor (EDITOR_MARKED_COLOR);
            }
            else
            {
                tty_lowlevel_setcolor (color);
            }
        }
        if (show_right_margin)
        {
            if (i > option_word_wrap_line_length + edit->start_col)
                tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR);
            i++;
        }
        tty_print_anychar (textchar);
        p++;
    }
}
Exemple #5
0
static void
print_to_widget (WEdit *edit, long row, int start_col, int start_col_real,
		 long end_col, unsigned int line[])
{
    unsigned int *p;

    int x = start_col_real + EDIT_TEXT_HORIZONTAL_OFFSET;
    int x1 = start_col + EDIT_TEXT_HORIZONTAL_OFFSET;
    int y = row + EDIT_TEXT_VERTICAL_OFFSET;
    int cols_to_skip = abs (x);

    set_color (EDITOR_NORMAL_COLOR);
    edit_move (x1, y);
    hline (' ', end_col + 1 - EDIT_TEXT_HORIZONTAL_OFFSET - x1);

    edit_move (x1 + FONT_OFFSET_X, y + FONT_OFFSET_Y);
    p = line;

    while (*p) {
	int style;
	int textchar;
	int color;

	if (cols_to_skip) {
	    p++;
	    cols_to_skip--;
	    continue;
	}

	style = *p & 0xFF00;
	textchar = *p & 0xFF;
	color = *p >> 16;

	if (style & MOD_ABNORMAL) {
	    /* Non-printable - use black background */
	    color = 0;
	}

	if (style & MOD_WHITESPACE) {
	    if (style & MOD_MARKED) {
		textchar = ' ';
		set_color (EDITOR_MARKED_COLOR);
	    } else {
#if 0
		if (color != EDITOR_NORMAL_COLOR) {
		    textchar = ' ';
		    lowlevel_set_color (color);
		} else
#endif
		    set_color (EDITOR_WHITESPACE_COLOR);
	    }
	} else {
	    if (style & MOD_BOLD) {
		set_color (EDITOR_BOLD_COLOR);
	    } else if (style & MOD_MARKED) {
		set_color (EDITOR_MARKED_COLOR);
	    } else {
		lowlevel_set_color (color);
	    }
	}

	addch (textchar);
	p++;
    }
}
Exemple #6
0
static inline void
edit_status_window (WEdit * edit)
{
    int y, x;
    int cols = edit->widget.cols;

    tty_setcolor (STATUSBAR_COLOR);

    if (cols > 5)
    {
        const char *fname = N_("NoName");
        char *full_fname = NULL;

        if (edit->filename_vpath != NULL)
        {
            full_fname = vfs_path_to_str (edit->filename_vpath);
            fname = x_basename (full_fname);
        }
#ifdef ENABLE_NLS
        else
            fname = _(fname);
#endif

        edit_move (2, 0);
        tty_printf ("[%s]", str_term_trim (fname, edit->widget.cols - 8 - 6));
        g_free (full_fname);
    }

    tty_getyx (&y, &x);
    x -= edit->widget.x;
    x += 4;
    if (x + 6 <= cols - 2 - 6)
    {
        edit_move (x, 0);
        tty_printf ("[%c%c%c%c]",
                    edit->mark1 != edit->mark2 ? (edit->column_highlight ? 'C' : 'B') : '-',
                    edit->modified ? 'M' : '-',
                    macro_index < 0 ? '-' : 'R', edit->overwrite == 0 ? '-' : 'O');
    }

    if (cols > 30)
    {
        edit_move (2, edit->widget.lines - 1);
        tty_printf ("%3ld %5ld/%ld %6ld/%ld",
                    edit->curs_col + edit->over_col,
                    edit->curs_line + 1, edit->total_lines + 1, edit->curs1, edit->last_byte);
    }

    /*
     * If we are at the end of file, print <EOF>,
     * otherwise print the current character as is (if printable),
     * as decimal and as hex.
     */
    if (cols > 46)
    {
        edit_move (32, edit->widget.lines - 1);
        if (edit->curs1 >= edit->last_byte)
            tty_print_string ("[<EOF>       ]");
#ifdef HAVE_CHARSET
        else if (edit->utf8)
        {
            unsigned int cur_utf;
            int cw = 1;

            cur_utf = edit_get_utf (edit, edit->curs1, &cw);
            if (cw <= 0)
                cur_utf = edit_get_byte (edit, edit->curs1);
            tty_printf ("[%05d 0x%04X]", cur_utf, cur_utf);
        }
#endif
        else
        {
            unsigned char cur_byte;

            cur_byte = edit_get_byte (edit, edit->curs1);
            tty_printf ("[%05d 0x%04X]", (unsigned int) cur_byte, (unsigned int) cur_byte);
        }
    }
}