Giter Club home page Giter Club logo

tvision's Introduction

Turbo Vision

A modern port of Turbo Vision 2.0, the classical framework for text-based user interfaces. Now cross-platform and with Unicode support.

tvedit in Konsole

I started this as a personal project at the very end of 2018. By May 2020 I considered it was very close to feature parity with the original, and decided to make it open.

The original goals of this project were:

  • Making Turbo Vision work on Linux by altering the legacy codebase as little as possible.
  • Keeping it functional on DOS/Windows.
  • Being as compatible as possible at the source code level with old Turbo Vision applications. This led me to implement some of the Borland C++ RTL functions, as explained below.

At one point I considered I had done enough, and that any attempts at revamping the library and overcoming its original limitations would require either extending the API or breaking backward compatibility, and that a major rewrite would be most likely necessary.

However, between July and August 2020 I found the way to integrate full-fledged Unicode support into the existing architecture, wrote the Turbo text editor and also made the new features available on Windows. So I am confident that Turbo Vision can now meet many of the expectations of modern users and programmers.

The original location of this project is https://github.com/magiblot/tvision.

Table of contents

What is Turbo Vision good for?

A lot has changed since Borland created Turbo Vision in the early 90's. Many GUI tools today separate appearance specification from behaviour specification, use safer or dynamic languages which do not segfault on error, and support either parallel or asynchronous programming, or both.

Turbo Vision does not excel at any of those, but it certainly overcomes many of the issues programmers still face today when writing terminal applications:

  1. Forget about terminal capabilities and direct terminal I/O. When writing a Turbo Vision application, all you have to care about is what you want your application to behave and look like—there is no need to add workarounds in your code. Turbo Vision tries its best to produce the same results on all environments. For example: in order to get a bright background color on the Linux console, the blink attribute has to be set. Turbo Vision does this for you.

  2. Reuse what has already been done. Turbo Vision provides many widget classes (also known as views), including resizable, overlapping windows, pull-down menus, dialog boxes, buttons, scroll bars, input boxes, check boxes and radio buttons. You may use and extend these; but even if you prefer creating your own, Turbo Vision already handles event dispatching, display of fullwidth Unicode characters, etc.: you do not need to waste time rewriting any of that.

  3. Can you imagine writing a text-based interface that works both on Linux and Windows (and thus is cross-platform) out-of-the-box, with no #ifdefs? Turbo Vision makes this possible. First: Turbo Vision keeps on using char arrays instead of relying on the implementation-defined and platform-dependent wchar_t or TCHAR. Second: thanks to UTF-8 support in setlocale in recent versions of Microsoft's RTL, code like the following will work as intended:

    std::ifstream f("コンピュータ.txt"); // On Windows, the RTL converts this to the system encoding on-the-fly.

How do I use Turbo Vision?

You can get started with the Turbo Vision For C++ User's Guide, and look at the sample applications hello, tvdemo and tvedit. Once you grasp the basics, I suggest you take a look at the Turbo Vision 2.0 Programming Guide, which is, in my opinion, more intuitive and easier to understand, despite using Pascal. By then you will probably be interested in the palette example, which contains a detailed description of how palettes are used.

Don't forget to check out the features and API changes sections as well.

Releases and downloads

This project has no stable releases for the time being. If you are a developer, try to stick to the latest commit and report any issues you find while upgrading.

If you just want to test the demo applications:

  • Unix systems: you'll have to build Turbo Vision yourself. You may follow the build instructions below.
  • Windows: you can find up-to-date binaries in the Actions section. Click on the first successful workflow (with a green tick) in the list. At the bottom of the workflow page, as long as you have logged in to GitHub, you'll find an Artifacts section with the following files:
    • examples-dos32.zip: 32-bit executables built with Borland C++. No Unicode support.
    • examples-x86.zip: 32-bit executables built with MSVC. Windows Vista or later required.
    • examples-x64.zip: 64-bit executables built with MSVC. x64 Windows Vista or later required.

Build environment

Linux

Turbo Vision can be built as an static library with CMake and GCC/Clang.

cmake . -B ./build -DCMAKE_BUILD_TYPE=Release && # Could also be 'Debug', 'MinSizeRel' or 'RelWithDebInfo'.
cmake --build ./build # or `cd ./build; make`

CMake versions older than 3.13 may not support the -B option. You can try the following instead:

mkdir -p build; cd build
cmake .. -DCMAKE_BUILD_TYPE=Release &&
cmake --build .

The above produces the following files:

  • libtvision.a, which is the Turbo Vision library.
  • The demo applications hello, tvdemo, tvedit, tvdir, which were bundled with the original Turbo Vision (although some of them have a few improvements).
  • The demo applications mmenu and palette from Borland's Technical Support.
  • tvhc, the Turbo Vision Help Compiler.

The library and executables can be found in ./build.

The build requirements are:

  • A compiler supporting C++14.
  • libncursesw (note the 'w').
  • libgpm for mouse support on the Linux console (optional).

If your distribution provides separate devel packages (e.g. libncurses-dev, libgpm-dev in Debian-based distros), install these too.

The runtime requirements are:

  • xsel or xclip for clipboard support in X11 environments.
  • wl-clipboard for clipboard support in Wayland environments.

The minimal command line required to build a Turbo Vision application (e.g. hello.cpp with GCC) from this project's root is:

g++ -std=c++14 -o hello hello.cpp ./build/libtvision.a -Iinclude -lncursesw -lgpm

