Module: Quiyo::Core

Included in:
Quiyo
Defined in:
lib/quiyo/core.rb

Instance Method Summary collapse

Instance Method Details

#helpObject



50
51
52
# File 'lib/quiyo/core.rb', line 50

def help
	p "Some help text here"
end

#readline_histObject



3
4
5
6
7
8
9
10
# File 'lib/quiyo/core.rb', line 3

def readline_hist
	line = Readline.readline(prompt, true)
	return nil if line.nil?
	if line =~ /^\s*$/ or Readline::HISTORY.to_a[-2] == line
		Readline::HISTORY.pop
	end
	line
end

#showpromptObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/quiyo/core.rb', line 12

def showprompt
	Readline.completion_append_character = " "
	Readline.completion_proc = Proc.new { |str|
		Dir[PATH+str+'*'].grep( /^#{Regexp.escape(str)}/ )
	}

	while line = self.readline_hist
		@mpd.connect unless @mpd.connected?
		action = line.split
		actions = {
			"np"              => lambda { nowplaying() },
			"info"            => lambda { info },
			"play"            => lambda { play(action[1]) },
			"pause"           => lambda { pause },
			"stop"            => lambda { stop },
			"next"            => lambda { playnext },
			"previous"        => lambda { playprevious },
			"lsplaylist"      => lambda { lsplist },
			"clearplaylist"   => lambda { clearplist },
			"addtoplaylist"   => lambda { addtoplist(action) },
			"delfromplaylist" => lambda { removefromplist(action[1]) },
			"search"          => lambda { search(action) },
			"list-artists"    => lambda { list("artists") },
			"list-albums"     => lambda { list("albums", action) },
			"love"            => lambda { love },
			"loved"           => lambda { loved },
			"volume"          => lambda { vol(action[1]) },
			"quit"            => lambda { quit },
			"verbose"         => lambda { eval(action.drop(1).join(" ")) }
		}

		CONF["aliases"].each { |k,v| actions[k] = lambda { eval(v) } }

		actions[action[0]].call

	end
end