This commit is contained in:
Tyrel Souza 2021-10-21 23:35:00 -04:00
parent 36a08aaf95
commit 0fb5770263

17
tted.c
View File

@ -64,6 +64,7 @@ struct editorConfig E;
/** prototypes */ /** prototypes */
void editorSetStatusMessage(const char *fmt, ...); void editorSetStatusMessage(const char *fmt, ...);
void editorRefreshScreen(); void editorRefreshScreen();
char *editorPrompt(char *prompt);
/** terminal */ /** terminal */
void die(const char *s) { void die(const char *s) {
@ -344,7 +345,13 @@ char *editorRowsToString(int *buflen) {
} }
void editorSave() { void editorSave() {
if (E.filename == NULL) return; if (E.filename == NULL) {
E.filename = editorPrompt("Save as: %s (ESC to cancel)");
if (E.filename == NULL) {
editorSetStatusMessage("Save aborted");
return;
}
}
int len; int len;
char *buf = editorRowsToString(&len); char *buf = editorRowsToString(&len);
@ -536,7 +543,13 @@ char *editorPrompt(char *prompt){
editorSetStatusMessage(prompt, buf); editorSetStatusMessage(prompt, buf);
editorRefreshScreen(); editorRefreshScreen();
int c = editorReadKey(); int c = editorReadKey();
if (c == '\r') { if (c == DEL_KEY || c == CTRL_KEY('h') || c == BACKSPACE) {
if (buflen != 0) buf[--buflen] = '\0';
} else if (c == '\x1b'){
editorSetStatusMessage("");
free(buf);
return NULL;
} else if (c == '\r') {
if (buflen != 0){ if (buflen != 0){
editorSetStatusMessage(""); editorSetStatusMessage("");
return buf; return buf;