better_prompt 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1b0275e59070ddcb50314443ed257f616af962ab8e7e328ee78ff337ef106b37
4
- data.tar.gz: 6e2a503dfa2399a1ddf25276647edf7a85422b723aeaf444c01832869d504e8b
3
+ metadata.gz: 13515348dbaad3c336ec4c5f86df8e7ac0262b2168917cddfcd5c81fe2ee6772
4
+ data.tar.gz: dc9fd7012b8b8ba0cc3f23bed6b3d6f10fc69374e4e429fc549ef71ea081ed8b
5
5
  SHA512:
6
- metadata.gz: e14e38212b0ac9b0840647f37acac1f61602e9a5152bce1dff23be3c2836bb658fb5a4c50434be1d1d9a22c9aaecfe0e16ab4f71467ebc35772996679c852117
7
- data.tar.gz: 2614387d896abbfe25104ed50e38c2752fc363d3a876d47368c6f7ea4afb55bc5677f5f56a7a819df9721f61a52db453e83346a887d096648bc4965ec7e6a858
6
+ metadata.gz: 50d86011d7817e5195e4be18f9c6ba973faba7608f18c28f0e1cdfa5dd983c26ca118b29f9579f4c790481bddb335c8c6a29600edd2a9edef223fc0bbfd53d73
7
+ data.tar.gz: a528bf0cd9e2f582f87ee20e9106c45a43fec4fed3f6eb625c684ed47e0ea21f5839e632af1e8eb7a657756b98399a6ddfa6e5cc9380fde2cbbadff1b8d86a9d
@@ -2,7 +2,7 @@ module BetterPrompt
2
2
  module Component
3
3
  class PromptList
4
4
  def self.build
5
- layout = RubyRich::Layout.new(name: "prompt_list", ratio: 4)
5
+ layout = RubyRich::Layout.new(name: "prompt_list", ratio: 4)
6
6
  draw_view(layout)
7
7
  register_event_listener(layout)
8
8
  return layout
@@ -11,41 +11,51 @@ module BetterPrompt
11
11
  def self.draw_view(layout)
12
12
  layout.update_content(RubyRich::Panel.new(
13
13
  "",
14
- title: "提示词列表 (Shift+2)"
14
+ title: "提示词列表 (Shift+2)",
15
15
  ))
16
16
  end
17
17
 
18
18
  def self.update_title(prompt)
19
- result = BetterPrompt.engine.call_worker(:summarize, {text: prompt[:prompt_content]})
20
- prompt[:prompt_title] = result.strip
19
+ result = BetterPrompt.engine.call_worker(:short_title, { text: prompt[:prompt_content] })
20
+ prompt[:prompt_title] = result.dig("choices", 0, "message", "content")
21
21
  prompt.save
22
- return result.strip
22
+ return prompt[:prompt_title]
23
23
  end
24
24
 
25
- def self.update_prompt_list(live, template_name)
25
+ def self.update_prompt_list(live, template_name, page_num = 1, pos = 0)
26
+ @template_name = template_name
27
+ @current_page = page_num
26
28
  prompt_list = live.find_panel("prompt_list")
27
- @prompt_list = BetterPrompt::ORM::Prompt.where(:prompt_template_name=>template_name).all
28
- @page_count = (@prompt_list.size / 9.0).ceil
29
- prompt_list.content = generate_content()
29
+ prompt_list.border_style = :red
30
+ per_page = 9
31
+ ds = BetterPrompt::ORM::Prompt.where(:prompt_template_name => template_name)
32
+ total_count = ds.count
33
+ @page_count = (total_count / per_page.to_f).ceil
34
+ page_num = [page_num.to_i, 1].max
35
+ offset = (page_num - 1) * per_page
36
+ @prompt_list = ds
37
+ .limit(per_page)
38
+ .offset(offset)
39
+ .all
40
+ prompt_list.content = generate_content(pos)
41
+ prompt_list.border_style = :green
30
42
  end
31
43
 
32
- def self.generate_content(pos=0, page_num=1)
44
+ def self.generate_content(pos)
33
45
  i = 0
34
- @current_page = page_num
35
- start_pos = (page_num - 1) * 9
36
- end_pos = start_pos + 9
37
46
  prompt_list_str = ""
47
+ count = @prompt_list.size
38
48
  @prompt_list.each do |prompt|
39
49
  i += 1
40
50
  title = prompt.prompt_title
41
- if title==nil
51
+ if title == nil
42
52
  title = update_title(prompt)
43
53
  end
44
54
  title_width = title.chars.sum { |c| Unicode::DisplayWidth.of(c) }
45
- if title_width>22
55
+ if title_width > 22
46
56
  new_title = ""
47
57
  title.chars.each do |c|