You may also need:

  • -Iinclude/tvision if your application uses Turbo Vision 1.x includes (#include <tv.h> instead of #include <tvision/tv.h>).

  • -Iinclude/tvision/compat/borland if your application includes Borland headers (dir.h, iostream.h, etc.).

  • On Gentoo (and possibly others): -ltinfow if both libtinfo.so and libtinfow.so are available in your system. Otherwise, you may get a segmentation fault when running Turbo Vision applications (#11). Note that tinfo is bundled with ncurses.

-lgpm is only necessary if Turbo Vision was built with libgpm support.

The backward-compatibility headers in include/tvision/compat/borland emulate the Borland C++ RTL. Turbo Vision's source code still depends on them, and they could be useful if porting old applications. This also means that including tvision/tv.h will bring several std names to the global namespace.

Windows (MSVC)

The build process with MSVC is slightly more complex, as there are more options to choose from. Note that you will need different build directories for different target architectures. For instance, to generate optimized binaries:

cmake . -B ./build && # Add '-A x64' (64-bit) or '-A Win32' (32-bit) to override the default platform.
cmake --build ./build --config Release # Could also be 'Debug', 'MinSizeRel' or 'RelWithDebInfo'.

In the example above, tvision.lib and the example applications will be placed at ./build/Release.

If you wish to link Turbo Vision statically against Microsoft's run-time library (/MT instead of /MD), enable the TV_USE_STATIC_RTL option (-DTV_USE_STATIC_RTL=ON when calling cmake).

If you wish to link an application against Turbo Vision, note that MSVC won't allow you to mix /MT with /MD or debug with non-debug binaries. All components have to be linked against the RTL in the same way.

If you develop your own Turbo Vision application make sure to enable the following compiler flags, or else you will get compilation errors when including <tvision/tv.h>:

/permissive-
/Zc:__cplusplus

If you use Turbo Vision as a CMake submodule, these flags will be enabled automatically.

Note: Turbo Vision uses setlocale to set the RTL functions in UTF-8 mode. This won't work if you use an old version of the RTL.

With the RTL statically linked in, and if UTF-8 is supported in setlocale, Turbo Vision applications are portable and work by default on Windows Vista and later.

Windows (MinGW)

Once your MinGW environment is properly set up, build is done in a similar way to Linux:

cmake . -B ./build -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release &&
cmake --build ./build

In the example above, libtvision.a and all examples are in ./build if TV_BUILD_EXAMPLES option is ON (the default).

If you wish to link an application against Turbo Vision, simply add -L./build/lib -ltvision to your linker and -I./include to your compiler

Windows/DOS (Borland C++)

Turbo Vision can still be built either as a DOS or Windows library with Borland C++. Obviously, there is no Unicode support here.

I can confirm the build process works with:

  • Borland C++ 4.52 with the Borland PowerPack for DOS.
  • Turbo Assembler 4.0.

You may face different problems depending on your build environment. For instance, Turbo Assembler needs a patch to work under Windows 95. On Windows XP everything seems to work fine. On Windows 10, MAKE may emit the error Fatal: Command arguments too long, which can be fixed by upgrading MAKE to the one bundled with Borland C++ 5.x.

Yes, this works on 64-bit Windows 10. What won't work is the Borland C++ installer, which is a 16-bit application. You will have to run it on another environment or try your luck with winevdm.

A Borland Makefile can be found in the project directory. Build can be done by doing:

cd project
make.exe <options>

Where <options> can be:

  • -DDOS32 for 32-bit DPMI applications (which still work on 64-bit Windows).
  • -DWIN32 for 32-bit native Win32 applications (not possible for TVDEMO, which relies on farcoreleft() and other antiquities).
  • -DDEBUG to build debug versions of the application and the library.
  • -DTVDEBUG to link the applications with the debug version of the library.
  • -DOVERLAY, -DALIGNMENT={2,4}, -DEXCEPTION, -DNO_STREAMABLE, -DNOTASM for things I have nave never used but appeared in the original makefiles.

This will compile the library into a LIB directory next to project, and will compile executables for the demo applications in their respective examples/* directories.

I'm sorry, the root makefile assumes it is executed from the project directory. You can still run the original makefiles directly (in source/tvision and examples/*) if you want to use different settings.

Vcpkg

Turbo Vision can be built and installed using the vcpkg dependency manager:

git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh
./vcpkg integrate install
./vcpkg install tvision

The tvision port in vcpkg is kept up to date by Microsoft team members and community contributors. If you find it to be out of date, please create an issue or pull request in the vcpkg repository.

Turbo Vision as a CMake dependency (not Borland C++)

If you choose the CMake build system for your application, there are two main ways to link against Turbo Vision:

  • Installing Turbo Vision and importing it with find_package. Installation depends on the generator type:

    • First, decide an install prefix. The default one will work out-of-the-box, but usually requires admin privileges. On Unix systems, you can use $HOME/.local instead. On Windows, you can use any custom path you want but you'll have to add it to the CMAKE_PREFIX_PATH environment variable when building your application.

    • For mono-config generators (Unix Makefiles, Ninja...), you only have to build and install once:

      cmake . -B ./build # '-DCMAKE_INSTALL_PREFIX=...' to override the install prefix.
      cmake --build ./build
      cmake --install ./build
    • For multi-config generators (Visual Studio, Ninja Multi-Config...) you should build and install all configurations:

      cmake . -B ./build # '-DCMAKE_INSTALL_PREFIX=...' to override the install prefix.
      cmake --build ./build --config Release
      cmake --build ./build --config Debug --target tvision
      cmake --build ./build --config RelWithDebInfo --target tvision
      cmake --build ./build --config MinSizeRel --target tvision
      cmake --install ./build --config Release
      cmake --install ./build --config Debug --component library
      cmake --install ./build --config RelWithDebInfo --component library
      cmake --install ./build --config MinSizeRel --component library

    Then, in your application's CMakeLists.txt, you may import it like this:

    find_package(tvision CONFIG)
    target_link_libraries(my_application tvision::tvision)
  • Have Turbo Vision in a submodule in your repository and import it with add_subdirectory:

    add_subdirectory(tvision) # Assuming Turbo Vision is in the 'tvision' directory.
    target_link_libraries(my_application tvision)

In either case, <tvision/tv.h> will be available in your application's include path during compilation, and your application will be linked against the necessary libraries (Ncurses, GPM...) automatically.

Features

Modern platforms (not Borland C++)

  • UTF-8 support. You can try it out in the tvedit application.
  • 24-bit color support (up from the original 16 colors).
  • 'Open File' dialogs accepts both Unix and Windows-style file paths and can expand ~/ into $HOME.
  • Redirection of stdin/stdout/stderr does not interfere with terminal I/O.
  • Compatibility with 32-bit help files.

There are a few environment variables that affect the behaviour of all Turbo Vision applications:

  • TVISION_MAX_FPS: maximum refresh rate, default 60. This can help keep smoothness in terminal emulators with unefficient handling of box-drawing characters. Special values for this option are 0, to disable refresh rate limiting, and -1, to actually draw to the terminal in every call to THardwareInfo::screenWrite (useful when debugging).

  • TVISION_CODEPAGE: the character set used internally by Turbo Vision to translate extended ASCII into Unicode. Valid values at the moment are 437 and 850, with 437 being the default, although adding more takes very little effort.

Unix

  • Ncurses-based terminal support.
  • Extensive mouse and keyboard support:
    • Support for X10 and SGR mouse encodings.
    • Support for Xterm's modifyOtherKeys.
    • Support for Paul Evans' fixterms and Kitty's keyboard protocol.
    • Support for Conpty's win32-input-mode (available in WSL).
    • Support for far2l's terminal extensions.
    • Support for key modifiers (via TIOCLINUX) and mouse (via GPM) in the Linux console.
  • Custom signal handler that restores the terminal state before the program crashes.
  • When stderr is a tty, messages written to it are redirected to a buffer to prevent them from messing up the display and are eventually printed to the console when exiting or suspending the application.
    • The buffer used for this purpose has a limited size, so writes to stderr will fail once the buffer is full. If you wish to preserve all of stderr, just redirect it into a file from the command line with 2>.

The following environment variables are also taken into account:

  • TERM: Ncurses uses it to determine terminal capabilities. It is set automatically by the terminal emulator.

  • COLORTERM: when set to truecolor or 24bit, Turbo Vision will assume the terminal emulator supports 24-bit color. It is set automatically by terminal emulators that support it.

  • TVISION_ESCDELAY: the number of milliseconds to wait after receiving an ESC key press, default 10. If another key is pressed during this delay, it will be interpreted as an Alt+Key combination. Using a larger value is useful when the terminal doesn't support the Alt key.

  • TVISION_USE_STDIO: when not empty, terminal I/O is performed through stdin/stdout, so that it can be redirected from the shell. By default, Turbo Vision performs terminal I/O through /dev/tty, allowing the user to redirect stdin, stdout and stderr for their needs, without affecting the application's stability.

    For example, the following will leave out.txt empty:

    tvdemo | tee out.txt

    While the following will dump all the escape sequences and text printed by the application into out.txt:

    TVISION_USE_STDIO=1 tvdemo | tee out.txt
  • TVISION_DISPLAY: strategy for drawing to screen. Valid values are ansi and ncurses, with ansi being the default. The Ncurses library is used in either case, with the difference that ncurses uses Ncurses' own draw methods and is limited to 16 colors, while ansi supports 24-bit color and avoids redundant buffering and UTF-8 to wide char conversions.

Windows

  • Only compatible with the Win32 Console API. On terminal emulators that don't support this, Turbo Vision will automatically pop up a separate console window.
  • Applications fit the console window size instead of the buffer size (no scrollbars are visible) and the console buffer is restored when exiting or suspending Turbo Vision.

The following are not available when compiling with Borland C++:

  • The console's codepage is set to UTF-8 on startup and restored on exit.
  • Microsoft's C runtime functions are set automatically to UTF-8 mode, so you as a developer don't need to use the wchar_t variants.
  • If the console crashes, a new one is allocated automatically.

Note: Turbo Vision writes UTF-8 text directly to the Windows console. If the console is set in legacy mode and the bitmap font is being used, Unicode characters will not be displayed properly (photo). To avoid this, Turbo Vision detects this situation and tries to change the console font to Consolas or Lucida Console.

All platforms

The following are new features not available in Borland's release of Turbo Vision or in previous open source ports (Sigala, SET):

  • Middle mouse button and mouse wheel support.
  • Arbitrary screen size support (up to 32767 rows or columns) and graceful handling of screen resize events.
  • Windows can be resized from their bottom left corner.
  • Windows can be dragged from empty areas with the middle mouse button.
  • Improved usability of menus: they can be closed by clicking again on the parent menu item.
  • Improved usability of scrollbars: dragging them also scrolls the page. Clicking on an empty area of the scrollbar moves the thumb right under the cursor. They respond by default to mouse wheel events.
  • TInputLines no longer scroll the text display on focus/unfocus, allowing relevant text to stay visible.
  • Support for LF line endings in TFileViewer (tvdemo) and TEditor (tvedit). TEditor preserves the line ending on file save but all newly created files use CRLF by default.
  • TEditor: context menu on right click.
  • TEditor: drag scroll with middle mouse button.
  • TEditor, TInputLine: delete whole words with kbAltBack, kbCtrlBack and kbCtrlDel.
  • TEditor: the Home key toggles between beginning of line and beginning of indented text.
  • TEditor: support for files bigger than 64 KiB on 32-bit or 64-bit builds.
  • tvdemo: event viewer applet useful for event debugging.
  • tvdemo: option to change the background pattern.

API changes

  • Screen writes are buffered and are usually sent to the terminal once for every iteration of the active event loop (see also TVISION_MAX_FPS). If you need to update the screen during a busy loop, you may use TScreen::flushScreen().

  • TDrawBuffer is no longer a fixed-length array and its methods prevent past-the-end array accesses. Therefore, old code containing comparisons against sizeof(TDrawBuffer)/sizeof(ushort) is no longer valid; such checks should be removed.

  • TApplication now provides dosShell(), cascade() and tile(), and handles cmDosShell, cmCascade and cmTile by default. These functions can be customized by overriding getTileRect() and writeShellMsg(). This is the same behaviour as in the Pascal version.

  • Mouse wheel support: new mouse event evMouseWheel. The wheel direction is specified in the new field event.mouse.wheel, whose possible values are mwUp, mwDown, mwLeft or mwRight.

  • Middle mouse button support: new mouse button flag mbMiddleButton.

  • The buttons field in evMouseUp events is no longer empty. It now indicates which button was released.

  • Triple-click support: new mouse event flag meTripleClick.

  • TRect methods move, grow, intersect and Union now return TRect& instead of being void so that they can be chained.

  • TOutlineViewer now allows the root node to have siblings.

  • New function ushort popupMenu(TPoint where, TMenuItem &aMenu, TGroup *receiver=0) which spawns a TMenuPopup on the desktop. See source/tvision/popupmnu.cpp.

  • New virtual method TMenuItem& TEditor::initContextMenu(TPoint p) that determines the entries of the right-click context menu in TEditor.

  • fexpand can now take a second parameter relativeTo.

  • New class TStringView, inspired by std::string_view.

    • Many functions which originally had null-terminated string parameters now receive TStringView instead. TStringView is compatible with std::string_view, std::string and const char * (even nullptr).
  • New class TSpan<T>, inspired by std::span.

  • New classes TDrawSurface and TSurfaceView, see <tvision/surface.h>.

  • The system integration subsystems (THardwareInfo, TScreen, TEventQueue...) are now initialized when constructing a TApplication for the first time, rather than before main. They are still destroyed on exit from main.

  • New method TVMemMgr::reallocateDiscardable() which can be used along allocateDiscardable and freeDiscardable.

  • New method TView::textEvent() which allows receiving text in an efficient manner, see Clipboard interaction.

  • New class TClipboard, see Clipboard interaction.

  • Unicode support, see Unicode.

  • True Color support, see extended colors.

  • New method static void TEvent::waitForEvent(int timeoutMs) which may block for up to timeoutMs milliseconds waiting for input events. If it blocks, it has the side effect of flushing screen updates. It is invoked by TProgram::getEvent() with static int TProgram::eventTimeout (default 20) as argument so that the event loop doesn't consume 100% CPU.

  • New method static void TEvent::putNothing() which puts an evNothing event into the event queue and causes TEvent::waitForEvent() not to block until an evNothing is returned by TEvent::getKeyEvent(). This will usually cause the main thread to wake up from TEvent::waitForEvent() and to invoke TApplication::idle() immediately. This method is thread-safe, so it can be used to unblock the event loop from any other thread.

  • New method void TView::getEvent(TEvent &, int timeoutMs) which allows waiting for an event with an user-provided timeout (instead of TProgram::eventTimeout).

  • It is now possible to specify a maximum text width or maximum character count in TInputLine. This is done through a new parameter in TInputLine's constructor, ushort limitMode, which controls how the second constructor parameter, uint limit, is to be treated. The ilXXXX constants define the possible values of limitMode:

    • ilMaxBytes (the default): the text can be up to limit bytes long, including the null terminator.
    • ilMaxWidth: the text can be up to limit columns wide.
    • ilMaxChars: the text can contain up to limit non-combining characters or graphemes.

    In any case, the text in a TInputLine can never be more than 256 bytes long, including the null terminator.

  • New functions which allow getting the names of Turbo Vision's constants at runtime (e.g. evCommand, kbShiftIns, etc.):

    void printKeyCode(ostream &, ushort keyCode);
    void printControlKeyState(ostream &, ushort controlKeyState);
    void printEventCode(ostream &, ushort eventCode);
    void printMouseButtonState(ostream &, ushort buttonState);
    void printMouseWheelState(ostream &, ushort wheelState);
    void printMouseEventFlags(ostream &, ushort eventFlags);
  • New class TKey which can be used to define new key combinations (e.g. Shift+Alt+Up) by specifying a key code and a mask of key modifiers:

    auto kbShiftAltUp = TKey(kbUp, kbShift | kbAltShift);
    assert(kbCtrlA == TKey('A', kbCtrlShift));
    assert(TKey(kbCtrlTab, kbShift) == TKey(kbTab, kbShift | kbCtrlShift));
    // Create menu hotkeys.
    new TMenuItem("~R~estart", cmRestart, TKey(kbDel, kbCtrlShift | kbAltShift), hcNoContext, "Ctrl-Alt-Del")
    // Examine KeyDown events:
    if (event.keyDown == TKey(kbEnter, kbShift))
        doStuff();
  • New methods which allow the usage of timed events:

    TTimerId TView::setTimer(uint timeoutMs, int periodMs = -1);
    void TView::killTimer(TTimerId id);

    setTimer starts a timer that will first time out in timeoutMs milliseconds and then every periodMs milliseconds.

    If periodMs is negative, the timer only times out a single time and is cleaned up automatically. Otherwise, it will keep timing out periodically until killTimer is invoked.

    When a timer times out, an evBroadcast event with the command cmTimeout is emitted, and message.infoPtr is set to the id of the timed-out timer.

    Timeout events are generated in TProgram::idle(), that is, only if there are no keyboard or mouse events available.

Screenshots

You will find some screenshots here. Feel free to add your own!

Contributing

If you know of any Turbo Vision applications whose source code has not been lost and that could benefit from this, let me know.

Applications using Turbo Vision

If your application is based on this project and you'd like it to appear in the following list, just let me know.

Unicode support

The Turbo Vision API has been extended to allow receiving Unicode input and displaying Unicode text. The supported encoding is UTF-8, for a number of reasons:

  • It is compatible with already present data types (char *), so it does not require intrusive modifications to existing code.
  • It is the same encoding used for terminal I/O, so redundant conversions are avoided.
  • Conformance to the UTF-8 Everywhere Manifesto, which exposes many other advantages.

Note that when built with Borland C++, Turbo Vision does not support Unicode. However, this does not affect the way Turbo Vision applications are written, since the API extensions are designed to allow for encoding-agnostic code.

Reading Unicode input

The traditional way to get text from a key press event is as follows:

// 'ev' is a TEvent, and 'ev.what' equals 'evKeyDown'.
switch (ev.keyDown.keyCode) {
    // Key shortcuts are usually checked first.
    // ...
    default: {
        // The character is encoded in the current codepage
        // (CP437 by default).
        char c = ev.keyDown.charScan.charCode;
        // ...
    }
}

Some of the existing Turbo Vision classes that deal with text input still depend on this methodology, which has not changed. Single-byte characters, when representable in the current codepage, continue to be available in ev.keyDown.charScan.charCode.

Unicode support consists in two new fields in ev.keyDown (which is a struct KeyDownEvent):

  • char text[4], which may contain whatever was read from the terminal: usually a UTF-8 sequence, but possibly any kind of raw data.
  • uchar textLength, which is the number of bytes of data available in text, from 0 to 4.

Note that the text string is not null-terminated. You can get a TStringView out of a KeyDownEvent with the getText() method.

So a Unicode character can be retrieved from TEvent in the following way:

switch (ev.keyDown.keyCode) {
    // ...
    default: {
        std::string_view sv = ev.keyDown.getText();
        processText(sv);
    }
}

Let's see it from another perspective. If the user types ñ, a TEvent is generated with the following keyDown struct:

KeyDownEvent {
    union {
        .keyCode = 0xA4,
        .charScan = CharScanType {
            .charCode = 164 ('ñ'), // In CP437
            .scanCode = 0
        }
    },
    .controlKeyState = 0x200 (kbInsState),
    .text = {'\xC3', '\xB1'}, // In UTF-8
    .textLength = 2
}

However, if they type the following will happen:

KeyDownEvent {
    union {
        .keyCode = 0x0 (kbNoKey), // '€' not part of CP437
        .charScan = CharScanType {
            .charCode = 0,
            .scanCode = 0
        }
    },
    .controlKeyState = 0x200 (kbInsState),
    .text = {'\xE2', '\x82', '\xAC'}, // In UTF-8
    .textLength = 3
}

If a key shortcut is pressed instead, text is empty:

KeyDownEvent {
    union {
        .keyCode = 0xB (kbCtrlK),
        .charScan = CharScanType {
            .charCode = 11 (''),
            .scanCode = 0
        }
    },
    .controlKeyState = 0x20C (kbCtrlShift | kbInsState),
    .text = {},
    .textLength = 0
}

So, in short: views designed without Unicode input in mind will continue to work exactly as they did before, and views which want to be Unicode-aware will have no issues in being so.

Displaying Unicode text

The original design of Turbo Vision uses 16 bits to represent a screen cell—8 bit for a character and 8 bit for BIOS color attributes.

A new TScreenCell type is defined in <tvision/scrncell.h> which is capable of holding a limited number of UTF-8 codepoints in addition to extended attributes (bold, underline, italic...). However, you should not write text into a TScreenCell directly but make use of Unicode-aware API functions instead.

Text display rules

A character provided as argument to any of the Turbo Vision API functions that deal with displaying text is interpreted as follows:

  • Non-printable characters in the range 0x00 to 0xFF are interpreted as characters in the active codepage. For instance, 0x7F is displayed as and 0xF0 as if using CP437. As an exception, 0x00 is always displayed as a regular space. These characters are all one column wide.
  • Character sequences which are not valid UTF-8 are interpreted as sequences of characters in the current codepage, as in the case above.
  • Valid UTF-8 sequences with a display width other than one are taken care of in a special way, see below.

For example, the string "╔[\xFE]╗" may be displayed as ╔[■]╗. This means that box-drawing characters can be mixed with UTF-8 in general, which is useful for backward compatibility. If you rely on this behaviour, though, you may get unexpected results: for instance, "\xC4\xBF" is a valid UTF-8 sequence and is displayed as Ŀ instead of ─┐.

One of the issues of Unicode support is the existence of multi-width characters and combining characters. This conflicts with Turbo Vision's original assumption that the screen is a grid of cells occupied by a single character each. Nevertheless, these cases are handled in the following way:

  • Multi-width characters can be drawn anywhere on the screen and nothing bad happens if they overlap partially with other characters.

  • Zero-width characters overlay the previous character. For example, the sequence में consists of the single-width character and the combining characters and . In this case, three Unicode codepoints are fit into the same cell.

    The ZERO WIDTH JOINER (U+200D) is always omitted, as it complicates things too much. For example, it can turn a string like "👩👦" (4 columns wide) into "👩‍👦" (2 columns wide). Not all terminal emulators respect the ZWJ, so, in order to produce predictable results, Turbo Vision will print both "👩👦" and "👩‍👦" as 👩👦.

  • No notable graphical glitches will occur as long as your terminal emulator respects character widths as measured by wcwidth.

Here is an example of such characters in the Turbo text editor: Wide character display

Unicode-aware API functions

The usual way of writing to the screen is by using TDrawBuffer. A few methods have been added and others have changed their meaning:

void TDrawBuffer::moveChar(ushort indent, char c, TColorAttr attr, ushort count);
void TDrawBuffer::putChar(ushort indent, char c);

c is always interpreted as a character in the active codepage.

ushort TDrawBuffer::moveStr(ushort indent, TStringView str, TColorAttr attr);
ushort TDrawBuffer::moveCStr(ushort indent, TStringView str, TAttrPair attrs);

str is interpreted according to the rules exposed previously.

ushort TDrawBuffer::moveStr(ushort indent, TStringView str, TColorAttr attr, ushort width, ushort begin = 0); // New
ushort TDrawBuffer::moveCStr(ushort indent, TStringView str, TColorAttr attr, ushort width, ushort begin = 0); // New

str is interpreted according to the rules exposed previously, but:

  • width specifies the maximum number of display columns that should be read from str.
  • begin specifies the number of display columns that should be skipped at the beginning of str. This is useful for horizontal scrolling. If begin is in the middle of a multi-width character, the remaining positions in that character are filled with spaces.

The return values are the number of display columns that were actually filled with text.

void TDrawBuffer::moveBuf(ushort indent, const void *source, TColorAttr attr, ushort count);

The name of this function is misleading. Even in its original implementation, source is treated as a string. So it is equivalent to moveStr(indent, TStringView((const char*) source, count), attr).

There are other useful Unicode-aware functions:

int cstrlen(TStringView s);

Returns the displayed length of s according to the aforementioned rules, discarding ~ characters.

int strwidth(TStringView s); // New

Returns the displayed length of s.

On Borland C++, these methods assume a single-byte encoding and all characters being one column wide. This makes it possible to write encoding-agnostic draw() and handleEvent() methods that work on both platforms without a single #ifdef.

The functions above are implemented using the functions from the TText namespace, another API extension. You will have to use them directly if you want to fill TScreenCell objects with text manually. To give an example, below are some of the TText functions. You can find all of them with complete descriptions in <tvision/ttext.h>.

size_t TText::next(TStringView text);
size_t TText::prev(TStringView text, size_t index);
void TText::drawChar(TSpan<TScreenCell> cells, char c);
size_t TText::drawStr(TSpan<TScreenCell> cells, size_t indent, TStringView text, int textIndent);
bool TText::drawOne(TSpan<TScreenCell> cells, size_t &i, TStringView text, size_t &j);

For drawing TScreenCell buffers into a view, the following methods are available:

void TView::writeBuf(short x, short y, short w, short h, const TScreenCell *b); // New
void TView::writeLine(short x, short y, short w, short h, const TScreenCell *b); // New

Example: Unicode text in menus and status bars

It's as simple as it can be. Let's modify hello.cpp as follows:

TMenuBar *THelloApp::initMenuBar( TRect r )
{
    r.b.y = r.a.y+1;
    return new TMenuBar( r,
      *new TSubMenu( "~Ñ~ello", kbAltH ) +
        *new TMenuItem( "階~毎~料入報最...", GreetThemCmd, kbAltG ) +
        *new TMenuItem( "五劫~の~擦り切れ", cmYes, kbNoKey, hcNoContext ) +
        *new TMenuItem( "העברית ~א~ינטרנט", cmNo, kbNoKey, hcNoContext ) +
         newLine() +
        *new TMenuItem( "E~x~it", cmQuit, cmQuit, hcNoContext, "Alt-X" )
        );
}

TStatusLine *THelloApp::initStatusLine( TRect r )
{
    r.a.y = r.b.y-1;
    return new TStatusLine( r,
        *new TStatusDef( 0, 0xFFFF ) +
            *new TStatusItem( "~Alt-Ç~ Exit", kbAltX, cmQuit ) +
            *new TStatusItem( 0, kbF10, cmMenu )
            );
}

Here is what it looks like:

Unicode Hello

Example: writing Unicode-aware draw() methods

The following is an excerpt from an old implementation of TFileViewer::draw() (part of the tvdemo application), which does not draw Unicode text properly:

if (delta.y + i < fileLines->getCount()) {
    char s[maxLineLength+1];
    p = (char *)(fileLines->at(delta.y+i));
    if (p == 0 || strlen(p) < delta.x)
        s[0] = EOS;
    else
        strnzcpy(s, p+delta.x, maxLineLength+1);
    b.moveStr(0, s, c);
}
writeBuf( 0, i, size.x, 1, b );

All it does is move part of a string in fileLines into b, which is a TDrawBuffer. delta is a TPoint representing the scroll offset in the text view, and i is the index of the visible line being processed. c is the text color. A few issues are present:

  • TDrawBuffer::moveStr(ushort, const char *, TColorAttr) takes a null-terminated string. In order to pass a substring of the current line, a copy is made into the array s, at the risk of a buffer overrun. The case where the line does not fit into s is not handled, so at most maxLineLenght characters will be copied. What's more, a multibyte character near position maxLineLength could be copied incompletely and be displayed as garbage.
  • delta.x is the first visible column. With multibyte-encoded text, it is no longer true that such column begins at position delta.x in the string.

Below is a corrected version of the code above that handles Unicode properly:

if (delta.y + i < fileLines->getCount()) {
    p = (char *)(fileLines->at(delta.y+i));
    if (p)
        b.moveStr(0, p, c, size.x, delta.x);
}
writeBuf( 0, i, size.x, 1, b );

The overload of moveStr used here is TDrawBuffer::moveStr(ushort indent, TStringView str, TColorAttr attr, ushort width, ushort begin). This function not only provides Unicode support, but also helps us write cleaner code and overcome some of the limitations previously present:

  • The intermediary copy is avoided, so the displayed text is not limited to maxLineLength bytes.
  • moveStr takes care of printing the string starting at column delta.x. We do not even need to worry about how many bytes correspond to delta.x columns.
  • Similarly, moveStr is instructed to copy at most size.x columns of text without us having to care about how many bytes that is nor dealing with edge cases. The code is written in an encoding-agnostic way and will work whether multibyte characters are being considered or not.
  • In case you hadn't realized yet, the intermediary copy in the previous version was completely unnecessary. It would have been necessary only if we had needed to trim the end of the line, but that was not the case: text occupies all of the view's width, and TView::writeBuf already takes care of not writing beyond it. Yet it is interesting to see how an unnecessary step not only was limiting functionality but also was prone to bugs.

Unicode support across standard views

Support for creating Unicode-aware views is in place, and most views in the original Turbo Vision library have been adapted to handle Unicode.

The following views can display Unicode text properly. Some of them also do horizontal scrolling or word wrapping; all of that should work fine.

The following views can, in addition, process Unicode text or user input:

  • TInputLine (81066ee5, cb489d42).
  • TEditor (702114dc). Instances are in UTF-8 mode by default. You may switch back to single-byte mode by pressing Ctrl+P. This only changes how the document is displayed and the encoding of user input; it does not alter the document. This class is used in the tvedit application; you may test it there.

Views not in this list may not have needed any corrections or I simply forgot to fix them. Please submit an issue if you notice anything not working as expected.

Use cases where Unicode is not supported (not an exhaustive list):

  • Highlighted key shortcuts, in general (e.g. TMenuBox, TStatusLine, TButton...).

Clipboard interaction

Originally, Turbo Vision offered no integration with the system clipboard, since there was no such thing on MS-DOS.

It did offer the possibility of using an instance of TEditor as an internal clipboard, via the TEditor::clipboard static member. However, TEditor was the only class able to interact with this clipboard. It was not possible to use it with TInputLine, for example.

Turbo Vision applications are now most likely to be ran in a graphical environment through a terminal emulator. In this context, it would be desirable to interact with the system clipboard in the same way as a regular GUI application would do.

To deal with this, a new class TClipboard has been added which allows accessing the system clipboard. If the system clipboard is not accessible, it will instead use an internal clipboard.

Enabling clipboard support

On Windows (including WSL) and macOS, clipboard integration is supported out-of-the-box.

On Unix systems other than macOS, it is necessary to install some external dependencies. See runtime requirements.

For applications running remotely (e.g. through SSH), clipboard integration is supported in the following situations:

  • When X11 forwarding over SSH is enabled (ssh -X).
  • When your terminal emulator supports far2l's terminal extensions (far2l, putty4far2l).
  • When your terminal emulator supports OSC 52 escape codes:
    • alacritty, kitty, foot.
    • xterm, if the allowWindowOps option is enabled.
    • A few other terminals only support the Copy action.

Additionally, it is always possible to paste text using your terminal emulator's own Paste command (usually Ctrl+Shift+V or Cmd+V).

API usage

To use the TClipboard class, define the macro Uses_TClipboard before including <tvision/tv.h>.

Writing to the clipboard

static void TClipboard::setText(TStringView text);

Sets the contents of the system clipboard to text. If the system clipboard is not accessible, an internal clipboard is used instead.

Reading the clipboard

static void TClipboard::requestText();

Requests the contents of the system clipboard asynchronously, which will be later received in the form of regular evKeyDown events. If the system clipboard is not accessible, an internal clipboard is used instead.

Processing Paste events

A Turbo Vision application may receive a Paste event for two different reasons:

  • Because TClipboard::requestText() was invoked.
  • Because the user pasted text through the terminal.

In both cases the application will receive the clipboard contents in the form of regular evKeyDown events. These events will have a kbPaste flag in keyDown.controlKeyState so that they can be distinguished from regular key presses.

Therefore, if your view can handle user input it will also handle Paste events by default. However, if the user pastes 5000 characters, the application will behave as if the user pressed the keyboard 5000 times. This involves drawing views, completing the event loop, updating the screen..., which is far from optimal if your view is a text editing component, for example.

For the purpose of dealing with this situation, another function has been added:

bool TView::textEvent(TEvent &event, TSpan<char> dest, size_t &length);

textEvent() attempts to read text from consecutive evKeyDown events and stores it in a user-provided buffer dest. It returns false when no more events are available or if a non-text event is found, in which case this event is saved with putEvent() so that it can be processed in the next iteration of the event loop. Finally, it calls clearEvent(event).

The exact number of bytes read is stored in the output parameter length, which will never be larger than dest.size().

Here is an example on how to use it:

// 'ev' is a TEvent, and 'ev.what' equals 'evKeyDown'.
// If we received text from the clipboard...
if (ev.keyDown.controlKeyState & kbPaste) {
    char buf[512];
    size_t length;
    // Fill 'buf' with the text in 'ev' and in
    // upcoming events from the input queue.
    while (textEvent(ev, buf, length)) {
        // Process 'length' bytes of text in 'buf'...
    }
}

Enabling application-wide clipboard usage

The standard views TEditor and TInputLine react to the cmCut, cmCopy and cmPaste commands. However, your application first has to be set up to use these commands. For example:

TStatusLine *TMyApplication::initStatusLine( TRect r )
{
    r.a.y = r.b.y - 1;
    return new TStatusLine( r,
        *new TStatusDef( 0, 0xFFFF ) +
            // ...
            *new TStatusItem( 0, kbCtrlX, cmCut ) +
            *new TStatusItem( 0, kbCtrlC, cmCopy ) +
            *new TStatusItem( 0, kbCtrlV, cmPaste ) +
            // ...
    );
}

TEditor and TInputLine automatically enable and disable these commands. For example, if a TEditor or TInputLine is focused, the cmPaste command will be enabled. If there is selected text, the cmCut and cmCopy commands will also be enabled. If no TEditor or TInputLines are focused, then these commands will be disabled.

Extended color support

The Turbo Vision API has been extended to allow more than the original 16 colors.

Colors can be specified using any of the following formats:

  • BIOS color attributes (4-bit), the format used originally on MS-DOS.
  • RGB (24-bit).
  • xterm-256color palette indices (8-bit).
  • The terminal default color. This is the color used by terminal emulators when no display attributes (bold, color...) are enabled (usually white for foreground and black for background).

Although Turbo Vision applications are likely to be ran in a terminal emulator, the API makes no assumptions about the display device. That is, the complexity of dealing with terminal emulators is hidden from the programmer and managed by Turbo Vision itself.

For example: color support varies among terminals. If the programmer uses a color format not supported by the terminal emulator, Turbo Vision will quantize it to what the terminal can display. The following images represent the quantization of a 24-bit RGB picture to 256, 16 and 8 color palettes:

24-bit color (original) 256 colors
mpv-shot0005 mpv-shot0002
16 colors 8 colors (bold as bright)
mpv-shot0003 mpv-shot0004

Extended color support basically comes down to the following:

  • Turbo Vision has originally used BIOS color attributes stored in an uchar. ushort is used to represent attribute pairs. This is still the case when using Borland C++.
  • In modern platforms a new type TColorAttr has been added which replaces uchar. It specifies a foreground and background color and a style. Colors can be specified in different formats (BIOS color attributes, 24-bit RGB...). Styles are the typical ones (bold, italic, underline...). There's also TAttrPair, which replaces ushort.
  • TDrawBuffer's methods, which used to take uchar or ushort parameters to specify color attributes, now take TColorAttr or TAttrPair.
  • TPalette, which used to contain an array of uchar, now contains an array of TColorAttr. The TView::mapColor method also returns TColorAttr instead of uchar.
  • TView::mapColor has been made virtual so that the palette system can be bypassed without having to rewrite any draw methods.
  • TColorAttr and TAttrPair can be initialized with and casted into uchar and ushort in a way such that legacy code still compiles out-of-the-box without any change in functionality.

Below is a more detailed explanation aimed at developers.

Data Types

In the first place we will explain the data types the programmer needs to know in order to take advantage of the extended color support. To get access to them, you may have to define the macro Uses_TColorAttr before including <tvision/tv.h>.

All the types described in this section are trivial. This means that they can be memset'd and memcpy'd. But variables of these types are uninitialized when declared without initializer, just like primitive types. So make sure you don't manipulate them before initializing them.

Color format types

Several types are defined which represent different color formats. The reason why these types exist is to allow distinguishing color formats using the type system. Some of them also have public fields which make it easier to manipulate individual bits.

  • TColorBIOS represents a BIOS color. It allows accessing the r, g, b and bright bits individually, and can be casted implicitly into/from uint8_t.

    The memory layout is:

    • Bit 0: Blue (field b).
    • Bit 1: Green (field g).
    • Bit 2: Red (field r).
    • Bit 3: Bright (field bright).
    • Bits 4-7: unused.

    Examples of TColorBIOS usage:

    TColorBIOS bios = 0x4;  // 0x4: red.
    bios.bright = 1;        // 0xC: light red.
    bios.b = bios.r;        // 0xD: light magenta.
    bios = bios ^ 3;        // 0xE: yellow.
    uint8_t c = bios;       // Implicit conversion to integer types.

    In terminal emulators, BIOS colors are mapped to the basic 16 ANSI colors.

  • TColorRGB represents a color in 24-bit RGB. It allows accessing the r, g and b bit fields individually, and can be casted implicitly into/from uint32_t.

    The memory layout is:

    • Bits 0-7: Blue (field b).
    • Bits 8-15: Green (field g).
    • Bits 16-23: Red (field r).
    • Bits 24-31: unused.

    Examples of TColorRGB usage:

    TColorRGB rgb = 0x9370DB;   // 0xRRGGBB.
    rgb = {0x93, 0x70, 0xDB};   // {R, G, B}.
    rgb = rgb ^ 0xFFFFFF;       // Negated.
    rgb.g = rgb.r & 0x88;       // Access to individual components.
    uint32_t c = rgb;           // Implicit conversion to integer types.
  • TColorXTerm represents an index into the xterm-256color color palette. It can be casted into and from uint8_t.

TColorDesired

TColorDesired represents a color which the programmer intends to show on screen, encoded in any of the supported color types.

A TColorDesired can be initialized in the following ways:

  • As a BIOS color: with a char literal or a TColorBIOS object:

    TColorDesired bios1 = '\xF';
    TColorDesired bios2 = TColorBIOS(0xF);
  • As a RGB color: with an int literal or a TColorRGB object:

    TColorDesired rgb1 = 0xFF7700; // 0xRRGGBB.
    TColorDesired rgb2 = TColorRGB(0xFF, 0x77, 0x00); // {R, G, B}.
    TColorDesired rgb3 = TColorRGB(0xFF7700); // 0xRRGGBB.
  • As an XTerm palette index: with a TColorXTerm object.

  • As the terminal default color: through zero-initialization:

    TColorDesired def1 {};
    // Or with 'memset':
    TColorDesired def2;
    memset(&def2, 0, sizeof(def2));

TColorDesired has methods to query the contained color, but you will usually not need to use them. See the struct definition in <tvision/colors.h> for more information.

Trivia: the name is inspired by Scintilla's ColourDesired.

TColorAttr

TColorAttr describes the color attributes of a screen cell. This is the type you are most likely to interact with if you intend to change the colors in a view.

A TColorAttr is composed of:

  • A foreground color, of type TColorDesired.

  • A background color, of type TColorDesired.

  • A style bitmask containing a combination of the following flags:

    • slBold.
    • slItalic.
    • slUnderline.
    • slBlink.
    • slReverse.
    • slStrike.

    These flags are based on the basic display attributes selectable through ANSI escape codes. The results may vary between terminal emulators. slReverse is probably the least reliable of them: prefer using the TColorAttr reverseAttribute(TColorAttr attr) free function over setting this flag.

The most straight-forward way to create a TColorAttr is by means of the TColorAttr(TColorDesired fg, TColorDesired bg, ushort style=0) and TColorAttr(int bios) constructors:

// Foreground: RGB 0x892312
// Background: RGB 0x7F00BB
// Style: Normal.
TColorAttr a1 = {TColorRGB(0x89, 0x23, 0x12), TColorRGB(0x7F, 0x00, 0xBB)};

// Foreground: BIOS 0x7.
// Background: RGB 0x7F00BB.
// Style: Bold, Italic.
TColorAttr a2 = {'\x7', 0x7F00BB, slBold | slItalic};

// Foreground: Terminal default.
// Background: BIOS 0xF.
// Style: Normal.
TColorAttr a3 = {{}, TColorBIOS(0xF)};

// Foreground: Terminal default.
// Background: Terminal default.
// Style: Normal.
TColorAttr a4 = {};

// Foreground: BIOS 0x0
// Background: BIOS 0x7
// Style: Normal
TColorAttr a5 = 0x70;

The fields of a TColorAttr can be accessed with the following free functions:

TColorDesired getFore(const TColorAttr &attr);
TColorDesired getBack(const TColorAttr &attr);
ushort getStyle(const TColorAttr &attr);
void setFore(TColorAttr &attr, TColorDesired fg);
void setBack(TColorAttr &attr, TColorDesired bg);
void setStyle(TColorAttr &attr, ushort style);

TAttrPair

TAttrPair is a pair of TColorAttr, used by some API functions to pass two attributes at once.

You may initialize a TAttrPair with the TAttrPair(const TColorAttrs &lo, const TColorAttrs &hi) constructor:

TColorAttr cNormal = {0x234983, 0x267232};
TColorAttr cHigh = {0x309283, 0x127844};
TAttrPair attrs = {cNormal, cHigh};
TDrawBuffer b;
b.moveCStr(0, "Normal text, ~Highlighted text~", attrs);

The attributes can be accessed with the [0] and [1] subindices:

TColorAttr lo = {0x892343, 0x271274};
TColorAttr hi = '\x93';
TAttrPair attrs = {lo, hi};
assert(lo == attrs[0]);
assert(hi == attrs[1]);

Changing the appearance of a TView

Views are commonly drawn by means of a TDrawBuffer. Most TDrawBuffer member functions take color attributes by parameter. For example:

ushort TDrawBuffer::moveStr(ushort indent, TStringView str, TColorAttr attr);
ushort TDrawBuffer::moveCStr(ushort indent, TStringView str, TAttrPair attrs);
void TDrawBuffer::putAttribute(ushort indent, TColorAttr attr);

However, the views provided with Turbo Vision usually store their color information in palettes. A view's palette can be queried with the following member functions:

TColorAttr TView::mapColor(uchar index);
TAttrPair TView::getColor(ushort indices);
  • mapColor looks up a single color attribute in the view's palette, given an index into the palette. Remember that the palette indices for each view class can be found in the Turbo Vision headers. For example, <tvision/views.h> says the following about TScrollBar:

    /* ---------------------------------------------------------------------- */
    /*      class TScrollBar                                                  */
    /*                                                                        */
    /*      Palette layout                                                    */
    /*        1 = Page areas                                                  */
    /*        2 = Arrows                                                      */
    /*        3 = Indicator                                                   */
    /* ---------------------------------------------------------------------- */
  • getColor is a helper function that allows querying two cell attributes at once. Each byte in the indices parameter contains an index into the palette. The TAttrPair result contains the two cell attributes.

    For example, the following can be found in the draw method of TMenuBar:

    TAttrPair cNormal = getColor(0x0301);
    TAttrPair cSelect = getColor(0x0604);

    Which would be equivalent to this:

    TAttrPair cNormal = {mapColor(1), mapColor(3)};
    TAttrPair cSelect = {mapColor(4), mapColor(6)};

As an API extension, the mapColor method has been made virtual. This makes it possible to override Turbo Vision's hierarchical palette system with a custom solution without having to rewrite the draw() method.

So, in general, there are three ways to use extended colors in views:

  1. By returning extended color attributes from an overridden mapColor method:
// The 'TMyScrollBar' class inherits from 'TScrollBar' and overrides 'TView::mapColor'.
TColorAttr TMyScrollBar::mapColor(uchar index) noexcept
{
    // In this example the values are hardcoded,
    // but they could be stored elsewhere if desired.
    switch (index)
    {
        case 1:     return {0x492983, 0x826124}; // Page areas.
        case 2:     return {0x438939, 0x091297}; // Arrows.
        case 3:     return {0x123783, 0x329812}; // Indicator.
        default:    return errorAttr;
    }
}
  1. By providing extended color attributes directly to TDrawBuffer methods, if the palette system is not being used. For example:

    // The 'TMyView' class inherits from 'TView' and overrides 'TView::draw'.
    void TMyView::draw()
    {
        TDrawBuffer b;
        TColorAttr color {0x1F1C1B, 0xFAFAFA, slBold};
        b.moveStr(0, "This is bold black text over a white background", color);
        /* ... */
    }
  2. By modifying the palettes. There are two ways to do this:

    1. By modifying the application palette after it has been built. Note that the palette elements are TColorAttr. For example:
    void updateAppPalette()
    {
        TPalette &pal = TProgram::application->getPalete();
        pal[1] = {0x762892, 0x828712};              // TBackground.
        pal[2] = {0x874832, 0x249838, slBold};      // TMenuView normal text.
        pal[3] = {{}, {}, slItalic | slUnderline};  // TMenuView disabled text.
        /* ... */
    }
    1. By using extended color attributes in the application palette definition:
    static const TColorAttr cpMyApp[] =
    {
        {0x762892, 0x828712},               // TBackground.
        {0x874832, 0x249838, slBold},       // TMenuView normal text.
        {{}, {}, slItalic | slUnderline},   // TMenuView disabled text.
        /* ... */
    };
    
    // The 'TMyApp' class inherits from 'TApplication' and overrides 'TView::getPalette'.
    TPalette &TMyApp::getPalette() const
    {
        static TPalette palette(cpMyApp);
        return palette;
    }

Display capabilities

TScreen::screenMode exposes some information about the display's color support:

  • If (TScreen::screenMode & 0xFF) == TDisplay::smMono, the display is monocolor (only relevant in DOS).
  • If (TScreen::screenMode & 0xFF) == TDisplay::smBW80, the display is grayscale (only relevant in DOS).
  • If (TScreen::screenMode & 0xFF) == TDisplay::smCO80, the display supports at least 16 colors.
    • If TScreen::screenMode & TDisplay::smColor256, the display supports at least 256 colors.
    • If TScreen::screenMode & TDisplay::smColorHigh, the display supports even more colors (e.g. 24-bit color). TDisplay::smColor256 is also set in this case.

Backward-compatibility of color types

The types defined previously represent concepts that are also important when developing for Borland C++:

Concept Layout in Borland C++ Layout in modern platforms
Color Attribute uchar. A BIOS color attribute. struct TColorAttr.
Color A 4-bit number. struct TColorDesired.
Attribute Pair ushort. An attribute in each byte. struct TAttrPair.

One of this project's key principles is that the API should be used in the same way both in Borland C++ and modern platforms, that is, without the need for #ifdefs. Another principle is that legacy code should compile out-of-the-box, and adapting it to the new features should increase complexity as little as possible.

Backward-compatibility is accomplished in the following way:

  • In Borland C++, TColorAttr and TAttrPair are typedef'd to uchar and ushort, respectively.

  • In modern platforms, TColorAttr and TAttrPair can be used in place of uchar and ushort, respectively, since they are able to hold any value that fits into them and can be casted implicitly into/from them.

    A TColorAttr initialized with uchar represents a BIOS color attribute. When converting back to uchar, the following happens:

    • If fg and bg are BIOS colors, and style is cleared, the resulting uchar represents the same BIOS color attribute contained in the TColorAttr (as in the code above).
    • Otherwise, the conversion results in a color attribute that stands out, i.e. white on magenta, meaning that the programmer should consider replacing uchar/ushort with TColorAttr/TAttrPair if they intend to support the extended color attributes.

    The same goes for TAttrPair and ushort, considering that it is composed of two TColorAttr.

A use case of backward-compatibility within Turbo Vision itself is the TPalette class, core of the palette system. In its original design, it used a single data type (uchar) to represent different things: array length, palette indices or color attributes.

The new design simply replaces uchar with TColorAttr. This means there are no changes in the way TPalette is used, yet TPalette is now able to store extended color attributes.

TColorDialog hasn't been remodeled, and thus it can't be used to pick extended color attributes at runtime.

Example: adding extended color support to legacy code

The following pattern of code is common across draw methods of views:

void TMyView::draw()
{
    ushort cFrame, cTitle;
    if (state & sfDragging)
    {
        cFrame = 0x0505;
        cTitle = 0x0005;
    }
    else
    {
        cFrame = 0x0503;
        cTitle = 0x0004;
    }
    cFrame = getColor(cFrame);
    cTitle = getColor(cTitle);
    /* ... */
}

In this case, ushort is used both as a pair of palette indices and as a pair of color attributes. getColor now returns a TAttrPair, so even though this compiles out-of-the-box, extended attributes will be lost in the implicit conversion to ushort.

The code above still works just like it did originally. It's only non-BIOS color attributes that don't produce the expected result. Because of the compatibility between TAttrPair and ushort, the following is enough to enable support for extended color attributes:

-    ushort cFrame, cTitle;
+    TAttrPair cFrame, cTitle;

Nothing prevents you from using different variables for palette indices and color attributes, which is what should actually be done. The point of backward-compatibility is the ability to support new features without changing the program's logic, that is, minimizing the risk of increasing code complexity or introducing bugs.

tvision's People

Contributors

asanoic avatar dchapiesky avatar electroly avatar frankxie05 avatar gerhobbelt avatar idispatch avatar jvprat avatar magiblot avatar michael137 avatar rmorales87atx avatar unxed avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tvision's Issues

Can't compile example in Visual Studio 2019

Hello there,

I have managed to build the project using cmake and MSVC, I could open the examples and even make small changes. However, when I create a new project, copy the hello.cpp to my project, set the include path and the lib path it fails to compile giving me these errors:

1>Tvision3.cpp 1>C:\Users\%username%\source\tvision-master\include\tvision\tv.h(35,9): warning C4068: unknown pragma 'option' 1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\limits(44,67): error C2864: 'std::_Num_base::has_denorm': a static data member with an in-class initializer must have non-volatile const integral type or be specified as 'inline' 1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\limits(44,67): message : type is 'std::float_denorm_style' 1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\limits(45,59): error C2864: etc. etc.

I would really like to use this library as I love CLI interfaces, I am currently working on a project for my university to create a unified interface for all our vacuum gauges. So far I have managed to do it well on Labview but I would like to build everything using Turbo Vision. Not only would it mean a great relief or resources compared to the bloat that is Labview, but CLI may also be used via SSL.

Any advice on how to overcome this issue would be greatly appreciated.

A few thoughts about the library...

Greetings again!
Thank you for the work done to adapt the library. I will allow myself a few remarks, which I ask you not to take as a reproach.

  1. I think that maintaining compatibility with compilers that have died is unnecessary. With all due respect to Borland, their compiler is a corpse. Therefore, I think the compatibility code with it can be removed, leaving only a link to the copyright.
  2. TurboVision itself, with all its advantages, has a lot of disadvantages, such as a very poor palette of control elements, the absence of some obvious functions (for example, window centering), etc. I think it's worth creatively expanding the functionality of the library with existing code.
  3. When compiling to MSVC, a warning occurs, which may lead to errors in the future. I am sending a message:

...>cmake . -B ./build -A x64
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.18363.
-- The C compiler identification is MSVC 19.26.28805.0
-- The CXX compiler identification is MSVC 19.26.28805.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.26.28801/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.26.28801/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test SUPPORTS_COUNTER_MACRO
-- Performing Test SUPPORTS_COUNTER_MACRO - Success
-- Install path: C:/Program Files/tvision
-- Build Examples: ON
-- Link w/static RTL: OFF
-- Configuring done
-- Generating done
-- Build files have been written to: D:/Design/tv_prj/tv/build

...>cmake --build ./build --config Release
Microsoft (R) Build Engine версии 16.6.0+5ff7b0c9e для .NET Framework
(C) Корпорация Майкрософт (Microsoft Corporation). Все права защищены.

Checking Build System
Building Custom Rule D:/Design/tv_prj/tv/source/CMakeLists.txt
cmake_pch.cxx
....
help.cpp
helpbase.cpp
histlist.cpp
D:\Design\tv_prj\tv\source\tvision\histlist.cpp(189,39): warning C4291: void *HistRec::operator new(size_t,HistRec *) noexcept: the corresponding delete operator was not found; if an exception occurs during initialization, the memory will not be freed [D:\Design\tv_prj\tv\build\source\tvision.vcxproj]
D:\Design\tv_prj\tv\source\tvision\histlist.cpp(55): message : см. объявление "HistRec::operator new" [D:\Design\tv_prj\tv\build\source\tvision.vcxproj]
mapcolor.cpp
menu.cpp
....
I'm sorry if my English is not very clear. My native language is Russian, I read normally, but I don't really speak and write))) - I use an automatic translator.

