Skip to content

Commit

Permalink
Provide additional information about the display's color capabilities
Browse files Browse the repository at this point in the history
See #52.
  • Loading branch information
magiblot committed Apr 6, 2021
1 parent 6e5a7b4 commit a1b4887
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 23 deletions.
1 change: 0 additions & 1 deletion include/tvision/internal/ncurdisp.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class NcursesDisplay : public TerminalDisplay {
int getColorCount() override;

void clearScreen() override;
ushort getScreenMode() override;

protected:

Expand Down
2 changes: 2 additions & 0 deletions include/tvision/internal/termdisp.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class TerminalDisplay : public BufferedDisplay
virtual int getColorCount();
virtual TermCap getCapabilities();

ushort getScreenMode() override;

};

#endif // TVISION_TERMDISP_H
1 change: 0 additions & 1 deletion include/tvision/internal/win32con.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ class Win32Display : public TerminalDisplay
int getColorCount() override;

void clearScreen() override;
ushort getScreenMode() override;

protected:

Expand Down
2 changes: 2 additions & 0 deletions include/tvision/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ class TDisplay
smCO80 = 0x0003,
smMono = 0x0007,
smFont8x8 = 0x0100,
smColor256 = 0x0200,
smColorHigh = 0x0400,
smChanged = 0x1000
};

Expand Down
17 changes: 1 addition & 16 deletions source/platform/ncurdisp.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#ifdef HAVE_NCURSES

#define Uses_TScreen
#define Uses_TColorAttr
#include <tvision/tv.h>

Expand All @@ -26,8 +25,7 @@ NcursesDisplay::NcursesDisplay() :
exit(1);
}
// Enable colors if the terminal supports it.
hasColors = getScreenMode() & TDisplay::smCO80;
if (hasColors)
if ((hasColors = has_colors()))
start_color();
/* Refresh now so that a possible first getch() doesn't make any relevant
* changes to the screen due to its implicit refresh(). */
Expand Down Expand Up @@ -78,19 +76,6 @@ void NcursesDisplay::clearScreen() { flushScreen(); wclear(stdscr); lowlevelFlus
void NcursesDisplay::lowlevelMoveCursor(uint x, uint y) { wmove(stdscr, y, x); }
void NcursesDisplay::lowlevelFlush() { wrefresh(stdscr); }

ushort NcursesDisplay::getScreenMode()
{
/* The original implementation just reads the video mode, and sets the small font
* if the number of rows is greater than 25.
* This function is called from TDisplay::getCrtMode, which just returns the
* value this does, and it is then assigned to a attribute of TScreen.
*
* For the time being, we will only use the video mode to tell Turbo Vision
* to use color or monochrome formatting according to the terminal capabilities.
* The video mode does not determine the number of rows or columns used. */
return has_colors() ? TDisplay::smCO80 : TDisplay::smMono;
}

void NcursesDisplay::lowlevelCursorSize(int size)
{
/* The caret is the keyboard cursor. If size is 0, the caret is hidden. The
Expand Down
17 changes: 17 additions & 0 deletions source/platform/termdisp.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#define Uses_TScreen
#include <tvision/tv.h>

#include <internal/termdisp.h>
#include <internal/terminal.h>
#include <internal/getenv.h>
Expand Down Expand Up @@ -39,3 +42,17 @@ TermCap TerminalDisplay::getCapabilities()
return termcap;
}

ushort TerminalDisplay::getScreenMode()
{
if (termcap.colors == NoColor)
return TDisplay::smMono;
else
{
ushort mode = TDisplay::smCO80;
if (termcap.colors == Direct)
mode |= TDisplay::smColor256 | TDisplay::smColorHigh;
else if (termcap.colors == Indexed256)
mode |= TDisplay::smColor256;
return mode;
}
}
5 changes: 0 additions & 5 deletions source/platform/win32con.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,11 +389,6 @@ void Win32Display::clearScreen()
lastAttr = attr;
}

ushort Win32Display::getScreenMode()
{
return TDisplay::smCO80;
}

// Fallback display support with rudimentary buffering.

void Win32Display::lowlevelWriteChars(TStringView chars, TColorAttr attr)
Expand Down

0 comments on commit a1b4887

Please sign in to comment.