Migrated code from std::old_io to std::io
This commit is contained in:
parent
57f013bd46
commit
869cb187b6
|
@ -2,9 +2,10 @@
|
||||||
|
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::cmp::min;
|
use std::cmp::min;
|
||||||
use std::old_path::Path;
|
use std::path::{Path, PathBuf};
|
||||||
use std::old_io::fs::File;
|
use std::fs::File;
|
||||||
use std::old_io::{IoResult, BufferedReader, BufferedWriter};
|
use std::io;
|
||||||
|
use std::io::{BufReader, BufWriter, Read, Write};
|
||||||
|
|
||||||
use ropey::{Rope, RopeSlice, RopeGraphemeIter, RopeLineIter};
|
use ropey::{Rope, RopeSlice, RopeGraphemeIter, RopeLineIter};
|
||||||
use self::undo_stack::{UndoStack};
|
use self::undo_stack::{UndoStack};
|
||||||
|
@ -21,7 +22,7 @@ mod undo_stack;
|
||||||
/// A text buffer
|
/// A text buffer
|
||||||
pub struct Buffer {
|
pub struct Buffer {
|
||||||
text: Rope,
|
text: Rope,
|
||||||
file_path: Option<Path>,
|
file_path: Option<PathBuf>,
|
||||||
undo_stack: UndoStack,
|
undo_stack: UndoStack,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,13 +47,14 @@ impl Buffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn new_from_file(path: &Path) -> IoResult<Buffer> {
|
pub fn new_from_file(path: &Path) -> io::Result<Buffer> {
|
||||||
let mut f = BufferedReader::new(try!(File::open(path)));
|
let mut f = BufReader::new(try!(File::open(path)));
|
||||||
let string = f.read_to_string().unwrap();
|
let mut string = String::new();
|
||||||
|
try!(f.read_to_string(&mut string));
|
||||||
|
|
||||||
let buf = Buffer {
|
let buf = Buffer {
|
||||||
text: Rope::from_str(string.as_slice()),
|
text: Rope::from_str(string.as_slice()),
|
||||||
file_path: Some(path.clone()),
|
file_path: Some(path.to_path_buf()),
|
||||||
undo_stack: UndoStack::new(),
|
undo_stack: UndoStack::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -60,11 +62,11 @@ impl Buffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn save_to_file(&self, path: &Path) -> IoResult<()> {
|
pub fn save_to_file(&self, path: &Path) -> io::Result<()> {
|
||||||
let mut f = BufferedWriter::new(try!(File::create(path)));
|
let mut f = BufWriter::new(try!(File::create(path)));
|
||||||
|
|
||||||
for c in self.text.chunk_iter() {
|
for c in self.text.chunk_iter() {
|
||||||
let _ = f.write_str(c);
|
let _ = f.write(c.as_bytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
use buffer::Buffer;
|
use buffer::Buffer;
|
||||||
use formatter::LineFormatter;
|
use formatter::LineFormatter;
|
||||||
use formatter::RoundingBehavior::*;
|
use formatter::RoundingBehavior::*;
|
||||||
use std::old_path::Path;
|
use std::path::{Path, PathBuf};
|
||||||
use std::cmp::{min, max};
|
use std::cmp::{min, max};
|
||||||
use string_utils::{grapheme_count, str_to_line_ending, LineEnding};
|
use string_utils::{grapheme_count, str_to_line_ending, LineEnding};
|
||||||
use utils::digit_count;
|
use utils::digit_count;
|
||||||
|
@ -15,7 +15,7 @@ mod cursor;
|
||||||
pub struct Editor<T: LineFormatter> {
|
pub struct Editor<T: LineFormatter> {
|
||||||
pub buffer: Buffer,
|
pub buffer: Buffer,
|
||||||
pub formatter: T,
|
pub formatter: T,
|
||||||
pub file_path: Path,
|
pub file_path: PathBuf,
|
||||||
pub line_ending_type: LineEnding,
|
pub line_ending_type: LineEnding,
|
||||||
pub soft_tabs: bool,
|
pub soft_tabs: bool,
|
||||||
pub soft_tab_width: u8,
|
pub soft_tab_width: u8,
|
||||||
|
@ -40,7 +40,7 @@ impl<T: LineFormatter> Editor<T> {
|
||||||
Editor {
|
Editor {
|
||||||
buffer: Buffer::new(),
|
buffer: Buffer::new(),
|
||||||
formatter: formatter,
|
formatter: formatter,
|
||||||
file_path: Path::new(""),
|
file_path: PathBuf::new(""),
|
||||||
line_ending_type: LineEnding::LF,
|
line_ending_type: LineEnding::LF,
|
||||||
soft_tabs: false,
|
soft_tabs: false,
|
||||||
soft_tab_width: 4,
|
soft_tab_width: 4,
|
||||||
|
@ -63,7 +63,7 @@ impl<T: LineFormatter> Editor<T> {
|
||||||
let mut ed = Editor {
|
let mut ed = Editor {
|
||||||
buffer: buf,
|
buffer: buf,
|
||||||
formatter: formatter,
|
formatter: formatter,
|
||||||
file_path: path.clone(),
|
file_path: path.to_path_buf(),
|
||||||
line_ending_type: LineEnding::LF,
|
line_ending_type: LineEnding::LF,
|
||||||
soft_tabs: false,
|
soft_tabs: false,
|
||||||
soft_tab_width: 4,
|
soft_tab_width: 4,
|
||||||
|
@ -89,7 +89,7 @@ impl<T: LineFormatter> Editor<T> {
|
||||||
|
|
||||||
|
|
||||||
pub fn save_if_dirty(&mut self) {
|
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);
|
let _ = self.buffer.save_to_file(&self.file_path);
|
||||||
self.dirty = false;
|
self.dirty = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
#![feature(core)]
|
#![feature(core)]
|
||||||
#![feature(old_io)]
|
|
||||||
#![feature(collections)]
|
#![feature(collections)]
|
||||||
#![feature(old_path)]
|
|
||||||
#![feature(test)]
|
#![feature(test)]
|
||||||
#![feature(std_misc)]
|
#![feature(std_misc)]
|
||||||
|
|
||||||
|
@ -14,7 +12,7 @@ extern crate ropey;
|
||||||
//extern crate freetype;
|
//extern crate freetype;
|
||||||
//extern crate sdl2;
|
//extern crate sdl2;
|
||||||
|
|
||||||
use std::old_path::Path;
|
use std::path::Path;
|
||||||
use docopt::Docopt;
|
use docopt::Docopt;
|
||||||
use editor::Editor;
|
use editor::Editor;
|
||||||
use term_ui::TermUI;
|
use term_ui::TermUI;
|
||||||
|
|
|
@ -5,7 +5,6 @@ use rustbox::Color;
|
||||||
use editor::Editor;
|
use editor::Editor;
|
||||||
use formatter::{LineFormatter, LINE_BLOCK_LENGTH, block_index_and_offset};
|
use formatter::{LineFormatter, LINE_BLOCK_LENGTH, block_index_and_offset};
|
||||||
use std::char;
|
use std::char;
|
||||||
use std::old_io::stdio;
|
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use std::time::duration::Duration;
|
use std::time::duration::Duration;
|
||||||
use std::cmp::min;
|
use std::cmp::min;
|
||||||
|
@ -47,7 +46,7 @@ pub struct TermUI {
|
||||||
impl TermUI {
|
impl TermUI {
|
||||||
pub fn new() -> TermUI {
|
pub fn new() -> TermUI {
|
||||||
let rb = match rustbox::RustBox::init(rustbox::InitOptions {
|
let rb = match rustbox::RustBox::init(rustbox::InitOptions {
|
||||||
buffer_stderr: stdio::stderr_raw().isatty(),
|
buffer_stderr: false,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}) {
|
}) {
|
||||||
Ok(rbox) => rbox,
|
Ok(rbox) => rbox,
|
||||||
|
@ -68,7 +67,7 @@ impl TermUI {
|
||||||
|
|
||||||
pub fn new_from_editor(ed: Editor<ConsoleLineFormatter>) -> TermUI {
|
pub fn new_from_editor(ed: Editor<ConsoleLineFormatter>) -> TermUI {
|
||||||
let rb = match rustbox::RustBox::init(rustbox::InitOptions {
|
let rb = match rustbox::RustBox::init(rustbox::InitOptions {
|
||||||
buffer_stderr: stdio::stderr_raw().isatty(),
|
buffer_stderr: false,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}) {
|
}) {
|
||||||
Ok(rbox) => rbox,
|
Ok(rbox) => rbox,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user