From c881c744b38932d3d96a0fcec9deb81ca4d25fcb Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Tue, 9 Apr 2013 03:07:48 -0500 Subject: apparently ::new is the convention these days --- src/hexes.rs | 61 ++++++++++++++++++++++++++++++------------------------------ test/rl.rs | 2 +- 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/src/hexes.rs b/src/hexes.rs index 4de2f12..01d4c65 100644 --- a/src/hexes.rs +++ b/src/hexes.rs @@ -28,32 +28,33 @@ struct Term { priv w: Writer, } -/** - * Creates a new `Term` instance. - * - * This can be used to manipulate the terminal for full screen applications. - */ -pub fn Term () -> Term { - info::init(); - - cbreak(); - echo(false); - - // XXX need to come up with a better way to handle optional caps - // should be able to use something like has_keypad_xmit or something - for ["smkx", "smcup", "sgr0", "cnorm"].each() |&cap| { - match info::escape(cap) { - Some(e) => print(e), - None => (), // not a big deal if these don't exist +impl Term { + /** + * Creates a new `Term` instance. + * + * This can be used to manipulate the terminal for full screen + * applications. + */ + pub fn new () -> Term { + info::init(); + + cbreak(); + echo(false); + + // XXX need to come up with a better way to handle optional caps + // should be able to use something like has_keypad_xmit or something + for ["smkx", "smcup", "sgr0", "cnorm"].each() |&cap| { + match info::escape(cap) { + Some(e) => print(e), + None => (), // not a big deal if these don't exist + } } - } - print(info::clear_screen()); + print(info::clear_screen()); - Term { r: Reader(), w: Writer() } -} + Term { r: Reader::new(), w: Writer::new() } + } -impl Term { /// Clears the screen. pub fn clear (&mut self) { self.w.clear(); @@ -196,10 +197,6 @@ struct AttrState { blink: bool, } -fn Writer () -> Writer { - Writer { buf: ~"", state: AttrState() } -} - fn AttrState () -> AttrState { AttrState { fg: None, @@ -213,6 +210,10 @@ fn AttrState () -> AttrState { } impl Writer { + fn new () -> Writer { + Writer { buf: ~"", state: AttrState() } + } + fn clear (&mut self) { self.buf.push_str(info::clear_screen()); } @@ -378,11 +379,11 @@ struct Reader { priv buf: ~str, } -fn Reader () -> Reader { - Reader { escapes: build_escapes_trie(), buf: ~"" } -} - impl Reader { + fn new () -> Reader { + Reader { escapes: build_escapes_trie(), buf: ~"" } + } + fn read (&mut self) -> Option { if self.buf.len() > 0 { return Some(self.next_key()); diff --git a/test/rl.rs b/test/rl.rs index 8771056..7ba3cd0 100644 --- a/test/rl.rs +++ b/test/rl.rs @@ -40,7 +40,7 @@ fn main () { let (cols, rows) = term::ios::size(); { - let mut term = Term(); + let mut term = Term::new(); let mut (x, y) = (0u, 0u); let mut cursor = true; -- cgit v1.2.3-54-g00ecf