use std::fmt;
use crate::commands::Command;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PlaybackState {
Playing,
Paused,
Stopped,
Loading,
}
impl fmt::Display for PlaybackState {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
PlaybackState::Playing => write!(f, "Playing"),
PlaybackState::Paused => write!(f, "Paused"),
PlaybackState::Stopped => write!(f, "Stopped"),
PlaybackState::Loading => write!(f, "Loading"),
}
}
}
#[derive(Debug, Clone)]
pub struct MediaInfo {
pub title: Option<String>,
pub duration: Option<f64>,
pub position: f64,
pub volume: f64,
pub muted: bool,
pub speed: f64,
pub filename: String,
pub path: String,
pub loop_enabled: bool,
}
impl Default for MediaInfo {
fn default() -> Self {
Self {
title: None,
duration: None,
position: 0.0,
volume: 100.0,
muted: false,
speed: 1.0,
filename: String::new(),
path: String::new(),
loop_enabled: false,
}
}
}
#[derive(Debug, Clone)]
pub struct PlayerState {
pub state: PlaybackState,
pub media_info: MediaInfo,
pub fullscreen: bool,
pub error_message: Option<String>,
pub connection_status: ConnectionStatus,
}
#[derive(Debug, Clone)]
pub struct ConnectionStatus {
pub connected: bool,
pub host: String,
pub port: u16,
pub password_set: bool,
pub password: String,
pub last_error: Option<String>,
}
impl Default for PlayerState {
fn default() -> Self {
Self {
state: PlaybackState::Stopped,
media_info: MediaInfo::default(),
fullscreen: false,
error_message: None,
connection_status: ConnectionStatus::default(),
}
}
}
impl Default for ConnectionStatus {
fn default() -> Self {
Self {
connected: false,
host: "127.0.0.1".to_string(),
port: 8080,
password_set: false,
password: String::new(),
last_error: None,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum MediaSource {
LocalFile(String),
Url(String),
}
impl fmt::Display for MediaSource {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
MediaSource::LocalFile(path) => write!(f, "File: {}", path),
MediaSource::Url(url) => write!(f, "URL: {}", url),
}
}
}
#[derive(Debug, Clone)]
pub enum TuiMode {
Normal,
Input,
Command,
Help,
Config,
YoutubeSearch,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct LogEntry {
pub level: String,
pub message: String,
}
#[derive(Clone)]
pub struct TuiLogger {
sender: std::sync::mpsc::Sender<Command>,
}
impl TuiLogger {
pub fn new(sender: std::sync::mpsc::Sender<Command>) -> Self {
Self { sender }
}
pub fn info(&self, message: &str) {
let _ = self.sender.send(Command::Log(LogEntry {
level: "INFO".to_string(),
message: message.to_string(),
}));
}
pub fn warn(&self, message: &str) {
let _ = self.sender.send(Command::Log(LogEntry {
level: "WARN".to_string(),
message: message.to_string(),
}));
}
pub fn error(&self, message: &str) {
let _ = self.sender.send(Command::Log(LogEntry {
level: "ERROR".to_string(),
message: message.to_string(),
}));
}
pub fn debug(&self, message: &str) {
let _ = self.sender.send(Command::Log(LogEntry {
level: "DEBUG".to_string(),
message: message.to_string(),
}));
}
}