mirror of
https://github.com/Savapitech/42sh.git
synced 2026-03-18 21:50:35 +01:00
Improve CTRL+D handling, now redisplay the prompt and command if the cursor is not home
This commit is contained in:
1
FIX.md
1
FIX.md
@@ -7,3 +7,4 @@
|
||||
- [ ] All AFL crashes
|
||||
- [ ] Fix CTRL+E and ->
|
||||
- [ ] Multi line editing
|
||||
- [ ] Foreach in if
|
||||
|
||||
@@ -50,10 +50,8 @@ bool append_null_terminator(buff_t *out)
|
||||
return true;
|
||||
if (!ensure_buff_av_capacity(out, 1))
|
||||
return false;
|
||||
U_DEBUG("buff sz: %zu\n", out->sz);
|
||||
if (out->str[out->sz - 1] == '\n')
|
||||
out->sz--;
|
||||
U_DEBUG("readline [%.*s]\n", (int)out->sz, out->str);
|
||||
out->str[out->sz] = '\0';
|
||||
out->sz++;
|
||||
return true;
|
||||
@@ -157,7 +155,6 @@ bool read_until_line_ending(
|
||||
return false;
|
||||
if (!populate_copy_buff(rh, rd, &tpi))
|
||||
return true;
|
||||
U_DEBUG("copied %zu chars to cpy (%zu used)\n", tpi.written, tpi.used);
|
||||
memmove(rh->in, &rh->in[tpi.used], BULK_READ_BUFF_SZ - tpi.used);
|
||||
memset(&rh->in[BULK_READ_BUFF_SZ - tpi.used], '\0', tpi.used);
|
||||
if (rh->cpy[tpi.written - 1] == '\n')
|
||||
@@ -165,7 +162,6 @@ bool read_until_line_ending(
|
||||
rd = read(ec->read_fd, rh->in, BULK_READ_BUFF_SZ);
|
||||
if (rd <= 0)
|
||||
return (rd == 0);
|
||||
U_DEBUG("read %zu characters\n", rd);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -180,7 +176,6 @@ bool readline(exec_ctx_t *ec, buff_t *out)
|
||||
|
||||
for (size_t i = 0; i < sizeof read_buff; i++)
|
||||
is_empty &= read_buff[i] == '\0';
|
||||
U_DEBUG("readline buff is empty? %d\n", is_empty);
|
||||
if (is_empty) {
|
||||
rd = read(ec->read_fd, read_buff, sizeof read_buff);
|
||||
if (rd < 0)
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "debug.h"
|
||||
#include "key_handler.h"
|
||||
#include "readline.h"
|
||||
#include "u_str.h"
|
||||
@@ -71,7 +70,6 @@ bool handle_key_arrow_left(
|
||||
rh->cursor--;
|
||||
refresh_line(rh);
|
||||
}
|
||||
U_DEBUG("Key [LEFT] cursor [%zd]\n", rh->cursor);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -82,6 +80,5 @@ bool handle_key_arrow_right(
|
||||
rh->cursor++;
|
||||
refresh_line(rh);
|
||||
}
|
||||
U_DEBUG("Key [RIGHT] cursor [%zd]\n", rh->cursor);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -21,8 +21,14 @@ bool handle_key_ctrl_c(readline_helper_t *rh, exec_ctx_t *ec, buff_t *buff)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool handle_key_ctrl_d(readline_helper_t *, exec_ctx_t *ec, buff_t *buff)
|
||||
bool handle_key_ctrl_d(readline_helper_t *rh, exec_ctx_t *ec, buff_t *buff)
|
||||
{
|
||||
if (rh->cursor) {
|
||||
WRITE_CONST(STDOUT_FILENO, "\n");
|
||||
print_shell_prompt(ec);
|
||||
refresh_line(rh);
|
||||
return false;
|
||||
}
|
||||
if (ec->ignoreof)
|
||||
return false;
|
||||
buff->sz = 0;
|
||||
@@ -39,7 +45,7 @@ bool handle_key_ctrl_l(readline_helper_t *, exec_ctx_t *ec, buff_t *)
|
||||
|
||||
bool handle_backspace(readline_helper_t *rh, exec_ctx_t *, buff_t *buff)
|
||||
{
|
||||
if (rh->cursor == 0)
|
||||
if (!rh->cursor || !buff->sz)
|
||||
return false;
|
||||
rh->cursor--;
|
||||
memmove(&buff->str[rh->cursor], &buff->str[rh->cursor + 1],
|
||||
|
||||
@@ -107,7 +107,6 @@ ssize_t handle_keys(
|
||||
char const *read_buff,
|
||||
size_t len)
|
||||
{
|
||||
U_DEBUG("Found special char, [%hhx]\n", *read_buff);
|
||||
for (size_t i = 0; i < sizeof KEY_HANDLERS / sizeof *KEY_HANDLERS; i++) {
|
||||
if (strncmp(read_buff, KEY_HANDLERS[i].name,
|
||||
strlen(KEY_HANDLERS[i].name)) != 0)
|
||||
|
||||
Reference in New Issue
Block a user