<commit_before><?php
/*
 * Copyright (c) 2014, <NAME>
 * All rights reserved.
 *
 * This file is part of Zeptech FunBox. For the full copyright and license
 * information please view the LICENSE file that was distributed with this
 * source code.
 */

/**
 * Prompt the user for a single line of input.
 *
 * @param string $prompt
 * $return string
 */
function prompt($prompt) {
	echo $prompt;
	$line = fgets(STDIN);
	return $line;
}<commit_msg>Add smarter prompt display and ability to specify default to prompt() function. Also trim user input before returning<commit_after><?php
/*
 * Copyright (c) 2014, <NAME>
 * All rights reserved.
 *
 * This file is part of Zeptech FunBox. For the full copyright and license
 * information please view the LICENSE file that was distributed with this
 * source code.
 */

/**
 * Prompt the user for a single line of input.
 *
 * @param string $prompt
 * $return string
 */
function prompt($prompt, $default = '') {
	$prompt = String($prompt)->trim()->trim(':');

	if ($default) {
		$prompt = String("$prompt ($default): ");
	} else {
		$prompt = String("$prompt: ");
	}

	echo $prompt;
	$line = trim(fgets(STDIN));
	if ($line === '') {
		return $default;
	}
	return $line;
}
{'fraction_non_alphanumeric': 0.13733552631578946, 'fraction_numerical': 0.006578947368421052, 'mean_word_length': 3.735408560311284, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6460691', 'n_tokens_mistral': 391, 'n_tokens_neox': 363, 'n_words': 144}