Skip to content

Commit

Permalink
Add changelod entry, fix rust format
Browse files Browse the repository at this point in the history
  • Loading branch information
JomerDev committed Jul 10, 2024
1 parent e658a6c commit b6a2429
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- [#843]: `defmt`: Sort IDs of log msgs by severity to allow runtime filtering by severity
- [#822]: `CI`: Run `cargo semver-checks` on every PR
- [#855]: `defmt-print`: Now uses tokio to make tcp and stdin reads async (in preparation for a `watch elf` flag)
- [#807]: `defmt-print`: Add watch_elf flag to allow elf reload without restarting `defmt-print`

[#852]: https://github.com/knurling-rs/defmt/pull/852
[#847]: https://github.com/knurling-rs/defmt/pull/847
[#845]: https://github.com/knurling-rs/defmt/pull/845
[#843]: https://github.com/knurling-rs/defmt/pull/843
[#822]: https://github.com/knurling-rs/defmt/pull/822
[#855]: https://github.com/knurling-rs/defmt/pull/855
[#807]: https://github.com/knurling-rs/defmt/pull/807

## [v0.3.8] - 2024-05-17

Expand Down
27 changes: 12 additions & 15 deletions print/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::{
env,
path::{Path, PathBuf}, time::Duration,
path::{Path, PathBuf},
};

use notify::{Config, Event, RecommendedWatcher, RecursiveMode, Watcher};
use anyhow::anyhow;
use clap::{Parser, Subcommand};
use defmt_decoder::{
Expand All @@ -13,11 +12,14 @@ use defmt_decoder::{
},
DecodeError, Frame, Locations, Table, DEFMT_VERSIONS,
};
use notify::{Config, Event, RecommendedWatcher, RecursiveMode, Watcher};

use tokio::{
fs,
io::{self, AsyncReadExt, Stdin},
net::TcpStream, select, sync::mpsc::Receiver,
net::TcpStream,
select,
sync::mpsc::Receiver,
};

/// Prints defmt-encoded logs to stdout
Expand Down Expand Up @@ -98,7 +100,7 @@ const READ_BUFFER_SIZE: usize = 1024;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
let opts = Opts::parse();
let opts = Opts::parse();

if opts.version {
return print_version();
Expand All @@ -119,7 +121,7 @@ async fn main() -> anyhow::Result<()> {
tx.send(res).await.unwrap();
})
},
Config::default().with_poll_interval(Duration::from_secs(1))
Config::default(),
)?;
let mut directory_path = opts.elf.clone().unwrap();
directory_path.pop(); // We want the elf directory instead of the elf, since some editors remove and recreate the file on save which will remove the notifier
Expand All @@ -129,37 +131,32 @@ async fn main() -> anyhow::Result<()> {

loop {
select! {
r = run(opts.clone(), &mut source) => {
if r.is_err() {
return r;
}
},
r = run(opts.clone(), &mut source) => r?,
_ = has_file_changed(&mut rx, &path) => ()
}
}
} else {
run(opts, &mut source).await
}

}

async fn has_file_changed(rx: &mut Receiver<Result<Event, notify::Error>>, path: &PathBuf) -> bool {
loop {
if let Some(Ok(event)) = rx.recv().await {
if event.paths.contains(path) {
match event.kind {
notify::EventKind::Create(_) | notify::EventKind::Modify(_) => {
notify::EventKind::Create(_) | notify::EventKind::Modify(_) => {
break;
},
_ => ()
}
_ => (),
}
}
}
}
true
}

async fn run(opts: Opts, source: &mut Source) -> anyhow::Result<()> {
async fn run(opts: Opts, source: &mut Source) -> anyhow::Result<()> {
let Opts {
elf,
json,
Expand Down

0 comments on commit b6a2429

Please sign in to comment.