diff options
| author | eunhhu <[email protected]> | 2026-09-30 16:33:21 +0100 |
|---|---|---|
| committer | eunhhu <[email protected]> | 2026-09-30 16:33:27 +0100 |
| commit | 49e0df31289956aa3fd627f851f8fb2b3e08aa13 (patch) | |
| tree | 44d06de75d04078f82f74cf883551c1c780ea5b7 | |
| parent | 72ecae6b6eb1365e722bd6d45acae8a5ccb74b23 (diff) | |
| download | vega-49e0df31289956aa3fd627f851f8fb2b3e08aa13.tar.gz vega-49e0df31289956aa3fd627f851f8fb2b3e08aa13.zip | |
Show an i64 with every digit on every surface
vega_text reads an i64 view or column as an integer and prints all of
its digits, so an ID past 2^53 shows as it is on the CLI, the TUI,
speech and the web surface, where a number would round.
| -rw-r--r-- | docs/design/001-first-component.md | 4 | ||||
| -rw-r--r-- | surfaces/screen.c | 7 | ||||
| -rw-r--r-- | surfaces/vega.h | 5 | ||||
| -rw-r--r-- | tests/check.py | 45 |
4 files changed, 57 insertions, 4 deletions
diff --git a/docs/design/001-first-component.md b/docs/design/001-first-component.md index 9e1ef80..387e7ad 100644 --- a/docs/design/001-first-component.md +++ b/docs/design/001-first-component.md @@ -62,8 +62,8 @@ Tab이 키 모드로 바꾸면 글자·숫자·Space가 `KeyA`·`Digit0`·`Space **값이 보이는 방식.** 값은 제 자리 안에서 제 글자로 보인다. 화면에 작용할 글자만 예외다(Pure `docs/design/015-boundary-meaning.md`가 정한 값의 뜻의 화면 쪽이다). -- 수는 Pure의 가장 짧은 글자로, bool은 `true`나 `false`로 보인다. 보간(`"{done}"`)과 같은 글자다. 다르게 보이고 - 싶은 앱은 조건식으로 글을 고른다(`if t.done { "완료" } else { "" }`). +- 수는 Pure의 가장 짧은 글자로, bool은 `true`나 `false`로, i64는 모든 자릿수로(2^53을 넘어도) 보인다. 보간(`"{done}"`)과 + 같은 글자다. 다르게 보이고 싶은 앱은 조건식으로 글을 고른다(`if t.done { "완료" } else { "" }`). - 제어 문자(C0)와 DEL은 제어 그림(␀…␟, ␡)으로, C1 제어는 �로, 줄과 문단의 구분자(U+2028, U+2029)는 로 보인다 (`vega_visible`). CLI, TUI, 픽셀, 웹 페이지가 모두 같다. 값은 제 줄을 끊지 못한다. diff --git a/surfaces/screen.c b/surfaces/screen.c index 51181a5..ed06c9d 100644 --- a/surfaces/screen.c +++ b/surfaces/screen.c @@ -1,6 +1,7 @@ #define _POSIX_C_SOURCE 200809L #include "vega.h" #include "module-text.h" +#include <inttypes.h> #include <math.h> #include <string.h> #include <time.h> @@ -163,6 +164,12 @@ bool vega_text(PureApp *app, uint32_t view, size_t row, char out[VEGA_TEXT], siz ++evaluations; *length = 0; out[0] = 0; + if (m->view_type[view] == PURE_VIEW_I64) { /* every digit */ + int64_t value; + if (!(column ? pure_app_cell_i64(app, view, row, &value) : pure_app_view_i64(app, view, &value))) return false; + *length = (size_t)snprintf(out, VEGA_TEXT, "%" PRId64, value); + return true; + } if (m->view_type[view] == PURE_VIEW_NUM || m->view_type[view] == PURE_VIEW_BOOL) { double value; if (!(column ? pure_app_cell(app, view, row, &value) : pure_app_view(app, view, &value))) return false; diff --git a/surfaces/vega.h b/surfaces/vega.h index c172d31..a800835 100644 --- a/surfaces/vega.h +++ b/surfaces/vega.h @@ -59,8 +59,9 @@ long vega_timers_run(VegaTimers *, PureApp *, double clock, bool *ticked); * returns how many there were. */ unsigned vega_check(const PureModule *, void (*report)(void *, const char *name, const char *message), void *context); -/* A view (row ignored) or a column at a row as text; numbers in Pure's - * shortest form. false when it has no value (for example a missing item). */ +/* A view (row ignored) or a column at a row as text: numbers in Pure's + * shortest form, bools as true or false, i64s with every digit. false when + * it has no value (for example a missing item). */ bool vega_text(PureApp *, uint32_t view, size_t row, char out[VEGA_TEXT], size_t *length); bool vega_number(PureApp *, uint32_t view, size_t row, double *out); size_t vega_rows(PureApp *, const VegaPart *); diff --git a/tests/check.py b/tests/check.py index 5b37646..b9f9572 100644 --- a/tests/check.py +++ b/tests/check.py @@ -1945,6 +1945,50 @@ def bools(vega, aup, work): return len(out) + len(dump) + len(said) +I64_APP = """use vega +record Row { + id: i64 +} +state rows: list of Row by id +state next: i64 = 9007199254740992 +input add = key Space +on add.down { + rows.add(Row { id: next }) + next = next + 1 +} +view last = next +view ids = each r in rows { + id = r.id +} +""" + + +def integers(vega, aup, work): + """An i64 shows every digit on every surface (the CLI, the TUI's cells, + speech and the web surface's JSON): past 2^53 too, where a number would + round.""" + source, module = work / 'integers.aup', work / 'integers.pmod' + source.write_text(I64_APP) + built = run(aup, 'build', source, '-o', module, env=dict(os.environ, AUP_PATH=str(ROOT / 'lib'))) + assert built.returncode == 0, built.stderr + script = 'key Space\nkey Space\nshow\n' + out = run(vega, 'cli', module, stdin=script).stdout.splitlines() + assert out == ['last: 9007199254740994', 'ids (2)', ' id', '> 9007199254740992', ' 9007199254740993'], out + dump = run(vega, 'tui', module, '--dump', '30x8', stdin=script).stdout.splitlines() + assert all(line in dump for line in ['|last 9007199254740994\tmuted', '>> 9007199254740992', '| 9007199254740993']), dump + said = run(vega, 'say', module, stdin=script).stdout.splitlines() + assert all(line in said for line in ['last: 9007199254740994.', 'Item 1 of 2: id 9007199254740992.']), said + surface = WebSurface(vega, module) + try: + for _ in range(2): surface.call('POST', '/key', 'Space') + screen = json.loads(surface.call('GET', '/screen?rows=5')[1]) + finally: + surface.stop() + assert screen['fields'] == [{'name': 'last', 'text': '9007199254740994'}], screen['fields'] + assert [item['cells'] for item in screen['parts'][0]['items']] == [['9007199254740992'], ['9007199254740993']], screen + return len(out) + len(dump) + len(said) + + def main(): parser = argparse.ArgumentParser() parser.add_argument('--vega', type=Path, required=True) @@ -1976,6 +2020,7 @@ def main(): report['hot_swap_lines'] = hot_swap(vega, aup, work) report['split_list_lines'] = split(vega, modules['today'], work, range(args.seeds)) report['bool_lines'] = bools(vega, aup, work) + report['i64_lines'] = integers(vega, aup, work) report['painted_frames'], report['first_paint_bytes'], report['later_paint_bytes'] = \ painting(vega, modules['todo'], range(args.seeds), [(40, 12), (24, 9), (80, 30)]) report['web_screens'] = web(vega, modules['todo'], work, range(args.seeds)) |
