Commit d5e77d23 authored by Wesley Wiser's avatar Wesley Wiser

Respond to PR feedback

parent 848ff01f
......@@ -5,26 +5,6 @@ use edit::buffer::{Buffer, SplitBuffer};
use std::process::exit;
enum BufferCommand {
SwitchToBuffer(usize),
}
fn try_get_buffer_command(c: &str) -> Option<BufferCommand> {
if !c.starts_with("b") {
return None;
}
let rest : String = c.chars().skip(1).collect();
//TODO more buffer commands
if let Ok(number) = rest.parse::<usize>() {
Some(BufferCommand::SwitchToBuffer(number))
} else {
None
}
}
impl Editor {
/// Invoke a command in the prompt
pub fn invoke(&mut self, cmd: String) {
......@@ -74,9 +54,9 @@ impl Editor {
},
"ls" => {
let description = get_buffers_description(&self.buffers);
let mut new_buffer : BufferInfo = SplitBuffer::from_str(&description).into();
let mut new_buffer: BufferInfo = SplitBuffer::from_str(&description).into();
new_buffer.title = Some("<Buffers>".into());
new_buffer.is_transient = true; //delete the buffer when the user switches away
new_buffer.is_transient = true; // delete the buffer when the user switches away
let new_buffer_index = self.buffers.new_buffer(new_buffer);
self.buffers.switch_to(new_buffer_index);
......@@ -89,17 +69,19 @@ impl Editor {
exit(0);
},
c => {
if let Some(buffer_command) = try_get_buffer_command(c) {
match buffer_command {
BufferCommand::SwitchToBuffer(n) => {
if !self.buffers.is_buffer_index_valid(n) {
self.status_bar.msg = format!("Invalid buffer #{}", n);
} else {
self.buffers.switch_to(n);
self.redraw_task = RedrawTask::Full;
self.status_bar.msg = format!("Switched to buffer #{}", n);
}
},
if c.starts_with("b") {
let rest: String = c.chars().skip(1).collect();
if let Ok(number) = rest.parse::<usize>() {
if !self.buffers.is_buffer_index_valid(number) {
self.status_bar.msg = format!("Invalid buffer #{}", number);
} else {
self.buffers.switch_to(number);
self.redraw_task = RedrawTask::Full;
self.status_bar.msg = format!("Switched to buffer #{}", number);
}
} else {
self.status_bar.msg = format!("Unknown command: {}", c);
}
} else {
self.status_bar.msg = format!("Unknown command: {}", c);
......
......@@ -76,7 +76,7 @@ impl BufferManager {
pub fn new_buffer(&mut self, buffer: BufferInfo) -> usize {
self.buffers.push(buffer);
self.buffers.len() -1
self.buffers.len() - 1
}
/// Returns an iterator over the buffers.
......@@ -111,7 +111,7 @@ impl BufferManager {
/// Switch the current buffer to the specified buffer
pub fn switch_to(&mut self, n: usize) {
assert!(n < self.buffers.len(), "Buffer index out of bounds");
debug_assert!(n < self.buffers.len(), "Buffer index out of bounds");
// if the current view is transient, delete it
let mut n = n;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment