split command execution to their own functions
This commit is contained in:
parent
92f9561e81
commit
26e76a3699
@ -295,12 +295,23 @@ class Command_prompt(Label):
|
|||||||
# parse command line
|
# parse command line
|
||||||
self.parse_argv()
|
self.parse_argv()
|
||||||
|
|
||||||
|
# single letter commands (which can be combined)
|
||||||
# write
|
# write
|
||||||
if self.argv[0]=="w" or self.argv[0]=="w!" or self.argv[0]=="wq":
|
if self.argv[0]=="w" or self.argv[0]=="w!" or self.argv[0]=="wq":
|
||||||
if len(self.argv)>2:
|
self.run_write(self.argv)
|
||||||
|
# edit file
|
||||||
|
if self.argv[0]=="e":
|
||||||
|
self.run_edit(self.argv)
|
||||||
|
# quit
|
||||||
|
if self.argv[0]=="q" or self.argv=="wq":
|
||||||
|
self.app.stop()
|
||||||
|
|
||||||
|
# wrie to file
|
||||||
|
def run_write(self,argv):
|
||||||
|
if len(argv)>2:
|
||||||
self.message="error: could not write to file: too many arguments -- usage: ':w [path to file]'"
|
self.message="error: could not write to file: too many arguments -- usage: ':w [path to file]'"
|
||||||
return
|
return
|
||||||
elif len(self.argv)==1:
|
elif len(argv)==1:
|
||||||
if self.app.openfile!="":
|
if self.app.openfile!="":
|
||||||
if self.app.readonly:
|
if self.app.readonly:
|
||||||
self.message="error: open file is readonly"
|
self.message="error: open file is readonly"
|
||||||
@ -311,50 +322,45 @@ class Command_prompt(Label):
|
|||||||
self.message="error: no file is open for editing, specify a path"
|
self.message="error: no file is open for editing, specify a path"
|
||||||
return
|
return
|
||||||
|
|
||||||
(ret,self.message)=filecheck.check_write(self.argv[1],self.argv[0]=="w!")
|
(ret,self.message)=filecheck.check_write(argv[1],argv[0]=="w!")
|
||||||
# add comment if no overwrite
|
# add comment if no overwrite
|
||||||
if ret==-2:
|
if ret==-2:
|
||||||
self.message+=" (use ':w!' to overwrite)"
|
self.message+=" (use ':w!' to overwrite)"
|
||||||
if ret<0:
|
if ret<0:
|
||||||
return
|
return
|
||||||
|
|
||||||
self.app.openfile=self.argv[1]
|
self.app.openfile=argv[1]
|
||||||
self.app.readonly=False
|
self.app.readonly=False
|
||||||
self.app.painter.write(self.argv[1])
|
self.app.painter.write(argv[1])
|
||||||
# update status bar
|
# update status bar
|
||||||
self.app.status_bar.draw()
|
self.app.status_bar.draw()
|
||||||
|
|
||||||
# edit file
|
def run_edit(self,argv):
|
||||||
if self.argv[0]=="e":
|
if len(argv)>2:
|
||||||
if len(self.argv)>2:
|
|
||||||
self.message="error: could not open file: too many arguments -- usage: ':e <path to file>'"
|
self.message="error: could not open file: too many arguments -- usage: ':e <path to file>'"
|
||||||
return
|
return
|
||||||
elif len(self.argv)==1:
|
elif len(argv)==1:
|
||||||
self.message="error: could not open file: no argument found -- usage: ':e <path to file>'"
|
self.message="error: could not open file: no argument found -- usage: ':e <path to file>'"
|
||||||
return
|
return
|
||||||
|
|
||||||
# check that the file can be edited
|
# check that the file can be edited
|
||||||
(ret,self.message)=filecheck.check_edit(self.argv[1])
|
(ret,self.message)=filecheck.check_edit(argv[1])
|
||||||
# error
|
# error
|
||||||
if ret<0:
|
if ret<0:
|
||||||
return
|
return
|
||||||
|
|
||||||
if os.path.isfile(self.argv[1]):
|
if os.path.isfile(argv[1]):
|
||||||
# read the file
|
# read the file
|
||||||
self.app.painter.read(self.argv[1])
|
self.app.painter.read(argv[1])
|
||||||
# set readonly mode
|
# set readonly mode
|
||||||
self.app.readonly=not os.access(self.argv[1],os.W_OK)
|
self.app.readonly=not os.access(argv[1],os.W_OK)
|
||||||
else:
|
else:
|
||||||
# new file, reset painter
|
# new file, reset painter
|
||||||
self.app.painter.reset()
|
self.app.painter.reset()
|
||||||
self.app.readonly=False
|
self.app.readonly=False
|
||||||
|
|
||||||
# select openfile in app
|
# select openfile in app
|
||||||
self.app.openfile=self.argv[1]
|
self.app.openfile=argv[1]
|
||||||
# update status bar
|
# update status bar
|
||||||
self.app.status_bar.draw()
|
self.app.status_bar.draw()
|
||||||
|
|
||||||
# quit
|
|
||||||
if self.argv[0]=="q" or self.argv=="wq":
|
|
||||||
self.app.stop()
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user