48
- if (new_title+c).chars.sum { |c| Unicode::DisplayWidth.of(c) }>22
58
+ if (new_title + c).chars.sum { |c| Unicode::DisplayWidth.of(c) } > 22
49
59
  new_title += ".."
50
60
  break
51
61
  else
@@ -54,23 +64,23 @@ module BetterPrompt
54
64
  end
55
65
  title = new_title
56
66
  end
57
- if i > start_pos && i <= end_pos
58
- if i-start_pos==pos
59
- prompt_list_str += RubyRich::AnsiCode.color(:blue)+ "#{i-start_pos} #{title}\n" + RubyRich::AnsiCode.reset
67
+ if i > 0 && i <= count
68
+ if i == pos
69
+ prompt_list_str += RubyRich::AnsiCode.color(:blue) + "#{i} #{title}\n" + RubyRich::AnsiCode.reset
60
70
  else
61
- prompt_list_str += RubyRich::AnsiCode.color(:blue)+ "#{i-start_pos}" + RubyRich::AnsiCode.reset + " #{title}\n"
71
+ prompt_list_str += RubyRich::AnsiCode.color(:blue) + "#{i}" + RubyRich::AnsiCode.reset + " #{title}\n"
62
72
  end
63
73
  end
64
74
  end
65
- if start_pos>0 or i > end_pos
75
+ if i > count
66
76
  prompt_list_str += " \n" * (25 - prompt_list_str.split("\n").size)
67
77
  end
68
- if start_pos>0
78
+ if @current_page > 1
69
79
  prompt_list_str += " " * 11 + "←" + " " * 2
70
80
  else
71
- prompt_list_str += " " * 14
81
+ prompt_list_str += " " * 14
72
82
  end
73
- if i > end_pos
83
+ if @current_page < @page_count
74
84
  prompt_list_str += " " * 2 + "→"
75
85
  end
76
86
  return prompt_list_str
@@ -81,8 +91,8 @@ module BetterPrompt
81
91
  prompt_list = live.find_panel("prompt_list")
82
92
  if prompt_list.border_style == :green
83
93
  if event[:value].to_i >= 1 && event[:value].to_i <= @prompt_list.count
84
- prompt_list.content = generate_content(event[:value].to_i, @current_page)
85
- prompt = @prompt_list[(@current_page - 1)*9+event[:value].to_i-1]
94
+ update_prompt_list(live, @template_name, @current_page, event[:value].to_i)
95
+ prompt = @prompt_list[event[:value].to_i - 1]
86
96
  dialog = ShowPrompt.build(prompt.prompt_content, live)
87
97
  live.layout.show_dialog(dialog)
88
98
  Response.clean
@@ -93,20 +103,20 @@ module BetterPrompt
93
103
  layout.key(:right) do |event, live|
94
104
  prompt_list = live.find_panel("prompt_list")
95
105
  if prompt_list.border_style == :green
96
- if @current_page<@page_count
97
- prompt_list.content = generate_content(0, @current_page+1)
106
+ if @current_page < @page_count
107
+ update_prompt_list(live, @template_name, @current_page + 1)
98
108
  end
99
109
  end
100
110
  end
101
111
  layout.key(:left) do |event, live|
102
112
  prompt_list = live.find_panel("prompt_list")
103
113
  if prompt_list.border_style == :green
104
- if @current_page>1
105
- prompt_list.content = generate_content(0, @current_page-1)
114
+ if @current_page > 1
115
+ update_prompt_list(live, @template_name, @current_page - 1)
106
116
  end
107
117
  end
108
118
  end
109
119
  end
110
120
  end
111
121
  end
112
- end
122
+ end
@@ -1,3 +1,3 @@
1
1
  module BetterPrompt
2
- VERSION = "0.2.0"
3
- end
2
+ VERSION = "0.2.2"
3
+ end
data/lib/better_prompt.rb CHANGED
@@ -141,7 +141,6 @@ module BetterPrompt
141
141
  if @engine == nil
142
142
  file_path = "./config/config.yml"
143
143
  file_path = "./config/llm_config.yml" unless File.exist?(file_path)
144
- BetterPrompt.logger.info(file_path)
145
144
  @engine = SmartPrompt::Engine.new(file_path)
146
145
  end
147
146
  return @engine
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: better_prompt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - zhuang biaowei
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: 0.3.1
18
+ version: 0.4.0
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
- version: 0.3.1
25
+ version: 0.4.0
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: sqlite3
28
28
  requirement: !ruby/object:Gem::Requirement
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
126
  requirements: []
127
- rubygems_version: 3.6.9
127
+ rubygems_version: 4.0.0
128
128
  specification_version: 4
129
129
  summary: A better command line prompt utility
130
130
  test_files: []