Python ncurses文本编辑器。需要帮助文本选择吗

Python ncurses文本编辑器。需要帮助文本选择吗,python,ncurses,Python,Ncurses,那里!我正在尝试创建一个文本编辑器。我在选择文本方面遇到了困难。选择功能正常,直到转换到新行。这就是我试图做的: import curses import string from dlist_mod import DoubleList stdscr=curses.initscr() curses.start_color() stdscr.keypad(1) curses.noecho() curses.cbreak() class Editor: """klasa Editor"""

那里!我正在尝试创建一个文本编辑器。我在选择文本方面遇到了困难。选择功能正常,直到转换到新行。这就是我试图做的:

import curses
import string
from dlist_mod import DoubleList


stdscr=curses.initscr()
curses.start_color()
stdscr.keypad(1)
curses.noecho()
curses.cbreak()
class Editor:
"""klasa Editor"""

    def __init__(self, stdscr):        
    """"inicijalizacija"""

        self.stdscr = stdscr
        self.maxy, self.maxx = self.stdscr.getmaxyx()
        curses.init_pair(1, curses.COLOR_BLUE, curses.COLOR_WHITE)
        self.lines = DoubleList()
        self.lines.append("6)Like s str other dynamic languages, Python is often used as a                  scripting language, but is also used in a wide range of non-scripting contexts.")
        self.lines.append("7)Using third-party tools, Python code can be packaged into standalone executable programs.")    
        self.lines.append("3)The language provides constructs intended to enable clear programs on both a small and large scale.")
        self.lines.append("4)Python supports multiple programming paradigms, including object-oriented, imperative and functional programming styles.")
        self.lines.append("5)It features a dynamic type system and automatic memory management and has a large and comprehensive standard library.")
        self.lines.append("8)Python interpreters are available for many operating systems. ")
        self.lines.append("9)CPython, the reference implementation of Python, is free and          open source software and has a community-based development model.")       
        self.lines.append("1)Python is a popular general-purpose, high-level programming language whose design philosophy emphasizes code readability.")
        self.lines.append("2)Python's syntax allows programmers to express concepts in         fewer lines of code than would be possible in languages such as C.")
        self.cursorY = 0
        self.cursorX = 0

        self.offsetY = 0
        self.offsetX = 0

        self.selectX = 0
        self.selectY = 0

        self.isSelecting = False
  def draw(self):
    """Ova funkcija sluzi za iscrtavanje prozora"""
    # iscrtavanje
    self.maxy, self.maxx = self.stdscr.getmaxyx()

    self.stdscr.clear()

    for i, line in enumerate(self.lines.values()):
        # ograniciti prostor ispisa
        dy = i - self.offsetY+1
        visibleLine = line[self.offsetX:self.maxx + self.offsetX - 1]
        self.stdscr.addstr(dy, 0, visibleLine)
        if dy >= 0 and dy < self.maxy:

            for l in line:
                if self.isSelecting and self.selectY==i:

                    x1 = min(self.selectX, self.cursorX) 
                    x2 = max(self.selectX,self.cursorX)

                    SelectedLine = line [x1:x2] 
                    self.stdscr.chgat(dy, x1,len(SelectedLine), curses.color_pair(1))
    def right(self):
    """ Funkcija za pomeranje kursora desno."""
        self.maxy, self.maxx = self.stdscr.getmaxyx()
        line = self.lines.index(self.cursorY)
        if self.cursorX < len(line):
            if self.cursorX - self.offsetX == self.maxx - 1:
                self.offsetX += 1
            self.cursorX += 1
        elif self.cursorY != self.lines.size() - 1:
            self.home()
            self.down()

    def down(self):
    """Funkcija za pomeranje kursora dole."""
    if self.cursorY < self.lines.size() - 1:
        if self.cursorY - self.offsetY == self.maxy - 1:
            self.offsetY += 1
        self.cursorY += 1

        line = self.lines.index(self.cursorY)
        while self.cursorX > len(line):
            self.left()


def up(self):
    """Funkcija za pomeranje kursora gore."""
    if self.cursorY > 0:
        if self.offsetY == self.cursorY:
            self.offsetY -= 1
        self.cursorY -= 1

        line = self.lines.index(self.cursorY)
        while self.cursorX > len(line):
            self.left()


     def handleInput(self):

        ch = self.stdscr.getch()
        logging.error(ch)


        if ch == curses.KEY_LEFT:
            if self.isSelecting:
                self.isSelecting = False
            self.left()

        elif ch == curses.KEY_RIGHT:
            if self.isSelecting:
                self.isSelecting = False
            self.right()
导入诅咒
导入字符串
从dlist_mod import DoubleList
stdscr=curses.initscr()
诅咒。开始使用颜色()
stdscr.键盘(1)
诅咒
诅咒
类编辑器:
“klasa编辑器”
def ___;初始(自我,stdscr):
“inicijalizacija”
self.stdscr=stdscr
self.maxy,self.maxx=self.stdscr.getmaxyx()
curses.init\u对(1,curses.COLOR\u蓝色,curses.COLOR\u白色)
self.lines=DoubleList()
self.lines.append(“6)与其他动态语言一样,Python经常被用作脚本语言,但也被广泛用于非脚本上下文。”)
self.lines.append(“7)使用第三方工具,Python代码可以打包成独立的可执行程序。”)
self.lines.append(“3)该语言提供了用于在小规模和大规模上实现清晰程序的结构。”)
self.lines.append(“4)Python支持多种编程范式,包括面向对象、命令式和函数式编程样式。”)
self.lines.append(“5)它有一个动态类型系统和自动内存管理,并有一个大型而全面的标准库。”)
self.lines.append(“8”)Python解释器可用于许多操作系统。")
self.lines.append(“9)Python,Python的参考实现,是免费的开源软件,具有基于社区的开发模型。”)
self.lines.append(“1)Python是一种流行的通用高级编程语言,其设计理念强调代码可读性。”)
self.lines.append(“2)Python的语法允许程序员用比C等语言更少的代码行来表达概念”)
self.cursorY=0
self.cursorX=0
self.offsetY=0
self.offsetX=0
self.selectX=0
self.selectY=0
self.isselection=False
def牵引(自):
“Ova funkcija sluzi za Iscertavanje prozora”
#伊斯卡塔瓦涅
self.maxy,self.maxx=self.stdscr.getmaxyx()
self.stdscr.clear()
对于i,枚举中的行(self.lines.values()):
#奥格拉尼西提普罗斯托伊皮萨酒店
dy=i-self.offsetY+1
visibleLine=行[self.offsetX:self.maxx+self.offsetX-1]
self.stdscr.addstr(dy,0,visibleLine)
如果dy>=0且dylen(行):
self.left()
def up(自我):
“我是一个很好的朋友。”
如果self.cursorY>0:
如果self.offsetY==self.cursorY:
self.offsetY-=1
self.cursorY-=1
line=self.lines.index(self.cursorY)
而self.cursorX>len(行):
self.left()
def手动输入(自身):
ch=self.stdscr.getch()
logging.error(ch)
如果ch==curses.KEY\u左:
如果self.isSelecting:
self.isselection=False
self.left()
elif ch==curses.KEY\u右:
如果self.isSelecting:
self.isselection=False
self.right()

我怎样才能选择文本呢?

我想这是因为您启用了鼠标


选择时按住Shift键,选择将正常工作。

我想这是因为您启用了鼠标

选择时按住Shift键,选择将正常工作