How to use choice method in tox

Best Python code snippet using tox_python

choice.js

Source:choice.js Github

copy

Full Screen

1// (C) Copyright 2015 Martin Dougiamas2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at6//7// http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS IS" BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// See the License for the specific language governing permissions and13// limitations under the License.14angular.module('mm.addons.mod_choice')15/**16 * Choice service.17 *18 * @module mm.addons.mod_choice19 * @ngdoc service20 * @name $mmaModChoice21 */22.factory('$mmaModChoice', function($q, $mmSite, $mmSitesManager, mmaModChoiceResultsAfterAnswer, mmaModChoiceResultsAfterClose,23 mmaModChoiceResultsAlways, mmaModChoiceComponent, $mmFilepool, $mmApp, $mmaModChoiceOffline, $mmUtil) {24 var self = {};25 /**26 * Check if results can be seen by a student. The student can see the results if:27 * - they're always published, OR28 * - they're published after the choice is closed and it's closed, OR29 * - they're published after answering and the user has answered.30 *31 * @param {Object} choice Choice to check.32 * @param {Boolean} hasAnswered True if user has answered the choice, false otherwise.33 * @return {Boolean} [description]34 */35 self.canStudentSeeResults = function(choice, hasAnswered) {36 var now = new Date().getTime();37 return choice.showresults === mmaModChoiceResultsAlways ||38 choice.showresults === mmaModChoiceResultsAfterClose && choice.timeclose !== 0 && choice.timeclose <= now ||39 choice.showresults === mmaModChoiceResultsAfterAnswer && hasAnswered;40 };41 /**42 * Delete responses from a choice.43 *44 * @module mm.addons.mod_choice45 * @ngdoc method46 * @name $mmaModChoice#deleteResponses47 * @param {Number} choiceId Choice ID.48 * @param {String} name Choice name.49 * @param {Number} courseId Course ID the choice belongs to.50 * @param {Number[]} [responses] IDs of the answers. If not defined, delete all the answers of the current user.51 * @param {String} [siteId] Site ID. If not defined, current site.52 * @return {Promise} Promise resolved when the options are deleted.53 */54 self.deleteResponses = function(choiceId, name, courseId, responses, siteId) {55 siteId = siteId || $mmSite.getId();56 responses = responses || [];57 if (!$mmApp.isOnline()) {58 // App is offline, store the action.59 return storeOffline();60 }61 // If there's already a response to be sent to the server, discard it first.62 return $mmaModChoiceOffline.deleteResponse(choiceId, siteId).then(function() {63 return self.deleteResponsesOnline(choiceId, responses, siteId).then(function() {64 return true;65 }).catch(function(error) {66 if (error && error.wserror) {67 // The WebService has thrown an error, this means that responses cannot be deleted.68 return $q.reject(error.error);69 } else {70 // Couldn't connect to server, store in offline.71 return storeOffline();72 }73 });74 });75 // Convenience function to store a message to be synchronized later.76 function storeOffline() {77 return $mmaModChoiceOffline.saveResponse(choiceId, name, courseId, responses, true, siteId).then(function() {78 return false;79 });80 }81 };82 /**83 * Delete responses from a choice. It will fail if offline or cannot connect.84 *85 * @module mm.addons.mod_choice86 * @ngdoc method87 * @name $mmaModChoice#deleteResponsesOnline88 * @param {Number} choiceId Choice ID.89 * @param {Number[]} [responses] IDs of the answers. If not defined, delete all the answers of the current user.90 * @param {String} [siteId] Site ID. If not defined, current site.91 * @return {Promise} Promise resolved when responses are successfully deleted.92 */93 self.deleteResponsesOnline = function(choiceId, responses, siteId) {94 siteId = siteId || $mmSite.getId();95 return $mmSitesManager.getSite(siteId).then(function(site) {96 var params = {97 choiceid: choiceId,98 responses: responses99 };100 return site.write('mod_choice_delete_choice_responses', params).catch(function(error) {101 return $q.reject({102 error: error,103 wserror: $mmUtil.isWebServiceError(error)104 });105 }).then(function(response) {106 // Other errors ocurring.107 if (!response || response.status === false) {108 return $q.reject({109 wserror: true110 });111 }112 // Invalidate related data.113 var promises = [114 self.invalidateOptions(choiceId, siteId),115 self.invalidateResults(choiceId, siteId)116 ];117 return $q.all(promises).catch(function() {118 // Ignore errors.119 });120 });121 });122 };123 /**124 * Get cache key for choice data WS calls.125 *126 * @param {Number} courseid Course ID.127 * @return {String} Cache key.128 */129 function getChoiceDataCacheKey(courseid) {130 return 'mmaModChoice:choice:' + courseid;131 }132 /**133 * Get cache key for choice options WS calls.134 *135 * @param {Number} choiceid Choice ID.136 * @return {String} Cache key.137 */138 function getChoiceOptionsCacheKey(choiceid) {139 return 'mmaModChoice:options:' + choiceid;140 }141 /**142 * Get cache key for choice results WS calls.143 *144 * @param {Number} choiceid Choice ID.145 * @return {String} Cache key.146 */147 function getChoiceResultsCacheKey(choiceid) {148 return 'mmaModChoice:results:' + choiceid;149 }150 /**151 * Returns if current site supports deleting choice responses.152 *153 * @module mm.addons.mod_choice154 * @ngdoc method155 * @name $mmaModChoice#isDeleteResponsesEnabled156 * @return {Boolean} True if supported, false otherwise.157 */158 self.isDeleteResponsesEnabled = function() {159 return $mmSite.wsAvailable('mod_choice_delete_choice_responses');160 };161 /**162 * Return whether or not the plugin is enabled in a certain site. Plugin is enabled if the choice WS are available.163 *164 * @module mm.addons.mod_choice165 * @ngdoc method166 * @name $mmaModChoice#isPluginEnabled167 * @param {String} [siteId] Site ID. If not defined, current site.168 * @return {Promise} Promise resolved with true if plugin is enabled, rejected or resolved with false otherwise.169 */170 self.isPluginEnabled = function(siteId) {171 siteId = siteId || $mmSite.getId();172 return $mmSitesManager.getSite(siteId).then(function(site) {173 return site.wsAvailable('mod_choice_get_choice_options') &&174 site.wsAvailable('mod_choice_get_choice_results') &&175 site.wsAvailable('mod_choice_get_choices_by_courses') &&176 site.wsAvailable('mod_choice_submit_choice_response');177 });178 };179 /**180 * Get a choice with key=value. If more than one is found, only the first will be returned.181 *182 * @param {String} siteId Site ID.183 * @param {Number} courseId Course ID.184 * @param {String} key Name of the property to check.185 * @param {Mixed} value Value to search.186 * @param {Boolean} [forceCache] True to always get the value from cache, false otherwise. Default false.187 * @return {Promise} Promise resolved when the choice is retrieved.188 */189 function getChoice(siteId, courseId, key, value, forceCache) {190 return $mmSitesManager.getSite(siteId).then(function(site) {191 var params = {192 courseids: [courseId]193 },194 preSets = {195 cacheKey: getChoiceDataCacheKey(courseId)196 };197 if (forceCache) {198 preSets.omitExpires = true;199 }200 return site.read('mod_choice_get_choices_by_courses', params, preSets).then(function(response) {201 if (response && response.choices) {202 var currentChoice;203 angular.forEach(response.choices, function(choice) {204 if (!currentChoice && choice[key] == value) {205 currentChoice = choice;206 }207 });208 if (currentChoice) {209 return currentChoice;210 }211 }212 return $q.reject();213 });214 });215 }216 /**217 * Get a choice by course module ID.218 *219 * @module mm.addons.mod_choice220 * @ngdoc method221 * @name $mmaModChoice#getChoice222 * @param {Number} courseId Course ID.223 * @param {Number} cmId Course module ID.224 * @param {String} [siteId] Site ID. If not defined, current site.225 * @param {Boolean} [forceCache] True to always get the value from cache, false otherwise. Default false.226 * @return {Promise} Promise resolved when the choice is retrieved.227 */228 self.getChoice = function(courseId, cmId, siteId, forceCache) {229 siteId = siteId || $mmSite.getId();230 return getChoice(siteId, courseId, 'coursemodule', cmId, forceCache);231 };232 /**233 * Get a choice by ID.234 *235 * @module mm.addons.mod_choice236 * @ngdoc method237 * @name $mmaModChoice#getChoiceById238 * @param {Number} courseId Course ID.239 * @param {Number} id Choice ID.240 * @param {String} [siteId] Site ID. If not defined, current site.241 * @param {Boolean} [forceCache] True to always get the value from cache, false otherwise. Default false.242 * @return {Promise} Promise resolved when the choice is retrieved.243 */244 self.getChoiceById = function(courseId, id, siteId, forceCache) {245 siteId = siteId || $mmSite.getId();246 return getChoice(siteId, courseId, 'id', id, forceCache);247 };248 /**249 * Get a choice options.250 *251 * @module mm.addons.mod_choice252 * @ngdoc method253 * @name $mmaModChoice#getOptions254 * @param {Number} choiceid Choice ID.255 * @return {Promise} Promise resolved with choice options.256 */257 self.getOptions = function(choiceid) {258 var params = {259 choiceid: choiceid260 },261 preSets = {262 cacheKey: getChoiceOptionsCacheKey(choiceid)263 };264 return $mmSite.read('mod_choice_get_choice_options', params, preSets).then(function(response) {265 if (response.options) {266 return response.options;267 }268 return $q.reject();269 });270 };271 /**272 * Get a choice results.273 *274 * @module mm.addons.mod_choice275 * @ngdoc method276 * @name $mmaModChoice#getResults277 * @param {Number} choiceid Choice ID.278 * @return {Promise} Promise resolved with choice results.279 */280 self.getResults = function(choiceid) {281 var params = {282 choiceid: choiceid283 },284 preSets = {285 cacheKey: getChoiceResultsCacheKey(choiceid)286 };287 return $mmSite.read('mod_choice_get_choice_results', params, preSets).then(function(response) {288 if (response.options) {289 return response.options;290 }291 return $q.reject();292 });293 };294 /**295 * Invalidates choice data.296 *297 * @module mm.addons.mod_choice298 * @ngdoc method299 * @name $mmaModChoice#invalidateChoiceData300 * @param {Number} courseid Course ID.301 * @return {Promise} Promise resolved when the data is invalidated.302 */303 self.invalidateChoiceData = function(courseid) {304 return $mmSite.invalidateWsCacheForKey(getChoiceDataCacheKey(courseid));305 };306 /**307 * Invalidate the prefetched content.308 *309 * @module mm.addons.mod_choice310 * @ngdoc method311 * @name $mmaModChoice#invalidateContent312 * @param {Number} moduleId The module ID.313 * @param {Number} courseId Course ID.314 * @return {Promise}315 */316 self.invalidateContent = function(moduleId, courseId) {317 var promises = [],318 siteId = $mmSite.getId();319 promises.push(self.getChoice(courseId, moduleId).then(function(choice) {320 var ps = [];321 ps.push(self.invalidateChoiceData(courseId));322 ps.push(self.invalidateOptions(choice.id));323 ps.push(self.invalidateResults(choice.id));324 return $q.all(ps);325 }));326 promises.push($mmFilepool.invalidateFilesByComponent(siteId, mmaModChoiceComponent, moduleId));327 return $q.all(promises);328 };329 /**330 * Invalidates options.331 *332 * @module mm.addons.mod_choice333 * @ngdoc method334 * @name $mmaModChoice#invalidateOptions335 * @param {Number} choiceId Choice ID.336 * @param {String} [siteId] Site ID. If not defined, current site.337 * @return {Promise} Promise resolved when the data is invalidated.338 */339 self.invalidateOptions = function(choiceId, siteId) {340 siteId = siteId || $mmSite.getId();341 return $mmSitesManager.getSite(siteId).then(function(site) {342 return site.invalidateWsCacheForKey(getChoiceOptionsCacheKey(choiceId));343 });344 };345 /**346 * Invalidates results.347 *348 * @module mm.addons.mod_choice349 * @ngdoc method350 * @name $mmaModChoice#invalidateResults351 * @param {Number} choiceId Choice ID.352 * @param {String} [siteId] Site ID. If not defined, current site.353 * @return {Promise} Promise resolved when the data is invalidated.354 */355 self.invalidateResults = function(choiceId, siteId) {356 siteId = siteId || $mmSite.getId();357 return $mmSitesManager.getSite(siteId).then(function(site) {358 return site.invalidateWsCacheForKey(getChoiceResultsCacheKey(choiceId));359 });360 };361 /**362 * Report the choice as being viewed.363 *364 * @module mm.addons.mod_choice365 * @ngdoc method366 * @name $mmaModChoice#logView367 * @param {String} id Choice ID.368 * @return {Promise} Promise resolved when the WS call is successful.369 */370 self.logView = function(id) {371 if (id) {372 var params = {373 choiceid: id374 };375 return $mmSite.write('mod_choice_view_choice', params);376 }377 return $q.reject();378 };379 /**380 * Send a response to a choice to Moodle.381 *382 * @module mm.addons.mod_choice383 * @ngdoc method384 * @name $mmaModChoice#submitResponse385 * @param {Number} choiceId Choice ID.386 * @param {String} name Choice name.387 * @param {Number} courseId Course ID the choice belongs to.388 * @param {Number[]} responses IDs of selected options.389 * @param {String} [siteId] Site ID. If not defined, current site.390 * @return {Promise} Promise resolved with boolean: true if response was sent to server, false if stored in device.391 */392 self.submitResponse = function(choiceId, name, courseId, responses, siteId) {393 siteId = siteId || $mmSite.getId();394 if (!$mmApp.isOnline()) {395 // App is offline, store the action.396 return storeOffline();397 }398 // If there's already a response to be sent to the server, discard it first.399 return $mmaModChoiceOffline.deleteResponse(choiceId, siteId).then(function() {400 return self.submitResponseOnline(choiceId, responses, siteId).then(function() {401 return true;402 }).catch(function(error) {403 if (error && error.wserror) {404 // The WebService has thrown an error, this means that responses cannot be submitted.405 return $q.reject(error.error);406 } else {407 // Couldn't connect to server, store in offline.408 return storeOffline();409 }410 });411 });412 // Convenience function to store a message to be synchronized later.413 function storeOffline() {414 return $mmaModChoiceOffline.saveResponse(choiceId, name, courseId, responses, false, siteId).then(function() {415 return false;416 });417 }418 };419 /**420 * Send a response to a choice to Moodle. It will fail if offline or cannot connect.421 *422 * @module mm.addons.mod_choice423 * @ngdoc method424 * @name $mmaModChoice#submitResponseOnline425 * @param {Number} choiceId Choice ID.426 * @param {Number[]} responses IDs of selected options.427 * @param {String} [siteId] Site ID. If not defined, current site.428 * @return {Promise} Promise resolved when responses are successfully submitted.429 */430 self.submitResponseOnline = function(choiceId, responses, siteId) {431 siteId = siteId || $mmSite.getId();432 return $mmSitesManager.getSite(siteId).then(function(site) {433 var params = {434 choiceid: choiceId,435 responses: responses436 };437 return site.write('mod_choice_submit_choice_response', params).catch(function(error) {438 return $q.reject({439 error: error,440 wserror: $mmUtil.isWebServiceError(error)441 });442 }).then(function() {443 // Invalidate related data.444 var promises = [445 self.invalidateOptions(choiceId, siteId),446 self.invalidateResults(choiceId, siteId)447 ];448 return $q.all(promises).catch(function() {449 // Ignore errors.450 });451 });452 });453 };454 return self;...

