Skip to content

Commit

Permalink
platform: rename ConsoleCtl
Browse files Browse the repository at this point in the history
  • Loading branch information
magiblot committed Oct 22, 2024
1 parent 6ac8050 commit 3518c8c
Show file tree
Hide file tree
Showing 23 changed files with 199 additions and 195 deletions.
8 changes: 4 additions & 4 deletions include/tvision/internal/ansiwrit.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ struct TermAttr
// AnsiScreenWriter allows printing characters and color attributes directly
// to screen using ANSI escape codes.

class StdioCtl;
class ConsoleCtl;

class AnsiScreenWriter
{
Expand All @@ -91,7 +91,7 @@ class AnsiScreenWriter
void reserve(size_t) noexcept;
};

const StdioCtl &io;
ConsoleCtl &con;
Buffer buf;
TermAttr lastAttr {};

Expand All @@ -100,8 +100,8 @@ class AnsiScreenWriter

public:

AnsiScreenWriter(StdioCtl &aIo) noexcept :
io(aIo)
AnsiScreenWriter(ConsoleCtl &aCon) noexcept :
con(aCon)
{
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef TVISION_STDIOCTL_H
#define TVISION_STDIOCTL_H
#ifndef TVISION_CONCTL_H
#define TVISION_CONCTL_H

#include <tvision/tv.h>
#include <stdio.h>
Expand All @@ -11,7 +11,7 @@
namespace tvision
{

class StdioCtl final
class ConsoleCtl
{
#ifdef _WIN32
enum { input = 0, startupOutput = 1, activeOutput = 2 };
Expand All @@ -27,21 +27,21 @@ class StdioCtl final
bool ownsFiles {false};
#endif // _WIN32

static StdioCtl *instance;
static ConsoleCtl *instance;

StdioCtl() noexcept;
~StdioCtl();
ConsoleCtl() noexcept;
~ConsoleCtl();

public:

// On Windows, the StdioCtl instance is created every time the alternate
// On Windows, the ConsoleCtl instance is created every time the alternate
// screen buffer is enabled and it is destroyed when restoring the console.
// On Unix, the StdioCtl instance is created just once at the beginning
// On Unix, the ConsoleCtl instance is created just once at the beginning
// of the program execution (in static initialization) and destroyed when
// exiting the program.

// Creates a global instance if none exists, and returns it.
static StdioCtl &getInstance() noexcept;
static ConsoleCtl &getInstance() noexcept;
// Destroys the global instance if it exists.
static void destroyInstance() noexcept;

Expand All @@ -65,4 +65,4 @@ class StdioCtl final

} //namespace tvision

#endif // TVISION_STDIOCTL_H
#endif // TVISION_CONCTL_H
4 changes: 2 additions & 2 deletions include/tvision/internal/far2l.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ namespace tvision
ParseResult parseFar2lAnswer(GetChBuf &, TEvent &, InputState &) noexcept;
ParseResult parseFar2lInput(GetChBuf &, TEvent &, InputState &) noexcept;

bool setFar2lClipboard(StdioCtl &, TStringView, InputState &) noexcept;
bool requestFar2lClipboard(StdioCtl &, InputState &) noexcept;
bool setFar2lClipboard(ConsoleCtl &, TStringView, InputState &) noexcept;
bool requestFar2lClipboard(ConsoleCtl &, InputState &) noexcept;

} // namespace tvision

Expand Down
11 changes: 6 additions & 5 deletions include/tvision/internal/linuxcon.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@ struct TEvent;
namespace tvision
{

class ConsoleCtl;
class SigwinchHandler;
class GpmInput;
struct InputState;

struct LinuxConsoleInput final : public EventSource
{
StdioCtl &io;
ConsoleCtl &con;
InputStrategy &input;

LinuxConsoleInput(StdioCtl &aIo, InputStrategy &aInput) noexcept :
LinuxConsoleInput(ConsoleCtl &aCon, InputStrategy &aInput) noexcept :
EventSource(aInput.handle),
io(aIo),
con(aCon),
input(aInput)
{
}
Expand Down Expand Up @@ -51,9 +52,9 @@ class LinuxConsoleStrategy : public ConsoleStrategy
public:

// Pre: 'io.isLinuxConsole()' returns 'true'.
// The lifetime of 'io' and 'displayBuf' must exceed that of the returned object.
// The lifetime of 'con' and 'displayBuf' must exceed that of the returned object.
// Takes ownership over 'inputState', 'display' and 'input'.
static LinuxConsoleStrategy &create( StdioCtl &io,
static LinuxConsoleStrategy &create( ConsoleCtl &con,
DisplayBuffer &displayBuf,
InputState &inputState,
DisplayStrategy &display,
Expand Down
4 changes: 2 additions & 2 deletions include/tvision/internal/ncurdisp.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class NcursesDisplay : public TerminalDisplay
{
public:

// The lifetime of 'io' exceeds that of 'this'.
NcursesDisplay(StdioCtl &io) noexcept;
// The lifetime of 'con' exceeds that of 'this'.
NcursesDisplay(ConsoleCtl &con) noexcept;
~NcursesDisplay();

private:
Expand Down
6 changes: 3 additions & 3 deletions include/tvision/internal/ncursinp.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class NcursesInput : public InputStrategy
enum : char { KEY_ESC = '\x1B' };
enum { readTimeoutMs = 10 };

StdioCtl &io;
ConsoleCtl &con;
InputState &state;
bool mouseEnabled;
NcursesInputGetter in;
Expand All @@ -44,8 +44,8 @@ class NcursesInput : public InputStrategy

public:

// Lifetimes of 'io', 'display' and 'state' must exceed that of 'this'.
NcursesInput(StdioCtl &io, NcursesDisplay &display, InputState &state, bool mouse) noexcept;
// Lifetimes of 'con', 'display' and 'state' must exceed that of 'this'.
NcursesInput(ConsoleCtl &con, NcursesDisplay &display, InputState &state, bool mouse) noexcept;
~NcursesInput();

bool getEvent(TEvent &ev) noexcept override;
Expand Down
1 change: 0 additions & 1 deletion include/tvision/internal/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#define Uses_TPoint
#define Uses_TColorAttr
#include <tvision/tv.h>
#include <internal/stdioctl.h>
#include <internal/dispbuff.h>
#include <internal/events.h>
#include <internal/mutex.h>
Expand Down
10 changes: 6 additions & 4 deletions include/tvision/internal/termdisp.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
namespace tvision
{

class ConsoleCtl;

// Terminal quirk flags.

const uint
Expand Down Expand Up @@ -39,7 +41,7 @@ class TerminalDisplay : public DisplayStrategy

protected:

StdioCtl &io;
ConsoleCtl &con;
TermCap termcap;

// The subclass must invoke this in the constructor.
Expand All @@ -50,9 +52,9 @@ class TerminalDisplay : public DisplayStrategy

public:

// The lifetime of 'aIo' exceeds that of 'this'.
TerminalDisplay(StdioCtl &aIo) noexcept :
io(aIo)
// The lifetime of 'aCon' exceeds that of 'this'.
TerminalDisplay(ConsoleCtl &aCon) noexcept :
con(aCon)
{
}

Expand Down
16 changes: 8 additions & 8 deletions include/tvision/internal/termio.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace tvision
{

class StdioCtl;
class ConsoleCtl;

struct Far2lState
{
Expand Down Expand Up @@ -120,15 +120,15 @@ inline uint CSIData::getValue(uint i, uint defaultValue) const noexcept

namespace TermIO
{
void mouseOn(StdioCtl &) noexcept;
void mouseOff(StdioCtl &) noexcept;
void keyModsOn(StdioCtl &) noexcept;
void keyModsOff(StdioCtl &) noexcept;
void mouseOn(ConsoleCtl &) noexcept;
void mouseOff(ConsoleCtl &) noexcept;
void keyModsOn(ConsoleCtl &) noexcept;
void keyModsOff(ConsoleCtl &) noexcept;

void normalizeKey(KeyDownEvent &keyDown) noexcept;

bool setClipboardText(StdioCtl &, TStringView, InputState &) noexcept;
bool requestClipboardText(StdioCtl &, void (&)(TStringView), InputState &) noexcept;
bool setClipboardText(ConsoleCtl &, TStringView, InputState &) noexcept;
bool requestClipboardText(ConsoleCtl &, void (&)(TStringView), InputState &) noexcept;

ParseResult parseEvent(GetChBuf&, TEvent&, InputState&) noexcept;
ParseResult parseEscapeSeq(GetChBuf&, TEvent&, InputState&) noexcept;
Expand All @@ -145,7 +145,7 @@ namespace TermIO
ParseResult parseWin32InputModeKeyOrEscapeSeq(const CSIData &, InputGetter&, TEvent&, InputState&) noexcept;

char *readUntilBelOrSt(GetChBuf &) noexcept;
void consumeUnprocessedInput(StdioCtl &, InputGetter &, InputState &) noexcept;
void consumeUnprocessedInput(ConsoleCtl &, InputGetter &, InputState &) noexcept;
}

} // namespace tvision
Expand Down
9 changes: 5 additions & 4 deletions include/tvision/internal/unixcon.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace tvision
{

class ConsoleCtl;
class SigwinchHandler;
struct InputState;
class DisplayBuffer;
Expand All @@ -17,20 +18,20 @@ class UnixConsoleStrategy : public ConsoleStrategy
{
StderrRedirector errRedir;

StdioCtl &io;
ConsoleCtl &con;
DisplayBuffer &displayBuf;
InputState &inputState;
SigwinchHandler *sigwinch;

UnixConsoleStrategy( DisplayStrategy &, InputStrategy &, StdioCtl &,
UnixConsoleStrategy( DisplayStrategy &, InputStrategy &, ConsoleCtl &,
DisplayBuffer &, InputState &,
SigwinchHandler * ) noexcept;

public:

// The lifetime of 'io' and 'displayBuf' must exceed that of the returned object.
// The lifetime of 'con' and 'displayBuf' must exceed that of the returned object.
// Takes ownership over 'inputState', 'display' and 'input'.
static UnixConsoleStrategy &create( StdioCtl &io,
static UnixConsoleStrategy &create( ConsoleCtl &con,
DisplayBuffer &displayBuf,
InputState &inputState,
DisplayStrategy &display,
Expand Down
22 changes: 9 additions & 13 deletions include/tvision/internal/win32con.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ void getWin32Mouse(const MOUSE_EVENT_RECORD &, TEvent &, InputState &) noexcept;

#ifdef _WIN32

class StdioCtl;
class ConsoleCtl;
class Win32Input;
class Win32Display;

class Win32ConsoleStrategy final : public ConsoleStrategy
{
StdioCtl &io;
ConsoleCtl &con;
UINT cpInput, cpOutput;

Win32ConsoleStrategy( StdioCtl &aIo,
Win32ConsoleStrategy( ConsoleCtl &aCon,
UINT cpInput, UINT cpOutput,
DisplayStrategy &aDisplay,
InputStrategy &aInput ) noexcept :
ConsoleStrategy(aDisplay, aInput, {&aInput}),
io(aIo),
con(aCon),
cpInput(cpInput),
cpOutput(cpOutput)
{
Expand All @@ -49,20 +49,16 @@ class Win32ConsoleStrategy final : public ConsoleStrategy

class Win32Input final : public InputStrategy
{
StdioCtl &io;
ConsoleCtl &con;
InputState state;

bool getEvent(const INPUT_RECORD &, TEvent &ev) noexcept;
bool getMouseEvent(MOUSE_EVENT_RECORD, TEvent &ev) noexcept;

public:

// The lifetime of 'aIo' must exceed that of 'this'.
Win32Input(StdioCtl &aIo) noexcept :
InputStrategy(aIo.in()),
io(aIo)
{
}
// The lifetime of 'con' must exceed that of 'this'.
Win32Input(ConsoleCtl &aCon) noexcept;

bool getEvent(TEvent &ev) noexcept override;
int getButtonCount() noexcept override;
Expand All @@ -74,8 +70,8 @@ class Win32Display : public TerminalDisplay
{
public:

// The lifetime of 'aIo' must exceed that of 'this'.
Win32Display(StdioCtl &aIo, bool useAnsi) noexcept;
// The lifetime of 'con' must exceed that of 'this'.
Win32Display(ConsoleCtl &con, bool useAnsi) noexcept;
~Win32Display();

private:
Expand Down
3 changes: 2 additions & 1 deletion source/platform/ansiwrit.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <internal/ansiwrit.h>
#include <internal/termdisp.h>
#include <internal/strings.h>
#include <internal/conctl.h>
#include <stdlib.h>

#define CSI "\x1B["
Expand Down Expand Up @@ -116,7 +117,7 @@ void AnsiScreenWriter::lowlevelMoveCursor(uint x, uint y) noexcept

void AnsiScreenWriter::lowlevelFlush() noexcept
{
io.write(buf.data(), buf.size());
con.write(buf.data(), buf.size());
buf.clear();
}

Expand Down
Loading

0 comments on commit 3518c8c

Please sign in to comment.