Working towards rust stable support.

This commit is contained in:
Nathan Vegdahl 2015-07-06 18:39:00 -07:00
parent 9644a1aa03
commit 6823706d69
8 changed files with 18 additions and 16 deletions

View File

@ -18,6 +18,7 @@ git = "https://github.com/cessen/ropey.git"
#git = "https://github.com/PistonDevelopers/freetype-rs.git" #git = "https://github.com/PistonDevelopers/freetype-rs.git"
[dependencies] [dependencies]
time = "0.1.30"
rustc-serialize = "0.3.0" rustc-serialize = "0.3.0"
docopt = "0.6.*" docopt = "0.6.*"
encoding = "*" encoding = "*"

View File

@ -53,7 +53,7 @@ impl Buffer {
try!(f.read_to_string(&mut string)); 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[..]),
file_path: Some(path.to_path_buf()), file_path: Some(path.to_path_buf()),
undo_stack: UndoStack::new(), undo_stack: UndoStack::new(),
}; };

View File

@ -13,7 +13,7 @@ use formatter::LineFormatter;
/// ///
/// `vis_start` is the visual 2d horizontal position of the cursor. This /// `vis_start` is the visual 2d horizontal position of the cursor. This
/// doesn't affect editing operations at all, but is used for cursor movement. /// doesn't affect editing operations at all, but is used for cursor movement.
#[derive(Copy)] #[derive(Copy, Clone)]
pub struct Cursor { pub struct Cursor {
pub range: (usize, usize), // start, end pub range: (usize, usize), // start, end
pub vis_start: usize, // start pub vis_start: usize, // start
@ -96,14 +96,14 @@ impl CursorSet {
impl Index<usize> for CursorSet { impl Index<usize> for CursorSet {
type Output = Cursor; type Output = Cursor;
fn index<'a>(&'a self, _index: &usize) -> &'a Cursor { fn index<'a>(&'a self, _index: usize) -> &'a Cursor {
&(self.cursors[*_index]) &(self.cursors[_index])
} }
} }
impl IndexMut<usize> for CursorSet { impl IndexMut<usize> for CursorSet {
fn index_mut<'a>(&'a mut self, _index: &usize) -> &'a mut Cursor { fn index_mut<'a>(&'a mut self, _index: usize) -> &'a mut Cursor {
&mut (self.cursors[*_index]) &mut (self.cursors[_index])
} }
} }

View File

@ -40,7 +40,7 @@ impl<T: LineFormatter> Editor<T> {
Editor { Editor {
buffer: Buffer::new(), buffer: Buffer::new(),
formatter: formatter, formatter: formatter,
file_path: PathBuf::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,
@ -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 != PathBuf::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;
} }

View File

@ -10,7 +10,7 @@ use buffer::Buffer;
pub const LINE_BLOCK_LENGTH: usize = 4096; pub const LINE_BLOCK_LENGTH: usize = 4096;
#[derive(Copy, PartialEq)] #[derive(Copy, Clone, PartialEq)]
pub enum RoundingBehavior { pub enum RoundingBehavior {
Round, Round,
Floor, Floor,

View File

@ -3,6 +3,7 @@
#![feature(test)] #![feature(test)]
#![feature(std_misc)] #![feature(std_misc)]
extern crate time;
extern crate test; extern crate test;
extern crate rustbox; extern crate rustbox;
extern crate docopt; extern crate docopt;

View File

@ -140,7 +140,7 @@ pub fn grapheme_pos_to_byte_pos(text: &str, pos: usize) -> usize {
/// Inserts the given text into the given string at the given grapheme index. /// Inserts the given text into the given string at the given grapheme index.
pub fn insert_text_at_grapheme_index(s: &mut String, text: &str, pos: usize) { pub fn insert_text_at_grapheme_index(s: &mut String, text: &str, pos: usize) {
// Find insertion position in bytes // Find insertion position in bytes
let byte_pos = grapheme_pos_to_byte_pos(s.as_slice(), pos); let byte_pos = grapheme_pos_to_byte_pos(&s[..], pos);
// Get byte vec of string // Get byte vec of string
let byte_vec = unsafe { s.as_mut_vec() }; let byte_vec = unsafe { s.as_mut_vec() };
@ -182,8 +182,8 @@ pub fn remove_text_between_grapheme_indices(s: &mut String, pos_a: usize, pos_b:
// Find removal positions in bytes // Find removal positions in bytes
// TODO: get both of these in a single pass // TODO: get both of these in a single pass
let byte_pos_a = grapheme_pos_to_byte_pos(s.as_slice(), pos_a); let byte_pos_a = grapheme_pos_to_byte_pos(&s[..], pos_a);
let byte_pos_b = grapheme_pos_to_byte_pos(s.as_slice(), pos_b); let byte_pos_b = grapheme_pos_to_byte_pos(&s[..], pos_b);
// Get byte vec of string // Get byte vec of string
let byte_vec = unsafe { s.as_mut_vec() }; let byte_vec = unsafe { s.as_mut_vec() };
@ -211,7 +211,7 @@ pub fn split_string_at_grapheme_index(s1: &mut String, pos: usize) -> String {
// Code block to contain the borrow of s2 // Code block to contain the borrow of s2
{ {
let byte_pos = grapheme_pos_to_byte_pos(s1.as_slice(), pos); let byte_pos = grapheme_pos_to_byte_pos(&s1[..], pos);
let byte_vec_1 = unsafe { s1.as_mut_vec() }; let byte_vec_1 = unsafe { s1.as_mut_vec() };
let byte_vec_2 = unsafe { s2.as_mut_vec() }; let byte_vec_2 = unsafe { s2.as_mut_vec() };
@ -231,7 +231,7 @@ pub fn split_string_at_grapheme_index(s1: &mut String, pos: usize) -> String {
/// Represents one of the valid Unicode line endings. /// Represents one of the valid Unicode line endings.
/// Also acts as an index into `LINE_ENDINGS`. /// Also acts as an index into `LINE_ENDINGS`.
#[derive(PartialEq, Copy)] #[derive(PartialEq, Copy, Clone)]
pub enum LineEnding { pub enum LineEnding {
None = 0, // No line ending None = 0, // No line ending
CRLF = 1, // CarriageReturn followed by LineFeed CRLF = 1, // CarriageReturn followed by LineFeed

View File

@ -3,10 +3,10 @@
use rustbox; use rustbox;
use rustbox::Color; use rustbox::Color;
use editor::Editor; use editor::Editor;
use time::Duration;
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::default::Default; use std::default::Default;
use std::time::duration::Duration;
use std::cmp::min; use std::cmp::min;
use string_utils::{is_line_ending, line_ending_to_str, LineEnding}; use string_utils::{is_line_ending, line_ending_to_str, LineEnding};
use utils::digit_count; use utils::digit_count;
@ -387,7 +387,7 @@ impl TermUI {
let lnx = c1.1 + (gutter_width - 1 - digit_count(line_num as u32, 10) as usize); let lnx = c1.1 + (gutter_width - 1 - digit_count(line_num as u32, 10) as usize);
let lny = screen_line as usize; let lny = screen_line as usize;
if lny >= c1.0 && lny <= c2.0 { if lny >= c1.0 && lny <= c2.0 {
self.rb.print(lnx, lny, rustbox::RB_NORMAL, Color::White, Color::Blue, format!("{}", line_num).as_slice()); self.rb.print(lnx, lny, rustbox::RB_NORMAL, Color::White, Color::Blue, &format!("{}", line_num)[..]);
} }
} }