Skip to content

Commit

Permalink
Paragraph stylehints use _par CSS classes, rather than a div selector
Browse files Browse the repository at this point in the history
Some other small fixes too
  • Loading branch information
curiousdannii committed Feb 12, 2024
1 parent 5c5dbab commit 5b6455f
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 40 deletions.
27 changes: 16 additions & 11 deletions src/glkapi/glkapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
GlkApi
======
Copyright (c) 2023 Dannii Willis
Copyright (c) 2024 Dannii Willis
MIT licenced
https://github.com/curiousdannii/asyncglk
Expand All @@ -25,7 +25,7 @@ import {evtype_Arrange, evtype_CharInput, evtype_Hyperlink, evtype_LineInput, ev
import {FileRef} from './filerefs.js'
import * as Interface from './interface.js'
import {DidNotReturn, GlkArray, GlkApiOptions, GlkByteArray, GlkSchannel, GlkWordArray, RefBoxArg, RefStructArg, RefStructValue} from './interface.js'
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'
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'
import {ArrayBackedStream, FileStream, NullStream, Stream} from './streams.js'
import {BlankWindow, BufferWindow, GraphicsWindow, GridWindow, PairWindow, TextWindow, Window, WindowBox} from './windows.js'

Expand Down Expand Up @@ -525,7 +525,7 @@ export class AsyncGlk implements Interface.GlkApi {

switch (sel) {
case gestalt_Version:
return 0x00000704
return 0x00000705
case gestalt_CharInput:
// Known special keys can be returned
if (val <= keycode_Left && val >= keycode_Func12) {
Expand All @@ -552,6 +552,7 @@ export class AsyncGlk implements Interface.GlkApi {
case gestalt_LineTerminatorKey:
return +(val === keycode_Escape || (val >= keycode_Func12 && val <= keycode_Func1))
// These are dependent on what GlkOte tells us it supports
// TODO: check all of these
case gestalt_DrawImage:
return +((val === wintype_Graphics || val === wintype_TextBuffer) && this.support.includes('graphics'))
case gestalt_GarglkText:
Expand Down Expand Up @@ -918,14 +919,16 @@ export class AsyncGlk implements Interface.GlkApi {
}
}

glk_set_terminators_line_event(win: Window, keycodes: GlkArray) {
glk_set_terminators_line_event(win: Window, keycodes: GlkArray | null) {
if (!win) {
throw new Error('Invalid Window')
}
const terminators: TerminatorCode[] = []
for (const code of keycodes) {
if (TERMINATOR_KEYS[code]) {
terminators.push(TERMINATOR_KEYS[code])
if (keycodes) {
for (const code of keycodes) {
if (TERMINATOR_KEYS[code]) {
terminators.push(TERMINATOR_KEYS[code])
}
}
}
if (terminators.length) {
Expand Down Expand Up @@ -1023,7 +1026,7 @@ export class AsyncGlk implements Interface.GlkApi {
}

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

const stylehints = wintype === wintype_TextBuffer ? this.stylehints.buffer : this.stylehints.grid
const selector = `${hint <= stylehint_Justification ? 'div' : 'span'}.Style_${STYLE_NAMES[style]}`
const selector = `.Style_${STYLE_NAMES[style]}${hint <= stylehint_Justification ? '_par' : ''}`
const justifications = ['left', 'justify', 'center', 'right']
const weights = ['lighter', 'normal', 'bold']
let stylevalue: string | number | undefined
Expand Down Expand Up @@ -1573,8 +1576,8 @@ export class AsyncGlk implements Interface.GlkApi {
type = evtype_CharInput
if (ev.value.length === 1) {
val1 = ev.value.codePointAt(0)!
if (!(win as TextWindow).uni_input) {
val1 = val1 & 0xFF
if (!(win as TextWindow).uni_input && val1 > MAX_LATIN1) {
val1 = QUESTION_MARK
}
}
else {
Expand All @@ -1585,6 +1588,7 @@ export class AsyncGlk implements Interface.GlkApi {
if (!win?.input.hyperlink) {
return
}
delete win.input.hyperlink;

Check failure on line 1591 in src/glkapi/glkapi.ts

View workflow job for this annotation

GitHub Actions / test (Node v20)

Extra semicolon

Check failure on line 1591 in src/glkapi/glkapi.ts

View workflow job for this annotation

GitHub Actions / test (Node v21)

Extra semicolon
type = evtype_Hyperlink
val1 = ev.value
break
Expand All @@ -1600,6 +1604,7 @@ export class AsyncGlk implements Interface.GlkApi {
if (!win?.input.mouse) {
return
}
delete win.input.mouse;

Check failure on line 1607 in src/glkapi/glkapi.ts

View workflow job for this annotation

GitHub Actions / test (Node v20)

Extra semicolon

Check failure on line 1607 in src/glkapi/glkapi.ts

View workflow job for this annotation

GitHub Actions / test (Node v21)

Extra semicolon
type = evtype_MouseInput
val1 = ev.x
val2 = ev.y
Expand Down
22 changes: 11 additions & 11 deletions src/glkote/web/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,49 @@
GlkOte Glk styles
====================
Copyright (c) 2022 Dannii Willis
Copyright (c) 2024 Dannii Willis
MIT licenced
https://github.com/curiousdannii/asyncglk
*/

span.Style_normal {}
.Style_normal {}

span.Style_emphasized {
.Style_emphasized {
font-style: italic;
}

.BufferWindow span.Style_preformatted {
.BufferWindow .Style_preformatted {
display: inline-block;
font-family: var(--glkote-mono-family);
padding: 0;
}

span.Style_header {
.Style_header {
font-weight: bold;
}

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

span.Style_subheader {
.Style_subheader {
font-weight: bold;
}

span.Style_alert {
.Style_alert {
font-weight: bold;
}

span.Style_note {
.Style_note {
font-style: italic;
}

div.Style_blockquote {
.Style_blockquote_par {
margin: 0 2em;
}

span.Style_input {
.Style_input {
font-weight: bold;
color: var(--glkote-input-fg);
}
Expand Down
Binary file added tests/advent.ulx
Binary file not shown.
63 changes: 63 additions & 0 deletions tests/advent.ulx.regtest
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
** game: advent.ulx
** remformat: yes

* prologue

ADVENTURE

> east
> get all
set of keys: Taken.
tasty food: Taken.
brass lantern: Taken.
small bottle: Taken.

> west
> south
> south
> south
> unlock grate with keys
> open it
> down
> west
> west
> turn on lamp
A note on the wall says, "Magic word XYZZY."

> xyzzy
Inside Building

* save/restore

>{include} prologue

> save
>{fileref_prompt} adventtest
Ok.

> restart
> yes
At End Of Road

> restore
>{fileref_prompt} adventtest
Ok.

> look
Inside Building

* menu

> look
> help
>{char} return
I know of places, actions, and things.

>{char} space
>{char} n
>{char} return
Perhaps the first adventurer was a mulatto slave named Stephen Bishop

>{char} space
>{char} q
At End Of Road
Binary file added tests/inputfeaturetest.ulx
Binary file not shown.
36 changes: 36 additions & 0 deletions tests/inputfeaturetest.ulx.regtest
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
** game: inputfeaturetest.ulx
** remformat: yes

# Not a complete test, but it does check the functions can be run

* basic

InputLineFeatureTest

> noecho
The library has been set to no-echo mode for line input.

> look
look
A voice booooms out: Welcome to the test chamber.

> echo
The library has been set to echo mode for line input (the normal behavior).

> interrupt
Your input will be interrupted in two seconds by a timer event.

>{timer}
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.)

> terminate
There are now 13 special line input terminator keys.

> even
There are now 6 special line input terminator keys.

> odd
There are now 6 special line input terminator keys.

> none
There are now 0 special line input terminator keys.
55 changes: 37 additions & 18 deletions tests/runtests.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash

cd "$(dirname "$0")"

Expand All @@ -8,35 +8,54 @@ fi

# The default 1 second timeout is just on the threshhold of being too short, so just bump them up to a standard 10 seconds to be safe

echo 'Quixe'
python regtest.py -i "./quixe.js" -t 10 glulxercise.ulx.regtest
echo 'ZVM'
python regtest.py -i "./zvm.js" -t 10 praxix.z5.regtest
python regtest.py -i "./zvm.js --rem=1" -r -t 10 advent.z5.regtest
FAILURES=0

run_test() {
python regtest.py -i "./quixe.js --rem=1" -r -t ${2:-10} $1 || ((FAILURES++))
}

echo 'Quixe tests'
echo ' glulxercise'
run_test glulxercise.ulx.regtest
# TODO: fix save
#echo ' advent'
#run_test advent.ulx.regtest
#rm adventtest
echo 'ZVM tests'
echo ' praxix'
python regtest.py -i "./zvm.js" -t 10 praxix.z5.regtest || ((FAILURES++))
echo ' advent'
python regtest.py -i "./zvm.js --rem=1" -r -t 10 advent.z5.regtest || ((FAILURES++))
rm adventtest

echo 'Glk tests'
echo ' datetimetest'
python regtest.py -i "./quixe.js --rem=1" -t 10 datetimetest.ulx.regtest
run_test datetimetest.ulx.regtest
echo ' extbinaryfile'
python regtest.py -i "./quixe.js --rem=1" -t 10 extbinaryfile.ulx.regtest
run_test extbinaryfile.ulx.regtest
echo ' externalfile'
python regtest.py -i "./quixe.js --rem=1" -t 10 externalfile.ulx.regtest
run_test externalfile.ulx.regtest
echo ' graphwintest'
python regtest.py -i "./quixe.js --rem=1" -t 10 graphwintest.gblorb.regtest
# TODO: support refresh
run_test graphwintest.gblorb.regtest
echo ' imagetest'
python regtest.py -i "./quixe.js --rem=1" -t 10 imagetest.gblorb.regtest
# TODO: support refresh
run_test imagetest.gblorb.regtest
echo ' inputeventtest'
python regtest.py -i "./quixe.js --rem=1" -t 10 inputeventtest.ulx.regtest
run_test inputeventtest.ulx.regtest
echo ' inputfeaturetest'
run_test inputfeaturetest.ulx.regtest
echo ' memstreamtest'
python regtest.py -i "./quixe.js --rem=1" -t 10 memstreamtest.ulx.regtest
run_test memstreamtest.ulx.regtest
echo ' resstreamtest'
python regtest.py -i "./quixe.js --rem=1" -t 10 resstreamtest.gblorb.regtest
run_test resstreamtest.gblorb.regtest
echo ' startsavetest'
python regtest.py -i "./quixe.js --rem=1" -t 10 startsavetest.gblorb.regtest
run_test startsavetest.gblorb.regtest
echo ' unicasetest'
python regtest.py -i "./quixe.js --rem=1" -t 10 unicasetest.ulx.regtest
run_test unicasetest.ulx.regtest
echo ' unicodetest'
python regtest.py -i "./quixe.js --rem=1" -t 10 unicodetest.ulx.regtest
run_test unicodetest.ulx.regtest
echo ' windowtest'
python regtest.py -i "./quixe.js --rem=1" -t 10 windowtest.ulx.regtest
run_test windowtest.ulx.regtest

exit $FAILURES

0 comments on commit 5b6455f

Please sign in to comment.