about summary refs log blame commit diff stats
path: root/tools/termbox/Readme
blob: d97cae4e5eb06f5f08f47221cf8b3024afb483fb (plain) (tree)
1
2

                                                       
Fork of https://github.com/nsf/termbox as of 2015-06-05
git hash 252bef01264a2aeef22ebe5bae0b5893a58947f3
/ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
module Action
	extend self

	def close_interface
		closei
	end

	def start_interface
		starti
	end

	def copy(files, path)
		files = [files] unless files.is_a? Array
		unless files.empty?
			CopyBar.new(files, path)
		end
	end

	def move(files, path)
		files = [files] unless files.is_a? Array
		unless files.empty?
			MoveBar.new(files, path)
		end
	end

	def run(rc = nil)
		rc ||= RunContext.new(Fm.getfiles)
		assert rc, RunContext

		all      = rc.all.or false
		files    = rc.files
		mode     = rc.mode.or 0

		return false if files.nil? or files.empty?

		handler = rc.exec

		return false unless handler

		wait     = rc.wait.or wait
		new_term = rc.new_term.or false
		detach   = rc.detach.or false

		log handler
		if detach
			run_detached(handler, rc)
		else
			run_inside(handler, rc)
		end
		return true
	end

	def run_detached(what, rc)
		if rc.new_term
			p = fork { exec('x-terminal-emulator', '-e', 'bash', '-c', what) }
#			Process.detach(p)
		else
			p = fork { exec "#{what} 2>> /dev/null >> /dev/null" }
			Process.detach(p)
		end
	end

	def run_inside(what, rc)
		close_interface unless rc.console
		system(*what)
		wait_for_enter if rc.wait
		start_interface unless rc.console
		CLI.clear_keybuffer
	end

	def wait_for_enter
		print "Press [ENTER] to continue..."
		$stdin.gets
	end
end