-
Notifications
You must be signed in to change notification settings - Fork 85
/
api.rs
122 lines (111 loc) · 2.89 KB
/
api.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
use enumset::EnumSetType;
use rkyv::{Archive, Deserialize, Serialize};
// shorthand for the function keys F1 - F4
pub const F1: char = '\u{0011}';
pub const F2: char = '\u{0012}';
pub const F3: char = '\u{0013}';
pub const F4: char = '\u{0014}';
// these are used to increment and decrement the selected post
pub const POST_SELECTED_NEXT: usize = usize::MAX - 0;
pub const POST_SELECTED_PREV: usize = usize::MAX - 1;
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
pub enum ChatOp {
// Save the Dialogue to pddb (ie after PostAdd, PostDelete)
DialogueSave = 0,
/// Set the current Dialogue to be displayed
DialogueSet,
/// change the Chat UI in/out of focus
GamChangeFocus,
/// a line of text has arrived
GamLine,
/// receive rawkeys from gam
GamRawkeys,
/// redraw our Chat UI
GamRedraw,
/// Show some user help
Help,
/// Add a new MenuItem to the App menu
MenuAdd,
/// Add a new Post to the Dialogue
PostAdd,
/// Delete a Post from the Dialogue
PostDel,
/// Find a Post by timestamp and Author
PostFind,
PostFlag,
/// exit the application
Quit,
}
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
pub enum IconOp {
PostMenu = 0,
F2Op,
F3Op,
AppMenu,
}
pub const POST_TEXT_MAX: usize = 3072;
#[derive(Archive, Serialize, Deserialize, Debug)]
pub struct Find {
pub author: xous_ipc::String<128>,
pub timestamp: u64,
pub key: Option<usize>, // the return post key if found.
}
#[derive(Archive, Serialize, Deserialize, Debug)]
pub struct Dialogue {
pub dict: xous_ipc::String<128>,
pub key: Option<xous_ipc::String<128>>,
}
#[derive(Archive, Serialize, Deserialize, Debug)]
pub struct Post {
pub dialogue_id: xous_ipc::String<128>,
pub author: xous_ipc::String<128>,
pub timestamp: u64,
pub text: xous_ipc::String<POST_TEXT_MAX>,
pub attach_url: Option<xous_ipc::String<128>>,
}
/// Events are sent to the Chat App when key things occur in the Chat UI
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
pub enum Event {
Focus,
F1, // F1 button click
F2, // F2 button click
F3, // you get the idea
F4, // guess
Up, // Up click
Down, // Down click
Left, // Left click
Right, // Right click
Top, // Top of post list reached
Bottom, // Bottom of post list reached
Key, // keystroke
Post, // new user Post committed
Menu, // menu item clicked
}
#[derive(
Archive,
Serialize,
Deserialize,
Debug,
num_derive::FromPrimitive,
num_derive::ToPrimitive,
EnumSetType,
)]
pub enum PostFlag {
Deleted,
Draft,
Hidden,
}
#[derive(
Archive,
Serialize,
Deserialize,
Debug,
num_derive::FromPrimitive,
num_derive::ToPrimitive,
EnumSetType,
)]
pub enum AuthorFlag {
Bold,
Hidden,
Right,
}