Skip to content

Commit 8eec3a7

Browse files
committed
---
yaml --- r: 63317 b: refs/heads/snap-stage3 c: c9e234a h: refs/heads/master i: 63315: 12f7ed5 v: v3
1 parent c003a69 commit 8eec3a7

File tree

3 files changed

+28
-17
lines changed

3 files changed

+28
-17
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 9f9e50540581881a3c3a7304eaa2577afda59048
4+
refs/heads/snap-stage3: c9e234a1ae7b631ca058f2331a3986630b5d1b64
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libextra/term.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use core::os;
2020
use terminfo::*;
2121
use terminfo::searcher::open;
2222
use terminfo::parser::compiled::parse;
23-
use terminfo::parm::{expand, Number};
23+
use terminfo::parm::{expand, Number, Variables};
2424

2525
// FIXME (#2807): Windows support.
2626

@@ -84,7 +84,7 @@ impl Terminal {
8484
pub fn fg(&self, color: u8) {
8585
if self.color_supported {
8686
let s = expand(*self.ti.strings.find_equiv(&("setaf")).unwrap(),
87-
[Number(color as int)], [], []);
87+
[Number(color as int)], &mut Variables::new());
8888
if s.is_ok() {
8989
self.out.write(s.get());
9090
} else {
@@ -95,7 +95,7 @@ impl Terminal {
9595
pub fn bg(&self, color: u8) {
9696
if self.color_supported {
9797
let s = expand(*self.ti.strings.find_equiv(&("setab")).unwrap(),
98-
[Number(color as int)], [], []);
98+
[Number(color as int)], &mut Variables::new());
9999
if s.is_ok() {
100100
self.out.write(s.get());
101101
} else {
@@ -105,7 +105,7 @@ impl Terminal {
105105
}
106106
pub fn reset(&self) {
107107
if self.color_supported {
108-
let s = expand(*self.ti.strings.find_equiv(&("op")).unwrap(), [], [], []);
108+
let s = expand(*self.ti.strings.find_equiv(&("op")).unwrap(), [], &mut Variables::new());
109109
if s.is_ok() {
110110
self.out.write(s.get());
111111
} else {

branches/snap-stage3/src/libextra/terminfo/parm.rs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,37 @@ pub enum Param {
3434
Number(int)
3535
}
3636

37+
/// Container for static and dynamic variable arrays
38+
pub struct Variables {
39+
/// Static variables A-Z
40+
sta: [Param, ..26],
41+
/// Dynamic variables a-z
42+
dyn: [Param, ..26]
43+
}
44+
45+
impl Variables {
46+
/// Return a new zero-initialized Variables
47+
pub fn new() -> Variables {
48+
Variables{ sta: [Number(0), ..26], dyn: [Number(0), ..26] }
49+
}
50+
}
51+
3752
/**
3853
Expand a parameterized capability
3954
4055
# Arguments
4156
* `cap` - string to expand
4257
* `params` - vector of params for %p1 etc
43-
* `sta` - vector of params corresponding to static variables
44-
* `dyn` - vector of params corresponding to stativ variables
58+
* `vars` - Variables struct for %Pa etc
4559
46-
To be compatible with ncurses, `sta` and `dyn` should be the same between calls to `expand` for
60+
To be compatible with ncurses, `vars` should be the same between calls to `expand` for
4761
multiple capabilities for the same terminal.
4862
*/
49-
pub fn expand(cap: &[u8], params: &mut [Param], sta: &mut [Param], dyn: &mut [Param])
63+
pub fn expand(cap: &[u8], params: &mut [Param], vars: &mut Variables)
5064
-> Result<~[u8], ~str> {
5165
assert!(cap.len() != 0, "expanding an empty capability makes no sense");
5266
assert!(params.len() <= 9, "only 9 parameters are supported by capability strings");
5367

54-
assert!(sta.len() <= 26, "only 26 static vars are able to be used by capability strings");
55-
assert!(dyn.len() <= 26, "only 26 dynamic vars are able to be used by capability strings");
56-
5768
let mut state = Nothing;
5869
let mut i = 0;
5970

@@ -170,21 +181,21 @@ pub fn expand(cap: &[u8], params: &mut [Param], sta: &mut [Param], dyn: &mut [Pa
170181
SetVar => {
171182
if cur >= 'A' && cur <= 'Z' {
172183
let idx = (cur as u8) - ('A' as u8);
173-
sta[idx] = stack.pop();
184+
vars.sta[idx] = stack.pop();
174185
} else if cur >= 'a' && cur <= 'z' {
175186
let idx = (cur as u8) - ('a' as u8);
176-
dyn[idx] = stack.pop();
187+
vars.dyn[idx] = stack.pop();
177188
} else {
178189
return Err(~"bad variable name in %P");
179190
}
180191
},
181192
GetVar => {
182193
if cur >= 'A' && cur <= 'Z' {
183194
let idx = (cur as u8) - ('A' as u8);
184-
stack.push(copy sta[idx]);
195+
stack.push(copy vars.sta[idx]);
185196
} else if cur >= 'a' && cur <= 'z' {
186197
let idx = (cur as u8) - ('a' as u8);
187-
stack.push(copy dyn[idx]);
198+
stack.push(copy vars.dyn[idx]);
188199
} else {
189200
return Err(~"bad variable name in %g");
190201
}
@@ -222,6 +233,6 @@ mod test {
222233
#[test]
223234
fn test_basic_setabf() {
224235
let s = bytes!("\\E[48;5;%p1%dm");
225-
assert_eq!(expand(s, [Number(1)], [], []).unwrap(), bytes!("\\E[48;5;1m").to_owned());
236+
assert_eq!(expand(s, [Number(1)], &mut Variables::new()).unwrap(), bytes!("\\E[48;5;1m").to_owned());
226237
}
227238
}

0 commit comments

Comments
 (0)