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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9b76efa6dcbdfe7a9f2184c7823b6c0292a6ce8b35ed44378679c06b0c847503
4
- data.tar.gz: cda10863c00442ecd0a5c24c5758251bcfa1bb04b84f623843c2b6df30d1ead5
3
+ metadata.gz: 956a007844ac17a49095d8a202f0c776b6b00937f090484c5f46a266e71b6fb8
4
+ data.tar.gz: 41627a82833e4b75dea99ad96e2e6be6f92f6795b20ee89675d80e048777919b
5
5
  SHA512:
6
- metadata.gz: 3251caa055e0e5e60b9cac6981e81b52c083eebf06c5c5a4d4e2f115171f4445ed79142694ef514c1f067aed13276f0e03230f85896e8fce425804abb2cbbd16
7
- data.tar.gz: '04008b119d99774c298f20f3d631a938221be60951df86e8e1c0eb6630060f3762561cfc62798f6cfa65746465c1b704febf63f1834dda82da248679d5adc6ea'
6
+ metadata.gz: 1fb5a56058312251ff31bc8331424440b856156b1cfa6403ee428c363a872cb0a8635bb9d86a16e0aef65737da0fd8973167f49eaa720bb7604f3e7fe9081903
7
+ data.tar.gz: ed83c9c9c93bd6c065d46f62664e355454b677f8cac01d5018774c418b7f5f231db335f2e66c9c6cb16c28829b30ae886f5c3b63240e32f612bd8ac709c9adc7
@@ -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=false)
12
+ def call(user_input, sys_cmd_mode)
13
13
  user_input = user_input.strip
14
- return handle_system_command(user_input, sys_cmd_mode) if user_input.start_with?(*Config.get("sys_cmd", "activate_keywords"))
15
- return handle_exit if Config.get("shell", "exit_keywords").include?(user_input)
16
- return unless user_input.start_with?("/")
17
- if user_input == "/help"
18
- handle_help
19
- elsif user_input == "/config"
20
- handle_config
21
- elsif user_input =~ /^\/prompt\s*/
22
- if user_input == "/prompt"
23
- handle_prompt
24
- else
25
- handle_choose_prompt(user_input.split(" ").last)
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(user_input, sys_cmd_mode)
31
- Config.get("sys_cmd", "activate_keywords").each do |sub_str|
32
- if user_input.start_with?(sub_str)
33
- cmd = user_input[sub_str.length..-1].strip
34
- return SYS_CHAT_CODE if Config.get("sys_cmd", "deactivate_keywords").include?(cmd) && sys_cmd_mode
35
- if (match = /^cd\s?(.*)$/.match(cmd))
36
- Dir.chdir(File.expand_path(match[1].empty? ? "~" : match[1]))
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, current_cmd_prefix), true))
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, _ = Command.call(user_content, sys_cmd_mode)
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, current_cmd_prefix)
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#{current_cmd_prefix}\e[0m"
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
@@ -1,3 +1,3 @@
1
1
  module Richat
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
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.0
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.4.10
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