From 6936e64b34afd8dfaa506815844573fdd13cd768 Mon Sep 17 00:00:00 2001 From: Aaron Gyes Date: Wed, 24 Aug 2016 21:22:32 -0700 Subject: [PATCH 1/2] Show history timestamps on seperate lines #-prefixed. Improves the grouping of multiline history entries by sepearating the timestamps and history entires onto seperate lines. Use wcsftime() Saves us a conversion, might as well. --- doc_src/history.txt | 2 +- src/history.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc_src/history.txt b/doc_src/history.txt index fa0cef87f..d0553d6d7 100644 --- a/doc_src/history.txt +++ b/doc_src/history.txt @@ -34,7 +34,7 @@ The following options are available: - `-p` or `--prefix` searches or deletes items in the history that begin with the specified text string. This is not currently supported by the `--delete` flag. -- `-t` or `--with-time` prefixes the output of each displayed history entry with the time it was recorded in the format "%Y-%m-%d %H:%M:%S" in your local timezone. +- `-t` or `--with-time` outputs the date and time history items were recorded at before each history entry, formatted for the configured locale. See environ(7) for more information. \subsection history-examples Example diff --git a/src/history.cpp b/src/history.cpp index 13fde6715..d8d503cf2 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -1402,9 +1402,9 @@ static bool format_history_record(const history_item_t &item, const bool with_ti const time_t seconds = item.timestamp(); struct tm timestamp; if (!localtime_r(&seconds, ×tamp)) return false; - char timestamp_string[22]; - if (strftime(timestamp_string, 22, "%Y-%m-%d %H:%M:%S ", ×tamp) != 21) return false; - streams.out.append(str2wcstring(timestamp_string)); + wchar_t timestamp_string[64]; + if (std::wcsftime(timestamp_string, 63, L"# %c:\n", ×tamp) == 0) return false; + streams.out.append(timestamp_string); } streams.out.append(item.str()); streams.out.append(L"\n"); From 3d6cb59b311fba0e38af3266930a58361fb9874b Mon Sep 17 00:00:00 2001 From: Aaron Gyes Date: Wed, 7 Sep 2016 07:16:02 -0700 Subject: [PATCH 2/2] Use %Y-%m-%d %H:%M:%S format, update tests Update history docs. Note - the omission of a mention of timezone was intentional. These were recorded as naive timestamps lacking timezone information in the first place. --- doc_src/history.txt | 2 +- src/history.cpp | 4 ++-- tests/history.expect | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc_src/history.txt b/doc_src/history.txt index d0553d6d7..a2c73201d 100644 --- a/doc_src/history.txt +++ b/doc_src/history.txt @@ -34,7 +34,7 @@ The following options are available: - `-p` or `--prefix` searches or deletes items in the history that begin with the specified text string. This is not currently supported by the `--delete` flag. -- `-t` or `--with-time` outputs the date and time history items were recorded at before each history entry, formatted for the configured locale. See environ(7) for more information. +- `-t` or `--with-time` outputs the date and time ("%Y-%m-%d %H:%M:%S") history items were recorded at on a line starting with "#" before each history entry. \subsection history-examples Example diff --git a/src/history.cpp b/src/history.cpp index d8d503cf2..12e0ef1ef 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -1402,8 +1402,8 @@ static bool format_history_record(const history_item_t &item, const bool with_ti const time_t seconds = item.timestamp(); struct tm timestamp; if (!localtime_r(&seconds, ×tamp)) return false; - wchar_t timestamp_string[64]; - if (std::wcsftime(timestamp_string, 63, L"# %c:\n", ×tamp) == 0) return false; + wchar_t timestamp_string[24]; + if (std::wcsftime(timestamp_string, 23, L"# %Y-%m-%d %H:%M:%S\n", ×tamp) == 0) return false; streams.out.append(timestamp_string); } streams.out.append(item.str()); diff --git a/tests/history.expect b/tests/history.expect index d1fcaf355..9e3269ee0 100644 --- a/tests/history.expect +++ b/tests/history.expect @@ -78,7 +78,7 @@ expect_prompt -re {\r\necho start1.*\r\necho start2} { # ========== # Verify implicit searching with a request for timestamps includes the timestamps. send "history -t echo start\r" -expect_prompt -re {\r\n\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d echo start1; builtin history;.*\r\n\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d echo start2; builtin history} { +expect_prompt -re {\r\n# \d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d\r\necho start1; builtin history;.*\r\n# \d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d\r\necho start2; builtin history} { puts "history function implicit search with timestamps succeeded" } unmatched { puts stderr "history function implicit search with timestamps failed"