openclacky 0.5.3 → 0.5.5

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.
@@ -1,72 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "tty-prompt"
4
- require "pastel"
5
- require "tty-screen"
6
-
7
- module Clacky
8
- module UI
9
- # Enhanced input prompt with box drawing and status info
10
- class Prompt
11
- def initialize
12
- @pastel = Pastel.new
13
- @tty_prompt = TTY::Prompt.new(interrupt: :exit)
14
- end
15
-
16
- # Read user input with enhanced prompt box
17
- # @param prefix [String] Prompt prefix (default: "You:")
18
- # @param placeholder [String] Placeholder text (not shown when using TTY::Prompt)
19
- # @return [String, nil] User input or nil on EOF
20
- def read_input(prefix: "You:", placeholder: nil)
21
- width = [TTY::Screen.width - 5, 70].min
22
-
23
- # Display complete box frame first
24
- puts @pastel.dim("╭" + "─" * width + "╮")
25
-
26
- # Empty input line - NO left border, just spaces and right border
27
- padding = " " * width
28
- puts @pastel.dim("#{padding} │")
29
-
30
- # Bottom border
31
- puts @pastel.dim("╰" + "─" * width + "╯")
32
-
33
- # Move cursor back up to input line (2 lines up)
34
- print "\e[2A" # Move up 2 lines
35
- print "\r" # Move to beginning of line
36
-
37
- # Read input with TTY::Prompt
38
- prompt_text = @pastel.bright_blue("#{prefix}")
39
- input = read_with_tty_prompt(prompt_text)
40
-
41
- # After input, clear the input box completely
42
- # Move cursor up 2 lines to the top of the box
43
- print "\e[2A"
44
- print "\r"
45
-
46
- # Clear all 3 lines of the box
47
- 3.times do
48
- print "\e[2K" # Clear entire line
49
- print "\e[1B" # Move down 1 line
50
- print "\r" # Move to beginning of line
51
- end
52
-
53
- # Move cursor back up to where the box started
54
- print "\e[3A"
55
- print "\r"
56
-
57
- input
58
- end
59
-
60
- private
61
-
62
- def read_with_tty_prompt(prompt)
63
- @tty_prompt.ask(prompt, required: false, echo: true) do |q|
64
- q.modify :strip
65
- end
66
- rescue TTY::Reader::InputInterrupt
67
- puts
68
- nil
69
- end
70
- end
71
- end
72
- end