Test interface with command runner

master
Joey Pollack 2 years ago
parent 044265dc51
commit e3ec07ca47

Binary file not shown.

Before

Width:  |  Height:  |  Size: 131 B

After

Width:  |  Height:  |  Size: 257 KiB

@ -1,4 +1,5 @@
use std::{process::Command, str};
use eframe::egui; use eframe::egui;
fn main() -> Result<(), eframe::Error> fn main() -> Result<(), eframe::Error>
@ -22,8 +23,8 @@ fn main() -> Result<(), eframe::Error>
struct JpmmvApp struct JpmmvApp
{ {
name: String, command: String,
age: u32, result: String,
} }
impl Default for JpmmvApp impl Default for JpmmvApp
@ -31,8 +32,8 @@ impl Default for JpmmvApp
fn default() -> Self fn default() -> Self
{ {
Self { Self {
name: "Arthur".to_owned(), command: "command".to_string(),
age: 42, result: "N/A".to_string()
} }
} }
} }
@ -43,17 +44,15 @@ impl eframe::App for JpmmvApp
{ {
egui::CentralPanel::default().show(ctx, |ui| egui::CentralPanel::default().show(ctx, |ui|
{ {
ui.heading("My egui Application"); ui.heading("Media Meta Viewer");
ui.horizontal(|ui| { ui.text_edit_singleline(&mut self.command);
let name_label = ui.label("Your name: ");
ui.text_edit_singleline(&mut self.name) if ui.button("Run Command").clicked()
.labelled_by(name_label.id); {
}); self.result = run_command(&format!("playerctl --player=strawberry {}", self.command))
ui.add(egui::Slider::new(&mut self.age, 0..=120).text("age"));
if ui.button("Increment").clicked() {
self.age += 1;
} }
ui.label(format!("Hello '{}', age {}", self.name, self.age));
ui.label(format!("Command result: {}", self.result));
ui.image(egui::include_image!( ui.image(egui::include_image!(
"../assets/Music Note.png" "../assets/Music Note.png"
@ -61,3 +60,5 @@ impl eframe::App for JpmmvApp
}); });
} }
} }

@ -0,0 +1,37 @@
pub struct SongMetadata
{
pub name: String,
pub artist: String,
pub album: String,
}
impl SongMetadata
{
fn new() -> SongMetadata
{
SongMetadata {
name: "NONE".to_string(),
artist: "NONE".to_string(),
album: "NONE".to_string(),
}
}
}
pub fn get_song_metadata() -> SongMetadata
{
const COM_START: String = "playerctl --player=strawberry ";
}
fn run_command(command: &str) -> String
{
let output = Command::new("sh")
.arg("-c")
.arg(command)
.output()
.expect("Failed to run the command");
str::from_utf8(&output.stdout).expect("Failed to convert command result to utf8 string").to_string()
}
Loading…
Cancel
Save