changeset 7:f87b969fa973

Little cleanup; change of plans - try to make it more like ed first
author Josef "Jeff" Sipek <jeffpc@josefsipek.net>
date Sat, 19 Aug 2006 17:23:15 -0400
parents 50745af6a63b
children 79340745c952
files vixm/ui.py
diffstat 1 files changed, 72 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/vixm/ui.py	Fri Aug 18 20:32:00 2006 -0400
+++ b/vixm/ui.py	Sat Aug 19 17:23:15 2006 -0400
@@ -45,30 +45,72 @@
 				util.strtime(s["time"]))
 		self.lists[playlist.LIST_PRIO].enqueue(s)
 
+	def __list(self, cmd, parts):
+		i = 1
+
+		if len(parts) > 1:
+			try:
+				listid = int(parts[1])
+				if listid < 0 or listid >= len(self.lists):
+					raise ValueError
+			except:
+				print "Invalid list number"
+				return
+		else:
+			listid = playlist.LIST_PRIO
+
+		for s in self.lists[listid]:
+			print "%d. %s (%s)" % (i, s["title"],
+					util.strtime(s["time"]))
+			i += 1
+
 	def __cmd(self, txt):
 		parts = txt.split()
 		cmd = parts[0]
 
+		# commad list:
+		#	quit	'q[!]'
+		#		quit fails if there are list changes in
+		#		memory that haven't been saved. The optional
+		#		'!' forces the quit
+		#
+		#	number	'[range]n [playlistid]'
+		#		prints playlist [playlistid] (default is
+		#		LIST_PRIO) with each entry being numbered.
+		#		If optional range is supplied, only the
+		#		songs in that range are printed. The range
+		#		string is standard ed-like line range (see
+		#		below for details)
+		#
+		#	list	'[range]l [playlistid]'
+		#		virtually identical to the number command
+		#		above, however the lines are not numbered.
+		#		The same rules apply to the range and
+		#		playlistid arguments
+		#
+		#	enqueue	'a songid'
+		#		enqueue a song songid from LIST_DEFAULT onto
+		#		LIST_PRIO. The enqueued song is added to the
+		#		end of LIST_PRIO
+		#
+		#	dequeue	'd songid'
+		#		remove songid from LIST_PRIO. The songid is
+		#		the id in LIST_PRIO, NOT LIST_DEFAULT
+		#
+		# range:
+		#	''	first entry; shortcut for '1'
+		#	'%'	entire list; shortcut for '1,$'
+		#	'$'	last entry
+		#	'n'	entry on line n
+		#	'm,n'	range of entries starting on line m and
+		#		ending on line n. Both m and n are included
+		#		in the list. m or n can both be an integer,
+		#		'' or '$'.
+
 		if cmd == "quit":
 			self.shutdown = True
 		elif cmd == "list":
-			i = 1
-
-			if len(parts) > 1:
-				try:
-					listid = int(parts[1])
-					if listid < 0 or listid >= len(self.lists):
-						raise ValueError
-				except:
-					print "Invalid list number"
-					return
-			else:
-				listid = playlist.LIST_PRIO
-
-			for s in self.lists[listid]:
-				print "%d. %s (%s)" % (i, s["title"],
-						util.strtime(s["time"]))
-				i += 1
+			self.__list(cmd, parts)
 		elif cmd == "lists":
 			print "#0 LIST_PRIO"
 			print "#1 LIST_DEFAULT"
@@ -79,18 +121,23 @@
 		while not self.shutdown:
 			tmp = sys.stdin.readline().strip()
 			
-			if tmp.startswith(":"):
-				# ':NNN'
+			# FIXME: we should use regexps for this
+			# 
+			# search:	'^\/(.+)'
+			# enqueue:	'^([0-9]+)'
+			# commands:	'^([A-Za-z]+)(([^ ]*) *)*'
+
+			if tmp.startswith("/"):
+				# '/ABC' - searching
+				print "Searching not yet implemented"
+			else:
+				# 'ABC' - commands and enqueues
 				try:
 					id = int(tmp[1:])
 				except:
 					self.__cmd(tmp[1:])
 					continue
+
+				# we got something numeric, let's enqueue
 				self.__enqueue(id)
 
-			elif tmp.startswith("/"):
-				# '/ABC'
-				print "Searching not yet implemented"
-			else:
-				print "Unable to parse command \"%s\"" % (tmp,)
-