Replace println_stderr! with eprintln!

This commit is contained in:
Alexandre Bury 2017-08-14 17:01:49 -07:00
parent 3a42760569
commit a48ff9082f
8 changed files with 41 additions and 49 deletions

View File

@ -1,6 +1,7 @@
extern crate cursive; extern crate cursive;
use cursive::Cursive; use cursive::Cursive;
use cursive::view::Boxable;
use cursive::views::{Dialog, TextView}; use cursive::views::{Dialog, TextView};
use cursive::align::HAlign; use cursive::align::HAlign;
@ -17,7 +18,8 @@ fn main() {
// and will adapt to the terminal size. // and will adapt to the terminal size.
siv.add_fullscreen_layer(Dialog::around(TextView::new(content)) siv.add_fullscreen_layer(Dialog::around(TextView::new(content))
.h_align(HAlign::Center) .h_align(HAlign::Center)
.button("Quit", |s| s.quit())); .button("Quit", |s| s.quit())
.full_screen());
// Show a popup on top of the view. // Show a popup on top of the view.
siv.add_layer(Dialog::info("Try resizing the terminal!\n(Press 'q' to \ siv.add_layer(Dialog::info("Try resizing the terminal!\n(Press 'q' to \
quit when you're done.)")); quit when you're done.)"));

View File

@ -260,7 +260,7 @@ fn blt_keycode_to_char(kc: KeyCode, shift: bool) -> char {
KeyCode::Num9 => '9', KeyCode::Num9 => '9',
KeyCode::Num0 => '0', KeyCode::Num0 => '0',
_ => { _ => {
println_stderr!("Found unknown input: {:?}", kc); eprintln!("Found unknown input: {:?}", kc);
unreachable!() unreachable!()
} }
} }

View File

@ -70,16 +70,6 @@ extern crate owning_ref;
#[macro_use] #[macro_use]
extern crate chan; extern crate chan;
#[allow(unused)]
macro_rules! println_stderr(
($($arg:tt)*) => { {
use ::std::io::Write;
let r = writeln!(&mut ::std::io::stderr(), $($arg)*);
r.expect("failed printing to stderr");
} }
);
macro_rules! new_default( macro_rules! new_default(
($c:ty) => { ($c:ty) => {
impl Default for $c { impl Default for $c {

View File

@ -160,7 +160,7 @@ impl<T: View> ViewWrapper for BoxView<T> {
let result = self.size let result = self.size
.zip_map(child_size.zip(req), SizeConstraint::result); .zip_map(child_size.zip(req), SizeConstraint::result);
// println_stderr!("{:?}", result); // eprintln!("{:?}", result);
if self.squishable { if self.squishable {
// We respect the request if we're less or equal. // We respect the request if we're less or equal.

View File

@ -495,7 +495,7 @@ impl View for EditView {
fn layout(&mut self, size: Vec2) { fn layout(&mut self, size: Vec2) {
self.last_length = size.x; self.last_length = size.x;
// println_stderr!("Promised: {}", size.x); // eprintln!("Promised: {}", size.x);
} }
fn take_focus(&mut self, _: Direction) -> bool { fn take_focus(&mut self, _: Direction) -> bool {

View File

@ -226,9 +226,9 @@ impl View for LinearLayout {
.iter_mut() .iter_mut()
.map(|c| c.required_size(req)) .map(|c| c.required_size(req))
.collect(); .collect();
// println_stderr!("Ideal sizes: {:?}", sizes); // eprintln!("Ideal sizes: {:?}", sizes);
let ideal = self.orientation.stack(sizes.iter()); let ideal = self.orientation.stack(sizes.iter());
// println_stderr!("Ideal result: {:?}", ideal); // eprintln!("Ideal result: {:?}", ideal);
// Does it fit? // Does it fit?
@ -241,7 +241,7 @@ impl View for LinearLayout {
// Ok, so maybe it didn't. Budget cuts, everyone. // Ok, so maybe it didn't. Budget cuts, everyone.
// Let's pretend we have almost no space in this direction. // Let's pretend we have almost no space in this direction.
let budget_req = req.with_axis(self.orientation, 1); let budget_req = req.with_axis(self.orientation, 1);
// println_stderr!("Budget req: {:?}", budget_req); // eprintln!("Budget req: {:?}", budget_req);
// See how they like it that way // See how they like it that way
let min_sizes: Vec<Vec2> = self.children let min_sizes: Vec<Vec2> = self.children
@ -249,8 +249,8 @@ impl View for LinearLayout {
.map(|c| c.required_size(budget_req)) .map(|c| c.required_size(budget_req))
.collect(); .collect();
let desperate = self.orientation.stack(min_sizes.iter()); let desperate = self.orientation.stack(min_sizes.iter());
// println_stderr!("Min sizes: {:?}", min_sizes); // eprintln!("Min sizes: {:?}", min_sizes);
// println_stderr!("Desperate: {:?}", desperate); // eprintln!("Desperate: {:?}", desperate);
// This is the lowest we'll ever go. It better fit at least. // This is the lowest we'll ever go. It better fit at least.
let orientation = self.orientation; let orientation = self.orientation;
@ -263,7 +263,7 @@ impl View for LinearLayout {
*req.get(self.orientation)); *req.get(self.orientation));
// TODO: print some error message or something // TODO: print some error message or something
// println_stderr!("Seriously? {:?} > {:?}???", desperate, req); // eprintln!("Seriously? {:?} > {:?}???", desperate, req);
// self.cache = Some(SizeCache::build(desperate, req)); // self.cache = Some(SizeCache::build(desperate, req));
self.cache = None; self.cache = None;
return desperate; return desperate;
@ -272,7 +272,7 @@ impl View for LinearLayout {
// This here is how much we're generously offered // This here is how much we're generously offered
// (We just checked that req >= desperate, so the subtraction is safe // (We just checked that req >= desperate, so the subtraction is safe
let mut available = self.orientation.get(&(req - desperate)); let mut available = self.orientation.get(&(req - desperate));
// println_stderr!("Available: {:?}", available); // eprintln!("Available: {:?}", available);
// Here, we have to make a compromise between the ideal // Here, we have to make a compromise between the ideal
// and the desperate solutions. // and the desperate solutions.
@ -282,7 +282,7 @@ impl View for LinearLayout {
.map(|(a, b)| a.saturating_sub(b)) .map(|(a, b)| a.saturating_sub(b))
.enumerate() .enumerate()
.collect(); .collect();
// println_stderr!("Overweight: {:?}", overweight); // eprintln!("Overweight: {:?}", overweight);
// So... distribute `available` to reduce the overweight... // So... distribute `available` to reduce the overweight...
// TODO: use child weight in the distribution... // TODO: use child weight in the distribution...
@ -302,7 +302,7 @@ impl View for LinearLayout {
allocations[j] = spent; allocations[j] = spent;
available -= spent; available -= spent;
} }
// println_stderr!("Allocations: {:?}", allocations); // eprintln!("Allocations: {:?}", allocations);
// Final lengths are the minimum ones + generous allocations // Final lengths are the minimum ones + generous allocations
let final_lengths: Vec<Vec2> = min_sizes.iter() let final_lengths: Vec<Vec2> = min_sizes.iter()
@ -311,7 +311,7 @@ impl View for LinearLayout {
.map(|(a, b)| a + b) .map(|(a, b)| a + b)
.map(|l| req.with_axis(self.orientation, l)) .map(|l| req.with_axis(self.orientation, l))
.collect(); .collect();
// println_stderr!("Final sizes: {:?}", final_lengths); // eprintln!("Final sizes: {:?}", final_lengths);
// Let's ask everyone one last time. Everyone should be happy. // Let's ask everyone one last time. Everyone should be happy.
// (But they may ask more on the other axis.) // (But they may ask more on the other axis.)
@ -320,7 +320,7 @@ impl View for LinearLayout {
.enumerate() .enumerate()
.map(|(i, c)| c.required_size(final_lengths[i])) .map(|(i, c)| c.required_size(final_lengths[i]))
.collect(); .collect();
// println_stderr!("Final sizes2: {:?}", final_sizes); // eprintln!("Final sizes2: {:?}", final_sizes);
// Let's stack everything to see what it looks like. // Let's stack everything to see what it looks like.
let compromise = self.orientation.stack(final_sizes.iter()); let compromise = self.orientation.stack(final_sizes.iter());

View File

@ -228,7 +228,7 @@ impl View for ListView {
.max() .max()
.unwrap_or(0) + 1; .unwrap_or(0) + 1;
// println_stderr!("Offset: {}", offset); // eprintln!("Offset: {}", offset);
self.scrollbase.draw(printer, |printer, i| match self.children[i] { self.scrollbase.draw(printer, |printer, i| match self.children[i] {
ListChild::Row(ref label, ref view) => { ListChild::Row(ref label, ref view) => {
printer.print((0, 0), label); printer.print((0, 0), label);
@ -278,7 +278,7 @@ impl View for ListView {
let available = size.x.saturating_sub(label_width + spacing + let available = size.x.saturating_sub(label_width + spacing +
scrollbar_width); scrollbar_width);
// println_stderr!("Available: {}", available); // eprintln!("Available: {}", available);
for child in self.children.iter_mut().filter_map(ListChild::view) { for child in self.children.iter_mut().filter_map(ListChild::view) {
child.layout(Vec2::new(available, 1)); child.layout(Vec2::new(available, 1));

View File

@ -80,7 +80,7 @@ impl TextArea {
/// Finds the row containing the grapheme at the given offset /// Finds the row containing the grapheme at the given offset
fn row_at(&self, offset: usize) -> usize { fn row_at(&self, offset: usize) -> usize {
// println_stderr!("Offset: {}", offset); // eprintln!("Offset: {}", offset);
self.rows self.rows
.iter() .iter()
.enumerate() .enumerate()
@ -201,7 +201,7 @@ impl TextArea {
if self.is_cache_valid(size) { if self.is_cache_valid(size) {
return; return;
} }
// println_stderr!("Computing! Oh yeah!"); // eprintln!("Computing! Oh yeah!");
let mut available = size.x; let mut available = size.x;
@ -232,7 +232,7 @@ impl TextArea {
if self.cursor == self.content.len() { if self.cursor == self.content.len() {
return; return;
} }
// println_stderr!("Rows: {:?}", self.rows); // eprintln!("Rows: {:?}", self.rows);
let len = self.content[self.cursor..] let len = self.content[self.cursor..]
.graphemes(true) .graphemes(true)
.next() .next()
@ -240,13 +240,13 @@ impl TextArea {
.len(); .len();
let start = self.cursor; let start = self.cursor;
let end = self.cursor + len; let end = self.cursor + len;
// println_stderr!("Start/end: {}/{}", start, end); // eprintln!("Start/end: {}/{}", start, end);
// println_stderr!("Content: `{}`", self.content); // eprintln!("Content: `{}`", self.content);
for _ in self.content.drain(start..end) {} for _ in self.content.drain(start..end) {}
// println_stderr!("Content: `{}`", self.content); // eprintln!("Content: `{}`", self.content);
let selected_row = self.selected_row(); let selected_row = self.selected_row();
// println_stderr!("Selected row: {}", selected_row); // eprintln!("Selected row: {}", selected_row);
if self.cursor == self.rows[selected_row].end { if self.cursor == self.rows[selected_row].end {
// We're removing an (implicit) newline. // We're removing an (implicit) newline.
// This means merging two rows. // This means merging two rows.
@ -260,10 +260,10 @@ impl TextArea {
for row in &mut self.rows.iter_mut().skip(1 + selected_row) { for row in &mut self.rows.iter_mut().skip(1 + selected_row) {
row.rev_shift(len); row.rev_shift(len);
} }
// println_stderr!("Rows: {:?}", self.rows); // eprintln!("Rows: {:?}", self.rows);
self.fix_damages(); self.fix_damages();
// println_stderr!("Rows: {:?}", self.rows); // eprintln!("Rows: {:?}", self.rows);
} }
fn insert(&mut self, ch: char) { fn insert(&mut self, ch: char) {
@ -312,7 +312,7 @@ impl TextArea {
// We don't need to go beyond a newline. // We don't need to go beyond a newline.
// If we don't find one, end of the text it is. // If we don't find one, end of the text it is.
// println_stderr!("Cursor: {}", self.cursor); // eprintln!("Cursor: {}", self.cursor);
let last_byte = self.content[self.cursor..].find('\n').map(|i| { let last_byte = self.content[self.cursor..].find('\n').map(|i| {
1 + i + self.cursor 1 + i + self.cursor
}); });
@ -321,11 +321,11 @@ impl TextArea {
}); });
let last_byte = last_byte.unwrap_or_else(|| self.content.len()); let last_byte = last_byte.unwrap_or_else(|| self.content.len());
// println_stderr!("Content: `{}` (len={})", // eprintln!("Content: `{}` (len={})",
// self.content, // self.content,
// self.content.len()); // self.content.len());
// println_stderr!("start/end: {}/{}", first_byte, last_byte); // eprintln!("start/end: {}/{}", first_byte, last_byte);
// println_stderr!("start/end rows: {}/{}", first_row, last_row); // eprintln!("start/end rows: {}/{}", first_row, last_row);
// Do we have access to the entire width?... // Do we have access to the entire width?...
let mut available = size.x; let mut available = size.x;
@ -337,12 +337,12 @@ impl TextArea {
} }
// First attempt, if scrollbase status didn't change. // First attempt, if scrollbase status didn't change.
// println_stderr!("Rows: {:?}", self.rows); // eprintln!("Rows: {:?}", self.rows);
let new_rows = let new_rows =
make_rows(&self.content[first_byte..last_byte], available); make_rows(&self.content[first_byte..last_byte], available);
// How much did this add? // How much did this add?
// println_stderr!("New rows: {:?}", new_rows); // eprintln!("New rows: {:?}", new_rows);
// println_stderr!("{}-{}", first_row, last_row); // eprintln!("{}-{}", first_row, last_row);
let new_row_count = self.rows.len() + new_rows.len() + first_row - let new_row_count = self.rows.len() + new_rows.len() + first_row -
last_row; last_row;
if !scrollable && new_row_count > size.y { if !scrollable && new_row_count > size.y {
@ -373,7 +373,7 @@ impl View for TextArea {
// Ideally, we'd want x = the longest row + 1 // Ideally, we'd want x = the longest row + 1
// (we always keep a space at the end) // (we always keep a space at the end)
// And y = number of rows // And y = number of rows
// println_stderr!("{:?}", self.rows); // eprintln!("{:?}", self.rows);
let scroll_width = if self.rows.len() > constraint.y { 1 } else { 0 }; let scroll_width = if self.rows.len() > constraint.y { 1 } else { 0 };
Vec2::new( Vec2::new(
scroll_width + 1 + self.rows.iter().map(|r| r.width).max().unwrap_or(1), scroll_width + 1 + self.rows.iter().map(|r| r.width).max().unwrap_or(1),
@ -401,13 +401,13 @@ impl View for TextArea {
}, },
); );
// println_stderr!("Content: `{}`", &self.content); // eprintln!("Content: `{}`", &self.content);
self.scrollbase.draw(printer, |printer, i| { self.scrollbase.draw(printer, |printer, i| {
// println_stderr!("Drawing row {}", i); // eprintln!("Drawing row {}", i);
let row = &self.rows[i]; let row = &self.rows[i];
// println_stderr!("row: {:?}", row); // eprintln!("row: {:?}", row);
let text = &self.content[row.start..row.end]; let text = &self.content[row.start..row.end];
// println_stderr!("row text: `{}`", text); // eprintln!("row text: `{}`", text);
printer.with_effect( printer.with_effect(
effect, effect,
|printer| { printer.print((0, 0), text); }, |printer| { printer.print((0, 0), text); },
@ -467,7 +467,7 @@ impl View for TextArea {
_ => return EventResult::Ignored, _ => return EventResult::Ignored,
} }
// println_stderr!("Rows: {:?}", self.rows); // eprintln!("Rows: {:?}", self.rows);
let focus = self.selected_row(); let focus = self.selected_row();
self.scrollbase.scroll_to(focus); self.scrollbase.scroll_to(focus);