1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

vfmt: add ability to use vfmt as a filter from stdin to stdout (#8432)

This commit is contained in:
Julia Bogdan Filipchuk
2021-01-30 02:38:54 -08:00
committed by GitHub
parent 7f5d654c3a
commit d26ac0f6cb
4 changed files with 49 additions and 34 deletions

View File

@@ -265,6 +265,25 @@ pub fn get_lines_joined() string {
return inputstr
}
// get_raw_lines_joined reads *all* input lines from stdin.
// It returns them as one large string. NB: unlike os.get_lines_joined,
// empty lines (that contain only `\r\n` or `\n`), will be present in
// the output.
// Reading is stopped, only on EOF of stdin.
pub fn get_raw_lines_joined() string {
mut line := ''
mut lines := []string{}
for {
line = get_raw_line()
if line.len <= 0 {
break
}
lines << line
}
res := lines.join('')
return res
}
// user_os returns current user operating system name.
pub fn user_os() string {
$if linux {

View File

@@ -457,15 +457,7 @@ pub fn parse_args(args []string) (&Preferences, string) {
output_option = '-o "$tmp_exe_file_path"'
}
tmp_v_file_path := '${tmp_file_path}.v'
mut lines := []string{}
for {
iline := os.get_raw_line()
if iline.len == 0 {
break
}
lines << iline
}
contents := lines.join('')
contents := os.get_raw_lines_joined()
os.write_file(tmp_v_file_path, contents) or {
panic('Failed to create temporary file $tmp_v_file_path')
}