make pagination starting at 1 instead of 0 (#186)

This commit is contained in:
Clément DOUIN 2021-08-06 13:33:51 +02:00
parent 97054d3133
commit 52e76d19e5
No known key found for this signature in database
GPG key ID: 69C9B9CFFDEE2DEF
3 changed files with 11 additions and 4 deletions

View file

@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Config option `signature-delimiter` to customize the signature delimiter (default to `-- \n`) [[#114](https://github.com/soywod/himalaya/pull/114)] - Config option `signature-delimiter` to customize the signature delimiter (default to `-- \n`) [[#114](https://github.com/soywod/himalaya/pull/114)]
- Expand tilde and env vars for `downloads-dir` and `signature` [#102] - Expand tilde and env vars for `downloads-dir` and `signature` [#102]
### Changed
- Pagination for list and search cmd starts from 1 instead of 0 [#186]
### Fixed ### Fixed
- New/reply/forward from Vim plugin since Tpl refactor [#176] - New/reply/forward from Vim plugin since Tpl refactor [#176]
@ -307,3 +311,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#146]: https://github.com/soywod/himalaya/issues/146 [#146]: https://github.com/soywod/himalaya/issues/146
[#160]: https://github.com/soywod/himalaya/issues/160 [#160]: https://github.com/soywod/himalaya/issues/160
[#176]: https://github.com/soywod/himalaya/issues/176 [#176]: https://github.com/soywod/himalaya/issues/176
[#186]: https://github.com/soywod/himalaya/issues/186

View file

@ -66,7 +66,7 @@ fn page_arg<'a>() -> clap::Arg<'a, 'a> {
.short("p") .short("p")
.long("page") .long("page")
.value_name("INT") .value_name("INT")
.default_value("0") .default_value("1")
} }
fn attachment_arg<'a>() -> clap::Arg<'a, 'a> { fn attachment_arg<'a>() -> clap::Arg<'a, 'a> {
@ -185,6 +185,7 @@ fn msg_matches_list(ctx: &Ctx, opt_matches: Option<&clap::ArgMatches>) -> Result
debug!("page size: {:?}", page_size); debug!("page size: {:?}", page_size);
let page: usize = opt_matches let page: usize = opt_matches
.and_then(|matches| matches.value_of("page").unwrap().parse().ok()) .and_then(|matches| matches.value_of("page").unwrap().parse().ok())
.map(|page| 1.max(page) - 1)
.unwrap_or_default(); .unwrap_or_default();
debug!("page: {}", &page); debug!("page: {}", &page);
@ -215,7 +216,8 @@ fn msg_matches_search(ctx: &Ctx, matches: &clap::ArgMatches) -> Result<bool> {
.value_of("page") .value_of("page")
.unwrap() .unwrap()
.parse() .parse()
.unwrap_or_default(); .map(|page| 1.max(page) - 1)
.unwrap_or(1);
debug!("page: {}", &page); debug!("page: {}", &page);
let query = matches let query = matches

View file

@ -74,7 +74,7 @@ fn msg() {
// List messages // List messages
// TODO: check non-existance of \Seen flag // TODO: check non-existance of \Seen flag
let msgs = imap_conn.list_msgs("INBOX", &10, &0).unwrap(); let msgs = imap_conn.list_msgs("INBOX", &10, &1).unwrap();
let msgs = if let Some(ref fetches) = msgs { let msgs = if let Some(ref fetches) = msgs {
Msgs::from(fetches) Msgs::from(fetches)
} else { } else {
@ -111,7 +111,7 @@ fn msg() {
.add_flags("INBOX", &msg_b.uid.to_string(), "\\Deleted") .add_flags("INBOX", &msg_b.uid.to_string(), "\\Deleted")
.unwrap(); .unwrap();
imap_conn.expunge("INBOX").unwrap(); imap_conn.expunge("INBOX").unwrap();
assert!(imap_conn.list_msgs("INBOX", &10, &0).unwrap().is_none()); assert!(imap_conn.list_msgs("INBOX", &10, &1).unwrap().is_none());
// Logout // Logout
imap_conn.logout(); imap_conn.logout();