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;
use cursive::Cursive;
use cursive::view::Boxable;
use cursive::views::{Dialog, TextView};
use cursive::align::HAlign;
@ -17,7 +18,8 @@ fn main() {
// and will adapt to the terminal size.
siv.add_fullscreen_layer(Dialog::around(TextView::new(content))
.h_align(HAlign::Center)
.button("Quit", |s| s.quit()));
.button("Quit", |s| s.quit())
.full_screen());
// Show a popup on top of the view.
siv.add_layer(Dialog::info("Try resizing the terminal!\n(Press 'q' to \
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::Num0 => '0',
_ => {
println_stderr!("Found unknown input: {:?}", kc);
eprintln!("Found unknown input: {:?}", kc);
unreachable!()
}
}

View File

@ -70,16 +70,6 @@ extern crate owning_ref;
#[macro_use]
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(
($c:ty) => {
impl Default for $c {

View File

@ -160,7 +160,7 @@ impl<T: View> ViewWrapper for BoxView<T> {
let result = self.size
.zip_map(child_size.zip(req), SizeConstraint::result);
// println_stderr!("{:?}", result);
// eprintln!("{:?}", result);
if self.squishable {
// 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) {
self.last_length = size.x;
// println_stderr!("Promised: {}", size.x);
// eprintln!("Promised: {}", size.x);
}
fn take_focus(&mut self, _: Direction) -> bool {

View File

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

View File

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

View File

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