Move cursor to prompt
This commit is contained in:
parent
bb637bab94
commit
a73bbecfcc
4 changed files with 12 additions and 11 deletions
|
@ -7,8 +7,6 @@
|
||||||
#include "erow.h"
|
#include "erow.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
struct erow;
|
|
||||||
|
|
||||||
struct buffer {
|
struct buffer {
|
||||||
char *filename;
|
char *filename;
|
||||||
|
|
||||||
|
@ -30,5 +28,4 @@ struct erow *buffer_get_crow(struct buffer *buffer);
|
||||||
size_t buffer_get_crow_len(struct buffer *buffer);
|
size_t buffer_get_crow_len(struct buffer *buffer);
|
||||||
void buffer_free(struct buffer *buffer);
|
void buffer_free(struct buffer *buffer);
|
||||||
|
|
||||||
|
|
||||||
#endif // BUFFER_H
|
#endif // BUFFER_H
|
||||||
|
|
|
@ -3,8 +3,6 @@
|
||||||
|
|
||||||
#include "buffer.h"
|
#include "buffer.h"
|
||||||
|
|
||||||
struct buffer;
|
|
||||||
|
|
||||||
void cursor_move(struct buffer *buffer, int dx, int dy);
|
void cursor_move(struct buffer *buffer, int dx, int dy);
|
||||||
|
|
||||||
#endif // CURSOR_H
|
#endif // CURSOR_H
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
@ -58,18 +59,24 @@ void editor_set_message(const char *fmt, ...) {
|
||||||
E.message_time = time(NULL);
|
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) {
|
char *editor_prompt(const char *prompt) {
|
||||||
size_t buf_cap = 64;
|
size_t buf_cap = 64;
|
||||||
size_t buf_size = 0;
|
size_t buf_size = 0;
|
||||||
char *buf = malloc(buf_cap);
|
char *buf = malloc(buf_cap);
|
||||||
|
|
||||||
|
char *prompt_prefix = strstr(prompt, "%s");
|
||||||
|
int prefix_len = (prompt_prefix ? prompt_prefix - prompt : 0);
|
||||||
|
|
||||||
buf[buf_size] = '\0';
|
buf[buf_size] = '\0';
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
editor_set_message(prompt, buf);
|
editor_set_message(prompt, buf);
|
||||||
ui_draw_screen();
|
ui_draw_screen();
|
||||||
|
|
||||||
|
if (prompt_prefix)
|
||||||
|
terminal_set_cursor_pos(E.screenrows + 2, prefix_len + buf_size + 1);
|
||||||
|
|
||||||
KEY key = terminal_read_key();
|
KEY key = terminal_read_key();
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case BACKSPACE:
|
case BACKSPACE:
|
||||||
|
|
|
@ -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 <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
@ -158,3 +153,7 @@ KEY terminal_read_key(void) {
|
||||||
return (KEY) c;
|
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>
|
||||||
|
|
Reference in a new issue