


"""simple docstring"""






import builtins
import sys

from ...utils.imports import _is_package_available
from . import cursor, input
from .helpers import Direction, clear_line, forceWrite, linebreak, move_cursor, reset_cursor, writeColor
from .keymap import KEYMAP


__snake_case							:     Union[str, Any]   =					False
try:
	__snake_case							:     Optional[Any]   =					_is_package_available('google.colab')
except ModuleNotFoundError:
	pass



@input.register
class     A__     :




	'''simple docstring'''





	def __init__(  self:	str ,    _SCREAMING_SNAKE_CASE:	str = None ,    _SCREAMING_SNAKE_CASE:	list = [])       -> Optional[Any]:

				"""simple docstring"""

				__lowerCAmelCase   :						Dict				= 0
				__lowerCAmelCase   :						List[str]				= choices
				__lowerCAmelCase   :						Optional[Any]				= prompt
				if sys.platform == "win32":
							__lowerCAmelCase   :						Optional[Any]				= "*"
				else:
							__lowerCAmelCase   :						List[Any]				= "➔ "

	def 							_SCREAMING_SNAKE_CASE     (  self:	Union[str, Any] ,    _SCREAMING_SNAKE_CASE:	str ,    _SCREAMING_SNAKE_CASE:	str = "")       -> Optional[int]:

				"""simple docstring"""

				if sys.platform != "win32":
							writeColor(self.choices[index] ,    32 ,    _SCREAMING_SNAKE_CASE)
				else:
							forceWrite(self.choices[index] ,    _SCREAMING_SNAKE_CASE)

	def 							_SCREAMING_SNAKE_CASE     (  self:	Dict ,    _SCREAMING_SNAKE_CASE:	int)       -> int:

				"""simple docstring"""

				if index == self.position:
							forceWrite(F""" {self.arrow_char} """)
							self.write_choice(_SCREAMING_SNAKE_CASE)
				else:
							forceWrite(F"""    {self.choices[index]}""")
				reset_cursor()

	def 							_SCREAMING_SNAKE_CASE     (  self:	List[str] ,    _SCREAMING_SNAKE_CASE:	Direction ,    _SCREAMING_SNAKE_CASE:	int = 1)       -> int:

				"""simple docstring"""

				__lowerCAmelCase   :						Optional[Any]				= self.position
				if direction == Direction.DOWN:
							if self.position + 1 >= len(self.choices):
										return
							self.position += num_spaces
				else:
							if self.position - 1 < 0:
										return
							self.position -= num_spaces
				clear_line()
				self.print_choice(_SCREAMING_SNAKE_CASE)
				move_cursor(_SCREAMING_SNAKE_CASE ,    direction.name)
				self.print_choice(self.position)

	@input.mark(KEYMAP["up"])
	def 							_SCREAMING_SNAKE_CASE     (  self:	int)       -> Optional[Any]:

				"""simple docstring"""

				self.move_direction(Direction.UP)

	@input.mark(KEYMAP["down"])
	def 							_SCREAMING_SNAKE_CASE     (  self:	Any)       -> int:

				"""simple docstring"""

				self.move_direction(Direction.DOWN)

	@input.mark(KEYMAP["newline"])
	def 							_SCREAMING_SNAKE_CASE     (  self:	int)       -> int:

				"""simple docstring"""

				move_cursor(len(self.choices) - self.position ,    "DOWN")
				return self.position

	@input.mark(KEYMAP["interrupt"])
	def 							_SCREAMING_SNAKE_CASE     (  self:	Dict)       -> List[str]:

				"""simple docstring"""

				move_cursor(len(self.choices) - self.position ,    "DOWN")
				raise KeyboardInterrupt

	@input.mark_multiple(*[KEYMAP[str(_SCREAMING_SNAKE_CASE)] for number in range(10)])
	def 							_SCREAMING_SNAKE_CASE     (  self:	str)       -> Optional[int]:

				"""simple docstring"""

				__lowerCAmelCase   :						Dict				= int(chr(self.current_selection))
				__lowerCAmelCase   :						List[Any]				= index - self.position
				if index == self.position:
							return
				if index < len(self.choices):
							if self.position > index:
										self.move_direction(Direction.UP ,    -movement)
							elif self.position < index:
										self.move_direction(Direction.DOWN ,    _SCREAMING_SNAKE_CASE)
							else:
										return
				else:
							return







	def 							_SCREAMING_SNAKE_CASE     (  self:	str ,    _SCREAMING_SNAKE_CASE:	int = 0)       -> Dict:

				"""simple docstring"""

				if self.prompt:
							linebreak()
							forceWrite(self.prompt ,    "\n")
							if in_colab:
										forceWrite("Please input a choice index (starting from 0), and press enter" ,    "\n")
							else:
										forceWrite("Please select a choice using the arrow or number keys, and selecting with enter" ,    "\n")
				__lowerCAmelCase   :						List[str]				= default_choice
				for i in range(len(self.choices)):
							self.print_choice(_SCREAMING_SNAKE_CASE)
							forceWrite("\n")
				move_cursor(len(self.choices) - self.position ,    "UP")
				with cursor.hide():
							while True:
										if in_colab:
													try:
																__lowerCAmelCase   :						Union[str, Any]				= int(builtins.input())
													except ValueError:
																__lowerCAmelCase   :						str				= default_choice
										else:
													__lowerCAmelCase   :						Union[str, Any]				= self.handle_input()
										if choice is not None:
													reset_cursor()
													for _ in range(len(self.choices) + 1):
																move_cursor(1 ,    "UP")
																clear_line()
													self.write_choice(_SCREAMING_SNAKE_CASE ,    "\n")
													return choice




"""simple docstring"""






import re

from filelock import FileLock


try:
	import nltk

	__snake_case							:     Any   =					True
except (ImportError, ModuleNotFoundError):
	__snake_case							:     Optional[int]   =					False

if NLTK_AVAILABLE:
	with FileLock('.lock') as lock:
		nltk.download('punkt', quiet=True)


def     _lowercase       (						__snake_case			)		->     str:
			re.sub("<n>"      ,""      ,__snake_case			)  # remove pegasus newline char
			assert NLTK_AVAILABLE, "nltk must be installed to separate newlines between sentences. (pip install nltk)"
			return "\n".join(nltk.sent_tokenize(__snake_case			)			)