OpenRPC examples upon request (keypress) #2

Open
opened 2 years ago by p · 0 comments
p commented 2 years ago
Owner

While our abilities are a bit constrained, we may print examples included in OpenRPC data when requested by the user. They will be syntax-highlighted and pretty-printed according to settings. Print "No examples found." if lacking.

The means of making this intermission has already been implemented for libedit in #1, however it remains unresolved for Readline.

Find a key sequence to bind to this action, in the likes of M-? (C-? is the DEL control character and cannot be used).

It is possible and may be desirable to run the pager for this occasion. For less -R we'll need to sanitize highlighted output by stripping away ^O^N characters--see degesch. Pager detection is tricky. We can try executing less -R ... first with a highlighted tmpfile() and default to ${PAGER:-more} with a stripped tmpfile() if unsuccessful. Highlighting is an extra stage, so we can just overwrite the tmpfile() with the raw version of the data and ftruncate() it to the new, shorter size. less(1) doesn't actually warrant reprinting the prompt if it runs on the alternate screen but we don't know up front in the parent process if this will happen. Highlighting will probably require a slight refactor.

Even the full schema may be printed but this requires resolving the full tree recursively, isn't as immediately useful, and makes for a new follow-up issue.

This requires at least elementary support of resolving $ref URIs. Intentionally do not include support for external documents. Only parse #/paths, in the most naïve way, i.e., check for a leading #/, split on slashes and try to traverse objects. Doing so should cover most usecases.

While our abilities are a bit constrained, we may print examples included in OpenRPC data when requested by the user. They will be syntax-highlighted and pretty-printed according to settings. Print "No examples found." if lacking. The means of making this intermission has already been implemented for libedit in #1, however it remains unresolved for Readline. Find a key sequence to bind to this action, in the likes of M-? (C-? is the DEL control character and cannot be used). It is possible and may be desirable to run the pager for this occasion. For `less -R` we'll need to sanitize highlighted output by stripping away ^O^N characters--see degesch. Pager detection is tricky. We can try executing `less -R ...` first with a highlighted `tmpfile()` and default to `${PAGER:-more}` with a stripped `tmpfile()` if unsuccessful. Highlighting is an extra stage, so we can just overwrite the `tmpfile()` with the raw version of the data and `ftruncate()` it to the new, shorter size. less(1) doesn't actually warrant reprinting the prompt if it runs on the alternate screen but we don't know up front in the parent process if this will happen. Highlighting will probably require a slight refactor. Even the full schema may be printed but this requires resolving the full tree recursively, isn't as immediately useful, and makes for a new follow-up issue. ~~This requires at least elementary support of resolving `$ref` URIs. Intentionally do not include support for external documents. Only parse `#/paths`, in the most naïve way, i.e., check for a leading `#/`, split on slashes and try to traverse objects. Doing so should cover most usecases.~~
p self-assigned this 2 years ago
p added this to the v1.2.0 milestone 2 years ago
p modified the milestone from v1.2.0 to v1.3.0 2 years ago
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date

No due date set.

Dependencies

No dependencies set.

Reference: p/json-rpc-shell#2
Loading…
There is no content yet.