1require "bubbletea"
2require "lipgloss"
3
4class Counter
5 include Bubbletea::Model
6
7 def initialize
8 @title_style = Lipgloss::Style.new.bold(true).foreground("212")
9 @help_style = Lipgloss::Style.new.foreground("241")
10 @prompt = File.readlines("prompts.txt").map(&:chomp)
11 @cursor = 0
12 @choice = nil
13 end
14
15 def init
16 [self, nil]
17 end
18
19 def update(message)
20 case message
21 when Bubbletea::KeyMessage
22 case message.to_s
23 when "q", "ctrl+c"
24 [self, Bubbletea.quit]
25 when "enter"
26 @cursor += 1
27 @choice = @prompt[@cursor]
28 [self, nil]
29 else
30 [self, nil]
31 end
32 else
33 [self, nil]
34 end
35 end
36
37 def view
38 lines = []
39 lines << @title_style.render("#{@choice}")
40 lines << ""
41 lines << @help_style.render("Press q to quit or enter for a new prompt")
42 lines.join("\n")
43 end
44end
45
46Bubbletea.run(Counter.new)