extended the ed app
This commit is contained in:
@@ -131,6 +131,21 @@ class Ed:
|
||||
self.dirty = True
|
||||
self.current_line = idx
|
||||
|
||||
elif cmd_char == 'c':
|
||||
if not self.buffer:
|
||||
print("?")
|
||||
continue
|
||||
del self.buffer[start-1 : end]
|
||||
idx = start - 1
|
||||
while True:
|
||||
line = input("")
|
||||
if line == ".":
|
||||
break
|
||||
self.buffer.insert(idx, line)
|
||||
idx += 1
|
||||
self.dirty = True
|
||||
self.current_line = idx
|
||||
|
||||
elif cmd_char == 'd':
|
||||
if not self.buffer:
|
||||
print("?")
|
||||
@@ -139,6 +154,25 @@ class Ed:
|
||||
self.current_line = min(start, len(self.buffer))
|
||||
self.dirty = True
|
||||
|
||||
elif cmd_char == 's':
|
||||
if not self.buffer or not params:
|
||||
print("?")
|
||||
continue
|
||||
# Simple s/old/new/ parser
|
||||
sep = params[0]
|
||||
parts = params.split(sep)
|
||||
if len(parts) < 3:
|
||||
print("?")
|
||||
continue
|
||||
old, new = parts[1], parts[2]
|
||||
start = max(1, start)
|
||||
end = min(len(self.buffer), end)
|
||||
for i in range(start - 1, end):
|
||||
if old in self.buffer[i]:
|
||||
self.buffer[i] = self.buffer[i].replace(old, new)
|
||||
self.dirty = True
|
||||
self.current_line = end
|
||||
|
||||
elif cmd_char == 'w':
|
||||
target = params if params else self.filename
|
||||
if not target:
|
||||
|
||||
Reference in New Issue
Block a user