Class: SnippetCli::Commands::New
Constant Summary
SnippetGenerator::NEW_LINE, SnippetGenerator::QUOTE
Instance Method Summary
collapse
#heading_snippet_export, #initialize_espanso_yml, #input_form_snippet_export, #picklist_snippet_export, #single_snippet_export, #textarea_snippet_export
#command, #cursor, #editor, #exec_exist?, #generator, #pager, #platform, #prompt, #screen, #which
Constructor Details
#initialize(options) ⇒ New
34
35
36
37
38
|
# File 'lib/snippet_cli/commands/new.rb', line 34
def initialize(options)
@options = options
@file_path = File.readlines("#{ENV["HOME"]}/snippet_cli_config.txt")[1]
@file_path = Ascii.process(@file_path)
end
|
Instance Method Details
#but_first ⇒ Object
40
41
42
43
44
45
46
47
48
|
# File 'lib/snippet_cli/commands/new.rb', line 40
def but_first()
puts @leading
puts "Now you'll enter what you want replaced."
puts @leading
puts "But first ..."
puts @leading
prompt.error("Don't use tabs. YAML hates them and it leads to unpredictable results.")
puts @leading
end
|
#execute(input: $stdin, output: $stdout) ⇒ Object
106
107
108
109
110
|
# File 'lib/snippet_cli/commands/new.rb', line 106
def execute(input: $stdin, output: $stdout)
output.puts show_banner()
new_form()
end
|
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/snippet_cli/commands/new.rb', line 50
def new_form()
puts "Let's add a new snippet to your configuration"
puts @leading
snippet_type = prompt.select("Do you want a Snippet or a Snippet with a form?") do ||
.enum "."
.choice "A snippet",1
.choice "A snippet with a form",2
.choice "A snippet from Semplificato API",3
end
case snippet_type
when 1
puts @leading
snippet_trigger=prompt.ask("What do you want to type to trigger the snippet?")
puts @leading
puts "Okay, the snippet will be triggered by:"
prompt.ok( ":#{snippet_trigger}")
puts@leading
but_first()
replacement = prompt.multiline("what did you want the trigger to be replaced with?")
if (replacement.length() > 1)
single_snippet_export(@file_path,snippet_trigger,replacement)
else
single_snippet_export(@file_path,snippet_trigger,replacement[0])
end
when 2
puts @leading
snippet_trigger=prompt.ask("What do you want to type to trigger the snippet?")
puts @leading
puts "Okay, the snippet will be triggered by:"
prompt.ok( ":#{snippet_trigger}")
puts@leading
but_first()
newprompt = TTY::Prompt.new
newprompt.warn("For a form field wrap the word in double brackets. Like {{example}}")
puts @leading
newprompt.ok("Also make sure the name of each form field is unique.")
puts @leading
replacement = prompt.multiline("what did you want the trigger to be replaced with?")
if (replacement.length() > 1)
input_form_snippet_export(@file_path,snippet_trigger,replacement)
else
input_form_snippet_export(@file_path,snippet_trigger,replacement[0])
end
when 3
puts @leading
url = prompt.ask("What's the URL of the snippet?",default: "http://localhost:3000/snippets/1")
json_url = url+(".json")
api_response=HTTParty.get(json_url)
response_parsed = api_response.body
single_snippet_export(@file_path,response_parsed['trigger'],response_parsed['replacement'])
puts@leading
prompt.ok("Added snippet from #{url}")
end
end
|
#show_banner ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/snippet_cli/commands/new.rb', line 16
def show_banner()
box = TTY::Box::frame(width:67, height:11, border: :thick, align: :left) do
"
##### # # ### ###### ###### ####### #######
# # ## # # # # # # # #
# # # # # # # # # # #
##### # # # # ###### ###### ##### #
# # # # # # # # #
# # # ## # # # # #
##### # # ### # # ####### # CLI
"
end
puts box
end
|