From 82e6fca1ddee3b97506dd1404aafe2af61052a25 Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Mon, 23 Feb 2015 20:50:55 -0800 Subject: [PATCH] Updated code for latest rustc. --- src/buffer/mod.rs | 20 ++++++++++---------- src/buffer/undo_stack.rs | 10 +++++----- src/editor/mod.rs | 6 +++--- src/main.rs | 8 ++++---- src/term_ui/mod.rs | 22 +++++++++++++++------- 5 files changed, 37 insertions(+), 29 deletions(-) diff --git a/src/buffer/mod.rs b/src/buffer/mod.rs index 3f89050..81004ad 100644 --- a/src/buffer/mod.rs +++ b/src/buffer/mod.rs @@ -194,7 +194,7 @@ impl Buffer { // manipulates the node tree. let s = self.string_from_range(pos_a, pos_b); self._remove_text(pos_a, pos_b); - self._insert_text(&s[], pos_to); + self._insert_text(&s[..], pos_to); } } @@ -257,19 +257,19 @@ impl Buffer { if let Some(op) = self.undo_stack.prev() { match op { InsertText(ref s, p) => { - let size = grapheme_count(&s[]); + let size = grapheme_count(&s[..]); self._remove_text(p, p+size); return Some(p); }, RemoveTextBefore(ref s, p) => { - let size = grapheme_count(&s[]); - self._insert_text(&s[], p); + let size = grapheme_count(&s[..]); + self._insert_text(&s[..], p); return Some(p+size); }, RemoveTextAfter(ref s, p) => { - self._insert_text(&s[], p); + self._insert_text(&s[..], p); return Some(p); }, @@ -295,13 +295,13 @@ impl Buffer { if let Some(op) = self.undo_stack.next() { match op { InsertText(ref s, p) => { - let size = grapheme_count(&s[]); - self._insert_text(&s[], p); + let size = grapheme_count(&s[..]); + self._insert_text(&s[..], p); return Some(p+size); }, RemoveTextBefore(ref s, p) | RemoveTextAfter(ref s, p) => { - let size = grapheme_count(&s[]); + let size = grapheme_count(&s[..]); self._remove_text(p, p+size); return Some(p); }, @@ -1505,7 +1505,7 @@ mod tests { let s = buf.string_from_range(1, 12); - assert!(&s[] == "i\nthere\npeo"); + assert!(&s[..] == "i\nthere\npeo"); } @@ -1516,7 +1516,7 @@ mod tests { let s = buf.string_from_range(0, 29); - assert!(&s[] == "Hi\nthere\npeople\nof\nthe\nworld!"); + assert!(&s[..] == "Hi\nthere\npeople\nof\nthe\nworld!"); } diff --git a/src/buffer/undo_stack.rs b/src/buffer/undo_stack.rs index 7a8c91a..f00793a 100644 --- a/src/buffer/undo_stack.rs +++ b/src/buffer/undo_stack.rs @@ -1,4 +1,4 @@ -use std::collections::DList; +use std::collections::LinkedList; /// A text editing operation @@ -14,15 +14,15 @@ pub enum Operation { /// An undo/redo stack of text editing operations pub struct UndoStack { - stack_a: DList, - stack_b: DList, + stack_a: LinkedList, + stack_b: LinkedList, } impl UndoStack { pub fn new() -> UndoStack { UndoStack { - stack_a: DList::new(), - stack_b: DList::new(), + stack_a: LinkedList::new(), + stack_b: LinkedList::new(), } } diff --git a/src/editor/mod.rs b/src/editor/mod.rs index ca29337..86a83cf 100644 --- a/src/editor/mod.rs +++ b/src/editor/mod.rs @@ -141,7 +141,7 @@ impl Editor { // Analyze stats and make a determination let mut lei = 0; let mut le_count = 0; - for i in 0us..8 { + for i in 0usize..8 { if line_ending_histogram[i] >= le_count { lei = i; le_count = line_ending_histogram[i]; @@ -170,7 +170,7 @@ impl Editor { let mut space_blocks: usize = 0; let mut space_histogram: [usize; 9] = [0, 0, 0, 0, 0, 0, 0, 0, 0]; - let mut last_indent = (false, 0us); // (was_tabs, indent_count) + let mut last_indent = (false, 0usize); // (was_tabs, indent_count) // Collect statistics let mut line_i: usize = 0; @@ -244,7 +244,7 @@ impl Editor { if space_blocks > (tab_blocks * 2) { let mut width = 0; let mut width_count = 0; - for i in 0us..9 { + for i in 0usize..9 { if space_histogram[i] > width_count { width = i; width_count = space_histogram[i]; diff --git a/src/main.rs b/src/main.rs index dd0dc5a..dbfacd4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ #![feature(core)] -#![feature(io)] +#![feature(old_io)] #![feature(collections)] -#![feature(path)] +#![feature(old_path)] #![feature(unicode)] #![feature(test)] #![feature(std_misc)] @@ -65,7 +65,7 @@ fn main() { if args.flag_gui { // // Load file, if specified // let editor = if let Option::Some(s) = args.arg_file { - // Editor::new_from_file(GUILineFormatter::new(4), &Path::new(&s[])) + // Editor::new_from_file(GUILineFormatter::new(4), &Path::new(&s[..])) // } // else { // Editor::new(GUILineFormatter::new(4)) @@ -80,7 +80,7 @@ fn main() { else { // Load file, if specified let editor = if let Option::Some(s) = args.arg_file { - Editor::new_from_file(ConsoleLineFormatter::new(4), &Path::new(&s[])) + Editor::new_from_file(ConsoleLineFormatter::new(4), &Path::new(&s[..])) } else { Editor::new(ConsoleLineFormatter::new(4)) diff --git a/src/term_ui/mod.rs b/src/term_ui/mod.rs index ead062c..43efe47 100644 --- a/src/term_ui/mod.rs +++ b/src/term_ui/mod.rs @@ -5,6 +5,8 @@ use rustbox::Color; use editor::Editor; use formatter::{LineFormatter, LINE_BLOCK_LENGTH, block_index_and_offset}; use std::char; +use std::old_io::stdio; +use std::default::Default; use std::time::duration::Duration; use string_utils::{is_line_ending, line_ending_to_str, LineEnding}; use utils::digit_count; @@ -43,7 +45,10 @@ pub struct TermUI { impl TermUI { pub fn new() -> TermUI { - let rb = match rustbox::RustBox::init(&[Some(rustbox::InitOption::BufferStderr)]) { + let rb = match rustbox::RustBox::init(rustbox::InitOptions { + buffer_stderr: stdio::stderr_raw().isatty(), + ..Default::default() + }) { Ok(rbox) => rbox, Err(_) => panic!("Could not create Rustbox instance."), }; @@ -61,7 +66,10 @@ impl TermUI { } pub fn new_from_editor(ed: Editor) -> TermUI { - let rb = match rustbox::RustBox::init(&[Some(rustbox::InitOption::BufferStderr)]) { + let rb = match rustbox::RustBox::init(rustbox::InitOptions { + buffer_stderr: stdio::stderr_raw().isatty(), + ..Default::default() + }) { Ok(rbox) => rbox, Err(_) => panic!("Could not create Rustbox instance."), }; @@ -174,7 +182,7 @@ impl TermUI { // Character 0 => { if let Option::Some(c) = char::from_u32(character) { - self.editor.insert_text_at_cursor(&c.to_string()[]); + self.editor.insert_text_at_cursor(&c.to_string()[..]); } }, @@ -228,7 +236,7 @@ impl TermUI { self.rb.print(i, 0, rustbox::RB_NORMAL, foreground, background, " "); } self.rb.print(1, 0, rustbox::RB_NORMAL, foreground, background, prefix); - self.rb.print(prefix.len() + 1, 0, rustbox::RB_NORMAL, foreground, background, &line[]); + self.rb.print(prefix.len() + 1, 0, rustbox::RB_NORMAL, foreground, background, &line[..]); self.rb.present(); @@ -318,7 +326,7 @@ impl TermUI { let filename = editor.file_path.display(); let dirty_char = if editor.dirty {"*"} else {""}; let name = format!("{}{}", filename, dirty_char); - self.rb.print(c1.1 + 1, c1.0, rustbox::RB_NORMAL, foreground, background, &name[]); + self.rb.print(c1.1 + 1, c1.0, rustbox::RB_NORMAL, foreground, background, &name[..]); // Percentage position in document // TODO: use view instead of cursor for calculation if there is more @@ -330,7 +338,7 @@ impl TermUI { 100 }; let pstring = format!("{}%", percentage); - self.rb.print(c2.1 - pstring.len(), c1.0, rustbox::RB_NORMAL, foreground, background, &pstring[]); + self.rb.print(c2.1 - pstring.len(), c1.0, rustbox::RB_NORMAL, foreground, background, &pstring[..]); // Text encoding info and tab style let nl = match editor.line_ending_type { @@ -346,7 +354,7 @@ impl TermUI { }; let soft_tabs_str = if editor.soft_tabs {"spaces"} else {"tabs"}; let info_line = format!("UTF8:{} {}:{}", nl, soft_tabs_str, editor.soft_tab_width as usize); - self.rb.print(c2.1 - 30, c1.0, rustbox::RB_NORMAL, foreground, background, &info_line[]); + self.rb.print(c2.1 - 30, c1.0, rustbox::RB_NORMAL, foreground, background, &info_line[..]); // Draw main text editing area self.draw_editor_text(editor, (c1.0 + 1, c1.1), c2);