From 976346c4bc2910dc2e8abec72d386f0570b47753 Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Thu, 16 Jan 2025 00:10:02 +0100 Subject: [PATCH] bin: Update usage of text view state --- bin/commands/patch/review.rs | 26 +++++++++++++------------- bin/commands/patch/select/imui.rs | 26 +++++++++++++------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/bin/commands/patch/review.rs b/bin/commands/patch/review.rs index caa10577..53f8faf2 100644 --- a/bin/commands/patch/review.rs +++ b/bin/commands/patch/review.rs @@ -112,13 +112,13 @@ impl Tui { } #[derive(Clone, Debug)] -pub enum Message<'a> { +pub enum Message { ShowMain, PanesChanged { state: PanesState }, HunkChanged { state: TableState }, HunkViewChanged { state: DiffViewState }, ShowHelp, - HelpChanged { state: TextViewState<'a> }, + HelpChanged { state: TextViewState }, Comment, Accept, Discard, @@ -200,7 +200,7 @@ pub struct App<'a> { /// State of panes widget on the main page. group: PanesState, /// State of text view widget on the help page. - help: TextViewState<'a>, + help: TextViewState, } impl<'a> TryFrom for App<'a> { @@ -258,7 +258,7 @@ impl<'a> App<'a> { ))), page: AppPage::Main, group: PanesState::new(2, Some(0)), - help: TextViewState::new(help_text(), Position::default()), + help: TextViewState::new(Position::default()), }; app.reload_states()?; @@ -361,7 +361,7 @@ impl<'a> App<'a> { } impl<'a> App<'a> { - fn show_hunk_list(&self, ui: &mut Ui>, frame: &mut Frame) { + fn show_hunk_list(&self, ui: &mut Ui, frame: &mut Frame) { let header = [Column::new(" Hunks ", Constraint::Fill(1))].to_vec(); let columns = [ Column::new("", Constraint::Length(2)), @@ -381,7 +381,7 @@ impl<'a> App<'a> { } } - fn show_hunk(&self, ui: &mut Ui>, frame: &mut Frame) { + fn show_hunk(&self, ui: &mut Ui, frame: &mut Frame) { let hunks = self.hunks.lock().unwrap(); let selected = hunks.selected(); @@ -414,7 +414,7 @@ impl<'a> App<'a> { } } - fn show_context_bar(&self, ui: &mut Ui>, frame: &mut Frame) { + fn show_context_bar(&self, ui: &mut Ui, frame: &mut Frame) { let hunks = &self.hunks.lock().unwrap().items; let id = format!(" {} ", format::cob(&self.patch)); @@ -470,8 +470,8 @@ impl<'a> App<'a> { } } -impl<'a> Show> for App<'a> { - fn show(&self, ctx: &Context>, frame: &mut Frame) -> Result<(), anyhow::Error> { +impl<'a> Show for App<'a> { + fn show(&self, ctx: &Context, frame: &mut Frame) -> Result<(), anyhow::Error> { Window::default().show(ctx, |ui| { let mut page_focus = self.group.focus(); @@ -525,13 +525,13 @@ impl<'a> Show> for App<'a> { ui.columns(frame, header, Some(Borders::Top)); let help = ui.text_view( frame, - self.help.text().to_string(), + help_text().to_string(), &mut cursor, Some(Borders::BottomSides), ); if help.changed { ui.send_message(Message::HelpChanged { - state: TextViewState::new(self.help.text().clone(), cursor), + state: TextViewState::new(cursor), }) } }); @@ -555,10 +555,10 @@ impl<'a> Show> for App<'a> { } } -impl<'a> store::Update> for App<'a> { +impl<'a> store::Update for App<'a> { type Return = Selection; - fn update(&mut self, message: Message<'a>) -> Option> { + fn update(&mut self, message: Message) -> Option> { log::info!("Received message: {:?}", message); match message { diff --git a/bin/commands/patch/select/imui.rs b/bin/commands/patch/select/imui.rs index 1541d82f..5adce56a 100644 --- a/bin/commands/patch/select/imui.rs +++ b/bin/commands/patch/select/imui.rs @@ -49,7 +49,7 @@ Pattern: is: | is:authored | authors:[, ] | Example: is:open is:authored improve"#; #[derive(Clone, Debug)] -pub enum Message<'a> { +pub enum Message { Quit, Exit { operation: Option, @@ -65,7 +65,7 @@ pub enum Message<'a> { page: Page, }, HelpChanged { - state: TextViewState<'a>, + state: TextViewState, }, ShowSearch, UpdateSearch { @@ -88,7 +88,7 @@ pub struct Storage { } #[derive(Clone, Debug)] -pub struct App<'a> { +pub struct App { storage: Storage, mode: Mode, page: Page, @@ -96,11 +96,11 @@ pub struct App<'a> { patches: TableState, search: BufferedValue, show_search: bool, - help: TextViewState<'a>, + help: TextViewState, filter: PatchItemFilter, } -impl<'a> TryFrom<&Context> for App<'a> { +impl TryFrom<&Context> for App { type Error = anyhow::Error; fn try_from(context: &Context) -> Result { @@ -132,16 +132,16 @@ impl<'a> TryFrom<&Context> for App<'a> { cursor: search.len(), }), show_search: false, - help: TextViewState::new(HELP, Position::default()), + help: TextViewState::new(Position::default()), filter, }) } } -impl<'a> store::Update> for App<'a> { +impl store::Update for App { type Return = Selection; - fn update(&mut self, message: Message<'a>) -> Option> { + fn update(&mut self, message: Message) -> Option> { log::debug!("[State] Received message: {:?}", message); match message { @@ -214,7 +214,7 @@ impl<'a> store::Update> for App<'a> { } } -impl<'a> Show> for App<'a> { +impl Show for App { fn show(&self, ctx: &im::Context, frame: &mut Frame) -> Result<()> { Window::default().show(ctx, |ui| { match self.page { @@ -328,13 +328,13 @@ impl<'a> Show> for App<'a> { let text_view = ui.text_view( frame, - self.help.text().to_string(), + HELP.to_string(), &mut cursor, Some(Borders::BottomSides), ); if text_view.changed { ui.send_message(Message::HelpChanged { - state: TextViewState::new(self.help.text().to_string(), cursor), + state: TextViewState::new(cursor), }) } @@ -380,7 +380,7 @@ impl<'a> Show> for App<'a> { } } -impl<'a> App<'a> { +impl App { pub fn show_patches(&self, frame: &mut Frame, ui: &mut im::Ui) { let patches = self .storage @@ -448,7 +448,7 @@ impl<'a> App<'a> { } } -impl<'a> App<'a> { +impl App { pub fn selected_patch(&self) -> Option<&PatchItem> { let patches = self .storage