Skip to content

Commit 7d54c32

Browse files
committed
Rustfmt libterm, skip long static in compiled.rs
1 parent 685e098 commit 7d54c32

File tree

6 files changed

+507
-390
lines changed

6 files changed

+507
-390
lines changed

src/libterm/lib.rs

+27-39
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,12 @@
6363
#![feature(str_char)]
6464
#![feature(vec_push_all)]
6565
#![cfg_attr(windows, feature(libc))]
66+
// Handle rustfmt skips
67+
#![feature(custom_attribute)]
68+
#![allow(unused_attributes)]
6669

67-
#[macro_use] extern crate log;
70+
#[macro_use]
71+
extern crate log;
6872

6973
pub use terminfo::TerminfoTerminal;
7074
#[cfg(windows)]
@@ -100,53 +104,37 @@ impl Write for WriterWrapper {
100104
/// Return a Terminal wrapping stdout, or None if a terminal couldn't be
101105
/// opened.
102106
pub fn stdout() -> Option<Box<Terminal<WriterWrapper> + Send>> {
103-
TerminfoTerminal::new(WriterWrapper {
104-
wrapped: box std::io::stdout(),
105-
})
107+
TerminfoTerminal::new(WriterWrapper { wrapped: box std::io::stdout() })
106108
}
107109

108110
#[cfg(windows)]
109111
/// Return a Terminal wrapping stdout, or None if a terminal couldn't be
110112
/// opened.
111113
pub fn stdout() -> Option<Box<Terminal<WriterWrapper> + Send>> {
112-
let ti = TerminfoTerminal::new(WriterWrapper {
113-
wrapped: box std::io::stdout(),
114-
});
114+
let ti = TerminfoTerminal::new(WriterWrapper { wrapped: box std::io::stdout() });
115115

116116
match ti {
117117
Some(t) => Some(t),
118-
None => {
119-
WinConsole::new(WriterWrapper {
120-
wrapped: box std::io::stdout(),
121-
})
122-
}
118+
None => WinConsole::new(WriterWrapper { wrapped: box std::io::stdout() }),
123119
}
124120
}
125121

126122
#[cfg(not(windows))]
127123
/// Return a Terminal wrapping stderr, or None if a terminal couldn't be
128124
/// opened.
129125
pub fn stderr() -> Option<Box<Terminal<WriterWrapper> + Send>> {
130-
TerminfoTerminal::new(WriterWrapper {
131-
wrapped: box std::io::stderr(),
132-
})
126+
TerminfoTerminal::new(WriterWrapper { wrapped: box std::io::stderr() })
133127
}
134128

135129
#[cfg(windows)]
136130
/// Return a Terminal wrapping stderr, or None if a terminal couldn't be
137131
/// opened.
138132
pub fn stderr() -> Option<Box<Terminal<WriterWrapper> + Send>> {
139-
let ti = TerminfoTerminal::new(WriterWrapper {
140-
wrapped: box std::io::stderr(),
141-
});
133+
let ti = TerminfoTerminal::new(WriterWrapper { wrapped: box std::io::stderr() });
142134

143135
match ti {
144136
Some(t) => Some(t),
145-
None => {
146-
WinConsole::new(WriterWrapper {
147-
wrapped: box std::io::stderr(),
148-
})
149-
}
137+
None => WinConsole::new(WriterWrapper { wrapped: box std::io::stderr() }),
150138
}
151139
}
152140

@@ -157,23 +145,23 @@ pub mod color {
157145
/// Number for a terminal color
158146
pub type Color = u16;
159147

160-
pub const BLACK: Color = 0;
161-
pub const RED: Color = 1;
162-
pub const GREEN: Color = 2;
163-
pub const YELLOW: Color = 3;
164-
pub const BLUE: Color = 4;
148+
pub const BLACK: Color = 0;
149+
pub const RED: Color = 1;
150+
pub const GREEN: Color = 2;
151+
pub const YELLOW: Color = 3;
152+
pub const BLUE: Color = 4;
165153
pub const MAGENTA: Color = 5;
166-
pub const CYAN: Color = 6;
167-
pub const WHITE: Color = 7;
168-
169-
pub const BRIGHT_BLACK: Color = 8;
170-
pub const BRIGHT_RED: Color = 9;
171-
pub const BRIGHT_GREEN: Color = 10;
172-
pub const BRIGHT_YELLOW: Color = 11;
173-
pub const BRIGHT_BLUE: Color = 12;
154+
pub const CYAN: Color = 6;
155+
pub const WHITE: Color = 7;
156+
157+
pub const BRIGHT_BLACK: Color = 8;
158+
pub const BRIGHT_RED: Color = 9;
159+
pub const BRIGHT_GREEN: Color = 10;
160+
pub const BRIGHT_YELLOW: Color = 11;
161+
pub const BRIGHT_BLUE: Color = 12;
174162
pub const BRIGHT_MAGENTA: Color = 13;
175-
pub const BRIGHT_CYAN: Color = 14;
176-
pub const BRIGHT_WHITE: Color = 15;
163+
pub const BRIGHT_CYAN: Color = 14;
164+
pub const BRIGHT_WHITE: Color = 15;
177165
}
178166

179167
/// Terminal attributes
@@ -206,7 +194,7 @@ pub mod attr {
206194
/// Convenience attribute to set the foreground color
207195
ForegroundColor(super::color::Color),
208196
/// Convenience attribute to set the background color
209-
BackgroundColor(super::color::Color)
197+
BackgroundColor(super::color::Color),
210198
}
211199
}
212200

