Bad(String),
}
+impl std::fmt::Display for AuthError {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) ->
+ Result<(), std::fmt::Error>
+ {
+ match self {
+ AuthError::Nonexistent(_) => {
+ write!(f, "not logged in")
+ },
+ AuthError::Bad(ref msg) => {
+ write!(f, "unable to read authentication: {}", msg)
+ },
+ }
+ }
+}
+
#[derive(Serialize, Deserialize, Debug)]
pub struct AuthConfig {
pub account_id: String,
impl AuthConfig {
pub fn load() -> Result<Self, AuthError> {
let xdg_dirs = match BaseDirectories::with_prefix("mastodonochrome") {
- Err(e) => Err(AuthError::Nonexistent(
+ Err(e) => Err(AuthError::Bad(
format!("unable to get config directory: {}", e))),
Ok(d) => Ok(d),
}?;
use unicode_width::UnicodeWidthStr;
use super::activity_stack::*;
-//use super::client::Client;
+use super::client::Client;
use super::coloured_string::{ColouredString, ColouredStringSlice};
use super::menu::*;
+use super::auth::AuthError;
fn ratatui_style_from_colour(colour: char) -> Style {
match colour {
subthread_sender: std::sync::mpsc::SyncSender<SubthreadEvent>,
subthread_receiver: std::sync::mpsc::Receiver<SubthreadEvent>,
state: TuiLogicalState,
- // FIXME: we'll need a Client here
+ client: Client,
}
#[derive(Eq, PartialEq, Debug, Clone, Copy, Hash)]
PgUp, PgDn, Home, End, Ins, Del,
}
+pub struct TuiError {
+ message: String,
+}
+
+impl TuiError {
+ pub fn new(message: &str) -> Self {
+ TuiError {
+ message: message.to_owned(),
+ }
+ }
+}
+
+impl From<std::io::Error> for TuiError {
+ fn from(err: std::io::Error) -> Self {
+ TuiError {
+ message: err.to_string(),
+ }
+ }
+}
+impl From<AuthError> for TuiError {
+ fn from(err: AuthError) -> Self {
+ TuiError {
+ message: err.to_string(),
+ }
+ }
+}
+
+impl std::fmt::Display for TuiError {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) ->
+ Result<(), std::fmt::Error>
+ {
+ write!(f, "unable to read authentication: {}", self.message)
+ }
+}
+
impl Tui {
- pub fn run() -> std::io::Result<()> {
+ pub fn run() -> Result<(), TuiError> {
stdout().execute(EnterAlternateScreen)?;
enable_raw_mode()?;
let mut terminal = Terminal::new(CrosstermBackend::new(stdout()))?;
}
});
+ let client = Client::new()?;
+
let mut tui = Tui {
terminal: terminal,
subthread_sender: sender,
subthread_receiver: receiver,
state: TuiLogicalState::new(),
+ client: client,
};
let result = tui.main_loop();
}
}
- fn main_loop(&mut self) -> std::io::Result<()> {
+ fn main_loop(&mut self) -> Result<(), TuiError> {
'outer: loop {
self.terminal.draw(|frame| {
let area = frame.size();