aboutsummaryrefslogtreecommitdiffstats
path: root/src/info.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/info.rs')
-rw-r--r--src/info.rs65
1 files changed, 51 insertions, 14 deletions
diff --git a/src/info.rs b/src/info.rs
index 5504de1..e4aa546 100644
--- a/src/info.rs
+++ b/src/info.rs
@@ -26,14 +26,33 @@ pub fn init () {
macro_rules! def_escape(
($name:ident -> $escape:expr) => (
- pub fn $name () -> ~str { escape($escape) }
+ pub fn $name () -> ~str {
+ let attr = $escape;
+ match escape(attr) {
+ Some(e) => e,
+ None => fail!(fmt!("%s is not supported on this terminal",
+ attr)),
+ }
+ }
);
($name:ident -> $escape:expr, $ty1:ident) => (
- pub fn $name (p1: $ty1) -> ~str { escape1($escape, p1 as int) }
+ pub fn $name (p1: $ty1) -> ~str {
+ let attr = $escape;
+ match escape1(attr, p1 as int) {
+ Some(e) => e,
+ None => fail!(fmt!("%s is not supported on this terminal",
+ attr)),
+ }
+ }
);
($name:ident -> $escape:expr, $ty1:ident, $ty2:ident) => (
pub fn $name (p1: $ty1, p2: $ty2) -> ~str {
- escape2($escape, p1 as int, p2 as int)
+ let attr = $escape;
+ match escape2(attr, p1 as int, p2 as int) {
+ Some(e) => e,
+ None => fail!(fmt!("%s is not supported on this terminal",
+ attr)),
+ }
}
);
)
@@ -131,14 +150,24 @@ def_escape!(key_f12 -> "kf12")
/// The terminal escape generated by the F<`n`> key.
pub fn key_f (n: uint) -> ~str {
- escape(fmt!("kf%?", n))
+ let attr = fmt!("kf%?", n);
+ match escape(attr) {
+ Some(e) => e,
+ None => fail!(fmt!("%s is not supported on this terminal", attr)),
+ }
}
/// The terminal escape corresponding to the `name` terminfo capability.
-pub fn escape (name: &str) -> ~str {
+pub fn escape (name: &str) -> Option<~str> {
do str::as_c_str(name) |c_name| {
unsafe {
- str::raw::from_c_str(tigetstr(c_name))
+ let e = tigetstr(c_name);
+ if e == ptr::null() {
+ None
+ }
+ else {
+ Some(str::raw::from_c_str(e))
+ }
}
}
}
@@ -148,10 +177,16 @@ pub fn escape (name: &str) -> ~str {
*
* This capability must take one parameter, which should be passed as `p1`.
*/
-pub fn escape1 (name: &str, p1: int) -> ~str {
+pub fn escape1 (name: &str, p1: int) -> Option<~str> {
do str::as_c_str(name) |c_name| {
unsafe {
- str::raw::from_c_str(tiparm1(tigetstr(c_name), p1))
+ let e = tigetstr(c_name);
+ if e == ptr::null() {
+ None
+ }
+ else {
+ Some(str::raw::from_c_str(tiparm1(e, p1)))
+ }
}
}
}
@@ -162,10 +197,16 @@ pub fn escape1 (name: &str, p1: int) -> ~str {
* This capability must take two parameters, which should be passed as `p1`
* and `p2`.
*/
-pub fn escape2 (name: &str, p1: int, p2: int) -> ~str {
+pub fn escape2 (name: &str, p1: int, p2: int) -> Option<~str> {
do str::as_c_str(name) |c_name| {
unsafe {
- str::raw::from_c_str(tiparm2(tigetstr(c_name), p1, p2))
+ let e = tigetstr(c_name);
+ if e == ptr::null() {
+ None
+ }
+ else {
+ Some(str::raw::from_c_str(tiparm2(e, p1, p2)))
+ }
}
}
}
@@ -176,10 +217,6 @@ unsafe fn tigetstr (name: *c_char) -> *c_char {
fail!(fmt!("%s is not a terminal capability",
unsafe { str::raw::from_c_str(name) }));
}
- else if c_out == ptr::null() {
- fail!(fmt!("The current terminal doesn't support %s",
- unsafe { str::raw::from_c_str(name) }));
- }
c_out
}