src/libterm/terminfo/mod.rs

+70-62
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ use self::parm::{expand, Number, Variables};
2828
#[derive(Debug)]
2929
pub struct TermInfo {
3030
/// Names for the terminal
31-
pub names: Vec<String> ,
31+
pub names: Vec<String>,
3232
/// Map of capability name to boolean value
3333
pub bools: HashMap<String, bool>,
3434
/// Map of capability name to numeric value
3535
pub numbers: HashMap<String, u16>,
3636
/// Map of capability name to raw (unexpanded) string
37-
pub strings: HashMap<String, Vec<u8> >
37+
pub strings: HashMap<String, Vec<u8>>,
3838
}
3939

4040
pub mod searcher;
@@ -49,19 +49,19 @@ pub mod parm;
4949

5050
fn cap_for_attr(attr: attr::Attr) -> &'static str {
5151
match attr {
52-
attr::Bold => "bold",
53-
attr::Dim => "dim",
54-
attr::Italic(true) => "sitm",
55-
attr::Italic(false) => "ritm",
56-
attr::Underline(true) => "smul",
57-
attr::Underline(false) => "rmul",
58-
attr::Blink => "blink",
59-
attr::Standout(true) => "smso",
60-
attr::Standout(false) => "rmso",
61-
attr::Reverse => "rev",
62-
attr::Secure => "invis",
52+
attr::Bold => "bold",
53+
attr::Dim => "dim",
54+
attr::Italic(true) => "sitm",
55+
attr::Italic(false) => "ritm",
56+
attr::Underline(true) => "smul",
57+
attr::Underline(false) => "rmul",
58+
attr::Blink => "blink",
59+
attr::Standout(true) => "smso",
60+
attr::Standout(false) => "rmso",
61+
attr::Reverse => "rev",
62+
attr::Secure => "invis",
6363
attr::ForegroundColor(_) => "setaf",
64-
attr::BackgroundColor(_) => "setab"
64+
attr::BackgroundColor(_) => "setab",
6565
}
6666
}
6767

@@ -70,7 +70,7 @@ fn cap_for_attr(attr: attr::Attr) -> &'static str {
7070
pub struct TerminfoTerminal<T> {
7171
num_colors: u16,
7272
out: T,
73-
ti: Box<TermInfo>
73+
ti: Box<TermInfo>,
7474
}
7575

7676
impl<T: Write+Send+'static> Terminal<T> for TerminfoTerminal<T> {
@@ -80,12 +80,12 @@ impl<T: Write+Send+'static> Terminal<T> for TerminfoTerminal<T> {
8080
let s = expand(self.ti
8181
.strings
8282
.get("setaf")
83-
.unwrap()
84-
,
85-
&[Number(color as isize)], &mut Variables::new());
83+
.unwrap(),
84+
&[Number(color as isize)],
85+
&mut Variables::new());
8686
if s.is_ok() {
8787
try!(self.out.write_all(&s.unwrap()));
88-
return Ok(true)
88+
return Ok(true);
8989
}
9090
}
9191
Ok(false)
@@ -97,12 +97,12 @@ impl<T: Write+Send+'static> Terminal<T> for TerminfoTerminal<T> {
9797
let s = expand(self.ti
9898
.strings
9999
.get("setab")
100-
.unwrap()
101-
,
102-
&[Number(color as isize)], &mut Variables::new());
100+
.unwrap(),
101+
&[Number(color as isize)],
102+
&mut Variables::new());
103103
if s.is_ok() {
104104
try!(self.out.write_all(&s.unwrap()));
105-
return Ok(true)
105+
return Ok(true);
106106
}
107107
}
108108
Ok(false)
@@ -116,12 +116,10 @@ impl<T: Write+Send+'static> Terminal<T> for TerminfoTerminal<T> {
116116
let cap = cap_for_attr(attr);
117117
let parm = self.ti.strings.get(cap);
118118
if parm.is_some() {
119-
let s = expand(parm.unwrap(),
120-
&[],
121-
&mut Variables::new());
119+
let s = expand(parm.unwrap(), &[], &mut Variables::new());
122120
if s.is_ok() {
123121
try!(self.out.write_all(&s.unwrap()));
124-
return Ok(true)
122+
return Ok(true);
125123
}
126124
}
127125
Ok(false)
@@ -131,9 +129,7 @@ impl<T: Write+Send+'static> Terminal<T> for TerminfoTerminal<T> {
131129

