meli: Tidy up use of debug!

melib::debug! macro was deprecated when we started using the `log` crate
in `melib`. This commit replaces it with log::{debug,trace}! macro uses.
pull/227/head
Manos Pitsidianakis 2023-06-16 20:20:12 +03:00
parent 575509f1ed
commit 45bac6eb16
Signed by: Manos Pitsidianakis
GPG Key ID: 7729C7707F7E09D0
28 changed files with 239 additions and 336 deletions

View File

@ -27,12 +27,13 @@
* See also the [`Component`] trait for more details.
*/
use smallvec::SmallVec;
use super::*;
use crate::{
melib::text_processing::{TextProcessing, Truncate},
terminal::boundaries::*,
};
use smallvec::SmallVec;
pub mod mail;
pub use crate::mail::*;
@ -178,12 +179,12 @@ pub trait Component: Display + Debug + Send + Sync {
}
fn realize(&self, parent: Option<ComponentId>, context: &mut Context) {
log::debug!("Realizing id {} w/ parent {:?}", self.id(), &parent);
// log::trace!("Realizing id {} w/ parent {:?}", self.id(), &parent);
context.realized.insert(self.id(), parent);
}
fn unrealize(&self, context: &mut Context) {
log::debug!("Unrealizing id {}", self.id());
// log::trace!("Unrealizing id {}", self.id());
context.unrealized.insert(self.id());
context
.replies
@ -297,9 +298,9 @@ impl ComponentPath {
pub fn resolve<'c>(&self, root: &'c dyn Component) -> Option<&'c dyn Component> {
let mut cursor = root;
for id in self.tail.iter().rev().chain(std::iter::once(&self.id)) {
log::trace!("resolve cursor = {} next id is {}", cursor.id(), &id);
// log::trace!("resolve cursor = {} next id is {}", cursor.id(), &id);
if *id == cursor.id() {
log::trace!("continue;");
// log::trace!("continue;");
continue;
}
cursor = cursor.children().remove(id)?;

View File

@ -256,7 +256,7 @@ impl ContactList {
context: &mut Context,
) {
if !is_valid_area!(area) {
debug!("BUG: invalid area in print_account");
log::debug!("BUG: invalid area in print_account");
}
let width = width!(area);

View File

@ -1355,9 +1355,7 @@ impl Component for Composer {
ViewMode::SelectEncryptKey(is_encrypt, ref mut selector),
UIEvent::FinishedUIDialog(id, result),
) if *id == selector.id() => {
debug!(&result);
if let Some(key) = result.downcast_mut::<Option<melib::gpgme::Key>>() {
debug!("got key {:?}", key);
if let Some(key) = key {
if *is_encrypt {
self.gpg_state.encrypt_keys.clear();
@ -1815,7 +1813,7 @@ impl Component for Composer {
}
let editor_command = format!("{} {}", editor, f.path().display());
log::debug!(
log::trace!(
"Executing: sh -c \"{}\"",
editor_command.replace('"', "\\\"")
);
@ -1957,7 +1955,7 @@ impl Component for Composer {
context.input_kill();
}
log::debug!("Executing: sh -c \"{}\"", command.replace('"', "\\\""));
log::trace!("Executing: sh -c \"{}\"", command.replace('"', "\\\""));
match Command::new("sh")
.args(["-c", command])
.stdin(Stdio::inherit())
@ -1967,7 +1965,7 @@ impl Component for Composer {
.and_then(|child| Ok(child.wait_with_output()?.stderr))
{
Ok(stderr) => {
debug!(&String::from_utf8_lossy(&stderr));
log::trace!("stderr: {}", &String::from_utf8_lossy(&stderr));
for path in stderr.split(|c| [b'\0', b'\t', b'\n'].contains(c)) {
match melib::email::compose::attachment_from_file(
&String::from_utf8_lossy(path).as_ref(),
@ -2227,7 +2225,6 @@ pub fn send_draft(
);
match output {
Err(err) => {
debug!("{:?} could not sign draft msg", err);
log::error!(
"Could not sign draft in account `{}`: {err}.",
context.accounts[&account_hash].name(),

View File

@ -56,11 +56,6 @@ impl KeySelection {
context: &mut Context,
) -> Result<Self> {
use melib::gpgme::*;
debug!("KeySelection::new");
debug!(&secret);
debug!(&local);
debug!(&pattern);
debug!(&allow_remote_lookup);
let mut ctx = Context::new()?;
if local {
ctx.set_auto_key_locate(LocateKey::LOCAL)?;
@ -109,8 +104,6 @@ impl Component for KeySelection {
}
fn process_event(&mut self, event: &mut UIEvent, context: &mut Context) -> bool {
debug!(&self);
debug!(&event);
match self {
KeySelection::LoadingKeys {
ref mut progress_spinner,

View File

@ -371,13 +371,13 @@ impl MailListingTrait for CompactListing {
continue 'items_for_loop;
};
if !context.accounts[&self.cursor_pos.0].contains_key(root_env_hash) {
debug!("key = {}", root_env_hash);
debug!(
log::debug!("key = {}", root_env_hash);
log::debug!(
"name = {} {}",
account[&self.cursor_pos.1].name(),
context.accounts[&self.cursor_pos.0].name()
);
debug!("{:#?}", context.accounts);
log::debug!("{:#?}", context.accounts);
panic!();
}
@ -1260,10 +1260,8 @@ impl CompactListing {
}
debug_assert!(end >= start);
if self.rows_drawn.get_max(start, end) == 0 {
//debug!("not drawing {}-{}", start, end);
return;
}
//debug!("drawing {}-{}", start, end);
for i in start..=end {
self.rows_drawn.update(i, 0);
}
@ -1425,7 +1423,6 @@ impl CompactListing {
if !account.collection.contains_key(&env_hash) {
continue;
}
debug!(account.collection.get_env(env_hash).subject());
let env_thread_node_hash = account.collection.get_env(env_hash).thread();
if !threads.thread_nodes.contains_key(&env_thread_node_hash) {
continue;
@ -1807,7 +1804,6 @@ impl Component for CompactListing {
UIEvent::Action(ref action) => {
match action {
Action::Sort(field, order) if !self.unfocused() => {
debug!("Sort {:?} , {:?}", field, order);
self.sort = (*field, *order);
self.sortcmd = true;
if !self.filtered_selection.is_empty() {
@ -1819,7 +1815,6 @@ impl Component for CompactListing {
return true;
}
Action::SubSort(field, order) if !self.unfocused() => {
debug!("SubSort {:?} , {:?}", field, order);
self.subsort = (*field, *order);
// FIXME: perform subsort.
return true;

View File

@ -276,13 +276,13 @@ impl MailListingTrait for ConversationsListing {
continue 'items_for_loop;
};
if !context.accounts[&self.cursor_pos.0].contains_key(root_env_hash) {
debug!("key = {}", root_env_hash);
debug!(
log::debug!("key = {}", root_env_hash);
log::debug!(
"name = {} {}",
account[&self.cursor_pos.1].name(),
context.accounts[&self.cursor_pos.0].name()
);
debug!("{:#?}", context.accounts);
log::debug!("{:#?}", context.accounts);
panic!();
}
@ -1392,36 +1392,11 @@ impl Component for ConversationsListing {
}
UIEvent::Action(ref action) => match action {
Action::SubSort(field, order) if !self.unfocused() => {
debug!("SubSort {:?} , {:?}", field, order);
self.subsort = (*field, *order);
// FIXME subsort
//if !self.filtered_selection.is_empty() {
// let threads = &account.collection.threads[&self.cursor_pos.1];
// threads.vec_inner_sort_by(&mut self.filtered_selection, self.sort,
// &account.collection);
//} else {
// self.refresh_mailbox(context, false);
//}
return true;
}
Action::Sort(field, order) if !self.unfocused() => {
debug!("Sort {:?} , {:?}", field, order);
// FIXME sort
/*
self.sort = (*field, *order);
if !self.filtered_selection.is_empty() {
let threads = &context.accounts[&self.cursor_pos.0].collection.threads
[&self.cursor_pos.1];
threads.vec_inner_sort_by(
&mut self.filtered_selection,
self.sort,
&context.accounts[&self.cursor_pos.0].collection.envelopes,
);
self.set_dirty(true);
} else {
self.refresh_mailbox(context, false);
}
*/
return true;
}
Action::Listing(ToggleThreadSnooze) if !self.unfocused() => {

View File

@ -765,13 +765,13 @@ impl PlainListing {
for i in iter {
if !context.accounts[&self.cursor_pos.0].contains_key(i) {
debug!("key = {}", i);
debug!(
log::debug!("key = {}", i);
log::debug!(
"name = {} {}",
mailbox.name(),
context.accounts[&self.cursor_pos.0].name()
);
debug!("{:#?}", context.accounts);
log::debug!("{:#?}", context.accounts);
panic!();
}
@ -858,13 +858,13 @@ impl PlainListing {
let columns = &mut self.data_columns.columns;
for ((idx, i), (_, strings)) in iter.enumerate().zip(self.rows.entries.iter()) {
if !context.accounts[&self.cursor_pos.0].contains_key(i) {
//debug!("key = {}", i);
//debug!(
//log::debug!("key = {}", i);
//log::debug!(
// "name = {} {}",
// mailbox.name(),
// context.accounts[&self.cursor_pos.0].name()
//);
//debug!("{:#?}", context.accounts);
//log::debug!("{:#?}", context.accounts);
panic!();
}
@ -1446,7 +1446,6 @@ impl Component for PlainListing {
}
UIEvent::Action(ref action) => match action {
Action::SubSort(field, order) if !self.unfocused() => {
debug!("SubSort {:?} , {:?}", field, order);
self.subsort = (*field, *order);
//if !self.filtered_selection.is_empty() {
// let threads = &account.collection.threads[&self.cursor_pos.1];
@ -1458,7 +1457,6 @@ impl Component for PlainListing {
return true;
}
Action::Sort(field, order) if !self.unfocused() => {
debug!("Sort {:?} , {:?}", field, order);
self.sort = (*field, *order);
return true;
}

View File

@ -102,8 +102,8 @@ macro_rules! row_attr {
}};
}
/// A list of all mail ([`Envelope`](melib::Envelope)s) in a `Mailbox`. On `\n` it opens the
/// [`Envelope`](melib::Envelope) content in a [`MailView`].
/// A list of all mail ([`Envelope`](melib::Envelope)s) in a `Mailbox`. On `\n`
/// it opens the [`Envelope`](melib::Envelope) content in a [`MailView`].
#[derive(Debug)]
pub struct ThreadListing {
/// (x, y, z): x is accounts, y is mailboxes, z is index inside a mailbox.
@ -844,7 +844,6 @@ impl ThreadListing {
return;
}
debug_assert!(end >= start);
//debug!("drawing {}-{}", start, end);
let min_width = (
self.data_columns.columns[0].size().0,
self.data_columns.columns[1].size().0,
@ -1453,14 +1452,12 @@ impl Component for ThreadListing {
}
UIEvent::Action(ref action) => match action {
Action::SubSort(field, order) => {
debug!("SubSort {:?} , {:?}", field, order);
self.subsort = (*field, *order);
self.set_dirty(true);
self.refresh_mailbox(context, false);
return true;
}
Action::Sort(field, order) => {
debug!("Sort {:?} , {:?}", field, order);
self.sort = (*field, *order);
self.set_dirty(true);
self.refresh_mailbox(context, false);

View File

@ -109,10 +109,10 @@ pub fn encrypt_filter(
Err("libgpgme functions are temporarily disabled due to an unsolved bug <https://git.meli.delivery/meli/meli/issues/176>.".into())
/*
let a: Attachment = a.into();
debug!("main attachment is {:?}", &a);
log::trace!("main attachment is {:?}", &a);
let mut ctx = Context::new()?;
let data = ctx.new_data_mem(
a.into_raw().as_bytes()
a.into_raw().as_bytes()
)?;
let sig_attachment = {

View File

@ -388,7 +388,11 @@ impl Component for MailView {
self.init_futures(context);
}
MailViewState::Loaded { .. } => {
log::debug!("MailView.active_jobs contains job id {:?} but MailViewState is already loaded; what job was this and why was it in active_jobs?", job_id);
log::debug!(
"MailView.active_jobs contains job id {:?} but MailViewState is \
already loaded; what job was this and why was it in active_jobs?",
job_id
);
}
_ => {}
}

View File

@ -31,8 +31,8 @@ use crate::ThreadEvent;
/// subviews for more menus.
///
/// Doesn't have a concept of accounts, mailboxes or mail backends.
/// Therefore all settings it needs need to be provided through the `view_settings` field of type
/// [`ViewSettings`].
/// Therefore all settings it needs need to be provided through the
/// `view_settings` field of type [`ViewSettings`].
#[derive(Debug)]
pub struct EnvelopeView {
pub pager: Pager,

View File

@ -19,9 +19,7 @@
* along with meli. If not, see <http://www.gnu.org/licenses/>.
*/
/*!
Notification handling components.
*/
//! Notification handling components
use std::process::{Command, Stdio};
#[cfg(all(target_os = "linux", feature = "dbus-notifications"))]
@ -123,7 +121,6 @@ mod dbus {
}
if let Err(err) = notification.show() {
log::debug!("Could not show dbus notification: {:?}", &err);
log::error!("Could not show dbus notification: {err}");
}
}
@ -197,7 +194,6 @@ impl Component for NotificationCommand {
if *kind == Some(NotificationType::NewMail) {
if let Some(ref path) = context.settings.notifications.xbiff_file_path {
if let Err(err) = update_xbiff(path) {
log::debug!("Could not update xbiff file: {:?}", &err);
log::error!("Could not update xbiff file: {err}.");
}
}
@ -224,7 +220,6 @@ impl Component for NotificationCommand {
}
Err(err) => {
log::error!("Could not run notification script: {err}.");
log::debug!("Could not run notification script: {:?}", err);
}
}
} else {
@ -257,7 +252,6 @@ impl Component for NotificationCommand {
}
Err(err) => {
log::error!("Could not run notification script: {err}.");
log::debug!("Could not run notification script: {:?}", err);
}
}
}

View File

@ -353,7 +353,7 @@ impl Component for StatusBar {
.map(std::path::Path::new)
{
suggestions.extend(
debug!(debug!(p).complete(true))
p.complete(true)
.into_iter()
.map(|m| format!("{}{}", self.ex_buffer.as_str(), m).into()),
);
@ -814,33 +814,12 @@ impl Component for StatusBar {
fn realize(&self, parent: Option<ComponentId>, context: &mut Context) {
context.realized.insert(self.id(), parent);
log::debug!(
"Realizing statusbar id {} w/ parent {:?}",
self.id(),
&parent
);
log::debug!(
"Realizing statusbar container id {} w/ parent {:?}",
self.container.id(),
&self.id
);
self.container.realize(self.id().into(), context);
log::debug!(
"Realizing progress_spinner container id {} w/ parent {:?}",
self.progress_spinner.id(),
&self.id
);
log::debug!(
"Realizing ex_buffer container id {} w/ parent {:?}",
self.ex_buffer.id(),
&self.id
);
self.progress_spinner.realize(self.id().into(), context);
self.ex_buffer.realize(self.id().into(), context);
}
fn unrealize(&self, context: &mut Context) {
log::debug!("Unrealizing id {}", self.id());
context.unrealized.insert(self.id());
self.container.unrealize(context);
self.progress_spinner.unrealize(context);
@ -1477,9 +1456,10 @@ impl Component for Tabbed {
self.help_curr_views = children_maps;
return true;
} else {
debug!(
"DEBUG: Child component with id {:?} not found.\nList: {:?}",
id, self.children
log::debug!(
"Child component with id {:?} not found.\nList: {:?}",
id,
self.children
);
}
}
@ -1627,16 +1607,13 @@ impl Component for Tabbed {
}
fn realize(&self, parent: Option<ComponentId>, context: &mut Context) {
log::debug!("Realizing Tabbed id {} w/ parent {:?}", self.id(), &parent);
context.realized.insert(self.id(), parent);
for c in &self.children {
log::debug!("Realizing child id {} w/ parent {:?}", c.id(), &self.id);
c.realize(self.id().into(), context);
}
}
fn unrealize(&self, context: &mut Context) {
log::debug!("Unrealizing id {}", self.id());
context
.replies
.push_back(UIEvent::ComponentUnrealize(self.id()));

View File

@ -936,7 +936,7 @@ impl<T: 'static + PartialEq + Debug + Clone + Sync + Send> UIDialog<T> {
..
} = self;
done_fn.take().and_then(|done_fn| {
debug!(done_fn(
done_fn(
*id,
entries
.iter()
@ -945,7 +945,7 @@ impl<T: 'static + PartialEq + Debug + Clone + Sync + Send> UIDialog<T> {
.cloned()
.collect::<Vec<_>>()
.as_slice(),
))
)
})
}
}

View File

@ -41,11 +41,13 @@ pub struct Pager {
colors: ThemeAttribute,
initialised: bool,
show_scrollbar: bool,
/// At the last draw, were the visible columns plus horizontal cursor less than total width?
/// Used to decide whether to accept `scroll_right` key events.
/// At the last draw, were the visible columns plus horizontal cursor less
/// than total width? Used to decide whether to accept `scroll_right`
/// key events.
cols_lt_width: bool,
/// At the last draw, were the visible rows plus vertical cursor less than total height?
/// Used to decide whether to accept `scroll_down` key events.
/// At the last draw, were the visible rows plus vertical cursor less than
/// total height? Used to decide whether to accept `scroll_down` key
/// events.
rows_lt_height: bool,
filtered_content: Option<(String, Result<CellBuffer>)>,
text_lines: Vec<String>,
@ -64,9 +66,9 @@ impl Pager {
const PAGES_AHEAD_TO_RENDER_NO: usize = 16;
pub fn new(context: &Context) -> Self {
let mut ret = Pager {
let mut ret = Self {
minimum_width: context.settings.pager.minimum_width,
..Pager::default()
..Self::default()
};
ret.set_colors(crate::conf::value(context, "theme_default"))
.set_reflow(if context.settings.pager.split_long_lines {
@ -154,7 +156,7 @@ impl Pager {
}
}
let mut ret = Pager {
let mut ret = Self {
text,
text_lines: vec![],
reflow,

View File

@ -510,8 +510,7 @@ impl Account {
Err(err) => {
main_loop_handler.send(ThreadEvent::UIEvent(UIEvent::StatusEvent(
StatusEvent::DisplayMessage(format!(
"Error with setting up an sqlite3 search database for account \
`{}`: {}",
"Error with setting up an sqlite3 search database for account `{}`: {}",
name, err
)),
)));
@ -843,7 +842,7 @@ impl Account {
return Some(EnvelopeUpdate(env_hash));
}
RefreshEventKind::Rename(old_hash, new_hash) => {
debug!("rename {} to {}", old_hash, new_hash);
log::trace!("rename {} to {}", old_hash, new_hash);
if !self.collection.rename(old_hash, new_hash, mailbox_hash) {
return Some(EnvelopeRename(old_hash, new_hash));
}
@ -1012,7 +1011,7 @@ impl Account {
self.watch();
}
RefreshEventKind::Failure(err) => {
debug!("RefreshEvent Failure: {}", err.to_string());
log::trace!("RefreshEvent Failure: {}", err.to_string());
while let Some((job_id, _)) =
self.active_jobs.iter().find(|(_, j)| j.is_watch())
{
@ -1222,7 +1221,6 @@ impl Account {
] {
if let Some(mailbox_hash) = mailbox {
if let Err(err) = self.save(bytes, *mailbox_hash, Some(flags)) {
debug!("{:?} could not save msg", err);
log::error!("Could not save in '{}' mailbox: {}.", *mailbox_hash, err);
} else {
saved_at = Some(*mailbox_hash);
@ -1237,7 +1235,7 @@ impl Account {
Ok(mailbox_hash)
} else {
let file = crate::types::create_temp_file(bytes, None, None, Some("eml"), false);
debug!("message saved in {}", file.path.display());
log::trace!("message saved in {}", file.path.display());
log::info!(
"Message was stored in {} so that you can restore it manually.",
file.path.display()
@ -1296,7 +1294,6 @@ impl Account {
};
use crate::conf::composing::SendMail;
debug!(&send_mail);
match send_mail {
SendMail::ShellCommand(ref command) => {
if command.is_empty() {
@ -1702,7 +1699,7 @@ impl Account {
ref mut handle,
..
} => {
debug!("got payload in status for {}", mailbox_hash);
log::trace!("got payload in status for {}", mailbox_hash);
match handle.chan.try_recv() {
Err(_) => {
/* canceled */
@ -1712,7 +1709,7 @@ impl Account {
return true;
}
Ok(Some((None, _))) => {
debug!("finished in status for {}", mailbox_hash);
log::trace!("finished in status for {}", mailbox_hash);
self.mailbox_entries
.entry(mailbox_hash)
.and_modify(|entry| {
@ -2154,7 +2151,7 @@ impl Account {
}
}
JobRequest::Watch { ref mut handle } => {
debug!("JobRequest::Watch finished??? ");
log::trace!("JobRequest::Watch finished??? ");
if let Ok(Some(Err(err))) = handle.chan.try_recv() {
if err.kind.is_timeout() {
self.watch();

View File

@ -37,7 +37,7 @@ use crossbeam::{
sync::{Parker, Unparker},
};
pub use futures::channel::oneshot;
use melib::{smol, uuid::Uuid};
use melib::{log, smol, uuid::Uuid};
use crate::types::{ThreadEvent, UIEvent};
@ -196,11 +196,11 @@ impl JobExecutor {
if let Some(meli_task) = task {
let MeliTask { task, id, timer } = meli_task;
if !timer {
debug!("Worker {} got task {:?}", i, id);
log::trace!("Worker {} got task {:?}", i, id);
}
let _ = catch_unwind(|| task.run());
if !timer {
debug!("Worker {} returned after {:?}", i, id);
log::trace!("Worker {} returned after {:?}", i, id);
}
}
})
@ -360,8 +360,8 @@ impl JobExecutor {
pub type JobChannel<T> = oneshot::Receiver<T>;
#[derive(Debug)]
/// JoinHandle for the future that allows us to cancel the task.
#[derive(Debug)]
pub struct JoinHandle<T> {
pub task: Arc<Mutex<Option<async_task::Task<()>>>>,
pub chan: JobChannel<T>,

View File

@ -47,7 +47,6 @@ pub use structopt::StructOpt;
#[global_allocator]
static GLOBAL: System = System;
#[macro_use]
pub extern crate melib;
pub use melib::{
error::*, log, AccountHash, Envelope, EnvelopeHash, EnvelopeRef, Flag, LogLevel, Mail, Mailbox,

View File

@ -107,7 +107,7 @@ impl MailcapEntry {
if flag.trim() == "copiousoutput" {
copiousoutput = true;
} else {
debug!("unknown mailcap flag: {}", flag);
log::trace!("unknown mailcap flag: {}", flag);
}
}
@ -130,7 +130,7 @@ impl MailcapEntry {
if flag.trim() == "copiousoutput" {
copiousoutput = true;
} else {
debug!("unknown mailcap flag: {}", flag);
log::trace!("unknown mailcap flag: {}", flag);
}
}
@ -191,7 +191,7 @@ impl MailcapEntry {
})
.collect::<Vec<String>>();
let cmd_string = format!("{} {}", cmd, args.join(" "));
log::debug!("Executing: sh -c \"{}\"", cmd_string.replace('"', "\\\""));
log::trace!("Executing: sh -c \"{}\"", cmd_string.replace('"', "\\\""));
if copiousoutput {
let out = if needs_stdin {
let mut child = Command::new("sh")
@ -227,7 +227,8 @@ impl MailcapEntry {
.stdout(Stdio::inherit())
.spawn()?;
pager.stdin.as_mut().unwrap().write_all(&out)?;
debug!(pager.wait_with_output()?.stdout);
let _output = pager.wait_with_output()?;
log::trace!("stdout = {}", String::from_utf8_lossy(&_output.stdout));
} else if needs_stdin {
let mut child = Command::new("sh")
.args(["-c", &cmd_string])
@ -240,7 +241,8 @@ impl MailcapEntry {
.as_mut()
.unwrap()
.write_all(&a.decode(Default::default()))?;
debug!(child.wait_with_output()?.stdout);
let _output = child.wait_with_output()?;
log::trace!("stdout = {}", String::from_utf8_lossy(&_output.stdout));
} else {
let child = Command::new("sh")
.args(["-c", &cmd_string])
@ -248,7 +250,8 @@ impl MailcapEntry {
.stdout(Stdio::inherit())
.spawn()?;
debug!(child.wait_with_output()?.stdout);
let _output = child.wait_with_output()?;
log::trace!("stdout = {}", String::from_utf8_lossy(&_output.stdout));
}
context.replies.push_back(UIEvent::Fork(ForkType::Finished));
Ok(())

View File

@ -327,7 +327,7 @@ fn run_app(opt: Opt) -> Result<()> {
match r {
Ok(ThreadEvent::Pulse) | Ok(ThreadEvent::UIEvent(UIEvent::Timer(_))) => {},
_ => {
log::debug!("{:?}", &r);
log::trace!("{:?}", &r);
}
}
match r.unwrap() {
@ -428,13 +428,12 @@ fn run_app(opt: Opt) -> Result<()> {
state.redraw();
},
ThreadEvent::JobFinished(id) => {
log::debug!("Job finished {}", id);
log::trace!("Job finished {}", id);
for account in state.context.accounts.values_mut() {
if account.process_event(&id) {
break;
}
}
//state.new_thread(id, name);
},
}
},
@ -453,7 +452,7 @@ fn run_app(opt: Opt) -> Result<()> {
}
other => {
log::debug!("got other signal: {:?}", other);
log::trace!("got other signal: {:?}", other);
}
}
},

View File

@ -19,7 +19,6 @@
* along with meli. If not, see <http://www.gnu.org/licenses/>.
*/
#[macro_use]
extern crate melib;
use std::collections::VecDeque;

View File

@ -166,14 +166,6 @@ pub async fn insert(
let body = match op.await.map(|bytes| envelope.body_bytes(&bytes)) {
Ok(body) => body.text(),
Err(err) => {
debug!(
"{}",
format!(
"Failed to open envelope {}: {}",
envelope.message_id_display(),
err
)
);
log::error!(
"Failed to open envelope {}: {err}",
envelope.message_id_display(),
@ -186,11 +178,6 @@ pub async fn insert(
"INSERT OR IGNORE INTO accounts (name) VALUES (?1)",
params![acc_name,],
) {
debug!(
"Failed to insert envelope {}: {}",
envelope.message_id_display(),
err
);
log::error!(
"Failed to insert envelope {}: {err}",
envelope.message_id_display(),
@ -238,10 +225,6 @@ pub async fn insert(
)
.map_err(|e| Error::new(e.to_string()))
{
log::debug!(
"Failed to insert envelope {}: {err}",
envelope.message_id_display(),
);
log::error!(
"Failed to insert envelope {}: {err}",
envelope.message_id_display(),
@ -266,7 +249,6 @@ pub fn remove(env_hash: EnvelopeHash) -> Result<()> {
)
.map_err(|e| Error::new(e.to_string()))
{
log::debug!("Failed to remove envelope {env_hash}: {err}");
log::error!("Failed to remove envelope {env_hash}: {err}");
return Err(err);
}
@ -308,14 +290,11 @@ pub fn index(context: &mut crate::state::Context, account_index: usize) -> Resul
x
};
let mut ctr = 0;
debug!(
"{}",
format!(
"Rebuilding {} index. {}/{}",
acc_name,
ctr,
env_hashes.len()
)
log::trace!(
"Rebuilding {} index. {}/{}",
acc_name,
ctr,
env_hashes.len()
);
for chunk in env_hashes.chunks(200) {
ctr += chunk.len();
@ -378,26 +357,23 @@ pub fn search(
let conn = melib_sqlite3::open_db(db_path)?;
let sort_field = match debug!(sort_field) {
let sort_field = match sort_field {
SortField::Subject => "subject",
SortField::Date => "timestamp",
};
let sort_order = match debug!(sort_order) {
let sort_order = match sort_order {
SortOrder::Asc => "ASC",
SortOrder::Desc => "DESC",
};
let mut stmt = conn
.prepare(
debug!(format!(
"SELECT hash FROM envelopes WHERE {} ORDER BY {} {};",
query_to_sql(query),
sort_field,
sort_order
))
.as_str(),
)
.prepare(&format!(
"SELECT hash FROM envelopes WHERE {} ORDER BY {} {};",
query_to_sql(query),
sort_field,
sort_order
))
.map_err(|e| Error::new(e.to_string()))?;
let results = stmt

View File

@ -95,7 +95,7 @@ impl InputHandler {
match self.control.upgrade() {
Some(_) => {}
None => {
debug!("restarting input_thread");
log::trace!("restarting input_thread");
self.restore();
}
}
@ -159,9 +159,9 @@ impl Context {
let was_online = accounts[account_pos].is_online.is_ok();
let ret = accounts[account_pos].is_online();
if ret.is_ok() && !was_online {
debug!("inserting mailbox hashes:");
log::trace!("inserting mailbox hashes:");
for mailbox_node in accounts[account_pos].list_mailboxes() {
debug!(
log::trace!(
"hash & mailbox: {:?} {}",
mailbox_node.hash,
accounts[account_pos][&mailbox_node.hash].name()
@ -297,13 +297,13 @@ impl Drop for State {
nix::unistd::Pid::from_raw(child.id() as i32),
Some(WaitPidFlag::WNOHANG),
) {
debug!("Failed to wait on subprocess {}: {}", child.id(), err);
log::warn!("Failed to wait on subprocess {}: {}", child.id(), err);
}
}
if let Some(ForkType::Embed(child_pid)) = self.child.take() {
/* Try wait, we don't want to block */
if let Err(e) = waitpid(child_pid, Some(WaitPidFlag::WNOHANG)) {
debug!("Failed to wait on subprocess {}: {}", child_pid, e);
log::warn!("Failed to wait on subprocess {}: {}", child_pid, e);
}
}
}
@ -501,7 +501,7 @@ impl State {
self.rcv_event(notification);
}
} else if let melib::backends::RefreshEventKind::Failure(err) = event.kind {
debug!(err);
log::warn!("Backend could not refresh: {}", err);
}
}

View File

@ -19,14 +19,12 @@
* along with meli. If not, see <http://www.gnu.org/licenses/>.
*/
/*! Terminal grid cells, keys, colors, etc.
*/
extern crate serde;
use self::serde::{de, de::Visitor, Deserialize, Deserializer};
extern crate unicode_segmentation;
//! Terminal grid cells, keys, colors, etc.
use melib::log;
use serde::{de, de::Visitor, Deserialize, Deserializer};
mod color;
pub use self::color::*;
pub use color::*;
#[macro_use]
mod position;
#[macro_use]
@ -568,9 +566,12 @@ pub mod screen {
if termcols.unwrap_or(72) as usize != self.cols
|| termrows.unwrap_or(120) as usize != self.rows
{
debug!(
log::trace!(
"Size updated, from ({}, {}) -> ({:?}, {:?})",
self.cols, self.rows, termcols, termrows
self.cols,
self.rows,
termcols,
termrows
);
}
self.cols = termcols.unwrap_or(72) as usize;

View File

@ -31,7 +31,10 @@ use std::{
ops::{Deref, DerefMut, Index, IndexMut},
};
use melib::text_processing::wcwidth;
use melib::{
log,
text_processing::{search::KMP, wcwidth},
};
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
use smallvec::SmallVec;
@ -275,10 +278,6 @@ impl CellBuffer {
/// | 666666666666 | | |
/// ```
pub fn scroll_up(&mut self, scroll_region: &ScrollRegion, top: usize, offset: usize) {
//debug!(
// "scroll_up scroll_region {:?}, top: {} offset {}",
// scroll_region, top, offset
//);
let l = scroll_region.left;
let r = if scroll_region.right == 0 {
self.size().0
@ -337,10 +336,6 @@ impl CellBuffer {
/// | 666666666666 | | 555555555555 |
/// ```
pub fn scroll_down(&mut self, scroll_region: &ScrollRegion, top: usize, offset: usize) {
//debug!(
// "scroll_down scroll_region {:?}, top: {} offset {}",
// scroll_region, top, offset
//);
for y in (scroll_region.bottom - offset + 1)..=scroll_region.bottom {
for x in 0..self.size().0 {
self[(x, y)] = Cell::default();
@ -953,9 +948,10 @@ pub fn copy_area_with_break(
src: Area,
) -> Pos {
if !is_valid_area!(dest) || !is_valid_area!(src) {
debug!(
log::debug!(
"BUG: Invalid areas in copy_area:\n src: {:?}\n dest: {:?}",
src, dest
src,
dest
);
return upper_left!(dest);
}
@ -1000,9 +996,10 @@ pub fn copy_area_with_break(
/// Copy a source `Area` to a destination.
pub fn copy_area(grid_dest: &mut CellBuffer, grid_src: &CellBuffer, dest: Area, src: Area) -> Pos {
if !is_valid_area!(dest) || !is_valid_area!(src) {
debug!(
log::debug!(
"BUG: Invalid areas in copy_area:\n src: {:?}\n dest: {:?}",
src, dest
src,
dest
);
return upper_left!(dest);
}
@ -1016,7 +1013,7 @@ pub fn copy_area(grid_dest: &mut CellBuffer, grid_src: &CellBuffer, dest: Area,
let mut src_y = get_y(upper_left!(src));
let (cols, rows) = grid_src.size();
if src_x >= cols || src_y >= rows {
debug!("BUG: src area outside of grid_src in copy_area",);
log::debug!("BUG: src area outside of grid_src in copy_area",);
return upper_left!(dest);
}
@ -1084,11 +1081,11 @@ pub fn change_colors(grid: &mut CellBuffer, area: Area, fg_color: Color, bg_colo
|| y >= get_y(bounds)
|| x >= get_x(bounds)
{
debug!("BUG: Invalid area in change_colors:\n area: {:?}", area);
log::debug!("BUG: Invalid area in change_colors:\n area: {:?}", area);
return;
}
if !is_valid_area!(area) {
debug!("BUG: Invalid area in change_colors:\n area: {:?}", area);
log::debug!("BUG: Invalid area in change_colors:\n area: {:?}", area);
return;
}
}
@ -1175,7 +1172,7 @@ pub fn write_string_to_grid(
return (x, y);
}
} else {
debug!(" Invalid area with string {} and area {:?}", s, area);
log::debug!(" Invalid area with string {} and area {:?}", s, area);
return (x, y);
}
}
@ -1713,8 +1710,6 @@ pub mod boundaries {
}
}
use melib::text_processing::search::KMP;
impl KMP for CellBuffer {
fn kmp_search(&self, pattern: &str) -> smallvec::SmallVec<[usize; 256]> {
let (mut w, prev_ind) =
@ -1755,35 +1750,6 @@ impl KMP for CellBuffer {
}
}
#[test]
fn test_cellbuffer_search() {
use melib::text_processing::{Reflow, TextProcessing, _ALICE_CHAPTER_1};
let lines: Vec<String> = _ALICE_CHAPTER_1.split_lines_reflow(Reflow::All, Some(78));
let mut buf = CellBuffer::new(
lines.iter().map(String::len).max().unwrap(),
lines.len(),
Cell::with_char(' '),
);
let width = buf.size().0;
for (i, l) in lines.iter().enumerate() {
write_string_to_grid(
l,
&mut buf,
Color::Default,
Color::Default,
Attr::DEFAULT,
((0, i), (width.saturating_sub(1), i)),
None,
);
}
for ind in buf.kmp_search("Alice") {
for c in &buf.cellvec()[ind..std::cmp::min(buf.cellvec().len(), ind + 25)] {
print!("{}", c.ch());
}
println!();
}
}
#[derive(Debug, Default, Copy, Hash, Clone, PartialEq, Eq)]
pub struct FormatTag {
pub fg: Option<Color>,
@ -1830,3 +1796,38 @@ pub enum WidgetWidth {
Hold(usize),
Set(usize),
}
#[cfg(test)]
mod tests {
use melib::text_processing::{Reflow, TextProcessing, _ALICE_CHAPTER_1};
use super::*;
#[test]
fn test_cellbuffer_search() {
let lines: Vec<String> = _ALICE_CHAPTER_1.split_lines_reflow(Reflow::All, Some(78));
let mut buf = CellBuffer::new(
lines.iter().map(String::len).max().unwrap(),
lines.len(),
Cell::with_char(' '),
);
let width = buf.size().0;
for (i, l) in lines.iter().enumerate() {
write_string_to_grid(
l,
&mut buf,
Color::Default,
Color::Default,
Attr::DEFAULT,
((0, i), (width.saturating_sub(1), i)),
None,
);
}
for ind in buf.kmp_search("Alice") {
for c in &buf.cellvec()[ind..std::cmp::min(buf.cellvec().len(), ind + 25)] {
print!("{}", c.ch());
}
println!();
}
}
}

View File

@ -185,9 +185,9 @@ pub fn create_pty(
fn forward_pty_translate_escape_codes(pty_fd: std::fs::File, grid: Arc<Mutex<EmbedTerminal>>) {
let mut bytes_iter = pty_fd.bytes();
//debug!("waiting for bytes");
//log::trace!("waiting for bytes");
while let Some(Ok(byte)) = bytes_iter.next() {
//debug!("got a byte? {:?}", byte as char);
//log::trace!("got a byte? {:?}", byte as char);
/* Drink deep, and descend. */
grid.lock().unwrap().process_byte(byte);
}

View File

@ -154,8 +154,7 @@ impl EmbedTerminal {
}
pub fn stop(&self) {
//debug!("stopping");
let _ = nix::sys::signal::kill(debug!(self.child_pid), nix::sys::signal::SIGSTOP);
let _ = nix::sys::signal::kill(self.child_pid, nix::sys::signal::SIGSTOP);
}
pub fn terminate(&self) {
@ -165,8 +164,7 @@ impl EmbedTerminal {
}
pub fn is_active(&self) -> Result<WaitStatus> {
debug!(waitpid(self.child_pid, Some(WaitPidFlag::WNOHANG),))
.map_err(|e| Error::new(e.to_string()))
waitpid(self.child_pid, Some(WaitPidFlag::WNOHANG)).map_err(|e| Error::new(e.to_string()))
}
pub fn process_byte(&mut self, byte: u8) {
@ -239,7 +237,6 @@ impl EmbedGrid {
return;
}
self.initialized = true;
//debug!("resizing to {:?}", new_val);
self.scroll_region.top = 0;
self.scroll_region.bottom = new_val.1.saturating_sub(1);
@ -367,7 +364,7 @@ impl EmbedGrid {
}
(b'D', State::ExpectingControlChar) => {
// ESCD Linefeed
//debug!("{}", EscCode::from((&(*state), byte)));
//log::trace!("{}", EscCode::from((&(*state), byte)));
if cursor.1 == scroll_region.bottom {
grid.scroll_up(scroll_region, scroll_region.top, 1);
} else {
@ -378,8 +375,8 @@ impl EmbedGrid {
}
(b'J', State::ExpectingControlChar) => {
// ESCJ Erase from the cursor to the end of the screen
//debug!("sending {}", EscCode::from((&(*state), byte)));
//debug!("erasing from {:?} to {:?}", cursor, terminal_size);
//log::trace!("sending {}", EscCode::from((&(*state), byte)));
//log::trace!("erasing from {:?} to {:?}", cursor, terminal_size);
for y in cursor.1..terminal_size.1 {
for x in cursor.0..terminal_size.0 {
grid[(x, y)] = Cell::default();
@ -389,14 +386,14 @@ impl EmbedGrid {
}
(b'K', State::ExpectingControlChar) => {
// ESCK Erase from the cursor to the end of the line
//debug!("sending {}", EscCode::from((&(*state), byte)));
//log::trace!("sending {}", EscCode::from((&(*state), byte)));
for x in cursor.0..terminal_size.0 {
grid[(x, cursor.1)] = Cell::default();
}
*state = State::Normal;
}
(_, State::ExpectingControlChar) => {
//debug!(
//log::trace!(
// "unrecognised: byte is {} and state is {:?}",
// byte as char, state
//);
@ -420,14 +417,14 @@ impl EmbedGrid {
}
/* Normal */
(b'\r', State::Normal) => {
//debug!("carriage return x-> 0, cursor was: {:?}", cursor);
//log::trace!("carriage return x-> 0, cursor was: {:?}", cursor);
cursor.0 = 0;
*wrap_next = false;
//debug!("cursor became: {:?}", cursor);
//log::trace!("cursor became: {:?}", cursor);
}
(b'\n', State::Normal) => {
//debug!("setting cell {:?} char '{}'", cursor, c as char);
//debug!("newline y-> y+1, cursor was: {:?}", cursor);
//log::trace!("setting cell {:?} char '{}'", cursor, c as char);
//log::trace!("newline y-> y+1, cursor was: {:?}", cursor);
if cursor.1 + 1 < terminal_size.1 || !is_alternate {
if cursor.1 == scroll_region.bottom && is_alternate {
@ -437,18 +434,18 @@ impl EmbedGrid {
}
}
*wrap_next = false;
//debug!("cursor became: {:?}", cursor);
//log::trace!("cursor became: {:?}", cursor);
}
(b'', State::Normal) => {
//debug!("Visual bell ^G, ignoring {:?}", cursor);
//log::trace!("Visual bell ^G, ignoring {:?}", cursor);
}
(0x08, State::Normal) => {
/* Backspace */
//debug!("backspace x-> x-1, cursor was: {:?}", cursor);
//log::trace!("backspace x-> x-1, cursor was: {:?}", cursor);
if cursor.0 > 0 {
cursor.0 -= 1;
}
//debug!("cursor became: {:?}", cursor);
//log::trace!("cursor became: {:?}", cursor);
}
(c, State::Normal) => {
/* Character to be printed. */
@ -470,14 +467,14 @@ impl EmbedGrid {
return;
}
CodepointBuf::TwoCodepoints(b) => {
//debug!("two byte char = ");
//log::trace!("two byte char = ");
unsafe { std::str::from_utf8_unchecked(&[*b, c]) }
.chars()
.next()
.unwrap()
}
CodepointBuf::ThreeCodepoints(b, Some(b1)) => {
//debug!("three byte char = ",);
//log::trace!("three byte char = ",);
unsafe { std::str::from_utf8_unchecked(&[*b, *b1, c]) }
.chars()
.next()
@ -488,7 +485,7 @@ impl EmbedGrid {
return;
}
CodepointBuf::FourCodepoints(b, Some(b1), Some(b2)) => {
//debug!("four byte char = ",);
//log::trace!("four byte char = ",);
unsafe { std::str::from_utf8_unchecked(&[*b, *b1, *b2, c]) }
.chars()
.next()
@ -503,7 +500,7 @@ impl EmbedGrid {
return;
}
_ => {
//debug!(
//log::trace!(
// "invalid utf8 sequence: codepoints = {:?} and c={}",
// codepoints, c
//);
@ -512,7 +509,7 @@ impl EmbedGrid {
}
}
};
//debug!("c = {:?}\tcursor={:?}", c, cursor);
//log::trace!("c = {:?}\tcursor={:?}", c, cursor);
*codepoints = CodepointBuf::None;
if *auto_wrap_mode && *wrap_next {
*wrap_next = false;
@ -525,7 +522,7 @@ impl EmbedGrid {
}
//if c == '↪' {
//debug!("↪ cursor is {:?}", cursor_val!());
//log::trace!("↪ cursor is {:?}", cursor_val!());
//}
grid[cursor_val!()].set_ch(c);
grid[cursor_val!()].set_fg(*fg_color);
@ -553,13 +550,13 @@ impl EmbedGrid {
}
(b'u', State::Csi) => {
/* restore cursor */
//debug!("restore cursor {}", EscCode::from((&(*state), byte)));
//log::trace!("restore cursor {}", EscCode::from((&(*state), byte)));
*show_cursor = true;
*state = State::Normal;
}
(b'm', State::Csi) => {
/* Reset character Attributes (SGR). Ps = 0 -> Normal (default), VT100 */
//debug!("{}", EscCode::from((&(*state), byte)));
//log::trace!("{}", EscCode::from((&(*state), byte)));
*fg_color = Color::Default;
*bg_color = Color::Default;
*attrs = Attr::DEFAULT;
@ -570,10 +567,10 @@ impl EmbedGrid {
}
(b'C', State::Csi) => {
// ESC[C CSI Cursor Forward one Time
//debug!("cursor forward one time, cursor was: {:?}", cursor);
//log::trace!("cursor forward one time, cursor was: {:?}", cursor);
cursor.0 = std::cmp::min(cursor.0 + 1, terminal_size.0.saturating_sub(1));
*wrap_next = false;
//debug!("cursor became: {:?}", cursor);
//log::trace!("cursor became: {:?}", cursor);
*state = State::Normal;
}
/* CSI ? stuff */
@ -604,11 +601,11 @@ impl EmbedGrid {
*screen_buffer = ScreenBuffer::Alternate;
}
_ => {
debug!("unknown csi? {:?}", String::from_utf8_lossy(buf.as_slice()));
log::trace!("unknown csi? {:?}", String::from_utf8_lossy(buf.as_slice()));
}
}
//debug!("{}", EscCode::from((&(*state), byte)));
//log::trace!("{}", EscCode::from((&(*state), byte)));
*state = State::Normal;
}
(b'l', State::CsiQ(ref mut buf)) => {
@ -644,13 +641,13 @@ impl EmbedGrid {
*screen_buffer = ScreenBuffer::Normal;
}
_ => {
debug!(
log::trace!(
"unknown csi? `l` {:?}",
String::from_utf8_lossy(buf.as_slice())
);
}
}
//debug!("{}", EscCode::from((&(*state), byte)));
//log::trace!("{}", EscCode::from((&(*state), byte)));
*state = State::Normal;
}
/* END OF CSI ? stuff */
@ -679,13 +676,13 @@ impl EmbedGrid {
),
Default::default(),
);
//debug!("{}", EscCode::from((&(*state), byte)));
//log::trace!("{}", EscCode::from((&(*state), byte)));
*state = State::Normal;
}
(b'K', State::Csi) => {
/* Erase in Line (ED), VT100. */
/* Erase to right (Default) */
//debug!("{}", EscCode::from((&(*state), byte)));
//log::trace!("{}", EscCode::from((&(*state), byte)));
for x in cursor.0..terminal_size.0 {
grid[(x, cursor.1)] = Cell::default();
}
@ -703,7 +700,7 @@ impl EmbedGrid {
grid.scroll_down(scroll_region, cursor.1, n);
//debug!("{}", EscCode::from((&(*state), byte)));
//log::trace!("{}", EscCode::from((&(*state), byte)));
*state = State::Normal;
}
(b'M', State::Csi) | (b'M', State::Csi1(_)) => {
@ -718,25 +715,25 @@ impl EmbedGrid {
grid.scroll_up(scroll_region, cursor.1, n);
//debug!("{}", EscCode::from((&(*state), byte)));
//log::trace!("{}", EscCode::from((&(*state), byte)));
*state = State::Normal;
}
(b'A', State::Csi) => {
// Move cursor up 1 line
//debug!("cursor up 1 times, cursor was: {:?}", cursor);
//log::trace!("cursor up 1 times, cursor was: {:?}", cursor);
if cursor.1 > 0 {
cursor.1 -= 1;
} else {
//debug!("cursor.1 == 0");
//log::trace!("cursor.1 == 0");
}
*wrap_next = false;
//debug!("cursor became: {:?}", cursor);
//log::trace!("cursor became: {:?}", cursor);
*state = State::Normal;
}
(b'K', State::Csi1(buf)) if buf.as_ref() == b"0" => {
/* Erase in Line (ED), VT100. */
/* Erase to right (Default) */
//debug!("{}", EscCode::from((&(*state), byte)));
//log::trace!("{}", EscCode::from((&(*state), byte)));
for x in cursor.0..terminal_size.0 {
grid[(x, cursor.1)] = Cell::default();
}
@ -748,7 +745,7 @@ impl EmbedGrid {
for x in 0..=cursor.0 {
grid[(x, cursor.1)] = Cell::default();
}
//debug!("{}", EscCode::from((&(*state), byte)));
//log::trace!("{}", EscCode::from((&(*state), byte)));
*state = State::Normal;
}
(b'K', State::Csi1(buf)) if buf.as_ref() == b"2" => {
@ -759,7 +756,7 @@ impl EmbedGrid {
grid[(x, y)] = Cell::default();
}
}
//debug!("{}", EscCode::from((&(*state), byte)));
//log::trace!("{}", EscCode::from((&(*state), byte)));
clear_area(
grid,
((0, 0), pos_dec(*terminal_size, (1, 1))),
@ -787,7 +784,7 @@ impl EmbedGrid {
),
Default::default(),
);
//debug!("{}", EscCode::from((&(*state), byte)));
//log::trace!("{}", EscCode::from((&(*state), byte)));
*state = State::Normal;
}
(b'J', State::Csi1(ref buf)) if buf.as_ref() == b"1" => {
@ -804,7 +801,7 @@ impl EmbedGrid {
),
Default::default(),
);
//debug!("{}", EscCode::from((&(*state), byte)));
//log::trace!("{}", EscCode::from((&(*state), byte)));
*state = State::Normal;
}
(b'J', State::Csi1(ref buf)) if buf.as_ref() == b"2" => {
@ -815,7 +812,7 @@ impl EmbedGrid {
((0, 0), pos_dec(*terminal_size, (1, 1))),
Default::default(),
);
//debug!("{}", EscCode::from((&(*state), byte)));
//log::trace!("{}", EscCode::from((&(*state), byte)));
*state = State::Normal;
}
(b'X', State::Csi1(ref buf)) => {
@ -838,7 +835,7 @@ impl EmbedGrid {
cur_x += 1;
ctr += 1;
}
//debug!("Erased {} Character(s)", ps);
//log::trace!("Erased {} Character(s)", ps);
*state = State::Normal;
}
(b't', State::Csi1(buf)) => {
@ -846,7 +843,7 @@ impl EmbedGrid {
if buf.as_ref() == b"18" || buf.as_ref() == b"19" {
// Ps = 18 → Report the size of the text area in characters as CSI 8 ; height ;
// width t debug!("report size of the text area");
//debug!("got {}", EscCode::from((&(*state), byte)));
//log::trace!("got {}", EscCode::from((&(*state), byte)));
stdin.write_all(b"\x1b[8;").unwrap();
stdin
.write_all((terminal_size.1).to_string().as_bytes())
@ -858,7 +855,7 @@ impl EmbedGrid {
stdin.write_all(&[b't']).unwrap();
stdin.flush().unwrap();
} else {
//debug!("ignoring unknown code {}",
//log::trace!("ignoring unknown code {}",
// EscCode::from((&(*state), byte)));
}
*state = State::Normal;
@ -866,8 +863,8 @@ impl EmbedGrid {
(b'n', State::Csi1(_)) => {
// Ps = 6 ⇒ Report Cursor Position (CPR) [row;column].
// Result is CSI r ; c R
//debug!("report cursor position");
//debug!("got {}", EscCode::from((&(*state), byte)));
//log::trace!("report cursor position");
//log::trace!("got {}", EscCode::from((&(*state), byte)));
stdin.write_all(&[b'\x1b', b'[']).unwrap();
stdin
.write_all((cursor.1 + 1).to_string().as_bytes())
@ -885,13 +882,13 @@ impl EmbedGrid {
let offset = unsafe { std::str::from_utf8_unchecked(buf) }
.parse::<usize>()
.unwrap();
//debug!("cursor up {} times, cursor was: {:?}", offset, cursor);
//log::trace!("cursor up {} times, cursor was: {:?}", offset, cursor);
if cursor.1 >= offset {
cursor.1 -= offset;
} else {
//debug!("offset > cursor.1");
//log::trace!("offset > cursor.1");
}
//debug!("cursor became: {:?}", cursor);
//log::trace!("cursor became: {:?}", cursor);
*state = State::Normal;
}
(b'B', State::Csi1(buf)) => {
@ -899,7 +896,7 @@ impl EmbedGrid {
let offset = unsafe { std::str::from_utf8_unchecked(buf) }
.parse::<usize>()
.unwrap();
//debug!("cursor down {} times, cursor was: {:?}", offset, cursor);
//log::trace!("cursor down {} times, cursor was: {:?}", offset, cursor);
if cursor.1 == scroll_region.bottom {
/* scroll down */
for y in scroll_region.top..scroll_region.bottom {
@ -917,7 +914,7 @@ impl EmbedGrid {
cursor.1 = terminal_size.1.saturating_sub(1);
}
*wrap_next = false;
//debug!("cursor became: {:?}", cursor);
//log::trace!("cursor became: {:?}", cursor);
*state = State::Normal;
}
(b'D', State::Csi1(buf)) => {
@ -928,7 +925,7 @@ impl EmbedGrid {
if cursor.0 >= offset {
cursor.0 -= offset;
}
//debug!(
//log::trace!(
// "ESC[ {} D cursor backwards cursor became: {:?}",
// offset, cursor
// );
@ -939,7 +936,7 @@ impl EmbedGrid {
let offset = unsafe { std::str::from_utf8_unchecked(buf) }
.parse::<usize>()
.unwrap();
//debug!(
//log::trace!(
// "cursor next line {} times, cursor was: {:?}",
// offset, cursor
//);
@ -951,7 +948,7 @@ impl EmbedGrid {
}
cursor.0 = 0;
*wrap_next = false;
//debug!("cursor became: {:?}", cursor);
//log::trace!("cursor became: {:?}", cursor);
*state = State::Normal;
}
(b'F', State::Csi1(buf)) => {
@ -959,14 +956,14 @@ impl EmbedGrid {
let offset = unsafe { std::str::from_utf8_unchecked(buf) }
.parse::<usize>()
.unwrap();
//debug!(
//log::trace!(
// "cursor previous line {} times, cursor was: {:?}",
// offset, cursor
//);
cursor.1 = cursor.1.saturating_sub(offset);
cursor.0 = 0;
*wrap_next = false;
//debug!("cursor became: {:?}", cursor);
//log::trace!("cursor became: {:?}", cursor);
*state = State::Normal;
}
(b'G', State::Csi1(_)) | (b'G', State::Csi) => {
@ -978,18 +975,18 @@ impl EmbedGrid {
} else {
1
};
//debug!("cursor absolute {}, cursor was: {:?}", new_col, cursor);
//log::trace!("cursor absolute {}, cursor was: {:?}", new_col, cursor);
if new_col < terminal_size.0 {
cursor.0 = new_col.saturating_sub(1);
} else {
//debug!(
//log::trace!(
// "error: new_cal = {} > terminal.size.0 =
// {}\nterminal_size = {:?}",
// new_col, terminal_size.0, terminal_size
//);
}
*wrap_next = false;
//debug!("cursor became: {:?}", cursor);
//log::trace!("cursor became: {:?}", cursor);
*state = State::Normal;
}
(b'C', State::Csi1(buf)) => {
@ -997,11 +994,11 @@ impl EmbedGrid {
let offset = unsafe { std::str::from_utf8_unchecked(buf) }
.parse::<usize>()
.unwrap();
//debug!("cursor forward {} times, cursor was: {:?}", offset, cursor);
//log::trace!("cursor forward {} times, cursor was: {:?}", offset, cursor);
if cursor.0 + offset < terminal_size.0 {
cursor.0 += offset;
}
//debug!("cursor became: {:?}", cursor);
//log::trace!("cursor became: {:?}", cursor);
*state = State::Normal;
}
(b'P', State::Csi1(_)) | (b'P', State::Csi) => {
@ -1020,7 +1017,7 @@ impl EmbedGrid {
for x in (terminal_size.0 - offset)..terminal_size.0 {
grid[(x, cursor.1)].set_ch(' ');
}
//debug!(
//log::trace!(
// "Delete {} Character(s) with cursor at {:?} ",
// offset, cursor
//);
@ -1035,7 +1032,7 @@ impl EmbedGrid {
} else {
1
};
//debug!(
//log::trace!(
// "Line position absolute row {} with cursor at {:?}",
// row, cursor
//);
@ -1044,7 +1041,7 @@ impl EmbedGrid {
cursor.1 = terminal_size.1.saturating_sub(1);
}
*wrap_next = false;
//debug!("cursor became: {:?}", cursor);
//log::trace!("cursor became: {:?}", cursor);
*state = State::Normal;
}
(b';', State::Csi1(ref mut buf1_p)) => {
@ -1151,7 +1148,7 @@ impl EmbedGrid {
b"106" => *bg_color = Color::Cyan,
b"107" => *bg_color = Color::White,
_ => {
debug!(
log::trace!(
"unknown attribute Csi1 {:?} m",
String::from_utf8_lossy(buf1.as_slice())
);
@ -1261,7 +1258,7 @@ impl EmbedGrid {
b"106" => *bg_color = Color::Cyan,
b"107" => *bg_color = Color::White,
_ => {
debug!(
log::trace!(
"unknown attribute Csi1 {:?} m",
String::from_utf8_lossy(buf1.as_slice())
);
@ -1283,7 +1280,7 @@ impl EmbedGrid {
*state = State::Csi3(buf1, buf2, buf3);
}
(b't', State::Csi2(_, _)) => {
//debug!("ignoring {}", EscCode::from((&(*state), byte)));
//log::trace!("ignoring {}", EscCode::from((&(*state), byte)));
// Window manipulation, skip it
*state = State::Normal;
}
@ -1303,7 +1300,7 @@ impl EmbedGrid {
};
let (min_y, max_y) = if *origin_mode {
//debug!(*origin_mode);
//log::trace!(*origin_mode);
orig_y += scroll_region.top;
(scroll_region.top, scroll_region.bottom)
} else {
@ -1314,13 +1311,13 @@ impl EmbedGrid {
cursor.1 = std::cmp::max(min_y, std::cmp::min(max_y, orig_y - 1));
*wrap_next = false;
//debug!("{}", EscCode::from((&(*state), byte)),);
//debug!(
//log::trace!("{}", EscCode::from((&(*state), byte)),);
//log::trace!(
// "cursor set to ({},{}), cursor was: {:?}",
// orig_x, orig_y, cursor
//);
//debug!("cursor became: {:?}", cursor);
//log::trace!("cursor became: {:?}", cursor);
*state = State::Normal;
}
(c, State::Csi2(_, ref mut buf)) if c.is_ascii_digit() => {
@ -1348,11 +1345,11 @@ impl EmbedGrid {
*cursor = (0, 0);
*wrap_next = false;
}
//debug!("set scrolling region to {:?}", scroll_region);
//log::trace!("set scrolling region to {:?}", scroll_region);
*state = State::Normal;
}
(b't', State::Csi3(_, _, _)) => {
//debug!("ignoring {}", EscCode::from((&(*state), byte)));
//log::trace!("ignoring {}", EscCode::from((&(*state), byte)));
// Window manipulation, skip it
*state = State::Normal;
}
@ -1367,7 +1364,7 @@ impl EmbedGrid {
*fg_color = if let Ok(byte) =
unsafe { std::str::from_utf8_unchecked(buf3) }.parse::<u8>()
{
//debug!("parsed buf as {}", byte);
//log::trace!("parsed buf as {}", byte);
Color::Byte(byte)
} else {
Color::Default
@ -1382,7 +1379,7 @@ impl EmbedGrid {
*bg_color = if let Ok(byte) =
unsafe { std::str::from_utf8_unchecked(buf3) }.parse::<u8>()
{
//debug!("parsed buf as {}", byte);
//log::trace!("parsed buf as {}", byte);
Color::Byte(byte)
} else {
Color::Default
@ -1542,7 +1539,7 @@ impl EmbedGrid {
*state = State::Normal;
}
(_, State::Csi) => {
debug!(
log::trace!(
"state: {:?} ignoring unknown code {} byte {}",
&state,
EscCode::from((&(*state), byte)),
@ -1551,7 +1548,7 @@ impl EmbedGrid {
*state = State::Normal;
}
(_, State::Csi1(_)) => {
debug!(
log::trace!(
"state: {:?} ignoring unknown code {} byte {}",
&state,
EscCode::from((&(*state), byte)),
@ -1560,7 +1557,7 @@ impl EmbedGrid {
*state = State::Normal;
}
(_, State::Csi2(_, _)) => {
debug!(
log::trace!(
"state: {:?} ignoring unknown code {} byte {}",
&state,
EscCode::from((&(*state), byte)),
@ -1569,7 +1566,7 @@ impl EmbedGrid {
*state = State::Normal;
}
(_, State::Csi3(_, _, _)) => {
debug!(
log::trace!(
"state: {:?} ignoring unknown code {} byte {}",
&state,
EscCode::from((&(*state), byte)),
@ -1578,7 +1575,7 @@ impl EmbedGrid {
*state = State::Normal;
}
(_, State::Csi4(_, _, _, _)) => {
debug!(
log::trace!(
"state: {:?} ignoring unknown code {} byte {}",
&state,
EscCode::from((&(*state), byte)),
@ -1587,7 +1584,7 @@ impl EmbedGrid {
*state = State::Normal;
}
(_, State::Csi5(_, _, _, _, _)) => {
debug!(
log::trace!(
"state: {:?} ignoring unknown code {} byte {}",
&state,
EscCode::from((&(*state), byte)),
@ -1596,7 +1593,7 @@ impl EmbedGrid {
*state = State::Normal;
}
(_, State::Csi6(_, _, _, _, _, _)) => {
debug!(
log::trace!(
"state: {:?} ignoring unknown code {} byte {}",
&state,
EscCode::from((&(*state), byte)),
@ -1605,7 +1602,7 @@ impl EmbedGrid {
*state = State::Normal;
}
(_, State::Osc1(_)) => {
debug!(
log::trace!(
"state: {:?} ignoring unknown code {} byte {}",
&state,
EscCode::from((&(*state), byte)),
@ -1614,7 +1611,7 @@ impl EmbedGrid {
*state = State::Normal;
}
(_, State::Osc2(_, _)) => {
debug!(
log::trace!(
"state: {:?} ignoring unknown code {} byte {}",
&state,
EscCode::from((&(*state), byte)),
@ -1623,7 +1620,7 @@ impl EmbedGrid {
*state = State::Normal;
}
(_, State::CsiQ(_)) => {
debug!(
log::trace!(
"state: {:?} ignoring unknown code {} byte {}",
&state,
EscCode::from((&(*state), byte)),
@ -1633,7 +1630,7 @@ impl EmbedGrid {
}
/* other stuff */
(_, State::G0) => {
debug!("ignoring {}", EscCode::from((&(*state), byte)));
log::trace!("ignoring {}", EscCode::from((&(*state), byte)));
*state = State::Normal;
}
}

View File

@ -246,7 +246,6 @@ pub fn get_events(
let mut paste_buf = String::with_capacity(256);
let mut stdin_iter = stdin.events_and_raw();
'poll_while: while let Ok(_n_raw) = poll(&mut [new_command_pollfd, stdin_fd], -1) {
//debug!(_n_raw);
select! {
default => {
if stdin_fd.revents().is_some() {
@ -292,7 +291,6 @@ pub fn get_events(
recv(rx) -> cmd => {
use nix::sys::time::TimeValLike;
let mut buf = [0;2];
//debug!("get_events_raw will nix::unistd::read");
let mut read_fd_set = nix::sys::select::FdSet::new();
read_fd_set.insert(new_command_fd);
let mut error_fd_set = nix::sys::select::FdSet::new();