bin: Update usage of text view state

This commit is contained in:
Erik Kundt
2025-01-16 00:10:02 +01:00
parent 63c46842fc
commit 976346c4bc
2 changed files with 26 additions and 26 deletions
+13 -13
View File
@@ -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<Tui> 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<Message<'a>>, frame: &mut Frame) {
fn show_hunk_list(&self, ui: &mut Ui<Message>, 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<Message<'a>>, frame: &mut Frame) {
fn show_hunk(&self, ui: &mut Ui<Message>, 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<Message<'a>>, frame: &mut Frame) {
fn show_context_bar(&self, ui: &mut Ui<Message>, 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<Message<'a>> for App<'a> {
fn show(&self, ctx: &Context<Message<'a>>, frame: &mut Frame) -> Result<(), anyhow::Error> {
impl<'a> Show<Message> for App<'a> {
fn show(&self, ctx: &Context<Message>, 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<Message<'a>> 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<Message<'a>> for App<'a> {
}
}
impl<'a> store::Update<Message<'a>> for App<'a> {
impl<'a> store::Update<Message> for App<'a> {
type Return = Selection;
fn update(&mut self, message: Message<'a>) -> Option<Exit<Self::Return>> {
fn update(&mut self, message: Message) -> Option<Exit<Self::Return>> {
log::info!("Received message: {:?}", message);
match message {
+13 -13
View File
@@ -49,7 +49,7 @@ Pattern: is:<state> | is:authored | authors:[<did>, <did>] | <search>
Example: is:open is:authored improve"#;
#[derive(Clone, Debug)]
pub enum Message<'a> {
pub enum Message {
Quit,
Exit {
operation: Option<PatchOperation>,
@@ -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<TextEditState>,
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<Self, Self::Error> {
@@ -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<Message<'a>> for App<'a> {
impl store::Update<Message> for App {
type Return = Selection;
fn update(&mut self, message: Message<'a>) -> Option<tui::Exit<Selection>> {
fn update(&mut self, message: Message) -> Option<tui::Exit<Selection>> {
log::debug!("[State] Received message: {:?}", message);
match message {
@@ -214,7 +214,7 @@ impl<'a> store::Update<Message<'a>> for App<'a> {
}
}
impl<'a> Show<Message<'a>> for App<'a> {
impl Show<Message> for App {
fn show(&self, ctx: &im::Context<Message>, frame: &mut Frame) -> Result<()> {
Window::default().show(ctx, |ui| {
match self.page {
@@ -328,13 +328,13 @@ impl<'a> Show<Message<'a>> 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<Message<'a>> for App<'a> {
}
}
impl<'a> App<'a> {
impl App {
pub fn show_patches(&self, frame: &mut Frame, ui: &mut im::Ui<Message>) {
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