Fomatted with recent rustfmt. No actual code changes.

This commit is contained in:
Nathan Vegdahl 2018-07-05 02:00:10 -07:00
parent de625e71dc
commit 5ca0f5e406
10 changed files with 108 additions and 196 deletions

View File

@ -1,16 +1,16 @@
#![allow(dead_code)]
use std::path::{Path, PathBuf};
use std::fs::File;
use std::io;
use std::io::{BufReader, BufWriter, Write};
use std::path::{Path, PathBuf};
use self::undo_stack::Operation::*;
use self::undo_stack::UndoStack;
use ropey;
use ropey::{Rope, RopeSlice};
use self::undo_stack::UndoStack;
use self::undo_stack::Operation::*;
use string_utils::char_count;
use utils::{prev_grapheme_boundary, next_grapheme_boundary, is_grapheme_boundary, RopeGraphemes};
use utils::{is_grapheme_boundary, next_grapheme_boundary, prev_grapheme_boundary, RopeGraphemes};
mod undo_stack;

View File

@ -1,8 +1,8 @@
#![allow(dead_code)]
use std::slice::{Iter, IterMut};
use std::ops::{Index, IndexMut};
use std::cmp::Ordering;
use std::ops::{Index, IndexMut};
use std::slice::{Iter, IterMut};
use buffer::Buffer;
use formatter::LineFormatter;

View File

