changeset 20:f39963e96ca1

Rework of the help string code Instead of having all the help strings in the command table, we just shove them into the __doc__ for each of the function handlers. This means that no one function can handle two different functionalities as their help string space would collide. This is fine most of the time anyway. However, the considerably cleaner command table is a major plus. The only other "negative" side-effect is the fact that we need to make sure that the first two lines of the function handler are in the right format. First line: the command along with any optional or mandatory arguments Second line: "\t - " followed by a one line description of what the command does. Subsequent lines: All subsequent lines are currently ignored, however it would be nice to display the entire __doc__ string content when something like "h <help string>"-type functionality is implemented.
author Josef "Jeff" Sipek <jeffpc@josefsipek.net>
date Sun, 20 Aug 2006 01:00:29 -0400
parents a3385f616b53
children dfcf1a46fc56
files vixm/control.py vixm/ui.py
diffstat 2 files changed, 55 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/vixm/control.py	Sun Aug 20 00:31:33 2006 -0400
+++ b/vixm/control.py	Sun Aug 20 01:00:29 2006 -0400
@@ -3,15 +3,29 @@
 import playlist, util
 
 def cmd_quit(ui, start, stop, args):
+	"""q[!]
+		- quit
+	Quits the program. The optional '!' forces the termination
+	regardless of any unsaved work"""
 	ui.shutdown = True
 
 def cmd_number(ui, start, stop, args):
+	"""[range]n [playlistid]
+		- print the addressed lines
+	The lines are printed along with the line/song numbers. See also: 'l'"""
 	do_list(ui, start, stop, True, args)
 
 def cmd_list(ui, start, stop, args):
+	"""[range]l [playlistid]
+		- print the addressed lines
+	See also: 'n'"""
 	do_list(ui, start, stop, False, args)
 
 def cmd_enqueue(ui, start, stop, args):
+	"""a [songid]
+		- appends/enqueues a song
+	A song at songid position in LIST_DEFAULT is appended to the end of
+	the LIST_PRIO playlist. Duplicates are _NOT_ eliminated."""
 	try:
 		id = int(args[0])-1
 
@@ -28,6 +42,10 @@
 	ui.lists[playlist.LIST_PRIO].enqueue(s)
 
 def cmd_dequeue(ui, start, stop, args):
+	"""[range]d
+		- delete/dequeue addressed songs
+	Songs in range are removed from the LIST_PRIO playlist. They still
+	remain in the LIST_DEFAULT at their original locations."""
 	l = ui.lists[playlist.LIST_PRIO]
 
 	max = len(l)
@@ -44,8 +62,14 @@
 		l.dequeue(s)
 
 def cmd_help(ui, start, stop, args):
-	for c in args[0]:
-		print "  %s\t%s" % (args[0][c][2],args[0][c][3])
+	"""h
+		- this help screen"""
+	keys = args[0].keys()
+	keys.sort()
+	for c in keys:
+		text = args[0][c][0].__doc__.split("\n")[0:2]
+		text = "\n".join(text)
+		print "  %s" % (text,)
 
 def do_list(ui, start, stop, number, args):
 	# get the list id from the argument or default to
@@ -92,21 +116,33 @@
 		i += 1
 
 def cmd_play(ui, start, stop, args):
+	"""x
+		- Direct XMMS control: play"""
 	xmms.control.play()
 
 def cmd_pause(ui, start, stop, args):
+	"""c
+		- Direct XMMS control: pause"""
 	xmms.control.pause()
 
 def cmd_stop(ui, start, stop, args):
+	"""v
+		- Direct XMMS control: stop"""
 	xmms.control.stop()
 
 def cmd_prev(ui, start, stop, args):
+	"""z
+		- Direct XMMS control: previous song"""
 	xmms.control.playlist_prev()
 
 def cmd_next(ui, start, stop, args):
+	"""b
+		- Direct XMMS control: next song"""
 	xmms.control.playlist_next()
 
 def cmd_shell(ui, start, stop, args):
+	"""![command]
+		- Execute a shell command"""
 	if args[0]:
 		os.system(args[0])
 	print "!"
--- a/vixm/ui.py	Sun Aug 20 00:31:33 2006 -0400
+++ b/vixm/ui.py	Sun Aug 20 01:00:29 2006 -0400
@@ -110,65 +110,44 @@
 		self.cmdtable = {
 			"q([!]){,1}":
 				(control.cmd_quit,
-				 False,
-				 "q[!]",
-				 "quit"),
-			"n( ([0-9]+)){,1}":
+				 False),
+			"n( *([0-9]+)){,1}":
 				(control.cmd_number,
-				 True,
-				 "[range]n [playlistid]",
-				 "numbered display of lines in range in playlistid"),
-			"l( ([0-9]+)){,1}":
+				 True),
+			"l( *([0-9]+)){,1}":
 				(control.cmd_list,
-				 True,
-				 "[range]l [playlistid]",
-				 "list lines in range in playlistid"),
-			"a ([0-9]+)":
+				 True),
+			"a *([0-9]+)":
 				(control.cmd_enqueue,
-				 False,
-				 "a [songid]",
-				 "add songid from default to priority"),
+				 False),
 			"d":
 				(control.cmd_dequeue,
-				 True,
-				 "[range]d",
-				 "remove songs in range from priority"),
+				 True),
 			"h":
 				(control.cmd_help,
-				 False,
-				 "h",
-				 "this help list"),
+				 False),
 			# the following commands are there do allow some,
 			# more direct control over xmms
 			"z":
 				(control.cmd_prev,
-				 "z",
-				 "previous item in playlist"),
+				 False),
 			"x":
 				(control.cmd_play,
-				 False,
-				 "x",
-				 "play"),
+				 False),
 			"c":
 				(control.cmd_pause,
-				 False,
-				 "c",
-				 "pause"),
+				 False),
 			"v":
 				(control.cmd_stop,
-				 False,
-				 "v",
-				 "stop"),
+				 False),
 			"b":
 				(control.cmd_next,
-				 False,
-				 "b",
-				 "next item in playlist"),
+				 False),
+			# the following commands are there to make the
+			# experience more like ed/ex/vi/vim
 			"!(.*)":
 				(control.cmd_shell,
-				 False,
-				 "![cmd]",
-				 "execute a shell command"),
+				 False),
 		}
 
 	def __cmd(self, txt):