use crate::ported::lib::threaded::MultiRunnedThread;
pub fn read_to_log(_pl: &(), client: std::process::Output) {
for line in String::from_utf8_lossy(&client.stdout).lines() {
if !line.is_empty() {
eprintln!("awesome-client: {}", line);
}
}
for line in String::from_utf8_lossy(&client.stderr).lines() {
if !line.is_empty() {
eprintln!("awesome-client: {}", line);
}
}
if !client.status.success() {
eprintln!("awesome-client: exited {}", client.status);
}
}
pub fn run() {
eprintln!(
"powerliners: bindings::wm::awesome::run() — Powerline class not yet ported; \
awesome WM integration disabled until Phase 2 lands"
);
}
pub struct AwesomeThread {
pub thread: MultiRunnedThread,
}
impl Default for AwesomeThread {
fn default() -> Self {
Self::new()
}
}
impl AwesomeThread {
pub fn new() -> Self {
Self {
thread: MultiRunnedThread::new(),
}
}
pub fn start(&self) {
self.thread.start_with(|_event| {
run();
});
}
pub fn join(&self) {
self.thread.join();
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn awesome_thread_starts_and_joins() {
let t = AwesomeThread::new();
t.start();
t.join();
}
#[test]
fn read_to_log_does_not_panic_on_success() {
let out = std::process::Output {
status: std::process::Command::new("true")
.status()
.unwrap_or_else(|_| {
#[cfg(unix)]
{
use std::os::unix::process::ExitStatusExt;
std::process::ExitStatus::from_raw(0)
}
#[cfg(not(unix))]
{
std::process::Command::new("cmd")
.arg("/c")
.arg("exit 0")
.status()
.unwrap()
}
}),
stdout: b"hello\nworld\n".to_vec(),
stderr: Vec::new(),
};
read_to_log(&(), out);
}
}