Skip to content

Commit

Permalink
Add option to set window title to "spt - Spotify TUI" on startup (Rig…
Browse files Browse the repository at this point in the history
  • Loading branch information
diegov authored Oct 1, 2021
1 parent 04de853 commit 93fd30f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ behavior:
repeat_context_icon: 🔁
playing_icon:
paused_icon:
# Sets the window title to "spt - Spotify TUI" via ANSI escape code.
set_window_title: true

keybindings:
# Key stroke can be used if it only uses two keys:
Expand Down
11 changes: 9 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ use crossterm::{
event::{DisableMouseCapture, EnableMouseCapture},
execute,
style::Print,
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
terminal::{
disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen, SetTitle,
},
ExecutableCommand,
};
use network::{get_spotify, IoEvent, Network};
Expand Down Expand Up @@ -268,7 +270,12 @@ async fn start_ui(user_config: UserConfig, app: &Arc<Mutex<App>>) -> Result<()>
execute!(stdout, EnterAlternateScreen, EnableMouseCapture)?;
enable_raw_mode()?;

let backend = CrosstermBackend::new(stdout);
let mut backend = CrosstermBackend::new(stdout);

if user_config.behavior.set_window_title {
backend.execute(SetTitle("spt - Spotify TUI"))?;
}

let mut terminal = Terminal::new(backend)?;
terminal.hide_cursor()?;

Expand Down
7 changes: 7 additions & 0 deletions src/user_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ pub struct BehaviorConfigString {
pub repeat_context_icon: Option<String>,
pub playing_icon: Option<String>,
pub paused_icon: Option<String>,
pub set_window_title: Option<bool>,
}

#[derive(Clone)]
Expand All @@ -235,6 +236,7 @@ pub struct BehaviorConfig {
pub repeat_context_icon: String,
pub playing_icon: String,
pub paused_icon: String,
pub set_window_title: bool,
}

#[derive(Default, Clone, Debug, PartialEq, Serialize, Deserialize)]
Expand Down Expand Up @@ -297,6 +299,7 @@ impl UserConfig {
repeat_context_icon: "🔁".to_string(),
playing_icon: "▶".to_string(),
paused_icon: "⏸".to_string(),
set_window_title: true,
},
path_to_config: None,
}
Expand Down Expand Up @@ -454,6 +457,10 @@ impl UserConfig {
self.behavior.repeat_context_icon = repeat_context_icon;
}

if let Some(set_window_title) = behavior_config.set_window_title {
self.behavior.set_window_title = set_window_title;
}

Ok(())
}

Expand Down

0 comments on commit 93fd30f

Please sign in to comment.