Archived
1
Fork 0

Move cursor to prompt

This commit is contained in:
Hadeed 2023-09-11 13:53:28 +05:00
parent bb637bab94
commit a73bbecfcc
4 changed files with 12 additions and 11 deletions

View file

@ -7,8 +7,6 @@
#include "erow.h"
#include "utils.h"
struct erow;
struct buffer {
char *filename;
@ -30,5 +28,4 @@ struct erow *buffer_get_crow(struct buffer *buffer);
size_t buffer_get_crow_len(struct buffer *buffer);
void buffer_free(struct buffer *buffer);
#endif // BUFFER_H

View file

@ -3,8 +3,6 @@
#include "buffer.h"
struct buffer;
void cursor_move(struct buffer *buffer, int dx, int dy);
#endif // CURSOR_H

View file

@ -3,6 +3,7 @@
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
@ -58,18 +59,24 @@ void editor_set_message(const char *fmt, ...) {
E.message_time = time(NULL);
}
// TODO: Implement a fully featured line editor here
// TODO: This could use some work
char *editor_prompt(const char *prompt) {
size_t buf_cap = 64;
size_t buf_size = 0;
char *buf = malloc(buf_cap);
char *prompt_prefix = strstr(prompt, "%s");
int prefix_len = (prompt_prefix ? prompt_prefix - prompt : 0);
buf[buf_size] = '\0';
while (true) {
editor_set_message(prompt, buf);
ui_draw_screen();
if (prompt_prefix)
terminal_set_cursor_pos(E.screenrows + 2, prefix_len + buf_size + 1);
KEY key = terminal_read_key();
switch (key) {
case BACKSPACE:

View file

@ -1,8 +1,3 @@
// IWYU pragma: no_include <bits/termios-c_cc.h>
// IWYU pragma: no_include <bits/termios-c_cflag.h>
// IWYU pragma: no_include <bits/termios-c_iflag.h>
// IWYU pragma: no_include <bits/termios-c_oflag.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
@ -158,3 +153,7 @@ KEY terminal_read_key(void) {
return (KEY) c;
}
// IWYU pragma: no_include <bits/termios-c_cc.h>
// IWYU pragma: no_include <bits/termios-c_cflag.h>
// IWYU pragma: no_include <bits/termios-c_iflag.h>
// IWYU pragma: no_include <bits/termios-c_oflag.h>