int main(void) { uart_init(); shift_init(); timer_init(); display_init(); keypad_init(); serial_init(); edit_init(); clock_init(); watchdog_init(WDTO_15MS, &oops); sei(); // enable interrupts printf("\r\n*** BOOTED ***\r\nSpaceTime, yay!\r\n"); timer_beep(10); while(1) { display_update(); serial_update(); edit_update(); clock_update(); } }
/* Refresh the screen without changing the position of lines. Use this * if we've moved and changed text. */ void edit_refresh(void) { filestruct *foo; int nlines; /* Figure out what maxrows should really be */ compute_maxrows(); if (openfile->current->lineno < openfile->edittop->lineno || openfile->current->lineno >= openfile->edittop->lineno + maxrows) { DEBUG_LOG("edit_refresh(): line = " << openfile->current->lineno << ", edittop " << openfile->edittop->lineno << " + maxrows " << maxrows); /* Make sure the current line is on the screen. */ edit_update(ISSET(SMOOTH_SCROLL) ? NONE : CENTER); } foo = openfile->edittop; DEBUG_LOG("edit_refresh(): edittop->lineno = " << openfile->edittop->lineno); for (nlines = 0; nlines < editwinrows && foo != NULL; nlines++) { nlines += update_line(foo, (foo == openfile->current) ? openfile->current_x : 0); foo = foo->next; } for (; nlines < editwinrows; nlines++) { blank_line(edit, nlines, 0, COLS); } reset_cursor(); wnoutrefresh(edit); }
/* Move up one page. */ void do_page_up(void) { int i, skipped = 0; /* If there's less than a page of text left on the screen, put the * cursor at the beginning of the first line of the file, and then * update the edit window. */ if (openfile->current->lineno == 1 || ( #ifndef NANO_TINY !ISSET(SOFTWRAP) && #endif openfile->current->lineno <= editwinrows - 2)) { do_first_line(); return; } /* If we're not in smooth scrolling mode, put the cursor at the * beginning of the top line of the edit window, as Pico does. */ #ifndef NANO_TINY if (!ISSET(SMOOTH_SCROLL)) { #endif openfile->current = openfile->edittop; openfile->placewewant = openfile->current_y = 0; #ifndef NANO_TINY } #endif for (i = editwinrows - 2; i - skipped > 0 && openfile->current != openfile->fileage; i--) { openfile->current = openfile->current->prev; #ifndef NANO_TINY if (ISSET(SOFTWRAP) && openfile->current) { skipped += strlenpt(openfile->current->data) / COLS; #ifdef DEBUG fprintf(stderr, "do_page_up: i = %d, skipped = %d based on line %ld len %lu\n", i, skipped, (long)openfile->current->lineno, (unsigned long)strlenpt(openfile->current->data)); #endif } #endif } openfile->current_x = actual_x(openfile->current->data, openfile->placewewant); #ifdef DEBUG fprintf(stderr, "do_page_up: openfile->current->lineno = %lu, skipped = %d\n", (unsigned long)openfile->current->lineno, skipped); #endif /* Scroll the edit window up a page. */ edit_update(NONE); }
static int editmenu_action(int msg) { switch(msg) { case 'e': case '\n': case '\r': edit_ok(msg);break; case 0x1b:deselectitem();quit_edit('\n');break; case UPDATE: edit_update();break; case UPDATE1: edit_update1();break; case CLEAN: printmenu();break; default: if(msg>='1' && msg <= '9')edit_digital(msg); else return 0;break; } return 1; }
/* Move down one page. */ void do_page_down(void) { int i; /* If there's less than a page of text left on the screen, put the * cursor at the beginning of the last line of the file, and then * update the edit window. */ if (openfile->current->lineno + maxrows - 2 >= openfile->filebot->lineno) { do_last_line(); return; } /* If we're not in smooth scrolling mode, put the cursor at the * beginning of the top line of the edit window, as Pico does. */ #ifndef NANO_TINY if (!ISSET(SMOOTH_SCROLL)) { #endif openfile->current = openfile->edittop; openfile->placewewant = openfile->current_y = 0; #ifndef NANO_TINY } #endif for (i = maxrows - 2; i > 0 && openfile->current != openfile->filebot; i--) { openfile->current = openfile->current->next; #ifdef DEBUG fprintf(stderr, "do_page_down: moving to line %lu\n", (unsigned long) openfile->current->lineno); #endif } openfile->current_x = actual_x(openfile->current->data, openfile->placewewant); /* Scroll the edit window down a page. */ edit_update(NONE); }
void command_get(t_env *env, t_cmd *cmd) { t_char *list; t_cur cur; edit_ini(&cur, env, cmd, &list); edit_line_display(list, &cur, cmd, env); while (!cmd->cmd_end) { env->key[0] = 0; read(0, env->key, 10); if (cmd->sig) if (edit_signal(&cur, env, cmd, &list)) continue ; edit_update(env, &cur, cmd); if (!edit_key(env->key, cmd, &cur, &list)) list = edit_char_add(list, env->key[0], &cur, cmd); if (list && cur.x > 0) list->mirror = 0; edit_line_display(list, &cur, cmd, env); } command_set(&cur, env, cmd, &list); }
/* Go to the specified line and column, or ask for them if interactive * is TRUE. Save the x-coordinate and y-coordinate if save_pos is TRUE. * Update the screen afterwards if allow_update is TRUE. Note that both * the line and column numbers should be one-based. */ void do_gotolinecolumn(ssize_t line, ssize_t column, bool use_answer, bool interactive, bool save_pos, bool allow_update) { if (interactive) { char *ans = mallocstrcpy(NULL, answer); functionptrtype func; /* Ask for the line and column. */ int i = do_prompt(FALSE, #ifndef DISABLE_TABCOMP TRUE, #endif MGOTOLINE, use_answer ? ans : "", #ifndef DISABLE_HISTORIES NULL, #endif /* TRANSLATORS: This is a prompt. */ edit_refresh, _("Enter line number, column number")); free(ans); /* Cancel, or Enter with blank string. */ if (i < 0) { statusbar(_("Cancelled")); display_main_list(); return; } func = func_from_key(&i); if (func == gototext_void) { /* Keep answer up on the statusbar. */ search_init(TRUE, TRUE); do_search(); return; } /* Do a bounds check. Display a warning on an out-of-bounds * line or column number only if we hit Enter at the statusbar * prompt. */ if (!parse_line_column(answer, &line, &column) || line < 1 || column < 1) { if (i == 0) statusbar(_("Invalid line or column number")); display_main_list(); return; } } else { if (line < 1) line = openfile->current->lineno; if (column < 1) column = openfile->placewewant + 1; } for (openfile->current = openfile->fileage; openfile->current != openfile->filebot && line > 1; line--) openfile->current = openfile->current->next; openfile->current_x = actual_x(openfile->current->data, column - 1); openfile->placewewant = column - 1; /* Put the top line of the edit window in range of the current line. * If save_pos is TRUE, don't change the cursor position when doing * it. */ edit_update(save_pos ? NONE : CENTER); /* If allow_update is TRUE, update the screen. */ if (allow_update) { edit_refresh(); display_main_list(); } }
/* Update any lines between old_current and current that need to be * updated. Use this if we've moved without changing any text. */ void edit_redraw(filestruct *old_current, size_t pww_save) { filestruct *foo = NULL; bool do_redraw = need_screen_update(0) || need_screen_update(pww_save); /* If either old_current or current is offscreen, scroll the edit * window until it's onscreen and get out. */ if (old_current->lineno < openfile->edittop->lineno || old_current->lineno >= openfile->edittop->lineno + maxrows || openfile->current->lineno < openfile->edittop->lineno || openfile->current->lineno >= openfile->edittop->lineno + maxrows) { DEBUG_LOG("edit_redraw(): line " << openfile->current->lineno << " was offscreen, oldcurrent = " << old_current->lineno << " edittop = " << openfile->edittop->lineno); /* If the mark is on, update all the lines between old_current * and either the old first line or old last line (depending on * whether we've scrolled up or down) of the edit window. */ if (openfile->mark_set) { ssize_t old_lineno; filestruct *old_edittop = openfile->edittop; if (old_edittop->lineno < openfile->edittop->lineno) { old_lineno = old_edittop->lineno; } else old_lineno = (old_edittop->lineno + maxrows <= openfile->filebot->lineno) ? old_edittop->lineno + editwinrows : openfile->filebot->lineno; foo = old_current; while (foo->lineno != old_lineno) { update_line(foo, 0); foo = (foo->lineno > old_lineno) ? foo->prev : foo->next; } } /* Make sure the current line is on the screen. */ edit_update(CENTER); /* Update old_current if we're not on the same page as * before. */ if (do_redraw) { update_line(old_current, 0); } /* If the mark is on, update all the lines between the old first * line or old last line of the edit window (depending on * whether we've scrolled up or down) and current. */ if (openfile->mark_set) { while (foo->lineno != openfile->current->lineno) { update_line(foo, 0); foo = (foo->lineno > openfile->current->lineno) ? foo->prev : foo->next; } } return; } /* Update old_current and current if we're not on the same page as * before. If the mark is on, update all the lines between * old_current and current too. */ foo = old_current; while (foo != openfile->current) { if (do_redraw) { update_line(foo, 0); } if (!openfile->mark_set) { break; } foo = (foo->lineno > openfile->current->lineno) ? foo->prev : foo->next; } if (do_redraw) { update_line(openfile->current, openfile->current_x); } }