@ -2,14 +2,14 @@
use std::collections::HashMap;
use self::cursor::CursorSet;
use buffer::Buffer;
use formatter::LineFormatter;
use formatter::RoundingBehavior::*;
use std::path::{Path, PathBuf};
use std::cmp::{max, min};
use std::path::{Path, PathBuf};
use string_utils::{char_count, rope_slice_to_line_ending, LineEnding};
use utils::{digit_count, RopeGraphemes};
use self::cursor::CursorSet;
mod cursor;
@ -378,7 +378,7 @@ impl<T: LineFormatter> Editor<T> {
// Insert spaces
let space_strs = [
"", " ", " ", " ", " ", " ", " ", " ", " "
"", " ", " ", " ", " ", " ", " ", " ", " ",
];
self.buffer.insert_text(space_strs[space_count], c.range.0);
self.dirty = true;

View File

@ -1,8 +1,8 @@
#![allow(dead_code)]
use std::cmp::min;
use ropey::RopeSlice;
use buffer::Buffer;
use ropey::RopeSlice;
use std::cmp::min;
use utils::RopeGraphemes;
// Maximum graphemes in a line before a soft line break is forced.

View File

@ -8,18 +8,18 @@ extern crate termion;
extern crate unicode_segmentation;
extern crate unicode_width;
use std::path::Path;
use docopt::Docopt;
use editor::Editor;
use term_ui::TermUI;
use std::path::Path;
use term_ui::formatter::ConsoleLineFormatter;
use term_ui::TermUI;
mod string_utils;
mod utils;
mod buffer;
mod formatter;
mod editor;
mod formatter;
mod string_utils;
mod term_ui;
mod utils;
// Usage documentation string
static USAGE: &'static str = "

View File

@ -1,8 +1,8 @@
#![allow(dead_code)]
//! Misc helpful utility functions for TextBuffer related stuff.
use std::iter::repeat;
use ropey::RopeSlice;
use std::iter::repeat;
use unicode_segmentation::UnicodeSegmentation;
pub fn is_line_ending(text: &str) -> bool {
@ -53,7 +53,7 @@ pub fn rope_slice_is_whitespace(text: &RopeSlice) -> bool {
// TODO: this is a naive categorization of whitespace characters.
// For better categorization these should be split up into groups
// based on e.g. breaking vs non-breaking spaces, among other things.
text == "\u{0020}" // SPACE
|| text == "\u{0009}" // CHARACTER TABULATION
|| text == "\u{00A0}" // NO-BREAK SPACE

View File

@ -1,9 +1,9 @@
use std::cmp::max;
use ropey::RopeSlice;
use utils::grapheme_width;
use string_utils::{rope_slice_is_line_ending, rope_slice_is_whitespace};
use formatter::{LineFormatter, RoundingBehavior};
use ropey::RopeSlice;
use string_utils::{rope_slice_is_line_ending, rope_slice_is_whitespace};
use utils::grapheme_width;
pub enum WrapType {
NoWrap,
@ -315,12 +315,12 @@ fn grapheme_vis_width_at_vis_pos(g: RopeSlice, pos: usize, tab_width: usize) ->
#[cfg(test)]
mod tests {
#![allow(unused_imports)]
use super::*;
use buffer::Buffer;
use formatter::RoundingBehavior::{Ceiling, Floor, Round};
use formatter::{LineFormatter, LINE_BLOCK_LENGTH};
use ropey::Rope;
use utils::RopeGraphemes;
use super::*;
use formatter::{LineFormatter, LINE_BLOCK_LENGTH};
use formatter::RoundingBehavior::{Ceiling, Floor, Round};
use buffer::Buffer;
#[test]
fn dimensions_1() {
@ -332,10 +332,7 @@ mod tests {
f.wrap_additional_indent = 0;
f.set_wrap_width(80);
assert_eq!(
f.dimensions(RopeGraphemes::new(&text.slice(..))),
(1, 22)
);
assert_eq!(f.dimensions(RopeGraphemes::new(&text.slice(..))), (1, 22));
}
#[test]
@ -348,25 +345,24 @@ mod tests {
f.wrap_additional_indent = 0;
f.set_wrap_width(12);
assert_eq!(
f.dimensions(RopeGraphemes::new(&text.slice(..))),
(5, 12)
);
assert_eq!(f.dimensions(RopeGraphemes::new(&text.slice(..))), (5, 12));
}
#[test]
fn dimensions_3() {
// 55 graphemes long
let text = Rope::from_str("税マイミ文末\
\
\
\
西\
\
\
\
\
");
let text = Rope::from_str(
"税マイミ文末\
\
\
\
西\
\
\
\
\
",
);
let mut f = ConsoleLineFormatter::new(4);
f.wrap_type = WrapType::CharWrap(0);
@ -374,25 +370,24 @@ mod tests {
f.wrap_additional_indent = 0;
f.set_wrap_width(12);
assert_eq!(
f.dimensions(RopeGraphemes::new(&text.slice(..))),
(10, 12)
);
assert_eq!(f.dimensions(RopeGraphemes::new(&text.slice(..))), (10, 12));
}
#[test]
fn dimensions_4() {
// 55 graphemes long
let text = Rope::from_str("税マイミ文末\
\
\
\
西\
\
\
\
\
");
let text = Rope::from_str(
"税マイミ文末\
\
\
\
西\
\
\
\
\
",
);
let mut f = ConsoleLineFormatter::new(4);
f.wrap_type = WrapType::WordWrap(0);
@ -400,10 +395,7 @@ mod tests {
f.wrap_additional_indent = 0;
f.set_wrap_width(12);
assert_eq!(
f.dimensions(RopeGraphemes::new(&text.slice(..))),
(10, 12)
);
assert_eq!(f.dimensions(RopeGraphemes::new(&text.slice(..))), (10, 12));
}
#[test]
@ -526,51 +518,27 @@ mod tests {
f.set_wrap_width(80);
assert_eq!(
f.v2d_to_index(
RopeGraphemes::new(&text.slice(..)),
(0, 0),
(Floor, Floor)
),
f.v2d_to_index(RopeGraphemes::new(&text.slice(..)), (0, 0), (Floor, Floor)),
0
);
assert_eq!(
f.v2d_to_index(
RopeGraphemes::new(&text.slice(..)),
(0, 5),
(Floor, Floor)
),
f.v2d_to_index(RopeGraphemes::new(&text.slice(..)), (0, 5), (Floor, Floor)),
5
);
assert_eq!(
f.v2d_to_index(
RopeGraphemes::new(&text.slice(..)),
(0, 22),
(Floor, Floor)
),
f.v2d_to_index(RopeGraphemes::new(&text.slice(..)), (0, 22), (Floor, Floor)),
22
);
assert_eq!(
f.v2d_to_index(
RopeGraphemes::new(&text.slice(..)),
(0, 23),
(Floor, Floor)
),
f.v2d_to_index(RopeGraphemes::new(&text.slice(..)), (0, 23), (Floor, Floor)),
22
);
assert_eq!(
f.v2d_to_index(
RopeGraphemes::new(&text.slice(..)),
(1, 0),
(Floor, Floor)
),
f.v2d_to_index(RopeGraphemes::new(&text.slice(..)), (1, 0), (Floor, Floor)),
22
);
assert_eq!(
f.v2d_to_index(
RopeGraphemes::new(&text.slice(..)),
(1, 1),
(Floor, Floor)
),
f.v2d_to_index(RopeGraphemes::new(&text.slice(..)), (1, 1), (Floor, Floor)),
22
);
}
@ -586,135 +554,71 @@ mod tests {
f.set_wrap_width(12);
assert_eq!(
f.v2d_to_index(
RopeGraphemes::new(&text.slice(..)),
(0, 0),
(Floor, Floor)
),
f.v2d_to_index(RopeGraphemes::new(&text.slice(..)), (0, 0), (Floor, Floor)),
0
);
assert_eq!(
f.v2d_to_index(
RopeGraphemes::new(&text.slice(..)),
(0, 11),
(Floor, Floor)
),
f.v2d_to_index(RopeGraphemes::new(&text.slice(..)), (0, 11), (Floor, Floor)),
11
);
assert_eq!(
f.v2d_to_index(
RopeGraphemes::new(&text.slice(..)),
(0, 12),
(Floor, Floor)
),
f.v2d_to_index(RopeGraphemes::new(&text.slice(..)), (0, 12), (Floor, Floor)),
11
);
assert_eq!(
f.v2d_to_index(
RopeGraphemes::new(&text.slice(..)),
(1, 0),
(Floor, Floor)
),
f.v2d_to_index(RopeGraphemes::new(&text.slice(..)), (1, 0), (Floor, Floor)),
12
);
assert_eq!(
f.v2d_to_index(
RopeGraphemes::new(&text.slice(..)),
(1, 11),
(Floor, Floor)
),
f.v2d_to_index(RopeGraphemes::new(&text.slice(..)), (1, 11), (Floor, Floor)),
23
);
assert_eq!(
f.v2d_to_index(
RopeGraphemes::new(&text.slice(..)),
(1, 12),
(Floor, Floor)
),
f.v2d_to_index(RopeGraphemes::new(&text.slice(..)), (1, 12), (Floor, Floor)),
23
);
assert_eq!(
f.v2d_to_index(
RopeGraphemes::new(&text.slice(..)),
(2, 0),
(Floor, Floor)
),
f.v2d_to_index(RopeGraphemes::new(&text.slice(..)), (2, 0), (Floor, Floor)),
24
);
assert_eq!(
f.v2d_to_index(
RopeGraphemes::new(&text.slice(..)),
(2, 11),
(Floor, Floor)
),
f.v2d_to_index(RopeGraphemes::new(&text.slice(..)), (2, 11), (Floor, Floor)),
35
);
assert_eq!(
f.v2d_to_index(
RopeGraphemes::new(&text.slice(..)),
(2, 12),
(Floor, Floor)
),
f.v2d_to_index(RopeGraphemes::new(&text.slice(..)), (2, 12), (Floor, Floor)),
35
);
assert_eq!(
f.v2d_to_index(
RopeGraphemes::new(&text.slice(..)),
(3, 0),
(Floor, Floor)
),
f.v2d_to_index(RopeGraphemes::new(&text.slice(..)), (3, 0), (Floor, Floor)),
36
);
assert_eq!(
f.v2d_to_index(
RopeGraphemes::new(&text.slice(..)),
(3, 11),
(Floor, Floor)
),
f.v2d_to_index(RopeGraphemes::new(&text.slice(..)), (3, 11), (Floor, Floor)),
47
);
assert_eq!(
f.v2d_to_index(
RopeGraphemes::new(&text.slice(..)),
(3, 12),
(Floor, Floor)
),
f.v2d_to_index(RopeGraphemes::new(&text.slice(..)), (3, 12), (Floor, Floor)),
47
);
assert_eq!(
f.v2d_to_index(
RopeGraphemes::new(&text.slice(..)),
(4, 0),
(Floor, Floor)
),
f.v2d_to_index(RopeGraphemes::new(&text.slice(..)), (4, 0), (Floor, Floor)),
48
);
assert_eq!(
f.v2d_to_index(
RopeGraphemes::new(&text.slice(..)),
(4, 7),
(Floor, Floor)
),
f.v2d_to_index(RopeGraphemes::new(&text.slice(..)), (4, 7), (Floor, Floor)),
55
);
assert_eq!(
f.v2d_to_index(
RopeGraphemes::new(&text.slice(..)),
(4, 8),
(Floor, Floor)
),
f.v2d_to_index(RopeGraphemes::new(&text.slice(..)), (4, 8), (Floor, Floor)),
56
);
assert_eq!(
f.v2d_to_index(
RopeGraphemes::new(&text.slice(..)),
(4, 9),
(Floor, Floor)
),
f.v2d_to_index(RopeGraphemes::new(&text.slice(..)), (4, 9), (Floor, Floor)),
56
);
}

View File

@ -7,10 +7,10 @@ use termion;
use termion::event::{Event, Key};
use termion::input::TermRead;
use self::formatter::ConsoleLineFormatter;
use editor::Editor;
use formatter::{block_index_and_offset, LineFormatter, LINE_BLOCK_LENGTH};
use self::formatter::ConsoleLineFormatter;
use string_utils::{rope_slice_is_line_ending, line_ending_to_str, LineEnding};
use string_utils::{line_ending_to_str, rope_slice_is_line_ending, LineEnding};
use utils::{digit_count, RopeGraphemes};
pub mod formatter;
@ -21,11 +21,13 @@ use self::screen::{Color, Screen, Style};
/// Generalized ui loop.
macro_rules! ui_loop {
($term_ui:ident, draw $draw:block, key_press($key:ident) $key_press:block) => {
($term_ui:ident,draw $draw:block,key_press($key:ident) $key_press:block) => {
let mut stop = false;
// Draw the editor to screen for the first time
{$draw};
{
$draw
};
$term_ui.screen.present();
// UI loop
@ -36,9 +38,7 @@ macro_rules! ui_loop {
loop {
match $term_ui.inp.next() {
Some(Ok(Event::Key($key))) => {
let (status, state_changed) = || -> (LoopStatus, bool) {
$key_press
}();
let (status, state_changed) = || -> (LoopStatus, bool) { $key_press }();
should_redraw |= state_changed;
if status == LoopStatus::Done {
stop = true;
@ -62,16 +62,23 @@ macro_rules! ui_loop {
if $term_ui.width != w as usize || $term_ui.height != h as usize {
$term_ui.width = w as usize;
$term_ui.height = h as usize;
$term_ui.editor.update_dim($term_ui.height - 1, $term_ui.width);
$term_ui
.editor
.update_dim($term_ui.height - 1, $term_ui.width);
$term_ui.editor.update_view_dim();
$term_ui.editor.formatter.set_wrap_width($term_ui.editor.view_dim.1);
$term_ui
.editor
.formatter
.set_wrap_width($term_ui.editor.view_dim.1);
$term_ui.screen.resize(w as usize, h as usize);
should_redraw = true;
}
// Draw the editor to screen
if should_redraw {
{$draw};
{
$draw
};
$term_ui.screen.present();
}
@ -367,14 +374,13 @@ impl TermUI {
.line_col_to_index((line_index, line_block_index * LINE_BLOCK_LENGTH));
let temp_line = editor.buffer.get_line(line_index);
let (vis_line_offset, _) = editor.formatter.index_to_v2d(
RopeGraphemes::new(&temp_line
.slice(
(line_block_index * LINE_BLOCK_LENGTH)
..min(
temp_line.len_chars(),
(line_block_index + 1) * LINE_BLOCK_LENGTH,
),
)),
RopeGraphemes::new(&temp_line.slice(
(line_block_index * LINE_BLOCK_LENGTH)
..min(
temp_line.len_chars(),
(line_block_index + 1) * LINE_BLOCK_LENGTH,
),
)),
editor.view_pos.0 - char_index,
);
@ -534,7 +540,9 @@ impl TermUI {
let px = pos_x as isize + screen_col - editor.view_pos.1 as isize;
let py = screen_line - 1;
if (px >= c1.1 as isize) && (py >= c1.0 as isize) && (px <= c2.1 as isize)
if (px >= c1.1 as isize)
&& (py >= c1.0 as isize)
&& (px <= c2.1 as isize)
&& (py <= c2.0 as isize)
{
self.screen.draw(

View File

@ -3,15 +3,15 @@ use std::cell::RefCell;
use std::io;
use std::io::{BufWriter, Write};
use ropey::RopeSlice;
use utils::{RopeGraphemes, grapheme_width};
use super::smallstring::SmallString;
use unicode_width::UnicodeWidthStr;
use unicode_segmentation::UnicodeSegmentation;
use ropey::RopeSlice;
use termion;
use termion::screen::AlternateScreen;
use termion::color;
use termion::raw::{IntoRawMode, RawTerminal};
use termion::screen::AlternateScreen;
use unicode_segmentation::UnicodeSegmentation;
use unicode_width::UnicodeWidthStr;
use utils::{grapheme_width, RopeGraphemes};
pub(crate) struct Screen {
out: RefCell<AlternateScreen<RawTerminal<BufWriter<io::Stdout>>>>,

View File

@ -1,4 +1,4 @@
use ropey::{RopeSlice, iter::Chunks};
use ropey::{iter::Chunks, RopeSlice};
use unicode_segmentation::{GraphemeCursor, GraphemeIncomplete};
use unicode_width::UnicodeWidthStr;