Пример #1
0
import readline
import sys
import argparse
from ed import ed

parser = argparse.ArgumentParser()
parser.add_argument("infile", type=str, help="Input file.")
parser.add_argument("-e", type=str, help="The script.")
parser.add_argument("-f", type=str, help="A file script.", default=None)
parser.add_argument("-n", action="store_true")
args = parser.parse_args()

buffer = ed.Buffer()
buffer.edit(args.infile)

if args.e:
    ed.process(args.e, buffer)
elif args.f:
    lines = (x.strip() for x in open(args.f).readlines())
    for line in lines:
        ed.process(line, buffer)

print("\n".join(buffer.lines))
Пример #2
0
def test_process():
    buffer = ed.Buffer()
    buffer.append('Test')
    buffer.append('Test')
    ed.process(",p", buffer)
    ed.process(",n", buffer)
    ed.process("1p", buffer)
    ed.process("1,2p", buffer)
    ed.process('f tests/out.txt', buffer)
    ed.process("w", buffer)
Пример #3
0
def handle_cmd(ed_cmd):
    if ed_cmd == "q":
        sys.exit(0)
    else:
        ed.process(ed_cmd, buffer)
Пример #4
0
import readline
import sys
from ed import ed

buffer = ed.Buffer()

while True:
    try:
        line = input("> ")
        ed.process(line, buffer)
    except EOFError: 
        print()
        sys.exit(0)
Пример #5
0
def test_process():
    buffer = ed.Buffer()
    buffer.append('Test')
    buffer.append('Test')
    ed.process(",p", buffer)
    ed.process(",n", buffer)
    ed.process("1p", buffer)
    ed.process("1,2p", buffer)
    ed.process('f tests/out.txt', buffer)
    ed.process("w", buffer)
Пример #6
0
import readline
import sys
from ed import ed

buffer = ed.Buffer()

while True:
    try:
        line = input("> ")
        ed.process(line, buffer)
    except EOFError:
        print()
        sys.exit(0)
Пример #7
0
import curses
import time import sys from curses.textpad import Textbox, rectangle from ed import ed  file_to_edit = sys.argv[1] buffer = ed.Buffer(file_name=file_to_edit)  def command(stdscr, repl_y, repl_x):     stdscr.addstr(repl_y, 0, ":")     editwin = curses.newwin(1, repl_x - 1, repl_y, repl_x + 2)     stdscr.refresh()     box = Textbox(editwin)     box.edit()     return box.gather()  def handle_cmd(ed_cmd):     if ed_cmd == "q":         sys.exit(0)
    else:
        ed.process(ed_cmd, buffer)

def main(stdscr):
    max_y, max_x = stdscr.getmaxyx()
    win_y = max_y - 3
    win_x = max_x - 1
    status_y = win_y + 1
    status_x = win_x
    repl_y = status_y + 1
    repl_x = status_x

    pad = curses.newpad(len(buffer.lines) + 1, 100)
    stdscr.addstr(status_y, 0, file_to_edit, curses.A_REVERSE)

    for i, line in enumerate(buffer.lines):
        pad.addstr(i, 0, line)

    cur_y = 0
    pad.refresh(cur_y,0, 0,0, win_y, win_x)
    stdscr.refresh()

    while True:
        key = stdscr.getkey()

        if key == " " or key == "KEY_DOWN":
            if cur_y < len(buffer.lines):
                cur_y += 1
        elif key == "KEY_UP":