-
Notifications
You must be signed in to change notification settings - Fork 0
/
terminal.rb
executable file
·95 lines (73 loc) · 2.52 KB
/
terminal.rb
1
2
3
4
5
6
7
8
9
10
11
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#######################################################################
# #
# Terminal class, main user interface #
# #
#######################################################################
require 'colorize'
require 'readline'
# require all core libs
Dir[File.dirname(__FILE__) + '/lib/core/*.rb'].each {|file| require file }
class Terminal
@@path = ""
public
def initialize(dir)
Core.setBaseDir(dir)
@@completions = TxtCompletion.getComps()
end
####################################################
# Start ganymed #
####################################################
def startGanymed()
printBanner()
startConsole()
end
private
####################################################
# Prints welcome banner #
####################################################
def printBanner()
puts ""
puts Banner.getBanner()
puts "http://www.ne4y-dev.de"
puts ""
puts Module.getVersion()
puts ""
end
####################################################
# Returns displaying path #
####################################################
def getPath()
@@path.empty? ? (path = "gnm > ".green) : (path = "gnm".green + " (#{@@path})".blue + " > ".green)
return path
end
####################################################
# Starts user interaction #
####################################################
def startConsole()
# test for text completion
comp = proc { |s| @@completions.grep(/^#{Regexp.escape(s)}/) }
Readline.completion_append_character = " "
Readline.completer_word_break_characters = ""
Readline.completion_proc = comp
while line = Readline.readline(getPath(), true)
cParser = CommandParser.new(line)
cParser.execute()
@@completions = TxtCompletion.getComps()
comp = proc { |s| @@completions.grep(/^#{Regexp.escape(s)}/) }
Readline.completion_proc = comp
puts ""
end
end
####################################################
# Get path #
####################################################
def self.getPath()
return @@path
end
####################################################
# Set path #
####################################################
def self.setPath(path)
@@path = path
end
end