mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-01-21 15:03:00 +08:00
Don't use printf("%d") just to convert an int to a string.
std::to_string, std::to_wstring are more appropriate
This commit is contained in:
parent
59cb2d02a8
commit
c2bc0c67f2
|
@ -1796,16 +1796,13 @@ static void validate_new_termsize(struct winsize *new_termsize, const environmen
|
|||
|
||||
/// Export the new terminal size as env vars and to the kernel if possible.
|
||||
static void export_new_termsize(struct winsize *new_termsize, env_stack_t &vars) {
|
||||
wchar_t buf[64];
|
||||
|
||||
auto cols = vars.get(L"COLUMNS", ENV_EXPORT);
|
||||
swprintf(buf, 64, L"%d", (int)new_termsize->ws_col);
|
||||
vars.set_one(L"COLUMNS", ENV_GLOBAL | (cols.missing_or_empty() ? ENV_DEFAULT : ENV_EXPORT),
|
||||
buf);
|
||||
std::to_wstring(int(new_termsize->ws_col)));
|
||||
|
||||
auto lines = vars.get(L"LINES", ENV_EXPORT);
|
||||
swprintf(buf, 64, L"%d", (int)new_termsize->ws_row);
|
||||
vars.set_one(L"LINES", ENV_GLOBAL | (lines.missing_or_empty() ? ENV_DEFAULT : ENV_EXPORT), buf);
|
||||
vars.set_one(L"LINES", ENV_GLOBAL | (lines.missing_or_empty() ? ENV_DEFAULT : ENV_EXPORT),
|
||||
std::to_wstring(int(new_termsize->ws_row)));
|
||||
|
||||
#ifdef HAVE_WINSIZE
|
||||
// Only write the new terminal size if we are in the foreground (#4477)
|
||||
|
|
|
@ -1545,7 +1545,7 @@ static void test_lru() {
|
|||
auto commajoin = [](const std::vector<int> &vs) {
|
||||
wcstring ret;
|
||||
for (int v : vs) {
|
||||
append_format(ret, L"%d,", v);
|
||||
ret.append(std::to_wstring(v));
|
||||
}
|
||||
if (!ret.empty()) ret.pop_back();
|
||||
return ret;
|
||||
|
|
|
@ -2013,15 +2013,13 @@ bool reader_get_selection(size_t *start, size_t *len) {
|
|||
void set_env_cmd_duration(struct timeval *after, struct timeval *before, env_stack_t &vars) {
|
||||
time_t secs = after->tv_sec - before->tv_sec;
|
||||
suseconds_t usecs = after->tv_usec - before->tv_usec;
|
||||
wchar_t buf[16];
|
||||
|
||||
if (after->tv_usec < before->tv_usec) {
|
||||
usecs += 1000000;
|
||||
secs -= 1;
|
||||
}
|
||||
|
||||
swprintf(buf, 16, L"%d", (secs * 1000) + (usecs / 1000));
|
||||
vars.set_one(ENV_CMD_DURATION, ENV_UNEXPORT, buf);
|
||||
vars.set_one(ENV_CMD_DURATION, ENV_UNEXPORT, std::to_wstring((secs * 1000) + (usecs / 1000)));
|
||||
}
|
||||
|
||||
void reader_run_command(parser_t &parser, const wcstring &cmd) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user