def put_update_cursor(self): 'Position cursor at start of dot itself for in-line edits.' if self.dot_i == 0: # empty buffer, cursor at window top iline = self.win_1 else: iline = self.dot_i display.put_cursor(iline, 1)
def update(buf): if session.session.foreground == session.eden and ed.buf == buf: terminal.set_line_mode() edsel.win.update(open_line=(not ed.command_mode)) # open line in insert mode # restore cursor to eden cmd line (bottom of scroll region), edit point display.put_cursor(edsel.cmd_n, 1) # FIXME just get it running for now terminal.set_char_mode() # FIXME should restore whatever was before
def put_insert_cursor(self): 'Position cursor at start of open line after dot for i(nsert) a c cmds' if self.dot_i == 0: # empty buffer,special case, cursor at window top iline = self.win_1 else: iline = self.dot_i + (0 if self.at_bottom_line() else 1) display.put_cursor(iline, 1) # open line after dot
def display_frame(): 'Clear and update the entire frame' # called from startup and update_frame display.put_cursor(1,1) # origin, upper left corner display.erase_display() update_windows() win.display_marker() display.set_scroll(cmd_1, cmd_n) put_command_cursor()
def other_window(self): 'Move cursor to other window, next in sequence.' ed.buf.replace(ed.buf.dot, self.line + '\n') # from goto_line edsel.do_window_command('') # reassign win, ed.buf, call update(Op.next) self.line = ed.buf.lines[ed.buf.dot].rstrip() # from several methods # From display_mode self.point = 0 self.start_col = 1 wdot = frame.win.wline(frame.win.buf.dot) display.put_cursor(wdot, 1)
def refresh(column=1): 'Clear and update entire frame in command mode, otherwise just the windows' if mode == Mode.command: display.put_cursor(1,1) # upper left corner display.erase() update_windows() if mode == Mode.command: display.set_scroll(cmd_1, cmd_n) # update() sets cursor elif mode == Mode.display: put_display_cursor(column=column)
def display_mode(self, line): 'Enter display editing mode.' # Based on ed.py do_command 'c' case ed.command_mode = False frame.update(Op.display) ed.prompt = ed.input_prompt wyshka.prompt = ed.prompt # self.do_command does this via wyshka shell eden.line = line # not including final \n at eol eden.point = 0 # 0-based eden.start_col = 1 # 1-based eden.clear_line = False # following lines based on frame Op.input and Op.command win = frame.win win.clear_marker(win.buf.dot) wdot = win.wline(win.buf.dot) display.put_cursor(wdot,1)
def open_line(self): """ Split line at point, replace line in buffer at dot with its prefix, append suffix after line at dot. """ prefix = self.line[:self.point] suffix = self.line[self.point:].rstrip() ed.buf.replace(ed.buf.dot, prefix + '\n') display.kill_line() # from cursor to end of line ed.buf.a(ed.buf.dot, suffix + '\n') # calls update(Op.insert ...) self.line = suffix self.point = 0 self.start_col = 1 frame.put_display_cursor() # buf.a() update moved cursor so we have to put it back.FIXME?Redundant? win = frame.win wdot = win.wline(win.buf.dot) display.put_cursor(wdot,1)
def display_text(self, open_line=False): """ Start on win_1 line, display buffer lines self.seg_1 .. self.seg_n If space remains in window, pad with empty lines to self.win_h If in insert mode (not command_mode), open line where text will be typed """ # lines in segment, usually same as self.win_hl, less if small buffer seg_h = self.seg_n - self.seg_1 + 1 # n of padding empty lines at window bottom, > 0 when small buffer blank_h = self.win_hl - seg_h display.put_cursor(self.win_1,1) # cursor to window top if open_line: # open line at dot to insert new text self.display_lines(self.seg_1 +(1 if self.at_bottom_line() else 0), self.dot) # leave space at dot display.kill_whole_line() # open line to insert new text print() # next line self.display_lines(self.dot+1, self.seg_n-(0 if self.near_buffer_top() else 1)) else: self.display_lines(self.seg_1, self.seg_n) for iline in range(blank_h if not open_line else blank_h - 1): display.kill_whole_line() print()
def put_command_cursor(): 'Put cursor at input line in scrolling command region' display.put_cursor(cmd_n, 1) # last line on display
def cleanup(): 'Restore full-screen scrolling, cursor to bottom.' display.set_scroll_all() display.put_cursor(nlines,1)
def update(op, sourcebuf=None, buffer=None, origin=0, destination=0, start=0, end=0, column=1): # display column numbers are 1-based 'Update the display: one window, several, or the entire frame.' global mode, win, ifocus, cmd_h # Clear display, redraw all the windows and scrolling command region. if op == Op.refresh: refresh(column=column) # Restore full screen scrolling, cursor to bottom elif op == Op.restore: display.set_scroll_all() display.put_cursor(nlines,1) # Rescale frame and window sizes, then refresh. elif op == Op.rescale: cmd_h = start if start else cmd_h rescale() # Create new buffer, ed B, Op.insert case will display its contents. elif op == Op.create: win.focus = True win.buf = buffer win.locate_segment(win.buf.dot) win.saved_dot = win.buf.dot win.reupdate() # Change buffer in current window, ed b E D elif op == Op.select: win.focus = True win.buf = buffer win.reupdate() # Delete current buffer, ed D elif op == Op.remove: for w in windows: if w.buf == sourcebuf: # deleted buffer w.buf = buffer # new current buffer w.reupdate() # Switch to ed input mode, for ed a i c commands elif op == Op.input: mode = Mode.input window.show_marker = False win.update_for_input() wdot = win.wline(win.buf.dot) display.put_cursor(wdot+1,1) # Switch to ed command mode, ed . while in input mode elif op == Op.command: mode = Mode.command window.show_marker = True # Overwrite '.' line on display, and lines below. win.update_from(win.buf.dot + 1) win.set_marker(win.buf.dot) # Switch to eden display mode elif op == Op.display: mode = Mode.display window.show_marker = False put_display_cursor(column=column) # Dot moved, ed l command elif op == Op.locate: win.locate(origin, destination) # Insert text: ed a i c m r t y commands # start, end are after insert, start == destination, end == win.buf.dot elif op == Op.insert and origin != background_task: if mode != Mode.input: # ed commands m r t y win.insert(origin, start, end) elif mode == Mode.input: # input mode after ed commands a i c # Text at dot is already up-to-date on display, open next line. win.update_for_input() for w in windows: if w.samebuf(win): w.adjust_insert(start, end, destination) if mode == Mode.input: # can't put input cursor til other windows done win.put_cursor_for_input(column=1) # Background task inserts text by calling buffer write() method. # Search for windows (if any) which displays that buffer. elif op == Op.insert and origin == background_task: for w in windows: if w.buf == buffer: w.saved_dot = w.buf.dot terminal.set_line_mode() w.insert(origin, start, end) terminal.set_char_mode() if mode == Mode.input: # can't put input cursor til other windows done win.put_cursor_for_input(column=column) elif mode == Mode.display: put_display_cursor(column=column) else: pass # Mode.commmand handled at the end of this fcn # Delete text: ed d m command # start,end are line numbers before delete, destination == win.buf.dot elif op == Op.delete: win.delete(destination) for w in windows: if w.samebuf(win): w.adjust_delete(start, end, destination) # Change text: ed s command # Update all lines in start..destination, don't know which lines changed elif op == Op.mutate: win.mutate(origin, start, destination) for w in windows: if w.samebuf(win): if w.intersects(start, destination): w.mutate_lines(start, destination) # Switch to next window, edsel o command elif op == Op.next: w0 = win w0.release_focus() w0.update_status() ifocus = ifocus+1 if ifocus+1 < len(windows) else 0 win = windows[ifocus] win.set_focus() win.update_status() # Delete all but current window, edsel o1 cmd elif op == Op.single: windows[:] = [win] ifocus = 0 win.resize(frame_top, windows_h-1, ncols) # one window, -1 excl status win.reupdate() # Split window, new window above becomes current window, edsel o2 command elif op == Op.hsplit: win_top = win.top win_nlines = win.nlines // 2 w0 = win w0.release_focus() w0.resize(win_top + win_nlines, w0.nlines - win_nlines, ncols) w0.move_update(w0.saved_dot) win = window.Window(win.buf,win_top,win_nlines-1,ncols) #-1 excl status win.focus = True windows.insert(ifocus, win) win.reupdate() # Update status line for given buffer in all of its windows elif op == Op.status: for w in windows: if w.buf == buffer: w.update_status() # In command mode put ed command cursor back in scrolling command region. # Then we can call standard Python input() or Piety Console restart(). if mode == Mode.command: put_command_cursor(column=column) # background task can set column # Each Op... case handles other modes, see refresh() and Op.refresh # Is that necessary? I recall it's because some cases use default column=1 return win # caller might need to know which window was selected
def put_display_cursor(column=1): wdot = win.wline(win.buf.dot) display.put_cursor(wdot,column)
def put_command_cursor(column=1): 'Put cursor at input line in scrolling command region, at given column' display.put_cursor(cmd_n, column) # last line on display