You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 line
2.5KB

  1. /* vview.c - drawing for the c64 vim clone: scroll, rows, status row. */
  2. extern char *bfr;
  3. extern unsigned blen;
  4. extern unsigned lptr[];
  5. extern int nlines, cy, cx, top, leftcol, mode, dirty;
  6. extern char *note;
  7. extern char fname[];
  8. extern char ybuf[];
  9. extern int ylen, yok;
  10. extern int redraw;
  11. /* decimal of v into t at p, returns the position after it */
  12. dnum(t, p, v)
  13. char *t;
  14. int p, v;
  15. {
  16. char d[6];
  17. int n;
  18. n = 0;
  19. if (v == 0) {
  20. t[p++] = 48;
  21. return p;
  22. }
  23. while (v > 0 && n < 5) {
  24. d[n++] = 48 + (v % 10);
  25. v = v / 10;
  26. }
  27. while (n > 0) t[p++] = d[--n];
  28. return p;
  29. }
  30. /* bring the cursor back into view */
  31. scroll()
  32. {
  33. if (cy < top) top = cy;
  34. if (cy > top + 23) top = cy - 23;
  35. if (top < 0) top = 0;
  36. if (cx < leftcol) leftcol = cx;
  37. if (cx > leftcol + 39) leftcol = cx - 39;
  38. if (leftcol < 0) leftcol = 0;
  39. return 0;
  40. }
  41. /* the status row: message, mode or name on the left; modified flag; line/total */
  42. dstat()
  43. {
  44. char t[40];
  45. char *s;
  46. int i, n, p;
  47. if (note != 0) s = note;
  48. else if (mode) s = "-- insert --";
  49. else if (fname[0] == 0) s = "[no name]";
  50. else s = fname;
  51. n = 0;
  52. for (i = 0; s[i] && i < 26; i++) t[n++] = s[i];
  53. while (n < 28) t[n++] = 32;
  54. if (dirty) t[n++] = 43; /* + */
  55. else t[n++] = 32;
  56. while (n < 31) t[n++] = 32;
  57. p = dnum(t, n, cy + 1);
  58. t[p++] = 47; /* / */
  59. p = dnum(t, p, nlines);
  60. mlrow((unsigned) t, p, 1984, 255, 128); /* row 24 = $0400 + 960, reverse */
  61. return 0;
  62. }
  63. /* what the screen showed last time, so a key that only moves the cursor
  64. repaints two rows instead of 24 */
  65. int ltop, lleft, lcy;
  66. /* repaint what changed, then the status row. redraw is raised by the editing
  67. code: 1 = the cursor line changed, 2 = lines moved, repaint everything.
  68. (no double bar: power c cannot type it, see NOTES.md) */
  69. dall()
  70. {
  71. int crow, ccol, orow, full;
  72. crow = cy - top;
  73. ccol = cx - leftcol;
  74. full = 0;
  75. if (redraw == 2) full = 1;
  76. if (top != ltop) full = 1;
  77. if (leftcol != lleft) full = 1;
  78. if (full) {
  79. mlscr(0, 23, crow, ccol); /* one call paints 24 rows */
  80. } else {
  81. orow = lcy - top; /* take the cursor off its old row */
  82. if (orow != crow && orow >= 0 && orow < 24) mlscr(orow, orow, crow, ccol);
  83. mlscr(crow, crow, crow, ccol);
  84. }
  85. ltop = top;
  86. lleft = leftcol;
  87. lcy = cy;
  88. redraw = 0;
  89. dstat();
  90. return 0;
  91. }
  92. /* end of vview.c */

Powered by TurnKey Linux.