Improve behaviour of menus against mouse events

The (boring) default behaviour of menus is as follows:

Peek 2019-07-14 23-23

  1. Clicking on an empty area of the menu bar causes a submenu to show up while the button is held (added in Turbo Vision 2.0).
  2. Clicking on the name of an open menu doesn't close it.
  3. Releasing the mouse button on the menu border causes the menu to close if the drag began on a highlightable entry.

In my opinion, (2) is the most important thing to achieve. It is not clear whether (1) is a bug or a feature, and (3) is completely idiotic.

TScrollBar usability issues

Peek 2019-07-08 18-19
(Recorded with Peek)

TScrollBar has several usability issues:

  1. Even if the thumb is dragged around, window contents are not updated until mouseup.
  2. The thumb cannot be dragged when the mouse is not above the scrollbar.
  3. Because the thumb is just 1 character big, clicking ahead of it doesn't converge in it ending up under the cursor. Instead, it bounces back and forth, rendering the feature useless.
  4. No mouse wheel support.

Judging from the source code at source/tvision/tscrlbar.cpp#L140, the current behaviour seems to be a design choice. I wonder what the reasons behind it are, but this behaviour is certainly unacceptable these days.

Mouse wheel not working on ubuntu 18.04

Hello !
Compiling on my machine with lubuntu 18.04 the mouse click works but not the mouse wheel, see the cmake output bellow:

