Migrated code from std::old_io to std::io

This commit is contained in:
Nathan Vegdahl 2015-03-15 16:03:23 -07:00
parent 57f013bd46
commit 869cb187b6
4 changed files with 21 additions and 22 deletions

View File

@ -2,9 +2,10 @@
use std::mem;
use std::cmp::min;
use std::old_path::Path;
use std::old_io::fs::File;
use std::old_io::{IoResult, BufferedReader, BufferedWriter};
use std::path::{Path, PathBuf};
use std::fs::File;
use std::io;
use std::io::{BufReader, BufWriter, Read, Write};
use ropey::{Rope, RopeSlice, RopeGraphemeIter, RopeLineIter};
use self::undo_stack::{UndoStack};
@ -21,7 +22,7 @@ mod undo_stack;
/// A text buffer
pub struct Buffer {
text: Rope,
file_path: Option<Path>,
file_path: Option<PathBuf>,
undo_stack: UndoStack,
}
@ -46,13 +47,14 @@ impl Buffer {
}
pub fn new_from_file(path: &Path) -> IoResult<Buffer> {
let mut f = BufferedReader::new(try!(File::open(path)));
let string = f.read_to_string().unwrap();
pub fn new_from_file(path: &Path) -> io::Result<Buffer> {
let mut f = BufReader::new(try!(File::open(path)));
let mut string = String::new();
try!(f.read_to_string(&mut string));
let buf = Buffer {
text: Rope::from_str(string.as_slice()),
file_path: Some(path.clone()),
file_path: Some(path.to_path_buf()),
undo_stack: UndoStack::new(),
};
@ -60,11 +62,11 @@ impl Buffer {
}
pub fn save_to_file(&self, path: &Path) -> IoResult<()> {
let mut f = BufferedWriter::new(try!(File::create(path)));
pub fn save_to_file(&self, path: &Path) -> io::Result<()> {
let mut f = BufWriter::new(try!(File::create(path)));
for c in self.text.chunk_iter() {
let _ = f.write_str(c);
let _ = f.write(c.as_bytes());
}
return Ok(());

View File

@ -3,7 +3,7 @@
use buffer::Buffer;
use formatter::LineFormatter;
use formatter::RoundingBehavior::*;
use std::old_path::Path;
use std::path::{Path, PathBuf};
use std::cmp::{min, max};
use string_utils::{grapheme_count, str_to_line_ending, LineEnding};
use utils::digit_count;
@ -15,7 +15,7 @@ mod cursor;
pub struct Editor<T: LineFormatter> {
pub buffer: Buffer,
pub formatter: T,
pub file_path: Path,
pub file_path: PathBuf,
pub line_ending_type: LineEnding,
pub soft_tabs: bool,
pub soft_tab_width: u8,
@ -40,7 +40,7 @@ impl<T: LineFormatter> Editor<T> {
Editor {
buffer: Buffer::new(),
formatter: formatter,
file_path: Path::new(""),
file_path: PathBuf::new(""),
line_ending_type: LineEnding::LF,
soft_tabs: false,
soft_tab_width: 4,
@ -63,7 +63,7 @@ impl<T: LineFormatter> Editor<T> {
let mut ed = Editor {
buffer: buf,
formatter: formatter,
file_path: path.clone(),
file_path: path.to_path_buf(),
line_ending_type: LineEnding::LF,
soft_tabs: false,
soft_tab_width: 4,
@ -89,7 +89,7 @@ impl<T: LineFormatter> Editor<T> {
pub fn save_if_dirty(&mut self) {
if self.dirty && self.file_path != Path::new("") {
if self.dirty && self.file_path != PathBuf::new("") {
let _ = self.buffer.save_to_file(&self.file_path);
self.dirty = false;
}

View File

@ -1,7 +1,5 @@
#![feature(core)]
#![feature(old_io)]
#![feature(collections)]
#![feature(old_path)]
#![feature(test)]
#![feature(std_misc)]
@ -14,7 +12,7 @@ extern crate ropey;
//extern crate freetype;
//extern crate sdl2;
use std::old_path::Path;
use std::path::Path;
use docopt::Docopt;
use editor::Editor;
use term_ui::TermUI;

View File

@ -5,7 +5,6 @@ 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 std::cmp::min;
@ -47,7 +46,7 @@ pub struct TermUI {
impl TermUI {
pub fn new() -> TermUI {
let rb = match rustbox::RustBox::init(rustbox::InitOptions {
buffer_stderr: stdio::stderr_raw().isatty(),
buffer_stderr: false,
..Default::default()
}) {
Ok(rbox) => rbox,
@ -68,7 +67,7 @@ impl TermUI {
pub fn new_from_editor(ed: Editor<ConsoleLineFormatter>) -> TermUI {
let rb = match rustbox::RustBox::init(rustbox::InitOptions {
buffer_stderr: stdio::stderr_raw().isatty(),
buffer_stderr: false,
..Default::default()
}) {
Ok(rbox) => rbox,