mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-25 10:11:17 -03:00
Switch env_var to using maybe_t
This eliminates the "missing" notion of env_var_t. Instead env_get returns a maybe_t<env_var_t>, which forces callers to handle the possibility that the variable is missing.
This commit is contained in:
@@ -1553,13 +1553,13 @@ static void validate_new_termsize(struct winsize *new_termsize) {
|
||||
}
|
||||
#endif
|
||||
// Fallback to the environment vars.
|
||||
env_var_t col_var = env_get(L"COLUMNS");
|
||||
env_var_t row_var = env_get(L"LINES");
|
||||
maybe_t<env_var_t> col_var = env_get(L"COLUMNS");
|
||||
maybe_t<env_var_t> row_var = env_get(L"LINES");
|
||||
if (!col_var.missing_or_empty() && !row_var.missing_or_empty()) {
|
||||
// Both vars have to have valid values.
|
||||
int col = fish_wcstoi(col_var.as_string().c_str());
|
||||
int col = fish_wcstoi(col_var->as_string().c_str());
|
||||
bool col_ok = errno == 0 && col > 0 && col <= USHRT_MAX;
|
||||
int row = fish_wcstoi(row_var.as_string().c_str());
|
||||
int row = fish_wcstoi(row_var->as_string().c_str());
|
||||
bool row_ok = errno == 0 && row > 0 && row <= USHRT_MAX;
|
||||
if (col_ok && row_ok) {
|
||||
new_termsize->ws_col = col;
|
||||
@@ -1582,11 +1582,11 @@ static void validate_new_termsize(struct winsize *new_termsize) {
|
||||
static void export_new_termsize(struct winsize *new_termsize) {
|
||||
wchar_t buf[64];
|
||||
|
||||
env_var_t cols = env_get(L"COLUMNS", ENV_EXPORT);
|
||||
auto cols = env_get(L"COLUMNS", ENV_EXPORT);
|
||||
swprintf(buf, 64, L"%d", (int)new_termsize->ws_col);
|
||||
env_set_one(L"COLUMNS", ENV_GLOBAL | (cols.missing_or_empty() ? ENV_DEFAULT : ENV_EXPORT), buf);
|
||||
|
||||
env_var_t lines = env_get(L"LINES", ENV_EXPORT);
|
||||
auto lines = env_get(L"LINES", ENV_EXPORT);
|
||||
swprintf(buf, 64, L"%d", (int)new_termsize->ws_row);
|
||||
env_set_one(L"LINES", ENV_GLOBAL | (lines.missing_or_empty() ? ENV_DEFAULT : ENV_EXPORT), buf);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user