132130
fn supports_attr(&self, attr: attr::Attr) -> bool {
133131
match attr {
134-
attr::ForegroundColor(_) | attr::BackgroundColor(_) => {
135-
self.num_colors > 0
136-
}
132+
attr::ForegroundColor(_) | attr::BackgroundColor(_) => self.num_colors > 0,
137133
_ => {
138134
let cap = cap_for_attr(attr);
139135
self.ti.strings.get(cap).is_some()
@@ -151,28 +147,33 @@ impl<T: Write+Send+'static> Terminal<T> for TerminfoTerminal<T> {
151147
cap = self.ti.strings.get("op");
152148
}
153149
}
154-
let s = cap.map_or(Err("can't find terminfo capability `sgr0`".to_owned()), |op| {
155-
expand(op, &[], &mut Variables::new())
156-
});
150+
let s = cap.map_or(Err("can't find terminfo capability `sgr0`".to_owned()),
151+
|op| expand(op, &[], &mut Variables::new()));
157152
if s.is_ok() {
158-
return self.out.write_all(&s.unwrap())
153+
return self.out.write_all(&s.unwrap());
159154
}
160155
Ok(())
161156
}
162157

163-
fn get_ref<'a>(&'a self) -> &'a T { &self.out }
158+
fn get_ref<'a>(&'a self) -> &'a T {
159+
&self.out
160+
}
164161

165-
fn get_mut<'a>(&'a mut self) -> &'a mut T { &mut self.out }
162+
fn get_mut<'a>(&'a mut self) -> &'a mut T {
163+
&mut self.out
164+
}
166165
}
167166

168167
impl<T: Write+Send+'static> UnwrappableTerminal<T> for TerminfoTerminal<T> {
169-
fn unwrap(self) -> T { self.out }
168+
fn unwrap(self) -> T {
169+
self.out
170+
}
170171
}
171172

172173
impl<T: Write+Send+'static> TerminfoTerminal<T> {
173174
/// Returns `None` whenever the terminal cannot be created for some
174175
/// reason.
175-
pub fn new(out: T) -> Option<Box<Terminal<T>+Send+'static>> {
176+
pub fn new(out: T) -> Option<Box<Terminal<T> + Send + 'static>> {
176177
let term = match env::var("TERM") {
177178
Ok(t) => t,
178179
Err(..) => {
@@ -183,20 +184,22 @@ impl<T: Write+Send+'static> TerminfoTerminal<T> {
183184

184185
let mut file = match open(&term[..]) {
185186
Ok(f) => f,
186-
Err(err) => return match env::var("MSYSCON") {
187-
Ok(ref val) if &val[..] == "mintty.exe" => {
188-
// msys terminal
189-
Some(box TerminfoTerminal{
190-
out: out,
191-
ti: msys_terminfo(),
192-
num_colors: 8,
193-
})
194-
},
195-
_ => {
196-
debug!("error finding terminfo entry: {:?}", err);
197-
None
198-
},
199-
},
187+
Err(err) => {
188+
return match env::var("MSYSCON") {
189+
Ok(ref val) if &val[..] == "mintty.exe" => {
190+
// msys terminal
191+
Some(box TerminfoTerminal {
192+
out: out,
193+
ti: msys_terminfo(),
194+
num_colors: 8,
195+
})
196+
}
197+
_ => {
198+
debug!("error finding terminfo entry: {:?}", err);
199+
None
200+
}
201+
};
202+
}
200203
};
201204

202205
let ti = parse(&mut file, false);
@@ -206,20 +209,25 @@ impl<T: Write+Send+'static> TerminfoTerminal<T> {
206209
}
207210

208211
let inf = ti.unwrap();
209-
let nc = if inf.strings.get("setaf").is_some()
210-
&& inf.strings.get("setab").is_some() {
211-
inf.numbers.get("colors").map_or(0, |&n| n)
212-
} else { 0 };
213-
214-
Some(box TerminfoTerminal {out: out,
215-
ti: inf,
216-
num_colors: nc})
212+
let nc = if inf.strings.get("setaf").is_some() && inf.strings.get("setab").is_some() {
213+
inf.numbers.get("colors").map_or(0, |&n| n)
214+
} else {
215+
0
216+
};
217+
218+
Some(box TerminfoTerminal {
219+
out: out,
220+
ti: inf,
221+
num_colors: nc,
222+
})
217223
}
218224

219225
fn dim_if_necessary(&self, color: color::Color) -> color::Color {
220226
if color >= self.num_colors && color >= 8 && color < 16 {
221-
color-8
222-
} else { color }
227+
color - 8
228+
} else {
229+
color
230+
}
223231
}
224232
}
225233

0 commit comments

Comments
 (0)