mirror of
https://github.com/fish-shell/fish-shell
synced 2024-11-10 15:14:44 +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 *commandline) {
|
||||
int exit_res = STATUS_CMD_OK;
|
||||
const wchar_t *line;
|
||||
|
||||
// TODO: rationalize this.
|
||||
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);
|
||||
|
||||
event_fire_generic(L"fish_prompt");
|
||||
line = reader_readline(nchars);
|
||||
auto mline = reader_readline(nchars);
|
||||
proc_pop_interactive();
|
||||
if (line) {
|
||||
if (0 < nchars && (size_t)nchars < wcslen(line)) {
|
||||
if (mline) {
|
||||
buff = mline.acquire();
|
||||
if (nchars > 0 && (size_t)nchars < buff.size()) {
|
||||
// Line may be longer than nchars if a keybinding used `commandline -i`
|
||||
// note: we're deliberately throwing away the tail of the commandline.
|
||||
// It shouldn't be unread because it was produced with `commandline -i`,
|
||||
// not typed.
|
||||
buff = wcstring(line, nchars);
|
||||
} else {
|
||||
buff = wcstring(line);
|
||||
buff.resize(nchars);
|
||||
}
|
||||
} else {
|
||||
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
|
||||
// reader_set_buffer during evaluation.
|
||||
const wchar_t *tmp = reader_readline(0);
|
||||
maybe_t<wcstring> tmp = reader_readline(0);
|
||||
|
||||
if (shell_is_exiting()) {
|
||||
handle_end_loop();
|
||||
} else if (tmp) {
|
||||
const wcstring command = tmp;
|
||||
const wcstring command = tmp.acquire();
|
||||
update_buff_pos(&data->command_line, 0);
|
||||
data->command_line.text.clear();
|
||||
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;
|
||||
}
|
||||
|
||||
const wchar_t *reader_readline(int nchars) {
|
||||
maybe_t<wcstring> reader_readline(int nchars) {
|
||||
wint_t c;
|
||||
int last_char = 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());
|
||||
}
|
||||
|
||||
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) {
|
||||
|
|
|
@ -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
|
||||
/// than nchars if a single keypress resulted in multiple characters being inserted into the
|
||||
/// commandline.
|
||||
const wchar_t *reader_readline(int nchars);
|
||||
maybe_t<wcstring> reader_readline(int nchars);
|
||||
|
||||
/// Push a new reader environment.
|
||||
void reader_push(const wcstring &name);
|
||||
|
|
Loading…
Reference in a new issue