Skip to content

Commit 94dbaec

Browse files
committed
Fix stty output when using stdin for input
Predoc uses the Argy-Bargy library to handle argument parsing. On non-Windows platforms, Argy-Bargy uses stty for internal purposes. This would cause an error when the input for Predoc was stdin. Argy-Bargy has been updated to direct error messages to /dev/null. This fixes #11 on GitHub Issues.
1 parent 59dda3c commit 94dbaec

1 file changed

Lines changed: 19 additions & 11 deletions

File tree

deps/argy-bargy/argy-bargy.janet

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@
111111
(++ i))
112112
subconfigs)
113113

114+
(defn devnull
115+
```
116+
Gets the /dev/null equivalent for the current platform as a file
117+
```
118+
[]
119+
(os/open (if (= :windows (os/which)) "NUL" "/dev/null") :rw))
120+
114121

115122
(defn- get-cols
116123
```
@@ -125,17 +132,18 @@
125132
(if win?
126133
["powershell" "-command" "&{(get-host).ui.rawui.WindowSize.Width;}"]
127134
["stty" "size"]))
128-
(with [f (file/temp)]
129-
(def exit-code (os/execute cmd :p {:out f :err nil}))
130-
(if (zero? exit-code)
131-
(do
132-
(file/seek f :set 0)
133-
(def out (string/trim (file/read f :all)))
134-
(def tcols (if win?
135-
(scan-number out)
136-
(scan-number (-> (string/split " " out) (get 1)))))
137-
(min tcols max-width))
138-
max-width)))))
135+
(with [null (devnull)]
136+
(with [f (file/temp)]
137+
(def exit-code (os/execute cmd :p {:out f :err null}))
138+
(if (zero? exit-code)
139+
(do
140+
(file/seek f :set 0)
141+
(def out (string/trim (file/read f :all)))
142+
(def tcols (if win?
143+
(scan-number out)
144+
(scan-number (-> (string/split " " out) (get 1)))))
145+
(min tcols max-width))
146+
max-width))))))
139147

140148

141149
(defn- get-rule

0 commit comments

Comments
 (0)