feat: switch text to UTF-8; add Unicode key events, dead keys & Czech layout; fix numpad navigation; add NumLock support
This commit is contained in:
1 parent
32660ddd1a
commit
2aa6360b3d
101 files changed
+3733
-1639
No files matched your search
@@ -466,13 +466,13 @@ static bool handle_key(const montauk::abi::KeyEvent& key) {
|
||||
if (g_game.game_over)
|
||||
return false;
|
||||
|
||||
if (key.scancode == 0x4B || key.ascii == 'a' || key.ascii == 'A')
|
||||
if (montauk::nav_scancode(key) == 0x4B || key.ascii == 'a' || key.ascii == 'A')
|
||||
return apply_move(DIR_LEFT);
|
||||
if (key.scancode == 0x4D || key.ascii == 'd' || key.ascii == 'D')
|
||||
if (montauk::nav_scancode(key) == 0x4D || key.ascii == 'd' || key.ascii == 'D')
|
||||
return apply_move(DIR_RIGHT);
|
||||
if (key.scancode == 0x48 || key.ascii == 'w' || key.ascii == 'W')
|
||||
if (montauk::nav_scancode(key) == 0x48 || key.ascii == 'w' || key.ascii == 'W')
|
||||
return apply_move(DIR_UP);
|
||||
if (key.scancode == 0x50 || key.ascii == 's' || key.ascii == 'S')
|
||||
if (montauk::nav_scancode(key) == 0x50 || key.ascii == 's' || key.ascii == 'S')
|
||||
return apply_move(DIR_DOWN);
|
||||
|
||||
return false;
|
||||
|
||||
@@ -469,12 +469,12 @@ static bool handle_key(const montauk::abi::KeyEvent& key) {
|
||||
g_win.closed = true;
|
||||
return false;
|
||||
}
|
||||
if (key.scancode == 0x4D || key.ascii == '+' || key.ascii == '=') {
|
||||
if (montauk::nav_scancode(key) == 0x4D || key.ascii == '+' || key.ascii == '=') {
|
||||
if (g_master_muted) toggle_master_mute();
|
||||
apply_master_volume(g_master_vol + 5);
|
||||
return true;
|
||||
}
|
||||
if (key.scancode == 0x4B || key.ascii == '-') {
|
||||
if (montauk::nav_scancode(key) == 0x4B || key.ascii == '-') {
|
||||
if (g_master_muted) toggle_master_mute();
|
||||
apply_master_volume(g_master_vol - 5);
|
||||
return true;
|
||||
|
||||
@@ -224,6 +224,8 @@ static void draw_text_fit(Canvas& c, int x, int y,
|
||||
out++;
|
||||
}
|
||||
|
||||
out = montauk::utf8::floor_boundary(text, montauk::slen(text), out);
|
||||
|
||||
if (out <= 0) return;
|
||||
buf[out] = '.';
|
||||
buf[out + 1] = '.';
|
||||
|
||||
@@ -400,6 +400,7 @@ static void fit_text(char* out, int outCap, const char* text, int maxWidth) {
|
||||
if (text_width(out) + text_width(ellipsis) > maxWidth) break;
|
||||
len++;
|
||||
}
|
||||
len = montauk::utf8::floor_boundary(text, montauk::slen(text), len);
|
||||
out[len++] = '.';
|
||||
out[len++] = '.';
|
||||
out[len++] = '.';
|
||||
@@ -798,8 +799,8 @@ static bool handle_key(const montauk::abi::KeyEvent& key) {
|
||||
return true;
|
||||
}
|
||||
int current = *selected_for_tab();
|
||||
if (key.scancode == 0x48) { select_index(current - 1); return true; } // Up
|
||||
if (key.scancode == 0x50) { select_index(current + 1); return true; } // Down
|
||||
if (montauk::nav_scancode(key) == 0x48) { select_index(current - 1); return true; } // Up
|
||||
if (montauk::nav_scancode(key) == 0x50) { select_index(current + 1); return true; } // Down
|
||||
if (key.ascii == 'r' || key.ascii == 'R') {
|
||||
reload();
|
||||
return true;
|
||||
|
||||
+204
-150
@@ -5,13 +5,9 @@
|
||||
* Browse curated sets of characters, click (or use the keyboard) to select,
|
||||
* and copy to the system clipboard for pasting into other apps.
|
||||
*
|
||||
* Character model: MontaukOS's GUI text stack is single-byte (Windows-1252,
|
||||
* with the 0x80-0x9F block mapped to typographic punctuation in
|
||||
* gui::decode_single_byte_codepoint). The glyph cache only holds codepoints
|
||||
* 0-255, so that byte range is exactly the set of glyphs the system font can
|
||||
* render. We therefore present that set and copy the *raw byte* to the
|
||||
* clipboard: it renders identically here and in every other Montauk app
|
||||
* (copying multi-byte UTF-8 would render as mojibake in the single-byte stack).
|
||||
* Character model: MontaukOS text is UTF-8. Each tile is a Unicode codepoint
|
||||
* and Copy puts its UTF-8 encoding on the clipboard. The sets are limited to
|
||||
* characters the system font (Roboto) actually has a glyph for.
|
||||
*
|
||||
* Copyright (c) 2026 Daniel Hammer
|
||||
*/
|
||||
@@ -37,7 +33,7 @@ using namespace gui;
|
||||
// ==== Character data ====
|
||||
|
||||
struct Glyph {
|
||||
uint8_t byte; // Windows-1252 byte value (what gets copied / rendered)
|
||||
uint32_t cp; // Unicode codepoint (copied as UTF-8)
|
||||
const char* name; // human-readable description
|
||||
};
|
||||
|
||||
@@ -49,141 +45,194 @@ struct CharSet {
|
||||
|
||||
// Accented Latin letters and ligatures (things you can't easily type).
|
||||
static const Glyph LATIN[] = {
|
||||
{0xC0, "Latin Capital Letter A With Grave"},
|
||||
{0xC1, "Latin Capital Letter A With Acute"},
|
||||
{0xC2, "Latin Capital Letter A With Circumflex"},
|
||||
{0xC3, "Latin Capital Letter A With Tilde"},
|
||||
{0xC4, "Latin Capital Letter A With Diaeresis"},
|
||||
{0xC5, "Latin Capital Letter A With Ring Above"},
|
||||
{0xC6, "Latin Capital Letter AE"},
|
||||
{0xC7, "Latin Capital Letter C With Cedilla"},
|
||||
{0xC8, "Latin Capital Letter E With Grave"},
|
||||
{0xC9, "Latin Capital Letter E With Acute"},
|
||||
{0xCA, "Latin Capital Letter E With Circumflex"},
|
||||
{0xCB, "Latin Capital Letter E With Diaeresis"},
|
||||
{0xCC, "Latin Capital Letter I With Grave"},
|
||||
{0xCD, "Latin Capital Letter I With Acute"},
|
||||
{0xCE, "Latin Capital Letter I With Circumflex"},
|
||||
{0xCF, "Latin Capital Letter I With Diaeresis"},
|
||||
{0xD0, "Latin Capital Letter Eth"},
|
||||
{0xD1, "Latin Capital Letter N With Tilde"},
|
||||
{0xD2, "Latin Capital Letter O With Grave"},
|
||||
{0xD3, "Latin Capital Letter O With Acute"},
|
||||
{0xD4, "Latin Capital Letter O With Circumflex"},
|
||||
{0xD5, "Latin Capital Letter O With Tilde"},
|
||||
{0xD6, "Latin Capital Letter O With Diaeresis"},
|
||||
{0xD8, "Latin Capital Letter O With Stroke"},
|
||||
{0xD9, "Latin Capital Letter U With Grave"},
|
||||
{0xDA, "Latin Capital Letter U With Acute"},
|
||||
{0xDB, "Latin Capital Letter U With Circumflex"},
|
||||
{0xDC, "Latin Capital Letter U With Diaeresis"},
|
||||
{0xDD, "Latin Capital Letter Y With Acute"},
|
||||
{0xDE, "Latin Capital Letter Thorn"},
|
||||
{0x8A, "Latin Capital Letter S With Caron"},
|
||||
{0x8C, "Latin Capital Ligature OE"},
|
||||
{0x8E, "Latin Capital Letter Z With Caron"},
|
||||
{0x9F, "Latin Capital Letter Y With Diaeresis"},
|
||||
{0xDF, "Latin Small Letter Sharp S"},
|
||||
{0xE0, "Latin Small Letter A With Grave"},
|
||||
{0xE1, "Latin Small Letter A With Acute"},
|
||||
{0xE2, "Latin Small Letter A With Circumflex"},
|
||||
{0xE3, "Latin Small Letter A With Tilde"},
|
||||
{0xE4, "Latin Small Letter A With Diaeresis"},
|
||||
{0xE5, "Latin Small Letter A With Ring Above"},
|
||||
{0xE6, "Latin Small Letter AE"},
|
||||
{0xE7, "Latin Small Letter C With Cedilla"},
|
||||
{0xE8, "Latin Small Letter E With Grave"},
|
||||
{0xE9, "Latin Small Letter E With Acute"},
|
||||
{0xEA, "Latin Small Letter E With Circumflex"},
|
||||
{0xEB, "Latin Small Letter E With Diaeresis"},
|
||||
{0xEC, "Latin Small Letter I With Grave"},
|
||||
{0xED, "Latin Small Letter I With Acute"},
|
||||
{0xEE, "Latin Small Letter I With Circumflex"},
|
||||
{0xEF, "Latin Small Letter I With Diaeresis"},
|
||||
{0xF0, "Latin Small Letter Eth"},
|
||||
{0xF1, "Latin Small Letter N With Tilde"},
|
||||
{0xF2, "Latin Small Letter O With Grave"},
|
||||
{0xF3, "Latin Small Letter O With Acute"},
|
||||
{0xF4, "Latin Small Letter O With Circumflex"},
|
||||
{0xF5, "Latin Small Letter O With Tilde"},
|
||||
{0xF6, "Latin Small Letter O With Diaeresis"},
|
||||
{0xF8, "Latin Small Letter O With Stroke"},
|
||||
{0xF9, "Latin Small Letter U With Grave"},
|
||||
{0xFA, "Latin Small Letter U With Acute"},
|
||||
{0xFB, "Latin Small Letter U With Circumflex"},
|
||||
{0xFC, "Latin Small Letter U With Diaeresis"},
|
||||
{0xFD, "Latin Small Letter Y With Acute"},
|
||||
{0xFE, "Latin Small Letter Thorn"},
|
||||
{0xFF, "Latin Small Letter Y With Diaeresis"},
|
||||
{0x9A, "Latin Small Letter S With Caron"},
|
||||
{0x9C, "Latin Small Ligature OE"},
|
||||
{0x9E, "Latin Small Letter Z With Caron"},
|
||||
{0x83, "Latin Small Letter F With Hook"},
|
||||
{0x00C0, "Latin Capital Letter A With Grave"},
|
||||
{0x00C1, "Latin Capital Letter A With Acute"},
|
||||
{0x00C2, "Latin Capital Letter A With Circumflex"},
|
||||
{0x00C3, "Latin Capital Letter A With Tilde"},
|
||||
{0x00C4, "Latin Capital Letter A With Diaeresis"},
|
||||
{0x00C5, "Latin Capital Letter A With Ring Above"},
|
||||
{0x00C6, "Latin Capital Letter AE"},
|
||||
{0x00C7, "Latin Capital Letter C With Cedilla"},
|
||||
{0x00C8, "Latin Capital Letter E With Grave"},
|
||||
{0x00C9, "Latin Capital Letter E With Acute"},
|
||||
{0x00CA, "Latin Capital Letter E With Circumflex"},
|
||||
{0x00CB, "Latin Capital Letter E With Diaeresis"},
|
||||
{0x00CC, "Latin Capital Letter I With Grave"},
|
||||
{0x00CD, "Latin Capital Letter I With Acute"},
|
||||
{0x00CE, "Latin Capital Letter I With Circumflex"},
|
||||
{0x00CF, "Latin Capital Letter I With Diaeresis"},
|
||||
{0x00D0, "Latin Capital Letter Eth"},
|
||||
{0x00D1, "Latin Capital Letter N With Tilde"},
|
||||
{0x00D2, "Latin Capital Letter O With Grave"},
|
||||
{0x00D3, "Latin Capital Letter O With Acute"},
|
||||
{0x00D4, "Latin Capital Letter O With Circumflex"},
|
||||
{0x00D5, "Latin Capital Letter O With Tilde"},
|
||||
{0x00D6, "Latin Capital Letter O With Diaeresis"},
|
||||
{0x00D8, "Latin Capital Letter O With Stroke"},
|
||||
{0x00D9, "Latin Capital Letter U With Grave"},
|
||||
{0x00DA, "Latin Capital Letter U With Acute"},
|
||||
{0x00DB, "Latin Capital Letter U With Circumflex"},
|
||||
{0x00DC, "Latin Capital Letter U With Diaeresis"},
|
||||
{0x00DD, "Latin Capital Letter Y With Acute"},
|
||||
{0x00DE, "Latin Capital Letter Thorn"},
|
||||
{0x0160, "Latin Capital Letter S With Caron"},
|
||||
{0x0152, "Latin Capital Ligature OE"},
|
||||
{0x017D, "Latin Capital Letter Z With Caron"},
|
||||
{0x0178, "Latin Capital Letter Y With Diaeresis"},
|
||||
{0x00DF, "Latin Small Letter Sharp S"},
|
||||
{0x00E0, "Latin Small Letter A With Grave"},
|
||||
{0x00E1, "Latin Small Letter A With Acute"},
|
||||
{0x00E2, "Latin Small Letter A With Circumflex"},
|
||||
{0x00E3, "Latin Small Letter A With Tilde"},
|
||||
{0x00E4, "Latin Small Letter A With Diaeresis"},
|
||||
{0x00E5, "Latin Small Letter A With Ring Above"},
|
||||
{0x00E6, "Latin Small Letter AE"},
|
||||
{0x00E7, "Latin Small Letter C With Cedilla"},
|
||||
{0x00E8, "Latin Small Letter E With Grave"},
|
||||
{0x00E9, "Latin Small Letter E With Acute"},
|
||||
{0x00EA, "Latin Small Letter E With Circumflex"},
|
||||
{0x00EB, "Latin Small Letter E With Diaeresis"},
|
||||
{0x00EC, "Latin Small Letter I With Grave"},
|
||||
{0x00ED, "Latin Small Letter I With Acute"},
|
||||
{0x00EE, "Latin Small Letter I With Circumflex"},
|
||||
{0x00EF, "Latin Small Letter I With Diaeresis"},
|
||||
{0x00F0, "Latin Small Letter Eth"},
|
||||
{0x00F1, "Latin Small Letter N With Tilde"},
|
||||
{0x00F2, "Latin Small Letter O With Grave"},
|
||||
{0x00F3, "Latin Small Letter O With Acute"},
|
||||
{0x00F4, "Latin Small Letter O With Circumflex"},
|
||||
{0x00F5, "Latin Small Letter O With Tilde"},
|
||||
{0x00F6, "Latin Small Letter O With Diaeresis"},
|
||||
{0x00F8, "Latin Small Letter O With Stroke"},
|
||||
{0x00F9, "Latin Small Letter U With Grave"},
|
||||
{0x00FA, "Latin Small Letter U With Acute"},
|
||||
{0x00FB, "Latin Small Letter U With Circumflex"},
|
||||
{0x00FC, "Latin Small Letter U With Diaeresis"},
|
||||
{0x00FD, "Latin Small Letter Y With Acute"},
|
||||
{0x00FE, "Latin Small Letter Thorn"},
|
||||
{0x00FF, "Latin Small Letter Y With Diaeresis"},
|
||||
{0x0161, "Latin Small Letter S With Caron"},
|
||||
{0x0153, "Latin Small Ligature OE"},
|
||||
{0x017E, "Latin Small Letter Z With Caron"},
|
||||
{0x0192, "Latin Small Letter F With Hook"},
|
||||
};
|
||||
|
||||
// Typographic punctuation.
|
||||
static const Glyph PUNCT[] = {
|
||||
{0xA1, "Inverted Exclamation Mark"},
|
||||
{0xBF, "Inverted Question Mark"},
|
||||
{0x91, "Left Single Quotation Mark"},
|
||||
{0x92, "Right Single Quotation Mark"},
|
||||
{0x93, "Left Double Quotation Mark"},
|
||||
{0x94, "Right Double Quotation Mark"},
|
||||
{0x82, "Single Low-9 Quotation Mark"},
|
||||
{0x84, "Double Low-9 Quotation Mark"},
|
||||
{0xAB, "Left-Pointing Double Angle Quotation Mark"},
|
||||
{0xBB, "Right-Pointing Double Angle Quotation Mark"},
|
||||
{0x8B, "Single Left-Pointing Angle Quotation Mark"},
|
||||
{0x9B, "Single Right-Pointing Angle Quotation Mark"},
|
||||
{0x96, "En Dash"},
|
||||
{0x97, "Em Dash"},
|
||||
{0x85, "Horizontal Ellipsis"},
|
||||
{0x95, "Bullet"},
|
||||
{0xB7, "Middle Dot"},
|
||||
{0x86, "Dagger"},
|
||||
{0x87, "Double Dagger"},
|
||||
{0xB6, "Pilcrow Sign"},
|
||||
{0xA7, "Section Sign"},
|
||||
{0x89, "Per Mille Sign"},
|
||||
{0x00A1, "Inverted Exclamation Mark"},
|
||||
{0x00BF, "Inverted Question Mark"},
|
||||
{0x2018, "Left Single Quotation Mark"},
|
||||
{0x2019, "Right Single Quotation Mark"},
|
||||
{0x201C, "Left Double Quotation Mark"},
|
||||
{0x201D, "Right Double Quotation Mark"},
|
||||
{0x201A, "Single Low-9 Quotation Mark"},
|
||||
{0x201E, "Double Low-9 Quotation Mark"},
|
||||
{0x00AB, "Left-Pointing Double Angle Quotation Mark"},
|
||||
{0x00BB, "Right-Pointing Double Angle Quotation Mark"},
|
||||
{0x2039, "Single Left-Pointing Angle Quotation Mark"},
|
||||
{0x203A, "Single Right-Pointing Angle Quotation Mark"},
|
||||
{0x2013, "En Dash"},
|
||||
{0x2014, "Em Dash"},
|
||||
{0x2026, "Horizontal Ellipsis"},
|
||||
{0x2022, "Bullet"},
|
||||
{0x00B7, "Middle Dot"},
|
||||
{0x2020, "Dagger"},
|
||||
{0x2021, "Double Dagger"},
|
||||
{0x00B6, "Pilcrow Sign"},
|
||||
{0x00A7, "Section Sign"},
|
||||
{0x2030, "Per Mille Sign"},
|
||||
};
|
||||
|
||||
// Currency symbols.
|
||||
static const Glyph CURRENCY[] = {
|
||||
{0x24, "Dollar Sign"},
|
||||
{0xA2, "Cent Sign"},
|
||||
{0xA3, "Pound Sign"},
|
||||
{0xA5, "Yen Sign"},
|
||||
{0x80, "Euro Sign"},
|
||||
{0xA4, "Currency Sign"},
|
||||
{0x83, "Latin Small Letter F With Hook (Florin)"},
|
||||
{0x0024, "Dollar Sign"},
|
||||
{0x00A2, "Cent Sign"},
|
||||
{0x00A3, "Pound Sign"},
|
||||
{0x00A5, "Yen Sign"},
|
||||
{0x20AC, "Euro Sign"},
|
||||
{0x00A4, "Currency Sign"},
|
||||
{0x0192, "Latin Small Letter F With Hook (Florin)"},
|
||||
};
|
||||
|
||||
// Math, technical, and miscellaneous symbols.
|
||||
static const Glyph SYMBOLS[] = {
|
||||
{0xA9, "Copyright Sign"},
|
||||
{0xAE, "Registered Sign"},
|
||||
{0x99, "Trade Mark Sign"},
|
||||
{0xB0, "Degree Sign"},
|
||||
{0xB1, "Plus-Minus Sign"},
|
||||
{0xD7, "Multiplication Sign"},
|
||||
{0xF7, "Division Sign"},
|
||||
{0xB5, "Micro Sign"},
|
||||
{0xAC, "Not Sign"},
|
||||
{0xBC, "Vulgar Fraction One Quarter"},
|
||||
{0xBD, "Vulgar Fraction One Half"},
|
||||
{0xBE, "Vulgar Fraction Three Quarters"},
|
||||
{0xB9, "Superscript One"},
|
||||
{0xB2, "Superscript Two"},
|
||||
{0xB3, "Superscript Three"},
|
||||
{0xAA, "Feminine Ordinal Indicator"},
|
||||
{0xBA, "Masculine Ordinal Indicator"},
|
||||
{0xA6, "Broken Bar"},
|
||||
{0xB4, "Acute Accent"},
|
||||
{0xA8, "Diaeresis"},
|
||||
{0xAF, "Macron"},
|
||||
{0xB8, "Cedilla"},
|
||||
{0x88, "Modifier Letter Circumflex Accent"},
|
||||
{0x98, "Small Tilde"},
|
||||
{0x00A9, "Copyright Sign"},
|
||||
{0x00AE, "Registered Sign"},
|
||||
{0x2122, "Trade Mark Sign"},
|
||||
{0x00B0, "Degree Sign"},
|
||||
{0x00B1, "Plus-Minus Sign"},
|
||||
{0x00D7, "Multiplication Sign"},
|
||||
{0x00F7, "Division Sign"},
|
||||
{0x00B5, "Micro Sign"},
|
||||
{0x00AC, "Not Sign"},
|
||||
{0x00BC, "Vulgar Fraction One Quarter"},
|
||||
{0x00BD, "Vulgar Fraction One Half"},
|
||||
{0x00BE, "Vulgar Fraction Three Quarters"},
|
||||
{0x00B9, "Superscript One"},
|
||||
{0x00B2, "Superscript Two"},
|
||||
{0x00B3, "Superscript Three"},
|
||||
{0x00AA, "Feminine Ordinal Indicator"},
|
||||
{0x00BA, "Masculine Ordinal Indicator"},
|
||||
{0x00A6, "Broken Bar"},
|
||||
{0x00B4, "Acute Accent"},
|
||||
{0x00A8, "Diaeresis"},
|
||||
{0x00AF, "Macron"},
|
||||
{0x00B8, "Cedilla"},
|
||||
{0x02C6, "Modifier Letter Circumflex Accent"},
|
||||
{0x02DC, "Small Tilde"},
|
||||
};
|
||||
|
||||
// Beyond the old single-byte range: Greek (Roboto covers the whole block).
|
||||
static const Glyph GREEK[] = {
|
||||
{0x0391, "Greek Capital Letter Alpha"},
|
||||
{0x0392, "Greek Capital Letter Beta"},
|
||||
{0x0393, "Greek Capital Letter Gamma"},
|
||||
{0x0394, "Greek Capital Letter Delta"},
|
||||
{0x0395, "Greek Capital Letter Epsilon"},
|
||||
{0x0396, "Greek Capital Letter Zeta"},
|
||||
{0x0397, "Greek Capital Letter Eta"},
|
||||
{0x0398, "Greek Capital Letter Theta"},
|
||||
{0x0399, "Greek Capital Letter Iota"},
|
||||
{0x039A, "Greek Capital Letter Kappa"},
|
||||
{0x039B, "Greek Capital Letter Lamda"},
|
||||
{0x039C, "Greek Capital Letter Mu"},
|
||||
{0x039D, "Greek Capital Letter Nu"},
|
||||
{0x039E, "Greek Capital Letter Xi"},
|
||||
{0x039F, "Greek Capital Letter Omicron"},
|
||||
{0x03A0, "Greek Capital Letter Pi"},
|
||||
{0x03A1, "Greek Capital Letter Rho"},
|
||||
{0x03A3, "Greek Capital Letter Sigma"},
|
||||
{0x03A4, "Greek Capital Letter Tau"},
|
||||
{0x03A5, "Greek Capital Letter Upsilon"},
|
||||
{0x03A6, "Greek Capital Letter Phi"},
|
||||
{0x03A7, "Greek Capital Letter Chi"},
|
||||
{0x03A8, "Greek Capital Letter Psi"},
|
||||
{0x03A9, "Greek Capital Letter Omega"},
|
||||
{0x03B1, "Greek Small Letter Alpha"},
|
||||
{0x03B2, "Greek Small Letter Beta"},
|
||||
{0x03B3, "Greek Small Letter Gamma"},
|
||||
{0x03B4, "Greek Small Letter Delta"},
|
||||
{0x03B5, "Greek Small Letter Epsilon"},
|
||||
{0x03B6, "Greek Small Letter Zeta"},
|
||||
{0x03B7, "Greek Small Letter Eta"},
|
||||
{0x03B8, "Greek Small Letter Theta"},
|
||||
{0x03B9, "Greek Small Letter Iota"},
|
||||
{0x03BA, "Greek Small Letter Kappa"},
|
||||
{0x03BB, "Greek Small Letter Lamda"},
|
||||
{0x03BC, "Greek Small Letter Mu"},
|
||||
{0x03BD, "Greek Small Letter Nu"},
|
||||
{0x03BE, "Greek Small Letter Xi"},
|
||||
{0x03BF, "Greek Small Letter Omicron"},
|
||||
{0x03C0, "Greek Small Letter Pi"},
|
||||
{0x03C1, "Greek Small Letter Rho"},
|
||||
{0x03C2, "Greek Small Letter Final Sigma"},
|
||||
{0x03C3, "Greek Small Letter Sigma"},
|
||||
{0x03C4, "Greek Small Letter Tau"},
|
||||
{0x03C5, "Greek Small Letter Upsilon"},
|
||||
{0x03C6, "Greek Small Letter Phi"},
|
||||
{0x03C7, "Greek Small Letter Chi"},
|
||||
{0x03C8, "Greek Small Letter Psi"},
|
||||
{0x03C9, "Greek Small Letter Omega"},
|
||||
};
|
||||
|
||||
#define SET(arr, label) { label, arr, (int)(sizeof(arr) / sizeof(arr[0])) }
|
||||
@@ -192,6 +241,7 @@ static const CharSet SETS[] = {
|
||||
SET(PUNCT, "Punctuation"),
|
||||
SET(CURRENCY, "Currency"),
|
||||
SET(SYMBOLS, "Symbols"),
|
||||
SET(GREEK, "Greek"),
|
||||
};
|
||||
static constexpr int SET_COUNT = (int)(sizeof(SETS) / sizeof(SETS[0]));
|
||||
|
||||
@@ -319,29 +369,26 @@ static void ensure_visible(const Layout& L) {
|
||||
|
||||
// ==== Helpers ====
|
||||
|
||||
static void glyph_str(uint8_t byte, char out[2]) {
|
||||
out[0] = (char)byte;
|
||||
out[1] = '\0';
|
||||
}
|
||||
|
||||
static int codepoint_of(uint8_t byte) {
|
||||
return decode_single_byte_codepoint((int)byte);
|
||||
static int glyph_str(uint32_t cp, char out[5]) {
|
||||
int n = montauk::utf8::encode(cp, out);
|
||||
out[n] = '\0';
|
||||
return n;
|
||||
}
|
||||
|
||||
static void copy_selected() {
|
||||
const Glyph& g = cur_set().glyphs[g_sel];
|
||||
char s[2];
|
||||
glyph_str(g.byte, s);
|
||||
gui::clipboard_set_text(s, 1);
|
||||
char s[5];
|
||||
int n = glyph_str(g.cp, s);
|
||||
gui::clipboard_set_text(s, n);
|
||||
g_copied_until = montauk::get_milliseconds() + COPIED_MS;
|
||||
}
|
||||
|
||||
// ==== Rendering ====
|
||||
|
||||
static void draw_centered_glyph(Canvas& c, const Rect& r, uint8_t byte,
|
||||
static void draw_centered_glyph(Canvas& c, const Rect& r, uint32_t cp,
|
||||
Color color, int size) {
|
||||
char s[2];
|
||||
glyph_str(byte, s);
|
||||
char s[5];
|
||||
glyph_str(cp, s);
|
||||
int tw = text_width(fonts::system_font, s, size);
|
||||
int th = text_height(fonts::system_font, size);
|
||||
draw_text(c, fonts::system_font, r.x + (r.w - tw) / 2,
|
||||
@@ -376,7 +423,7 @@ static void render(Canvas& c) {
|
||||
c.fill_rounded_rect(r.x, r.y, r.w, r.h, g_theme.radius_md, border);
|
||||
c.fill_rounded_rect(r.x + 1, r.y + 1, r.w - 2, r.h - 2,
|
||||
g_theme.radius_md > 0 ? g_theme.radius_md - 1 : 0, fill);
|
||||
draw_centered_glyph(c, r, set.glyphs[i].byte, glyph, CELL_SIZE);
|
||||
draw_centered_glyph(c, r, set.glyphs[i].cp, glyph, CELL_SIZE);
|
||||
}
|
||||
|
||||
// ---- Scrollbar (shared MTK widget; no-ops when the set fits) ----
|
||||
@@ -407,14 +454,21 @@ static void render(Canvas& c) {
|
||||
g_theme.radius_md, g_theme.border);
|
||||
c.fill_rounded_rect(preview.x + 1, preview.y + 1, preview.w - 2, preview.h - 2,
|
||||
g_theme.radius_md - 1, colors::WHITE);
|
||||
draw_centered_glyph(c, preview, sg.byte, g_theme.text, PREVIEW_SIZE);
|
||||
draw_centered_glyph(c, preview, sg.cp, g_theme.text, PREVIEW_SIZE);
|
||||
|
||||
// Name + metadata, as a two-line block vertically centered on the preview.
|
||||
int cp = codepoint_of(sg.byte);
|
||||
int cp = (int)sg.cp;
|
||||
char enc[5];
|
||||
int enc_len = glyph_str(sg.cp, enc);
|
||||
char utf8_hex[16];
|
||||
int hp = 0;
|
||||
for (int i = 0; i < enc_len; i++)
|
||||
hp += snprintf(utf8_hex + hp, sizeof(utf8_hex) - hp, i ? " %02X" : "%02X",
|
||||
(unsigned)(uint8_t)enc[i]);
|
||||
int text_x = preview.x + preview.w + 14;
|
||||
char meta[64];
|
||||
snprintf(meta, sizeof(meta), "U+%04X dec %d Alt 0%d",
|
||||
cp, cp, (int)sg.byte);
|
||||
snprintf(meta, sizeof(meta), "U+%04X dec %d UTF-8 %s",
|
||||
cp, cp, utf8_hex);
|
||||
|
||||
int name_h = text_height(title_font, NAME_SIZE);
|
||||
int meta_h = text_height(fonts::system_font, META_SIZE);
|
||||
@@ -527,7 +581,7 @@ static bool handle_key(const montauk::abi::KeyEvent& key, int w, int h) {
|
||||
const int count = cur_set().count;
|
||||
bool redraw = false;
|
||||
|
||||
switch (key.scancode) {
|
||||
switch (montauk::nav_scancode(key)) {
|
||||
case 0x4B: // Left
|
||||
if (g_sel > 0) { g_sel--; ensure_visible(L); redraw = true; }
|
||||
break;
|
||||
|
||||
@@ -306,12 +306,12 @@ extern "C" void _start() {
|
||||
|
||||
if (ev.type == 0 && ev.key.pressed) {
|
||||
if (ev.key.scancode == 0x01) break; // Escape
|
||||
if (ev.key.scancode == 0x51) {
|
||||
if (montauk::nav_scancode(ev.key) == 0x51) {
|
||||
// Page Down: scroll down
|
||||
g_scroll += 60;
|
||||
render();
|
||||
}
|
||||
if (ev.key.scancode == 0x49) {
|
||||
if (montauk::nav_scancode(ev.key) == 0x49) {
|
||||
// Page Up: scroll up
|
||||
g_scroll -= 60;
|
||||
if (g_scroll < 0) g_scroll = 0;
|
||||
|
||||
@@ -351,36 +351,21 @@ void filemanager_on_key(Window* win, const montauk::abi::KeyEvent& key) {
|
||||
} else if (key.scancode == 0x01) {
|
||||
filemanager_cancel_pathbar(fm);
|
||||
} else if (key.ascii == '\b' || key.scancode == 0x0E) {
|
||||
if (fm->pathbar_cursor > 0) {
|
||||
for (int i = fm->pathbar_cursor - 1; i < fm->pathbar_len - 1; i++)
|
||||
fm->pathbar_buf[i] = fm->pathbar_buf[i + 1];
|
||||
fm->pathbar_len--;
|
||||
fm->pathbar_cursor--;
|
||||
fm->pathbar_buf[fm->pathbar_len] = '\0';
|
||||
}
|
||||
} else if (key.scancode == 0x53) {
|
||||
if (fm->pathbar_cursor < fm->pathbar_len) {
|
||||
for (int i = fm->pathbar_cursor; i < fm->pathbar_len - 1; i++)
|
||||
fm->pathbar_buf[i] = fm->pathbar_buf[i + 1];
|
||||
fm->pathbar_len--;
|
||||
fm->pathbar_buf[fm->pathbar_len] = '\0';
|
||||
}
|
||||
} else if (key.scancode == 0x4B) {
|
||||
if (fm->pathbar_cursor > 0) fm->pathbar_cursor--;
|
||||
} else if (key.scancode == 0x4D) {
|
||||
if (fm->pathbar_cursor < fm->pathbar_len) fm->pathbar_cursor++;
|
||||
} else if (key.scancode == 0x47) {
|
||||
montauk::utf8::erase_before(fm->pathbar_buf, &fm->pathbar_len, &fm->pathbar_cursor);
|
||||
} else if (montauk::nav_scancode(key) == 0x53) {
|
||||
montauk::utf8::erase_at(fm->pathbar_buf, &fm->pathbar_len, fm->pathbar_cursor);
|
||||
} else if (montauk::nav_scancode(key) == 0x4B) {
|
||||
fm->pathbar_cursor = montauk::utf8::prev_boundary(fm->pathbar_buf, fm->pathbar_cursor);
|
||||
} else if (montauk::nav_scancode(key) == 0x4D) {
|
||||
fm->pathbar_cursor = montauk::utf8::next_boundary(fm->pathbar_buf, fm->pathbar_len,
|
||||
fm->pathbar_cursor);
|
||||
} else if (montauk::nav_scancode(key) == 0x47) {
|
||||
fm->pathbar_cursor = 0;
|
||||
} else if (key.scancode == 0x4F) {
|
||||
} else if (montauk::nav_scancode(key) == 0x4F) {
|
||||
fm->pathbar_cursor = fm->pathbar_len;
|
||||
} else if ((unsigned char)key.ascii >= 32
|
||||
&& (unsigned char)key.ascii != 127 && fm->pathbar_len < 254) {
|
||||
for (int i = fm->pathbar_len; i > fm->pathbar_cursor; i--)
|
||||
fm->pathbar_buf[i] = fm->pathbar_buf[i - 1];
|
||||
fm->pathbar_buf[fm->pathbar_cursor] = key.ascii;
|
||||
fm->pathbar_cursor++;
|
||||
fm->pathbar_len++;
|
||||
fm->pathbar_buf[fm->pathbar_len] = '\0';
|
||||
} else {
|
||||
montauk::utf8::insert_key(fm->pathbar_buf, &fm->pathbar_len, 255,
|
||||
&fm->pathbar_cursor, key);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -394,44 +379,27 @@ void filemanager_on_key(Window* win, const montauk::abi::KeyEvent& key) {
|
||||
filemanager_cancel_rename(fm);
|
||||
} else if (key.ascii == '\b' || key.scancode == 0x0E) {
|
||||
// Backspace
|
||||
if (fm->rename_cursor > 0) {
|
||||
for (int i = fm->rename_cursor - 1; i < fm->rename_len - 1; i++)
|
||||
fm->rename_buf[i] = fm->rename_buf[i + 1];
|
||||
fm->rename_len--;
|
||||
fm->rename_cursor--;
|
||||
fm->rename_buf[fm->rename_len] = '\0';
|
||||
}
|
||||
} else if (key.scancode == 0x53) {
|
||||
montauk::utf8::erase_before(fm->rename_buf, &fm->rename_len, &fm->rename_cursor);
|
||||
} else if (montauk::nav_scancode(key) == 0x53) {
|
||||
// Delete key
|
||||
if (fm->rename_cursor < fm->rename_len) {
|
||||
for (int i = fm->rename_cursor; i < fm->rename_len - 1; i++)
|
||||
fm->rename_buf[i] = fm->rename_buf[i + 1];
|
||||
fm->rename_len--;
|
||||
fm->rename_buf[fm->rename_len] = '\0';
|
||||
}
|
||||
} else if (key.scancode == 0x4B) {
|
||||
montauk::utf8::erase_at(fm->rename_buf, &fm->rename_len, fm->rename_cursor);
|
||||
} else if (montauk::nav_scancode(key) == 0x4B) {
|
||||
// Left arrow
|
||||
if (fm->rename_cursor > 0) fm->rename_cursor--;
|
||||
} else if (key.scancode == 0x4D) {
|
||||
fm->rename_cursor = montauk::utf8::prev_boundary(fm->rename_buf, fm->rename_cursor);
|
||||
} else if (montauk::nav_scancode(key) == 0x4D) {
|
||||
// Right arrow
|
||||
if (fm->rename_cursor < fm->rename_len) fm->rename_cursor++;
|
||||
} else if (key.scancode == 0x47) {
|
||||
fm->rename_cursor = montauk::utf8::next_boundary(fm->rename_buf, fm->rename_len,
|
||||
fm->rename_cursor);
|
||||
} else if (montauk::nav_scancode(key) == 0x47) {
|
||||
// Home
|
||||
fm->rename_cursor = 0;
|
||||
} else if (key.scancode == 0x4F) {
|
||||
} else if (montauk::nav_scancode(key) == 0x4F) {
|
||||
// End
|
||||
fm->rename_cursor = fm->rename_len;
|
||||
} else if ((unsigned char)key.ascii >= 32
|
||||
&& (unsigned char)key.ascii != 127) {
|
||||
} else if (key.ascii != '/' && key.ascii != '\\') {
|
||||
// Printable character (reject / and other FS-unsafe chars)
|
||||
if (key.ascii != '/' && key.ascii != '\\' && fm->rename_len < 62) {
|
||||
for (int i = fm->rename_len; i > fm->rename_cursor; i--)
|
||||
fm->rename_buf[i] = fm->rename_buf[i - 1];
|
||||
fm->rename_buf[fm->rename_cursor] = key.ascii;
|
||||
fm->rename_cursor++;
|
||||
fm->rename_len++;
|
||||
fm->rename_buf[fm->rename_len] = '\0';
|
||||
}
|
||||
montauk::utf8::insert_key(fm->rename_buf, &fm->rename_len, 63,
|
||||
&fm->rename_cursor, key);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -466,7 +434,7 @@ void filemanager_on_key(Window* win, const montauk::abi::KeyEvent& key) {
|
||||
|
||||
if (key.ascii == '\b' || key.scancode == 0x0E) {
|
||||
filemanager_go_up(fm);
|
||||
} else if (key.scancode == 0x48) {
|
||||
} else if (montauk::nav_scancode(key) == 0x48) {
|
||||
// Up arrow
|
||||
if (fm->grid_view) {
|
||||
Rect cr_r = win->content_rect();
|
||||
@@ -477,7 +445,7 @@ void filemanager_on_key(Window* win, const montauk::abi::KeyEvent& key) {
|
||||
if (fm->selected > 0) fm->selected--;
|
||||
}
|
||||
filemanager_scroll_to_selected(win, fm);
|
||||
} else if (key.scancode == 0x50) {
|
||||
} else if (montauk::nav_scancode(key) == 0x50) {
|
||||
// Down arrow
|
||||
if (fm->grid_view) {
|
||||
Rect cr_r = win->content_rect();
|
||||
@@ -488,22 +456,22 @@ void filemanager_on_key(Window* win, const montauk::abi::KeyEvent& key) {
|
||||
if (fm->selected < fm->entry_count - 1) fm->selected++;
|
||||
}
|
||||
filemanager_scroll_to_selected(win, fm);
|
||||
} else if (key.scancode == 0x4B && !key.alt && fm->grid_view) {
|
||||
} else if (montauk::nav_scancode(key) == 0x4B && !key.alt && fm->grid_view) {
|
||||
// Left arrow (grid view only)
|
||||
if (fm->selected > 0) fm->selected--;
|
||||
} else if (key.scancode == 0x4D && !key.alt && fm->grid_view) {
|
||||
} else if (montauk::nav_scancode(key) == 0x4D && !key.alt && fm->grid_view) {
|
||||
// Right arrow (grid view only)
|
||||
if (fm->selected < fm->entry_count - 1) fm->selected++;
|
||||
} else if (key.ascii == '\n' || key.ascii == '\r') {
|
||||
if (fm->selected >= 0 && fm->selected < fm->entry_count)
|
||||
filemanager_open_entry(fm, fm->selected);
|
||||
} else if (key.scancode == 0x53) {
|
||||
} else if (montauk::nav_scancode(key) == 0x53) {
|
||||
// Delete key
|
||||
filemanager_delete_selected(fm);
|
||||
} else if (key.alt && key.scancode == 0x4B) {
|
||||
} else if (key.alt && montauk::nav_scancode(key) == 0x4B) {
|
||||
// Alt+Left: go back
|
||||
filemanager_go_back(fm);
|
||||
} else if (key.alt && key.scancode == 0x4D) {
|
||||
} else if (key.alt && montauk::nav_scancode(key) == 0x4D) {
|
||||
// Alt+Right: go forward
|
||||
filemanager_go_forward(fm);
|
||||
}
|
||||
|
||||
@@ -65,10 +65,10 @@ static void props_fit_text(const char* src, char* out, int out_len, int max_w) {
|
||||
while (len > 0) {
|
||||
out[len] = '\0';
|
||||
if (text_width(out) + ellipsis_w <= max_w) break;
|
||||
len--;
|
||||
len = montauk::utf8::prev_boundary(out, len);
|
||||
}
|
||||
|
||||
if (len > out_len - 4) len = out_len - 4;
|
||||
if (len > out_len - 4) len = montauk::utf8::floor_boundary(out, len, out_len - 4);
|
||||
if (len < 0) len = 0;
|
||||
out[len] = '.';
|
||||
out[len + 1] = '.';
|
||||
|
||||
@@ -32,12 +32,14 @@ static int fitted_prefix_len(const char* src, int max_w, int max_len) {
|
||||
char tmp[128];
|
||||
int best = 0;
|
||||
int limit = max_len < 127 ? max_len : 127;
|
||||
for (int len = 1; len <= limit; len++) {
|
||||
for (int len = montauk::utf8::next_boundary(src, max_len, 0); len <= limit;
|
||||
len = montauk::utf8::next_boundary(src, max_len, len)) {
|
||||
copy_label_range(tmp, sizeof(tmp), src, 0, len);
|
||||
if (text_width(tmp) > max_w) break;
|
||||
best = len;
|
||||
if (len >= max_len) break;
|
||||
}
|
||||
return best > 0 ? best : 1;
|
||||
return best > 0 ? best : montauk::utf8::next_boundary(src, max_len, 0);
|
||||
}
|
||||
|
||||
static void fit_label_with_ellipsis(char* dst, int dst_max, const char* src, int max_w) {
|
||||
@@ -49,10 +51,10 @@ static void fit_label_with_ellipsis(char* dst, int dst_max, const char* src, int
|
||||
while (len > 0) {
|
||||
dst[len] = '\0';
|
||||
if (text_width(dst) + ellipsis_w <= max_w) break;
|
||||
len--;
|
||||
len = montauk::utf8::prev_boundary(dst, len);
|
||||
}
|
||||
|
||||
if (len > dst_max - 4) len = dst_max - 4;
|
||||
if (len > dst_max - 4) len = montauk::utf8::floor_boundary(dst, len, dst_max - 4);
|
||||
if (len < 0) len = 0;
|
||||
dst[len] = '.';
|
||||
dst[len + 1] = '.';
|
||||
@@ -403,7 +405,7 @@ void filemanager_on_draw(Window* win, Framebuffer& fb) {
|
||||
// Draw rename text (truncated to cell width)
|
||||
char display[16];
|
||||
int rlen = fm->rename_len;
|
||||
if (rlen > 10) rlen = 10;
|
||||
if (rlen > 10) rlen = montauk::utf8::floor_boundary(fm->rename_buf, fm->rename_len, 10);
|
||||
for (int k = 0; k < rlen; k++) display[k] = fm->rename_buf[k];
|
||||
display[rlen] = '\0';
|
||||
c.text(cell_x + 4, ty, display, colors::TEXT_COLOR);
|
||||
@@ -557,18 +559,19 @@ void filemanager_on_draw(Window* win, Framebuffer& fb) {
|
||||
int name_max_w = size_col_x - tx - 8;
|
||||
if (name_max_w < 20) name_max_w = c.w - FM_SCROLLBAR_W - tx - 8;
|
||||
char label[64];
|
||||
montauk::strncpy(label, name, 63);
|
||||
montauk::utf8::copy(label, 64, name);
|
||||
|
||||
if (text_width(label) > name_max_w && montauk::slen(name) > 3) {
|
||||
int ellipsis_w = text_width("...");
|
||||
int final_len = montauk::slen(name);
|
||||
int final_len = montauk::slen(label);
|
||||
while (final_len > 1) {
|
||||
label[final_len] = '\0';
|
||||
int w = text_width(label);
|
||||
if (w + ellipsis_w <= name_max_w) break;
|
||||
final_len--;
|
||||
final_len = montauk::utf8::prev_boundary(label, final_len);
|
||||
}
|
||||
if (final_len > 60) final_len = 60;
|
||||
if (final_len > 60)
|
||||
final_len = montauk::utf8::floor_boundary(label, final_len, 60);
|
||||
label[final_len] = '.';
|
||||
label[final_len + 1] = '.';
|
||||
label[final_len + 2] = '.';
|
||||
|
||||
@@ -44,7 +44,7 @@ void settings_draw_about(Canvas& c, SettingsState* st) {
|
||||
mtk::draw_separator(c, x, y, c.w - 2 * x, theme);
|
||||
y += 12;
|
||||
|
||||
c.text(x, y, "Copyright \xa9 2026 Montauk Operating System Project", theme.text_muted);
|
||||
c.text(x, y, "Copyright \u00A9 2026 Montauk Operating System Project", theme.text_muted);
|
||||
}
|
||||
|
||||
} // namespace settings_app
|
||||
@@ -103,7 +103,7 @@ void desktop_draw_lock_screen(DesktopState* ds) {
|
||||
|
||||
// Masked password text (clipped to field width)
|
||||
char masked[65];
|
||||
int len = ds->lock_password_len;
|
||||
int len = montauk::utf8::count(ds->lock_password); // one '*' per character
|
||||
if (len > 64) len = 64;
|
||||
int max_text_w = content_w - 10 - 10 - 2; // left pad, right pad, cursor
|
||||
// Show only the trailing portion that fits
|
||||
|
||||
@@ -105,7 +105,11 @@ int wrap_text(const char* text, int max_w, char (*lines)[LINE_CHARS], int max_li
|
||||
char* last = lines[max_lines - 1];
|
||||
int len = montauk::slen(last);
|
||||
if (len > LINE_CHARS - 4) len = LINE_CHARS - 4;
|
||||
while (len > 0 && text_width(last) + text_width("...") > max_w) last[--len] = '\0';
|
||||
last[len] = '\0';
|
||||
while (len > 0 && text_width(last) + text_width("...") > max_w) {
|
||||
len = montauk::utf8::prev_boundary(last, len);
|
||||
last[len] = '\0';
|
||||
}
|
||||
last[len] = '.'; last[len + 1] = '.'; last[len + 2] = '.'; last[len + 3] = '\0';
|
||||
}
|
||||
return count;
|
||||
|
||||
@@ -98,22 +98,12 @@ static void handle_lock_keyboard(DesktopState* ds, const montauk::abi::KeyEvent&
|
||||
|
||||
// Backspace
|
||||
if (key.ascii == '\b' || key.scancode == 0x0E) {
|
||||
if (ds->lock_password_len > 0) {
|
||||
ds->lock_password_len--;
|
||||
ds->lock_password[ds->lock_password_len] = '\0';
|
||||
}
|
||||
montauk::utf8::erase_last(ds->lock_password, &ds->lock_password_len);
|
||||
return;
|
||||
}
|
||||
|
||||
// Printable characters
|
||||
if ((unsigned char)key.ascii >= 0x20
|
||||
&& (unsigned char)key.ascii != 0x7F) {
|
||||
if (ds->lock_password_len < 63) {
|
||||
ds->lock_password[ds->lock_password_len] = key.ascii;
|
||||
ds->lock_password_len++;
|
||||
ds->lock_password[ds->lock_password_len] = '\0';
|
||||
}
|
||||
}
|
||||
// Printable characters (stored as UTF-8)
|
||||
montauk::utf8::append_key(ds->lock_password, &ds->lock_password_len, 64, key);
|
||||
}
|
||||
|
||||
static void forward_external_mouse(gui::Window* win,
|
||||
|
||||
@@ -361,7 +361,7 @@ static void launcher_activate_selected(DesktopState* ds) {
|
||||
}
|
||||
|
||||
static void launcher_update_super_state(DesktopState* ds, const montauk::abi::KeyEvent& key) {
|
||||
uint8_t sc = key.scancode & 0x7F;
|
||||
uint8_t sc = montauk::nav_scancode(key) & 0x7F;
|
||||
if (sc == 0x5B) {
|
||||
ds->super_left_down = key.pressed;
|
||||
} else if (sc == 0x5C) {
|
||||
@@ -371,7 +371,7 @@ static void launcher_update_super_state(DesktopState* ds, const montauk::abi::Ke
|
||||
|
||||
static const char* fit_trailing_text(const char* text, int max_w) {
|
||||
const char* visible = text;
|
||||
while (*visible && text_width(visible) > max_w) visible++;
|
||||
while (*visible && text_width(visible) > max_w) montauk::utf8::next(&visible);
|
||||
return visible;
|
||||
}
|
||||
|
||||
@@ -420,7 +420,7 @@ void desktop_close_launcher(DesktopState* ds) {
|
||||
|
||||
bool desktop_handle_launcher_keyboard(DesktopState* ds, const montauk::abi::KeyEvent& key) {
|
||||
launcher_update_super_state(ds, key);
|
||||
uint8_t sc = key.scancode & 0x7F;
|
||||
uint8_t sc = montauk::nav_scancode(key) & 0x7F;
|
||||
|
||||
if (sc == 0x5B || sc == 0x5C) {
|
||||
return true;
|
||||
@@ -456,11 +456,8 @@ bool desktop_handle_launcher_keyboard(DesktopState* ds, const montauk::abi::KeyE
|
||||
}
|
||||
|
||||
if (key.ascii == '\b' || sc == 0x0E) {
|
||||
if (ds->launcher_query_len > 0) {
|
||||
ds->launcher_query_len--;
|
||||
ds->launcher_query[ds->launcher_query_len] = '\0';
|
||||
if (montauk::utf8::erase_last(ds->launcher_query, &ds->launcher_query_len))
|
||||
desktop_update_launcher_results(ds);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -495,12 +492,8 @@ bool desktop_handle_launcher_keyboard(DesktopState* ds, const montauk::abi::KeyE
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((unsigned char)key.ascii >= 0x20
|
||||
&& (unsigned char)key.ascii != 0x7F && ds->launcher_query_len < 63) {
|
||||
ds->launcher_query[ds->launcher_query_len++] = key.ascii;
|
||||
ds->launcher_query[ds->launcher_query_len] = '\0';
|
||||
if (montauk::utf8::append_key(ds->launcher_query, &ds->launcher_query_len, 64, key))
|
||||
desktop_update_launcher_results(ds);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -280,7 +280,7 @@ static bool handle_key(const montauk::abi::KeyEvent& key) {
|
||||
int row_count = build_display_rows(&de, rows);
|
||||
if (row_count == 0) return true;
|
||||
|
||||
if (key.scancode == 0x48) { // Up
|
||||
if (montauk::nav_scancode(key) == 0x48) { // Up
|
||||
if (de.selected_row <= 0) de.selected_row = 0;
|
||||
else de.selected_row--;
|
||||
// Scroll up just enough to bring the selected row's top into view.
|
||||
@@ -289,7 +289,7 @@ static bool handle_key(const montauk::abi::KeyEvent& key) {
|
||||
sel_top += (rows[i].type == ROW_CATEGORY) ? CAT_H : ITEM_H;
|
||||
if (sel_top < de.scroll_y)
|
||||
de.scroll_y = sel_top;
|
||||
} else if (key.scancode == 0x50) { // Down
|
||||
} else if (montauk::nav_scancode(key) == 0x50) { // Down
|
||||
if (de.selected_row < row_count - 1)
|
||||
de.selected_row++;
|
||||
// Scroll down just enough to bring the selected row's bottom into view.
|
||||
@@ -300,7 +300,7 @@ static bool handle_key(const montauk::abi::KeyEvent& key) {
|
||||
int list_h = g_win_h - TOOLBAR_H;
|
||||
if (sel_top + sel_h > de.scroll_y + list_h)
|
||||
de.scroll_y = sel_top + sel_h - list_h;
|
||||
} else if (key.scancode == 0x4B) { // Left — collapse
|
||||
} else if (montauk::nav_scancode(key) == 0x4B) { // Left — collapse
|
||||
if (de.selected_row >= 0 && de.selected_row < row_count) {
|
||||
int cat = rows[de.selected_row].category;
|
||||
if (!de.collapsed[cat]) {
|
||||
@@ -318,7 +318,7 @@ static bool handle_key(const montauk::abi::KeyEvent& key) {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (key.scancode == 0x4D) { // Right — expand
|
||||
} else if (montauk::nav_scancode(key) == 0x4D) { // Right — expand
|
||||
if (de.selected_row >= 0 && de.selected_row < row_count) {
|
||||
int cat = rows[de.selected_row].category;
|
||||
de.collapsed[cat] = false;
|
||||
|
||||
@@ -261,15 +261,16 @@ void fit_text_start(const char* src, char* out, int out_len, int max_px) {
|
||||
// Grid labels must fit their cell in pixels. Character-count truncation is
|
||||
// insufficient for the proportional system font and lets wide names paint
|
||||
// over the adjacent label.
|
||||
int keep = montauk::slen(src);
|
||||
if (keep > out_len - 3) keep = out_len - 3;
|
||||
int slen = montauk::slen(src);
|
||||
int keep = slen;
|
||||
if (keep > out_len - 3) keep = montauk::utf8::floor_boundary(src, slen, out_len - 3);
|
||||
while (keep > 0) {
|
||||
for (int i = 0; i < keep; i++) out[i] = src[i];
|
||||
out[keep] = '.';
|
||||
out[keep + 1] = '.';
|
||||
out[keep + 2] = '\0';
|
||||
if (text_width(out) <= max_px) return;
|
||||
keep--;
|
||||
keep = montauk::utf8::prev_boundary(src, keep);
|
||||
}
|
||||
|
||||
safe_copy(out, out_len, "..");
|
||||
@@ -1216,14 +1217,14 @@ void handle_file_key(const montauk::abi::KeyEvent& key) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (key.scancode == 0x4B || key.scancode == 0x48) {
|
||||
if (montauk::nav_scancode(key) == 0x4B || montauk::nav_scancode(key) == 0x48) {
|
||||
if (st->selected > 0) st->selected--;
|
||||
else if (st->entry_count > 0) st->selected = 0;
|
||||
file_ensure_selected_visible(st);
|
||||
return;
|
||||
}
|
||||
|
||||
if (key.scancode == 0x4D || key.scancode == 0x50) {
|
||||
if (montauk::nav_scancode(key) == 0x4D || montauk::nav_scancode(key) == 0x50) {
|
||||
if (st->selected < st->entry_count - 1) st->selected++;
|
||||
else if (st->entry_count > 0) st->selected = st->entry_count - 1;
|
||||
file_ensure_selected_visible(st);
|
||||
|
||||
@@ -143,7 +143,8 @@ void fit_text_end(const char* src, char* out, int out_len, int max_px) {
|
||||
gui::dialogs::safe_copy(out, out_len, candidate);
|
||||
return;
|
||||
}
|
||||
keep--;
|
||||
// Drop one whole character from the front of the tail
|
||||
keep = slen - montauk::utf8::next_boundary(src, slen, slen - keep);
|
||||
}
|
||||
|
||||
gui::dialogs::safe_copy(out, out_len, "...");
|
||||
|
||||
@@ -480,13 +480,13 @@ void handle_print_key(const montauk::abi::KeyEvent& key) {
|
||||
g_print.error[0] = '\0';
|
||||
return;
|
||||
}
|
||||
if ((key.scancode == 0x48 || key.scancode == 0x4B) && g_print.printer_count > 0) {
|
||||
if ((montauk::nav_scancode(key) == 0x48 || montauk::nav_scancode(key) == 0x4B) && g_print.printer_count > 0) {
|
||||
if (g_print.selected_printer > 0) g_print.selected_printer--;
|
||||
else g_print.selected_printer = 0;
|
||||
g_print.error[0] = '\0';
|
||||
return;
|
||||
}
|
||||
if ((key.scancode == 0x50 || key.scancode == 0x4D) && g_print.printer_count > 0) {
|
||||
if ((montauk::nav_scancode(key) == 0x50 || montauk::nav_scancode(key) == 0x4D) && g_print.printer_count > 0) {
|
||||
if (g_print.selected_printer < g_print.printer_count - 1) g_print.selected_printer++;
|
||||
else g_print.selected_printer = g_print.printer_count - 1;
|
||||
g_print.error[0] = '\0';
|
||||
|
||||
@@ -339,9 +339,9 @@ static bool handle_key(const montauk::abi::KeyEvent& key) {
|
||||
if (dt.fmt_dlg.open) {
|
||||
if (key.scancode == 0x01) { // Escape
|
||||
close_format_dialog();
|
||||
} else if (key.scancode == 0x48 && dt.fmt_dlg.selected_fs > 0) {
|
||||
} else if (montauk::nav_scancode(key) == 0x48 && dt.fmt_dlg.selected_fs > 0) {
|
||||
dt.fmt_dlg.selected_fs--;
|
||||
} else if (key.scancode == 0x50 && dt.fmt_dlg.selected_fs < NUM_FS_TYPES - 1) {
|
||||
} else if (montauk::nav_scancode(key) == 0x50 && dt.fmt_dlg.selected_fs < NUM_FS_TYPES - 1) {
|
||||
dt.fmt_dlg.selected_fs++;
|
||||
} else if (key.ascii == '\n' || key.ascii == '\r') {
|
||||
format_dialog_do_format();
|
||||
@@ -354,14 +354,14 @@ static bool handle_key(const montauk::abi::KeyEvent& key) {
|
||||
|
||||
if (key.scancode == 0x01) { // Escape
|
||||
return false; // signal quit
|
||||
} else if (key.scancode == 0x48) { // Up
|
||||
} else if (montauk::nav_scancode(key) == 0x48) { // Up
|
||||
if (dt.selected_part > 0) dt.selected_part--;
|
||||
else if (nparts > 0) dt.selected_part = 0;
|
||||
} else if (key.scancode == 0x50) { // Down
|
||||
} else if (montauk::nav_scancode(key) == 0x50) { // Down
|
||||
if (dt.selected_part < nparts - 1) dt.selected_part++;
|
||||
} else if (key.scancode == 0x4B) { // Left
|
||||
} else if (montauk::nav_scancode(key) == 0x4B) { // Left
|
||||
if (dt.selected_disk > 0) { dt.selected_disk--; dt.selected_part = -1; dt.scroll_y = 0; }
|
||||
} else if (key.scancode == 0x4D) { // Right
|
||||
} else if (montauk::nav_scancode(key) == 0x4D) { // Right
|
||||
if (dt.selected_disk < dt.disk_count - 1) { dt.selected_disk++; dt.selected_part = -1; dt.scroll_y = 0; }
|
||||
} else if (key.ascii == 'n' || key.ascii == 'N') {
|
||||
do_create_partition();
|
||||
|
||||
@@ -53,6 +53,8 @@ static void draw_text_fit(Canvas& c, int x, int y,
|
||||
out++;
|
||||
}
|
||||
|
||||
out = montauk::utf8::floor_boundary(text, montauk::slen(text), out);
|
||||
|
||||
if (out <= 0) return;
|
||||
buf[out] = '.';
|
||||
buf[out + 1] = '.';
|
||||
|
||||
@@ -252,6 +252,7 @@ static void fit_text(char* out, int outCap, const char* text, int maxWidth) {
|
||||
if (text_width(out) + text_width(ellipsis) > maxWidth) break;
|
||||
len++;
|
||||
}
|
||||
len = montauk::utf8::floor_boundary(text, montauk::slen(text), len);
|
||||
out[len++] = '.';
|
||||
out[len++] = '.';
|
||||
out[len++] = '.';
|
||||
|
||||
+77
-38
@@ -7,6 +7,7 @@
|
||||
#include <montauk/syscall.h>
|
||||
#include <montauk/heap.h>
|
||||
#include <montauk/string.h>
|
||||
#include <montauk/utf8.h>
|
||||
|
||||
using montauk::slen;
|
||||
using montauk::memcpy;
|
||||
@@ -166,6 +167,16 @@ static void line_delete_char(Line* ln, int pos) {
|
||||
ln->data[ln->len] = '\0';
|
||||
}
|
||||
|
||||
// Lines are UTF-8. cursorCol is a byte offset kept on a character boundary;
|
||||
// the screen works in columns, one per character.
|
||||
static int line_display_col(const Line* ln, int byteCol) {
|
||||
return montauk::utf8::count(ln->data, byteCol < ln->len ? byteCol : ln->len);
|
||||
}
|
||||
|
||||
static int line_byte_col(const Line* ln, int displayCol) {
|
||||
return montauk::utf8::offset_of(ln->data, ln->len, displayCol);
|
||||
}
|
||||
|
||||
static void line_append(Line* ln, const char* s, int slen) {
|
||||
line_ensure(ln, ln->len + slen);
|
||||
memcpy(ln->data + ln->len, s, slen);
|
||||
@@ -300,6 +311,21 @@ static void load_file(const char* fname) {
|
||||
}
|
||||
montauk::close(handle);
|
||||
|
||||
// Pre-UTF-8 files are Windows-1252: convert once so edits never mix
|
||||
// encodings and saving writes UTF-8.
|
||||
bool converted = false;
|
||||
if (buf && size > 0 && !montauk::utf8::valid((const char*)buf, (int)size)) {
|
||||
int cap = (int)size * 3 + 1;
|
||||
uint8_t* conv = (uint8_t*)montauk::malloc(cap);
|
||||
if (conv) {
|
||||
size = (uint64_t)montauk::utf8::normalize((const char*)buf, (int)size,
|
||||
(char*)conv, cap);
|
||||
montauk::mfree(buf);
|
||||
buf = conv;
|
||||
converted = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Parse into lines
|
||||
numLines = 0;
|
||||
if (buf && size > 0) {
|
||||
@@ -325,7 +351,7 @@ static void load_file(const char* fname) {
|
||||
line_init(&lines[0]);
|
||||
}
|
||||
|
||||
set_status("File loaded");
|
||||
set_status(converted ? "File loaded (converted from Windows-1252 to UTF-8)" : "File loaded");
|
||||
}
|
||||
|
||||
static bool save_file() {
|
||||
@@ -413,14 +439,13 @@ static int prompt_input(const char* promptStr, char* out, int outMax) {
|
||||
}
|
||||
|
||||
if (ev.ascii == '\b') {
|
||||
if (pos > 0) {
|
||||
pos--;
|
||||
if (montauk::utf8::erase_last(out, &pos)) {
|
||||
putch('\b'); putch(' '); putch('\b');
|
||||
}
|
||||
} else if (ev.ascii >= ' ' && pos < outMax - 1) {
|
||||
out[pos++] = ev.ascii;
|
||||
out[pos] = '\0';
|
||||
putch(ev.ascii);
|
||||
} else {
|
||||
int before = pos;
|
||||
if (montauk::utf8::append_key(out, &pos, outMax, ev))
|
||||
print(out + before);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -506,14 +531,15 @@ static void draw_line(int screenRow, int docLine) {
|
||||
reset_attrs();
|
||||
|
||||
// Line content
|
||||
// The visible window is leftCol..leftCol+maxChars in columns; convert
|
||||
// it to a byte range so whole UTF-8 characters are emitted.
|
||||
Line* ln = &lines[docLine];
|
||||
int startCol = leftCol;
|
||||
int startCol = line_byte_col(ln, leftCol);
|
||||
int maxChars = screenCols - gutterWidth;
|
||||
int visibleLen = 0;
|
||||
if (startCol < ln->len) {
|
||||
visibleLen = ln->len - startCol;
|
||||
if (visibleLen > maxChars) visibleLen = maxChars;
|
||||
}
|
||||
int endCol = startCol;
|
||||
for (int n = 0; n < maxChars && endCol < ln->len; n++)
|
||||
endCol = montauk::utf8::next_boundary(ln->data, ln->len, endCol);
|
||||
int visibleLen = endCol - startCol;
|
||||
|
||||
if (synLang != SYN_LANG_NONE) {
|
||||
// Tokenize the WHOLE line, not just the visible window: the
|
||||
@@ -577,7 +603,7 @@ static void render() {
|
||||
|
||||
// Position cursor
|
||||
int screenY = cursorRow - topLine + 2; // +2 for status bar
|
||||
int screenX = cursorCol - leftCol + gutterWidth;
|
||||
int screenX = line_display_col(&lines[cursorRow], cursorCol) - leftCol + gutterWidth;
|
||||
cursor_to(screenY, screenX);
|
||||
|
||||
show_cursor();
|
||||
@@ -598,12 +624,13 @@ static void scroll() {
|
||||
|
||||
// Horizontal scrolling
|
||||
int textCols = screenCols - gutterWidth;
|
||||
if (cursorCol < leftCol) {
|
||||
leftCol = cursorCol;
|
||||
int displayCol = line_display_col(&lines[cursorRow], cursorCol);
|
||||
if (displayCol < leftCol) {
|
||||
leftCol = displayCol;
|
||||
fullRedraw = true;
|
||||
}
|
||||
if (cursorCol >= leftCol + textCols) {
|
||||
leftCol = cursorCol - textCols + 1;
|
||||
if (displayCol >= leftCol + textCols) {
|
||||
leftCol = displayCol - textCols + 1;
|
||||
fullRedraw = true;
|
||||
}
|
||||
}
|
||||
@@ -617,6 +644,10 @@ static void insert_char(char c) {
|
||||
fullRedraw = true;
|
||||
}
|
||||
|
||||
static void insert_bytes(const char* s, int n) {
|
||||
for (int i = 0; i < n; i++) insert_char(s[i]);
|
||||
}
|
||||
|
||||
static void insert_tab() {
|
||||
for (int i = 0; i < TAB_WIDTH; i++) {
|
||||
insert_char(' ');
|
||||
@@ -647,8 +678,11 @@ static void insert_newline() {
|
||||
|
||||
static void delete_char_backspace() {
|
||||
if (cursorCol > 0) {
|
||||
line_delete_char(&lines[cursorRow], cursorCol - 1);
|
||||
cursorCol--;
|
||||
int start = montauk::utf8::prev_boundary(lines[cursorRow].data, cursorCol);
|
||||
while (cursorCol > start) {
|
||||
line_delete_char(&lines[cursorRow], cursorCol - 1);
|
||||
cursorCol--;
|
||||
}
|
||||
modified = true;
|
||||
fullRedraw = true;
|
||||
} else if (cursorRow > 0) {
|
||||
@@ -665,7 +699,9 @@ static void delete_char_backspace() {
|
||||
|
||||
static void delete_char_forward() {
|
||||
if (cursorCol < lines[cursorRow].len) {
|
||||
line_delete_char(&lines[cursorRow], cursorCol);
|
||||
Line* ln = &lines[cursorRow];
|
||||
int n = montauk::utf8::next_boundary(ln->data, ln->len, cursorCol) - cursorCol;
|
||||
while (n-- > 0) line_delete_char(ln, cursorCol);
|
||||
modified = true;
|
||||
fullRedraw = true;
|
||||
} else if (cursorRow < numLines - 1) {
|
||||
@@ -793,26 +829,26 @@ static void handle_key(const montauk::abi::KeyEvent& ev) {
|
||||
|
||||
// Non-ASCII keys (scancode-based)
|
||||
if (ev.ascii == 0) {
|
||||
switch (ev.scancode) {
|
||||
switch (montauk::nav_scancode(ev)) {
|
||||
case SC_UP:
|
||||
if (cursorRow > 0) {
|
||||
int col = line_display_col(&lines[cursorRow], cursorCol);
|
||||
cursorRow--;
|
||||
if (cursorCol > lines[cursorRow].len)
|
||||
cursorCol = lines[cursorRow].len;
|
||||
cursorCol = line_byte_col(&lines[cursorRow], col);
|
||||
fullRedraw = true;
|
||||
}
|
||||
return;
|
||||
case SC_DOWN:
|
||||
if (cursorRow < numLines - 1) {
|
||||
int col = line_display_col(&lines[cursorRow], cursorCol);
|
||||
cursorRow++;
|
||||
if (cursorCol > lines[cursorRow].len)
|
||||
cursorCol = lines[cursorRow].len;
|
||||
cursorCol = line_byte_col(&lines[cursorRow], col);
|
||||
fullRedraw = true;
|
||||
}
|
||||
return;
|
||||
case SC_LEFT:
|
||||
if (cursorCol > 0) {
|
||||
cursorCol--;
|
||||
cursorCol = montauk::utf8::prev_boundary(lines[cursorRow].data, cursorCol);
|
||||
} else if (cursorRow > 0) {
|
||||
cursorRow--;
|
||||
cursorCol = lines[cursorRow].len;
|
||||
@@ -821,7 +857,8 @@ static void handle_key(const montauk::abi::KeyEvent& ev) {
|
||||
return;
|
||||
case SC_RIGHT:
|
||||
if (cursorCol < lines[cursorRow].len) {
|
||||
cursorCol++;
|
||||
cursorCol = montauk::utf8::next_boundary(lines[cursorRow].data,
|
||||
lines[cursorRow].len, cursorCol);
|
||||
} else if (cursorRow < numLines - 1) {
|
||||
cursorRow++;
|
||||
cursorCol = 0;
|
||||
@@ -836,20 +873,22 @@ static void handle_key(const montauk::abi::KeyEvent& ev) {
|
||||
cursorCol = lines[cursorRow].len;
|
||||
fullRedraw = true;
|
||||
return;
|
||||
case SC_PGUP:
|
||||
case SC_PGUP: {
|
||||
int col = line_display_col(&lines[cursorRow], cursorCol);
|
||||
cursorRow -= editorRows;
|
||||
if (cursorRow < 0) cursorRow = 0;
|
||||
if (cursorCol > lines[cursorRow].len)
|
||||
cursorCol = lines[cursorRow].len;
|
||||
cursorCol = line_byte_col(&lines[cursorRow], col);
|
||||
fullRedraw = true;
|
||||
return;
|
||||
case SC_PGDN:
|
||||
}
|
||||
case SC_PGDN: {
|
||||
int col = line_display_col(&lines[cursorRow], cursorCol);
|
||||
cursorRow += editorRows;
|
||||
if (cursorRow >= numLines) cursorRow = numLines - 1;
|
||||
if (cursorCol > lines[cursorRow].len)
|
||||
cursorCol = lines[cursorRow].len;
|
||||
cursorCol = line_byte_col(&lines[cursorRow], col);
|
||||
fullRedraw = true;
|
||||
return;
|
||||
}
|
||||
case SC_DELETE:
|
||||
delete_char_forward();
|
||||
return;
|
||||
@@ -869,11 +908,11 @@ static void handle_key(const montauk::abi::KeyEvent& ev) {
|
||||
case '\t':
|
||||
insert_tab();
|
||||
break;
|
||||
default:
|
||||
if (ev.ascii >= ' ') {
|
||||
insert_char(ev.ascii);
|
||||
}
|
||||
default: {
|
||||
char typed[montauk::utf8::MAX_BYTES];
|
||||
insert_bytes(typed, montauk::utf8::key_utf8(ev, typed));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -402,12 +402,12 @@ extern "C" void _start() {
|
||||
if (ev.key.ascii == 'q' || ev.key.ascii == 'Q' || ev.key.scancode == 0x01)
|
||||
break;
|
||||
|
||||
if (ev.key.scancode == 0x48) { g_scroll_y -= SCROLL_STEP; redraw = true; }
|
||||
if (ev.key.scancode == 0x50) { g_scroll_y += SCROLL_STEP; redraw = true; }
|
||||
if (ev.key.scancode == 0x47) { g_scroll_y = 0; redraw = true; }
|
||||
if (ev.key.scancode == 0x4F) { g_scroll_y = g_content_h; redraw = true; }
|
||||
if (ev.key.scancode == 0x49) { g_scroll_y -= g_win_h; redraw = true; }
|
||||
if (ev.key.scancode == 0x51) { g_scroll_y += g_win_h; redraw = true; }
|
||||
if (montauk::nav_scancode(ev.key) == 0x48) { g_scroll_y -= SCROLL_STEP; redraw = true; }
|
||||
if (montauk::nav_scancode(ev.key) == 0x50) { g_scroll_y += SCROLL_STEP; redraw = true; }
|
||||
if (montauk::nav_scancode(ev.key) == 0x47) { g_scroll_y = 0; redraw = true; }
|
||||
if (montauk::nav_scancode(ev.key) == 0x4F) { g_scroll_y = g_content_h; redraw = true; }
|
||||
if (montauk::nav_scancode(ev.key) == 0x49) { g_scroll_y -= g_win_h; redraw = true; }
|
||||
if (montauk::nav_scancode(ev.key) == 0x51) { g_scroll_y += g_win_h; redraw = true; }
|
||||
|
||||
if (redraw) {
|
||||
clamp_scroll();
|
||||
|
||||
@@ -620,13 +620,13 @@ extern "C" void _start() {
|
||||
else if (key.ctrl && (key.ascii == '-' || key.ascii == 31)) { zoom_out(cx, cy); redraw = true; }
|
||||
|
||||
// Arrow keys to pan
|
||||
else if (key.scancode == 0x48) { g_pan_y += PAN_STEP; redraw = true; }
|
||||
else if (key.scancode == 0x50) { g_pan_y -= PAN_STEP; redraw = true; }
|
||||
else if (key.scancode == 0x4B) { g_pan_x += PAN_STEP; redraw = true; }
|
||||
else if (key.scancode == 0x4D) { g_pan_x -= PAN_STEP; redraw = true; }
|
||||
else if (montauk::nav_scancode(key) == 0x48) { g_pan_y += PAN_STEP; redraw = true; }
|
||||
else if (montauk::nav_scancode(key) == 0x50) { g_pan_y -= PAN_STEP; redraw = true; }
|
||||
else if (montauk::nav_scancode(key) == 0x4B) { g_pan_x += PAN_STEP; redraw = true; }
|
||||
else if (montauk::nav_scancode(key) == 0x4D) { g_pan_x -= PAN_STEP; redraw = true; }
|
||||
|
||||
// Home to center
|
||||
else if (key.scancode == 0x47) { center_image(); redraw = true; }
|
||||
else if (montauk::nav_scancode(key) == 0x47) { center_image(); redraw = true; }
|
||||
|
||||
if (redraw && g_load_ok) clamp_pan();
|
||||
}
|
||||
|
||||
@@ -333,14 +333,14 @@ static bool handle_key(const montauk::abi::KeyEvent& key) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (key.scancode == 0x48) { // Up
|
||||
if (montauk::nav_scancode(key) == 0x48) { // Up
|
||||
if (st.step == STEP_SELECT_DISK && st.selected_disk > 0)
|
||||
st.selected_disk--;
|
||||
else if (st.step == STEP_UPDATE_SELECT_PART && st.selected_part > 0)
|
||||
st.selected_part--;
|
||||
else if (st.step == STEP_PARTITION_SCHEME && st.partition_scheme > 0)
|
||||
st.partition_scheme--;
|
||||
} else if (key.scancode == 0x50) { // Down
|
||||
} else if (montauk::nav_scancode(key) == 0x50) { // Down
|
||||
if (st.step == STEP_SELECT_DISK && st.selected_disk < st.disk_count - 1)
|
||||
st.selected_disk++;
|
||||
else if (st.step == STEP_UPDATE_SELECT_PART && st.selected_part < st.part_count - 1)
|
||||
|
||||
@@ -48,6 +48,8 @@ static void draw_text_fit(Canvas& c, int x, int y,
|
||||
out++;
|
||||
}
|
||||
|
||||
out = montauk::utf8::floor_boundary(text, montauk::slen(text), out);
|
||||
|
||||
if (out <= 0) return;
|
||||
buf[out] = '.';
|
||||
buf[out + 1] = '.';
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <montauk/syscall.h>
|
||||
#include <montauk/string.h>
|
||||
#include <montauk/utf8.h>
|
||||
#include <libc/stdio.h>
|
||||
|
||||
using montauk::slen;
|
||||
@@ -621,7 +622,7 @@ static void ui_render() {
|
||||
for (int i = 0; i < input.len; i++) sb_putc(input.buf[i]);
|
||||
|
||||
// Position cursor at input insertion point
|
||||
sb_cursor_to(term.rows, input.pos + 3);
|
||||
sb_cursor_to(term.rows, montauk::utf8::count(input.buf, input.pos) + 3);
|
||||
|
||||
// Single flush — entire screen in one print call
|
||||
sb_flush();
|
||||
@@ -892,7 +893,7 @@ extern "C" void _start() {
|
||||
}
|
||||
|
||||
// Handle special keys by scancode
|
||||
switch (ev.scancode) {
|
||||
switch (montauk::nav_scancode(ev)) {
|
||||
case 0x49: // Page Up
|
||||
if (msgBuf.scrollOffset < msgBuf.count - term.msgAreaRows) {
|
||||
msgBuf.scrollOffset += term.msgAreaRows / 2;
|
||||
@@ -922,22 +923,12 @@ extern "C" void _start() {
|
||||
input.len = 0;
|
||||
}
|
||||
} else if (ev.ascii == '\b') {
|
||||
if (input.pos > 0) {
|
||||
for (int j = input.pos - 1; j < input.len - 1; j++) {
|
||||
input.buf[j] = input.buf[j + 1];
|
||||
}
|
||||
input.pos--;
|
||||
input.len--;
|
||||
}
|
||||
} else if (ev.ascii >= ' ' && ev.ascii <= '~') {
|
||||
if (input.len < 510) {
|
||||
for (int j = input.len; j > input.pos; j--) {
|
||||
input.buf[j] = input.buf[j - 1];
|
||||
}
|
||||
input.buf[input.pos] = ev.ascii;
|
||||
input.pos++;
|
||||
input.len++;
|
||||
}
|
||||
input.buf[input.len] = '\0';
|
||||
montauk::utf8::erase_before(input.buf, &input.len, &input.pos);
|
||||
} else if (montauk::utf8::key_codepoint(ev)) {
|
||||
// IRC text is UTF-8
|
||||
input.buf[input.len] = '\0';
|
||||
montauk::utf8::insert_key(input.buf, &input.len, 511, &input.pos, ev);
|
||||
} else {
|
||||
dirty = false; // Unhandled key, no redraw needed
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <montauk/keyboard.h>
|
||||
#include <montauk/syscall.h>
|
||||
#include <montauk/string.h>
|
||||
#include <montauk/utf8.h>
|
||||
#include <gui/mtk.hpp>
|
||||
#include <gui/mtk/settings.hpp>
|
||||
#include <gui/standalone.hpp>
|
||||
@@ -176,14 +177,16 @@ static void draw_layouts_tab(Canvas& c, const mtk::Theme& theme) {
|
||||
// Key Map tab: what the active layout actually remaps. Rows are identified by
|
||||
// the character the key produces unshifted, so no copy of the US scancode
|
||||
// table is needed here to name the physical keys.
|
||||
static void draw_char_cell(Canvas& c, int x, int y, uint8_t byte,
|
||||
static void draw_char_cell(Canvas& c, int x, int y, uint32_t cp, bool dead,
|
||||
const mtk::Theme& theme) {
|
||||
char text[2] = {(char)byte, '\0'};
|
||||
if (byte == 0) {
|
||||
if (cp == 0) {
|
||||
c.text(x, y, "-", theme.text_muted);
|
||||
} else {
|
||||
c.text(x, y, text, theme.text);
|
||||
return;
|
||||
}
|
||||
char text[5];
|
||||
text[montauk::utf8::encode(cp, text)] = '\0';
|
||||
// Dead keys (accents that combine with the next letter) in the accent color
|
||||
c.text(x, y, text, dead ? theme.accent : theme.text);
|
||||
}
|
||||
|
||||
static void draw_keymap_tab(Canvas& c, const mtk::Theme& theme) {
|
||||
@@ -220,9 +223,12 @@ static void draw_keymap_tab(Canvas& c, const mtk::Theme& theme) {
|
||||
if (index >= layout.key_count) break;
|
||||
const montauk::keyboard::KeyMap& key = layout.keys[index];
|
||||
int y = list_y() + row * MAP_ROW_H;
|
||||
draw_char_cell(c, gx + col[0], y, key.base, theme);
|
||||
draw_char_cell(c, gx + col[1], y, key.shift, theme);
|
||||
draw_char_cell(c, gx + col[2], y, key.altgr, theme);
|
||||
draw_char_cell(c, gx + col[0], y, key.base,
|
||||
montauk::keyboard::is_dead_key(layout, key.base), theme);
|
||||
draw_char_cell(c, gx + col[1], y, key.shift,
|
||||
montauk::keyboard::is_dead_key(layout, key.shift), theme);
|
||||
draw_char_cell(c, gx + col[2], y, key.altgr,
|
||||
montauk::keyboard::is_dead_key(layout, key.altgr), theme);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -319,7 +319,7 @@ extern "C" void _start() {
|
||||
break;
|
||||
default:
|
||||
// Handle scancodes for special keys
|
||||
switch (ev.scancode) {
|
||||
switch (montauk::nav_scancode(ev)) {
|
||||
case 0x48: // Up arrow
|
||||
if (scroll > 0) scroll--;
|
||||
break;
|
||||
|
||||
+16
-21
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <montauk/syscall.h>
|
||||
#include <montauk/string.h>
|
||||
#include <montauk/utf8.h>
|
||||
#include <montauk/heap.h>
|
||||
#include <gui/gui.hpp>
|
||||
#include <gui/mtk/settings.hpp>
|
||||
@@ -415,11 +416,6 @@ static char ascii_lower(char c) {
|
||||
return (c >= 'A' && c <= 'Z') ? (char)(c + 32) : c;
|
||||
}
|
||||
|
||||
static bool is_printable_byte(char c) {
|
||||
unsigned char value = (unsigned char)c;
|
||||
return value >= 32 && value != 127;
|
||||
}
|
||||
|
||||
static bool str_contains_case_insensitive(const char* text, const char* needle) {
|
||||
if (!needle || !needle[0]) return true;
|
||||
if (!text || !text[0]) return false;
|
||||
@@ -516,19 +512,16 @@ static void rebuild_filtered_view() {
|
||||
ensure_selected_visible();
|
||||
}
|
||||
|
||||
static void append_filter_char(char c) {
|
||||
static void append_filter_key(const montauk::abi::KeyEvent& key) {
|
||||
int len = montauk::slen(g.filter_text);
|
||||
if (len >= MAX_FILTER - 1) return;
|
||||
g.filter_text[len] = c;
|
||||
g.filter_text[len + 1] = '\0';
|
||||
rebuild_filtered_view();
|
||||
if (montauk::utf8::append_key(g.filter_text, &len, MAX_FILTER, key))
|
||||
rebuild_filtered_view();
|
||||
}
|
||||
|
||||
static void pop_filter_char() {
|
||||
int len = montauk::slen(g.filter_text);
|
||||
if (len <= 0) return;
|
||||
g.filter_text[len - 1] = '\0';
|
||||
rebuild_filtered_view();
|
||||
if (montauk::utf8::erase_last(g.filter_text, &len))
|
||||
rebuild_filtered_view();
|
||||
}
|
||||
|
||||
static void clear_filter() {
|
||||
@@ -1120,8 +1113,10 @@ static void render(uint32_t* pixels) {
|
||||
int qlen = montauk::slen(query);
|
||||
if (qlen > 15) {
|
||||
montauk::memcpy(filter_query, "...", 3);
|
||||
montauk::memcpy(filter_query + 3, query + qlen - 15, 15);
|
||||
filter_query[18] = '\0';
|
||||
int start = montauk::utf8::floor_boundary(query, qlen, qlen - 15);
|
||||
if (start < qlen - 15) start = montauk::utf8::next_boundary(query, qlen, start);
|
||||
montauk::memcpy(filter_query + 3, query + start, qlen - start);
|
||||
filter_query[3 + qlen - start] = '\0';
|
||||
query = filter_query;
|
||||
}
|
||||
|
||||
@@ -1426,11 +1421,11 @@ static bool handle_key(const montauk::abi::KeyEvent& key, bool& quit) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!g.show_visualizer && key.scancode == 0x48) { // Up
|
||||
if (!g.show_visualizer && montauk::nav_scancode(key) == 0x48) { // Up
|
||||
move_selection(-1);
|
||||
return true;
|
||||
}
|
||||
if (!g.show_visualizer && key.scancode == 0x50) { // Down
|
||||
if (!g.show_visualizer && montauk::nav_scancode(key) == 0x50) { // Down
|
||||
move_selection(1);
|
||||
return true;
|
||||
}
|
||||
@@ -1449,8 +1444,8 @@ static bool handle_key(const montauk::abi::KeyEvent& key, bool& quit) {
|
||||
else g.filter_active = false;
|
||||
return true;
|
||||
}
|
||||
if (!key.ctrl && !key.alt && is_printable_byte(key.ascii)) {
|
||||
append_filter_char(key.ascii);
|
||||
if (!key.ctrl && !key.alt && montauk::utf8::key_codepoint(key)) {
|
||||
append_filter_key(key);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -1479,11 +1474,11 @@ static bool handle_key(const montauk::abi::KeyEvent& key, bool& quit) {
|
||||
g.show_visualizer = !g.show_visualizer;
|
||||
return true;
|
||||
}
|
||||
if (key.scancode == 0x4D) { // Right arrow
|
||||
if (montauk::nav_scancode(key) == 0x4D) { // Right arrow
|
||||
next_track(false);
|
||||
return true;
|
||||
}
|
||||
if (key.scancode == 0x4B) { // Left arrow
|
||||
if (montauk::nav_scancode(key) == 0x4B) { // Left arrow
|
||||
prev_track();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -247,6 +247,7 @@ static void fit_text(char* out, int out_cap, const char* text, int max_w) {
|
||||
break;
|
||||
out_len++;
|
||||
}
|
||||
out_len = montauk::utf8::floor_boundary(text, montauk::slen(text), out_len);
|
||||
out[out_len] = '.';
|
||||
out[out_len + 1] = '.';
|
||||
out[out_len + 2] = '.';
|
||||
@@ -1216,8 +1217,8 @@ static bool handle_key(const montauk::abi::KeyEvent& key) {
|
||||
wifi_join_selected();
|
||||
return true;
|
||||
}
|
||||
if (key.scancode == 0x48 || key.scancode == 0x50) { // up / down
|
||||
int step = key.scancode == 0x48 ? -1 : 1;
|
||||
if (montauk::nav_scancode(key) == 0x48 || montauk::nav_scancode(key) == 0x50) { // up / down
|
||||
int step = montauk::nav_scancode(key) == 0x48 ? -1 : 1;
|
||||
int next = g_wifi_selected < 0 ? 0 : g_wifi_selected + step;
|
||||
if (next < 0) next = 0;
|
||||
if (next >= g_wifi_count) next = g_wifi_count - 1;
|
||||
|
||||
@@ -235,25 +235,13 @@ extern "C" void _start() {
|
||||
} else if (key.scancode == 0x01) {
|
||||
g_pathbar_open = false;
|
||||
} else if (key.ascii == '\b' || key.scancode == 0x0E) {
|
||||
if (g_pathbar_cursor > 0) {
|
||||
for (int i = g_pathbar_cursor - 1; i < g_pathbar_len - 1; i++)
|
||||
g_pathbar_text[i] = g_pathbar_text[i + 1];
|
||||
g_pathbar_len--;
|
||||
g_pathbar_cursor--;
|
||||
g_pathbar_text[g_pathbar_len] = '\0';
|
||||
}
|
||||
} else if (key.scancode == 0x4B) {
|
||||
if (g_pathbar_cursor > 0) g_pathbar_cursor--;
|
||||
} else if (key.scancode == 0x4D) {
|
||||
if (g_pathbar_cursor < g_pathbar_len) g_pathbar_cursor++;
|
||||
} else if ((unsigned char)key.ascii >= 32
|
||||
&& (unsigned char)key.ascii != 127 && g_pathbar_len < 254) {
|
||||
for (int i = g_pathbar_len; i > g_pathbar_cursor; i--)
|
||||
g_pathbar_text[i] = g_pathbar_text[i - 1];
|
||||
g_pathbar_text[g_pathbar_cursor] = key.ascii;
|
||||
g_pathbar_cursor++;
|
||||
g_pathbar_len++;
|
||||
g_pathbar_text[g_pathbar_len] = '\0';
|
||||
montauk::utf8::erase_before(g_pathbar_text, &g_pathbar_len, &g_pathbar_cursor);
|
||||
} else if (montauk::nav_scancode(key) == 0x4B) {
|
||||
g_pathbar_cursor = montauk::utf8::prev_boundary(g_pathbar_text, g_pathbar_cursor);
|
||||
} else if (montauk::nav_scancode(key) == 0x4D) {
|
||||
g_pathbar_cursor = montauk::utf8::next_boundary(g_pathbar_text, g_pathbar_len, g_pathbar_cursor);
|
||||
} else {
|
||||
montauk::utf8::insert_key(g_pathbar_text, &g_pathbar_len, 255, &g_pathbar_cursor, key);
|
||||
}
|
||||
redraw = true;
|
||||
goto done_keys;
|
||||
@@ -274,9 +262,9 @@ extern "C" void _start() {
|
||||
redraw = true;
|
||||
}
|
||||
// Page Down / Right arrow: next page
|
||||
else if (key.scancode == 0x51 || key.scancode == 0x4D) {
|
||||
else if (montauk::nav_scancode(key) == 0x51 || montauk::nav_scancode(key) == 0x4D) {
|
||||
if (g_doc.valid) {
|
||||
if (key.scancode == 0x4D && g_scroll_y < max_scroll()) {
|
||||
if (montauk::nav_scancode(key) == 0x4D && g_scroll_y < max_scroll()) {
|
||||
// Right arrow scrolls down within page
|
||||
} else {
|
||||
go_to_page(g_current_page + 1);
|
||||
@@ -285,9 +273,9 @@ extern "C" void _start() {
|
||||
}
|
||||
}
|
||||
// Page Up / Left arrow: previous page
|
||||
else if (key.scancode == 0x49 || key.scancode == 0x4B) {
|
||||
else if (montauk::nav_scancode(key) == 0x49 || montauk::nav_scancode(key) == 0x4B) {
|
||||
if (g_doc.valid) {
|
||||
if (key.scancode == 0x4B && g_scroll_y > 0) {
|
||||
if (montauk::nav_scancode(key) == 0x4B && g_scroll_y > 0) {
|
||||
// Left arrow scrolls up within page
|
||||
} else {
|
||||
go_to_page(g_current_page - 1);
|
||||
@@ -296,23 +284,23 @@ extern "C" void _start() {
|
||||
}
|
||||
}
|
||||
// Up arrow: scroll up
|
||||
else if (key.scancode == 0x48) {
|
||||
else if (montauk::nav_scancode(key) == 0x48) {
|
||||
g_scroll_y -= SCROLL_STEP;
|
||||
clamp_scroll();
|
||||
redraw = true;
|
||||
}
|
||||
// Down arrow: scroll down
|
||||
else if (key.scancode == 0x50) {
|
||||
else if (montauk::nav_scancode(key) == 0x50) {
|
||||
g_scroll_y += SCROLL_STEP;
|
||||
clamp_scroll();
|
||||
redraw = true;
|
||||
}
|
||||
// Home: first page
|
||||
else if (key.scancode == 0x47) {
|
||||
else if (montauk::nav_scancode(key) == 0x47) {
|
||||
if (g_doc.valid) { go_to_page(0); redraw = true; }
|
||||
}
|
||||
// End: last page
|
||||
else if (key.scancode == 0x4F) {
|
||||
else if (montauk::nav_scancode(key) == 0x4F) {
|
||||
if (g_doc.valid) { go_to_page(g_doc.page_count - 1); redraw = true; }
|
||||
}
|
||||
// Ctrl++ or Ctrl+=: zoom in
|
||||
|
||||
@@ -71,7 +71,7 @@ static void draw_affine_text(uint32_t* pixels, const TextItem& item,
|
||||
by0>-0.0001f&&by0<0.0001f&&by1>-0.0001f&&by1<0.0001f) {
|
||||
float pen=0;
|
||||
for(int i=0;i<text_len;i++) {
|
||||
CachedGlyph* glyph=font->get_glyph(cache,(uint8_t)text[i]);
|
||||
CachedGlyph* glyph=font->get_glyph(cache,decode_single_byte_codepoint((uint8_t)text[i]));
|
||||
if(!glyph)continue;
|
||||
if(glyph->bitmap) {
|
||||
int gx=base_x+floor_pixel(pen*g_zoom+0.5f)+glyph->xoff;
|
||||
@@ -101,7 +101,7 @@ static void draw_affine_text(uint32_t* pixels, const TextItem& item,
|
||||
|
||||
float pen = 0;
|
||||
for (int i = 0; i < text_len; i++) {
|
||||
CachedGlyph* glyph = font->get_glyph(cache, (uint8_t)text[i]);
|
||||
CachedGlyph* glyph = font->get_glyph(cache, decode_single_byte_codepoint((uint8_t)text[i]));
|
||||
if (!glyph) continue;
|
||||
if (glyph->bitmap) {
|
||||
float gx0 = (float)(pen + glyph->xoff);
|
||||
|
||||
@@ -143,14 +143,8 @@ static gui::TrueTypeFont* load_page_font(const char* path) {
|
||||
|
||||
static void free_page_font(gui::TrueTypeFont* font) {
|
||||
if (!font) return;
|
||||
for (int i = 0; i < font->cache_count; i++) {
|
||||
for (int g = 0; g < 256; g++) {
|
||||
if (font->caches[i].glyphs[g].bitmap) {
|
||||
montauk::mfree(font->caches[i].glyphs[g].bitmap);
|
||||
font->caches[i].glyphs[g].bitmap = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < font->cache_count; i++)
|
||||
gui::TrueTypeFont::free_cache(&font->caches[i]);
|
||||
if (font->data) {
|
||||
montauk::free(font->data);
|
||||
font->data = nullptr;
|
||||
@@ -209,8 +203,8 @@ static void draw_text(uint8_t* rgb, PageFonts* fonts, bool bold,
|
||||
|
||||
int cx = x;
|
||||
int baseline = y + gc->ascent;
|
||||
for (int i = 0; text[i] != '\0'; i++) {
|
||||
gui::CachedGlyph* glyph = font->get_glyph(gc, (unsigned char)text[i]);
|
||||
for (const char* p = text; *p;) {
|
||||
gui::CachedGlyph* glyph = font->get_glyph(gc, (int)montauk::utf8::next(&p));
|
||||
if (!glyph) continue;
|
||||
|
||||
if (glyph->bitmap) {
|
||||
|
||||
@@ -230,7 +230,8 @@ static void text_fit(const char* src, char* out, int out_len, int max_w) {
|
||||
int keep = montauk::slen(src);
|
||||
while (keep > 0) {
|
||||
char tmp[MAX_DEBUG_LEN];
|
||||
int n = keep < (int)sizeof(tmp) - 4 ? keep : (int)sizeof(tmp) - 4;
|
||||
int n = keep < (int)sizeof(tmp) - 4 ? keep
|
||||
: montauk::utf8::floor_boundary(src, keep, (int)sizeof(tmp) - 4);
|
||||
for (int i = 0; i < n; i++) tmp[i] = src[i];
|
||||
tmp[n] = '\0';
|
||||
str_append(tmp, ell, (int)sizeof(tmp));
|
||||
@@ -238,7 +239,7 @@ static void text_fit(const char* src, char* out, int out_len, int max_w) {
|
||||
montauk::strncpy(out, tmp, out_len - 1);
|
||||
return;
|
||||
}
|
||||
keep--;
|
||||
keep = montauk::utf8::prev_boundary(src, keep);
|
||||
}
|
||||
montauk::strncpy(out, ell, out_len - 1);
|
||||
}
|
||||
@@ -1162,12 +1163,12 @@ static void handle_key(const montauk::abi::KeyEvent& key) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (key.scancode == 0x4B) {
|
||||
if (montauk::nav_scancode(key) == 0x4B) {
|
||||
cycle_tab(-1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (key.scancode == 0x4D) {
|
||||
if (montauk::nav_scancode(key) == 0x4D) {
|
||||
cycle_tab(1);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -527,6 +527,8 @@ static void draw_text_fit(Canvas& c, int x, int y,
|
||||
out++;
|
||||
}
|
||||
|
||||
out = montauk::utf8::floor_boundary(text, montauk::slen(text), out);
|
||||
|
||||
if (out <= 0) return;
|
||||
buf[out] = '.';
|
||||
buf[out + 1] = '.';
|
||||
@@ -852,24 +854,24 @@ static bool handle_key(const montauk::abi::KeyEvent& key) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (key.scancode == 0x4B) {
|
||||
if (montauk::nav_scancode(key) == 0x4B) {
|
||||
cycle_tab(-1);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (key.scancode == 0x4D) {
|
||||
if (montauk::nav_scancode(key) == 0x4D) {
|
||||
cycle_tab(1);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (key.scancode == 0x53) {
|
||||
if (montauk::nav_scancode(key) == 0x53) {
|
||||
if (can_kill_selected()) {
|
||||
kill_selected();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (key.scancode == 0x48) {
|
||||
if (montauk::nav_scancode(key) == 0x48) {
|
||||
if (g_pm.active_tab == PM_TAB_PROCESSES) {
|
||||
if (g_pm.selected > 0) g_pm.selected--;
|
||||
else if (g_pm.proc_count > 0) g_pm.selected = 0;
|
||||
@@ -884,7 +886,7 @@ static bool handle_key(const montauk::abi::KeyEvent& key) {
|
||||
}
|
||||
}
|
||||
|
||||
if (key.scancode == 0x50) {
|
||||
if (montauk::nav_scancode(key) == 0x50) {
|
||||
if (g_pm.active_tab == PM_TAB_PROCESSES) {
|
||||
if (g_pm.selected < g_pm.proc_count - 1) g_pm.selected++;
|
||||
else if (g_pm.selected < 0 && g_pm.proc_count > 0) g_pm.selected = 0;
|
||||
|
||||
+16
-11
@@ -92,7 +92,9 @@ static void prompt() {
|
||||
|
||||
// ---- Line editing ----
|
||||
|
||||
static void erase_input(int len) {
|
||||
// Erase the echoed input: one terminal cell per UTF-8 character.
|
||||
static void erase_input(const char* line, int bytes) {
|
||||
int len = montauk::utf8::count(line, bytes);
|
||||
for (int i = 0; i < len; i++) montauk::putchar('\b');
|
||||
for (int i = 0; i < len; i++) montauk::putchar(' ');
|
||||
for (int i = 0; i < len; i++) montauk::putchar('\b');
|
||||
@@ -100,9 +102,9 @@ static void erase_input(int len) {
|
||||
|
||||
static void replace_line(char* line, int* pos, const char* newContent) {
|
||||
int oldLen = *pos;
|
||||
erase_input(oldLen);
|
||||
erase_input(line, oldLen);
|
||||
int newLen = slen(newContent);
|
||||
if (newLen > 255) newLen = 255;
|
||||
if (newLen > 255) newLen = montauk::utf8::floor_boundary(newContent, newLen, 255);
|
||||
for (int i = 0; i < newLen; i++) {
|
||||
line[i] = newContent[i];
|
||||
montauk::putchar(newContent[i]);
|
||||
@@ -431,14 +433,14 @@ extern "C" void _start() {
|
||||
|
||||
// Arrow keys: ascii == 0, check scancode
|
||||
if (ev.ascii == 0) {
|
||||
if (ev.scancode == SC_UP) {
|
||||
if (montauk::nav_scancode(ev) == SC_UP) {
|
||||
int next = hist_nav + 1;
|
||||
const char* entry = history_get(next);
|
||||
if (entry) {
|
||||
hist_nav = next;
|
||||
replace_line(line, &pos, entry);
|
||||
}
|
||||
} else if (ev.scancode == SC_DOWN) {
|
||||
} else if (montauk::nav_scancode(ev) == SC_DOWN) {
|
||||
if (hist_nav > 0) {
|
||||
hist_nav--;
|
||||
const char* entry = history_get(hist_nav);
|
||||
@@ -447,7 +449,7 @@ extern "C" void _start() {
|
||||
}
|
||||
} else if (hist_nav == 0) {
|
||||
hist_nav = -1;
|
||||
erase_input(pos);
|
||||
erase_input(line, pos);
|
||||
pos = 0;
|
||||
line[0] = '\0';
|
||||
}
|
||||
@@ -496,15 +498,18 @@ extern "C" void _start() {
|
||||
hist_nav = -1;
|
||||
prompt();
|
||||
} else if (ev.ascii == '\b') {
|
||||
if (pos > 0) {
|
||||
pos--;
|
||||
// One terminal cell per character, however many UTF-8 bytes
|
||||
line[pos] = '\0';
|
||||
if (montauk::utf8::erase_last(line, &pos)) {
|
||||
montauk::putchar('\b');
|
||||
montauk::putchar(' ');
|
||||
montauk::putchar('\b');
|
||||
}
|
||||
} else if (ev.ascii >= ' ' && pos < 255) {
|
||||
line[pos++] = ev.ascii;
|
||||
montauk::putchar(ev.ascii);
|
||||
} else {
|
||||
line[pos] = '\0';
|
||||
int before = pos;
|
||||
if (montauk::utf8::append_key(line, &pos, 256, ev))
|
||||
montauk::print(line + before);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <montauk/syscall.h>
|
||||
#include <montauk/string.h>
|
||||
#include <montauk/utf8.h>
|
||||
#include <montauk/heap.h>
|
||||
#include <montauk/config.h>
|
||||
#include <montauk/capabilities.h>
|
||||
|
||||
@@ -415,25 +415,13 @@ extern "C" void _start() {
|
||||
} else if (key.scancode == 0x01) {
|
||||
g_pathbar_open = false;
|
||||
} else if (key.ascii == '\b' || key.scancode == 0x0E) {
|
||||
if (g_pathbar_cursor > 0) {
|
||||
for (int i = g_pathbar_cursor - 1; i < g_pathbar_len - 1; i++)
|
||||
g_pathbar_text[i] = g_pathbar_text[i + 1];
|
||||
g_pathbar_len--;
|
||||
g_pathbar_cursor--;
|
||||
g_pathbar_text[g_pathbar_len] = '\0';
|
||||
}
|
||||
} else if (key.scancode == 0x4B) {
|
||||
if (g_pathbar_cursor > 0) g_pathbar_cursor--;
|
||||
} else if (key.scancode == 0x4D) {
|
||||
if (g_pathbar_cursor < g_pathbar_len) g_pathbar_cursor++;
|
||||
} else if ((unsigned char)key.ascii >= 32
|
||||
&& (unsigned char)key.ascii != 127 && g_pathbar_len < 254) {
|
||||
for (int i = g_pathbar_len; i > g_pathbar_cursor; i--)
|
||||
g_pathbar_text[i] = g_pathbar_text[i - 1];
|
||||
g_pathbar_text[g_pathbar_cursor] = key.ascii;
|
||||
g_pathbar_cursor++;
|
||||
g_pathbar_len++;
|
||||
g_pathbar_text[g_pathbar_len] = '\0';
|
||||
montauk::utf8::erase_before(g_pathbar_text, &g_pathbar_len, &g_pathbar_cursor);
|
||||
} else if (montauk::nav_scancode(key) == 0x4B) {
|
||||
g_pathbar_cursor = montauk::utf8::prev_boundary(g_pathbar_text, g_pathbar_cursor);
|
||||
} else if (montauk::nav_scancode(key) == 0x4D) {
|
||||
g_pathbar_cursor = montauk::utf8::next_boundary(g_pathbar_text, g_pathbar_len, g_pathbar_cursor);
|
||||
} else {
|
||||
montauk::utf8::insert_key(g_pathbar_text, &g_pathbar_len, 255, &g_pathbar_cursor, key);
|
||||
}
|
||||
redraw = true;
|
||||
goto done_keys;
|
||||
@@ -441,12 +429,12 @@ extern "C" void _start() {
|
||||
|
||||
// Autocomplete interaction (when editing with autocomplete open)
|
||||
if (g_ac_open && g_editing) {
|
||||
if (key.scancode == 0x48) { // Up
|
||||
if (montauk::nav_scancode(key) == 0x48) { // Up
|
||||
g_ac_sel = (g_ac_sel - 1 + g_ac_count) % g_ac_count;
|
||||
redraw = true;
|
||||
goto done_keys;
|
||||
}
|
||||
if (key.scancode == 0x50) { // Down
|
||||
if (montauk::nav_scancode(key) == 0x50) { // Down
|
||||
g_ac_sel = (g_ac_sel + 1) % g_ac_count;
|
||||
redraw = true;
|
||||
goto done_keys;
|
||||
@@ -498,7 +486,7 @@ extern "C" void _start() {
|
||||
redraw = true;
|
||||
}
|
||||
// Arrow keys (with Shift = extend selection)
|
||||
else if (key.scancode == 0x48 && !g_editing) { // Up
|
||||
else if (montauk::nav_scancode(key) == 0x48 && !g_editing) { // Up
|
||||
if (key.shift) {
|
||||
if (!g_has_selection) { g_anchor_col = g_sel_col; g_anchor_row = g_sel_row; g_has_selection = true; }
|
||||
if (g_sel_row > 0) g_sel_row--;
|
||||
@@ -509,7 +497,7 @@ extern "C" void _start() {
|
||||
ensure_sel_visible();
|
||||
redraw = true;
|
||||
}
|
||||
else if (key.scancode == 0x50 && !g_editing) { // Down
|
||||
else if (montauk::nav_scancode(key) == 0x50 && !g_editing) { // Down
|
||||
if (key.shift) {
|
||||
if (!g_has_selection) { g_anchor_col = g_sel_col; g_anchor_row = g_sel_row; g_has_selection = true; }
|
||||
if (g_sel_row < MAX_ROWS - 1) g_sel_row++;
|
||||
@@ -520,7 +508,7 @@ extern "C" void _start() {
|
||||
ensure_sel_visible();
|
||||
redraw = true;
|
||||
}
|
||||
else if (key.scancode == 0x4B && !g_editing) { // Left
|
||||
else if (montauk::nav_scancode(key) == 0x4B && !g_editing) { // Left
|
||||
if (key.shift) {
|
||||
if (!g_has_selection) { g_anchor_col = g_sel_col; g_anchor_row = g_sel_row; g_has_selection = true; }
|
||||
if (g_sel_col > 0) g_sel_col--;
|
||||
@@ -531,7 +519,7 @@ extern "C" void _start() {
|
||||
ensure_sel_visible();
|
||||
redraw = true;
|
||||
}
|
||||
else if (key.scancode == 0x4D && !g_editing) { // Right
|
||||
else if (montauk::nav_scancode(key) == 0x4D && !g_editing) { // Right
|
||||
if (key.shift) {
|
||||
if (!g_has_selection) { g_anchor_col = g_sel_col; g_anchor_row = g_sel_row; g_has_selection = true; }
|
||||
if (g_sel_col < MAX_COLS - 1) g_sel_col++;
|
||||
@@ -545,14 +533,8 @@ extern "C" void _start() {
|
||||
// Backspace
|
||||
else if (key.ascii == '\b' || key.scancode == 0x0E) {
|
||||
if (g_editing) {
|
||||
if (g_edit_cursor > 0) {
|
||||
for (int i = g_edit_cursor - 1; i < g_edit_len - 1; i++)
|
||||
g_edit_buf[i] = g_edit_buf[i + 1];
|
||||
g_edit_len--;
|
||||
g_edit_cursor--;
|
||||
g_edit_buf[g_edit_len] = '\0';
|
||||
if (montauk::utf8::erase_before(g_edit_buf, &g_edit_len, &g_edit_cursor))
|
||||
update_autocomplete();
|
||||
}
|
||||
redraw = true;
|
||||
} else {
|
||||
undo_push();
|
||||
@@ -567,15 +549,10 @@ extern "C" void _start() {
|
||||
}
|
||||
}
|
||||
// Delete key
|
||||
else if (key.scancode == 0x53) {
|
||||
else if (montauk::nav_scancode(key) == 0x53) {
|
||||
if (g_editing) {
|
||||
if (g_edit_cursor < g_edit_len) {
|
||||
for (int i = g_edit_cursor; i < g_edit_len - 1; i++)
|
||||
g_edit_buf[i] = g_edit_buf[i + 1];
|
||||
g_edit_len--;
|
||||
g_edit_buf[g_edit_len] = '\0';
|
||||
if (montauk::utf8::erase_at(g_edit_buf, &g_edit_len, g_edit_cursor))
|
||||
update_autocomplete();
|
||||
}
|
||||
redraw = true;
|
||||
} else {
|
||||
undo_push();
|
||||
@@ -590,18 +567,18 @@ extern "C" void _start() {
|
||||
}
|
||||
}
|
||||
// Edit mode arrow keys (cursor movement within formula bar)
|
||||
else if (key.scancode == 0x4B && g_editing) {
|
||||
if (g_edit_cursor > 0) g_edit_cursor--;
|
||||
else if (montauk::nav_scancode(key) == 0x4B && g_editing) {
|
||||
g_edit_cursor = montauk::utf8::prev_boundary(g_edit_buf, g_edit_cursor);
|
||||
update_autocomplete();
|
||||
redraw = true;
|
||||
}
|
||||
else if (key.scancode == 0x4D && g_editing) {
|
||||
if (g_edit_cursor < g_edit_len) g_edit_cursor++;
|
||||
else if (montauk::nav_scancode(key) == 0x4D && g_editing) {
|
||||
g_edit_cursor = montauk::utf8::next_boundary(g_edit_buf, g_edit_len, g_edit_cursor);
|
||||
update_autocomplete();
|
||||
redraw = true;
|
||||
}
|
||||
// Home key
|
||||
else if (key.scancode == 0x47) {
|
||||
else if (montauk::nav_scancode(key) == 0x47) {
|
||||
if (g_editing) {
|
||||
g_edit_cursor = 0;
|
||||
update_autocomplete();
|
||||
@@ -613,7 +590,7 @@ extern "C" void _start() {
|
||||
redraw = true;
|
||||
}
|
||||
// End key
|
||||
else if (key.scancode == 0x4F) {
|
||||
else if (montauk::nav_scancode(key) == 0x4F) {
|
||||
if (g_editing) {
|
||||
g_edit_cursor = g_edit_len;
|
||||
update_autocomplete();
|
||||
@@ -670,23 +647,16 @@ extern "C" void _start() {
|
||||
redraw = true;
|
||||
}
|
||||
// Printable character: start editing or insert
|
||||
else if ((unsigned char)key.ascii >= 32
|
||||
&& (unsigned char)key.ascii != 127 && !key.ctrl) {
|
||||
else if (montauk::utf8::key_codepoint(key) && !key.ctrl) {
|
||||
if (!g_editing) {
|
||||
clear_selection();
|
||||
g_editing = true;
|
||||
g_edit_buf[0] = key.ascii;
|
||||
g_edit_buf[1] = '\0';
|
||||
g_edit_len = 1;
|
||||
g_edit_cursor = 1;
|
||||
} else if (g_edit_len < CELL_TEXT_MAX - 1) {
|
||||
for (int i = g_edit_len; i > g_edit_cursor; i--)
|
||||
g_edit_buf[i] = g_edit_buf[i - 1];
|
||||
g_edit_buf[g_edit_cursor] = key.ascii;
|
||||
g_edit_len++;
|
||||
g_edit_cursor++;
|
||||
g_edit_buf[g_edit_len] = '\0';
|
||||
g_edit_buf[0] = '\0';
|
||||
g_edit_len = 0;
|
||||
g_edit_cursor = 0;
|
||||
}
|
||||
montauk::utf8::insert_key(g_edit_buf, &g_edit_len, CELL_TEXT_MAX,
|
||||
&g_edit_cursor, key);
|
||||
update_autocomplete();
|
||||
redraw = true;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <montauk/service_log.h>
|
||||
#include <montauk/ssh.h>
|
||||
#include <montauk/utf8.h>
|
||||
#include <libc/stdio.h>
|
||||
|
||||
extern "C" {
|
||||
@@ -1009,8 +1010,20 @@ static void feed_child(int pid, const uint8_t* data, int size) {
|
||||
/* Remaining C0 codes are the control-modified letters. */
|
||||
key.ascii = (char)('a' + value - 1);
|
||||
key.ctrl = true;
|
||||
} else {
|
||||
} else if (value < 0x80) {
|
||||
key.ascii = (char)value;
|
||||
key.codepoint = value;
|
||||
} else {
|
||||
/* The client sends UTF-8; the key event carries the codepoint plus
|
||||
its Windows-1252 byte for legacy readers. A keystroke's sequence
|
||||
arrives in one packet, so splitting across feed_child calls is
|
||||
ignored. */
|
||||
int n;
|
||||
uint32_t cp = montauk::utf8::decode((const char*)data + i, size - i, &n);
|
||||
i += n - 1;
|
||||
uint8_t b = montauk::utf8::to_cp1252(cp);
|
||||
key.codepoint = cp;
|
||||
key.ascii = b ? (char)b : montauk::abi::KEY_ASCII_SUBSTITUTE;
|
||||
}
|
||||
|
||||
montauk::childio_writekey(pid, &key);
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
#include <montauk/syscall.h>
|
||||
#include <montauk/utf8.h>
|
||||
#include <montauk/string.h>
|
||||
|
||||
using montauk::skip_spaces;
|
||||
@@ -176,15 +177,18 @@ extern "C" void _start() {
|
||||
montauk::send(fd, sendBuf, sendPos);
|
||||
sendPos = 0;
|
||||
} else if (ev.ascii == '\b') {
|
||||
if (sendPos > 0) {
|
||||
sendPos--;
|
||||
sendBuf[sendPos] = '\0';
|
||||
if (montauk::utf8::erase_last(sendBuf, &sendPos)) {
|
||||
montauk::putchar('\b');
|
||||
montauk::putchar(' ');
|
||||
montauk::putchar('\b');
|
||||
}
|
||||
} else if (ev.ascii >= ' ' && sendPos < 254) {
|
||||
sendBuf[sendPos++] = ev.ascii;
|
||||
montauk::putchar(ev.ascii);
|
||||
} else {
|
||||
// Typed text is sent as UTF-8; leave room for the '\n'
|
||||
sendBuf[sendPos] = '\0';
|
||||
int before = sendPos;
|
||||
if (montauk::utf8::append_key(sendBuf, &sendPos, 255, ev))
|
||||
montauk::print(sendBuf + before);
|
||||
}
|
||||
} else {
|
||||
montauk::wait_handle(fd, montauk::abi::IPC_SIGNAL_READABLE | montauk::abi::IPC_SIGNAL_PEER_CLOSED, 10);
|
||||
|
||||
@@ -479,9 +479,9 @@ static void handle_key(const montauk::abi::KeyEvent& key) {
|
||||
step_font_size(FONT_SIZE_STEP);
|
||||
} else if (key.ascii == '-') {
|
||||
step_font_size(-FONT_SIZE_STEP);
|
||||
} else if (key.scancode == 0x48) { // Up
|
||||
} else if (montauk::nav_scancode(key) == 0x48) { // Up
|
||||
select_theme(g_panel.theme_index - 1);
|
||||
} else if (key.scancode == 0x50) { // Down
|
||||
} else if (montauk::nav_scancode(key) == 0x50) { // Down
|
||||
select_theme(g_panel.theme_index + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ int g_line_count = 0;
|
||||
// Cursor
|
||||
int g_cursor_pos = 0; // byte position
|
||||
int g_cursor_line = 0;
|
||||
int g_cursor_col = 0;
|
||||
int g_cursor_col = 0; // character (display) column, not bytes
|
||||
int g_scroll_y = 0; // first visible line
|
||||
int g_scroll_x = 0; // horizontal scroll in pixels
|
||||
bool g_scroll_dragging = false;
|
||||
@@ -264,7 +264,8 @@ static void update_cursor_pos() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
g_cursor_col = g_cursor_pos - g_line_offsets[g_cursor_line];
|
||||
int ls = g_line_offsets[g_cursor_line];
|
||||
g_cursor_col = montauk::utf8::count(g_buffer + ls, g_cursor_pos - ls);
|
||||
g_cursor_moved = true;
|
||||
}
|
||||
|
||||
@@ -275,6 +276,12 @@ static int line_length(int line) {
|
||||
return end - start;
|
||||
}
|
||||
|
||||
// Byte offset of character column `col` on a line (clamped to its end).
|
||||
static int line_col_to_pos(int line, int col) {
|
||||
int start = g_line_offsets[line];
|
||||
return start + montauk::utf8::offset_of(g_buffer + start, line_length(line), col);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Buffer operations
|
||||
// ============================================================================
|
||||
@@ -294,17 +301,10 @@ static void delete_range(int start, int count) {
|
||||
g_buf_len -= count;
|
||||
}
|
||||
|
||||
static void insert_string(const char* s, int len);
|
||||
|
||||
static void insert_char(char c) {
|
||||
if (g_buf_len >= MAX_CAP - 1) return;
|
||||
ensure_capacity(1);
|
||||
for (int i = g_buf_len; i > g_cursor_pos; i--)
|
||||
g_buffer[i] = g_buffer[i - 1];
|
||||
g_buffer[g_cursor_pos] = c;
|
||||
g_buf_len++;
|
||||
g_cursor_pos++;
|
||||
g_modified = true;
|
||||
recompute_lines();
|
||||
update_cursor_pos();
|
||||
insert_string(&c, 1);
|
||||
}
|
||||
|
||||
static void insert_string(const char* s, int len) {
|
||||
@@ -323,8 +323,9 @@ static void insert_string(const char* s, int len) {
|
||||
|
||||
static void backspace() {
|
||||
if (g_cursor_pos <= 0) return;
|
||||
g_cursor_pos--;
|
||||
delete_range(g_cursor_pos, 1);
|
||||
int start = montauk::utf8::prev_boundary(g_buffer, g_cursor_pos);
|
||||
delete_range(start, g_cursor_pos - start);
|
||||
g_cursor_pos = start;
|
||||
g_modified = true;
|
||||
recompute_lines();
|
||||
update_cursor_pos();
|
||||
@@ -332,7 +333,8 @@ static void backspace() {
|
||||
|
||||
static void delete_char() {
|
||||
if (g_cursor_pos >= g_buf_len) return;
|
||||
delete_range(g_cursor_pos, 1);
|
||||
delete_range(g_cursor_pos,
|
||||
montauk::utf8::next_boundary(g_buffer, g_buf_len, g_cursor_pos) - g_cursor_pos);
|
||||
g_modified = true;
|
||||
recompute_lines();
|
||||
update_cursor_pos();
|
||||
@@ -344,30 +346,28 @@ static void delete_char() {
|
||||
|
||||
static void move_up() {
|
||||
if (g_cursor_line <= 0) return;
|
||||
int col = g_cursor_col;
|
||||
int prev = g_cursor_line - 1;
|
||||
int len = line_length(prev);
|
||||
if (col > len) col = len;
|
||||
g_cursor_pos = g_line_offsets[prev] + col;
|
||||
g_cursor_pos = line_col_to_pos(g_cursor_line - 1, g_cursor_col);
|
||||
update_cursor_pos();
|
||||
}
|
||||
|
||||
static void move_down() {
|
||||
if (g_cursor_line >= g_line_count - 1) return;
|
||||
int col = g_cursor_col;
|
||||
int next = g_cursor_line + 1;
|
||||
int len = line_length(next);
|
||||
if (col > len) col = len;
|
||||
g_cursor_pos = g_line_offsets[next] + col;
|
||||
g_cursor_pos = line_col_to_pos(g_cursor_line + 1, g_cursor_col);
|
||||
update_cursor_pos();
|
||||
}
|
||||
|
||||
static void move_left() {
|
||||
if (g_cursor_pos > 0) { g_cursor_pos--; update_cursor_pos(); }
|
||||
if (g_cursor_pos > 0) {
|
||||
g_cursor_pos = montauk::utf8::prev_boundary(g_buffer, g_cursor_pos);
|
||||
update_cursor_pos();
|
||||
}
|
||||
}
|
||||
|
||||
static void move_right() {
|
||||
if (g_cursor_pos < g_buf_len) { g_cursor_pos++; update_cursor_pos(); }
|
||||
if (g_cursor_pos < g_buf_len) {
|
||||
g_cursor_pos = montauk::utf8::next_boundary(g_buffer, g_buf_len, g_cursor_pos);
|
||||
update_cursor_pos();
|
||||
}
|
||||
}
|
||||
|
||||
static void move_home() {
|
||||
@@ -621,6 +621,25 @@ static bool load_file(const char* path) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Files written before MontaukOS moved to UTF-8 are Windows-1252. Convert
|
||||
// them once on load, so edits (which insert UTF-8) never mix encodings
|
||||
// and saving writes the whole file back as UTF-8.
|
||||
bool converted = false;
|
||||
if (!montauk::utf8::valid(temp, got)) {
|
||||
int conv_cap = got * 3 + 1;
|
||||
if (conv_cap > MAX_CAP) conv_cap = MAX_CAP;
|
||||
char* conv = (char*)montauk::malloc(conv_cap);
|
||||
if (!conv) {
|
||||
montauk::mfree(temp);
|
||||
set_status("Out of memory while opening file");
|
||||
return false;
|
||||
}
|
||||
got = montauk::utf8::normalize(temp, got, conv, conv_cap);
|
||||
montauk::mfree(temp);
|
||||
temp = conv;
|
||||
converted = true;
|
||||
}
|
||||
|
||||
if (got >= g_buf_cap) {
|
||||
int new_cap = got + 1024;
|
||||
if (new_cap > MAX_CAP) new_cap = MAX_CAP;
|
||||
@@ -649,7 +668,7 @@ static bool load_file(const char* path) {
|
||||
|
||||
g_syntax_language = syn_detect_language(g_filepath);
|
||||
clear_selection();
|
||||
set_status("");
|
||||
set_status(converted ? "Converted from Windows-1252 to UTF-8" : "");
|
||||
|
||||
recompute_lines();
|
||||
update_cursor_pos();
|
||||
@@ -686,10 +705,8 @@ static int hit_test(int mx, int my, int editor_y) {
|
||||
|
||||
int clicked_col = (mx - LINE_NUM_W - 4 + g_scroll_x + cell_w / 2) / cell_w;
|
||||
if (clicked_col < 0) clicked_col = 0;
|
||||
int ll = line_length(clicked_line);
|
||||
if (clicked_col > ll) clicked_col = ll;
|
||||
|
||||
return g_line_offsets[clicked_line] + clicked_col;
|
||||
return line_col_to_pos(clicked_line, clicked_col);
|
||||
}
|
||||
|
||||
static void draw_context_menu(uint32_t* pixels, int W, int H) {
|
||||
@@ -861,14 +878,19 @@ static void render(uint32_t* pixels) {
|
||||
syn_highlight_line(g_buffer + line_start, line_len, syn_line_buf,
|
||||
SYN_LINE_BUF_CAP, g_syntax_language, syn_state);
|
||||
|
||||
for (int ci = 0; ci < line_len; ci++) {
|
||||
int px_x = text_start_x + ci * cell_w - g_scroll_x;
|
||||
// One monospace cell per character; ci walks bytes, col walks cells.
|
||||
for (int ci = 0, col = 0; ci < line_len; col++) {
|
||||
int ch_bytes;
|
||||
uint32_t ch = montauk::utf8::decode(g_buffer + line_start + ci,
|
||||
line_len - ci, &ch_bytes);
|
||||
int byte_pos = line_start + ci;
|
||||
int syn_index = ci;
|
||||
ci += ch_bytes;
|
||||
|
||||
int px_x = text_start_x + col * cell_w - g_scroll_x;
|
||||
if (px_x + cell_w <= LINE_NUM_W + 1) continue;
|
||||
if (px_x >= text_area_w) break;
|
||||
|
||||
int byte_pos = line_start + ci;
|
||||
char ch = g_buffer[byte_pos];
|
||||
|
||||
// Selection highlight
|
||||
if (g_has_selection && byte_pos >= sel_s && byte_pos < sel_e) {
|
||||
int hl_h = cell_h;
|
||||
@@ -878,22 +900,24 @@ static void render(uint32_t* pixels) {
|
||||
}
|
||||
|
||||
Color char_color = TEXT_COLOR;
|
||||
if (g_syntax_language != SYN_LANG_NONE && ci < syn_len)
|
||||
char_color = syn_color(syn_line_buf[ci]);
|
||||
if (g_syntax_language != SYN_LANG_NONE && syn_index < syn_len)
|
||||
char_color = syn_color(syn_line_buf[syn_index]);
|
||||
|
||||
if (ch >= 32 || ch < 0) {
|
||||
if (ch >= 32) {
|
||||
if (gc) {
|
||||
g_font_mono->draw_char_to_buffer(pixels, W, H, px_x, py + gc->ascent,
|
||||
ch, char_color, gc);
|
||||
(int)ch, char_color, gc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Selection highlight for newline at end of line
|
||||
if (g_has_selection && line + 1 < g_line_count) {
|
||||
int nl_pos = line_start + line_len;
|
||||
if (nl_pos >= sel_s && nl_pos < sel_e) {
|
||||
int px_x = text_start_x + line_len * cell_w - g_scroll_x;
|
||||
int line_cols = montauk::utf8::count(g_buffer + line_start, line_len);
|
||||
int px_x = text_start_x + line_cols * cell_w - g_scroll_x;
|
||||
if (px_x > LINE_NUM_W && px_x < text_area_w) {
|
||||
int hl_h = cell_h;
|
||||
if (py + hl_h > editor_y + text_area_h) hl_h = editor_y + text_area_h - py;
|
||||
@@ -1052,25 +1076,12 @@ static bool handle_key(montauk::abi::KeyEvent& key, int win_id) {
|
||||
return true;
|
||||
}
|
||||
if (key.ascii == '\b' || key.scancode == 0x0E) {
|
||||
if (g_pathbar_cursor > 0) {
|
||||
for (int i = g_pathbar_cursor - 1; i < g_pathbar_len - 1; i++)
|
||||
g_pathbar_text[i] = g_pathbar_text[i + 1];
|
||||
g_pathbar_len--;
|
||||
g_pathbar_cursor--;
|
||||
g_pathbar_text[g_pathbar_len] = '\0';
|
||||
}
|
||||
montauk::utf8::erase_before(g_pathbar_text, &g_pathbar_len, &g_pathbar_cursor);
|
||||
return true;
|
||||
}
|
||||
if (key.scancode == 0x4B) { if (g_pathbar_cursor > 0) g_pathbar_cursor--; return true; }
|
||||
if (key.scancode == 0x4D) { if (g_pathbar_cursor < g_pathbar_len) g_pathbar_cursor++; return true; }
|
||||
if ((unsigned char)key.ascii >= 32
|
||||
&& (unsigned char)key.ascii != 127 && g_pathbar_len < 254) {
|
||||
for (int i = g_pathbar_len; i > g_pathbar_cursor; i--)
|
||||
g_pathbar_text[i] = g_pathbar_text[i - 1];
|
||||
g_pathbar_text[g_pathbar_cursor] = key.ascii;
|
||||
g_pathbar_cursor++;
|
||||
g_pathbar_len++;
|
||||
g_pathbar_text[g_pathbar_len] = '\0';
|
||||
if (montauk::nav_scancode(key) == 0x4B) { g_pathbar_cursor = montauk::utf8::prev_boundary(g_pathbar_text, g_pathbar_cursor); return true; }
|
||||
if (montauk::nav_scancode(key) == 0x4D) { g_pathbar_cursor = montauk::utf8::next_boundary(g_pathbar_text, g_pathbar_len, g_pathbar_cursor); return true; }
|
||||
if (montauk::utf8::insert_key(g_pathbar_text, &g_pathbar_len, 255, &g_pathbar_cursor, key)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -1123,19 +1134,19 @@ static bool handle_key(montauk::abi::KeyEvent& key, int win_id) {
|
||||
}
|
||||
|
||||
// Arrow keys
|
||||
if (key.scancode == 0x48) { // Up
|
||||
if (montauk::nav_scancode(key) == 0x48) { // Up
|
||||
if (key.shift) start_selection(); else if (g_has_selection) clear_selection();
|
||||
move_up();
|
||||
if (key.shift) update_selection();
|
||||
return true;
|
||||
}
|
||||
if (key.scancode == 0x50) { // Down
|
||||
if (montauk::nav_scancode(key) == 0x50) { // Down
|
||||
if (key.shift) start_selection(); else if (g_has_selection) clear_selection();
|
||||
move_down();
|
||||
if (key.shift) update_selection();
|
||||
return true;
|
||||
}
|
||||
if (key.scancode == 0x4B) { // Left
|
||||
if (montauk::nav_scancode(key) == 0x4B) { // Left
|
||||
if (key.shift) {
|
||||
start_selection(); move_left(); update_selection();
|
||||
} else if (g_has_selection) {
|
||||
@@ -1144,7 +1155,7 @@ static bool handle_key(montauk::abi::KeyEvent& key, int win_id) {
|
||||
} else move_left();
|
||||
return true;
|
||||
}
|
||||
if (key.scancode == 0x4D) { // Right
|
||||
if (montauk::nav_scancode(key) == 0x4D) { // Right
|
||||
if (key.shift) {
|
||||
start_selection(); move_right(); update_selection();
|
||||
} else if (g_has_selection) {
|
||||
@@ -1155,14 +1166,14 @@ static bool handle_key(montauk::abi::KeyEvent& key, int win_id) {
|
||||
}
|
||||
|
||||
// Home
|
||||
if (key.scancode == 0x47) {
|
||||
if (montauk::nav_scancode(key) == 0x47) {
|
||||
if (key.shift) start_selection(); else if (g_has_selection) clear_selection();
|
||||
move_home();
|
||||
if (key.shift) update_selection();
|
||||
return true;
|
||||
}
|
||||
// End
|
||||
if (key.scancode == 0x4F) {
|
||||
if (montauk::nav_scancode(key) == 0x4F) {
|
||||
if (key.shift) start_selection(); else if (g_has_selection) clear_selection();
|
||||
move_end();
|
||||
if (key.shift) update_selection();
|
||||
@@ -1170,7 +1181,7 @@ static bool handle_key(montauk::abi::KeyEvent& key, int win_id) {
|
||||
}
|
||||
|
||||
// Page Up
|
||||
if (key.scancode == 0x49) {
|
||||
if (montauk::nav_scancode(key) == 0x49) {
|
||||
if (key.shift) start_selection(); else if (g_has_selection) clear_selection();
|
||||
int cell_h = font_cell_h();
|
||||
int vis = cell_h > 0 ? (g_win_h - TOOLBAR_H - STATUS_H) / cell_h : 20;
|
||||
@@ -1179,7 +1190,7 @@ static bool handle_key(montauk::abi::KeyEvent& key, int win_id) {
|
||||
return true;
|
||||
}
|
||||
// Page Down
|
||||
if (key.scancode == 0x51) {
|
||||
if (montauk::nav_scancode(key) == 0x51) {
|
||||
if (key.shift) start_selection(); else if (g_has_selection) clear_selection();
|
||||
int cell_h = font_cell_h();
|
||||
int vis = cell_h > 0 ? (g_win_h - TOOLBAR_H - STATUS_H) / cell_h : 20;
|
||||
@@ -1189,7 +1200,7 @@ static bool handle_key(montauk::abi::KeyEvent& key, int win_id) {
|
||||
}
|
||||
|
||||
// Delete
|
||||
if (key.scancode == 0x53) {
|
||||
if (montauk::nav_scancode(key) == 0x53) {
|
||||
if (g_has_selection) delete_selection(); else delete_char();
|
||||
return true;
|
||||
}
|
||||
@@ -1214,10 +1225,12 @@ static bool handle_key(montauk::abi::KeyEvent& key, int win_id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Printable
|
||||
if ((unsigned char)key.ascii >= 32 && (unsigned char)key.ascii != 127) {
|
||||
// Printable (inserted as UTF-8)
|
||||
char typed[montauk::utf8::MAX_BYTES];
|
||||
int typed_len = montauk::utf8::key_utf8(key, typed);
|
||||
if (typed_len > 0) {
|
||||
if (g_has_selection) delete_selection();
|
||||
insert_char(key.ascii);
|
||||
insert_string(typed, typed_len);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1404,12 +1417,8 @@ static bool handle_mouse(montauk::abi::WinEvent& ev, int win_id) {
|
||||
if (new_line >= g_scroll_y + visible_lines) new_line = g_scroll_y + visible_lines - 1;
|
||||
if (new_line < 0) new_line = 0;
|
||||
if (new_line >= g_line_count) new_line = g_line_count - 1;
|
||||
int col = g_cursor_col;
|
||||
int ll = line_length(new_line);
|
||||
if (col > ll) col = ll;
|
||||
g_cursor_pos = g_line_offsets[new_line] + col;
|
||||
g_cursor_line = new_line;
|
||||
g_cursor_col = col;
|
||||
g_cursor_pos = line_col_to_pos(new_line, g_cursor_col);
|
||||
update_cursor_pos();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -455,7 +455,8 @@ static void fit_text(char* out, int cap, const char* text, int max_w) {
|
||||
static constexpr const char* ellipsis = "...";
|
||||
int len = montauk::slen(out);
|
||||
while (len > 0) {
|
||||
out[--len] = '\0';
|
||||
len = montauk::utf8::prev_boundary(out, len);
|
||||
out[len] = '\0';
|
||||
char candidate[160];
|
||||
snprintf(candidate, sizeof(candidate), "%s%s", out, ellipsis);
|
||||
if (text_width(candidate) <= max_w) {
|
||||
@@ -1051,12 +1052,12 @@ static bool handle_key(const montauk::abi::KeyEvent& key) {
|
||||
|
||||
int old_country = g_selected_country;
|
||||
|
||||
if (key.scancode == 0x4B) g_focus_pane = 0; // Left
|
||||
else if (key.scancode == 0x4D) g_focus_pane = 1; // Right
|
||||
else if (key.scancode == 0x48 && *selected > 0) (*selected)--; // Up
|
||||
else if (key.scancode == 0x50 && *selected < count - 1) (*selected)++; // Down
|
||||
else if (key.scancode == 0x49) *selected = gui_max(0, *selected - 8); // Page Up
|
||||
else if (key.scancode == 0x51) *selected = gui_min(count - 1, *selected + 8); // Page Down
|
||||
if (montauk::nav_scancode(key) == 0x4B) g_focus_pane = 0; // Left
|
||||
else if (montauk::nav_scancode(key) == 0x4D) g_focus_pane = 1; // Right
|
||||
else if (montauk::nav_scancode(key) == 0x48 && *selected > 0) (*selected)--; // Up
|
||||
else if (montauk::nav_scancode(key) == 0x50 && *selected < count - 1) (*selected)++; // Down
|
||||
else if (montauk::nav_scancode(key) == 0x49) *selected = gui_max(0, *selected - 8); // Page Up
|
||||
else if (montauk::nav_scancode(key) == 0x51) *selected = gui_min(count - 1, *selected + 8); // Page Down
|
||||
else return false;
|
||||
|
||||
if (old_country != g_selected_country) {
|
||||
|
||||
@@ -297,7 +297,7 @@ static void copy_text_fit(char* out, int out_cap, const char* text, int max_w, i
|
||||
int len = montauk::slen(out);
|
||||
const char* ellipsis = "...";
|
||||
while (len > 0) {
|
||||
len--;
|
||||
len = montauk::utf8::prev_boundary(out, len);
|
||||
out[len] = '\0';
|
||||
char trial[160];
|
||||
montauk::strncpy(trial, out, (int)sizeof(trial));
|
||||
@@ -1235,14 +1235,14 @@ static bool handle_key(const montauk::abi::KeyEvent& key, bool& quit) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (key.scancode == 0x4B) {
|
||||
if (montauk::nav_scancode(key) == 0x4B) {
|
||||
uint64_t cur = current_time_us();
|
||||
if (cur > 5000000ull) cur -= 5000000ull;
|
||||
else cur = 0;
|
||||
seek_to_time(cur);
|
||||
return true;
|
||||
}
|
||||
if (key.scancode == 0x4D) {
|
||||
if (montauk::nav_scancode(key) == 0x4D) {
|
||||
seek_to_time(current_time_us() + 5000000ull);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -251,9 +251,9 @@ static void do_fetch() {
|
||||
extract_array_value(body, bodyLen, "\"areaName\"", area, sizeof(area));
|
||||
extract_array_value(body, bodyLen, "\"country\"", country, sizeof(country));
|
||||
|
||||
// Degree sign is U+00B0 = 0xB0 in Latin-1 (single byte, within the 256-entry glyph cache)
|
||||
snprintf(g_temp, sizeof(g_temp), "%s\xb0""C", temp_raw);
|
||||
snprintf(g_feels, sizeof(g_feels), "Feels like: %s\xb0""C", feels_raw);
|
||||
// Degree sign U+00B0 (UTF-8)
|
||||
snprintf(g_temp, sizeof(g_temp), "%s\u00B0C", temp_raw);
|
||||
snprintf(g_feels, sizeof(g_feels), "Feels like: %s\u00B0C", feels_raw);
|
||||
|
||||
if (area[0] && country[0])
|
||||
snprintf(g_location, sizeof(g_location), "%s, %s", area, country);
|
||||
|
||||
+24
-10
@@ -10,6 +10,7 @@
|
||||
|
||||
#include <montauk/syscall.h>
|
||||
#include <montauk/string.h>
|
||||
#include <montauk/utf8.h>
|
||||
#include <http/http.hpp>
|
||||
|
||||
extern "C" {
|
||||
@@ -177,12 +178,23 @@ static int extract_json_string(const char* buf, int len, const char* key,
|
||||
else if (h >= 'A' && h <= 'F') val |= h - 'A' + 10;
|
||||
}
|
||||
p += 4;
|
||||
if (val < 128) out[j++] = (char)val;
|
||||
else if (val == 0x2013 || val == 0x2014) out[j++] = '-';
|
||||
else if (val == 0x2018 || val == 0x2019) out[j++] = '\'';
|
||||
else if (val == 0x201C || val == 0x201D) out[j++] = '"';
|
||||
else if (val == 0x2026) { out[j++] = '.'; out[j++] = '.'; out[j++] = '.'; }
|
||||
else out[j++] = '?';
|
||||
// The terminal renders UTF-8; join surrogate pairs
|
||||
if (val >= 0xD800 && val <= 0xDBFF && p + 6 < len &&
|
||||
buf[p + 1] == '\\' && buf[p + 2] == 'u') {
|
||||
unsigned lo = 0;
|
||||
for (int k = 3; k <= 6; k++) {
|
||||
char h = buf[p + k];
|
||||
lo <<= 4;
|
||||
if (h >= '0' && h <= '9') lo |= h - '0';
|
||||
else if (h >= 'a' && h <= 'f') lo |= h - 'a' + 10;
|
||||
else if (h >= 'A' && h <= 'F') lo |= h - 'A' + 10;
|
||||
}
|
||||
if (lo >= 0xDC00 && lo <= 0xDFFF) {
|
||||
val = 0x10000 + ((val - 0xD800) << 10) + (lo - 0xDC00);
|
||||
p += 6;
|
||||
}
|
||||
}
|
||||
j += montauk::utf8::encode(val, out + j);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -219,9 +231,12 @@ static int wrap_paragraph(const char* text, int textLen, int cols,
|
||||
const char* lastSpace = nullptr;
|
||||
int col = 0;
|
||||
|
||||
// One terminal column per UTF-8 character
|
||||
while (p < end && col < cols) {
|
||||
if (*p == ' ') lastSpace = p;
|
||||
p++;
|
||||
int n;
|
||||
montauk::utf8::decode(p, (int)(end - p), &n);
|
||||
p += n;
|
||||
col++;
|
||||
}
|
||||
|
||||
@@ -376,8 +391,7 @@ static void render_pager(WikiLine* lines, int totalLines, int scroll,
|
||||
int maxW = cols;
|
||||
if (ln.type == LINE_SECTION && ln.level > 2)
|
||||
maxW -= (ln.level - 2) * 2;
|
||||
int printLen = ln.len;
|
||||
if (printLen > maxW) printLen = maxW;
|
||||
int printLen = montauk::utf8::offset_of(ln.text, ln.len, maxW < 0 ? 0 : maxW);
|
||||
for (int c = 0; c < printLen; c++)
|
||||
sb_putc(ln.text[c]);
|
||||
|
||||
@@ -463,7 +477,7 @@ static void run_pager(WikiLine* lines, int totalLines, const char* title,
|
||||
case 'g': scroll = 0; break;
|
||||
case 'G': scroll = maxScroll; break;
|
||||
default:
|
||||
switch (ev.scancode) {
|
||||
switch (montauk::nav_scancode(ev)) {
|
||||
case 0x48: if (scroll > 0) scroll--; break; // Up
|
||||
case 0x50: if (scroll < maxScroll) scroll++; break; // Down
|
||||
case 0x49: scroll -= contentRows; if (scroll < 0) scroll = 0; break; // PgUp
|
||||
|
||||
@@ -41,7 +41,7 @@ static bool init_buffers_and_fonts() {
|
||||
|
||||
static void handle_key_event(const montauk::abi::WinEvent& ev, bool& search_pending) {
|
||||
uint8_t ascii = ev.key.ascii;
|
||||
uint8_t scan = ev.key.scancode;
|
||||
uint8_t scan = montauk::nav_scancode(ev.key);
|
||||
|
||||
if (g_search_focused) {
|
||||
if (ascii == '\n' || ascii == '\r') {
|
||||
|
||||
@@ -10,64 +10,12 @@
|
||||
// Codepoint and UTF-8 helpers
|
||||
// ============================================================================
|
||||
|
||||
int encode_single_byte_codepoint(unsigned codepoint) {
|
||||
if (codepoint < 0x80) return (int)codepoint;
|
||||
if (codepoint >= 0xA0 && codepoint <= 0xFF) return (int)codepoint;
|
||||
|
||||
switch (codepoint) {
|
||||
case 0x20AC: return 0x80;
|
||||
case 0x201A: return 0x82;
|
||||
case 0x0192: return 0x83;
|
||||
case 0x201E: return 0x84;
|
||||
case 0x2026: return 0x85;
|
||||
case 0x2020: return 0x86;
|
||||
case 0x2021: return 0x87;
|
||||
case 0x02C6: return 0x88;
|
||||
case 0x2030: return 0x89;
|
||||
case 0x0160: return 0x8A;
|
||||
case 0x2039: return 0x8B;
|
||||
case 0x0152: return 0x8C;
|
||||
case 0x017D: return 0x8E;
|
||||
case 0x2018: return 0x91;
|
||||
case 0x2019: return 0x92;
|
||||
case 0x201C: return 0x93;
|
||||
case 0x201D: return 0x94;
|
||||
case 0x2022: return 0x95;
|
||||
case 0x2013: return 0x96;
|
||||
case 0x2014: return 0x97;
|
||||
case 0x02DC: return 0x98;
|
||||
case 0x2122: return 0x99;
|
||||
case 0x0161: return 0x9A;
|
||||
case 0x203A: return 0x9B;
|
||||
case 0x0153: return 0x9C;
|
||||
case 0x017E: return 0x9E;
|
||||
case 0x0178: return 0x9F;
|
||||
default: return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Article text is kept as UTF-8, which the renderer draws directly.
|
||||
void append_codepoint(char* out, int* j, int maxOut, unsigned codepoint) {
|
||||
if (!out || !j || *j >= maxOut - 1) return;
|
||||
|
||||
int encoded = encode_single_byte_codepoint(codepoint);
|
||||
if (encoded >= 0) {
|
||||
out[(*j)++] = (char)encoded;
|
||||
return;
|
||||
}
|
||||
|
||||
switch (codepoint) {
|
||||
case 0x00A0:
|
||||
out[(*j)++] = ' ';
|
||||
return;
|
||||
case 0x2010:
|
||||
case 0x2011:
|
||||
case 0x2212:
|
||||
out[(*j)++] = '-';
|
||||
return;
|
||||
default:
|
||||
out[(*j)++] = '?';
|
||||
return;
|
||||
}
|
||||
if (!out || !j) return;
|
||||
int n = montauk::utf8::encoded_length(codepoint);
|
||||
if (*j + n > maxOut - 1) return;
|
||||
*j += montauk::utf8::encode(codepoint, out + *j);
|
||||
}
|
||||
|
||||
void underscores_to_spaces(char* text) {
|
||||
@@ -205,14 +153,27 @@ int extract_json_string(const char* buf, int len, const char* key,
|
||||
case '/': out[j++] = '/'; break;
|
||||
case 'u': {
|
||||
if (p + 4 < len) {
|
||||
unsigned val = 0;
|
||||
for (int k = 1; k <= 4; k++) {
|
||||
char h = buf[p + k]; val <<= 4;
|
||||
if (h>='0'&&h<='9') val |= h-'0';
|
||||
else if (h>='a'&&h<='f') val |= h-'a'+10;
|
||||
else if (h>='A'&&h<='F') val |= h-'A'+10;
|
||||
}
|
||||
auto hex4 = [&](int at) {
|
||||
unsigned val = 0;
|
||||
for (int k = 0; k < 4; k++) {
|
||||
char h = buf[at + k]; val <<= 4;
|
||||
if (h>='0'&&h<='9') val |= h-'0';
|
||||
else if (h>='a'&&h<='f') val |= h-'a'+10;
|
||||
else if (h>='A'&&h<='F') val |= h-'A'+10;
|
||||
}
|
||||
return val;
|
||||
};
|
||||
unsigned val = hex4(p + 1);
|
||||
p += 4;
|
||||
// A character outside the BMP is a \uD8xx\uDCxx pair
|
||||
if (val >= 0xD800 && val <= 0xDBFF && p + 6 < len &&
|
||||
buf[p + 1] == '\\' && buf[p + 2] == 'u') {
|
||||
unsigned lo = hex4(p + 3);
|
||||
if (lo >= 0xDC00 && lo <= 0xDFFF) {
|
||||
val = 0x10000 + ((val - 0xD800) << 10) + (lo - 0xDC00);
|
||||
p += 6;
|
||||
}
|
||||
}
|
||||
append_codepoint(out, &j, maxOut, val);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <montauk/syscall.h>
|
||||
#include <montauk/string.h>
|
||||
#include <montauk/utf8.h>
|
||||
#include <montauk/heap.h>
|
||||
#include <gui/mtk.hpp>
|
||||
#include <gui/mtk/settings.hpp>
|
||||
@@ -184,7 +185,6 @@ int document_top_pad();
|
||||
// text.cpp -- encoding, HTTP/URL/JSON parsing
|
||||
// ============================================================================
|
||||
|
||||
int encode_single_byte_codepoint(unsigned codepoint);
|
||||
void append_codepoint(char* out, int* j, int maxOut, unsigned codepoint);
|
||||
void underscores_to_spaces(char* text);
|
||||
bool is_main_page_query(const char* query);
|
||||
|
||||
@@ -263,7 +263,7 @@ static int wp_char_advance_at(WordProcessorState* wp, int abs_pos, int layout_dp
|
||||
wp_font_at(wp, abs_pos, layout_dpi, &font, &gc);
|
||||
if (!font || !gc) return wp_points_to_pixels(6, layout_dpi);
|
||||
|
||||
CachedGlyph* g = font->get_glyph(gc, (unsigned char)ch);
|
||||
CachedGlyph* g = font->get_glyph(gc, decode_single_byte_codepoint((unsigned char)ch));
|
||||
return g ? g->advance : wp_points_to_pixels(6, layout_dpi);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,17 +14,46 @@ static void wp_set_status(WordProcessorState* wp, const char* msg) {
|
||||
wp->status_msg[sizeof(wp->status_msg) - 1] = '\0';
|
||||
}
|
||||
|
||||
// Documents store text as Windows-1252 (one byte per character, matching the
|
||||
// WinAnsi fonts used for PDF export); the clipboard is UTF-8. Convert both ways.
|
||||
static char* wp_cp1252_to_utf8_alloc(const char* text, int len, int* out_len) {
|
||||
char* out = (char*)montauk::malloc(len * 3 + 1);
|
||||
if (!out) return nullptr;
|
||||
int o = 0;
|
||||
for (int i = 0; i < len; i++)
|
||||
o += montauk::utf8::encode(montauk::utf8::from_cp1252((uint8_t)text[i]), out + o);
|
||||
out[o] = '\0';
|
||||
*out_len = o;
|
||||
return out;
|
||||
}
|
||||
|
||||
// Characters with no Windows-1252 form become '?'.
|
||||
static int wp_utf8_to_cp1252_inplace(char* text, int len) {
|
||||
int o = 0;
|
||||
for (int pos = 0; pos < len;) {
|
||||
int n;
|
||||
uint32_t cp = montauk::utf8::decode(text + pos, len - pos, &n);
|
||||
pos += n;
|
||||
uint8_t b = cp == 0 ? 0 : montauk::utf8::to_cp1252(cp);
|
||||
text[o++] = b ? (char)b : '?';
|
||||
}
|
||||
text[o] = '\0';
|
||||
return o;
|
||||
}
|
||||
|
||||
static bool wp_copy_selection_to_clipboard(WordProcessorState* wp) {
|
||||
int len = 0;
|
||||
char* text = wp_selection_plain_text_alloc(wp, &len);
|
||||
if (text == nullptr || len <= 0) {
|
||||
if (text) montauk::mfree(text);
|
||||
char* raw = wp_selection_plain_text_alloc(wp, &len);
|
||||
if (raw == nullptr || len <= 0) {
|
||||
if (raw) montauk::mfree(raw);
|
||||
wp_set_status(wp, "Nothing selected");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ok = gui::clipboard_set_text(text, len);
|
||||
montauk::mfree(text);
|
||||
char* text = wp_cp1252_to_utf8_alloc(raw, len, &len);
|
||||
montauk::mfree(raw);
|
||||
bool ok = text && gui::clipboard_set_text(text, len);
|
||||
if (text) montauk::mfree(text);
|
||||
if (!ok) {
|
||||
wp_set_status(wp, "Copy failed");
|
||||
return false;
|
||||
@@ -52,6 +81,7 @@ static bool wp_paste_from_clipboard(WordProcessorState* wp) {
|
||||
wp_set_status(wp, "Clipboard is empty");
|
||||
return false;
|
||||
}
|
||||
len = wp_utf8_to_cp1252_inplace(text, len);
|
||||
|
||||
bool ok = wp_replace_selection_with_text(wp, text, len);
|
||||
montauk::mfree(text);
|
||||
@@ -263,7 +293,7 @@ static int wp_hit_test_text(WordProcessorState* wp, int local_x, int local_y, in
|
||||
for (int ci = 0; ci < to_check; ci++) {
|
||||
char ch = r->text[ro + ci];
|
||||
CachedGlyph* g = (ch >= 32 || ch < 0) && ch != '\n'
|
||||
? font->get_glyph(gc, (unsigned char)ch) : nullptr;
|
||||
? font->get_glyph(gc, decode_single_byte_codepoint((unsigned char)ch)) : nullptr;
|
||||
int char_w = g ? g->advance : 0;
|
||||
|
||||
if (x + char_w / 2 > click_x) return best_abs;
|
||||
@@ -611,32 +641,18 @@ void wp_handle_key(const montauk::abi::KeyEvent& key) {
|
||||
return;
|
||||
}
|
||||
if (key.ascii == '\b' || key.scancode == 0x0E) {
|
||||
if (wp->pathbar_cursor > 0) {
|
||||
for (int i = wp->pathbar_cursor - 1; i < wp->pathbar_len - 1; i++)
|
||||
wp->pathbar_text[i] = wp->pathbar_text[i + 1];
|
||||
wp->pathbar_len--;
|
||||
wp->pathbar_cursor--;
|
||||
wp->pathbar_text[wp->pathbar_len] = '\0';
|
||||
}
|
||||
montauk::utf8::erase_before(wp->pathbar_text, &wp->pathbar_len, &wp->pathbar_cursor);
|
||||
return;
|
||||
}
|
||||
if (key.scancode == 0x4B) {
|
||||
if (wp->pathbar_cursor > 0) wp->pathbar_cursor--;
|
||||
if (montauk::nav_scancode(key) == 0x4B) {
|
||||
wp->pathbar_cursor = montauk::utf8::prev_boundary(wp->pathbar_text, wp->pathbar_cursor);
|
||||
return;
|
||||
}
|
||||
if (key.scancode == 0x4D) {
|
||||
if (wp->pathbar_cursor < wp->pathbar_len) wp->pathbar_cursor++;
|
||||
if (montauk::nav_scancode(key) == 0x4D) {
|
||||
wp->pathbar_cursor = montauk::utf8::next_boundary(wp->pathbar_text, wp->pathbar_len, wp->pathbar_cursor);
|
||||
return;
|
||||
}
|
||||
if ((unsigned char)key.ascii >= 32
|
||||
&& (unsigned char)key.ascii != 127 && wp->pathbar_len < 254) {
|
||||
for (int i = wp->pathbar_len; i > wp->pathbar_cursor; i--)
|
||||
wp->pathbar_text[i] = wp->pathbar_text[i - 1];
|
||||
wp->pathbar_text[wp->pathbar_cursor] = key.ascii;
|
||||
wp->pathbar_cursor++;
|
||||
wp->pathbar_len++;
|
||||
wp->pathbar_text[wp->pathbar_len] = '\0';
|
||||
}
|
||||
montauk::utf8::insert_key(wp->pathbar_text, &wp->pathbar_len, 255, &wp->pathbar_cursor, key);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -736,22 +752,22 @@ void wp_handle_key(const montauk::abi::KeyEvent& key) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (key.ctrl && key.alt && key.scancode == 0x48) {
|
||||
if (key.ctrl && key.alt && montauk::nav_scancode(key) == 0x48) {
|
||||
wp_adjust_paragraph_spacing_before(wp, -WP_SPACE_STEP);
|
||||
wp_history_checkpoint(wp);
|
||||
return;
|
||||
}
|
||||
if (key.ctrl && key.alt && key.scancode == 0x50) {
|
||||
if (key.ctrl && key.alt && montauk::nav_scancode(key) == 0x50) {
|
||||
wp_adjust_paragraph_spacing_before(wp, WP_SPACE_STEP);
|
||||
wp_history_checkpoint(wp);
|
||||
return;
|
||||
}
|
||||
if (key.ctrl && key.shift && key.scancode == 0x48) {
|
||||
if (key.ctrl && key.shift && montauk::nav_scancode(key) == 0x48) {
|
||||
wp_adjust_paragraph_spacing_after(wp, -WP_SPACE_STEP);
|
||||
wp_history_checkpoint(wp);
|
||||
return;
|
||||
}
|
||||
if (key.ctrl && key.shift && key.scancode == 0x50) {
|
||||
if (key.ctrl && key.shift && montauk::nav_scancode(key) == 0x50) {
|
||||
wp_adjust_paragraph_spacing_after(wp, WP_SPACE_STEP);
|
||||
wp_history_checkpoint(wp);
|
||||
return;
|
||||
@@ -783,21 +799,21 @@ void wp_handle_key(const montauk::abi::KeyEvent& key) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (key.scancode == 0x48) {
|
||||
if (montauk::nav_scancode(key) == 0x48) {
|
||||
if (key.shift) wp_start_selection(wp);
|
||||
else wp_clear_selection(wp);
|
||||
wp_cursor_up(wp);
|
||||
if (key.shift) wp_update_selection_to_cursor(wp);
|
||||
return;
|
||||
}
|
||||
if (key.scancode == 0x50) {
|
||||
if (montauk::nav_scancode(key) == 0x50) {
|
||||
if (key.shift) wp_start_selection(wp);
|
||||
else wp_clear_selection(wp);
|
||||
wp_cursor_down(wp);
|
||||
if (key.shift) wp_update_selection_to_cursor(wp);
|
||||
return;
|
||||
}
|
||||
if (key.scancode == 0x4B) {
|
||||
if (montauk::nav_scancode(key) == 0x4B) {
|
||||
if (key.shift) wp_start_selection(wp);
|
||||
else if (wp->has_selection) {
|
||||
int s, e;
|
||||
@@ -810,7 +826,7 @@ void wp_handle_key(const montauk::abi::KeyEvent& key) {
|
||||
if (key.shift) wp_update_selection_to_cursor(wp);
|
||||
return;
|
||||
}
|
||||
if (key.scancode == 0x4D) {
|
||||
if (montauk::nav_scancode(key) == 0x4D) {
|
||||
if (key.shift) wp_start_selection(wp);
|
||||
else if (wp->has_selection) {
|
||||
int s, e;
|
||||
@@ -824,7 +840,7 @@ void wp_handle_key(const montauk::abi::KeyEvent& key) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (key.scancode == 0x47) {
|
||||
if (montauk::nav_scancode(key) == 0x47) {
|
||||
if (key.shift) wp_start_selection(wp);
|
||||
else wp_clear_selection(wp);
|
||||
int abs = wp_abs_pos(wp, wp->cursor_run, wp->cursor_offset);
|
||||
@@ -834,7 +850,7 @@ void wp_handle_key(const montauk::abi::KeyEvent& key) {
|
||||
if (key.shift) wp_update_selection_to_cursor(wp);
|
||||
return;
|
||||
}
|
||||
if (key.scancode == 0x4F) {
|
||||
if (montauk::nav_scancode(key) == 0x4F) {
|
||||
if (key.shift) wp_start_selection(wp);
|
||||
else wp_clear_selection(wp);
|
||||
int abs = wp_abs_pos(wp, wp->cursor_run, wp->cursor_offset);
|
||||
@@ -858,7 +874,7 @@ void wp_handle_key(const montauk::abi::KeyEvent& key) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (key.scancode == 0x53) {
|
||||
if (montauk::nav_scancode(key) == 0x53) {
|
||||
if (wp->has_selection) wp_delete_selection(wp);
|
||||
else wp_delete_char(wp);
|
||||
wp_history_checkpoint(wp);
|
||||
|
||||
@@ -217,7 +217,7 @@ static void wp_draw_print_list_marker(Canvas& c, WordProcessorState* wp, WrapLin
|
||||
if (!font) font = g_ui_font;
|
||||
int th = text_height(font, font_px);
|
||||
int top_y = py + (wl->height - th) / 2;
|
||||
char bullet[2] = { '\x95', '\0' };
|
||||
const char* bullet = "\u2022";
|
||||
draw_text(c, font, bullet_x, top_y, bullet, colors::BLACK, font_px);
|
||||
return;
|
||||
}
|
||||
@@ -293,7 +293,8 @@ static bool wp_encode_print_page(WordProcessorState* wp,
|
||||
|
||||
if (ch != '\n' && (ch >= 32 || ch < 0)) {
|
||||
int adv = font->draw_char_to_buffer(
|
||||
c.pixels, c.w, c.h, x, baseline, (unsigned char)ch, colors::BLACK, gc);
|
||||
c.pixels, c.w, c.h, x, baseline,
|
||||
decode_single_byte_codepoint((unsigned char)ch), colors::BLACK, gc);
|
||||
x += adv;
|
||||
}
|
||||
char_idx++;
|
||||
|
||||
@@ -111,7 +111,8 @@ static void wp_fit_ui_text(const char* src, char* out, int out_len, int max_w) {
|
||||
if (text_width(g_ui_font, out, fonts::UI_SIZE) <= max_w) return;
|
||||
|
||||
int slen = montauk::slen(src);
|
||||
for (int keep = slen; keep > 1; keep--) {
|
||||
for (int keep = slen; keep > 1;
|
||||
keep = slen - montauk::utf8::next_boundary(src, slen, slen - keep)) {
|
||||
char candidate[256];
|
||||
candidate[0] = '.';
|
||||
candidate[1] = '.';
|
||||
@@ -138,7 +139,8 @@ static void wp_fit_ui_text_end(const char* src, char* out, int out_len, int max_
|
||||
out[out_len - 1] = '\0';
|
||||
if (text_width(g_ui_font, out, fonts::UI_SIZE) <= max_w) return;
|
||||
|
||||
for (int keep = montauk::slen(src); keep > 0; keep--) {
|
||||
for (int keep = montauk::slen(src); keep > 0;
|
||||
keep = montauk::utf8::prev_boundary(src, keep)) {
|
||||
char candidate[256];
|
||||
if (keep > (int)sizeof(candidate) - 3) continue;
|
||||
montauk::memcpy(candidate, src, keep);
|
||||
@@ -225,7 +227,7 @@ static void wp_draw_list_marker(Canvas& c, WordProcessorState* wp, WrapLine* wl,
|
||||
if (!font) font = g_ui_font;
|
||||
int th = text_height(font, bullet_size);
|
||||
int top_y = py + (wl->height - th) / 2;
|
||||
char bullet[2] = { '\x95', '\0' };
|
||||
const char* bullet = "\u2022";
|
||||
draw_text(c, font, bullet_x, top_y, bullet, colors::TEXT_COLOR, bullet_size);
|
||||
return;
|
||||
}
|
||||
@@ -346,7 +348,7 @@ void wp_render() {
|
||||
Color special_bg = wp->special_char_flyout_open ? btn_active : btn_bg;
|
||||
c.fill_rounded_rect(WP_BTN_SECTION_X, 6, 24, 24, 3, special_bg);
|
||||
{
|
||||
char section[2] = { (char)0xA7, '\0' };
|
||||
const char* section = "\u00A7";
|
||||
TrueTypeFont* font = wp_get_font(wp_default_font_id(), 0);
|
||||
draw_text(c, font ? font : g_ui_font, WP_BTN_SECTION_X + 6, 8, section, colors::TEXT_COLOR, fonts::UI_SIZE);
|
||||
}
|
||||
@@ -355,7 +357,7 @@ void wp_render() {
|
||||
|
||||
Color pageview_bg = wp->page_view_mode ? btn_active : btn_bg;
|
||||
c.fill_rounded_rect(WP_BTN_PAGEVIEW_X, 6, 24, 24, 3, pageview_bg);
|
||||
wp_draw_ui_icon_button(c, WP_BTN_PAGEVIEW_X, 6, 24, 24, g_icon_page_view, "\xA7",
|
||||
wp_draw_ui_icon_button(c, WP_BTN_PAGEVIEW_X, 6, 24, 24, g_icon_page_view, "\u00A7",
|
||||
pageview_bg, colors::TEXT_COLOR);
|
||||
|
||||
c.hline(0, WP_TOOLBAR_H - 1, c.w, colors::BORDER);
|
||||
@@ -506,7 +508,7 @@ void wp_render() {
|
||||
|
||||
int char_adv = 0;
|
||||
if (ch != '\n' && (ch >= 32 || ch < 0)) {
|
||||
CachedGlyph* g = font->get_glyph(gc, (unsigned char)ch);
|
||||
CachedGlyph* g = font->get_glyph(gc, decode_single_byte_codepoint((unsigned char)ch));
|
||||
char_adv = g ? g->advance : 8;
|
||||
}
|
||||
|
||||
@@ -558,7 +560,8 @@ void wp_render() {
|
||||
Color text_col = (wp->has_selection && abs_ch >= sel_s && abs_ch < sel_e)
|
||||
? Color::from_rgb(0x10, 0x10, 0x10) : colors::TEXT_COLOR;
|
||||
int adv = font->draw_char_to_buffer(
|
||||
c.pixels, c.w, c.h, x, baseline, (unsigned char)ch, text_col, gc);
|
||||
c.pixels, c.w, c.h, x, baseline,
|
||||
decode_single_byte_codepoint((unsigned char)ch), text_col, gc);
|
||||
x += adv;
|
||||
} else {
|
||||
x += char_adv;
|
||||
@@ -717,7 +720,9 @@ void wp_render() {
|
||||
c.rect(dx, dy, dw, dh, colors::BORDER);
|
||||
for (int i = 0; i < WP_SPECIAL_CHAR_OPTION_COUNT; i++) {
|
||||
int iy = dy + 2 + i * WP_SPECIAL_CHAR_ROW_H;
|
||||
char glyph[2] = { (char)WP_SPECIAL_CHAR_OPTIONS[i].code, '\0' };
|
||||
char glyph[5];
|
||||
glyph[montauk::utf8::encode(montauk::utf8::from_cp1252(
|
||||
WP_SPECIAL_CHAR_OPTIONS[i].code), glyph)] = '\0';
|
||||
c.fill_rect(dx + 2, iy, dw - 4, WP_SPECIAL_CHAR_ROW_H - 2, colors::MENU_BG);
|
||||
draw_text(c, glyph_font ? glyph_font : g_ui_font,
|
||||
dx + 8, iy + (WP_SPECIAL_CHAR_ROW_H - sfh) / 2,
|
||||
|
||||
@@ -193,6 +193,10 @@ struct WPFontTable {
|
||||
bool loaded;
|
||||
};
|
||||
|
||||
// Document text is Windows-1252, one byte per character, unlike the rest of
|
||||
// MontaukOS (UTF-8). It matches the MWP1 file format and the WinAnsi-encoded
|
||||
// fonts of PDF export. Convert at the edges: decode_single_byte_codepoint()
|
||||
// for glyphs, and UTF-8 <-> 1252 for the clipboard (input.cpp).
|
||||
struct StyledRun {
|
||||
char* text;
|
||||
int len;
|
||||
|
||||
Reference in new issue
Block a user