/* * updateline() - like updateScreen() but only for cursor line * * This determines whether or not we need to call updateScreen() to examine * the entire screen for changes. This occurs if the size of the cursor line * (in rows) hasn't changed. */ void updateline() { int row; int n; screenalloc(); /* allocate screen buffers if size changed */ if (Nextscreen == NULL || RedrawingDisabled) return; screenchar(NULL, 0, 0); /* init cursor position of screenchar() */ outstr(T_CI); /* disable cursor */ row = screenline(Curpos.lnum, Cline_row, (int)Rows - 1); outstr(T_CV); /* enable cursor again */ n = row - Cline_row; if (n != Cline_size) /* line changed size */ { if (n < Cline_size) /* got smaller: delete lines */ s_del(row, Cline_size - n, FALSE); else /* got bigger: insert lines */ s_ins(Cline_row + Cline_size, n - Cline_size, FALSE); updateScreen(VALID_TO_CURSCHAR); } }
static void refresh_line(struct line *line, int ypos) { char *str = screenline(line->data, NULL) + scrcol; pos(0, ypos); str[screenwidth] = 0; printf("%s%c[K", str, 27); pos(cursx, cursy); }
static int do_edit(int argc, char *argv[]) { int lastscrcol; int i; int linepos; int c; if (argc != 2) return COMMAND_ERROR_USAGE; screenwidth = 80; screenheight = 25; /* check if we are called as "sedit" instead of "edit" */ if (*argv[0] == 's') { smartscroll = 1; getwinsize(); } buffer = NULL; if(edit_read_file(argv[1])) return 1; cursx = 0; cursy = 0; textx = 0; scrcol = 0; curline = buffer; scrline = curline; lastscrline = scrline; lastscrcol = 0; printf("%c[2J", 27); pos(0, -1); printf("%c[7m %-25s <ctrl-d>: Save and quit <ctrl-c>: quit %c[0m", 27, argv[1], 27); printf("%c[2;%dr", 27, screenheight); screenheight--; /* status line */ pos(0, 0); refresh(1); while (1) { int curlen = strlen(curline->data); if (textx > curlen) textx = curlen; if (textx < 1) textx = 0; screenline(curline->data, &linepos); if (linepos > scrcol + screenwidth) scrcol = linepos - screenwidth; if (scrcol > linepos) scrcol = linepos; cursx = linepos - scrcol; while (cursy >= screenheight) { cursy--; scrline = scrline->next; } while (cursy < 0) { cursy++; scrline = scrline->prev; } if (scrline != lastscrline || scrcol != lastscrcol) refresh(0); lastscrcol = scrcol; lastscrline = scrline; pos(cursx, cursy); c = read_key(); switch (c) { case BB_KEY_UP: if (!curline->prev) continue; curline = curline->prev; cursy--; textx = setpos(curline->data, linepos); break; case BB_KEY_DOWN: if (!curline->next) continue; curline = curline->next; cursy++; textx = setpos(curline->data, linepos); break; case BB_KEY_RIGHT: textx++; break; case BB_KEY_LEFT: textx--; break; case BB_KEY_HOME: textx = 0; break; case BB_KEY_END: textx = curlen; break; case BB_KEY_PAGEUP: for (i = 0; i < screenheight - 1; i++) { if (!curline->prev) break; cursy--; curline = curline->prev; } textx = setpos(curline->data, linepos); break; case BB_KEY_PAGEDOWN: for (i = 0; i < screenheight - 1; i++) { if (!curline->next) break; cursy++; curline = curline->next; } textx = setpos(curline->data, linepos); break; case BB_KEY_DEL: if (textx == curlen) { if (curline->next) merge_line(curline); } else delete_char(textx); break; case 13: case 10: split_line(); break; case 127: case 8: if (textx > 0) { textx--; delete_char(textx); } else { if (!curline->prev) break; curline = curline->prev; cursy--; textx = strlen(curline->data); merge_line(curline); } break; case 4: save_file(argv[1]); goto out; case 3: goto out; default: if ((signed char)c != -1) insert_char(c); } } out: free_buffer(); printf("%c[2J%c[r", 27, 27); printf("\n"); return 0; }