file: 10-C-utils.t package: muf status: alpha
This function prompts the user for an integer value via
@$s.queryOutput and then reads it via
@$s.queryInput. It loops until
it obtains a value greater than or equal to
min and strictly less than max
and then returns that value.
It is currently implemented as:
: queryForInt { $ $ $ $ -> $ } -> max -> was -> min -> what
was min >= if
[ "The '%s' was %d\n" what was
| ]print @$s.queryOutput writeStream
fi
do{
[ "Please enter new integer value for '%s':\n" what
| ]print @$s.queryOutput writeStream
@$s.queryInput readStreamLine pop trimString -> string
string stringInt -> result
result min < if
[ "Sorry, the '%s' must be at least %d\n" what min
| ]print @$s.queryOutput writeStream
continue
fi
result max >= if
[ "Sorry, the '%s' must be less than %d\n" what max
| ]print @$s.queryOutput writeStream
continue
fi
result return
}
;
'queryForInt export
Go to the first, previous, next, last section, table of contents.