Skip to content

Commit 249f83e

Browse files
author
José Valim
committed
IO should default to the group leader
1 parent 608f0a3 commit 249f83e

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

lib/elixir/lib/io.ex

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ defmodule IO do
2323
2424
"""
2525

26+
import :erlang, only: [group_leader: 0]
27+
2628
@doc """
2729
Reads `count` bytes from the IO device. It returns:
2830
@@ -34,7 +36,7 @@ defmodule IO do
3436
for instance {:error, :estale} if reading from an
3537
NFS file system.
3638
"""
37-
def read(device // :stdio, count) do
39+
def read(device // group_leader(), count) do
3840
:io.get_chars(map_dev(device), "", count)
3941
end
4042

@@ -44,7 +46,7 @@ defmodule IO do
4446
4547
Check `read/2` for more information.
4648
"""
47-
def binread(device // :stdio, count) do
49+
def binread(device // group_leader(), count) do
4850
case :file.read(map_dev(device), count) do
4951
{ :ok, data } -> data
5052
other -> other
@@ -65,7 +67,7 @@ defmodule IO do
6567
This function does the same as `gets/2`,
6668
except the prompt is not required as argument.
6769
"""
68-
def readline(device // :stdio) do
70+
def readline(device // group_leader()) do
6971
:io.get_line(map_dev(device), "")
7072
end
7173

@@ -75,7 +77,7 @@ defmodule IO do
7577
7678
Check `readline/1` for more information.
7779
"""
78-
def binreadline(device // :stdio) do
80+
def binreadline(device // group_leader()) do
7981
case :file.read_line(map_dev(device)) do
8082
{ :ok, data } -> data
8183
other -> other
@@ -99,7 +101,7 @@ defmodule IO do
99101
#=> "error"
100102
101103
"""
102-
def write(device // :stdio, item) do
104+
def write(device // group_leader(), item) do
103105
:io.put_chars map_dev(device), to_iodata(item)
104106
end
105107

@@ -109,7 +111,7 @@ defmodule IO do
109111
110112
Check `write/2` for more information.
111113
"""
112-
def binwrite(device // :stdio, item) do
114+
def binwrite(device // group_leader(), item) do
113115
:file.write map_dev(device), to_iodata(item)
114116
end
115117

@@ -118,7 +120,7 @@ defmodule IO do
118120
but adds a new line at the end. The argument is expected
119121
to be a chardata.
120122
"""
121-
def puts(device // :stdio, item) do
123+
def puts(device // group_leader(), item) do
122124
erl_dev = map_dev(device)
123125
:io.put_chars erl_dev, [to_iodata(item), ?\n]
124126
end
@@ -127,7 +129,7 @@ defmodule IO do
127129
Inspects and writes the given argument to the device
128130
followed by a new line. Returns the item given.
129131
"""
130-
def inspect(device // :stdio, item, opts // []) do
132+
def inspect(device // group_leader(), item, opts // []) do
131133
puts device, Binary.Inspect.inspect(item, opts)
132134
item
133135
end
@@ -143,7 +145,7 @@ defmodule IO do
143145
for instance {:error, :estale} if reading from an
144146
NFS file system.
145147
"""
146-
def getb(device // :stdio, prompt, count // 1) do
148+
def getb(device // group_leader(), prompt, count // 1) do
147149
:io.get_chars(map_dev(device), to_iodata(prompt), count)
148150
end
149151

@@ -159,7 +161,7 @@ defmodule IO do
159161
for instance {:error, :estale} if reading from an
160162
NFS file system.
161163
"""
162-
def gets(device // :stdio, prompt) do
164+
def gets(device // group_leader(), prompt) do
163165
:io.get_line(map_dev(device), to_iodata(prompt))
164166
end
165167

0 commit comments

Comments
 (0)