implemented edurl and viewurl helpers

This commit is contained in:
Luxferre
2025-12-26 09:59:30 +02:00
parent a1ebcfcb4c
commit ab5c859cee
3 changed files with 30 additions and 10 deletions
+22 -7
View File
@@ -201,20 +201,35 @@ def edit(fname):
editor = Ed(fname)
editor.run()
def edbuf():
def edbuf(bufstr=''):
editor = Ed()
editor.buffer = bufstr.split('\n')
editor.current_line = len(editor.buffer)
editor.run()
return '\n'.join(editor.buffer)
def edurl(url):
from deck.http import http_fetch
status, text = http_fetch(url)
return edbuf(text)
def viewbuf(text, lno=False):
if lno:
buf = text.split('\n')
for i in range(0, len(buf) - 1):
buf[i] = f'{(i+1):<5} {buf[i]}'
text = '\n'.join(buf)
print_paged(text)
def view(fname, lno=False):
try:
with open(fname, 'r') as f:
text = f.read()
if lno:
buf = text.split('\n')
for i in range(0, len(buf) - 1):
buf[i] = f'{(i+1):<5} {buf[i]}'
text = '\n'.join(buf)
print_paged(text)
viewbuf(text, lno)
except:
print('Error opening the input file!')
def viewurl(url, lno=False):
from deck.http import http_fetch
status, text = http_fetch(url)
viewbuf(text, lno)