From: Simon Tatham Date: Thu, 4 Jan 2024 11:58:51 +0000 (+0000) Subject: Add an initial_pos to the File constructor. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=749f224d8fbc6578889d7ecce1c85020ef919d27;p=mastodonochrome.git Add an initial_pos to the File constructor. --- diff --git a/src/file.rs b/src/file.rs index 2841378..9ef42c3 100644 --- a/src/file.rs +++ b/src/file.rs @@ -257,7 +257,8 @@ struct File { } impl File { - fn new(client: &mut Client, source: Source, desc: ColouredString) -> + fn new(client: &mut Client, source: Source, desc: ColouredString, + initial_pos: Option) -> Result { source.init(client)?; @@ -279,8 +280,13 @@ impl File { contents.update_items(client); // FIXME: once we have an LDB, that's where initial pos comes from - let initial_pos = FilePosition::item_bottom( - contents.last_index() as isize); + let mut initial_pos = initial_pos.unwrap_or_else( + || FilePosition::item_bottom(isize::MAX)); + + initial_pos.item = max(initial_pos.item, contents.first_index()); + initial_pos.item = min(initial_pos.item, contents.last_index()); + + dbg!(initial_pos); let ff = File { contents, @@ -1089,7 +1095,7 @@ pub fn home_timeline(client: &mut Client) -> let file = File::::new( client, FeedSource::new(FeedId::Home), ColouredString::general( "Home timeline ", - "HHHHHHHHHHHHHHHHHKH"))?; + "HHHHHHHHHHHHHHHHHKH"), None)?; Ok(Box::new(file)) } @@ -1099,7 +1105,7 @@ pub fn local_timeline(client: &mut Client) -> let file = File::::new( client, FeedSource::new(FeedId::Local), ColouredString::general( "Local public timeline ", - "HHHHHHHHHHHHHHHHHHHHHHHHHKH"))?; + "HHHHHHHHHHHHHHHHHHHHHHHHHKH"), None)?; Ok(Box::new(file)) } @@ -1109,7 +1115,7 @@ pub fn public_timeline(client: &mut Client) -> let file = File::::new( client, FeedSource::new(FeedId::Public), ColouredString::general( "Public timeline

", - "HHHHHHHHHHHHHHHHHHHKH"))?; + "HHHHHHHHHHHHHHHHHHHKH"), None)?; Ok(Box::new(file)) } @@ -1119,7 +1125,7 @@ pub fn mentions(client: &mut Client) -> let file = File::::new( client, FeedSource::new(FeedId::Mentions), ColouredString::general( "Mentions [ESC][R]", - "HHHHHHHHHHHHKKKHHKH"))?; + "HHHHHHHHHHHHKKKHHKH"), None)?; Ok(Box::new(file)) } @@ -1129,7 +1135,7 @@ pub fn ego_log(client: &mut Client) -> let file = File::::new( client, FeedSource::new(FeedId::Ego), ColouredString::general( "Ego Log [ESC][L][L][E]", - "HHHHHHHHHHHKKKHHKHHKHHKH"))?; + "HHHHHHHHHHHKKKHHKHHKHHKH"), None)?; Ok(Box::new(file)) } @@ -1139,7 +1145,7 @@ pub fn list_status_favouriters(client: &mut Client, id: &str) -> let file = File::::new( client, FeedSource::new(FeedId::Favouriters(id.to_owned())), ColouredString::uniform( - &format!("Users who favourited post {id}"), 'H'))?; + &format!("Users who favourited post {id}"), 'H'), None)?; Ok(Box::new(file)) } @@ -1149,7 +1155,7 @@ pub fn list_status_boosters(client: &mut Client, id: &str) -> let file = File::::new( client, FeedSource::new(FeedId::Boosters(id.to_owned())), ColouredString::uniform( - &format!("Users who boosted post {id}"), 'H'))?; + &format!("Users who boosted post {id}"), 'H'), None)?; Ok(Box::new(file)) } @@ -1162,7 +1168,7 @@ pub fn list_user_followers(client: &mut Client, id: &str) -> let file = File::::new( client, FeedSource::new(FeedId::Followers(id.to_owned())), ColouredString::uniform( - &format!("Users who follow {name}"), 'H'))?; + &format!("Users who follow {name}"), 'H'), None)?; Ok(Box::new(file)) } @@ -1175,7 +1181,7 @@ pub fn list_user_followees(client: &mut Client, id: &str) -> let file = File::::new( client, FeedSource::new(FeedId::Followees(id.to_owned())), ColouredString::uniform( - &format!("Users who {name} follows"), 'H'))?; + &format!("Users who {name} follows"), 'H'), None)?; Ok(Box::new(file)) } @@ -1185,7 +1191,7 @@ pub fn hashtag_timeline(client: &mut Client, tag: &str) -> let title = ColouredString::uniform( &format!("Posts mentioning hashtag #{tag}"), 'H'); let file = File::::new( - client, FeedSource::new(FeedId::Hashtag(tag.to_owned())), title)?; + client, FeedSource::new(FeedId::Hashtag(tag.to_owned())), title, None)?; Ok(Box::new(file)) } @@ -1211,7 +1217,7 @@ pub fn examine_user(client: &mut Client, account_id: &str) -> &format!("Information about user {username}"), 'H'); let file = File::::new( - client, StaticSource::singleton(ac.id), title)?; + client, StaticSource::singleton(ac.id), title, None)?; Ok(Box::new(file)) } @@ -1236,7 +1242,7 @@ pub fn view_single_post(client: &mut Client, status_id: &str) -> &format!("Information about post {}", st.id), 'H'); let file = File::::new( - client, StaticSource::singleton(st.id), title)?; + client, StaticSource::singleton(st.id), title, None)?; Ok(Box::new(file)) } @@ -1272,6 +1278,6 @@ pub fn view_thread(client: &mut Client, start_id: &str, full: bool) -> let title = ColouredString::uniform(&title, 'H'); let file = File::::new( - client, StaticSource::vector(ids), title)?; + client, StaticSource::vector(ids), title, None)?; Ok(Box::new(file)) }