commandline: move handling of cursor option

No behavior change intended.
Will use the "buffer_part" computation in the next commit.
This commit is contained in:
Johannes Altmanninger 2021-06-23 00:19:42 +02:00
parent caf1bbfc97
commit 016569905e

View File

@ -372,25 +372,6 @@ maybe_t<int> builtin_commandline(parser_t &parser, io_streams_t &streams, const
buffer_part = STRING_MODE;
}
if (cursor_mode) {
if (argc - w.woptind) {
long new_pos = fish_wcstol(argv[w.woptind]);
if (errno) {
streams.err.append_format(BUILTIN_ERR_NOT_NUMBER, cmd, argv[w.woptind]);
builtin_print_error_trailer(parser, streams.err, cmd);
}
current_buffer = reader_get_buffer();
new_pos =
std::max(0L, std::min(new_pos, static_cast<long>(std::wcslen(current_buffer))));
reader_set_buffer(current_buffer, static_cast<size_t>(new_pos));
} else {
streams.out.append_format(L"%lu\n",
static_cast<unsigned long>(reader_get_cursor_pos()));
}
return STATUS_CMD_OK;
}
if (line_mode) {
size_t pos = reader_get_cursor_pos();
const wchar_t *buff = reader_get_buffer();
@ -431,6 +412,25 @@ maybe_t<int> builtin_commandline(parser_t &parser, io_streams_t &streams, const
}
}
if (cursor_mode) {
if (argc - w.woptind) {
long new_pos = fish_wcstol(argv[w.woptind]);
if (errno) {
streams.err.append_format(BUILTIN_ERR_NOT_NUMBER, cmd, argv[w.woptind]);
builtin_print_error_trailer(parser, streams.err, cmd);
}
current_buffer = reader_get_buffer();
new_pos =
std::max(0L, std::min(new_pos, static_cast<long>(std::wcslen(current_buffer))));
reader_set_buffer(current_buffer, static_cast<size_t>(new_pos));
} else {
streams.out.append_format(L"%lu\n",
static_cast<unsigned long>(reader_get_cursor_pos()));
}
return STATUS_CMD_OK;
}
int arg_count = argc - w.woptind;
if (arg_count == 0) {
write_part(begin, end, cut_at_cursor, tokenize, current_buffer, current_cursor_pos,