require "bubbletea" require "lipgloss" class Counter include Bubbletea::Model def initialize @title_style = Lipgloss::Style.new.bold(true).foreground("212") @help_style = Lipgloss::Style.new.foreground("241") @prompt = File.readlines("prompts.txt").map(&:chomp) @cursor = 0 @choice = nil end def init [self, nil] end def update(message) case message when Bubbletea::KeyMessage case message.to_s when "q", "ctrl+c" [self, Bubbletea.quit] when "enter" @cursor += 1 @choice = @prompt[@cursor] [self, nil] else [self, nil] end else [self, nil] end end def view lines = [] lines << @title_style.render("#{@choice}") lines << "" lines << @help_style.render("Press q to quit or enter for a new prompt") lines.join("\n") end end Bubbletea.run(Counter.new)