File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change 1
1
require " ./dev_journal/*"
2
2
3
3
module DevJournal
4
- # TODO Put your code here
5
4
end
6
5
7
6
DevJournal ::CLI .run
Original file line number Diff line number Diff line change 1
1
require " option_parser"
2
2
require " colorize"
3
+ require " tempfile"
3
4
4
5
module DevJournal
5
6
class CLI
@@ -20,7 +21,7 @@ module DevJournal
20
21
case
21
22
when @search_text then search
22
23
when @clear_last_entry then clear_last_entry
23
- when @argv [0 ]? && @argv [0 ] == " -" then stdin_input
24
+ when @argv [0 ]? && @argv [0 ] == " -" then editor_input
24
25
when @argv [0 ]? then argv_input
25
26
else show_recent_entries
26
27
end
@@ -52,6 +53,21 @@ module DevJournal
52
53
end
53
54
end
54
55
56
+ def editor_input
57
+ body = [] of String
58
+ editor = ENV .fetch(" EDITOR" , " vim" )
59
+
60
+ tempfile = Tempfile .new(" devjournal" )
61
+ system(editor, [tempfile.path])
62
+
63
+ if $? .normal_exit?
64
+ body = File .read_lines(tempfile.path)
65
+ add_entry(body.join(" \n " ))
66
+ end
67
+
68
+ tempfile.unlink
69
+ end
70
+
55
71
def stdin_input
56
72
lines = [] of String
57
73
You can’t perform that action at this time.
0 commit comments