cmake .
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Library output: xxx/tvision/lib
-- Binary output : xxx/tvision/bin
-- Install path  : /usr/local
-- Build Examples: ON
-- Build w/GPM   : ON
-- gpm library requested
-- gpm library found
-- Configuring done
-- Generating done
-- Build files have been written to: xxx/tvision

And here is tvedit link parameters:

/usr/bin/c++     CMakeFiles/tvedit.dir/examples/tvedit/tvedit1.cpp.o CMakeFiles/tvedit.dir/examples/tvedit/tvedit2.cpp.o CMakeFiles/tvedit.dir/examples/tvedit/tvedit3.cpp.o  -o bin/tvedit  lib/libtvision.a -lncursesw /usr/lib/x86_64-linux-gnu/libgpm.so

Cheers !

Konsole: overly wide Unicode characters mess up intended layouts

I'm trying to find a solution to this rendering issue in Konsole.

konsole

This is a TEditor example showing how the line formatting gets shifted around due to those ❺ symbols. Also, the title of this window is clipped (there's no close parenthesis). These symbols are rendered slightly wider than a single cell, leading to the rest of the printed line being shifted out of alignment. Other terminals show this symbol in a single terminal cell, but Konsole is painting the line with variable character widths with chaotic effects.

image

Here's my evolution of the ASCII table from tvdemo. On the right you can see some extra-wide characters that mess up the whole line. ⑪-⑯ and ❽-❿ are clipped. When you click on one, it selects the "wrong" character due to the rendering discrepancy.

Open to suggestions on this. Konsole is the only terminal I've tested so far with this issue.

Basics...

A version number would be great - something that differentiates your working version from some of the other tvisions out there...

Might even be worth renaming to something like TVision2020

Shared lib compile?

Terminal widget?

Hello @magiblot ! I just became aware of this active Turbo Vision project recently over on the notcurses thread.

Besides "hello!" :-) I wanted to mention something I had done with SET's rhtvision a long time ago: qterminal . This was a port of Qodem's VT100/102/220/Linux terminal to Turbo Vision (screenshot1 screenshot2 screenshot3):

  • I discovered that rhtvision had the wrong mappings for Unicode codepoints 0x2264 and 0x2265 (≤ and ≥); they were swapped. Just wanted to mention that, I don't know if you had started from there or are added your own Unicode awareness to a fresh branch off the Borland TV sources.
  • If you don't yet have a terminal widget and are interested, I would be happy to get it running again and provide a bug-fixed public domain licensed version of it for you. Just let me know.
  • If you do have your own terminal widget, how could I test it out?

