Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What?
Introducing
watch
. A simple feature that mimics the basic features of thewatch
function found on Linux/Unix systems.Why?
I've developed a lot of command line tools, and I often needed to monitor output in the console. Most of the time with tables and such.
Using the
watch
functionality on Linux systems should do it, but this requires the entire framework to be loaded every time, which can put a strain on the server capacity. With this, we don't even need cache, but we can use theonce
function instead for things that shouldn't be cached, but still are needed.Example
In the playground directory, there is an example with a table updating with new records every second. Here to just demonstrate the simplicity.
###Testing
Watch comes with a few testing tools.
fakeTimes
By default it iterates just once, but you can tell how many iterations
watch
should execute.assertSecondsSleptBetweenIntervals
Allows you to assert the total seconds slept between intervals. Allows users to test if they passed the correct value.
shouldNotFakeIntervalSleep
This is not really a thing users would most likely use, but I used it to allow actually test sleeping. I can remove it if you don't want us to actually test sleep functions.
Considerations
Right now, Prompt is resetting the cursor position using the lines count. When a user presses enter, this messes up the output.
I added a new method
isFaked
to the FakesInputOutput trait which can be used to detect if Prompt is currently being faked. This might be helpful in the future if things like sections as described in #115 are going to be added.