Use env_logger and debug! instead of println!
This commit is contained in:
parent
e9b2263276
commit
bb3e547660
146
Cargo.lock
generated
146
Cargo.lock
generated
@ -2,6 +2,15 @@
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "1.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstream"
|
||||
version = "0.6.4"
|
||||
@ -186,12 +195,35 @@ dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "env_logger"
|
||||
version = "0.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "95b3f3e67048839cb0d0781f445682a35113da7121f7c949db0e2be96a4fbece"
|
||||
dependencies = [
|
||||
"humantime",
|
||||
"is-terminal",
|
||||
"log",
|
||||
"regex",
|
||||
"termcolor",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
|
||||
|
||||
[[package]]
|
||||
name = "errno"
|
||||
version = "0.3.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f258a7194e7f7c2a7837a8913aeab7fd8c383457034fa20ce4dd3dcb813e8eb8"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "event-listener"
|
||||
version = "3.1.0"
|
||||
@ -554,6 +586,18 @@ version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7"
|
||||
|
||||
[[package]]
|
||||
name = "humantime"
|
||||
version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "2.0.1"
|
||||
@ -565,10 +609,33 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.148"
|
||||
name = "is-terminal"
|
||||
version = "0.4.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b"
|
||||
checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b"
|
||||
dependencies = [
|
||||
"hermit-abi",
|
||||
"rustix",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.150"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
version = "0.4.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "969488b55f8ac402214f3f5fd243ebb7206cf82de60d3172994707a4bcc2b829"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
@ -589,13 +656,16 @@ dependencies = [
|
||||
name = "music-reader"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-channel",
|
||||
"cairo-rs",
|
||||
"clap",
|
||||
"env_logger",
|
||||
"gio",
|
||||
"glib",
|
||||
"glib-macros",
|
||||
"gtk4",
|
||||
"log",
|
||||
"poppler-rs",
|
||||
]
|
||||
|
||||
@ -742,6 +812,35 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.10.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-automata",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
|
||||
|
||||
[[package]]
|
||||
name = "rustc_version"
|
||||
version = "0.4.0"
|
||||
@ -751,6 +850,19 @@ dependencies = [
|
||||
"semver",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "0.38.25"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc99bc2d4f1fed22595588a013687477aedf3cdcfb26558c559edb67b4d9b22e"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"errno",
|
||||
"libc",
|
||||
"linux-raw-sys",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "1.0.19"
|
||||
@ -849,19 +961,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9d0e916b1148c8e263850e1ebcbd046f333e0683c724876bb0da63ea4373dc8a"
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.49"
|
||||
name = "termcolor"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4"
|
||||
checksum = "ff1bc3d3f05aff0403e8ac0d92ced918ec05b666a43f83297ccef5bea8a3d449"
|
||||
dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.50"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.49"
|
||||
version = "1.0.50"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc"
|
||||
checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@ -953,6 +1074,15 @@ version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-util"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
|
@ -12,3 +12,6 @@ glib = "0.18.3"
|
||||
clap = { version = "4.4.6", features = ["derive"] }
|
||||
gtk = { version = "0.7.3", package = "gtk4", features = ["v4_8"] }
|
||||
async-channel = "2.1.0"
|
||||
anyhow = "1.0.75"
|
||||
log = "0.4.20"
|
||||
env_logger = "0.10.1"
|
||||
|
17
src/cache.rs
17
src/cache.rs
@ -1,5 +1,6 @@
|
||||
use glib::timeout_future;
|
||||
use gtk::gdk::Texture;
|
||||
use log::debug;
|
||||
use poppler::Document;
|
||||
use std::{
|
||||
collections::BTreeMap,
|
||||
@ -34,7 +35,7 @@ impl PageCache {
|
||||
}
|
||||
|
||||
pub fn cache_pages(&mut self, page_numbers: Vec<usize>, area_height: i32) {
|
||||
println!("Caching pages {:?}", page_numbers);
|
||||
debug!("Caching pages {:?}", page_numbers);
|
||||
let begin_of_cashing = Instant::now();
|
||||
for page_number in page_numbers {
|
||||
if self.pages.contains_key(&page_number) {
|
||||
@ -52,7 +53,7 @@ impl PageCache {
|
||||
}
|
||||
}
|
||||
}
|
||||
println!(
|
||||
debug!(
|
||||
"done caching in {}ms",
|
||||
begin_of_cashing.elapsed().as_millis()
|
||||
);
|
||||
@ -74,7 +75,7 @@ impl PageCache {
|
||||
}
|
||||
|
||||
fn process_command(&mut self, command: CacheCommand) -> Option<CacheResponse> {
|
||||
println!("Processing command: {:?}...", command);
|
||||
debug!("Processing command: {:?}...", command);
|
||||
match command {
|
||||
CacheCommand::CachePages { pages, area_height } => {
|
||||
self.cache_pages(pages, area_height);
|
||||
@ -82,9 +83,9 @@ impl PageCache {
|
||||
}
|
||||
CacheCommand::GetCurrentTwoPages { page_left_number } => {
|
||||
if let Some(page_left) = self.get_page(page_left_number) {
|
||||
println!("got left page");
|
||||
debug!("got left page");
|
||||
if let Some(page_right) = self.get_page(page_left_number + 1) {
|
||||
println!("got right page");
|
||||
debug!("got right page");
|
||||
Some(CacheResponse::TwoPagesRetrieved {
|
||||
page_left,
|
||||
page_right,
|
||||
@ -93,7 +94,7 @@ impl PageCache {
|
||||
Some(CacheResponse::SinglePageRetrieved { page: page_left })
|
||||
}
|
||||
} else {
|
||||
println!("did not get any page");
|
||||
debug!("did not get any page");
|
||||
// TODO: if page left was not empty, this could be because page turning was too quick.
|
||||
// In this case, just not rendering the current page is okay, but when no more render requests are available, one would want to wait for the caching
|
||||
None
|
||||
@ -136,9 +137,9 @@ where
|
||||
while let Ok(command) = command_receiver.recv().await {
|
||||
if let Some(response) = cache.process_command(command) {
|
||||
// response_sender.send_blocking(response).unwrap();
|
||||
println!("Command processed, activating receiver....");
|
||||
debug!("Command processed, activating receiver....");
|
||||
receiver(response);
|
||||
println!("receiver done");
|
||||
debug!("receiver done");
|
||||
}
|
||||
|
||||
// Add delay to tell gtk to give rendering priority
|
||||
|
@ -3,6 +3,7 @@ use std::rc::Rc;
|
||||
use cairo::{Context, ImageSurface};
|
||||
use glib::Bytes;
|
||||
use gtk::gdk::Texture;
|
||||
use log::debug;
|
||||
use poppler::Page;
|
||||
|
||||
pub fn draw_pages_to_texture(pages: &[Rc<Page>], area_height: i32) -> Texture {
|
||||
@ -52,7 +53,7 @@ fn draw_pages(pages: &[Rc<Page>], context: &Context, area_width: i32, area_heigh
|
||||
let scale = height_to_scale_to / page_height;
|
||||
let scaled_width = page_width * scale;
|
||||
|
||||
println!(
|
||||
debug!(
|
||||
"drawing with size: {}, {}",
|
||||
scaled_width, height_to_scale_to
|
||||
);
|
||||
|
@ -3,8 +3,10 @@ mod draw;
|
||||
mod ui;
|
||||
|
||||
use clap::Parser;
|
||||
use env_logger::Env;
|
||||
use gtk::prelude::*;
|
||||
use gtk::Application;
|
||||
use log::debug;
|
||||
use std::cell::RefCell;
|
||||
use std::path::PathBuf;
|
||||
use std::rc::Rc;
|
||||
@ -19,8 +21,9 @@ struct Cli {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
env_logger::Builder::from_env(Env::default().default_filter_or("debug")).init();
|
||||
let cli = Cli::parse();
|
||||
println!("Parse args");
|
||||
debug!("Parse args");
|
||||
let app = Application::builder().application_id(APP_ID).build();
|
||||
|
||||
app.connect_activate(move |app| {
|
||||
|
11
src/ui.rs
11
src/ui.rs
@ -9,6 +9,7 @@ use gtk::{
|
||||
glib, Application, ApplicationWindow, Box, Button, FileChooserAction, FileChooserDialog,
|
||||
HeaderBar, Label, Orientation, Picture, ResponseType,
|
||||
};
|
||||
use log::debug;
|
||||
|
||||
use crate::cache::{self, CacheCommand};
|
||||
use glib::clone;
|
||||
@ -62,7 +63,7 @@ impl DocumentCanvas {
|
||||
}
|
||||
|
||||
pub fn cache_surrounding_pages(&self, area_height: i32) {
|
||||
println!("Send cache request");
|
||||
debug!("Send cache request");
|
||||
self.page_cache_sender
|
||||
.send_blocking(CacheCommand::CachePages {
|
||||
pages: vec![
|
||||
@ -164,7 +165,7 @@ fn process_left_click(ui: &mut Ui, x: f64, y: f64) {
|
||||
|
||||
impl Ui {
|
||||
pub fn build(app: &Application) -> Rc<RefCell<Ui>> {
|
||||
println!("building ui");
|
||||
debug!("building ui");
|
||||
let open_file_button = Button::from_icon_name("document-open");
|
||||
|
||||
let app_wrapper = Box::builder().orientation(Orientation::Vertical).build();
|
||||
@ -268,7 +269,7 @@ fn choose_file(ui: Rc<RefCell<Ui>>, window: &ApplicationWindow) {
|
||||
}
|
||||
|
||||
pub fn load_document(file: impl AsRef<Path>, ui: Rc<RefCell<Ui>>) {
|
||||
println!("Loading file...");
|
||||
debug!("Loading file...");
|
||||
// TODO: catch errors, maybe show error dialog
|
||||
let path: PathBuf = file.as_ref().to_path_buf();
|
||||
let uri = format!("file://{}", path.to_str().unwrap());
|
||||
@ -293,7 +294,7 @@ pub fn load_document(file: impl AsRef<Path>, ui: Rc<RefCell<Ui>>) {
|
||||
ui.borrow_mut().image_right.set_visible(true);
|
||||
let area_height = ui.borrow().image_left.height();
|
||||
ui.borrow().document_canvas.as_ref().unwrap().cache_surrounding_pages(area_height);
|
||||
println!("Image size: {}, {}", ui.borrow().image_left.width(), ui.borrow().image_left.height());
|
||||
debug!("Image size: {}, {}", ui.borrow().image_left.width(), ui.borrow().image_left.height());
|
||||
}
|
||||
}),
|
||||
);
|
||||
@ -305,5 +306,5 @@ pub fn load_document(file: impl AsRef<Path>, ui: Rc<RefCell<Ui>>) {
|
||||
ui.borrow_mut().document_canvas = Some(document_canvas);
|
||||
|
||||
update_page_status(&ui.borrow());
|
||||
println!("finished loading document");
|
||||
debug!("finished loading document");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user