Full Screen

Full Screen

btcSingle1.py

Source:btcSingle1.py Github

copy

Full Screen

...25time.sleep(5)26z = 127# =========================[MMDZA.CoM]==============================28while True:29 c1 = str(random.choice('0123456789abcdefABCDEF'))30 c2 = str(random.choice('0123456789abcdefABCDEF'))31 c3 = str(random.choice('0123456789abcdefABCDEF'))32 c4 = str(random.choice('0123456789abcdefABCDEF'))33 c5 = str(random.choice('0123456789abcdefABCDEF'))34 c6 = str(random.choice('0123456789abcdefABCDEF'))35 c7 = str(random.choice('0123456789abcdefABCDEF'))36 c8 = str(random.choice('0123456789abcdefABCDEF'))37 c9 = str(random.choice('0123456789abcdefABCDEF'))38 c10 = str(random.choice('0123456789abcdefABCDEF'))39 c11 = str(random.choice('0123456789abcdefABCDEF'))40 c12 = str(random.choice('0123456789abcdefABCDEF'))41 c13 = str(random.choice('0123456789abcdefABCDEF'))42 c14 = str(random.choice('0123456789abcdefABCDEF'))43 c15 = str(random.choice('0123456789abcdefABCDEF'))44 c16 = str(random.choice('0123456789abcdefABCDEF'))45 c17 = str(random.choice('0123456789abcdefABCDEF'))46 c18 = str(random.choice('0123456789abcdefABCDEF'))47 c19 = str(random.choice('0123456789abcdefABCDEF'))48 c20 = str(random.choice('0123456789abcdefABCDEF'))49 c21 = str(random.choice('0123456789abcdefABCDEF'))50 c22 = str(random.choice('0123456789abcdefABCDEF'))51 c23 = str(random.choice('0123456789abcdefABCDEF'))52 c24 = str(random.choice('0123456789abcdefABCDEF'))53 c25 = str(random.choice('0123456789abcdefABCDEF'))54 c26 = str(random.choice('0123456789abcdefABCDEF'))55 c27 = str(random.choice('0123456789abcdefABCDEF'))56 c28 = str(random.choice('0123456789abcdefABCDEF'))57 c29 = str(random.choice('0123456789abcdefABCDEF'))58 c30 = str(random.choice('0123456789abcdefABCDEF'))59 c31 = str(random.choice('0123456789abcdefABCDEF'))60 c32 = str(random.choice('0123456789abcdefABCDEF'))61 c33 = str(random.choice('0123456789abcdefABCDEF'))62 c34 = str(random.choice('0123456789abcdefABCDEF'))63 c35 = str(random.choice('0123456789abcdefABCDEF'))64 c36 = str(random.choice('0123456789abcdefABCDEF'))65 c37 = str(random.choice('0123456789abcdefABCDEF'))66 c38 = str(random.choice('0123456789abcdefABCDEF'))67 c39 = str(random.choice('0123456789abcdefABCDEF'))68 c40 = str(random.choice('0123456789abcdefABCDEF'))69 c41 = str(random.choice('0123456789abcdefABCDEF'))70 c42 = str(random.choice('0123456789abcdefABCDEF'))71 c43 = str(random.choice('0123456789abcdefABCDEF'))72 c44 = str(random.choice('0123456789abcdefABCDEF'))73 c45 = str(random.choice('0123456789abcdefABCDEF'))74 c46 = str(random.choice('0123456789abcdefABCDEF'))75 c47 = str(random.choice('0123456789abcdefABCDEF'))76 c48 = str(random.choice('0123456789abcdefABCDEF'))77 c49 = str(random.choice('0123456789abcdefABCDEF'))78 c50 = str(random.choice('0123456789abcdefABCDEF'))79 c51 = str(random.choice('0123456789abcdefABCDEF'))80 c52 = str(random.choice('0123456789abcdefABCDEF'))81 c53 = str(random.choice('0123456789abcdefABCDEF'))82 c54 = str(random.choice('0123456789abcdefABCDEF'))83 c55 = str(random.choice('0123456789abcdefABCDEF'))84 c56 = str(random.choice('0123456789abcdefABCDEF'))85 c57 = str(random.choice('0123456789abcdefABCDEF'))86 c58 = str(random.choice('0123456789abcdefABCDEF'))87 c59 = str(random.choice('0123456789abcdefABCDEF'))88 c60 = str(random.choice('0123456789abcdefABCDEF'))89 c61 = str(random.choice('0123456789abcdefABCDEF'))90 c62 = str(random.choice('0123456789abcdefABCDEF'))91 c63 = str(random.choice('0123456789abcdefABCDEF'))92 c64 = str(random.choice('0123456789abcdefABCDEF'))93 magic = (94 c1 + c2 + c3 + c4 + c5 + c6 + c7 + c8 + c9 + c10 + c11 + c12 + c13 + c14 + c15 + c16 + c17 + c18 + c19 + c20 + c21 + c22 + c23 + c24 + c25 + c26 + c27 + c28 + c29 + c30 + c31 + c32 + c33 + c34 + c35 + c36 + c37 + c38 + c39 + c40 + c41 + c42 + c43 + c44 + c45 + c46 + c47 + c48 + c49 + c50 + c51 + c52 + c53 + c54 + c55 + c56 + c57 + c58 + c59 + c60 + c61 + c62 + c63 + c64)95 PRIVATE_KEY = str(magic)96 # =========================[MMDZA.CoM]==============================97 hdwallet: HDWallet = HDWallet(symbol=SYMBOL)98 hdwallet.from_private_key(private_key=PRIVATE_KEY)99 privatekey = hdwallet.private_key()100 btcaddr1 = hdwallet.p2sh_address()101 # =========================[MMDZA.CoM]==============================102 URL = ('https://bitcoin.atomicwallet.io/address/' + btcaddr1)103 markup = "<h1></h1>"104 headers = {105 "User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537'}106 page = requests.get(URL, headers=headers)...

