implemented edurl and viewurl helpers
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user