aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorelioat <elioat@tilde.institute>2025-11-15 21:13:53 -0500
committerelioat <elioat@tilde.institute>2025-11-15 21:13:53 -0500
commitc88b806a9f0af91ebeee57d0dac4e21e8ecd0bb4 (patch)
tree7978ca8ddf1551223cbed69518631135dd3e73ab
parent73c8e8d63af17a6e1440b4190255f8cae0c5c980 (diff)
downloadtour-c88b806a9f0af91ebeee57d0dac4e21e8ecd0bb4.tar.gz
Simplify input reading - just read naturally without manual echo
Let the terminal handle echo naturally. We simply read the input, strip the newline, and send it. No manual echo, no duplicate text. Result: Clean input/output with no duplication.
-rw-r--r--gleam/gossip/src/gossip_utils.erl32
1 files changed, 17 insertions, 15 deletions
diff --git a/gleam/gossip/src/gossip_utils.erl b/gleam/gossip/src/gossip_utils.erl
index 311251f..23ba0fe 100644
--- a/gleam/gossip/src/gossip_utils.erl
+++ b/gleam/gossip/src/gossip_utils.erl
@@ -22,22 +22,24 @@ read_line() ->
<<"">>
end.
-% Read a line without echoing it to the terminal
-% We handle the echo ourselves to avoid blank lines
+% Read a line from standard input
+% The terminal will naturally echo what the user types
read_line_no_echo() ->
- try
- io:setopts(user, [{echo, false}]),
- Line = read_line(),
- io:setopts(user, [{echo, true}]),
- % Strip the newline from the line if present
- StrippedLine = string:trim(Line, trailing, "\n"),
- % Echo just the trimmed text (without the extra newline)
- io:format("~s~n", [StrippedLine]),
- StrippedLine
- catch
- _:_ ->
- % If setopts fails, just read normally
- read_line()
+ case file:read_line(standard_io) of
+ {ok, Data} when is_list(Data) ->
+ % Data is a list of character codes including the newline
+ % Convert to binary and strip the newline
+ Line = unicode:characters_to_binary(Data),
+ string:trim(Line, trailing, "\n");
+ {ok, Data} ->
+ % In case it's already binary
+ string:trim(Data, trailing, "\n");
+ eof ->
+ % Return empty string on EOF to signal end of input
+ <<"">>;
+ {error, _Reason} ->
+ % Return empty string on any error
+ <<"">>
end.
% Send a message to a Pid (works for both local and remote PIDs)