Full Screen

Full Screen

form.js

Source:form.js Github

copy

Full Screen

1'use strict';2const colors = require('ansi-colors');3const SelectPrompt = require('./select');4const placeholder = require('../placeholder');5class FormPrompt extends SelectPrompt {6 constructor(options) {7 super({ ...options, multiple: true });8 this.type = 'form';9 this.initial = this.options.initial;10 this.align = [this.options.align, 'right'].find(v => v != null);11 this.emptyError = '';12 this.values = {};13 }14 async reset(first) {15 await super.reset();16 if (first === true) this._index = this.index;17 this.index = this._index;18 this.values = {};19 this.choices.forEach(choice => choice.reset && choice.reset());20 return this.render();21 }22 dispatch(char) {23 return !!char && this.append(char);24 }25 append(char) {26 let choice = this.focused;27 if (!choice) return this.alert();28 let { cursor, input } = choice;29 choice.value = choice.input = input.slice(0, cursor) + char + input.slice(cursor);30 choice.cursor++;31 return this.render();32 }33 delete() {34 let choice = this.focused;35 if (!choice || choice.cursor <= 0) return this.alert();36 let { cursor, input } = choice;37 choice.value = choice.input = input.slice(0, cursor - 1) + input.slice(cursor);38 choice.cursor--;39 return this.render();40 }41 deleteForward() {42 let choice = this.focused;43 if (!choice) return this.alert();44 let { cursor, input } = choice;45 if (input[cursor] === void 0) return this.alert();46 let str = `${input}`.slice(0, cursor) + `${input}`.slice(cursor + 1);47 choice.value = choice.input = str;48 return this.render();49 }50 right() {51 let choice = this.focused;52 if (!choice) return this.alert();53 if (choice.cursor >= choice.input.length) return this.alert();54 choice.cursor++;55 return this.render();56 }57 left() {58 let choice = this.focused;59 if (!choice) return this.alert();60 if (choice.cursor <= 0) return this.alert();61 choice.cursor--;62 return this.render();63 }64 space(ch, key) {65 return this.dispatch(ch, key);66 }67 number(ch, key) {68 return this.dispatch(ch, key);69 }70 next() {71 let ch = this.focused;72 if (!ch) return this.alert();73 let { initial, input } = ch;74 if (initial && initial.startsWith(input) && input !== initial) {75 ch.value = ch.input = initial;76 ch.cursor = ch.value.length;77 return this.render();78 }79 return super.next();80 }81 prev() {82 let ch = this.focused;83 if (!ch) return this.alert();84 if (ch.cursor === 0) return super.prev();85 ch.value = ch.input = '';86 ch.cursor = 0;87 return this.render();88 }89 separator() {90 return '';91 }92 format(value) {93 return !this.state.submitted ? super.format(value) : '';94 }95 pointer() {96 return '';97 }98 indicator(choice) {99 return choice.input ? '⦿' : '⊙';100 }101 async choiceSeparator(choice, i) {102 let sep = await this.resolve(choice.separator, this.state, choice, i) || ':';103 return sep ? ' ' + this.styles.disabled(sep) : '';104 }105 async renderChoice(choice, i) {106 await this.onChoice(choice, i);107 let { state, styles } = this;108 let { cursor, initial = '', name, hint, input = '' } = choice;109 let { muted, submitted, primary, danger } = styles;110 let help = hint;111 let focused = this.index === i;112 let validate = choice.validate || (() => true);113 let sep = await this.choiceSeparator(choice, i);114 let msg = choice.message;115 if (this.align === 'right') msg = msg.padStart(this.longest + 1, ' ');116 if (this.align === 'left') msg = msg.padEnd(this.longest + 1, ' ');117 // re-populate the form values (answers) object118 let value = this.values[name] = (input || initial);119 let color = input ? 'success' : 'dark';120 if ((await validate.call(choice, value, this.state)) !== true) {121 color = 'danger';122 }123 let style = styles[color];124 let indicator = style(await this.indicator(choice, i)) + (choice.pad || '');125 let indent = this.indent(choice);126 let line = () => [indent, indicator, msg + sep, input, help].filter(Boolean).join(' ');127 if (state.submitted) {128 msg = colors.unstyle(msg);129 input = submitted(input);130 help = '';131 return line();132 }133 if (choice.format) {134 input = await choice.format.call(this, input, choice, i);135 } else {136 let color = this.styles.muted;137 let options = { input, initial, pos: cursor, showCursor: focused, color };138 input = placeholder(this, options);139 }140 if (!this.isValue(input)) {141 input = this.styles.muted(this.symbols.ellipsis);142 }143 if (choice.result) {144 this.values[name] = await choice.result.call(this, value, choice, i);145 }146 if (focused) {147 msg = primary(msg);148 }149 if (choice.error) {150 input += (input ? ' ' : '') + danger(choice.error.trim());151 } else if (choice.hint) {152 input += (input ? ' ' : '') + muted(choice.hint.trim());153 }154 return line();155 }156 async submit() {157 this.value = this.values;158 return super.base.submit.call(this);159 }160}...

Full Screen

Full Screen

editable.js

Source:editable.js Github

copy

Full Screen

1'use strict';2const Select = require('./select');3const Form = require('./form');4const form = Form.prototype;5class Editable extends Select {6 constructor(options) {7 super({ ...options, multiple: true });8 this.align = [this.options.align, 'left'].find(v => v != null);9 this.emptyError = '';10 this.values = {};11 }12 dispatch(char, key) {13 let choice = this.focused;14 let parent = choice.parent || {};15 if (!choice.editable && !parent.editable) {16 if (char === 'a' || char === 'i') return super[char]();17 }18 return form.dispatch.call(this, char, key);19 }20 append(char, key) {21 return form.append.call(this, char, key);22 }23 delete(char, key) {24 return form.delete.call(this, char, key);25 }26 space(char) {27 return this.focused.editable ? this.append(char) : super.space();28 }29 number(char) {30 return this.focused.editable ? this.append(char) : super.number(char);31 }32 next() {33 return this.focused.editable ? form.next.call(this) : super.next();34 }35 prev() {36 return this.focused.editable ? form.prev.call(this) : super.prev();37 }38 async indicator(choice, i) {39 let symbol = choice.indicator || '';40 let value = choice.editable ? symbol : super.indicator(choice, i);41 return await this.resolve(value, this.state, choice, i) || '';42 }43 indent(choice) {44 return choice.role === 'heading' ? '' : (choice.editable ? ' ' : ' ');45 }46 async renderChoice(choice, i) {47 choice.indent = '';48 if (choice.editable) return form.renderChoice.call(this, choice, i);49 return super.renderChoice(choice, i);50 }51 error() {52 return '';53 }54 footer() {55 return this.state.error;56 }57 async validate() {58 let result = true;59 for (let choice of this.choices) {60 if (typeof choice.validate !== 'function') {61 continue;62 }63 if (choice.role === 'heading') {64 continue;65 }66 let val = choice.parent ? this.value[choice.parent.name] : this.value;67 if (choice.editable) {68 val = choice.value === choice.name ? choice.initial || '' : choice.value;69 } else if (!this.isDisabled(choice)) {70 val = choice.enabled === true;71 }72 result = await choice.validate(val, this.state);73 if (result !== true) {74 break;75 }76 }77 if (result !== true) {78 this.state.error = typeof result === 'string' ? result : 'Invalid Input';79 }80 return result;81 }82 submit() {83 if (this.focused.newChoice === true) return super.submit();84 if (this.choices.some(ch => ch.newChoice)) {85 return this.alert();86 }87 this.value = {};88 for (let choice of this.choices) {89 let val = choice.parent ? this.value[choice.parent.name] : this.value;90 if (choice.role === 'heading') {91 this.value[choice.name] = {};92 continue;93 }94 if (choice.editable) {95 val[choice.name] = choice.value === choice.name96 ? (choice.initial || '')97 : choice.value;98 } else if (!this.isDisabled(choice)) {99 val[choice.name] = choice.enabled === true;100 }101 }102 return this.base.submit.call(this);103 }104}...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tox automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful