bin: Adjust to new textarea

This commit is contained in:
Erik Kundt
2024-06-20 14:43:01 +02:00
parent cbb33f68c1
commit 35830ecbc0
3 changed files with 85 additions and 73 deletions
+28 -24
View File
@@ -26,7 +26,7 @@ use tui::store;
use tui::store::StateValue;
use tui::ui::span;
use tui::ui::widget::container::{Column, Container, Footer, FooterProps, Header, HeaderProps};
use tui::ui::widget::text::{TextArea, TextAreaProps};
use tui::ui::widget::input::{TextArea, TextAreaProps};
use tui::ui::widget::window::{Page, PageProps, Shortcuts, ShortcutsProps, Window, WindowProps};
use tui::ui::widget::{ToWidget, Widget};
use tui::{BoxedAny, Channel, Exit, PageStack};
@@ -83,6 +83,7 @@ impl BrowserState {
#[derive(Clone, Debug)]
pub struct HelpState {
scroll: usize,
cursor: (usize, usize),
}
#[derive(Clone, Debug)]
@@ -196,7 +197,10 @@ impl TryFrom<&Context> for State {
search,
show_search: false,
},
help: HelpState { scroll: 0 },
help: HelpState {
scroll: 0,
cursor: (0, 0),
},
})
}
}
@@ -219,6 +223,7 @@ pub enum Message {
LeavePage,
ScrollHelp {
scroll: usize,
cursor: (usize, usize),
},
}
@@ -273,8 +278,9 @@ impl store::State<Selection> for State {
self.pages.pop();
None
}
Message::ScrollHelp { scroll } => {
Message::ScrollHelp { scroll, cursor } => {
self.help.scroll = scroll;
self.help.cursor = cursor;
None
}
}
@@ -378,13 +384,13 @@ fn help_page(_state: &State, channel: &Channel<Message>) -> Widget<State, Messag
TextArea::default()
.to_widget(tx.clone())
.on_event(|_, s, _| {
Some(Message::ScrollHelp {
scroll: s.and_then(|p| p.unwrap_usize()).unwrap_or_default(),
})
let (scroll, cursor) = s.and_then(|p| p.unwrap_textarea()).unwrap_or_default();
Some(Message::ScrollHelp { scroll, cursor })
})
.on_update(|_| {
.on_update(|state: &State| {
TextAreaProps::default()
.text(&help_text())
.content(help_text())
.cursor(state.help.cursor)
.to_boxed_any()
.into()
}),
@@ -436,32 +442,32 @@ fn help_text() -> Text<'static> {
Line::raw(""),
Line::from(vec![
Span::raw(format!("{key:>10}", key = "↑,k")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("move cursor one line up").gray().dim(),
]),
Line::from(vec![
Span::raw(format!("{key:>10}", key = "↓,j")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("move cursor one line down").gray().dim(),
]),
Line::from(vec![
Span::raw(format!("{key:>10}", key = "PageUp")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("move cursor one page up").gray().dim(),
]),
Line::from(vec![
Span::raw(format!("{key:>10}", key = "PageDown")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("move cursor one page down").gray().dim(),
]),
Line::from(vec![
Span::raw(format!("{key:>10}", key = "Home")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("move cursor to the first line").gray().dim(),
]),
Line::from(vec![
Span::raw(format!("{key:>10}", key = "End")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("move cursor to the last line").gray().dim(),
]),
Line::raw(""),
@@ -469,32 +475,32 @@ fn help_text() -> Text<'static> {
Line::raw(""),
Line::from(vec![
Span::raw(format!("{key:>10}", key = "enter")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("Select notification (if --mode id)").gray().dim(),
]),
Line::from(vec![
Span::raw(format!("{key:>10}", key = "enter")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("Show notification").gray().dim(),
]),
Line::from(vec![
Span::raw(format!("{key:>10}", key = "c")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("Clear notifications").gray().dim(),
]),
Line::from(vec![
Span::raw(format!("{key:>10}", key = "/")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("Search").gray().dim(),
]),
Line::from(vec![
Span::raw(format!("{key:>10}", key = "?")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("Show help").gray().dim(),
]),
Line::from(vec![
Span::raw(format!("{key:>10}", key = "Esc")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("Quit / cancel").gray().dim(),
]),
Line::raw(""),
@@ -502,18 +508,16 @@ fn help_text() -> Text<'static> {
Line::raw(""),
Line::from(vec![
Span::raw(format!("{key:>10}", key = "Pattern")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("is:<state> | is:patch | is:issue | <search>")
.gray()
.dim(),
]),
Line::from(vec![
Span::raw(format!("{key:>10}", key = "Example")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("is:unseen is:patch Print").gray().dim(),
]),
Line::raw(""),
Line::raw(""),
]
.to_vec(),
)
+28 -24
View File
@@ -21,7 +21,7 @@ use tui::store;
use tui::store::StateValue;
use tui::ui::span;
use tui::ui::widget::container::{Column, Container, Footer, FooterProps, Header, HeaderProps};
use tui::ui::widget::text::{TextArea, TextAreaProps};
use tui::ui::widget::input::{TextArea, TextAreaProps};
use tui::ui::widget::window::{Page, PageProps, Shortcuts, ShortcutsProps, Window, WindowProps};
use tui::ui::widget::{ToWidget, Widget};
@@ -77,6 +77,7 @@ impl BrowserState {
#[derive(Clone, Debug)]
pub struct HelpState {
scroll: usize,
cursor: (usize, usize),
}
#[derive(Clone, Debug)]
@@ -115,7 +116,10 @@ impl TryFrom<&Context> for State {
search,
show_search: false,
},
help: HelpState { scroll: 0 },
help: HelpState {
scroll: 0,
cursor: (0, 0),
},
})
}
}
@@ -138,6 +142,7 @@ pub enum Message {
LeavePage,
ScrollHelp {
scroll: usize,
cursor: (usize, usize),
},
}
@@ -192,8 +197,9 @@ impl store::State<Selection> for State {
self.pages.pop();
None
}
Message::ScrollHelp { scroll } => {
Message::ScrollHelp { scroll, cursor } => {
self.help.scroll = scroll;
self.help.cursor = cursor;
None
}
}
@@ -297,13 +303,13 @@ fn help_page(_state: &State, channel: &Channel<Message>) -> Widget<State, Messag
TextArea::default()
.to_widget(tx.clone())
.on_event(|_, s, _| {
Some(Message::ScrollHelp {
scroll: s.and_then(|p| p.unwrap_usize()).unwrap_or_default(),
})
let (scroll, cursor) = s.and_then(|p| p.unwrap_textarea()).unwrap_or_default();
Some(Message::ScrollHelp { scroll, cursor })
})
.on_update(|_| {
.on_update(|state: &State| {
TextAreaProps::default()
.text(&help_text())
.content(help_text())
.cursor(state.help.cursor)
.to_boxed_any()
.into()
}),
@@ -356,7 +362,7 @@ fn help_text() -> Text<'static> {
Line::from(
[
Span::raw(format!("{key:>10}", key = "↑,k")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("move cursor one line up").gray().dim(),
]
.to_vec(),
@@ -364,7 +370,7 @@ fn help_text() -> Text<'static> {
Line::from(
[
Span::raw(format!("{key:>10}", key = "↓,j")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("move cursor one line down").gray().dim(),
]
.to_vec(),
@@ -372,7 +378,7 @@ fn help_text() -> Text<'static> {
Line::from(
[
Span::raw(format!("{key:>10}", key = "PageUp")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("move cursor one page up").gray().dim(),
]
.to_vec(),
@@ -380,7 +386,7 @@ fn help_text() -> Text<'static> {
Line::from(
[
Span::raw(format!("{key:>10}", key = "PageDown")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("move cursor one page down").gray().dim(),
]
.to_vec(),
@@ -388,7 +394,7 @@ fn help_text() -> Text<'static> {
Line::from(
[
Span::raw(format!("{key:>10}", key = "Home")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("move cursor to the first line").gray().dim(),
]
.to_vec(),
@@ -396,7 +402,7 @@ fn help_text() -> Text<'static> {
Line::from(
[
Span::raw(format!("{key:>10}", key = "End")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("move cursor to the last line").gray().dim(),
]
.to_vec(),
@@ -407,7 +413,7 @@ fn help_text() -> Text<'static> {
Line::from(
[
Span::raw(format!("{key:>10}", key = "enter")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("Select issue (if --mode id)").gray().dim(),
]
.to_vec(),
@@ -415,7 +421,7 @@ fn help_text() -> Text<'static> {
Line::from(
[
Span::raw(format!("{key:>10}", key = "enter")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("Show issue").gray().dim(),
]
.to_vec(),
@@ -423,7 +429,7 @@ fn help_text() -> Text<'static> {
Line::from(
[
Span::raw(format!("{key:>10}", key = "e")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("Edit patch").gray().dim(),
]
.to_vec(),
@@ -431,7 +437,7 @@ fn help_text() -> Text<'static> {
Line::from(
[
Span::raw(format!("{key:>10}", key = "/")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("Search").gray().dim(),
]
.to_vec(),
@@ -439,7 +445,7 @@ fn help_text() -> Text<'static> {
Line::from(
[
Span::raw(format!("{key:>10}", key = "?")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("Show help").gray().dim(),
]
.to_vec(),
@@ -447,7 +453,7 @@ fn help_text() -> Text<'static> {
Line::from(
[
Span::raw(format!("{key:>10}", key = "Esc")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("Quit / cancel").gray().dim(),
]
.to_vec(),
@@ -458,7 +464,7 @@ fn help_text() -> Text<'static> {
Line::from(
[
Span::raw(format!("{key:>10}", key = "Pattern")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("is:<state> | is:authored | is:assigned | authors:[<did>, ...] | assignees:[<did>, ...] | <search>")
.gray()
.dim(),
@@ -468,13 +474,11 @@ fn help_text() -> Text<'static> {
Line::from(
[
Span::raw(format!("{key:>10}", key = "Example")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("is:solved is:authored alias").gray().dim(),
]
.to_vec(),
),
Line::raw(""),
Line::raw(""),
]
.to_vec())
}
+29 -25
View File
@@ -19,7 +19,7 @@ use termion::event::Key;
use tui::store;
use tui::ui::span;
use tui::ui::widget::container::{Column, Container, Footer, FooterProps, Header, HeaderProps};
use tui::ui::widget::text::{TextArea, TextAreaProps};
use tui::ui::widget::input::{TextArea, TextAreaProps};
use tui::ui::widget::window::{Page, PageProps, Shortcuts, ShortcutsProps, Window, WindowProps};
use tui::ui::widget::{ToWidget, Widget};
@@ -74,6 +74,7 @@ impl BrowserState {
#[derive(Clone, Debug)]
pub struct HelpState {
scroll: usize,
cursor: (usize, usize),
}
#[derive(Clone, Debug)]
@@ -112,7 +113,10 @@ impl TryFrom<&Context> for State {
search,
show_search: false,
},
help: HelpState { scroll: 0 },
help: HelpState {
scroll: 0,
cursor: (0, 0),
},
})
}
}
@@ -135,6 +139,7 @@ pub enum Message {
LeavePage,
ScrollHelp {
scroll: usize,
cursor: (usize, usize),
},
}
@@ -189,8 +194,9 @@ impl store::State<Selection> for State {
self.pages.pop();
None
}
Message::ScrollHelp { scroll } => {
Message::ScrollHelp { scroll, cursor } => {
self.help.scroll = scroll;
self.help.cursor = cursor;
None
}
}
@@ -295,13 +301,13 @@ fn help_page(_state: &State, channel: &Channel<Message>) -> Widget<State, Messag
TextArea::default()
.to_widget(tx.clone())
.on_event(|_, s, _| {
Some(Message::ScrollHelp {
scroll: s.and_then(|p| p.unwrap_usize()).unwrap_or_default(),
})
let (scroll, cursor) = s.and_then(|p| p.unwrap_textarea()).unwrap_or_default();
Some(Message::ScrollHelp { scroll, cursor })
})
.on_update(|_| {
.on_update(|state: &State| {
TextAreaProps::default()
.text(&help_text())
.content(help_text())
.cursor(state.help.cursor)
.to_boxed_any()
.into()
}),
@@ -353,32 +359,32 @@ fn help_text() -> Text<'static> {
Line::raw(""),
Line::from(vec![
Span::raw(format!("{key:>10}", key = "↑,k")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("move cursor one line up").gray().dim(),
]),
Line::from(vec![
Span::raw(format!("{key:>10}", key = "↓,j")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("move cursor one line down").gray().dim(),
]),
Line::from(vec![
Span::raw(format!("{key:>10}", key = "PageUp")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("move cursor one page up").gray().dim(),
]),
Line::from(vec![
Span::raw(format!("{key:>10}", key = "PageDown")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("move cursor one page down").gray().dim(),
]),
Line::from(vec![
Span::raw(format!("{key:>10}", key = "Home")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("move cursor to the first line").gray().dim(),
]),
Line::from(vec![
Span::raw(format!("{key:>10}", key = "End")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("move cursor to the last line").gray().dim(),
]),
Line::raw(""),
@@ -386,37 +392,37 @@ fn help_text() -> Text<'static> {
Line::raw(""),
Line::from(vec![
Span::raw(format!("{key:>10}", key = "enter")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("Select patch (if --mode id)").gray().dim(),
]),
Line::from(vec![
Span::raw(format!("{key:>10}", key = "enter")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("Show patch").gray().dim(),
]),
Line::from(vec![
Span::raw(format!("{key:>10}", key = "c")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("Checkout patch").gray().dim(),
]),
Line::from(vec![
Span::raw(format!("{key:>10}", key = "d")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("Show patch diff").gray().dim(),
]),
Line::from(vec![
Span::raw(format!("{key:>10}", key = "/")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("Search").gray().dim(),
]),
Line::from(vec![
Span::raw(format!("{key:>10}", key = "?")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("Show help").gray().dim(),
]),
Line::from(vec![
Span::raw(format!("{key:>10}", key = "Esc")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("Quit / cancel").gray().dim(),
]),
Line::raw(""),
@@ -424,18 +430,16 @@ fn help_text() -> Text<'static> {
Line::raw(""),
Line::from(vec![
Span::raw(format!("{key:>10}", key = "Pattern")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("is:<state> | is:authored | authors:[<did>, <did>] | <search>")
.gray()
.dim(),
]),
Line::from(vec![
Span::raw(format!("{key:>10}", key = "Example")).gray(),
Span::raw(" "),
Span::raw(": "),
Span::raw("is:open is:authored improve").gray().dim(),
]),
Line::raw(""),
Line::raw(""),
]
.to_vec(),
)