/*! * This function does not check the validity of its bounds. * * \param row The row coordinate of the top of the box. * \param column The column coordinate of the left side of the box. * \param width The width of the box. * \param height The height of the box. */ void draw_border( int row, int column, int width, int height ) { int i, j; // Draw the corners first. Looks interesting to watch. position_cursor( row, column ); std::cout << "\xC9"; position_cursor( row + height - 1, column + width - 1 ); std::cout << "\xBC"; position_cursor( row, column + width - 1 ); std::cout << "\xBB"; position_cursor( row + height - 1, column ); std::cout << "\xC8"; // Draw top and bottom of the border. i = column + 1; position_cursor( row, i ); for( ; i < column + width - 1; i++ ) std::cout << "\xCD"; i = column + 1; position_cursor( row + height - 1, i ); for( ; i < column + width - 1; i++ ) std::cout << "\xCD"; // Draw the sides of the border. j = row + 1; for( ; j < row + height - 1; j++ ) { position_cursor( j, column ); std::cout << "\xBA"; position_cursor( j, column + width - 1 ); std::cout << "\xBA"; } }
/*! * The following function works similarly to fill_box except that it also draws a black * "shadow" across the bottom of the box and down the right side of the box. This shadow * is one row high and two columns wide. This function assumes it will fit. * * \param row The row coordinate of the top of the box. * \param column The column coordinate of the left side of the box. * \param width The width of the box. * \param height The height of the box. */ void fill_shadowed_box( int row, int column, int width, int height ) { int index; // Fill the main region in the current color. fill_box( row, column, width, height ); // Draw the shadow along the bottom. Assume it fits. set_color( B_BLACK ); position_cursor( row + height, column + width + 1 ); for( index = column + 2; index <= column + width + 1; index++ ) std::cout << " "; // Draw the shadow down the right side. Assume it fits. for( index = row + 1; index <= row + height; index++ ) { position_cursor( index, column + width ); std::cout << " "; } }
/*! * This function does not check the validity of its bounds. The color used is the * currently selected color. * * \param row The row coordinate of the top of the box. * \param column The column coordinate of the left side of the box. * \param width The width of the box. * \param height The height of the box. */ void fill_box( int row, int column, int width, int height ) { int i, j; // Nested loops do the trick slowly, but correctly. for( j = row; j <= row + height - 1; j++) { position_cursor( j, column ); for (i = column; i <= column + width - 1; i++) { std::cout << " "; } } }
static void really_update (SLrline_Type *rli, int new_curs_position) { SLuchar_Type *b, *bmax, *p, *pmax; unsigned int col, max_col; int utf8_mode = rli->flags & SL_RLINE_UTF8_MODE; col = 0; max_col = rli->edit_width-1; b = rli->old_upd; p = rli->new_upd; bmax = b + rli->old_upd_len; pmax = p + rli->new_upd_len; while (col < max_col) { SLwchar_Type pch, bch; SLuchar_Type *p1, *b1; unsigned int plen, blen; b1 = compute_char_width (b, bmax, utf8_mode, &blen, &bch, NULL); p1 = compute_char_width (p, pmax, utf8_mode, &plen, &pch, NULL); if ((p1 != p) && ((b1-b) == (p1-p)) && (bch == pch)) { col += plen; b = b1; p = p1; continue; } spit_out (rli, p, pmax, col); col = rli->curs_pos; if (col < rli->last_nonblank_column) erase_eol (rli); rli->last_nonblank_column = col; break; } position_cursor (rli, new_curs_position); /* update finished, so swap */ rli->old_upd_len = rli->new_upd_len; p = rli->old_upd; rli->old_upd = rli->new_upd; rli->new_upd = p; }
static void spit_out(SLrline_Type *rli, SLuchar_Type *p, SLuchar_Type *pmax, int col) { int utf8_mode = rli->flags & SL_RLINE_UTF8_MODE; position_cursor (rli, col); while (p < pmax) { SLuchar_Type *p1; unsigned int dcol; p1 = compute_char_width (p, pmax, utf8_mode, &dcol, NULL, NULL); while (p < p1) putc((char) *p++, stdout); col += dcol; } rli->curs_pos = col; }
/** * Edit a stream * @param console_in stream to read console from * @param console_out stream to write console to * @param stream stream to read/write file to */ void muon_edit(handle_t console_in, handle_t console_out, const char *title, handle_t stream) { int rc; int i; editor_t *ed = (editor_t *) neutron_malloc(sizeof(editor_t)); memset(ed, 0, sizeof(editor_t)); ed->console_in = console_in; ed->console_out = console_out; ed->title = title; ed->anchor = -1; rc = load_file(ed, stream); get_console_size(ed); bool done = false; int key; ed->refresh = 1; while (!done) { if (ed->refresh) { draw_screen(ed); draw_full_statusline(ed); ed->refresh = 0; ed->lineupdate = 0; } else if (ed->lineupdate) { update_line(ed); ed->lineupdate = 0; draw_statusline(ed); } else { draw_statusline(ed); } position_cursor(ed); key = getkey(ed); if (key >= ' ' && key <= 0x7F) { insert_char(ed, (char) key); } else { switch (key) { case KEY_F1: help(ed); break; case KEY_F5: redraw_screen(ed); break; case KEY_UP: up(ed, 0); break; case KEY_DOWN: down(ed, 0); break; case KEY_LEFT: left(ed, 0); break; case KEY_RIGHT: right(ed, 0); break; case KEY_HOME: home(ed, 0); break; case KEY_END: end(ed, 0); break; case KEY_PGUP: pageup(ed, 0); break; case KEY_PGDN: pagedown(ed, 0); break; case KEY_CTRL_RIGHT: wordright(ed, 0); break; case KEY_CTRL_LEFT: wordleft(ed, 0); break; case KEY_CTRL_HOME: top(ed, 0); break; case KEY_CTRL_END: bottom(ed, 0); break; case KEY_SHIFT_UP: up(ed, 1); break; case KEY_SHIFT_DOWN: down(ed, 1); break; case KEY_SHIFT_LEFT: left(ed, 1); break; case KEY_SHIFT_RIGHT: right(ed, 1); break; case KEY_SHIFT_PGUP: pageup(ed, 1); break; case KEY_SHIFT_PGDN: pagedown(ed, 1); break; case KEY_SHIFT_HOME: home(ed, 1); break; case KEY_SHIFT_END: end(ed, 1); break; case KEY_SHIFT_CTRL_RIGHT: wordright(ed, 1); break; case KEY_SHIFT_CTRL_LEFT: wordleft(ed, 1); break; case KEY_SHIFT_CTRL_HOME: top(ed, 1); break; case KEY_SHIFT_CTRL_END: bottom(ed, 1); break; case ctrl('a'): select_all(ed); break; case ctrl('c'): copy_selection(ed); break; case ctrl('f'): find_text(ed, 0); break; case ctrl('l'): goto_line(ed); break; case ctrl('g'): find_text(ed, 1); break; case KEY_TAB: indent(ed, INDENT); break; case KEY_SHIFT_TAB: unindent(ed, INDENT); break; case KEY_ENTER: newline(ed); break; case KEY_BACKSPACE: backspace(ed); break; case KEY_DEL: del(ed); break; case ctrl('x'): cut_selection(ed); break; case ctrl('z'): undo(ed); break; case ctrl('r'): redo(ed); break; case ctrl('v'): paste_selection(ed); break; case ctrl('s'): save_editor(ed); break; case ctrl('q'): done = close_editor(ed); break; } } } gotoxy(ed, 0, ed->lines + 1); outstr(ed, RESET_COLOR CLREOL); if (ed->clipboard) neutron_free(ed->clipboard); if (ed->search) neutron_free(ed->search); if (ed->linebuf) neutron_free(ed->linebuf); clear_undo(ed); neutron_free(ed); }
void new_assignment_help( HELP_WINDOW *hw, char *help[], struct screen *help_heading, int *ch ) { int col, row, i; int update_name, change_color, draw_page; save_and_draw( hw, help_heading, &w_ptr ); show_func_list( hw, help ); col = hw->ulft_col + hw->dply_col; row = hw->ulft_row + hw->dply_row + hw->v_row; change_color = TRUE; *ch = 0; while (*ch!=RTURN && *ch!=ESC) { draw_page = FALSE; position_cursor( hw, hw->line_length, &update_name, &change_color, ch ); switch (*ch) { case PGUP : if (hw->select > hw->avail_lines-1) { hw->select = hw->select - hw->avail_lines; if (hw->v_row > hw->select) hw->select = hw->v_row; draw_page = TRUE; } else if (hw->select - hw->v_row > 0) { hw->select = hw->v_row; draw_page = TRUE; } break; case PGDN : if (hw->select + hw->avail_lines < hw->num_entries) { hw->select = hw->select + hw->avail_lines; draw_page = TRUE; } else if (hw->select + hw->avail_lines - hw->v_row < hw->num_entries) { hw->select = hw->num_entries - 1; draw_page = TRUE; } if ((hw->num_entries - 1) - hw->select < hw->avail_lines && draw_page) { i = row - hw->v_row; scroll_window( 0, i, col, i+hw->avail_lines-1, col+hw->line_length, NORMAL ); } break; } if (draw_page == TRUE) { show_func_list( hw, help ); update_name = TRUE; change_color = TRUE; } row = hw->ulft_row + hw->dply_row + hw->v_row; if (update_name) s_output( help[hw->select], row, col, NORMAL ); if (change_color) hlight_line( col, row, hw->line_length, cfg.attr ); *ch = getkey( ); change_color = FALSE; } window_control( &w_ptr, RESTORE, hw->ulft_col, hw->ulft_row, hw->total_col, hw->total_row ); if (*ch != RTURN) *ch = 0; }
void master_help( HELP_WINDOW *hw, KEY_DEFS *help, struct screen *help_heading, char *t, int *ch ) { FILE *fp; int col, row, i, j; int update_name, change_color, draw_page; char str[80]; char *blank = " "; char temp[20]; HELP_WINDOW hw_k; xygoto( -1, -1 ); save_and_draw( hw, help_heading, &w_ptr ); show_key_def_list( hw, help ); col = hw->ulft_col + hw->dply_col; row = hw->ulft_row + hw->dply_row + hw->v_row; change_color = TRUE; *ch = 0; while (*ch!=F3 && *ch != F10 && *ch!=ESC) { draw_page = FALSE; position_cursor( hw, hw->line_length, &update_name, &change_color, ch ); switch (*ch) { case PGUP : if (hw->select > hw->avail_lines-1) { hw->select = hw->select - hw->avail_lines; if (hw->v_row > hw->select) hw->select = hw->v_row; draw_page = TRUE; } else if (hw->select - hw->v_row > 0) { hw->select = hw->v_row; draw_page = TRUE; } break; case PGDN : if (hw->select + hw->avail_lines < hw->num_entries) { hw->select = hw->select + hw->avail_lines; draw_page = TRUE; } else if (hw->select + hw->avail_lines - hw->v_row < hw->num_entries) { hw->select = hw->num_entries - 1; draw_page = TRUE; } if ((hw->num_entries - 1) - hw->select < hw->avail_lines && draw_page) { i = row - hw->v_row; scroll_window( 0, i, col, i+hw->avail_lines-1, col+hw->line_length, NORMAL ); } break; case F5 : hw_k.dply_col = 2; hw_k.dply_row = 3; hw_k.line_length = 33; hw_k.avail_lines = 6; hw_k.v_row = 0; hw_k.select = 0; hw_k.num_entries = NUM_FUNC; hw_k.ulft_col = 20; hw_k.ulft_row = row + 1; if (hw_k.ulft_row > 12) hw_k.ulft_row = row - 12; hw_k.total_col = 37; hw_k.total_row = 12; new_assignment_help( &hw_k, avail_func, func_head, ch ); if (*ch == RTURN) { help[hw->select].key[0] = '*'; help[hw->select].func_index = (unsigned char)hw_k.select; s_output( help[hw->select].key, row, col, cfg.attr ); s_output( " ", row, col+31, cfg.attr ); s_output( avail_func[help[hw->select].func_index], row, col+31, cfg.attr ); *ch = 0; } break; case F7 : hw_k.ulft_col = 14; hw_k.ulft_row = 10; hw_k.total_col = 52; hw_k.total_row = 5; save_and_draw( &hw_k, file_head, &w_ptr ); xygoto( hw_k.ulft_col+28, hw_k.ulft_row+2 ); gets( str ); j = TRUE; if ((i = access( str, EXIST )) == 0) { s_output( blank, hw_k.ulft_row+2, hw_k.ulft_col+1, NORMAL ); s_output( "OK to overwrite exiting file (y/n)?", hw_k.ulft_row+2, hw_k.ulft_col+1, NORMAL ); xygoto( hw_k.ulft_col+38, hw_k.ulft_row+2 ); i = getkey( ); while (i != 'Y' && i != 'y' && i != 'N' && i != 'n') i = getkey( ); if (i == 'n' || i == 'N') j = FALSE; } xygoto( -1, -1 ); if (j == TRUE && (fp = fopen( str, "w" )) != NULL) { for (i=0; i<hw->num_entries && j; i++) { fprintf( fp, " %22s = ", help[i].key+3 ); fprintf( fp, " %s\n", avail_func[help[i].func_index] ); } fclose( fp ); } else { s_output( blank, hw_k.ulft_row+2, hw_k.ulft_col+1, NORMAL ); s_output( "Cannot open file. Press any key to contine.", hw_k.ulft_row+2, hw_k.ulft_col+1, NORMAL ); j = getkey( ); } window_control( &w_ptr, RESTORE, hw_k.ulft_col, hw_k.ulft_row, hw_k.total_col, hw_k.total_row ); break; case F8 : if ((fp = fopen( "PRN", "a" )) != NULL) { hw_k.ulft_col = 20; hw_k.ulft_row = 10; hw_k.total_col = 42; hw_k.total_row = 5; save_and_draw( &hw_k, print_head, &w_ptr ); j = TRUE; for (i=0; i<hw->num_entries && j; i++) { itoa( i+1, temp, 10 ); s_output( temp, hw_k.ulft_row+2, hw_k.ulft_col+16, NORMAL ); fprintf( fp, " %22s = ", help[i].key+3 ); fprintf( fp, " %s\n", avail_func[help[i].func_index] ); if (kbhit()) { j = getkey( ); if (j == ESC) j = FALSE; else j = TRUE; } } fprintf( fp, "\f" ); fclose( fp ); window_control( &w_ptr, RESTORE, hw_k.ulft_col, hw_k.ulft_row, hw_k.total_col, hw_k.total_row ); } break; } if (draw_page == TRUE) { show_key_def_list( hw, help ); update_name = TRUE; change_color = TRUE; } row = hw->ulft_row + hw->dply_row + hw->v_row; if (update_name) { s_output( help[hw->select].key, row, col, NORMAL ); s_output( avail_func[help[hw->select].func_index], row, col+31, NORMAL ); } if (change_color) hlight_line( col, row, hw->line_length, cfg.attr ); *ch = getkey( ); change_color = FALSE; } window_control( &w_ptr, RESTORE, hw->ulft_col, hw->ulft_row, hw->total_col, hw->total_row ); }