Skip to content

Commit

Permalink
[Linux console] UPPER/LOWER HALF BLOCK characters support
Browse files Browse the repository at this point in the history
Merge pull request #75 from netxs-group/dev/sdn
  • Loading branch information
o-sdn-o authored Jul 5, 2021
2 parents 7e46673 + 7d196e7 commit d2836b1
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 6 deletions.
66 changes: 63 additions & 3 deletions src/netxs/os/system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,13 +305,71 @@ namespace netxs::os
log(" os: mouse mode: ", mode & legacy::mouse ? "console" : "VT-style");
return mode;
}
static auto vtgafont_update()
static auto vtgafont_update(iota mode)
{
#if defined (__linux__)

if (local_mode())
if (mode & legacy::mouse)
{

auto chars = std::vector<unsigned char>(512 * 32 * 4);
auto fdata = console_font_op{ .op = KD_FONT_OP_GET,
.flags = 0,
.width = 32,
.height = 32,
.charcount = 512,
.data = chars.data() };
if (!ok(::ioctl(STDOUT_FD, KDFONTOP, &fdata), "KDFONTOP + KD_FONT_OP_GET failed")) return;

auto slice_bytes = (fdata.width + 7) / 8;
auto block_bytes = (slice_bytes * fdata.height + 31) / 32 * 32;
auto tophalf_idx = 10;
auto lowhalf_idx = 254;
auto tophalf_ptr = fdata.data + block_bytes * tophalf_idx;
auto lowhalf_ptr = fdata.data + block_bytes * lowhalf_idx;
for (auto row = 0; row < fdata.height; row++)
{
auto is_top = row < fdata.height / 2;
*tophalf_ptr = is_top ? 0xFF : 0x00;
*lowhalf_ptr = is_top ? 0x00 : 0xFF;
tophalf_ptr+= slice_bytes;
lowhalf_ptr+= slice_bytes;
}
fdata.op = KD_FONT_OP_SET;
if (!ok(::ioctl(STDOUT_FD, KDFONTOP, &fdata), "KDFONTOP + KD_FONT_OP_SET failed")) return;

auto max_sz = std::numeric_limits<unsigned short>::max();
auto spairs = std::vector<unipair>(max_sz);
auto dpairs = std::vector<unipair>(max_sz);
auto srcmap = unimapdesc{ max_sz, spairs.data() };
auto dstmap = unimapdesc{ max_sz, dpairs.data() };
auto dstptr = dstmap.entries;
auto srcptr = srcmap.entries;
if (!ok(::ioctl(STDOUT_FD, GIO_UNIMAP, &srcmap), "GIO_UNIMAP failed")) return;
auto srcend = srcmap.entries + srcmap.entry_ct;
while (srcptr != srcend) // Drop 10, 211, 254 and 0x2580▀ + 0x2584▄.
{
auto& smap = *srcptr++;
if (smap.fontpos != 10
&& smap.fontpos != 211
&& smap.fontpos != 254
&& smap.unicode != 0x2580
&& smap.unicode != 0x2584) *dstptr++ = smap;
}
dstmap.entry_ct = dstptr - dstmap.entries;
unipair new_recs[] = { { 0x2580, 10 },
{ 0x2219, 211 },
{ 0x2022, 211 },
{ 0x25CF, 211 },
{ 0x25A0, 254 },
{ 0x25AE, 254 },
{ 0x2584, 254 } };
if (dstmap.entry_ct < max_sz - std::size(new_recs)) // Add new records.
{
for (auto& p : new_recs) *dstptr++ = p;
dstmap.entry_ct += std::size(new_recs);
if (!ok(::ioctl(STDOUT_FD, PIO_UNIMAP, &dstmap), "PIO_UNIMAP failed")) return;
}
else log(" os: vtgafont_update failed - UNIMAP is full");
}

#endif
Expand Down Expand Up @@ -2246,6 +2304,8 @@ namespace netxs::os
auto& ipcio = *_globals<void>::ipcio;

os::set_palette(mode);
os::vtgafont_update(mode);

auto input = std::thread{ [&]() { reader(mode); } };

while (output(ipcio.recv()))
Expand Down
6 changes: 3 additions & 3 deletions src/vtmd.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) NetXS Group.
// Licensed under the MIT license.

#define MONOTTY_VER "Monotty Desktopio v0.4.7"
#define MONOTTY_VER "Monotty Desktopio v0.4.8"
// Autostart demo apps.
//#define DEMO
// Enable keyboard input and disable exit by single Esc.
Expand Down Expand Up @@ -2489,7 +2489,7 @@ utility like ctags is used to locate the definitions.
auto block = item_area->template attach<ui::fork>(axis::X);
auto mark_area = block->template attach<slot::_1, ui::pads>(dent{ 1,1,0,0 }, dent{ 0,0,0,0 });
auto mark = mark_area->template attach<ui::item>(
ansi::bgc4(selected ? 0xFF00ff00 : 0xFF000000) + " ", faux)
ansi::fgc4(selected ? 0xFF00ff00 : 0xFF000000) + "██", faux)
->invoke([&](auto& boss)
{
if (auto client = client_shadow.lock())
Expand All @@ -2500,7 +2500,7 @@ utility like ctags is used to locate the definitions.
auto selected = id == data;
if(auto mark = mark_shadow.lock())
{
mark->set(ansi::bgc4(selected ? 0xFF00ff00 : 0xFF000000) + " ");
mark->set(ansi::bgc4(selected ? 0xFF00ff00 : 0xFF000000) + "██");
mark->deface();
}
};
Expand Down

0 comments on commit d2836b1

Please sign in to comment.