-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.cpp
68 lines (59 loc) · 2.66 KB
/
main.cpp
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
#include <iostream>
#include "SlackUI.hpp"
#include "SlackClient.hpp"
#include <assert.h>
#include <string.h>
static void check_cmdline(int, char **, std::string&);
int main(int argc, char* argv[]) {
std::string TOKEN_NAME;
check_cmdline(argc, argv, TOKEN_NAME);
auto token = std::getenv(TOKEN_NAME.c_str());
if (!token) {
// fallback to default token name
token = std::getenv("SLACK_TOKEN");
if (!token) {
if (argc == 1) {
std::cerr << "No token specified. Check helper message (\"--help\")" << std::endl;;
exit(EXIT_FAILURE);
} else if (argc > 1) {
std::cerr << "Neither specific token nor default token found. Check helper message (\"--help\")" << std::endl;;
exit(EXIT_FAILURE);
}
}
}
assert(token != nullptr);
SlackUI ui;
SlackClient c;
ui.set_client(&c);
c.set_ui(&ui);
c.set_token(token);
ui.show();
return 0;
}
static void check_cmdline(int argc, char *argv[], std::string& TOKEN_NAME) {
if (argc == 2) {
if (strcmp(argv[1], "--help") == 0) {
std::cout << std::endl << " Slack++: https://github.com/ga2arch/slack." << std::endl;
std::cout << " Developed by Gabriele Carrettoni and Federico Di Pierro." << std::endl;
std::cout << " GPL licensed software." << std::endl << std::endl;
std::cout << " How to:" << std::endl;
std::cout << " \t* export $your_wanted_name_SLACK_TOKEN. Note that \"_SLACK_TOKEN\" suffix is needed." << std::endl;
std::cout << " \t* start program with: " << argv[0] << " $your_wanted_name" << std::endl;
std::cout << " \t* slack++ will fallback to $SLACK_TOKEN env variable if no args are passed." << std::endl;
std::cout << " Usage:" << std::endl;
std::cout << " \t* ESC to quit." << std::endl;
std::cout << " \t* tab to change focused win." << std::endl;
std::cout << " \t* In roster mode:" << std::endl;
std::cout << " \t * enter to choose an user to chat with." << std::endl;
std::cout << " \t * 'm' to mute current user. 'n' to mute all." << std::endl;
std::cout << " \t* In input mode:" << std::endl;
std::cout << " \t * enter to send a message." << std::endl;
std::cout << " \t * key_up/key_down to scroll chat history." << std::endl;
std::cout << " Enjoy!" << std::endl << std::endl;
exit(EXIT_SUCCESS);
} else {
TOKEN_NAME = argv[1];
TOKEN_NAME.append("_SLACK_TOKEN");
}
}
}