Implementation of variable with killring entries

This commit is contained in:
Karolina Gontarek 2021-04-09 21:08:56 +02:00 committed by ridiculousfish
parent 0a559ac457
commit ed64cf5e34
4 changed files with 38 additions and 0 deletions

View file

@ -35,6 +35,7 @@
#include "termsize.h"
#include "wcstringutil.h"
#include "wutil.h" // IWYU pragma: keep
#include "kill.h"
/// Some configuration path environment variables.
#define FISH_DATADIR_VAR L"__fish_data_dir"
@ -93,6 +94,7 @@ static constexpr const electric_var_t electric_variables[] = {
{L"fish_pid", electric_var_t::freadonly},
{L"history", electric_var_t::freadonly | electric_var_t::fcomputed},
{L"hostname", electric_var_t::freadonly},
{L"killring", electric_var_t::freadonly | electric_var_t::fcomputed},
{L"pipestatus", electric_var_t::freadonly | electric_var_t::fcomputed},
{L"status", electric_var_t::freadonly | electric_var_t::fcomputed},
{L"status_generation", electric_var_t::freadonly | electric_var_t::fcomputed},
@ -716,6 +718,8 @@ maybe_t<env_var_t> env_scoped_impl_t::try_get_computed(const wcstring &key) cons
wcstring_list_t result;
if (history) history->get_history(result);
return env_var_t(L"history", std::move(result));
} else if (key == L"killring") {
return env_var_t(L"killring", kill_entries());
} else if (key == L"pipestatus") {
const auto &js = perproc_data().statuses;
wcstring_list_t result;

View file

@ -83,6 +83,7 @@
#include "wcstringutil.h"
#include "wildcard.h"
#include "wutil.h" // IWYU pragma: keep
#include "kill.h"
static const char *const *s_arguments;
static int s_test_run_count = 0;
@ -6409,6 +6410,31 @@ Executed in 500.00 micros fish external
free(saved_locale);
}
static void test_killring() {
say(L"Testing killring");
do_test(kill_entries().empty());
kill_add(L"a");
kill_add(L"b");
kill_add(L"c");
do_test((kill_entries() == wcstring_list_t{L"c", L"b", L"a"}));
do_test(kill_yank_rotate() == L"b");
do_test((kill_entries() == wcstring_list_t{L"b", L"a", L"c"}));
do_test(kill_yank_rotate() == L"a");
do_test((kill_entries() == wcstring_list_t{L"a", L"c", L"b"}));
kill_add(L"d");
do_test((kill_entries() == wcstring_list_t{L"d", L"a", L"c", L"b"}));
do_test(kill_yank_rotate() == L"a");
do_test((kill_entries() == wcstring_list_t{L"a", L"c", L"b", L"d"}));
}
struct termsize_tester_t {
static void test();
};
@ -6617,6 +6643,7 @@ int main(int argc, char **argv) {
// history_tests_t::test_history_speed();
if (should_test_function("termsize")) termsize_tester_t::test();
if (should_test_function("killring")) test_killring();
say(L"Encountered %d errors in low-level tests", err_count);
if (s_test_run_count == 0) say(L"*** No Tests Were Actually Run! ***");

View file

@ -55,3 +55,7 @@ wcstring kill_yank() {
}
return kill_list.front();
}
wcstring_list_t kill_entries() {
return {kill_list.begin(), kill_list.end()};
}

View file

@ -19,4 +19,7 @@ wcstring kill_yank_rotate();
/// Paste from the killring.
wcstring kill_yank();
/// Get copy of kill ring as vector of strings
wcstring_list_t kill_entries();
#endif