Luanti 5.10.0-dev
 
Loading...
Searching...
No Matches
terminal_chat_console.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2015 est31 <MTest31@outlook.com>
4
5#pragma once
6
7#include "chat.h"
8#include "threading/thread.h"
9#include "util/container.h"
10#include "log.h"
11#include "log_internal.h"
12#include <set>
13#include <sstream>
14
15
16struct ChatInterface;
17
18class TermLogOutput : public ILogOutput {
19public:
20
21 void logRaw(LogLevel lev, std::string_view line)
22 {
23 queue.push_back(std::make_pair(lev, std::string(line)));
24 }
25
26 virtual void log(LogLevel lev, const std::string &combined,
27 const std::string &time, const std::string &thread_name,
28 std::string_view payload_text)
29 {
30 std::ostringstream os(std::ios_base::binary);
31 os << time << ": [" << thread_name << "] " << payload_text;
32
33 queue.push_back(std::make_pair(lev, os.str()));
34 }
35
37};
38
40public:
41
43 Thread("TerminalThread")
44 {}
45
46 void setup(
47 ChatInterface *iface,
48 bool *kill_requested,
49 const std::string &nick)
50 {
51 m_nick = nick;
52 m_kill_requested = kill_requested;
53 m_chat_interface = iface;
54 }
55
56 virtual void *run();
57
58 // Highly required!
59 void clearKillStatus() { m_kill_requested = nullptr; }
60
62
63private:
64 // these have stupid names so that nobody missclassifies them
65 // as curses functions. Oh, curses has stupid names too?
66 // Well, at least it was worth a try...
69
70 void draw_text();
71
72 void typeChatMessage(const std::wstring &m);
73
74 void handleInput(int ch, bool &complete_redraw_needed);
75
76 void step(int ch);
77
78 // Used to ensure the deinitialisation is always called.
86
88 std::string m_nick;
89
92
93 std::set<std::string> m_nicks;
94
95 int m_cols;
96 int m_rows;
98
99 bool *m_kill_requested = nullptr;
102
104
105 bool m_esc_mode = false;
106
107 u64 m_game_time = 0;
109};
110
Definition chat.h:270
Definition log_internal.h:84
Definition container.h:117
void push_back(const T &t)
Definition container.h:130
Definition terminal_chat_console.h:18
MutexedQueue< std::pair< LogLevel, std::string > > queue
Definition terminal_chat_console.h:36
void logRaw(LogLevel lev, std::string_view line)
Definition terminal_chat_console.h:21
virtual void log(LogLevel lev, const std::string &combined, const std::string &time, const std::string &thread_name, std::string_view payload_text)
Definition terminal_chat_console.h:26
Definition terminal_chat_console.h:39
void handleInput(int ch, bool &complete_redraw_needed)
void clearKillStatus()
Definition terminal_chat_console.h:59
ChatBackend m_chat_backend
Definition terminal_chat_console.h:100
int m_log_level
Definition terminal_chat_console.h:87
void typeChatMessage(const std::wstring &m)
TermLogOutput m_log_output
Definition terminal_chat_console.h:103
u8 m_utf8_bytes_to_wait
Definition terminal_chat_console.h:90
TerminalChatConsole()
Definition terminal_chat_console.h:42
int m_cols
Definition terminal_chat_console.h:95
u32 m_time_of_day
Definition terminal_chat_console.h:108
bool m_can_draw_text
Definition terminal_chat_console.h:97
virtual void * run()
void step(int ch)
u64 m_game_time
Definition terminal_chat_console.h:107
std::string m_pending_utf8_bytes
Definition terminal_chat_console.h:91
std::set< std::string > m_nicks
Definition terminal_chat_console.h:93
void setup(ChatInterface *iface, bool *kill_requested, const std::string &nick)
Definition terminal_chat_console.h:46
int m_rows
Definition terminal_chat_console.h:96
bool m_esc_mode
Definition terminal_chat_console.h:105
ChatInterface * m_chat_interface
Definition terminal_chat_console.h:101
std::string m_nick
Definition terminal_chat_console.h:88
bool * m_kill_requested
Definition terminal_chat_console.h:99
Definition thread.h:57
LogLevel
Definition log_internal.h:20
@ LL_ACTION
Definition log_internal.h:24
Definition chat_interface.h:61
Definition terminal_chat_console.h:79
CursesInitHelper(TerminalChatConsole *a_console)
Definition terminal_chat_console.h:81
~CursesInitHelper()
Definition terminal_chat_console.h:84
TerminalChatConsole * cons
Definition terminal_chat_console.h:80
TerminalChatConsole g_term_console