diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index 226dcb362..646cfcdac 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -6619,17 +6619,18 @@ static void test_timer_format() { t2.cpu_children.ru_stime.tv_usec = 500; t2.wall += std::chrono::microseconds(500); auto expected = - L"\x1b(0qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\x1b(B\n" -"Executed in 500.00 μs fish external\n" -" usr time 1.00 sec 1.00 sec 1.00 ms\n" -" sys time 1.00 sec 1.00 sec 0.50 ms"; - // (a) (b) (c) + LR"( +________________________________________________________ +Executed in 500.00 micros fish external + usr time 1.00 secs 1.00 secs 1.00 millis + sys time 1.00 secs 1.00 secs 0.50 millis +)"; // (a) (b) (c) // (a) remaining columns should align even if there are different units // (b) carry to the next unit when it would overflow %6.2F // (c) carry to the next unit when the larger one exceeds 1000 std::wstring actual = timer_snapshot_t::print_delta(t1, t2, true); if (actual != expected) { - err(L"Failed to format timer snapshot\nExpected:\n %ls\nActual:\n %ls\n", expected, + err(L"Failed to format timer snapshot\nExpected: %ls\nActual:%ls\n", expected, actual.c_str()); } setlocale(LC_NUMERIC, saved_locale); diff --git a/src/timer.cpp b/src/timer.cpp index 1fac5feaf..3906afc52 100644 --- a/src/timer.cpp +++ b/src/timer.cpp @@ -11,19 +11,6 @@ #include #include -#if HAVE_CURSES_H -#include -#elif HAVE_NCURSES_H -#include -#elif HAVE_NCURSES_CURSES_H -#include -#endif -#if HAVE_TERM_H -#include -#elif HAVE_NCURSES_TERM_H -#include -#endif - #include "builtin.h" #include "common.h" #include "exec.h" @@ -126,31 +113,31 @@ wcstring timer_snapshot_t::print_delta(const timer_snapshot_t &t1, const timer_s auto unit_name = [](tunit unit) { switch (unit) { case tunit::minutes: - return L"minutes"; + return "minutes"; case tunit::seconds: - return L"seconds"; + return "seconds"; case tunit::milliseconds: - return L"milliseconds"; + return "milliseconds"; case tunit::microseconds: - return L"microseconds"; + return "microseconds"; } // GCC does not recognize the exhaustive switch above - return L""; + return ""; }; auto unit_short_name = [](tunit unit) { switch (unit) { case tunit::minutes: - return L"min"; + return "mins"; case tunit::seconds: - return L"sec"; + return "secs"; case tunit::milliseconds: - return L"ms"; + return "millis"; case tunit::microseconds: - return L"μs"; + return "micros"; } // GCC does not recognize the exhaustive switch above - return L""; + return ""; }; auto convert = [](int64_t micros, tunit unit) { @@ -176,9 +163,10 @@ wcstring timer_snapshot_t::print_delta(const timer_snapshot_t &t1, const timer_s wcstring output; if (!verbose) { - append_format(output, L"\nExecuted in %6.2F %ls" - L"\n usr time %6.2F %ls" - L"\n sys time %6.2F %ls" + append_format(output, L"\n_______________________________" + L"\nExecuted in %6.2F %s" + L"\n usr time %6.2F %s" + L"\n sys time %6.2F %s" L"\n", wall_time, unit_name(wall_unit), usr_time, unit_name(cpu_unit), @@ -191,17 +179,16 @@ wcstring timer_snapshot_t::print_delta(const timer_snapshot_t &t1, const timer_s double child_usr_time = convert(child_usr_micros, child_unit); double child_sys_time = convert(child_sys_micros, child_unit); - int column2_unit_len = std::max(wcslen(unit_short_name(wall_unit)), - wcslen(unit_short_name(cpu_unit))); - // TODO: improve layout + int column2_unit_len = std::max(strlen(unit_short_name(wall_unit)), + strlen(unit_short_name(cpu_unit))); append_format(output, - L"%s%s%s" - L"\nExecuted in %6.2F %-*ls %-*s %s" - L"\n usr time %6.2F %-*ls %6.2F %ls %6.2F %ls" - L"\n sys time %6.2F %-*ls %6.2F %ls %6.2F %ls", - enter_alt_charset_mode, std::string(45, 'q').c_str(), exit_alt_charset_mode, + L"\n________________________________________________________" + L"\nExecuted in %6.2F %-*s %-*s %s" + L"\n usr time %6.2F %-*s %6.2F %s %6.2F %s" + L"\n sys time %6.2F %-*s %6.2F %s %6.2F %s" + L"\n", wall_time, column2_unit_len, unit_short_name(wall_unit), - static_cast(wcslen(unit_short_name(fish_unit))) + 7, "fish", "external", + static_cast(strlen(unit_short_name(fish_unit))) + 7, "fish", "external", usr_time, column2_unit_len, unit_short_name(cpu_unit), fish_usr_time, unit_short_name(fish_unit), child_usr_time, unit_short_name(child_unit), sys_time, column2_unit_len, unit_short_name(cpu_unit), fish_sys_time, diff --git a/tests/checks/time.fish b/tests/checks/time.fish index 7923dce6f..0eb469be7 100644 --- a/tests/checks/time.fish +++ b/tests/checks/time.fish @@ -3,37 +3,37 @@ time sleep 0 # These are a tad awkward because it picks the correct unit and adapts whitespace. # The idea is that it's a table. -#CHECKERR: {{.*}} -#CHECKERR: Executed in {{[\d,.\s]*}} {{ms|μs|sec}} {{\s*}}fish {{\s*}}external -#CHECKERR: usr time {{[\d,.\s]*}} {{ms|μs|sec}} {{[\d,.\s]*}} {{ms|μs|sec}} {{[\d,.\s]*}} {{ms|μs|sec}} -#CHECKERR: sys time {{[\d,.\s]*}} {{ms|μs|sec}} {{[\d,.\s]*}} {{ms|μs|sec}} {{[\d,.\s]*}} {{ms|μs|sec}} +#CHECKERR: ________________________________________________________ +#CHECKERR: Executed in {{[\d,.\s]*}} {{millis|micros|secs}} {{\s*}}fish {{\s*}}external +#CHECKERR: usr time {{[\d,.\s]*}} {{millis|micros|secs}} {{[\d,.\s]*}} {{millis|micros|secs}} {{[\d,.\s]*}} {{millis|micros|secs}} +#CHECKERR: sys time {{[\d,.\s]*}} {{millis|micros|secs}} {{[\d,.\s]*}} {{millis|micros|secs}} {{[\d,.\s]*}} {{millis|micros|secs}} time for i in (seq 1 2) echo banana end #CHECK: banana #CHECK: banana -#CHECKERR: {{.*}} -#CHECKERR: Executed in {{[\d,.\s]*}} {{ms|μs|sec}} {{\s*}}fish {{\s*}}external -#CHECKERR: usr time {{[\d,.\s]*}} {{ms|μs|sec}} {{[\d,.\s]*}} {{ms|μs|sec}} {{[\d,.\s]*}} {{ms|μs|sec}} -#CHECKERR: sys time {{[\d,.\s]*}} {{ms|μs|sec}} {{[\d,.\s]*}} {{ms|μs|sec}} {{[\d,.\s]*}} {{ms|μs|sec}} +#CHECKERR: ________________________________________________________ +#CHECKERR: Executed in {{[\d,.\s]*}} {{millis|micros|secs}} {{\s*}}fish {{\s*}}external +#CHECKERR: usr time {{[\d,.\s]*}} {{millis|micros|secs}} {{[\d,.\s]*}} {{millis|micros|secs}} {{[\d,.\s]*}} {{millis|micros|secs}} +#CHECKERR: sys time {{[\d,.\s]*}} {{millis|micros|secs}} {{[\d,.\s]*}} {{millis|micros|secs}} {{[\d,.\s]*}} {{millis|micros|secs}} # Make sure we're not double-parsing time echo 'foo -s bar' #CHECK: foo -s bar -#CHECKERR: {{.*}} -#CHECKERR: Executed in {{[\d,.\s]*}} {{ms|μs|sec}} {{\s*}}fish {{\s*}}external -#CHECKERR: usr time {{[\d,.\s]*}} {{ms|μs|sec}} {{[\d,.\s]*}} {{ms|μs|sec}} {{[\d,.\s]*}} {{ms|μs|sec}} -#CHECKERR: sys time {{[\d,.\s]*}} {{ms|μs|sec}} {{[\d,.\s]*}} {{ms|μs|sec}} {{[\d,.\s]*}} {{ms|μs|sec}} +#CHECKERR: ________________________________________________________ +#CHECKERR: Executed in {{[\d,.\s]*}} {{millis|micros|secs}} {{\s*}}fish {{\s*}}external +#CHECKERR: usr time {{[\d,.\s]*}} {{millis|micros|secs}} {{[\d,.\s]*}} {{millis|micros|secs}} {{[\d,.\s]*}} {{millis|micros|secs}} +#CHECKERR: sys time {{[\d,.\s]*}} {{millis|micros|secs}} {{[\d,.\s]*}} {{millis|micros|secs}} {{[\d,.\s]*}} {{millis|micros|secs}} true && time a=b not builtin true | true -#CHECKERR: {{.*}} +#CHECKERR: ___{{.*}} #CHECKERR: {{.*}} #CHECKERR: {{.*}} #CHECKERR: {{.*}} not time true -#CHECKERR: {{.*}} +#CHECKERR: ___{{.*}} #CHECKERR: {{.*}} #CHECKERR: {{.*}} #CHECKERR: {{.*}}