3 Copyright (C) 2015 est31 <MTest31@outlook.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #ifndef TERMINAL_CHAT_CONSOLE_H
21 #define TERMINAL_CHAT_CONSOLE_H
24 #include "threading/thread.h"
25 #include "chat_interface.h"
30 class TermLogOutput : public ILogOutput {
33 void logRaw(LogLevel lev, const std::string &line)
35 queue.push_back(std::make_pair(lev, line));
38 virtual void log(LogLevel lev, const std::string &combined,
39 const std::string &time, const std::string &thread_name,
40 const std::string &payload_text)
42 std::ostringstream os(std::ios_base::binary);
43 os << time << ": [" << thread_name << "] " << payload_text;
45 queue.push_back(std::make_pair(lev, os.str()));
48 MutexedQueue<std::pair<LogLevel, std::string> > queue;
51 class TerminalChatConsole : public Thread {
54 TerminalChatConsole() :
55 Thread("TerminalThread"),
56 m_log_level(LL_ACTION),
57 m_utf8_bytes_to_wait(0),
58 m_kill_requested(NULL),
67 const std::string &nick)
70 m_kill_requested = kill_requested;
71 m_chat_interface = iface;
77 void clearKillStatus() { m_kill_requested = NULL; }
79 void stopAndWaitforThread();
82 // these have stupid names so that nobody missclassifies them
83 // as curses functions. Oh, curses has stupid names too?
84 // Well, at least it was worth a try...
86 void deInitOfCurses();
90 void typeChatMessage(const std::wstring &m);
92 void handleInput(int ch, bool &complete_redraw_needed);
96 // Used to ensure the deinitialisation is always called.
97 struct CursesInitHelper {
98 TerminalChatConsole *cons;
99 CursesInitHelper(TerminalChatConsole * a_console)
101 { cons->initOfCurses(); }
102 ~CursesInitHelper() { cons->deInitOfCurses(); }
108 u8 m_utf8_bytes_to_wait;
109 std::string m_pending_utf8_bytes;
111 std::list<std::string> m_nicks;
115 bool m_can_draw_text;
117 bool *m_kill_requested;
118 ChatBackend m_chat_backend;
119 ChatInterface *m_chat_interface;
121 TermLogOutput m_log_output;
129 extern TerminalChatConsole g_term_console;