-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Needs: - Integration test - README docs Notably, the hard part about this might not be writing the values to stdin, but rather dealing with the fact that most interactive processes behave VERY differently when run without a TTY. There are workarounds such as using the `script` command line tool, however integrating with a TTY shall be an exercise for the reader.
- Loading branch information
Showing
4 changed files
with
88 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
class Rundoc::CodeCommand::Background | ||
# Will send contents to the background process via STDIN along with a newline | ||
# | ||
# | ||
class StdinWrite < Rundoc::CodeCommand | ||
def initialize(contents, name:, wait:, timeout: 5, ending: $/) | ||
@contents = contents | ||
@ending = ending | ||
@spawn = Rundoc::CodeCommand::Background::ProcessSpawn.find(name) | ||
@wait = wait | ||
@timeout_value = Integer(timeout) | ||
@contents_written = nil | ||
end | ||
|
||
# The command is rendered (`:::>-`) by the output of the `def call` method. | ||
def to_md(env = {}) | ||
writecontents | ||
end | ||
|
||
# The contents produced by the command (`:::->`) are rendered by the `def to_md` method. | ||
def call(env = {}) | ||
writecontents | ||
output = @spawn.log.read | ||
output | ||
end | ||
|
||
def writecontents | ||
@contents_written ||= @spawn.write( | ||
contents, | ||
wait: @wait, | ||
ending: @ending, | ||
timeout: @timeout_value | ||
) | ||
end | ||
end | ||
end | ||
Rundoc.register_code_command(:"background.writeln", Rundoc::CodeCommand::Background::Wait) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters