Files
five/hbrt/debugkey.go
CharlesKWON f4ed42556b checkpoint: season-wide bug fix campaign + infra
Cumulative season's silent-bug hunting (~62 fixes) across the FiveSql2
SQL engine, the Five compiler/runtime, and the hbrdd RDD layer. Saved
as a single checkpoint before refactoring the parser to delegate xBase
command translation to the preprocessor.

Highlights:

FiveSql2 engine (_FiveSql2/src/)
- prefix-glob index attach -> explicit convention (<table>_pk.ntx,
  <table>_uq.ntx, <table>.cdx) — fixes silent multi-row INSERT row-drop
- DROP/CREATE TABLE FErase chain extended (.cdx, .fsc, .fsv, .dbt, .fpt)
- COUNT(DISTINCT col) parsed + aggregated via hSeen hash
- UNION column-count mismatch returns SQL_ERR_GRAMMAR (was silent)
- DISTINCT + ORDER BY hidden-col leak fixed (trim before DISTINCT)
- Derived table FROM (SELECT...) + JOIN right-side derived
- Self-FK CASCADE depth 2+ via SqlGetSingleColPK pre-collect
- LAG/LEAD default arg uses SqlEvalRowExpr (handles -N const exprs)
- DATE literal round-trip validation (Feb 29 non-leap rejected)
- CREATE OR REPLACE VIEW; CREATE VIEW errors on already-exists
- AlterTable type dispatcher comma-wrapped (1-char type "A" no longer
  matches CHARACTER)

Compiler / runtime
- gengo: HB_ -> FV_ prefix on emitted Go function names (Five identity)
- gengo split: emit_block.go, emit_stmt.go, folding.go extracted
- parser/stmtreg.go nudges
- hbrt: debug TUI/CLI restructure (debugcmd, debugkey, termios_*),
  windows debug stubs collapsed
- thread/vm/value/class/pcinterp tightening from panic traces

RDD layer (hbrdd/)
- dbf: null bitmap support (null.go + null_test.go), mmap split
  (mmap_posix.go / mmap_windows.go), byte-level numeric parse
- ntx/cdx: windows mmap parity
- workarea + mem RDD: cross-area state-bleed fixes

RTL (hbrtl/)
- errorlog rewrite with platform-specific FD (errorlog_fd_unix /
  errorlog_fd_other)
- sqlscan, sqlhelpers, indexrtl, datetime extensions

Gates green at checkpoint:
- go test ./...        : PASS
- FiveSql2 SQL:1999    : 43/43
- Harbour compat       : 56/56

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-30 09:26:25 +09:00

61 lines
1.4 KiB
Go

// Copyright (c) 2026 Charles KWON OhJun (charleskwonohjun@gmail.com)
// All rights reserved.
// Cross-platform ANSI key-sequence decoder. Each termios_<os>.go
// collects bytes from the terminal in raw mode, then hands them here
// for classification. The decoder output (ASCII or 0xE0-0xFC pseudo-
// code) is the same on every OS so debugtui.go can stay platform-
// neutral.
package hbrt
// decodeDebugKey translates a raw byte buffer captured in TTY/console
// raw mode into a single logical key. Returns 0 when nothing was read.
// Pseudo-codes 0xE0-0xE3 cover arrow keys; 0xF5-0xFC cover F5-F12.
func decodeDebugKey(buf []byte, n int) int {
if n == 0 {
return 0
}
if buf[0] != 0x1B {
return int(buf[0])
}
if n == 1 {
return 0x1B // bare ESC
}
if n >= 3 && buf[1] == '[' {
// Arrow keys: ESC [ A/B/C/D
switch buf[2] {
case 'A':
return 0xE0 // Up
case 'B':
return 0xE1 // Down
case 'C':
return 0xE2 // Right
case 'D':
return 0xE3 // Left
}
// F5-F12: ESC [ 1 5 ~ through ESC [ 2 4 ~
if n >= 4 && buf[n-1] == '~' {
switch string(buf[2 : n-1]) {
case "15":
return 0xF5
case "17":
return 0xF6
case "18":
return 0xF7
case "19":
return 0xF8
case "20":
return 0xF9
case "21":
return 0xFA
case "23":
return 0xFB
case "24":
return 0xFC
}
}
}
return 0 // ignore unknown ESC sequences — never quit on them
}