diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/comp/front/extenv.rs | 13 | ||||
| -rw-r--r-- | src/lib/GenericOS.rs | 9 | ||||
| -rw-r--r-- | src/lib/Term.rs | 2 |
3 files changed, 19 insertions, 5 deletions
diff --git a/src/comp/front/extenv.rs b/src/comp/front/extenv.rs index a3fdde95..15483cec 100644 --- a/src/comp/front/extenv.rs +++ b/src/comp/front/extenv.rs @@ -23,9 +23,18 @@ fn expand_syntax_ext(parser.parser p, p.err("malformed #env call"); } + // FIXME: if this was more thorough it would manufacture an + // Option.t[str] rather than just an maybe-empty string. + auto var = expr_to_str(p, args.(0)); - auto val = GenericOS.getenv(var); - ret make_new_str(sp, val); + alt (GenericOS.getenv(var)) { + case (Option.none[str]) { + ret make_new_str(sp, ""); + } + case (Option.some[str](?s)) { + ret make_new_str(sp, s); + } + } } // FIXME: duplicate code copied from extfmt. diff --git a/src/lib/GenericOS.rs b/src/lib/GenericOS.rs index c60fa2b8..30b1d1d0 100644 --- a/src/lib/GenericOS.rs +++ b/src/lib/GenericOS.rs @@ -1,4 +1,9 @@ -fn getenv(str n) -> str { - ret Str.str_from_cstr(OS.libc.getenv(Str.buf(n))); +fn getenv(str n) -> Option.t[str] { + auto s = OS.libc.getenv(Str.buf(n)); + if (s == 0 as Str.sbuf) { + ret Option.none[str]; + } else { + ret Option.some[str](Str.str_from_cstr(s)); + } } diff --git a/src/lib/Term.rs b/src/lib/Term.rs index fca04bff..b07dcc0c 100644 --- a/src/lib/Term.rs +++ b/src/lib/Term.rs @@ -31,7 +31,7 @@ fn reset(IO.buf_writer writer) { } fn color_supported() -> bool { - ret Str.eq(GenericOS.getenv("TERM"), "xterm-color"); + ret GenericOS.getenv("TERM") == Option.some[str]("xterm-color"); } fn set_color(IO.buf_writer writer, u8 first_char, u8 color) { |