mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 21:33:09 +00:00
reader_readline to return maybe_t<wcstring>
Stop returning a raw pointer.
This commit is contained in:
parent
47f1b026e6
commit
0a29eb3142
3 changed files with 10 additions and 12 deletions
|
@ -202,7 +202,6 @@ static int read_interactive(wcstring &buff, int nchars, bool shell, bool silent,
|
||||||
const wchar_t *prompt, const wchar_t *right_prompt,
|
const wchar_t *prompt, const wchar_t *right_prompt,
|
||||||
const wchar_t *commandline) {
|
const wchar_t *commandline) {
|
||||||
int exit_res = STATUS_CMD_OK;
|
int exit_res = STATUS_CMD_OK;
|
||||||
const wchar_t *line;
|
|
||||||
|
|
||||||
// TODO: rationalize this.
|
// TODO: rationalize this.
|
||||||
const auto &vars = env_stack_t::principal();
|
const auto &vars = env_stack_t::principal();
|
||||||
|
@ -227,17 +226,16 @@ static int read_interactive(wcstring &buff, int nchars, bool shell, bool silent,
|
||||||
proc_push_interactive(1);
|
proc_push_interactive(1);
|
||||||
|
|
||||||
event_fire_generic(L"fish_prompt");
|
event_fire_generic(L"fish_prompt");
|
||||||
line = reader_readline(nchars);
|
auto mline = reader_readline(nchars);
|
||||||
proc_pop_interactive();
|
proc_pop_interactive();
|
||||||
if (line) {
|
if (mline) {
|
||||||
if (0 < nchars && (size_t)nchars < wcslen(line)) {
|
buff = mline.acquire();
|
||||||
|
if (nchars > 0 && (size_t)nchars < buff.size()) {
|
||||||
// Line may be longer than nchars if a keybinding used `commandline -i`
|
// Line may be longer than nchars if a keybinding used `commandline -i`
|
||||||
// note: we're deliberately throwing away the tail of the commandline.
|
// note: we're deliberately throwing away the tail of the commandline.
|
||||||
// It shouldn't be unread because it was produced with `commandline -i`,
|
// It shouldn't be unread because it was produced with `commandline -i`,
|
||||||
// not typed.
|
// not typed.
|
||||||
buff = wcstring(line, nchars);
|
buff.resize(nchars);
|
||||||
} else {
|
|
||||||
buff = wcstring(line);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
exit_res = STATUS_CMD_ERROR;
|
exit_res = STATUS_CMD_ERROR;
|
||||||
|
|
|
@ -2373,12 +2373,12 @@ static int read_i() {
|
||||||
|
|
||||||
// Put buff in temporary string and clear buff, so that we can handle a call to
|
// Put buff in temporary string and clear buff, so that we can handle a call to
|
||||||
// reader_set_buffer during evaluation.
|
// reader_set_buffer during evaluation.
|
||||||
const wchar_t *tmp = reader_readline(0);
|
maybe_t<wcstring> tmp = reader_readline(0);
|
||||||
|
|
||||||
if (shell_is_exiting()) {
|
if (shell_is_exiting()) {
|
||||||
handle_end_loop();
|
handle_end_loop();
|
||||||
} else if (tmp) {
|
} else if (tmp) {
|
||||||
const wcstring command = tmp;
|
const wcstring command = tmp.acquire();
|
||||||
update_buff_pos(&data->command_line, 0);
|
update_buff_pos(&data->command_line, 0);
|
||||||
data->command_line.text.clear();
|
data->command_line.text.clear();
|
||||||
data->command_line_changed(&data->command_line);
|
data->command_line_changed(&data->command_line);
|
||||||
|
@ -2448,7 +2448,7 @@ static bool text_ends_in_comment(const wcstring &text) {
|
||||||
return token.type == TOK_COMMENT;
|
return token.type == TOK_COMMENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
const wchar_t *reader_readline(int nchars) {
|
maybe_t<wcstring> reader_readline(int nchars) {
|
||||||
wint_t c;
|
wint_t c;
|
||||||
int last_char = 0;
|
int last_char = 0;
|
||||||
size_t yank_len = 0;
|
size_t yank_len = 0;
|
||||||
|
@ -3350,7 +3350,7 @@ const wchar_t *reader_readline(int nchars) {
|
||||||
outputter_t::stdoutput().set_color(rgb_color_t::reset(), rgb_color_t::reset());
|
outputter_t::stdoutput().set_color(rgb_color_t::reset(), rgb_color_t::reset());
|
||||||
}
|
}
|
||||||
|
|
||||||
return finished ? data->command_line.text.c_str() : NULL;
|
return finished ? maybe_t<wcstring>{data->command_line.text} : none();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool jump(jump_direction_t dir, jump_precision_t precision, editable_line_t *el, wchar_t target) {
|
bool jump(jump_direction_t dir, jump_precision_t precision, editable_line_t *el, wchar_t target) {
|
||||||
|
|
|
@ -144,7 +144,7 @@ bool reader_thread_job_is_stale();
|
||||||
/// characters even if a full line has not yet been read. Note: the returned value may be longer
|
/// characters even if a full line has not yet been read. Note: the returned value may be longer
|
||||||
/// than nchars if a single keypress resulted in multiple characters being inserted into the
|
/// than nchars if a single keypress resulted in multiple characters being inserted into the
|
||||||
/// commandline.
|
/// commandline.
|
||||||
const wchar_t *reader_readline(int nchars);
|
maybe_t<wcstring> reader_readline(int nchars);
|
||||||
|
|
||||||
/// Push a new reader environment.
|
/// Push a new reader environment.
|
||||||
void reader_push(const wcstring &name);
|
void reader_push(const wcstring &name);
|
||||||
|
|
Loading…
Reference in a new issue