Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Formatting
  • Loading branch information
Peterwmoss committed Aug 27, 2020
commit c672d599a5664bb144c5362e109be037aa614ccc
43 changes: 22 additions & 21 deletions src/ui/audio_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use tui::{
backend::Backend,
layout::{Constraint, Direction, Layout},
style::Style,
widgets::{BarChart, Block, Borders, Paragraph},
text::{Span, Spans},
widgets::{BarChart, Block, Borders, Paragraph},
Frame,
};
const PITCHES: [&str; 12] = [
Expand All @@ -25,7 +25,10 @@ where
.split(f.size());

let analysis_block = Block::default()
.title(Span::styled("Analysis", Style::default().fg(app.user_config.theme.inactive)))
.title(Span::styled(
"Analysis",
Style::default().fg(app.user_config.theme.inactive),
))
.borders(Borders::ALL)
.border_style(Style::default().fg(app.user_config.theme.inactive));

Expand Down Expand Up @@ -73,25 +76,23 @@ where
.find(|section| section.start >= progress_seconds);

if let (Some(segment), Some(section)) = (segment, section) {
let texts = vec![
Spans::from(vec![
Span::raw(format!(
"Tempo: {} (confidence {:.0}%)\n",
section.tempo,
section.tempo_confidence * 100.0
)),
Span::raw(format!(
"Key: {} (confidence {:.0}%)\n",
PITCHES.get(section.key as usize).unwrap_or(&PITCHES[0]),
section.key_confidence * 100.0
)),
Span::raw(format!(
"Time Signature: {}/4 (confidence {:.0}%)\n",
section.time_signature,
section.time_signature_confidence * 100.0
)),
])
];
let texts = vec![Spans::from(vec![
Span::raw(format!(
"Tempo: {} (confidence {:.0}%)\n",
section.tempo,
section.tempo_confidence * 100.0
)),
Span::raw(format!(
"Key: {} (confidence {:.0}%)\n",
PITCHES.get(section.key as usize).unwrap_or(&PITCHES[0]),
section.key_confidence * 100.0
)),
Span::raw(format!(
"Time Signature: {}/4 (confidence {:.0}%)\n",
section.time_signature,
section.time_signature_confidence * 100.0
)),
])];
let p = Paragraph::new(texts)
.block(analysis_block)
.style(Style::default().fg(app.user_config.theme.text));
Expand Down
127 changes: 90 additions & 37 deletions src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use tui::{
backend::Backend,
layout::{Alignment, Constraint, Direction, Layout, Rect},
style::{Modifier, Style},
text::{Span, Spans, Text},
widgets::{Block, Borders, Clear, Gauge, List, ListItem, ListState, Paragraph, Row, Table, Wrap},
text::{Text, Spans, Span},
Frame,
};
use util::{
Expand Down Expand Up @@ -129,7 +129,10 @@ where
let input = Paragraph::new(lines).block(
Block::default()
.borders(Borders::ALL)
.title(Span::styled("Search", get_color(highlight_state, app.user_config.theme)))
.title(Span::styled(
"Search",
get_color(highlight_state, app.user_config.theme),
))
.border_style(get_color(highlight_state, app.user_config.theme)),
);
f.render_widget(input, chunks[0]);
Expand Down Expand Up @@ -768,7 +771,14 @@ where
{
let chunks = Layout::default()
.direction(Direction::Vertical)
.constraints([Constraint::Percentage(50), Constraint::Percentage(25), Constraint::Percentage(25)].as_ref())
.constraints(
[
Constraint::Percentage(50),
Constraint::Percentage(25),
Constraint::Percentage(25),
]
.as_ref(),
)
.margin(1)
.split(layout_chunk);

Expand Down Expand Up @@ -811,7 +821,10 @@ where

let title_block = Block::default()
.borders(Borders::ALL)
.title(Span::styled(&title, get_color(highlight_state, app.user_config.theme)))
.title(Span::styled(
&title,
get_color(highlight_state, app.user_config.theme),
))
.border_style(get_color(highlight_state, app.user_config.theme));

f.render_widget(title_block, layout_chunk);
Expand Down Expand Up @@ -840,12 +853,16 @@ where
PlayingItem::Episode(episode) => format!("{} - {}", episode.name, episode.show.name),
};

let lines = Text::from(Span::styled(play_bar_text, Style::default().fg(app.user_config.theme.playbar_text)));
let lines = Text::from(Span::styled(
play_bar_text,
Style::default().fg(app.user_config.theme.playbar_text),
));

let artist = Paragraph::new(lines)
.style(Style::default().fg(app.user_config.theme.playbar_text))
.block(
Block::default().title(Span::styled(&track_name,
Block::default().title(Span::styled(
&track_name,
Style::default()
.fg(app.user_config.theme.selected)
.add_modifier(Modifier::BOLD),
Expand All @@ -856,15 +873,17 @@ where

let song_progress_label = display_track_progress(app.song_progress_ms, duration_ms);
let song_progress = Gauge::default()
.gauge_style(
Style::default()
.fg(app.user_config.theme.playbar_progress)
.bg(app.user_config.theme.playbar_background)
.add_modifier(Modifier::ITALIC | Modifier::BOLD))
.percent(perc)
.label(Span::styled(&song_progress_label,
Style::default()
.fg(app.user_config.theme.playbar_progress_text)));
.gauge_style(
Style::default()
.fg(app.user_config.theme.playbar_progress)
.bg(app.user_config.theme.playbar_background)
.add_modifier(Modifier::ITALIC | Modifier::BOLD),
)
.percent(perc)
.label(Span::styled(
&song_progress_label,
Style::default().fg(app.user_config.theme.playbar_progress_text),
));
f.render_widget(song_progress, chunks[2]);
}
}
Expand Down Expand Up @@ -909,7 +928,10 @@ Hint: a playback device must be either an official spotify client or a light wei
.block(
Block::default()
.borders(Borders::ALL)
.title(Span::styled("Error", Style::default().fg(app.user_config.theme.error_border)))
.title(Span::styled(
"Error",
Style::default().fg(app.user_config.theme.error_border),
))
.border_style(Style::default().fg(app.user_config.theme.error_border)),
);
f.render_widget(playing_paragraph, chunks[0]);
Expand All @@ -932,7 +954,10 @@ where
);

let welcome = Block::default()
.title(Span::styled("Welcome!", get_color(highlight_state, app.user_config.theme)))
.title(Span::styled(
"Welcome!",
get_color(highlight_state, app.user_config.theme),
))
.borders(Borders::ALL)
.border_style(get_color(highlight_state, app.user_config.theme));
f.render_widget(welcome, layout_chunk);
Expand All @@ -951,7 +976,11 @@ where
let mut top_text = Text::from(BANNER);
top_text.patch_style(Style::default().fg(app.user_config.theme.banner));

let bottom_text_raw = format!("{}{}", "\nPlease report any bugs or missing features to https://github.com/Rigellute/spotify-tui\n\n", clean_changelog);
let bottom_text_raw = format!(
"{}{}",
"\nPlease report any bugs or missing features to https://github.com/Rigellute/spotify-tui\n\n",
clean_changelog
);
let bottom_text = Text::from(bottom_text_raw.as_str());

// Contains the banner
Expand Down Expand Up @@ -984,7 +1013,10 @@ fn draw_not_implemented_yet<B>(
current_route.hovered_block == block,
);
let display_block = Block::default()
.title(Span::styled(title, get_color(highlight_state, app.user_config.theme)))
.title(Span::styled(
title,
get_color(highlight_state, app.user_config.theme),
))
.borders(Borders::ALL)
.border_style(get_color(highlight_state, app.user_config.theme));

Expand Down Expand Up @@ -1121,24 +1153,27 @@ where
.style(Style::default().fg(app.user_config.theme.text))
.wrap(Wrap { trim: true })
.block(
Block::default()
.borders(Borders::NONE)
.title(Span::styled("Welcome to spotify-tui!",
Style::default()
.fg(app.user_config.theme.active)
.add_modifier(Modifier::BOLD)
)
));
Block::default().borders(Borders::NONE).title(Span::styled(
"Welcome to spotify-tui!",
Style::default()
.fg(app.user_config.theme.active)
.add_modifier(Modifier::BOLD),
)),
);
f.render_widget(instructions, chunks[0]);

let no_device_message = Span::raw("No devices found: Make sure a device is active");

let items = match &app.devices {
Some(items) => {
Some(items) => {
if items.devices.is_empty() {
vec![ListItem::new(no_device_message)]
vec![ListItem::new(no_device_message)]
} else {
items.devices.iter().map(|device| ListItem::new(Span::raw(&device.name))).collect()
items
.devices
.iter()
.map(|device| ListItem::new(Span::raw(&device.name)))
.collect()
}
}
None => vec![ListItem::new(no_device_message)],
Expand All @@ -1149,7 +1184,10 @@ where
let list = List::new(items)
.block(
Block::default()
.title(Span::styled("Devices", Style::default().fg(app.user_config.theme.active)))
.title(Span::styled(
"Devices",
Style::default().fg(app.user_config.theme.active),
))
.borders(Borders::ALL)
.border_style(Style::default().fg(app.user_config.theme.inactive)),
)
Expand Down Expand Up @@ -1345,18 +1383,26 @@ fn draw_selectable_list<B, S>(
let mut state = ListState::default();
state.select(selected_index);

let lst_items : Vec<ListItem<>> = items.iter().map(|i| ListItem::new(Span::raw(i.as_ref()))).collect();
let lst_items: Vec<ListItem> = items
.iter()
.map(|i| ListItem::new(Span::raw(i.as_ref())))
.collect();

//TODO
let list = List::new(lst_items)
.block(
Block::default()
.title(Span::styled(title, get_color(highlight_state, app.user_config.theme)))
.title(Span::styled(
title,
get_color(highlight_state, app.user_config.theme),
))
.borders(Borders::ALL)
.border_style(get_color(highlight_state, app.user_config.theme)),
)
.style(Style::default().fg(app.user_config.theme.text))
.highlight_style(get_color(highlight_state, app.user_config.theme).add_modifier(Modifier::BOLD));
.highlight_style(
get_color(highlight_state, app.user_config.theme).add_modifier(Modifier::BOLD),
);
f.render_stateful_widget(list, layout_chunk, &mut state);
}

Expand Down Expand Up @@ -1393,7 +1439,10 @@ where
// app.dialog, but would have to introduce lifetime
let text = Spans::from(vec![
Span::raw("Are you sure you want to delete\nthe playlist: "),
Span::styled(playlist.as_str(), Style::default().add_modifier(Modifier::BOLD)),
Span::styled(
playlist.as_str(),
Style::default().add_modifier(Modifier::BOLD),
),
Span::raw("?"),
]);

Expand Down Expand Up @@ -1443,7 +1492,8 @@ fn draw_table<B>(
) where
B: Backend,
{
let selected_style = get_color(highlight_state, app.user_config.theme).add_modifier(Modifier::BOLD);
let selected_style =
get_color(highlight_state, app.user_config.theme).add_modifier(Modifier::BOLD);

let track_playing_index = app.current_playback_context.to_owned().and_then(|ctx| {
ctx.item.and_then(|item| match item {
Expand Down Expand Up @@ -1516,7 +1566,10 @@ fn draw_table<B>(
Block::default()
.borders(Borders::ALL)
.style(Style::default().fg(app.user_config.theme.text))
.title(Span::styled(title, get_color(highlight_state, app.user_config.theme)))
.title(Span::styled(
title,
get_color(highlight_state, app.user_config.theme),
))
.border_style(get_color(highlight_state, app.user_config.theme)),
)
.style(Style::default().fg(app.user_config.theme.text))
Expand Down