"""text~~~~An object for displaying a text area in a terminal."""fromblessedimportTerminalfromblessed.keyboardimportKeystrokefromthurible.panelimportScroll,Titlefromthurible.utilimportBox
[docs]classText(Scroll,Title):"""Create a new :class:`thurible.Text` object. This class displays text to the document and allows the user to scroll through that text if it is too long to fit in the terminal window. As a subclass of :class:`thurible.panel.Scroll` and :class:`thurible.panel.Title`, it can also take those parameters and has those public methods, properties, and active keys. :param content: (Optional.) The text to display in the interior of the panel. :param content_align_h: (Optional.) The horizontal alignment of the contents of the panel. It defaults to "left". :param content_align_v: (Optional.) The vertical alignment of the contents of the panel. It defaults to "top". :return: A :class:`thurible.Text` object. :rtype: thurible.Text :usage: To create a new minimal :class:`thurible.Text` object: .. testcode:: import thurible text = thurible.Text() To create a :class:`thurible.Text` object containing the text "spam".: .. testsetup:: import thurible .. testcode:: text = thurible.Text('spam') Information on the sizing of :class:`thurible.Text` objects can be found in the :ref:`sizing` section below. :active keys: This class defines the following :ref:`active keys<active>`: * KEY_END: Scroll to the end of the content. * KEY_DOWN: Scroll down in the content. * KEY_HOME: Scroll to the top of the content. * KEY_PGDOWN: Scroll one screen down in the content. * KEY_PGUP: Scroll one page up in the content. * KEY_UP: Scroll one line up in the content. """# Magic methods.def__init__(self,content:str='',content_align_h:str='left',content_align_v:str='top',*args,**kwargs)->None:self.content=contentkwargs['content_align_h']=content_align_hkwargs['content_align_v']=content_align_vsuper().__init__(*args,**kwargs)def__eq__(self,other)->bool:ifnotisinstance(other,self.__class__):returnNotImplementedreturn(super().__eq__(other)andself.content==other.content)def__str__(self)->str:"""Return a string that will draw the entire panel."""# Set up.lines=self.lineslength=len(lines)height=self.inner_heightwidth=self.inner_widthy=self.inner_yx=self.inner_xself._start=0self._stop=heightresult=super().__str__()# Create the display string and return.y+=self._align_v(self.content_align_v,length,height)result,height,y=self._flow(result,length,height,width,y,x)self._overscroll(length,height)result+=self._visible(lines,width,y,x)returnresult# Properties.@propertydeflines(self)->list[str]:"""The lines of text available to be displayed in the panel after they have been wrapped to fit the width of the interior of the panel. :return: A :class:`list` object containing each line of text as a :class:`str`. :rtype: list """width=self.inner_widthifwidth!=self._wrapped_width:wrapped=self.term.wrap(self.content,width)self._lines=wrappedself._wrapped_width=widthreturnself._lines