Skip to content

Commit 0b5ba05

Browse files
committed
Paragraph stylehints use _par CSS classes, rather than a div selector
Some other small fixes too
1 parent 5c5dbab commit 0b5ba05

File tree

10 files changed

+172
-49
lines changed

10 files changed

+172
-49
lines changed

src/common/protocol.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,14 +468,14 @@ export interface WindowUpdate {
468468
/** CSS Properties
469469
*
470470
* CSS property names and values, with a few special property:
471-
* - `monospace`: sets a run to be monospaced, but adding class `monospace` to the `span`. Should only be used for `span`s, may misbehave if set on a `div`.
471+
* - `monospace`: sets a run to be monospaced, by adding the class `monospace` to the `span`. Should only be used for `span`s, may misbehave if set on a `div`.
472472
* - `reverse`: enables reverse mode. If you provide colours then do not pre-reverse them.
473473
* Ex: `background-color: #FFF, color: #000, reverse: 1` will be displayed as white text on a black background
474474
*/
475475
export type CSSProperties = Record<string, string | number>
476476

477477
/** CSS styles
478-
* Keys will usually be for Glk styles, ex: `div.Style_header` or `span.Style_user1`
478+
* Keys will usually be for Glk styles, ex: `.Style_header_par` or `.Style_user1`
479479
* But they can be anything else. Use a blank string to target the window itself.
480480
*/
481481
export type WindowStyles = Record<string, CSSProperties>

src/glkapi/glkapi.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
GlkApi
44
======
55
6-
Copyright (c) 2023 Dannii Willis
6+
Copyright (c) 2024 Dannii Willis
77
MIT licenced
88
https://github.com/curiousdannii/asyncglk
99
@@ -25,7 +25,7 @@ import {evtype_Arrange, evtype_CharInput, evtype_Hyperlink, evtype_LineInput, ev
2525
import {FileRef} from './filerefs.js'
2626
import * as Interface from './interface.js'
2727
import {DidNotReturn, GlkArray, GlkApiOptions, GlkByteArray, GlkSchannel, GlkWordArray, RefBoxArg, RefStructArg, RefStructValue} from './interface.js'
28-
import {CSS_STYLE_PROPERTIES, FILE_MODES, FILE_TYPES, IMAGE_ALIGNMENTS, KEY_NAMES_TO_CODES, STYLE_NAMES, TERMINATOR_KEYS, TERMINATOR_KEYS_TO_CODES} from './lib_constants.js'
28+
import {CSS_STYLE_PROPERTIES, FILE_MODES, FILE_TYPES, IMAGE_ALIGNMENTS, KEY_NAMES_TO_CODES, MAX_LATIN1, QUESTION_MARK, STYLE_NAMES, TERMINATOR_KEYS, TERMINATOR_KEYS_TO_CODES} from './lib_constants.js'
2929
import {ArrayBackedStream, FileStream, NullStream, Stream} from './streams.js'
3030
import {BlankWindow, BufferWindow, GraphicsWindow, GridWindow, PairWindow, TextWindow, Window, WindowBox} from './windows.js'
3131

@@ -525,7 +525,7 @@ export class AsyncGlk implements Interface.GlkApi {
525525

526526
switch (sel) {
527527
case gestalt_Version:
528-
return 0x00000704
528+
return 0x00000705
529529
case gestalt_CharInput:
530530
// Known special keys can be returned
531531
if (val <= keycode_Left && val >= keycode_Func12) {
@@ -552,6 +552,7 @@ export class AsyncGlk implements Interface.GlkApi {
552552
case gestalt_LineTerminatorKey:
553553
return +(val === keycode_Escape || (val >= keycode_Func12 && val <= keycode_Func1))
554554
// These are dependent on what GlkOte tells us it supports
555+
// TODO: check all of these
555556
case gestalt_DrawImage:
556557
return +((val === wintype_Graphics || val === wintype_TextBuffer) && this.support.includes('graphics'))
557558
case gestalt_GarglkText:
@@ -918,14 +919,16 @@ export class AsyncGlk implements Interface.GlkApi {
918919
}
919920
}
920921

921-
glk_set_terminators_line_event(win: Window, keycodes: GlkArray) {
922+
glk_set_terminators_line_event(win: Window, keycodes: GlkArray | null) {
922923
if (!win) {
923924
throw new Error('Invalid Window')
924925
}
925926
const terminators: TerminatorCode[] = []
926-
for (const code of keycodes) {
927-
if (TERMINATOR_KEYS[code]) {
928-
terminators.push(TERMINATOR_KEYS[code])
927+
if (keycodes) {
928+
for (const code of keycodes) {
929+
if (TERMINATOR_KEYS[code]) {
930+
terminators.push(TERMINATOR_KEYS[code])
931+
}
929932
}
930933
}
931934
if (terminators.length) {
@@ -1023,7 +1026,7 @@ export class AsyncGlk implements Interface.GlkApi {
10231026
}
10241027

10251028
glk_stylehint_clear(wintype: number, style: number, hint: number) {
1026-
const selector = `${hint <= stylehint_Justification ? 'div' : 'span'}.Style_${STYLE_NAMES[style]}`
1029+
const selector = `.Style_${STYLE_NAMES[style]}${hint <= stylehint_Justification ? '_par' : ''}`
10271030
function remove_style(styles: WindowStyles) {
10281031
if (styles[selector]) {
10291032
delete styles[selector][CSS_STYLE_PROPERTIES[hint]]
@@ -1056,7 +1059,7 @@ export class AsyncGlk implements Interface.GlkApi {
10561059
}
10571060

10581061
const stylehints = wintype === wintype_TextBuffer ? this.stylehints.buffer : this.stylehints.grid
1059-
const selector = `${hint <= stylehint_Justification ? 'div' : 'span'}.Style_${STYLE_NAMES[style]}`
1062+
const selector = `.Style_${STYLE_NAMES[style]}${hint <= stylehint_Justification ? '_par' : ''}`
10601063
const justifications = ['left', 'justify', 'center', 'right']
10611064
const weights = ['lighter', 'normal', 'bold']
10621065
let stylevalue: string | number | undefined
@@ -1573,8 +1576,8 @@ export class AsyncGlk implements Interface.GlkApi {
15731576
type = evtype_CharInput
15741577
if (ev.value.length === 1) {
15751578
val1 = ev.value.codePointAt(0)!
1576-
if (!(win as TextWindow).uni_input) {
1577-
val1 = val1 & 0xFF
1579+
if (!(win as TextWindow).uni_input && val1 > MAX_LATIN1) {
1580+
val1 = QUESTION_MARK
15781581
}
15791582
}
15801583
else {
@@ -1585,6 +1588,7 @@ export class AsyncGlk implements Interface.GlkApi {
15851588
if (!win?.input.hyperlink) {
15861589
return
15871590
}
1591+
delete win.input.hyperlink
15881592
type = evtype_Hyperlink
15891593
val1 = ev.value
15901594
break
@@ -1600,6 +1604,7 @@ export class AsyncGlk implements Interface.GlkApi {
16001604
if (!win?.input.mouse) {
16011605
return
16021606
}
1607+
delete win.input.mouse
16031608
type = evtype_MouseInput
16041609
val1 = ev.x
16051610
val2 = ev.y

src/glkote/web/styles.css

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,49 @@
33
GlkOte Glk styles
44
====================
55
6-
Copyright (c) 2022 Dannii Willis
6+
Copyright (c) 2024 Dannii Willis
77
MIT licenced
88
https://github.com/curiousdannii/asyncglk
99
1010
*/
1111

12-
span.Style_normal {}
12+
.Style_normal {}
1313

14-
span.Style_emphasized {
14+
.Style_emphasized {
1515
font-style: italic;
1616
}
1717

18-
.BufferWindow span.Style_preformatted {
18+
.BufferWindow .Style_preformatted {
1919
display: inline-block;
2020
font-family: var(--glkote-mono-family);
2121
padding: 0;
2222
}
2323

24-
span.Style_header {
24+
.Style_header {
2525
font-weight: bold;
2626
}
2727

28-
.BufferWindow span.Style_header {
28+
.BufferWindow .Style_header {
2929
font-size: 1.13333em; /* 17px when using the default 15px buffer window text size */
3030
}
3131

32-
span.Style_subheader {
32+
.Style_subheader {
3333
font-weight: bold;
3434
}
3535

36-
span.Style_alert {
36+
.Style_alert {
3737
font-weight: bold;
3838
}
3939

40-
span.Style_note {
40+
.Style_note {
4141
font-style: italic;
4242
}
4343

44-
div.Style_blockquote {
44+
.Style_blockquote_par {
4545
margin: 0 2em;
4646
}
4747

48-
span.Style_input {
48+
.Style_input {
4949
font-weight: bold;
5050
color: var(--glkote-input-fg);
5151
}

src/glkote/web/windows.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ https://github.com/curiousdannii/asyncglk
5959
padding: 0;
6060
}
6161

62-
.BufferLine span.Style_preformatted.proportional {
62+
.BufferLine .Style_preformatted.proportional {
6363
display: inline;
6464
font-family: var(--glkote-prop-family);
6565
padding: var(--glkote-prop-half-leading) 0;

src/glkote/web/windows.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,13 @@ abstract class TextualWindow extends WindowBase {
206206

207207
// Copy styles for the <input>
208208
// May not play nice with reverse
209-
if (styles[`${windowid} span.Style_input`]) {
210-
styles[`${windowid} .LineInput`] = styles[`${windowid} span.Style_input`]
209+
if (styles[`${windowid} .Style_input`]) {
210+
styles[`${windowid} .LineInput`] = styles[`${windowid} .Style_input`]
211211
}
212212
}
213213

214214
// Set window background colour, for normal and reverse mode
215-
const normal_styles = styles[`${windowid} span.Style_normal`]
215+
const normal_styles = styles[`${windowid} .Style_normal`]
216216
const bg = this.bg || normal_styles?.['background-color']
217217
const fg = this.fg || normal_styles?.color
218218
if (bg || fg) {
@@ -241,7 +241,7 @@ abstract class TextualWindow extends WindowBase {
241241
create_text_run(run: protocol.TextRun, split_words?: boolean): JQuery<HTMLElement> {
242242
const run_style = run.style
243243
// Is this run or this style monospace mode?
244-
const monospace_val = run.css_styles?.monospace ?? this.styles?.[`span.Style_${run_style}`]?.monospace
244+
const monospace_val = run.css_styles?.monospace ?? this.styles?.[`.Style_${run_style}`]?.monospace
245245
let monospace_class = ''
246246
// Only add the class if we're changing the default font-family for this style
247247
if (typeof monospace_val !== 'undefined') {
@@ -255,7 +255,7 @@ abstract class TextualWindow extends WindowBase {
255255
}
256256
}
257257
// Is this run or this style reverse mode?
258-
const reverse = run.css_styles?.reverse ?? this.styles?.[`span.Style_${run_style}`]?.reverse
258+
const reverse = run.css_styles?.reverse ?? this.styles?.[`.Style_${run_style}`]?.reverse
259259
// Create a template span and apply classes and styles
260260
const el = create('span', `Style_${run_style}${reverse ? ' reverse' : ''}${monospace_class}`)
261261
if (run.css_styles) {
@@ -461,7 +461,7 @@ export class BufferWindow extends TextualWindow {
461461
}
462462
if (!line_has_style) {
463463
line_has_style = 1
464-
divel.addClass(`Style_${run.style}`)
464+
divel.addClass(`Style_${run.style}_par`)
465465
}
466466
divel.append(this.create_text_run(run, line_index === data.text.length ? true : undefined))
467467
// Store the last text run for setting styles in the input

tests/advent.ulx

164 KB
Binary file not shown.

tests/advent.ulx.regtest

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
** game: advent.ulx
2+
** remformat: yes
3+
4+
* prologue
5+
6+
ADVENTURE
7+
8+
> east
9+
> get all
10+
set of keys: Taken.
11+
tasty food: Taken.
12+
brass lantern: Taken.
13+
small bottle: Taken.
14+
15+
> west
16+
> south
17+
> south
18+
> south
19+
> unlock grate with keys
20+
> open it
21+
> down
22+
> west
23+
> west
24+
> turn on lamp
25+
A note on the wall says, "Magic word XYZZY."
26+
27+
> xyzzy
28+
Inside Building
29+
30+
* save/restore
31+
32+
>{include} prologue
33+
34+
> save
35+
>{fileref_prompt} adventtest
36+
Ok.
37+
38+
> restart
39+
> yes
40+
At End Of Road
41+
42+
> restore
43+
>{fileref_prompt} adventtest
44+
Ok.
45+
46+
> look
47+
Inside Building
48+
49+
* menu
50+
51+
> look
52+
> help
53+
>{char} return
54+
I know of places, actions, and things.
55+
56+
>{char} space
57+
>{char} n
58+
>{char} return
59+
Perhaps the first adventurer was a mulatto slave named Stephen Bishop
60+
61+
>{char} space
62+
>{char} q
63+
At End Of Road

tests/inputfeaturetest.ulx

10 KB
Binary file not shown.

tests/inputfeaturetest.ulx.regtest

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
** game: inputfeaturetest.ulx
2+
** remformat: yes
3+
4+
# Not a complete test, but it does check the functions can be run
5+
6+
* basic
7+
8+
InputLineFeatureTest
9+
10+
> noecho
11+
The library has been set to no-echo mode for line input.
12+
13+
> look
14+
look
15+
A voice booooms out: Welcome to the test chamber.
16+
17+
> echo
18+
The library has been set to echo mode for line input (the normal behavior).
19+
20+
> interrupt
21+
Your input will be interrupted in two seconds by a timer event.
22+
23+
>{timer}
24+
The timer went off! (The command line was empty, though. You should see an empty prompt on the line above. Try typing something during those two seconds.)
25+
26+
> terminate
27+
There are now 13 special line input terminator keys.
28+
29+
> even
30+
There are now 6 special line input terminator keys.
31+
32+
> odd
33+
There are now 6 special line input terminator keys.
34+
35+
> none
36+
There are now 0 special line input terminator keys.

0 commit comments

Comments
 (0)