feat: switch between provider sessions without restarting
This commit is contained in:
+46
-38
@@ -294,11 +294,11 @@ impl Screen {
|
||||
}
|
||||
|
||||
// History owns the actual screens, so back/forward never has to refetch a catalog.
|
||||
struct Browser {
|
||||
pub(crate) struct Browser {
|
||||
options: Options,
|
||||
config_path: PathBuf,
|
||||
config: config::Config,
|
||||
state: State,
|
||||
pub(crate) state: State,
|
||||
screens: Vec<Screen>,
|
||||
index: usize,
|
||||
input: Option<String>,
|
||||
@@ -380,7 +380,12 @@ impl Picker {
|
||||
}
|
||||
|
||||
impl Browser {
|
||||
fn new(options: Options, config_path: PathBuf, config: config::Config, state: State) -> Self {
|
||||
pub(crate) fn new(
|
||||
options: Options,
|
||||
config_path: PathBuf,
|
||||
config: config::Config,
|
||||
state: State,
|
||||
) -> Self {
|
||||
let mut query = String::new();
|
||||
crate::paste_input(&mut query, options.query.as_deref().unwrap_or(""));
|
||||
let mut browser = Self {
|
||||
@@ -1279,6 +1284,7 @@ impl Browser {
|
||||
"Show series/episode info with cover art",
|
||||
),
|
||||
(Action::Help, "Keyboard help"),
|
||||
(Action::ProviderChoose, "Choose provider"),
|
||||
(Action::Quit, "Exit"),
|
||||
(Action::Interrupt, "Exit immediately"),
|
||||
];
|
||||
@@ -1437,6 +1443,7 @@ impl Browser {
|
||||
"NORMAL",
|
||||
&[
|
||||
(Action::Help, "help"),
|
||||
(Action::ProviderChoose, "provider"),
|
||||
(Action::VideoPlay, "play"),
|
||||
(Action::InfoOverview, "info"),
|
||||
(Action::WatchStatusWatching, "mark watching"),
|
||||
@@ -1453,6 +1460,7 @@ impl Browser {
|
||||
"NORMAL",
|
||||
&[
|
||||
(Action::Help, "help"),
|
||||
(Action::ProviderChoose, "provider"),
|
||||
(Action::SearchEdit, "search"),
|
||||
(
|
||||
Action::VideoPlay,
|
||||
@@ -2040,44 +2048,44 @@ fn media_details(media: &Media) -> String {
|
||||
text
|
||||
}
|
||||
|
||||
pub fn run(
|
||||
terminal: &mut DefaultTerminal,
|
||||
options: Options,
|
||||
config_path: PathBuf,
|
||||
config: config::Config,
|
||||
state: State,
|
||||
) -> io::Result<()> {
|
||||
struct RestoreTerminalInput;
|
||||
impl Drop for RestoreTerminalInput {
|
||||
fn drop(&mut self) {
|
||||
let _ = execute!(
|
||||
io::stdout(),
|
||||
DisableBracketedPaste,
|
||||
SetCursorStyle::DefaultUserShape
|
||||
);
|
||||
impl Browser {
|
||||
pub(crate) fn run(&mut self, terminal: &mut DefaultTerminal) -> io::Result<Option<bool>> {
|
||||
struct RestoreTerminalInput;
|
||||
impl Drop for RestoreTerminalInput {
|
||||
fn drop(&mut self) {
|
||||
let _ = execute!(
|
||||
io::stdout(),
|
||||
DisableBracketedPaste,
|
||||
SetCursorStyle::DefaultUserShape
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
let _restore = RestoreTerminalInput;
|
||||
execute!(
|
||||
io::stdout(),
|
||||
EnableBracketedPaste,
|
||||
SetCursorStyle::SteadyBlock
|
||||
)?;
|
||||
let mut browser = Browser::new(options, config_path, config, state);
|
||||
browser.thumbnail.query_terminal();
|
||||
let started = Instant::now();
|
||||
loop {
|
||||
browser.update();
|
||||
terminal.draw(|frame| browser.draw(frame, started.elapsed()))?;
|
||||
if event::poll(Duration::from_millis(100))? {
|
||||
match event::read()? {
|
||||
Event::Key(key) if key.kind != KeyEventKind::Release => {
|
||||
if browser.key(key) {
|
||||
return Ok(());
|
||||
let _restore = RestoreTerminalInput;
|
||||
execute!(
|
||||
io::stdout(),
|
||||
EnableBracketedPaste,
|
||||
SetCursorStyle::SteadyBlock
|
||||
)?;
|
||||
self.thumbnail.query_terminal();
|
||||
let started = Instant::now();
|
||||
loop {
|
||||
self.update();
|
||||
terminal.draw(|frame| self.draw(frame, started.elapsed()))?;
|
||||
if event::poll(Duration::from_millis(100))? {
|
||||
match event::read()? {
|
||||
Event::Key(key) if key.kind != KeyEventKind::Release => {
|
||||
if self.config.keys.resolve(self.context(), key)
|
||||
== Some(Action::ProviderChoose)
|
||||
{
|
||||
return crate::choose_provider(terminal, &self.config.keys, Some(true));
|
||||
}
|
||||
if self.key(key) {
|
||||
return Ok(None);
|
||||
}
|
||||
}
|
||||
Event::Paste(text) => self.paste(&text),
|
||||
_ => {}
|
||||
}
|
||||
Event::Paste(text) => browser.paste(&text),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user