context, like 'I was trying to fetch this status because this other
one was replying to it'.
-In the `get_user_to_examine` and `get_post_id_to_read` overlay
-activities, a simple 'not found' error shouldn't throw the user into
-the Error Log. That's overkill. We should instead toggle to an overlay
-activity showing a friendlier bottom-line error message, and abort the
-attempt. (Then the user can try again via line recall if it was just a
-typo – at least, once we implement line recall.)
-
We don't have good handling for I/O errors while saving the user's
LDB. That's not a _client_ error, but we could make an extra enum
branch in `ClientError` anyway, so that the TuiLogicalState could put
use std::cmp::{max, min};
use unicode_width::UnicodeWidthChar;
-use super::activity_stack::{NonUtilityActivity, UtilityActivity};
+use super::activity_stack::{
+ NonUtilityActivity, OverlayActivity, UtilityActivity,
+};
use super::client::{Client, ClientError};
use super::coloured_string::*;
use super::file::SearchDirection;
}
}
+struct BottomLineErrorOverlay {
+ line: CentredInfoLine,
+}
+
+impl BottomLineErrorOverlay {
+ fn new(msg: &str) -> Self {
+ let msg = ColouredString::uniform("Error: ", 'r')
+ + ColouredString::plain(msg)
+ + ColouredString::general(" [RET]", " kkk ");
+ BottomLineErrorOverlay {
+ line: CentredInfoLine::new(msg),
+ }
+ }
+}
+
+impl ActivityState for BottomLineErrorOverlay {
+ fn draw(
+ &self,
+ w: usize,
+ _h: usize,
+ ) -> (Vec<ColouredString>, CursorPosition) {
+ (self.line.render(w), CursorPosition::End)
+ }
+
+ fn handle_keypress(
+ &mut self,
+ key: OurKey,
+ _client: &mut Client,
+ ) -> LogicalAction {
+ match key {
+ Return => LogicalAction::PopOverlaySilent,
+ _ => LogicalAction::Nothing,
+ }
+ }
+}
+
pub trait EditableMenuLineData {
// If SECRET, then the implementor of this trait promises that
// display() will show the text as ***** when it's not being
UtilityActivity::ExamineUser(account.id).into(),
),
- // FIXME: it would be nice to discriminate errors
- // better here, and do something a bit less
- // terrifying for plain "account not found", like
- // allowing the user to re-edit
+ Err(ClientError::UrlFetchHTTPRich(
+ _,
+ reqwest::StatusCode::NOT_FOUND,
+ _,
+ )) => LogicalAction::Goto(
+ OverlayActivity::BottomLineError(
+ format!("User '{}' not found", s)
+ )
+ .into(),
+ ),
+
Err(err) => LogicalAction::Error(err),
}
}
UtilityActivity::InfoStatus(st.id).into(),
),
- // FIXME: it would be nice to discriminate errors
- // better here, and do something a bit less
- // terrifying for plain "status not found", like
- // allowing the user to re-edit
+ Err(ClientError::UrlFetchHTTPRich(
+ _,
+ reqwest::StatusCode::NOT_FOUND,
+ _,
+ )) => LogicalAction::Goto(
+ OverlayActivity::BottomLineError(
+ format!("Post id {} not found", s)
+ )
+ .into(),
+ ),
+
Err(err) => LogicalAction::Error(err),
}
}
))
}
+pub fn bottom_line_error(msg: &str) -> Box<dyn ActivityState> {
+ Box::new(BottomLineErrorOverlay::new(msg))
+}
+
#[derive(Debug, PartialEq, Eq, Clone)]
struct ComposeBufferRegion {
start: usize,