272273
1
 
1
/*
2
/*
2
* Copyright 2009, Chris Bedford, d.b.a, Build Lackey Labs. All Rights Reserved.
3
 * Copyright 2009, Chris Bedford, d.b.a, Build Lackey Labs. All Rights Reserved.
3
*
4
 *
4
*
5
 *
5
*       Licensed under the Apache License, Version 2.0 (the "License");
6
 *       Licensed under the Apache License, Version 2.0 (the "License");
6
*       you may not use this file except in compliance with the
7
 *       you may not use this file except in compliance with the
7
*       License. You may obtain a copy of the License at
8
 *       License. You may obtain a copy of the License at
8
*
9
 *
9
*         http://www.apache.org/licenses/LICENSE-2.0
10
 *         http://www.apache.org/licenses/LICENSE-2.0
10
*
11
 *
11
*       Unless required by applicable law or agreed to in writing, software
12
 *       Unless required by applicable law or agreed to in writing, software
12
*       distributed under the License is distributed on an "AS IS" BASIS,
13
 *       distributed under the License is distributed on an "AS IS" BASIS,
13
*       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 *       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
*
15
 *
15
*       See the License for the specific language governing permissions
16
 *       See the License for the specific language governing permissions
16
*       and limitations under the License.
17
 *       and limitations under the License.
17
*
18
 *
18
*/
19
 */
 
 
20
 
 
 
21
 
19
 
22
 
 
 
23
package com.lackey.provis.cmdline.util
20
package com.lackey.provis.cmdline.util
24
 
21
 
25
import org.slf4j.Logger
22
import org.slf4j.Logger
...
 
...
 
51
                  boolean wrapLines = true) {
48
                  boolean wrapLines = true) {
52
    while (true) {
49
    while (true) {
53
      if (wrapLines) {
50
      if (wrapLines) {
54
        TextUtils.writeNicelyWrappedLines (prompt, SCREEN_WIDTH, OUTPUT)
51
        TextUtils.writeNicelyWrappedLines(prompt, SCREEN_WIDTH, OUTPUT)
55
      } else {
52
      } else {
56
        OUTPUT.println(prompt)
53
        OUTPUT.println(prompt)
57
      }
54
      }
...
 
...
 
93
   * structure that provides all (3,2) [3 choose 2] mappings of a short code, 
90
   * structure that provides all (3,2) [3 choose 2] mappings of a short code, 
94
   * a string name, and an enum value.
91
   * a string name, and an enum value.
95
   *
92
   *
96
   * {@see  http://www.codeproject.com/KB/recipes/Combinatorics.aspx }
93
   * {@see http://www.codeproject.com/KB/recipes/Combinatorics.aspx }
97
   */
94
   */
98
  CommandShellType askForEnumType(String prompt,
95
  CommandShellType askForEnumType(String prompt,
99
                                  Map<Character, CommandShellType> codeToCommandShellType) {
96
                                  Map<Character, CommandShellType> codeToCommandShellType) {
...
 
...
 
120
      }
117
      }
121
    }
118
    }
122
  }
119
  }
 
 
120
 
 
 
121
 
 
 
122
  boolean askYesOrNo(String prompt, boolean wrapLines = true) {
 
 
123
    while (true) {
 
 
124
      if (wrapLines) {
 
 
125
        TextUtils.writeNicelyWrappedLines(prompt, SCREEN_WIDTH, OUTPUT)
 
 
126
      } else {
 
 
127
        OUTPUT.println(prompt)
 
 
128
      }
 
 
129
      String input = readLineWithDebugging()
 
 
130
      if (!input) {
 
 
131
        continue
 
 
132
      }
 
 
133
 
 
 
134
      String normalizedInput = input.toLowerCase()
 
 
135
      if (normalizedInput == "y") {
 
 
136
        return true
 
 
137
      }
 
 
138
      if (normalizedInput == "n") {
 
 
139
        return false
 
 
140
      }
 
 
141
    }
 
 
142
  }
123
}
143
}