[120879] branches/gsoc14-interactive/base/src/port/port.tcl
shasha at macports.org
shasha at macports.org
Tue Jun 10 11:19:49 PDT 2014
Revision: 120879
https://trac.macports.org/changeset/120879
Author: shasha at macports.org
Date: 2014-06-10 11:19:49 -0700 (Tue, 10 Jun 2014)
Log Message:
-----------
Some more code for printing questions
Modified Paths:
--------------
branches/gsoc14-interactive/base/src/port/port.tcl
Modified: branches/gsoc14-interactive/base/src/port/port.tcl
===================================================================
--- branches/gsoc14-interactive/base/src/port/port.tcl 2014-06-10 18:14:45 UTC (rev 120878)
+++ branches/gsoc14-interactive/base/src/port/port.tcl 2014-06-10 18:19:49 UTC (rev 120879)
@@ -5230,13 +5230,53 @@
# Create namespace for questions
namespace eval portclient::questions {
+
##
+ # Function that handles printing of a timeout.
+ #
+ # @param time
+ # The amount of time for which a timeout is to occur.
+ proc ui_timeout {time} {
+ # Something using vwait
+ }
+
+ ##
+ # Main function that displays the choices for a multiple choice question.
+ #
+ # @param msg
+ # The question specific message that is to be printed before asking the question.
+ # @param ???name???
+ # May be a qid will be of better use instead as the client does not do anything port specific.
+ # @param ports
+ # The list of ports for which the question is being asked.
+ # @param time
+ # The amount of time for which a timeout is to occur.
+ proc ui_choice {msg name ports {time 0}} {
+ # Print the main message
+ puts $msg
+
+ # Print portname or port list suitably
+ set i 1
+ foreach port $ports {
+ puts -nonewline " $i) "
+ puts $port
+ incr i
+ }
+
+ # Check if timeout is set or not
+ if {$time > 0} {
+ # Run ui_timeout and skip the rest of the stuff here
+ puts "just testing"
+ }
+ }
+
+ ##
# Display a question that asks the user for yes/no as an answer.
#
# @param msg
# The question specific message that is to be printed before asking the question.
- # @param name
- # The name of the port.
+ # @param ???name???
+ # May be a qid will be of better use instead as the client does not do anything port specific.
# @param ports
# The port/list of ports for which the question is being asked.
# @param def
@@ -5251,7 +5291,7 @@
}
puts -nonewline $msg
- set leftmargin "\t"
+ set leftmargin " "
# Print portname or port list suitably
if {llength ports == 1} {
@@ -5285,21 +5325,69 @@
}
##
- # Display a question that asks the user for yes/no as an answer.
+ # Display a question that asks the user for a single choice as an answer.
#
# @param msg
# The question specific message that is to be printed before asking the question.
- # @param name
- # The name of the port.
+ # @param ???name???
+ # May be a qid will be of better use instead as the client does not do anything port specific.
# @param ports
# The port/list of ports for which the question is being asked.
# @param def
# The default answer to the question.
# @param time
# The amount of time for which a timeout is to occur.
- proc ui_ask_singlechoice {msg name ports def time} {
+ proc ui_ask_singlechoice {msg name ports def {time 0}} {
+ ui_choice msg name ports time
+
+ # User Input (single input restriction)
+ puts "Enter a number to select an option: "
+ while 1 {
+ set input [gets stdin]
+ if {($input <= [llength $ports] && [string is integer -strict $input])} {
+ return $input
+ } else {
+ puts "Please enter an index from the above list."
+ }
+ }
}
+
+ ##
+ # Display a question that asks the user for multiple choices as answer.
+ #
+ # @param msg
+ # The question specific message that is to be printed before asking the question.
+ # @param ???name???
+ # May be a qid will be of better use instead as the client does not do anything port specific.
+ # @param ports
+ # The list of ports for which the question is being asked.
+ # @param def
+ # The default answer to the question.
+ # @param time
+ # The amount of time for which a timeout is to occur.
+ proc ui_ask_multichoice {msg name ports def {time 0}} {
+
+ ui_choice msg name ports time
+
+ # User Input (with Multiple input parsing)
+ while 1 {
+ puts "Enter the numbers to select the options: "
+ set input [gets stdin]
+ set count 1
+ foreach num $input {
+ if {($num <= [llength $ports] && [string is integer -strict $num])} {
+ incr count
+ } else {
+ puts "Please enter numbers separated by a space which are indices from the above list."
+ break
+ }
+ }
+ if {$count == [llength input]} {
+ return input
+ }
+ }
+ }
}
##########################################
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/macports-changes/attachments/20140610/6d4baf69/attachment-0001.html>
More information about the macports-changes
mailing list