-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
use crossterm::event::KeyCode; | ||
use ratatui::{prelude::*, Frame}; | ||
use rm_shared::{ | ||
action::{Action, UpdateAction}, | ||
status_task::StatusTask, | ||
}; | ||
use transmission_rpc::types::Id; | ||
|
||
use crate::{ | ||
transmission::TorrentAction, | ||
tui::{ | ||
app, | ||
components::{Component, ComponentAction, InputManager}, | ||
}, | ||
}; | ||
|
||
pub struct Rename { | ||
id: Id, | ||
curr_name: String, | ||
input_mgr: InputManager, | ||
ctx: app::Ctx, | ||
} | ||
|
||
impl Rename { | ||
pub fn new(ctx: app::Ctx, to_rename: Id, curr_name: String) -> Self { | ||
let prompt = String::from("New name: "); | ||
|
||
Self { | ||
id: to_rename, | ||
ctx, | ||
input_mgr: InputManager::new_with_value(prompt, curr_name.clone()), | ||
curr_name, | ||
} | ||
} | ||
|
||
fn rename(&self) { | ||
let new_name = self.input_mgr.text(); | ||
|
||
if self.curr_name == new_name { | ||
return; | ||
} | ||
|
||
let task = StatusTask::new_rename(self.curr_name.clone()); | ||
|
||
self.ctx | ||
.send_update_action(UpdateAction::StatusTaskSet(task)); | ||
self.ctx.send_torrent_action(TorrentAction::Rename( | ||
self.id.clone(), | ||
self.curr_name.clone(), | ||
self.input_mgr.text(), | ||
)) | ||
} | ||
} | ||
|
||
impl Component for Rename { | ||
fn handle_actions(&mut self, action: Action) -> crate::tui::components::ComponentAction { | ||
match action { | ||
Action::Input(input) => { | ||
if input.code == KeyCode::Esc { | ||
return ComponentAction::Quit; | ||
} else if input.code == KeyCode::Enter { | ||
self.rename(); | ||
return ComponentAction::Quit; | ||
} | ||
|
||
if self.input_mgr.handle_key(input).is_some() { | ||
self.ctx.send_action(Action::Render); | ||
} | ||
|
||
ComponentAction::Nothing | ||
} | ||
|
||
_ => ComponentAction::Nothing, | ||
} | ||
} | ||
|
||
fn render(&mut self, f: &mut Frame, rect: Rect) { | ||
self.input_mgr.render(f, rect) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters