Subversion Repositories SvarDOS

Rev

Rev 1275 | Rev 1282 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1275 Rev 1276
Line 135... Line 135...
135
}
135
}
136
 
136
 
137
 
137
 
138
static void cursor_eol(struct linedb *db, unsigned char *cursorposx, unsigned char screenw) {
138
static void cursor_eol(struct linedb *db, unsigned char *cursorposx, unsigned char screenw) {
139
  /* adjust xoffset to make sure eol is visible on screen */
139
  /* adjust xoffset to make sure eol is visible on screen */
140
  if (db->xoffset >= db->cursor->len) db->xoffset = db->cursor->len - 1;
140
  if (db->xoffset > db->cursor->len) db->xoffset = db->cursor->len - 1;
141
  if (db->xoffset + screenw - 1 <= db->cursor->len) db->xoffset = db->cursor->len - screenw + 2;
141
  if (db->xoffset + screenw - 1 <= db->cursor->len) db->xoffset = db->cursor->len - screenw + 2;
142
  *cursorposx = db->cursor->len - db->xoffset;
142
  *cursorposx = db->cursor->len - db->xoffset;
143
}
143
}
144
 
144
 
145
 
145
 
-
 
146
static void cursor_down(struct linedb *db, unsigned char *cursorposy, unsigned char screenh) {
-
 
147
  if (db->cursor->next != NULL) {
-
 
148
    db->cursor = db->cursor->next;
-
 
149
    if (*cursorposy < screenh - 2) {
-
 
150
      *cursorposy += 1;
-
 
151
    } else {
-
 
152
      db->topscreen = db->topscreen->next;
-
 
153
    }
-
 
154
  }
-
 
155
}
-
 
156
 
-
 
157
 
-
 
158
static void cursor_home(struct linedb *db, unsigned char *cursorposx) {
-
 
159
  *cursorposx = 0;
-
 
160
  db->xoffset = 0;
-
 
161
}
-
 
162
 
-
 
163
 
146
int main(int argc, char **argv) {
164
int main(int argc, char **argv) {
147
  FILE *fd;
165
  FILE *fd;
148
  const char *fname = NULL;
166
  const char *fname = NULL;
149
  char buff[1024];
167
  char buff[1024];
150
  struct linedb db;
168
  struct linedb db;
Line 191... Line 209...
191
 
209
 
192
    ui_refresh(&db, screenw, screenh);
210
    ui_refresh(&db, screenw, screenh);
193
 
211
 
194
    k = keyb_getkey();
212
    k = keyb_getkey();
195
    if (k == 0x150) { /* down */
213
    if (k == 0x150) { /* down */
196
      if (db.cursor->next != NULL) {
-
 
197
        db.cursor = db.cursor->next;
-
 
198
        if (cursorposy < screenh - 2) {
214
      cursor_down(&db, &cursorposy, screenh);
199
          cursorposy++;
-
 
200
        } else {
-
 
201
          db.topscreen = db.topscreen->next;
-
 
202
        }
-
 
203
      }
-
 
204
 
215
 
205
    } else if (k == 0x148) { /* up */
216
    } else if (k == 0x148) { /* up */
206
      cursor_up(&db, &cursorposy);
217
      cursor_up(&db, &cursorposy);
207
 
218
 
208
    } else if (k == 0x14D) { /* right */
219
    } else if (k == 0x14D) { /* right */
Line 210... Line 221...
210
        if (cursorposx < screenw - 2) {
221
        if (cursorposx < screenw - 2) {
211
          cursorposx++;
222
          cursorposx++;
212
        } else {
223
        } else {
213
          db.xoffset++;
224
          db.xoffset++;
214
        }
225
        }
-
 
226
      } else {
-
 
227
        cursor_down(&db, &cursorposy, screenh);
-
 
228
        cursor_home(&db, &cursorposx);
215
      }
229
      }
216
 
230
 
217
    } else if (k == 0x14B) { /* left */
231
    } else if (k == 0x14B) { /* left */
218
      if (cursorposx > 0) {
232
      if (cursorposx > 0) {
219
        cursorposx--;
233
        cursorposx--;
220
      } else if (db.xoffset > 0) {
234
      } else if (db.xoffset > 0) {
221
        db.xoffset--;
235
        db.xoffset--;
222
      } else {
236
      } else if (db.cursor->prev != NULL) { /* jump to end of line above */
223
        cursor_up(&db, &cursorposy);
237
        cursor_up(&db, &cursorposy);
224
        cursor_eol(&db, &cursorposx, screenw);
238
        cursor_eol(&db, &cursorposx, screenw);
225
      }
239
      }
226
 
240
 
227
    } else if (k == 0x1B) { /* ESC */
241
    } else if (k == 0x1B) { /* ESC */