VIM-like-text-editor/views.py

48 lines
1.7 KiB
Python

import curses
class CursesAdapter:
def __init__(self) -> None:
self.screen = curses.initscr()
self.screen.keypad(True)
self.cols = curses.COLS
self.lines = curses.LINES
# init color system
curses.start_color()
# green color pair
curses.init_pair(1, curses.COLOR_MAGENTA, curses.COLOR_BLACK)
curses.curs_set(1) # Make cursor visible
def Refresh(self) -> None:
"""Apply changes"""
self.screen.refresh()
def Cleanup(self) -> None:
curses.endwin()
def SetCursor(self, x: int, y: int):
"""set cursor position (x, y)"""
self.screen.move(x, y)
def SetChar(self, x: int, y: int, code: int):
"""set char position (x, y)"""
self.screen.addch(x, y, code)
def SetString(self, x: int, y: int, data: str):
"""set string begin position (x, y)"""
self.screen.addstr(x, y, data)
def GetChar(self) -> int:
"""Wait users input"""
return self.screen.getch()
def EditModeBar(self, currentLine, totalLines, fileName):
"""Print edit mode information panel"""
self.screen.addstr(self.lines - 1, 0, ' ' * (self.cols - 1)) # Очистка строки
self.screen.addstr(self.lines - 1, 0, "FILE: ")
self.screen.addstr(fileName, curses.color_pair(1)) # Имя файла
self.screen.addstr(" | MODE:")
self.screen.addstr(" EDIT", curses.color_pair(1))
self.screen.addstr(" | LINE: ")
self.screen.addstr(str(currentLine + 1), curses.color_pair(1))
self.screen.addstr("/")
self.screen.addstr(str(totalLines), curses.color_pair(1)) # Общее количество строк