Very nice to see your project here! 💗

Also I love your Turbo editor screenshots. Very cool!

Layout/resizing console window in Windows - will become broken

First of all thank you for this project. It was always something what I wanted (to have TVISION enabled in PC again) and you actually overachieved this with Unicode support and Linux portability. Great job!

One thing which I’m seeing is that if you run app in Windows console (E.g. tvdemo.exe with some window open in app) and you do resize of console with Alt+Enter or resizing with dragging right corner of Windows console, the layout will become broken. Not sure if this can be fixed somehow or if this is known limitation but would be nice to have this working properly.

Exception in DOS

Problem user here again. :-) This is the demo program from the TV C++ manual. Pressing F4 should open a window that displays a source file. Instead it throws an exception.

image

Pressing F4 should open a dialog but I get another exception:

image

I am able to pull down menus but that's it.

(To be sure it's not DOSBox, I also tried it in VirtualBox in an NT 4.0 command prompt.)

Cannot compile under BCPP 5.02 with TASM 5.0 (Win 98 SE)

Trying to compile geninc gives several errors related to missing files (which are in fact missing from source) and geninc32 simply states "Invalid target->/Ts" I'm banging my head against the wall here as my co-worker on this project, Sduensin, tells me he's managed to compile it fine in his build environment under windows 3.1 I've followed the instructions in build.txt until now, can anyone tell me what I'm doing wrong here?

tvhc: use stderr

This is a pretty minor issue, but it would be nice if tvhc used cerr to print warnings/errors and cout for the copyright notice. Currently it uses cout for everything, so there's no easy way to silence the copyright notice without also silencing errors.

Wrong whitelist rule causes `rg` to fail to search code content

See also BurntSushi/ripgrep#1819, I can't search code via rg, because rg will search the contents of the repository as directed by the .gitignore rules, not by the files actually owned by the repository.

❯ rg TApplication::TApplication
(nothing)

❯ rg --no-ignore TApplication::TApplication
source/tvision/tapplica.cpp
41:TApplication::TApplication() :

I think this may cause some difficulties for me to read the source code. Hopefully it will improve.

Cannot compile tvision

I am running on Ubuntu 20.04
Linux ubuntuclient 5.8.0-40-generic #45~20.04.1-Ubuntu SMP Fri Jan 15 11:35:04 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

I have downloaded the project and unzip it which created the folder structure
I the run:
hsv@ubuntuclient:~/tvision/tvision-master$ cmake . -B ./build -DCMAKE_BUILD_TYPE=Release && cmake --build ./build
-- Install path: /usr/local
-- Build Examples: ON
-- Build w/GPM: ON
-- gpm library requested
CMake Warning at CMakeLists.txt:36 (message):
gpm library requested but not found
Call Stack (most recent call first):
source/CMakeLists.txt:113 (tv_message)

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
NCURSESW
linked by target "tvision" in directory /home/hsv/tvision/tvision-master/source

-- Configuring incomplete, errors occurred!
See also "/home/hsv/tvision/tvision-master/build/CMakeFiles/CMakeOutput.log".
See also "/home/hsv/tvision/tvision-master/build/CMakeFiles/CMakeError.log".

CMakeError.log
CMakeOutput.log

What should I do different to get it compiled?
Regards
Henning

Cannot compile tvision in win32

Error en tvision/source/platform/winwidth.cpp

error C2061: error de sintaxis: identificador 'TStringView'

solution:

in tvision/source/platform/winwidth.h:

add #include <tvision/tv.h> for resolver bug : error C2061: error de sintaxis: identificador 'TStringView'

the code would look like this:

#ifndef WINWIDTH_H
#define WINWIDTH_H

#ifdef _WIN32

// add #include <tvision/tv.h> for resolver bug : error C2061: error de sintaxis: identificador 'TStringView'
#include <tvision/tv.h>
#include <tvision/compat/win.h>
#include
#include
#include
#include
#include <unordered_map>

......

Unresolved External 'SetConsoleActiveScreenBuffer' in DOS with BC++ 4.52.

After much hackery, I have managed to build TV using BC++ 4.52 / PowerPack / TASM4 in DOSBox-X with Windows 3.11 and Win32s. After creating a project for my sample program (basically the tutorial chapter from the TV manual) and adding TV32 to my library list, I get the following after compilation:

Linker Error: Unresolved External 'SetConsoleActiveScreenBuffer' referenced from module ..\SOURCE\TVISION\HARDWRVR.CPP

At this stage of my TV knowledge, I'm at a loss. Ideas?

Thanks again!

The build of demo applications are broken on FC32

There are some problems in linking stage:

[ 95%] Building CXX object CMakeFiles/tvdemo.dir/examples/tvdemo/puzzle.cpp.o
In file included from /usr/include/c++/10/backward/strstream:50,
                 from /home/pavel/src/tvision/include/override/strstrea.h:4,
                 from /home/pavel/src/tvision/examples/tvdemo/puzzle.cpp:29:
/usr/include/c++/10/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header which may be removed without further notice at a future date. Please use a non-deprecated interface with equivalent functionality instead. For a listing of replacement headers and interfaces, consult the file backward_warning.h. To disable this warning use -Wno-deprecated. [-Wcpp]
   32 | #warning \
      |  ^~~~~~~
[ 95%] Building CXX object CMakeFiles/tvdemo.dir/examples/tvdemo/tvdemo1.cpp.o
[ 96%] Building CXX object CMakeFiles/tvdemo.dir/examples/tvdemo/tvdemo2.cpp.o
[ 96%] Building CXX object CMakeFiles/tvdemo.dir/examples/tvdemo/tvdemo3.cpp.o
[ 97%] Linking CXX executable tvdemo
/usr/bin/ld: /tmp/tvdemo.ecc3yZ.ltrans0.ltrans.o: in function `TWindow::streamableName() const':
:(.text+0x3): undefined reference to `TWindow::name'
/usr/bin/ld: /tmp/tvdemo.ecc3yZ.ltrans0.ltrans.o: in function `non-virtual thunk to TWindow::streamableName() const':
:(.text+0x13): undefined reference to `TWindow::name'
/usr/bin/ld: /tmp/tvdemo.ecc3yZ.ltrans0.ltrans.o: in function `TDialog::streamableName() const':
:(.text+0x83): undefined reference to `TDialog::name'
/usr/bin/ld: /tmp/tvdemo.ecc3yZ.ltrans0.ltrans.o: in function `non-virtual thunk to TDialog::streamableName() const':
:(.text+0x93): undefined reference to `TDialog::name'
/usr/bin/ld: /tmp/tvdemo.ecc3yZ.ltrans0.ltrans.o: in function `TCollection::streamableName() const':
:(.text+0x123): undefined reference to `TCollection::name'
/usr/bin/ld: /tmp/tvdemo.ecc3yZ.ltrans0.ltrans.o: in function `TView::streamableName() const':
:(.text+0x183): undefined reference to `TView::name'
/usr/bin/ld: /tmp/tvdemo.ecc3yZ.ltrans0.ltrans.o: in function `non-virtual thunk to TView::streamableName() const':
:(.text+0x193): undefined reference to `TView::name'
/usr/bin/ld: /tmp/tvdemo.ecc3yZ.ltrans0.ltrans.o: in function `TStaticText::streamableName() const':
:(.text+0x1a3): undefined reference to `TStaticText::name'
/usr/bin/ld: /tmp/tvdemo.ecc3yZ.ltrans0.ltrans.o: in function `non-virtual thunk to TStaticText::streamableName() const':
:(.text+0x1b3): undefined reference to `TStaticText::name'
/usr/bin/ld: /tmp/tvdemo.ecc3yZ.ltrans0.ltrans.o: in function `TGroup::streamableName() const':
:(.text+0x203): undefined reference to `TGroup::name'
/usr/bin/ld: /tmp/tvdemo.ecc3yZ.ltrans0.ltrans.o: in function `non-virtual thunk to TGroup::streamableName() const':
:(.text+0x213): undefined reference to `TGroup::name'
/usr/bin/ld: /tmp/tvdemo.ecc3yZ.ltrans0.ltrans.o: in function `TAsciiChart::read(ipstream&)':
:(.text+0x2b6): undefined reference to `TWindow::read(ipstream&)'
/usr/bin/ld: /tmp/tvdemo.ecc3yZ.ltrans0.ltrans.o: in function `non-virtual thunk to TAsciiChart::read(ipstream&)':
:(.text+0x2ca): undefined reference to `TWindow::read(ipstream&)'
/usr/bin/ld: /tmp/tvdemo.ecc3yZ.ltrans0.ltrans.o: in function `TCalendarWindow::read(ipstream&)':
:(.text+0x2e6): undefined reference to `TWindow::read(ipstream&)'
/usr/bin/ld: /tmp/tvdemo.ecc3yZ.ltrans0.ltrans.o: in function `non-virtual thunk to TCalendarWindow::read(ipstream&)':
:(.text+0x2fa): undefined reference to `TWindow::read(ipstream&)'
/usr/bin/ld: /tmp/tvdemo.ecc3yZ.ltrans0.ltrans.o: in function `TPuzzleWindow::read(ipstream&)':
:(.text+0x316): undefined reference to `TWindow::read(ipstream&)'
/usr/bin/ld: /tmp/tvdemo.ecc3yZ.ltrans0.ltrans.o::(.text+0x32a): more undefined references to `TWindow::read(ipstream&)' follow
/usr/bin/ld: /tmp/tvdemo.ecc3yZ.ltrans0.ltrans.o: in function `TTable::read(ipstream&)':
:(.text+0x366): undefined reference to `TView::read(ipstream&)'
/usr/bin/ld: /tmp/tvdemo.ecc3yZ.ltrans0.ltrans.o: in function `non-virtual thunk to TTable::read(ipstream&)':
:(.text+0x37a): undefined reference to `TView::read(ipstream&)'
/usr/bin/ld: /tmp/tvdemo.ecc3yZ.ltrans0.ltrans.o: in function `TTable::build()':
:(.text+0x3aa): undefined reference to `TView::TView(StreamableInit)'
/usr/bin/ld: /tmp/tvdemo.ecc3yZ.ltrans0.ltrans.o: in function `TReport::build()':

Support for Unicode in PuTTY and Windows conhost

I'm trying to use UTF-8 in my help file, but it seems like some common terminals don't support Unicode. I've prepared a test program: https://gist.github.com/electroly/8965f566fa4546eac186a28a9d364c35.

image

It seems that macOS iTerm2, macOS Terminal, and Windows Terminal have full Unicode support, but PuTTY and the Windows conhost do not. I have "legacy mode" disabled in the Windows console, and I'm using a TrueType font. Does this match your experience, or is there some way to improve the platform support? I haven't tried to build tvision using Visual Studio; might this be different if I did?

This is an unfortunate situation on Windows. Windows Terminal doesn't seem to support the mouse, and conhost doesn't seem to support Unicode, so none of the terminal options on Windows support all tvision features. The macOS Terminal similarly doesn't seem to support the mouse, but least iTerm2 is available for Macs and it supports both the mouse and Unicode. Do you know of a terminal on Windows that supports both the mouse and Unicode?

Build failure on OpenBSD

I wanted to test if this program worked on OpenBSD (and NetBSD too, but that is for later) and I got this error. I didn't have any issues with cmake, but both make and gmake failed on me.

make:
make

gmake:
gmake

What is the issue at hand? Can this please be fixed?

Add recommendation for Windows Terminal to readme?

I'm sure you saw this as I see you commented on the issue, but microsoft/terminal#376 was finally fixed. It's shipping right now in "Windows Terminal Preview". I tested it and the mouse now works with TMBASIC. At long last, we have 256 color support, full Unicode with fallback, and mouse support on Windows. I'm going to make the explicit recommendation for TMBASIC that people use Windows Terminal.

Very slow under Windows Console

I use the pre-built Turbo editor (TVedit.exe) to check if Turbo Vision is suitable for my need. Every time the cursor is moved (point-and-click with mouse, by Backspace, Left Arrow, Right Arrow, Ctrl+one of those, or simply by typing an alphanum key) the cursor disappears for almost 1 second, which is terribly slow.

Syntax highlighting

Is it possible to make CPP editor widget syntax highlight theme?
what is the most elegant way to do it?

Windows: automatically set TrueType font when raster font is configured?

Not sure if this is appropriate for tvision to be doing; this might be something the client application should handle. I'm happy to ship this fix in the TMBASIC codebase but wanted to offer it to you in case tvision could use it.

Here is the code, please feel free to steal any or all of it if you're interested: https://github.com/electroly/tmbasic/blob/master/src/util/initConsole.cpp

I use GetCurrentConsoleFontEx to determine whether the console host is using a raster font, and if so, I use SetCurrentConsoleFontEx to change the font to either Consolas or Lucida Console. I check first to make sure the font is available on the system and bail if neither is present. Both fonts ship with the versions of Windows that tvision supports, but I wanted to err on the side of caution.

Doing this at startup allows TMBASIC to display correctly on a fresh Windows 7 install without the user needing to change their console settings. I haven't tested Vista but I imagine it will work the same there.

I had to link in -lgdi32 so I can use EnumFontFamiliesEx to check whether Consolas or Lucida Console are available.

Query terminal color capabilities

In my RGB color picker, I find it would be helpful to know what the terminal supports. There are two related situations I'm concerned about:

  1. The user's terminal only supports 16 colors, and I'm showing a 256 color palette. Swaths of colors in the palette look the same to the user, but they really have different RGB values. If the user clicks a color from the palette, they don't know what color they've actually selected and if their work is later displayed on a 256 color terminal, the colors won't be what they had intended. It seems better to show a 16 color palette to users who can't see 256 colors.

  2. The user has TERM=vt100. In this case I'd hide the palette entirely and make the user enter R/G/B numbers.

image
image

256 color terminal support

I suspect the answer is "no", but is there any chance to have 256 color support in the future?

Thanks!

cmake instructions in README are not correct

I'm not familiar with cmake, but the instructions in the README were not working for me. I could not get it to put the build files into a build directory. I tried to create a build directory, and it complained that the CMakeLists.txt was not located in that build directory. Moving the file into that directory didn't work. In the end, I was only able to make it work just by building in the projects top level directory like so:

cmake -DCMAKE_BUILD_TYPE=Release && make

When I checked the man page for my version of cmake, there was no mention whatsoever of the -B parameter. I have cmake version 3.10.2 on Ubuntu 18.04.

Here is some terminal output of me trying to make it work that is probably a better illustration of the problem.

apreche:~/projects/tvision [master] $ ls
CMakeLists.txt  COPYRIGHT  examples  hello.cpp  include  project  README.md  source
apreche:~/projects/tvision [master] $ cmake . -B ./build -DCMAKE_BUILD_TYPE=Release && cmake --build ./build
CMake Error: The source directory "/home/apreche/projects/tvision/build" does not exist.
Specify --help for usage, or press the help button on the CMake GUI.
apreche:~/projects/tvision [master] $ mkdir build
apreche:~/projects/tvision [master] $ cmake . -B ./build -DCMAKE_BUILD_TYPE=Release && cmake --build ./build
CMake Error: The source directory "/home/apreche/projects/tvision/build" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
apreche:~/projects/tvision [master] $ cp CMakeLists.txt build/
apreche:~/projects/tvision [master] $ cmake . -B ./build -DCMAKE_BUILD_TYPE=Release && cmake --build ./build
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test SUPPORTS_COUNTER_MACRO
-- Performing Test SUPPORTS_COUNTER_MACRO - Success
-- Install path: /usr/local
-- Build Examples: ON
-- Build w/GPM: ON
You have called ADD_LIBRARY for library tvision without any source files. This typically indicates a problem with your CMakeLists.txt file
-- gpm library requested
-- gpm library found
CMake Error at CMakeLists.txt:202 (add_subdirectory):
  add_subdirectory given source "examples" which is not an existing
  directory.


-- Configuring incomplete, errors occurred!
See also "/home/apreche/projects/tvision/CMakeFiles/CMakeOutput.log".
apreche:~/projects/tvision [master] $ ls
build  CMakeCache.txt  CMakeFiles  CMakeLists.txt  COPYRIGHT  examples  hello.cpp  include  project  README.md  source
apreche:~/projects/tvision [master] $ ls build/
CMakeLists.txt
apreche:~/projects/tvision [master] $

vs

apreche:~/projects/tvision [master] $ cmake -DCMAKE_BUILD_TYPE=Release && make
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features

...

[ 98%] Building CXX object examples/mmenu/CMakeFiles/mmenu.dir/test.cpp.o
[ 99%] Linking CXX executable ../../mmenu
[ 99%] Built target mmenu
Scanning dependencies of target palette
[ 99%] Building CXX object examples/palette/CMakeFiles/palette.dir/palette.cpp.o
[100%] Building CXX object examples/palette/CMakeFiles/palette.dir/test.cpp.o
[100%] Linking CXX executable ../../palette
[100%] Built target palette
apreche:~/projects/tvision [master %] $ ls
build           CMakeFiles           CMakeLists.txt  examples  genphone  hello.cpp  libtvision.a  mmenu    parts.f32     project    source  tvdir   tvforms
CMakeCache.txt  cmake_install.cmake  COPYRIGHT       genparts  hello     include    Makefile      palette  phonenum.f32  README.md  tvdemo  tvedit  tvhc
apreche:~/projects/tvision [master %] $

Library `tinfow` required in Linking

I was looking around to find a TUI library for C++, and I ended up here. I was trying this fork of tvision out yesterday and I noticed that all applications would segfault after compilation.

After debugging I found out that I need to link tinfow after ncursesw for it to work.

So with

if (TV_PLATF EQUAL TV_PLATF_UNIX)
    find_library(NCURSESW ncursesw REQUIRED)
    if (NCURSESW)
-        list(APPEND LIBS ${NCURSESW})
+        list(APPEND LIBS ${NCURSESW} tinfow)
        target_compile_definitions(tvision PRIVATE HAVE_NCURSES)
    endif()
    # Optional dependencies
    find_library(GPM gpm)
    if (GPM)
        list(APPEND LIBS ${GPM})
        target_compile_definitions(tvision PRIVATE HAVE_GPM)
    endif()
endif()

(This was also for the GPL fork of tvision, they have the same issue)

I am on Gentoo Linux with ncurses 6.2-r1 and gcc 9.3.0.

I would suggest checking if tinfow is available and linking it when it and ncursesw do.

Please note that tinfow is required. It will NOT work with tinfo!

Info for Gentoo Uses: tinfo and tinfow are installed when the tinfo use flag is set on ncruses.

building on Win11/64bit/Visual Studio 2022 - util.h errors

First of all, thanks for the excellent library. I've been building a tiny program on linux and it works fine. I'm using tvision as a git submodule, and building using cmake.

However, when I use Visual Studio 2022 with the same code, I get the following errors when building the generated solution... Is there something obvious I'm missing?

<prj>\tvision\include\tvision/util.h(21,22): error C2062: type 'int' unexpected [<prj>\build\ed6.vcxproj]
<prj>\tvision\include\tvision/util.h(21,22): error C2059: syntax error: ')' [<prj>\build\ed6.vcxproj]
<prj>\tvision\include\tvision/util.h(22,1): error C2143: syntax error: missing ';' before '{' [<prj>\build\ 
ed6.vcxproj]
<prj>\tvision\include\tvision/util.h(22,1): error C2447: '{': missing function header (old-style formal list?) [D: 
\code2\ed6\build\ed6.vcxproj]
<prj>\tvision\include\tvision/util.h(26,22): error C2062: type 'int' unexpected [<prj>\build\ed6.vcxproj]   
<prj>\tvision\include\tvision/util.h(26,22): error C2059: syntax error: ')' [<prj>\build\ed6.vcxproj]       
<prj>\tvision\include\tvision/util.h(27,1): error C2143: syntax error: missing ';' before '{' [<prj>\build\ 
ed6.vcxproj]
<prj>\tvision\include\tvision/util.h(27,1): error C2447: '{': missing function header (old-style formal list?) [D: 
\code2\ed6\build\ed6.vcxproj]
<prj>\tvision\include\tvision/util.h(34,27): error C2988: unrecognizable template declaration/definition [D:\code2 
\ed6\build\ed6.vcxproj]
<prj>\tvision\include\tvision/util.h(34,27): error C2059: syntax error: 'const' [<prj>\build\ed6.vcxproj]   
<prj>\tvision\include\tvision/util.h(34,1): error C2059: syntax error: ')' [<prj>\build\ed6.vcxproj]        
<prj>\tvision\include\tvision/util.h(35,1): error C2143: syntax error: missing ';' before '{' [<prj>\build\ 
ed6.vcxproj]
<prj>\tvision\include\tvision/util.h(35,1): error C2447: '{': missing function header (old-style formal list?) [D: 
\code2\ed6\build\ed6.vcxproj]
<prj>\tvision\include\tvision/util.h(40,27): error C2988: unrecognizable template declaration/definition [D:\code2 
\ed6\build\ed6.vcxproj]
<prj>\tvision\include\tvision/util.h(40,27): error C2059: syntax error: 'const' [<prj>\build\ed6.vcxproj]   
<prj>\tvision\include\tvision/util.h(40,1): error C2059: syntax error: ')' [<prj>\build\ed6.vcxproj]        
<prj>\tvision\include\tvision/util.h(41,1): error C2143: syntax error: missing ';' before '{' [<prj>\build\ 
ed6.vcxproj]
<prj>\tvision\include\tvision/util.h(41,1): error C2447: '{': missing function header (old-style formal list?) [D: 
\code2\ed6\build\ed6.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\include\limits(41,67): fatal error C190 
3: unable to recover from previous error(s); stopping compilation [<prj>\build\ed6.vcxproj]

alternative mouse support

hi, i've been studying how midnight commander manages to provide mouse support without GPM nor mouse-support baked into curses, and it seems to be relatively easy.

lib/tty/tty.c

    xmouse_seq = tty_tgetstr ("kmous");
    if (xmouse_seq == NULL)
        xmouse_seq = tty_tgetstr ("Km");
    smcup = tty_tgetstr ("smcup");
    if (smcup == NULL)
        smcup = tty_tgetstr ("ti");
    rmcup = tty_tgetstr ("rmcup");
    if (rmcup == NULL)
        rmcup = tty_tgetstr ("te");
...
    if (is_xterm)
    {
        /* Default to the standard xterm sequence */
        if (xmouse_seq == NULL)
            xmouse_seq = ESC_STR "[M";

        /* Enable mouse unless explicitly disabled by --nomouse */
        if (use_mouse_p != MOUSE_DISABLED)
        {
            if (mc_global.tty.old_mouse)
                use_mouse_p = MOUSE_XTERM_NORMAL_TRACKING;
            else
            {
                /* FIXME: this dirty hack to set supported type of tracking the mouse */
                const char *color_term = getenv ("COLORTERM");
                if (strncmp (termvalue, "rxvt", 4) == 0 ||
                    (color_term != NULL && strncmp (color_term, "rxvt", 4) == 0) ||
                    strcmp (termvalue, "Eterm") == 0)
                    use_mouse_p = MOUSE_XTERM_NORMAL_TRACKING;
                else
                    use_mouse_p = MOUSE_XTERM_BUTTON_EVENT_TRACKING;
            }
        }
    }

    /* No termcap for SGR extended mouse (yet), hardcode it for now */
    if (xmouse_seq != NULL)
        xmouse_extended_seq = ESC_STR "[<";

lib/tty/mouse.c

void 
init_mouse (void)
{
    switch (use_mouse_p)
    {
    case MOUSE_XTERM_NORMAL_TRACKING:
    case MOUSE_XTERM_BUTTON_EVENT_TRACKING:
        define_sequence (MCKEY_MOUSE, xmouse_seq, MCKEY_NOACTION);
        define_sequence (MCKEY_EXTENDED_MOUSE, xmouse_extended_seq, MCKEY_NOACTION);
        break;

    default:
        break;
    }

    enable_mouse ();
}

void
enable_mouse (void)
{
    if (mouse_enabled)
        return;

    switch (use_mouse_p)
    {   
    case MOUSE_XTERM_NORMAL_TRACKING:
        /* save old highlight mouse tracking */
        printf (ESC_STR "[?1001s");

        /* enable mouse tracking */
        printf (ESC_STR "[?1000h");
        
        /* enable SGR extended mouse reporting */
        printf (ESC_STR "[?1006h");
    
        fflush (stdout);
        mouse_enabled = TRUE;
        break;
            
    case MOUSE_XTERM_BUTTON_EVENT_TRACKING:
        /* save old highlight mouse tracking */
        printf (ESC_STR "[?1001s");

        /* enable mouse tracking */
        printf (ESC_STR "[?1002h");
            
        /* enable SGR extended mouse reporting */
        printf (ESC_STR "[?1006h");
 
        fflush (stdout);
        mouse_enabled = TRUE;
        break;

    default:
        break;
    }
}

void
disable_mouse (void)
{
    if (!mouse_enabled)
        return;

    mouse_enabled = FALSE;

    switch (use_mouse_p)
    {
    case MOUSE_XTERM_NORMAL_TRACKING:
        /* disable SGR extended mouse reporting */
        printf (ESC_STR "[?1006l");

        /* disable mouse tracking */
        printf (ESC_STR "[?1000l");

        /* restore old highlight mouse tracking */
        printf (ESC_STR "[?1001r");
        fflush (stdout);
        break;
    case MOUSE_XTERM_BUTTON_EVENT_TRACKING:
        /* disable SGR extended mouse reporting */
        printf (ESC_STR "[?1006l");

        /* disable mouse tracking */
        printf (ESC_STR "[?1002l");

        /* restore old highlight mouse tracking */
        printf (ESC_STR "[?1001r");

        fflush (stdout);
        break;
    default:
        break;
    }
}

the is_xterm variable is set from a heuristic in lib/tty/tty.c - the force_xterm parameter is true when the command line arg -x was provided to mc.

/**
 * Check terminal type. If $TERM is not set or value is empty, mc finishes with EXIT_FAILURE.
 *
 * @param force_xterm Set forced the XTerm type
 *
 * @return true if @param force_xterm is true or value of $TERM is one of term*, konsole*
 *              rxvt*, Eterm or dtterm
 */
gboolean
tty_check_term (gboolean force_xterm)
{  
    const char *termvalue;
    const char *xdisplay;
   
    termvalue = getenv ("TERM");
    if (termvalue == NULL || *termvalue == '\0')
    {
        fputs (_("The TERM environment variable is unset!\n"), stderr);
        exit (EXIT_FAILURE);
    }
 
    xdisplay = getenv ("DISPLAY");
    if (xdisplay != NULL && *xdisplay == '\0')
        xdisplay = NULL;

    return force_xterm || strncmp (termvalue, "xterm", 5) == 0
        || strncmp (termvalue, "konsole", 7) == 0
        || strncmp (termvalue, "rxvt", 4) == 0
        || strcmp (termvalue, "Eterm") == 0
        || strcmp (termvalue, "dtterm") == 0
        || (strncmp (termvalue, "screen", 6) == 0 && xdisplay != NULL);
}

finally, in lib/tty/key.c, input is translated into GPM messages:

static void
xmouse_get_event (Gpm_Event * ev, gboolean extended)
{
    static struct timeval tv1 = { 0, 0 };       /* Force first click as single */
    static struct timeval tv2;
    static int clicks = 0;
    static int last_btn = 0;
    int btn;

    /* Decode Xterm mouse information to a GPM style event */

    if (!extended)
    {
        /* Variable btn has following meaning: */
        /* 0 = btn1 dn, 1 = btn2 dn, 2 = btn3 dn, 3 = btn up */
        btn = tty_lowlevel_getch () - 32;
        /* Coordinates are 33-based */
        /* Transform them to 1-based */
        ev->x = tty_lowlevel_getch () - 32;
        ev->y = tty_lowlevel_getch () - 32;
    }
    else
    {
        /* SGR 1006 extension (e.g. "\e[<0;12;300M"):
           - Numbers are encoded in decimal to make it ASCII-safe
           and to overcome the limit of 223 columns/rows.
           - Mouse release is encoded by trailing 'm' rather than 'M'
           so that the released button can be reported.
           - Numbers are no longer offset by 32. */
        char c;
        btn = ev->x = ev->y = 0;
        ev->type = 0;           /* In case we return on an invalid sequence */
        while ((c = tty_lowlevel_getch ()) != ';')
        {
            if (c < '0' || c > '9')
                return;
            btn = 10 * btn + (c - '0');
        }
        while ((c = tty_lowlevel_getch ()) != ';')
        {
            if (c < '0' || c > '9')
                return;
            ev->x = 10 * ev->x + (c - '0');
        }
        while ((c = tty_lowlevel_getch ()) != 'M' && c != 'm')
        {
            if (c < '0' || c > '9')
                return;
            ev->y = 10 * ev->y + (c - '0');
        }
        /* Legacy mouse protocol doesn't tell which button was released,
           conveniently all of mc's widgets are written not to rely on this
           information. With the SGR extension the released button becomes
           known, but for the sake of simplicity we just ignore it. */
        if (c == 'm')
            btn = 3;
    }

    /* There seems to be no way of knowing which button was released */
    /* So we assume all the buttons were released */

    if (btn == 3)
    {
        if (last_btn != 0)
        {
            if ((last_btn & (GPM_B_UP | GPM_B_DOWN)) != 0)
            {
                /* FIXME: DIRTY HACK */
                /* don't generate GPM_UP after mouse wheel */
                /* need for menu event handling */
                ev->type = 0;
                tv1.tv_sec = 0;
                tv1.tv_usec = 0;
            }
            else
            {
                ev->type = GPM_UP | (GPM_SINGLE << clicks);
                GET_TIME (tv1);
            }
            ev->buttons = 0;
            last_btn = 0;
            clicks = 0;
        }
        else
        {
            /* Bogus event, maybe mouse wheel */
            ev->type = 0;
        }
    }
    else
    {
        if (btn >= 32 && btn <= 34)
        {
            btn -= 32;
            ev->type = GPM_DRAG;
        }
        else
            ev->type = GPM_DOWN;

        GET_TIME (tv2);
        if (tv1.tv_sec && (DIF_TIME (tv1, tv2) < double_click_speed))
        {
            clicks++;
            clicks %= 3;
        }
        else
            clicks = 0;

        switch (btn)
        {
        case 0:
            ev->buttons = GPM_B_LEFT;
            break;
        case 1:
            ev->buttons = GPM_B_MIDDLE;
            break;
        case 2:
            ev->buttons = GPM_B_RIGHT;
            break;
        case 64:
            ev->buttons = GPM_B_UP;
            clicks = 0;
            break;
        case 65:
            ev->buttons = GPM_B_DOWN;
            clicks = 0;
            break;
        default:
            /* Nothing */
            ev->type = 0;
            ev->buttons = 0;
            break;
        }
        last_btn = ev->buttons;
    }
}

/* --------------------------------------------------------------------------------------------- */
/* Returns a character read from stdin with appropriate interpretation */
/* Also takes care of generated mouse events */
/* Returns EV_MOUSE if it is a mouse event */
/* Returns EV_NONE  if non-blocking or interrupt set and nothing was done */

int
tty_get_event (struct Gpm_Event *event, gboolean redo_event, gboolean block)
{
...
    if (mouse_enabled && (c == MCKEY_MOUSE
#ifdef KEY_MOUSE
                          || c == KEY_MOUSE
#endif /* KEY_MOUSE */
                          || c == MCKEY_EXTENDED_MOUSE))
    {
        /* Mouse event */
        xmouse_get_event (event, c == MCKEY_EXTENDED_MOUSE);
        c = (event->type != 0) ? EV_MOUSE : EV_NONE;
    }
...
}

(adding these snippets here for the record, in case you're interested into adding support, and also as a reference for myself).

Right-to-left (RTL) text support needs improvement, including fixing the README

From the README:

        *new TMenuItem( "העברית ~א~ינטרנט", cmNo, kbNoKey, hcNoContext ) +
         newLine() +

This should create the text העברית אינטרנט with the א (at the beginning of the leftmost word) in red.

Instead, as can be seen on the screenshot, it creates a different text ינטרנטא העברית where the words have now switched sides, and the א has moved from the beginning of the word (right) to its end (left). This way the word אינטרנט ("internet") has become ינטרנטא ("yanterneta"?).

Unicode and zero width charcaters

With zero width characters being drawn as a question mark, I'm wondering how to display something like the images attached. In this case, the zero width character should place a dot over the last symbol (image 1), but instead displays a single column wide question mark (image 2)
image_1
image_2

There is also extra spacing in image 2 that shouldn't be there.

Is there a way to get the string displayed properly?

This is the string
"\xe0\xa4\x95\xe0\xa4\xbe\xe0\xa4\x9a\xe0\xa4\x82\x0a"

THelpWindow: link formatting is wrong when preceded by multi-byte UTF-8 character

I have prepared a test program: https://gist.github.com/electroly/c57e79c035b01a9f2b764311cce476a6

image
image

When the é character is on the same line as the link, the link coloring and click target is shifted over by one character, misaligned from the actual link text. If you resize the help window small enough that the link wraps onto the next line, then it's fine. They must be on the same on-screen line for this to happen.

The é character in this help file is \xC3\xA9, so I assume it must be incorrectly using byte lengths for link formatting here. If I convert this file to CP437 so that the character is \x82, then it displays correctly.

Garbage and crash in Help window

After a certain point in the commit history, the Help window started to trim its message from "No help is avaiable in this context." to "No help", often appended with garbage.

Screenshot_20190514_183817

I can also experience a crash when using the computers at college, reproducible by maximizing and then restoring the window without moving it around or resizing it.

Thread 1 "tvdemo" received signal SIGSEGV, Segmentation fault.
0x00007ffff6b891b2 in _int_free (av=0x7ffff6eae640 <main_arena>, p=<optimized out>, have_lock=0) at malloc.c:4019

#0  0x00007ffff6b891b2 in _int_free (av=0x7ffff6eae640 <main_arena>, p=<optimized out>, have_lock=0) at malloc.c:4019
#1  0x000000000043482e in deleteBlock (blk=0x7c0c10) at /dev/shm/tvision/source/tvision/new.cpp:188
#2  0x000000000043487a in operator delete[] (blk=0x7c0c10) at /dev/shm/tvision/source/tvision/new.cpp:200
#3  0x000000000040f5d5 in THelpViewer::draw (this=0x7be9a0) at /dev/shm/tvision/source/tvision/help.cpp:154
#4  0x000000000041356e in TView::drawView (this=0x7be9a0) at /dev/shm/tvision/source/tvision/tview.cpp:337
#5  0x00000000004171b0 in TScroller::changeBounds (this=0x7be9a0, bounds=...) at /dev/shm/tvision/source/tvision/tscrolle.cpp:65
#6  0x000000000040f1bb in THelpViewer::changeBounds (this=0x7be9a0, bounds=...) at /dev/shm/tvision/source/tvision/help.cpp:83
#7  0x0000000000423570 in doCalcChange (p=0x7be9a0, d=0x7fffffffd740) at /dev/shm/tvision/source/tvision/tgroup.cpp:65
#8  0x000000000043a1cf in TGroup::forEach (this=0x7be7b0, func=0x423514 <doCalcChange(TView*, void*)>, args=0x7fffffffd740) at /dev/shm/tvision/source/tvision/grp.cpp:51
#9  0x000000000042369f in TGroup::changeBounds (this=0x7be7b0, bounds=...) at /dev/shm/tvision/source/tvision/tgroup.cpp:97
#10 0x0000000000413d84 in TView::locate (this=0x7be7b0, bounds=...) at /dev/shm/tvision/source/tvision/tview.cpp:507
#11 0x0000000000410f98 in TWindow::zoom (this=0x7be7b0) at /dev/shm/tvision/source/tvision/twindow.cpp:229
#12 0x0000000000410ad9 in TWindow::handleEvent (this=0x7be7b0, event=...) at /dev/shm/tvision/source/tvision/twindow.cpp:139
#13 0x000000000042399e in TGroup::execute (this=0x7be7b0) at /dev/shm/tvision/source/tvision/tgroup.cpp:182
#14 0x0000000000423b06 in TGroup::execView (this=0x6a9cb0, p=0x7be7b0) at /dev/shm/tvision/source/tvision/tgroup.cpp:207
#15 0x0000000000407291 in TVDemo::getEvent (this=0x6a9cb0, event=...) at /dev/shm/tvision/examples/tvdemo/tvdemo1.cpp:145
#16 0x0000000000423980 in TGroup::execute (this=0x6a9cb0) at /dev/shm/tvision/source/tvision/tgroup.cpp:181
#17 0x0000000000419e5f in TProgram::run (this=0x6a9cb0) at /dev/shm/tvision/source/tvision/tprogram.cpp:279
#18 0x0000000000406adc in main (argc=1, argv=0x7fffffffdb08) at /dev/shm/tvision/examples/tvdemo/tvdemo1.cpp:63

Using openSUSE Leap 42.3, linux 4.4.165-81-default, gcc 4.8.5 and glibc 2.22.

Ctrl+Space / Ctrl+@ (NUL) in input line on Linux eventually causes tvision crash

Run tvedit, File->Open.., enter several Ctrl+@ characters (shown as spaces..), then backspace them. See tvedit crashes.

Fix might be like this:

From 90660811ec90279e1cec23df4fd186fc94a52b48 Mon Sep 17 00:00:00 2001
From: Anton Kovalenko <[email protected]>
Date: Mon, 21 Dec 2020 15:53:48 +0300
Subject: [PATCH] TInputLine: never add \NUL to an input line

strlen(data) is used on input line text, so putting \nul there
(e.g. pressing Ctrl+Space or Ctrl+@ on Linux) confuses TInputLine into
invalid memory access.
---
 source/tvision/tinputli.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/source/tvision/tinputli.cpp b/source/tvision/tinputli.cpp
index f1569b7..bc1f8e1 100644
--- a/source/tvision/tinputli.cpp
+++ b/source/tvision/tinputli.cpp
@@ -356,7 +356,7 @@ void TInputLine::handleEvent( TEvent& event )
                         setState(sfCursorIns, Boolean(!(state & sfCursorIns)));
                         break;
                     default:
-                        if ((len = event.keyDown.textLength))
+                        if ((len = event.keyDown.textLength) && event.keyDown.text[0])
                             {
                             deleteSelect();
                             if( (state & sfCursorIns) != 0 )
-- 
2.27.0

Critical error when entering national symbols in TInputLine.

Greetings!
It is sad, but a fact, the library contains a critical error that leads to the crash of the program when entering national symbols into the input line of the TInputLine object.

To be honest, I don't know how it will happen on layouts other than Russian. The steps to reproduce the error are as follows:

  1. create a dialog box with an input line and a button.
  2. activate it
  3. move the input focus to the line
  4. switch to the national layout
  5. select all the text if it is in the input line
  6. we start typing the word with a capital letter using "Shift"
    ...
    in some cases, the library selects non-existent text, that is, the first character is obtained and the selection is green to the end of an empty line, sometimes it simply selects the first symbol and while Shift is clamped, all the symbols are entered into the position where the cursor is. sometimes when you enter several characters, the program crashes.

it is sad that this error does not allow you to work normally

I'm ready to make a video to demonstrate this effect. put it on a file sharing site so that you can see it with your own eyes. I will demonstrate it on my dialog constructor.

yes, this error pops up only in the input line, using TMemo does not lead to such effects.

tvforms build error when cross-compiling for Windows from Linux with mingw-w64

image

I'm using tvision commit f5c4c35 with a fresh install of Arch Linux and mingw-w64. I see that your CI is building for Windows successfully, so this seems to be an issue cross-compiling for Windows from Linux. The name of these executables (genphone, genparts) makes me think the build process is trying to run them after building them, meaning they should have been built for the build system (Linux) and not the host system (Windows).

In traditional configure scripts there's usually the ability to specify separate build and host systems for cross-compiling. Is there a way I can do this for tvision?

I have a similar issue with tvhc, which I need to run as part of my own build. My workaround was to use Wine to execute tvhc.exe, but it would be nicer if I could build tvhc for the build system instead of the host system. Perhaps the best fix is for me to just do two tvision builds, one for Windows with TV_BUILD_EXAMPLES=OFF and one for Linux with TV_BUILD_EXAMPLES=ON. This would fix it all for me, but tvision would still be unable to cross-compile the tvforms example for anyone who wants to do that.

need help with creating node.js binding for tvision

Hello! I've just experimenting with node.js binding for tvision. This tool has the possibility to simplify such work:
https://github.com/charto/nbind

I followed this tutorial (replacing vg with tvision):
https://github.com/charto/nbind/blob/master/doc/vg-tutorial.md

Made simple demo js_tvision.cpp:

#include "../tvision/include/tvision/tv.h"
#include "nbind/api.h"

#include "nbind/nbind.h"


namespace tvision {

NBIND_CLASS(TApplication) {

  // Add an empty constructor
  construct<>();

  method(run);
}

}

Unfortunately, npm run -- node-gyp configure build step fails with the following error:

../../tvision/include/tvision/tv.h:634:10: fatal error: tvision/config.h: No such file or directory
  634 | #include <tvision/config.h>
      |          ^~~~~~~~~~~~~~~~~~
compilation terminated.

Please suggest the direction of further work! Thanks!

PS: There is a huge demand in the world of node.js for a powerful TUI framework. Take a look at this module and the number of its forks:
https://www.npmjs.com/package/blessed
https://www.npmjs.com/package/neo-blessed
https://www.npmjs.com/package/post-blessed
But its capabilities are far from those of Turbo Vision, and its usability is far from perfect. My dream is to be able to do "npm install tvision", and use all TV power to create TUI interfaces for cli node.js applications.

Official Open Watcom C/C++ Support

Given that Open Watcom C/C++ (1.9, v2 fork) is open-source and Borland C++ 4.52 is not, would you be willing to consider making Open Watcom an officially supported compiler for building DOS applications?

(Aside from a known bug in the Linux installer which you work around by either setting TERMINFO=/path/to/terminfo or setting TERM=vt100, it's also by far the easiest way to cross-build for DOS from modern OSes.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.