diff --git a/src/client.rs b/src/client.rs index e51f45b..c77ee96 100644 --- a/src/client.rs +++ b/src/client.rs @@ -69,11 +69,26 @@ pub enum Request { GetPitch, SetVolume(ClientScope, i8), GetVolume, - SetPauseContext(ClientScope, u8), + SetPauseContext(ClientScope, u16), SetHistory(ClientScope, bool), SetNotification(NotificationType, bool), + // Blocks Begin, End, + // History + HistoryGetClients, + HistoryGetClientId, + HistoryGetClientMessages(ClientScope, u16, u16), + HistoryGetLastMessageId, + HistoryGetMessage(MessageId), + HistoryCursorGet, + HistoryCursorSet(ClientId, HistoryPosition), + HistoryCursorMove(CursorDirection), + HistorySort(SortDirection, SortKey), + HistorySetShortMessageLength(u16), + HistorySetMessageTypeOrdering(Ordering), + HistorySearch(MessageScope, String), + // Misc. Quit, } @@ -281,6 +296,18 @@ impl Client { } Request::Begin => send_one_line!(self, "BLOCK BEGIN"), Request::End => send_one_line!(self, "BLOCK END"), + Request::HistoryGetClients => panic!("not implemented"), + Request::HistoryGetClientId => panic!("not implemented"), + Request::HistoryGetClientMessages(_scope, _start, _number) => panic!("not implemented"), + Request::HistoryGetLastMessageId => panic!("not implemented"), + Request::HistoryGetMessage(_id) => panic!("not implemented"), + Request::HistoryCursorGet => panic!("not implemented"), + Request::HistoryCursorSet(_scope, _pos) => panic!("not implemented"), + Request::HistoryCursorMove(_direction) => panic!("not implemented"), + Request::HistorySort(_direction, _key) => panic!("not implemented"), + Request::HistorySetShortMessageLength(_length) => panic!("not implemented"), + Request::HistorySetMessageTypeOrdering(_ordering) => panic!("not implemented"), + Request::HistorySearch(_scope, _condition) => panic!("not implemented"), Request::Quit => send_one_line!(self, "QUIT"), }?; Ok(self) @@ -453,7 +480,7 @@ impl Client { } /// Set the number of (more or less) sentences that should be repeated after a previously paused text is resumed. - pub fn set_pause_context(&mut self, scope: ClientScope, value: u8) -> ClientResult<&mut Self> { + pub fn set_pause_context(&mut self, scope: ClientScope, value: u16) -> ClientResult<&mut Self> { self.send(Request::SetPauseContext(scope, value)) } @@ -594,7 +621,13 @@ impl Client { .and_then(|lines| parse_single_value(&lines)) } - /// Receive integer + /// Receive signed 8-bit integer + pub fn receive_i8(&mut self) -> ClientResult { + self.receive_string(OK_GET) + .and_then(|s| s.parse().map_err(|_| ClientError::InvalidType)) + } + + /// Receive unsigned 8-bit integer pub fn receive_u8(&mut self) -> ClientResult { self.receive_string(OK_GET) .and_then(|s| s.parse().map_err(|_| ClientError::InvalidType)) diff --git a/src/types.rs b/src/types.rs index 375761a..88f6cb6 100644 --- a/src/types.rs +++ b/src/types.rs @@ -458,6 +458,70 @@ impl ClientName { } } +/// Cursor motion in history +#[derive(StrumDisplay, Debug, Clone)] +pub enum CursorDirection { + #[strum(serialize = "backward")] + Backward, + #[strum(serialize = "forward")] + Forward, +} + +/// Sort direction in history +#[derive(StrumDisplay, Debug, Clone)] +pub enum SortDirection { + #[strum(serialize = "asc")] + Ascending, + #[strum(serialize = "desc")] + Descending, +} + +/// Property messages are ordered by in history +#[derive(StrumDisplay, Debug, Clone)] +pub enum SortKey { + #[strum(serialize = "client_name")] + ClientName, + #[strum(serialize = "priority")] + Priority, + #[strum(serialize = "message_type")] + MessageType, + #[strum(serialize = "time")] + Time, + #[strum(serialize = "user")] + User, +} + +/// Sort ordering +#[derive(StrumDisplay, Debug, Clone)] +pub enum Ordering { + #[strum(serialize = "text")] + Text, + #[strum(serialize = "sound_icon")] + SoundIcon, + #[strum(serialize = "char")] + Char, + #[strum(serialize = "key")] + Key, +} + +/// Position in history +#[derive(Debug, Clone)] +pub enum HistoryPosition { + First, + Last, + Pos(u16), +} + +impl fmt::Display for HistoryPosition { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + HistoryPosition::First => write!(f, "first"), + HistoryPosition::Last => write!(f, "last"), + HistoryPosition::Pos(n) => write!(f, "pos {}", n), + } + } +} + #[cfg(test)] mod tests { diff --git a/tests/fifo_sync_tests.rs b/tests/fifo_sync_tests.rs index 41920ed..b94ccd9 100644 --- a/tests/fifo_sync_tests.rs +++ b/tests/fifo_sync_tests.rs @@ -232,7 +232,7 @@ test_setter!( test_getter!( get_rate, - receive_u8, + receive_i8, (), "GET RATE\r\n", "251-0\r\n251 OK GET RETURNED\r\n", @@ -250,7 +250,7 @@ test_setter!( test_getter!( get_volume, - receive_u8, + receive_i8, (), "GET VOLUME\r\n", "251-100\r\n251 OK GET RETURNED\r\n", @@ -259,7 +259,7 @@ test_getter!( test_getter!( get_pitch, - receive_u8, + receive_i8, (), "GET PITCH\r\n", "251-0\r\n251 OK GET RETURNED\r\n",