Minetest 5.9.0-dev
 
Loading...
Searching...
No Matches
terminal_chat_console.h
Go to the documentation of this file.
1/*
2Minetest
3Copyright (C) 2015 est31 <MTest31@outlook.com>
4
5This program is free software; you can redistribute it and/or modify
6it under the terms of the GNU Lesser General Public License as published by
7the Free Software Foundation; either version 2.1 of the License, or
8(at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU Lesser General Public License for more details.
14
15You should have received a copy of the GNU Lesser General Public License along
16with this program; if not, write to the Free Software Foundation, Inc.,
1751 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18*/
19
20#pragma once
21
22#include "chat.h"
23#include "threading/thread.h"
24#include "util/container.h"
25#include "log.h"
26#include <set>
27#include <sstream>
28
29
30struct ChatInterface;
31
32class TermLogOutput : public ILogOutput {
33public:
34
35 void logRaw(LogLevel lev, const std::string &line)
36 {
37 queue.push_back(std::make_pair(lev, line));
38 }
39
40 virtual void log(LogLevel lev, const std::string &combined,
41 const std::string &time, const std::string &thread_name,
42 const std::string &payload_text)
43 {
44 std::ostringstream os(std::ios_base::binary);
45 os << time << ": [" << thread_name << "] " << payload_text;
46
47 queue.push_back(std::make_pair(lev, os.str()));
48 }
49
51};
52
54public:
55
57 Thread("TerminalThread")
58 {}
59
60 void setup(
61 ChatInterface *iface,
62 bool *kill_requested,
63 const std::string &nick)
64 {
65 m_nick = nick;
66 m_kill_requested = kill_requested;
67 m_chat_interface = iface;
68 }
69
70 virtual void *run();
71
72 // Highly required!
73 void clearKillStatus() { m_kill_requested = nullptr; }
74
76
77private:
78 // these have stupid names so that nobody missclassifies them
79 // as curses functions. Oh, curses has stupid names too?
80 // Well, at least it was worth a try...
83
84 void draw_text();
85
86 void typeChatMessage(const std::wstring &m);
87
88 void handleInput(int ch, bool &complete_redraw_needed);
89
90 void step(int ch);
91
92 // Used to ensure the deinitialisation is always called.
96 : cons(a_console)
97 { cons->initOfCurses(); }
99 };
100
102 std::string m_nick;
103
106
107 std::set<std::string> m_nicks;
108
112
113 bool *m_kill_requested = nullptr;
116
118
119 bool m_esc_mode = false;
120
121 u64 m_game_time = 0;
123};
124
Definition: chat.h:285
Definition: log.h:103
Definition: container.h:132
void push_back(const T &t)
Definition: container.h:145
Definition: terminal_chat_console.h:32
virtual void log(LogLevel lev, const std::string &combined, const std::string &time, const std::string &thread_name, const std::string &payload_text)
Definition: terminal_chat_console.h:40
void logRaw(LogLevel lev, const std::string &line)
Definition: terminal_chat_console.h:35
MutexedQueue< std::pair< LogLevel, std::string > > queue
Definition: terminal_chat_console.h:50
Definition: terminal_chat_console.h:53
void handleInput(int ch, bool &complete_redraw_needed)
void clearKillStatus()
Definition: terminal_chat_console.h:73
ChatBackend m_chat_backend
Definition: terminal_chat_console.h:114
int m_log_level
Definition: terminal_chat_console.h:101
void typeChatMessage(const std::wstring &m)
TermLogOutput m_log_output
Definition: terminal_chat_console.h:117
u8 m_utf8_bytes_to_wait
Definition: terminal_chat_console.h:104
TerminalChatConsole()
Definition: terminal_chat_console.h:56
int m_cols
Definition: terminal_chat_console.h:109
u32 m_time_of_day
Definition: terminal_chat_console.h:122
bool m_can_draw_text
Definition: terminal_chat_console.h:111
virtual void * run()
void step(int ch)
u64 m_game_time
Definition: terminal_chat_console.h:121
std::string m_pending_utf8_bytes
Definition: terminal_chat_console.h:105
std::set< std::string > m_nicks
Definition: terminal_chat_console.h:107
void setup(ChatInterface *iface, bool *kill_requested, const std::string &nick)
Definition: terminal_chat_console.h:60
int m_rows
Definition: terminal_chat_console.h:110
bool m_esc_mode
Definition: terminal_chat_console.h:119
ChatInterface * m_chat_interface
Definition: terminal_chat_console.h:115
std::string m_nick
Definition: terminal_chat_console.h:102
bool * m_kill_requested
Definition: terminal_chat_console.h:113
Definition: thread.h:57
LogLevel
Definition: log.h:39
@ LL_ACTION
Definition: log.h:43
Definition: chat_interface.h:76
Definition: terminal_chat_console.h:93
CursesInitHelper(TerminalChatConsole *a_console)
Definition: terminal_chat_console.h:95
~CursesInitHelper()
Definition: terminal_chat_console.h:98
TerminalChatConsole * cons
Definition: terminal_chat_console.h:94
TerminalChatConsole g_term_console