richat 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/richat/command.rb +30 -28
- data/lib/richat/shell.rb +4 -8
- data/lib/richat/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 956a007844ac17a49095d8a202f0c776b6b00937f090484c5f46a266e71b6fb8
|
4
|
+
data.tar.gz: 41627a82833e4b75dea99ad96e2e6be6f92f6795b20ee89675d80e048777919b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1fb5a56058312251ff31bc8331424440b856156b1cfa6403ee428c363a872cb0a8635bb9d86a16e0aef65737da0fd8973167f49eaa720bb7604f3e7fe9081903
|
7
|
+
data.tar.gz: ed83c9c9c93bd6c065d46f62664e355454b677f8cac01d5018774c418b7f5f231db335f2e66c9c6cb16c28829b30ae886f5c3b63240e32f612bd8ac709c9adc7
|
data/lib/richat/command.rb
CHANGED
@@ -9,41 +9,43 @@ module Richat
|
|
9
9
|
class << self
|
10
10
|
attr_reader :prompt, :prompt_id
|
11
11
|
|
12
|
-
def call(user_input, sys_cmd_mode
|
12
|
+
def call(user_input, sys_cmd_mode)
|
13
13
|
user_input = user_input.strip
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
if user_input == "/
|
23
|
-
|
24
|
-
|
25
|
-
|
14
|
+
|
15
|
+
if sys_cmd_mode
|
16
|
+
return SYS_CHAT_CODE if Config.get("sys_cmd", "deactivate_keywords").include?(user_input)
|
17
|
+
handle_system_command(user_input)
|
18
|
+
else
|
19
|
+
return SYS_CMD_CODE if Config.get("sys_cmd", "activate_keywords").include?(user_input)
|
20
|
+
return handle_exit if Config.get("shell", "exit_keywords").include?(user_input)
|
21
|
+
return unless user_input.start_with?("/")
|
22
|
+
if user_input == "/help"
|
23
|
+
handle_help
|
24
|
+
elsif user_input == "/config"
|
25
|
+
handle_config
|
26
|
+
elsif user_input =~ /^\/prompt\s*/
|
27
|
+
if user_input == "/prompt"
|
28
|
+
handle_prompt
|
29
|
+
else
|
30
|
+
handle_choose_prompt(user_input.split(" ").last)
|
31
|
+
end
|
26
32
|
end
|
27
33
|
end
|
28
34
|
end
|
29
35
|
|
30
|
-
def handle_system_command(
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
else
|
38
|
-
system(cmd)
|
39
|
-
end
|
40
|
-
if sys_cmd_mode
|
41
|
-
return NEXT_CODE
|
42
|
-
else
|
43
|
-
return SYS_CMD_CODE, sub_str
|
44
|
-
end
|
36
|
+
def handle_system_command(cmd)
|
37
|
+
if (match = /^cd\s?(.*)$/.match(cmd))
|
38
|
+
fp = File.expand_path(match[1].empty? ? "~" : match[1])
|
39
|
+
begin
|
40
|
+
Dir.chdir(fp)
|
41
|
+
rescue
|
42
|
+
puts "cd: no such file or directory: #{fp}"
|
45
43
|
end
|
44
|
+
else
|
45
|
+
system(cmd)
|
46
46
|
end
|
47
|
+
|
48
|
+
NEXT_CODE
|
47
49
|
end
|
48
50
|
|
49
51
|
def handle_exit
|
data/lib/richat/shell.rb
CHANGED
@@ -34,20 +34,17 @@ module Richat
|
|
34
34
|
|
35
35
|
Command.print_welcome if Config.get("shell", "show_welcome_info")
|
36
36
|
sys_cmd_mode = false
|
37
|
-
current_cmd_prefix = nil
|
38
37
|
|
39
38
|
begin
|
40
|
-
while (user_content = Readline.readline(shell_prompt(sys_cmd_mode
|
39
|
+
while (user_content = Readline.readline(shell_prompt(sys_cmd_mode), true))
|
41
40
|
if user_content.empty?
|
42
41
|
Readline::HISTORY&.pop
|
43
42
|
next
|
44
43
|
end
|
45
44
|
|
46
|
-
user_content = current_cmd_prefix + user_content if sys_cmd_mode
|
47
45
|
File.open(history_path, 'a') { |f| f.puts(user_content) } if enable_full_completion
|
48
46
|
|
49
|
-
code
|
50
|
-
if code
|
47
|
+
if (code = Command.call(user_content, sys_cmd_mode))
|
51
48
|
if code == Command::NEXT_CODE
|
52
49
|
next
|
53
50
|
elsif code == Command::EXIT_CODE
|
@@ -57,7 +54,6 @@ module Richat
|
|
57
54
|
next
|
58
55
|
elsif code == Command::SYS_CMD_CODE
|
59
56
|
sys_cmd_mode = true
|
60
|
-
current_cmd_prefix = _
|
61
57
|
next
|
62
58
|
elsif code == Command::SYS_CHAT_CODE
|
63
59
|
sys_cmd_mode = false
|
@@ -98,9 +94,9 @@ module Richat
|
|
98
94
|
|
99
95
|
private
|
100
96
|
|
101
|
-
def shell_prompt(sys_cmd_mode
|
97
|
+
def shell_prompt(sys_cmd_mode)
|
102
98
|
if sys_cmd_mode
|
103
|
-
"\e[32m#{Command.prompt_id&.+" "}\e[0m\e[33m>>\e[0m \e[32m
|
99
|
+
"\e[32m#{Command.prompt_id&.+" "}\e[0m\e[33m>>\e[0m \e[32m$ \e[0m"
|
104
100
|
else
|
105
101
|
"\e[32m#{Command.prompt_id&.+" "}\e[0m\e[33m>> \e[0m"
|
106
102
|
end
|
data/lib/richat/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: richat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- fzdp
|
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
110
|
requirements: []
|
111
|
-
rubygems_version: 3.
|
111
|
+
rubygems_version: 3.0.9
|
112
112
|
signing_key:
|
113
113
|
specification_version: 4
|
114
114
|
summary: Richat is a command-line ChatGPT tool
|